michael@0: /* GRAPHITE2 LICENSING michael@0: michael@0: Copyright 2010, SIL International michael@0: All rights reserved. michael@0: michael@0: This library is free software; you can redistribute it and/or modify michael@0: it under the terms of the GNU Lesser General Public License as published michael@0: by the Free Software Foundation; either version 2.1 of License, or michael@0: (at your option) any later version. michael@0: michael@0: This program is distributed in the hope that it will be useful, michael@0: but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@0: Lesser General Public License for more details. michael@0: michael@0: You should also have received a copy of the GNU Lesser General Public michael@0: License along with this library in the file named "LICENSE". michael@0: If not, write to the Free Software Foundation, 51 Franklin Street, michael@0: Suite 500, Boston, MA 02110-1335, USA or visit their web page on the michael@0: internet at http://www.fsf.org/licenses/lgpl.html. michael@0: michael@0: Alternatively, the contents of this file may be used under the terms of the michael@0: Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public michael@0: License, as published by the Free Software Foundation, either version 2 michael@0: of the License or (at your option) any later version. michael@0: */ michael@0: #pragma once michael@0: michael@0: #include michael@0: michael@0: #include "graphite2/Font.h" michael@0: michael@0: #include "inc/Main.h" michael@0: #include "inc/FeatureMap.h" michael@0: #include "inc/TtfUtil.h" michael@0: #include "inc/Silf.h" michael@0: #include "inc/Error.h" michael@0: michael@0: namespace graphite2 { michael@0: michael@0: class Cmap; michael@0: class FileFace; michael@0: class GlyphCache; michael@0: class NameTable; michael@0: class json; michael@0: michael@0: michael@0: using TtfUtil::Tag; michael@0: michael@0: // These are the actual tags, as distinct from the consecutive IDs in TtfUtil.h michael@0: michael@0: class Face michael@0: { michael@0: // Prevent any kind of copying michael@0: Face(const Face&); michael@0: Face& operator=(const Face&); michael@0: michael@0: public: michael@0: class Table; michael@0: static float default_glyph_advance(const void* face_ptr, gr_uint16 glyphid); michael@0: michael@0: Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops); michael@0: virtual ~Face(); michael@0: michael@0: virtual bool runGraphite(Segment *seg, const Silf *silf) const; michael@0: michael@0: public: michael@0: bool readGlyphs(uint32 faceOptions); michael@0: bool readGraphite(const Table & silf); michael@0: bool readFeatures(); michael@0: void takeFileFace(FileFace* pFileFace/*takes ownership*/); michael@0: michael@0: const SillMap & theSill() const; michael@0: const GlyphCache & glyphs() const; michael@0: Cmap & cmap() const; michael@0: NameTable * nameTable() const; michael@0: void setLogger(FILE *log_file); michael@0: json * logger() const throw(); michael@0: michael@0: const Silf * chooseSilf(uint32 script) const; michael@0: uint16 languageForLocale(const char * locale) const; michael@0: michael@0: // Features michael@0: uint16 numFeatures() const; michael@0: const FeatureRef * featureById(uint32 id) const; michael@0: const FeatureRef * feature(uint16 index) const; michael@0: michael@0: // Glyph related michael@0: uint16 getGlyphMetric(uint16 gid, uint8 metric) const; michael@0: uint16 findPseudo(uint32 uid) const; michael@0: michael@0: // Errors michael@0: unsigned int error() const { return m_error; } michael@0: bool error(Error e) { m_error = e.error(); return false; } michael@0: unsigned int error_context() const { return m_error; } michael@0: void error_context(unsigned int errcntxt) { m_errcntxt = errcntxt; } michael@0: michael@0: CLASS_NEW_DELETE; michael@0: private: michael@0: SillMap m_Sill; michael@0: gr_face_ops m_ops; michael@0: const void * m_appFaceHandle; // non-NULL michael@0: FileFace * m_pFileFace; //owned michael@0: mutable GlyphCache * m_pGlyphFaceCache; // owned - never NULL michael@0: mutable Cmap * m_cmap; // cmap cache if available michael@0: mutable NameTable * m_pNames; michael@0: mutable json * m_logger; michael@0: unsigned int m_error; michael@0: unsigned int m_errcntxt; michael@0: protected: michael@0: Silf * m_silfs; // silf subtables. michael@0: uint16 m_numSilf; // num silf subtables in the silf table michael@0: private: michael@0: uint16 m_ascent, michael@0: m_descent; michael@0: #ifdef GRAPHITE2_TELEMETRY michael@0: public: michael@0: mutable telemetry tele; michael@0: #endif michael@0: }; michael@0: michael@0: michael@0: michael@0: inline michael@0: const SillMap & Face::theSill() const michael@0: { michael@0: return m_Sill; michael@0: } michael@0: michael@0: inline michael@0: uint16 Face::numFeatures() const michael@0: { michael@0: return m_Sill.theFeatureMap().numFeats(); michael@0: } michael@0: michael@0: inline michael@0: const FeatureRef * Face::featureById(uint32 id) const michael@0: { michael@0: return m_Sill.theFeatureMap().findFeatureRef(id); michael@0: } michael@0: michael@0: inline michael@0: const FeatureRef *Face::feature(uint16 index) const michael@0: { michael@0: return m_Sill.theFeatureMap().feature(index); michael@0: } michael@0: michael@0: inline michael@0: const GlyphCache & Face::glyphs() const michael@0: { michael@0: return *m_pGlyphFaceCache; michael@0: } michael@0: michael@0: inline michael@0: Cmap & Face::cmap() const michael@0: { michael@0: return *m_cmap; michael@0: }; michael@0: michael@0: inline michael@0: json * Face::logger() const throw() michael@0: { michael@0: return m_logger; michael@0: } michael@0: michael@0: michael@0: michael@0: class Face::Table michael@0: { michael@0: const Face * _f; michael@0: mutable const byte * _p; michael@0: uint32 _sz; michael@0: michael@0: public: michael@0: Table() throw(); michael@0: Table(const Face & face, const Tag n) throw(); michael@0: Table(const Table & rhs) throw(); michael@0: ~Table() throw(); michael@0: michael@0: operator const byte * () const throw(); michael@0: michael@0: Table & operator = (const Table & rhs) throw(); michael@0: size_t size() const throw(); michael@0: }; michael@0: michael@0: inline michael@0: Face::Table::Table() throw() michael@0: : _f(0), _p(0), _sz(0) michael@0: { michael@0: } michael@0: michael@0: inline michael@0: Face::Table::Table(const Table & rhs) throw() michael@0: : _f(rhs._f), _p(rhs._p), _sz(rhs._sz) michael@0: { michael@0: rhs._p = 0; michael@0: } michael@0: michael@0: inline michael@0: Face::Table::~Table() throw() michael@0: { michael@0: if (_p && _f->m_ops.release_table) michael@0: (*_f->m_ops.release_table)(_f->m_appFaceHandle, _p); michael@0: } michael@0: michael@0: inline michael@0: Face::Table::operator const byte * () const throw() michael@0: { michael@0: return _p; michael@0: } michael@0: michael@0: inline michael@0: size_t Face::Table::size() const throw() michael@0: { michael@0: return _sz; michael@0: } michael@0: michael@0: } // namespace graphite2 michael@0: michael@0: struct gr_face : public graphite2::Face {};