Face.h (5653B)
1 /* GRAPHITE2 LICENSING 2 3 Copyright 2010, SIL International 4 All rights reserved. 5 6 This library is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as published 8 by the Free Software Foundation; either version 2.1 of License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should also have received a copy of the GNU Lesser General Public 17 License along with this library in the file named "LICENSE". 18 If not, write to the Free Software Foundation, 51 Franklin Street, 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 20 internet at http://www.fsf.org/licenses/lgpl.html. 21 22 Alternatively, the contents of this file may be used under the terms of the 23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public 24 License, as published by the Free Software Foundation, either version 2 25 of the License or (at your option) any later version. 26 */ 27 #pragma once 28 29 #include <cstdio> 30 31 #include "graphite2/Font.h" 32 33 #include "inc/Main.h" 34 #include "inc/FeatureMap.h" 35 #include "inc/TtfUtil.h" 36 #include "inc/Silf.h" 37 #include "inc/Error.h" 38 39 namespace graphite2 { 40 41 class Cmap; 42 class FileFace; 43 class GlyphCache; 44 class NameTable; 45 class json; 46 class Font; 47 48 49 using TtfUtil::Tag; 50 51 // These are the actual tags, as distinct from the consecutive IDs in TtfUtil.h 52 53 class Face 54 { 55 // Prevent any kind of copying 56 Face(const Face&); 57 Face& operator=(const Face&); 58 59 public: 60 class Table; 61 static float default_glyph_advance(const void* face_ptr, gr_uint16 glyphid); 62 63 Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops); 64 virtual ~Face(); 65 66 virtual bool runGraphite(Segment *seg, const Silf *silf) const; 67 68 public: 69 bool readGlyphs(uint32 faceOptions); 70 bool readGraphite(const Table & silf); 71 bool readFeatures(); 72 void takeFileFace(FileFace* pFileFace/*takes ownership*/); 73 74 const SillMap & theSill() const; 75 const GlyphCache & glyphs() const; 76 Cmap & cmap() const; 77 NameTable * nameTable() const; 78 void setLogger(FILE *log_file); 79 json * logger() const throw(); 80 81 const Silf * chooseSilf(uint32 script) const; 82 uint16 languageForLocale(const char * locale) const; 83 84 // Features 85 uint16 numFeatures() const; 86 const FeatureRef * featureById(uint32 id) const; 87 const FeatureRef * feature(uint16 index) const; 88 89 // Glyph related 90 int32 getGlyphMetric(uint16 gid, uint8 metric) const; 91 uint16 findPseudo(uint32 uid) const; 92 93 // Errors 94 unsigned int error() const { return m_error; } 95 bool error(Error e) { m_error = e.error(); return false; } 96 unsigned int error_context() const { return m_error; } 97 void error_context(unsigned int errcntxt) { m_errcntxt = errcntxt; } 98 99 CLASS_NEW_DELETE; 100 private: 101 SillMap m_Sill; 102 gr_face_ops m_ops; 103 const void * m_appFaceHandle; // non-NULL 104 FileFace * m_pFileFace; //owned 105 mutable GlyphCache * m_pGlyphFaceCache; // owned - never NULL 106 mutable Cmap * m_cmap; // cmap cache if available 107 mutable NameTable * m_pNames; 108 mutable json * m_logger; 109 unsigned int m_error; 110 unsigned int m_errcntxt; 111 protected: 112 Silf * m_silfs; // silf subtables. 113 uint16 m_numSilf; // num silf subtables in the silf table 114 private: 115 uint16 m_ascent, 116 m_descent; 117 #ifdef GRAPHITE2_TELEMETRY 118 public: 119 mutable telemetry tele; 120 #endif 121 }; 122 123 124 125 inline 126 const SillMap & Face::theSill() const 127 { 128 return m_Sill; 129 } 130 131 inline 132 uint16 Face::numFeatures() const 133 { 134 return m_Sill.theFeatureMap().numFeats(); 135 } 136 137 inline 138 const FeatureRef * Face::featureById(uint32 id) const 139 { 140 return m_Sill.theFeatureMap().findFeatureRef(id); 141 } 142 143 inline 144 const FeatureRef *Face::feature(uint16 index) const 145 { 146 return m_Sill.theFeatureMap().feature(index); 147 } 148 149 inline 150 const GlyphCache & Face::glyphs() const 151 { 152 return *m_pGlyphFaceCache; 153 } 154 155 inline 156 Cmap & Face::cmap() const 157 { 158 return *m_cmap; 159 }; 160 161 inline 162 json * Face::logger() const throw() 163 { 164 return m_logger; 165 } 166 167 168 169 class Face::Table 170 { 171 const Face * _f; 172 mutable const byte * _p; 173 size_t _sz; 174 bool _compressed; 175 176 Error decompress(); 177 178 void release(); 179 180 public: 181 Table() throw(); 182 Table(const Face & face, const Tag n, uint32 version=0xffffffff) throw(); 183 ~Table() throw(); 184 Table(const Table && rhs) throw(); 185 186 operator const byte * () const throw(); 187 188 size_t size() const throw(); 189 Table & operator = (const Table && rhs) throw(); 190 }; 191 192 inline 193 Face::Table::Table() throw() 194 : _f(0), _p(0), _sz(0), _compressed(false) 195 { 196 } 197 198 inline 199 Face::Table::Table(const Table && rhs) throw() 200 : _f(rhs._f), _p(rhs._p), _sz(rhs._sz), _compressed(rhs._compressed) 201 { 202 rhs._p = 0; 203 } 204 205 inline 206 Face::Table::~Table() throw() 207 { 208 release(); 209 } 210 211 inline 212 Face::Table::operator const byte * () const throw() 213 { 214 return _p; 215 } 216 217 inline 218 size_t Face::Table::size() const throw() 219 { 220 return _sz; 221 } 222 223 } // namespace graphite2 224 225 struct gr_face : public graphite2::Face {};