gfx/graphite2/src/inc/Face.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:0c7a91566292
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 <stdio.h>
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
47
48 using TtfUtil::Tag;
49
50 // These are the actual tags, as distinct from the consecutive IDs in TtfUtil.h
51
52 class Face
53 {
54 // Prevent any kind of copying
55 Face(const Face&);
56 Face& operator=(const Face&);
57
58 public:
59 class Table;
60 static float default_glyph_advance(const void* face_ptr, gr_uint16 glyphid);
61
62 Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops);
63 virtual ~Face();
64
65 virtual bool runGraphite(Segment *seg, const Silf *silf) const;
66
67 public:
68 bool readGlyphs(uint32 faceOptions);
69 bool readGraphite(const Table & silf);
70 bool readFeatures();
71 void takeFileFace(FileFace* pFileFace/*takes ownership*/);
72
73 const SillMap & theSill() const;
74 const GlyphCache & glyphs() const;
75 Cmap & cmap() const;
76 NameTable * nameTable() const;
77 void setLogger(FILE *log_file);
78 json * logger() const throw();
79
80 const Silf * chooseSilf(uint32 script) const;
81 uint16 languageForLocale(const char * locale) const;
82
83 // Features
84 uint16 numFeatures() const;
85 const FeatureRef * featureById(uint32 id) const;
86 const FeatureRef * feature(uint16 index) const;
87
88 // Glyph related
89 uint16 getGlyphMetric(uint16 gid, uint8 metric) const;
90 uint16 findPseudo(uint32 uid) const;
91
92 // Errors
93 unsigned int error() const { return m_error; }
94 bool error(Error e) { m_error = e.error(); return false; }
95 unsigned int error_context() const { return m_error; }
96 void error_context(unsigned int errcntxt) { m_errcntxt = errcntxt; }
97
98 CLASS_NEW_DELETE;
99 private:
100 SillMap m_Sill;
101 gr_face_ops m_ops;
102 const void * m_appFaceHandle; // non-NULL
103 FileFace * m_pFileFace; //owned
104 mutable GlyphCache * m_pGlyphFaceCache; // owned - never NULL
105 mutable Cmap * m_cmap; // cmap cache if available
106 mutable NameTable * m_pNames;
107 mutable json * m_logger;
108 unsigned int m_error;
109 unsigned int m_errcntxt;
110 protected:
111 Silf * m_silfs; // silf subtables.
112 uint16 m_numSilf; // num silf subtables in the silf table
113 private:
114 uint16 m_ascent,
115 m_descent;
116 #ifdef GRAPHITE2_TELEMETRY
117 public:
118 mutable telemetry tele;
119 #endif
120 };
121
122
123
124 inline
125 const SillMap & Face::theSill() const
126 {
127 return m_Sill;
128 }
129
130 inline
131 uint16 Face::numFeatures() const
132 {
133 return m_Sill.theFeatureMap().numFeats();
134 }
135
136 inline
137 const FeatureRef * Face::featureById(uint32 id) const
138 {
139 return m_Sill.theFeatureMap().findFeatureRef(id);
140 }
141
142 inline
143 const FeatureRef *Face::feature(uint16 index) const
144 {
145 return m_Sill.theFeatureMap().feature(index);
146 }
147
148 inline
149 const GlyphCache & Face::glyphs() const
150 {
151 return *m_pGlyphFaceCache;
152 }
153
154 inline
155 Cmap & Face::cmap() const
156 {
157 return *m_cmap;
158 };
159
160 inline
161 json * Face::logger() const throw()
162 {
163 return m_logger;
164 }
165
166
167
168 class Face::Table
169 {
170 const Face * _f;
171 mutable const byte * _p;
172 uint32 _sz;
173
174 public:
175 Table() throw();
176 Table(const Face & face, const Tag n) throw();
177 Table(const Table & rhs) throw();
178 ~Table() throw();
179
180 operator const byte * () const throw();
181
182 Table & operator = (const Table & rhs) throw();
183 size_t size() const throw();
184 };
185
186 inline
187 Face::Table::Table() throw()
188 : _f(0), _p(0), _sz(0)
189 {
190 }
191
192 inline
193 Face::Table::Table(const Table & rhs) throw()
194 : _f(rhs._f), _p(rhs._p), _sz(rhs._sz)
195 {
196 rhs._p = 0;
197 }
198
199 inline
200 Face::Table::~Table() throw()
201 {
202 if (_p && _f->m_ops.release_table)
203 (*_f->m_ops.release_table)(_f->m_appFaceHandle, _p);
204 }
205
206 inline
207 Face::Table::operator const byte * () const throw()
208 {
209 return _p;
210 }
211
212 inline
213 size_t Face::Table::size() const throw()
214 {
215 return _sz;
216 }
217
218 } // namespace graphite2
219
220 struct gr_face : public graphite2::Face {};

mercurial