1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/graphite2/src/inc/Face.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,220 @@ 1.4 +/* GRAPHITE2 LICENSING 1.5 + 1.6 + Copyright 2010, SIL International 1.7 + All rights reserved. 1.8 + 1.9 + This library is free software; you can redistribute it and/or modify 1.10 + it under the terms of the GNU Lesser General Public License as published 1.11 + by the Free Software Foundation; either version 2.1 of License, or 1.12 + (at your option) any later version. 1.13 + 1.14 + This program is distributed in the hope that it will be useful, 1.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.17 + Lesser General Public License for more details. 1.18 + 1.19 + You should also have received a copy of the GNU Lesser General Public 1.20 + License along with this library in the file named "LICENSE". 1.21 + If not, write to the Free Software Foundation, 51 Franklin Street, 1.22 + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 1.23 + internet at http://www.fsf.org/licenses/lgpl.html. 1.24 + 1.25 +Alternatively, the contents of this file may be used under the terms of the 1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public 1.27 +License, as published by the Free Software Foundation, either version 2 1.28 +of the License or (at your option) any later version. 1.29 +*/ 1.30 +#pragma once 1.31 + 1.32 +#include <stdio.h> 1.33 + 1.34 +#include "graphite2/Font.h" 1.35 + 1.36 +#include "inc/Main.h" 1.37 +#include "inc/FeatureMap.h" 1.38 +#include "inc/TtfUtil.h" 1.39 +#include "inc/Silf.h" 1.40 +#include "inc/Error.h" 1.41 + 1.42 +namespace graphite2 { 1.43 + 1.44 +class Cmap; 1.45 +class FileFace; 1.46 +class GlyphCache; 1.47 +class NameTable; 1.48 +class json; 1.49 + 1.50 + 1.51 +using TtfUtil::Tag; 1.52 + 1.53 +// These are the actual tags, as distinct from the consecutive IDs in TtfUtil.h 1.54 + 1.55 +class Face 1.56 +{ 1.57 + // Prevent any kind of copying 1.58 + Face(const Face&); 1.59 + Face& operator=(const Face&); 1.60 + 1.61 +public: 1.62 + class Table; 1.63 + static float default_glyph_advance(const void* face_ptr, gr_uint16 glyphid); 1.64 + 1.65 + Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops); 1.66 + virtual ~Face(); 1.67 + 1.68 + virtual bool runGraphite(Segment *seg, const Silf *silf) const; 1.69 + 1.70 +public: 1.71 + bool readGlyphs(uint32 faceOptions); 1.72 + bool readGraphite(const Table & silf); 1.73 + bool readFeatures(); 1.74 + void takeFileFace(FileFace* pFileFace/*takes ownership*/); 1.75 + 1.76 + const SillMap & theSill() const; 1.77 + const GlyphCache & glyphs() const; 1.78 + Cmap & cmap() const; 1.79 + NameTable * nameTable() const; 1.80 + void setLogger(FILE *log_file); 1.81 + json * logger() const throw(); 1.82 + 1.83 + const Silf * chooseSilf(uint32 script) const; 1.84 + uint16 languageForLocale(const char * locale) const; 1.85 + 1.86 + // Features 1.87 + uint16 numFeatures() const; 1.88 + const FeatureRef * featureById(uint32 id) const; 1.89 + const FeatureRef * feature(uint16 index) const; 1.90 + 1.91 + // Glyph related 1.92 + uint16 getGlyphMetric(uint16 gid, uint8 metric) const; 1.93 + uint16 findPseudo(uint32 uid) const; 1.94 + 1.95 + // Errors 1.96 + unsigned int error() const { return m_error; } 1.97 + bool error(Error e) { m_error = e.error(); return false; } 1.98 + unsigned int error_context() const { return m_error; } 1.99 + void error_context(unsigned int errcntxt) { m_errcntxt = errcntxt; } 1.100 + 1.101 + CLASS_NEW_DELETE; 1.102 +private: 1.103 + SillMap m_Sill; 1.104 + gr_face_ops m_ops; 1.105 + const void * m_appFaceHandle; // non-NULL 1.106 + FileFace * m_pFileFace; //owned 1.107 + mutable GlyphCache * m_pGlyphFaceCache; // owned - never NULL 1.108 + mutable Cmap * m_cmap; // cmap cache if available 1.109 + mutable NameTable * m_pNames; 1.110 + mutable json * m_logger; 1.111 + unsigned int m_error; 1.112 + unsigned int m_errcntxt; 1.113 +protected: 1.114 + Silf * m_silfs; // silf subtables. 1.115 + uint16 m_numSilf; // num silf subtables in the silf table 1.116 +private: 1.117 + uint16 m_ascent, 1.118 + m_descent; 1.119 +#ifdef GRAPHITE2_TELEMETRY 1.120 +public: 1.121 + mutable telemetry tele; 1.122 +#endif 1.123 +}; 1.124 + 1.125 + 1.126 + 1.127 +inline 1.128 +const SillMap & Face::theSill() const 1.129 +{ 1.130 + return m_Sill; 1.131 +} 1.132 + 1.133 +inline 1.134 +uint16 Face::numFeatures() const 1.135 +{ 1.136 + return m_Sill.theFeatureMap().numFeats(); 1.137 +} 1.138 + 1.139 +inline 1.140 +const FeatureRef * Face::featureById(uint32 id) const 1.141 +{ 1.142 + return m_Sill.theFeatureMap().findFeatureRef(id); 1.143 +} 1.144 + 1.145 +inline 1.146 +const FeatureRef *Face::feature(uint16 index) const 1.147 +{ 1.148 + return m_Sill.theFeatureMap().feature(index); 1.149 +} 1.150 + 1.151 +inline 1.152 +const GlyphCache & Face::glyphs() const 1.153 +{ 1.154 + return *m_pGlyphFaceCache; 1.155 +} 1.156 + 1.157 +inline 1.158 +Cmap & Face::cmap() const 1.159 +{ 1.160 + return *m_cmap; 1.161 +}; 1.162 + 1.163 +inline 1.164 +json * Face::logger() const throw() 1.165 +{ 1.166 + return m_logger; 1.167 +} 1.168 + 1.169 + 1.170 + 1.171 +class Face::Table 1.172 +{ 1.173 + const Face * _f; 1.174 + mutable const byte * _p; 1.175 + uint32 _sz; 1.176 + 1.177 +public: 1.178 + Table() throw(); 1.179 + Table(const Face & face, const Tag n) throw(); 1.180 + Table(const Table & rhs) throw(); 1.181 + ~Table() throw(); 1.182 + 1.183 + operator const byte * () const throw(); 1.184 + 1.185 + Table & operator = (const Table & rhs) throw(); 1.186 + size_t size() const throw(); 1.187 +}; 1.188 + 1.189 +inline 1.190 +Face::Table::Table() throw() 1.191 +: _f(0), _p(0), _sz(0) 1.192 +{ 1.193 +} 1.194 + 1.195 +inline 1.196 +Face::Table::Table(const Table & rhs) throw() 1.197 +: _f(rhs._f), _p(rhs._p), _sz(rhs._sz) 1.198 +{ 1.199 + rhs._p = 0; 1.200 +} 1.201 + 1.202 +inline 1.203 +Face::Table::~Table() throw() 1.204 +{ 1.205 + if (_p && _f->m_ops.release_table) 1.206 + (*_f->m_ops.release_table)(_f->m_appFaceHandle, _p); 1.207 +} 1.208 + 1.209 +inline 1.210 +Face::Table::operator const byte * () const throw() 1.211 +{ 1.212 + return _p; 1.213 +} 1.214 + 1.215 +inline 1.216 +size_t Face::Table::size() const throw() 1.217 +{ 1.218 + return _sz; 1.219 +} 1.220 + 1.221 +} // namespace graphite2 1.222 + 1.223 +struct gr_face : public graphite2::Face {};