w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

otf.hh
Go to the documentation of this file.
1 // -*- related-file-name: "../../libefont/otf.cc" -*-
2 #ifndef EFONT_OTF_HH
3 #define EFONT_OTF_HH
4 #include <efont/otfdata.hh>
5 #include <lcdf/hashcode.hh>
6 class ErrorHandler;
7 namespace Efont { namespace OpenType {
8 class Post;
9 class Name;
10 
11 typedef int Glyph; // 16-bit integer
12 
13 class Tag {
14  public:
15  Tag() : _tag(0U) { }
16  explicit Tag(uint32_t tag) : _tag(tag) { }
17  Tag(const char *name);
18  Tag(const String &name);
19  // default destructor
20 
21  static Tag head_tag() { return Tag(0x68656164U); }
22 
23  typedef bool (Tag::*unspecified_bool_type)() const;
24  bool null() const { return _tag == 0; }
25  operator unspecified_bool_type() const {
26  return _tag != 0 ? &Tag::null : 0;
27  }
28  bool valid() const;
29 
30  uint32_t value() const { return _tag; }
31 
32  String text() const;
34 
35  const uint8_t* table_entry(const uint8_t* table, int n, int entry_size) const;
36 
37  const char* script_description() const;
38  const char* language_description() const;
39  const char* feature_description() const;
40 
41  private:
43 };
44 
45 inline hashcode_t hashcode(const Tag& t) {
46  return t.value();
47 }
48 
49 class Font {
50  public:
51  Font(const String& str, ErrorHandler* errh = 0);
52  // default destructor
53 
54  bool ok() const { return _error >= 0; }
55  bool check_checksums(ErrorHandler* errh = 0) const;
56  int error() const { return _error; }
57 
58  const String& data_string() const { return _str; }
59  const uint8_t* data() const { return _str.udata(); }
60  int length() const { return _str.length(); }
61 
62  unsigned units_per_em() const { return _units_per_em; }
63 
64  int ntables() const;
65  bool has_table(Tag tag) const;
66  String table(Tag tag) const;
68  Tag table_tag(int i) const;
69 
70  static uint32_t checksum(const uint8_t *, const uint8_t *);
71  static uint32_t checksum(const String &);
72  static Font make(bool truetype, const Vector<Tag>& tags, const Vector<String>& data);
73 
74  enum { HEADER_SIZE = 12, TABLE_DIR_ENTRY_SIZE = 16 };
75 
76  private:
78  int _error;
79  unsigned _units_per_em;
80 
82 };
83 
84 class ScriptList {
85  public:
86  ScriptList() { }
87  inline ScriptList(const String&, ErrorHandler* = 0);
88  int assign(const String&, ErrorHandler* = 0);
89  // default destructor
90 
91  bool ok() const { return _str.length() > 0; }
92 
94  int features(Tag script, Tag langsys, int& required_fid, Vector<int>& fids, ErrorHandler* = 0, bool clear_fids = true) const;
95 
96  private:
100 
102 
104  int script_offset(Tag) const;
105  int check_script(Tag, int, ErrorHandler*) const;
106  int langsys_offset(Tag, Tag, ErrorHandler* = 0) const;
107 };
108 
109 class FeatureList {
110  public:
112  inline FeatureList(const String&, ErrorHandler* = 0);
113  int assign(const String&, ErrorHandler* = 0);
114  // default destructor
115 
116  bool ok() const { return _str.length() > 0; }
117 
118  Tag tag(int fid) const;
119  String params(int fid, int length, ErrorHandler* = 0, bool old_style_offset = false) const;
120  String size_params(int fid, const Name& name, ErrorHandler* = 0) const;
121  int lookups(int fid, Vector<int>& results, ErrorHandler* = 0, bool clear_results = true) const;
122 
123  int find(Tag, const Vector<int>& fids) const;
124  void filter(Vector<int>& fids, const Vector<Tag>& sorted_ftags) const;
125  inline void filter(Vector<int>& fids, Tag ftag) const;
126 
127  int lookups(const Vector<int>& fids, Vector<int>& results, ErrorHandler* = 0) const;
128  int lookups(const Vector<int>& required_fids, const Vector<int>& fids, const Vector<Tag>& sorted_ftags, Vector<int>& results, ErrorHandler* = 0) const;
129  int lookups(int required_fid, const Vector<int>& fids, const Vector<Tag>& sorted_ftags, Vector<int>& results, ErrorHandler* = 0) const;
130  int lookups(const ScriptList&, Tag script, Tag langsys, const Vector<Tag>& sorted_ftags, Vector<int>& results, ErrorHandler* = 0) const;
131 
132  private:
135 
137 
139  int script_offset(Tag) const;
140  int langsys_offset(Tag, Tag, ErrorHandler* = 0) const;
141 };
142 
143 class Coverage {
144  public:
145  Coverage() noexcept; // empty coverage
146  Coverage(Glyph first, Glyph last) noexcept; // range coverage
147  Coverage(const Vector<bool> &gmap) noexcept; // used-bytemap coverage
148  Coverage(const String &str, ErrorHandler *errh = 0, bool check = true) noexcept;
149  // default destructor
150 
151  bool ok() const noexcept { return _str.length() > 0; }
152  int size() const noexcept;
153  bool has_fast_covers() const noexcept {
154  return _str.length() > 0 && _str.data()[1] == T_X_BYTEMAP;
155  }
156 
157  int coverage_index(Glyph) const noexcept;
158  bool covers(Glyph g) const noexcept { return coverage_index(g) >= 0; }
159 
160  void unparse(StringAccum&) const noexcept;
161  String unparse() const noexcept;
162 
163  class iterator { public:
164  iterator() : _pos(0), _value(0) { }
165  // private constructor
166  // default destructor
167 
168  bool ok() const { return _pos < _str.length(); }
169  operator bool() const { return ok(); }
170 
171  Glyph operator*() const { return _value; }
172  Glyph value() const { return _value; }
173  int coverage_index() const;
174 
175  void operator++(int);
176  void operator++() { (*this)++; }
177  bool forward_to(Glyph);
178 
179  // XXX should check iterators are of same type
180  bool operator<(const iterator& o) { return _value < o._value; }
181  bool operator<=(const iterator& o) { return _value <= o._value; }
182  bool operator>=(const iterator& o) { return _value >= o._value; }
183  bool operator>(const iterator& o) { return _value > o._value; }
184  bool operator==(const iterator& o) { return _value == o._value; }
185  bool operator!=(const iterator& o) { return _value != o._value; }
186 
187  private:
189  int _pos;
191  friend class Coverage;
192  iterator(const String &str, bool is_end);
193  };
194 
195  iterator begin() const { return iterator(_str, false); }
196  iterator end() const { return iterator(_str, true); }
197  Glyph operator[](int) const noexcept;
198 
199  enum { T_LIST = 1, T_RANGES = 2, T_X_BYTEMAP = 3,
201 
202  private:
204 
205  int check(ErrorHandler*);
206 };
207 
208 Coverage operator&(const Coverage&, const Coverage&);
209 bool operator<=(const Coverage&, const Coverage&);
210 
211 inline bool operator>=(const Coverage& a, const Coverage& b) {
212  return b <= a;
213 }
214 
215 class GlyphSet {
216  public:
217  GlyphSet();
218  GlyphSet(const GlyphSet&);
219  ~GlyphSet();
220 
221  inline bool covers(Glyph g) const;
222  inline bool operator[](Glyph g) const;
223  int change(Glyph, bool);
224  void insert(Glyph g) { change(g, true); }
225  void remove(Glyph g) { change(g, false); }
226 
227  GlyphSet& operator=(const GlyphSet&);
228 
229  private:
230  enum { GLYPHBITS = 16, SHIFT = 8,
232  MASK = (1 << UNSHIFT) - 1, VLEN = (1 << SHIFT),
233  VULEN = (1 << UNSHIFT) >> 5
234  };
235 
237 };
238 
239 class ClassDef {
240  public:
241  ClassDef(const String&, ErrorHandler* = 0) noexcept;
242  // default destructor
243 
244  bool ok() const { return _str.length() > 0; }
245  int nclass() const noexcept;
246 
247  int lookup(Glyph) const noexcept;
248  int operator[](Glyph g) const noexcept { return lookup(g); }
249 
250  void unparse(StringAccum&) const noexcept;
251  String unparse() const noexcept;
252 
254  public:
255  // private constructor
256  // default destructor
257 
258  bool ok() const { return _pos < _str.length(); }
259  operator bool() const { return ok(); }
260 
261  Glyph operator*() const { return *_coviter; }
262  Glyph value() const { return *_coviter; }
263  int class_value() const { return _class; }
264 
265  void operator++(int);
266  void operator++() { (*this)++; }
267 
268  // XXX should check iterators are of same type
269  bool operator<(const class_iterator& o) { return _coviter < o._coviter; }
270  bool operator<=(const class_iterator& o) { return _coviter <= o._coviter; }
271  bool operator>=(const class_iterator& o) { return _coviter >= o._coviter; }
272  bool operator>(const class_iterator& o) { return _coviter > o._coviter; }
273  bool operator==(const class_iterator& o) { return _coviter == o._coviter; }
274  bool operator!=(const class_iterator& o) { return _coviter != o._coviter; }
275 
276  private:
278  int _pos;
279  int _class;
281  friend class ClassDef;
282  class_iterator(const String&, int, int, const Coverage::iterator&);
283  void increment_class0();
284  enum { FIRST_POS = -1, LAST_POS = -2 };
285  };
286 
287  // XXX does not work correctly for class 0
289  class_iterator begin(int c, const Coverage& coverage) const { return class_iterator(_str, 0, c, coverage.begin()); }
291 
292  enum { T_LIST = 1, T_RANGES = 2,
295 
296  private:
298 
299  int check(ErrorHandler*);
300 };
301 
303 
304 
305 inline bool operator==(Tag t1, uint32_t t2) {
306  return t1.value() == t2;
307 }
308 
309 inline bool operator!=(Tag t1, uint32_t t2) {
310  return t1.value() != t2;
311 }
312 
313 inline bool operator<(Tag t1, uint32_t t2) {
314  return t1.value() < t2;
315 }
316 
317 inline bool operator>(Tag t1, uint32_t t2) {
318  return t1.value() > t2;
319 }
320 
321 inline bool operator<=(Tag t1, uint32_t t2) {
322  return t1.value() <= t2;
323 }
324 
325 inline bool operator>=(Tag t1, uint32_t t2) {
326  return t1.value() >= t2;
327 }
328 
329 inline bool operator==(Tag t1, Tag t2) {
330  return t1.value() == t2.value();
331 }
332 
333 inline bool operator!=(Tag t1, Tag t2) {
334  return t1.value() != t2.value();
335 }
336 
337 inline bool operator<(Tag t1, Tag t2) {
338  return t1.value() < t2.value();
339 }
340 
342  assign(str, errh);
343 }
344 
346  assign(str, errh);
347 }
348 
349 inline void FeatureList::filter(Vector<int>& fids, Tag ftag) const {
351  tags.push_back(ftag);
352  filter(fids, tags);
353 }
354 
355 inline bool GlyphSet::covers(Glyph g) const {
356  if ((unsigned)g > MAXGLYPH)
357  return false;
358  else if (const uint32_t* u = _v[g >> SHIFT])
359  return (u[(g & MASK) >> 5] & (1 << (g & 0x1F))) != 0;
360  else
361  return false;
362 }
363 
364 inline bool GlyphSet::operator[](Glyph g) const {
365  return covers(g);
366 }
367 
368 } // namespace Efont::OpenType
369 } // namespace Efont
370 
371 #endif
#define name
static char gmap[128]
Definition: asciitopgm.c:19
#define bool
Definition: autosp.c:101
bool operator>(const class_iterator &o)
Definition: otf.hh:272
bool operator==(const class_iterator &o)
Definition: otf.hh:273
bool operator>=(const class_iterator &o)
Definition: otf.hh:271
bool operator<=(const class_iterator &o)
Definition: otf.hh:270
bool operator!=(const class_iterator &o)
Definition: otf.hh:274
bool operator<(const class_iterator &o)
Definition: otf.hh:269
int nclass() const noexcept
class_iterator begin(int c) const
Definition: otf.hh:288
int lookup(Glyph) const noexcept
Definition: otf.cc:1280
class_iterator begin(int c, const Coverage &coverage) const
Definition: otf.hh:289
class_iterator end(int c) const
Definition: otf.hh:290
ClassDef(const String &, ErrorHandler *=0) noexcept
Definition: otf.cc:1240
String unparse() const noexcept
Definition: otf.cc:1339
int check(ErrorHandler *)
Definition: otf.cc:1249
bool ok() const
Definition: otf.hh:244
bool operator>=(const iterator &o)
Definition: otf.hh:182
bool operator<(const iterator &o)
Definition: otf.hh:180
bool operator==(const iterator &o)
Definition: otf.hh:184
bool operator>(const iterator &o)
Definition: otf.hh:183
bool operator<=(const iterator &o)
Definition: otf.hh:181
bool operator!=(const iterator &o)
Definition: otf.hh:185
bool ok() const noexcept
Definition: otf.hh:151
Coverage() noexcept
Definition: otf.cc:750
bool covers(Glyph g) const noexcept
Definition: otf.hh:158
int size() const noexcept
Definition: otf.cc:847
iterator end() const
Definition: otf.hh:196
iterator begin() const
Definition: otf.hh:195
int coverage_index(Glyph) const noexcept
Definition: otf.cc:864
bool has_fast_covers() const noexcept
Definition: otf.hh:153
int check(ErrorHandler *)
Definition: otf.cc:811
Glyph operator[](int) const noexcept
Definition: otf.cc:909
String unparse() const noexcept
Definition: otf.cc:961
int check_header(ErrorHandler *)
Definition: otf.cc:522
String size_params(int fid, const Name &name, ErrorHandler *=0) const
Definition: otf.cc:573
Tag tag(int fid) const
Definition: otf.cc:533
int find(Tag, const Vector< int > &fids) const
Definition: otf.cc:611
int langsys_offset(Tag, Tag, ErrorHandler *=0) const
String params(int fid, int length, ErrorHandler *=0, bool old_style_offset=false) const
Definition: otf.cc:546
void filter(Vector< int > &fids, const Vector< Tag > &sorted_ftags) const
Definition: otf.cc:629
int assign(const String &, ErrorHandler *=0)
Definition: otf.cc:511
int lookups(int fid, Vector< int > &results, ErrorHandler *=0, bool clear_results=true) const
Definition: otf.cc:664
uint32_t table_checksum(Tag tag) const
Definition: otf.cc:142
Tag table_tag(int i) const
Definition: otf.cc:154
const uint8_t * data() const
Definition: otf.hh:59
unsigned _units_per_em
Definition: otf.hh:79
bool check_checksums(ErrorHandler *errh=0) const
Definition: otf.cc:88
int ntables() const
Definition: otf.cc:112
int parse_header(ErrorHandler *)
Definition: otf.cc:41
Font(const String &str, ErrorHandler *errh=0)
Definition: otf.cc:34
int length() const
Definition: otf.hh:60
static Font make(bool truetype, const Vector< Tag > &tags, const Vector< String > &data)
Definition: otf.cc:193
const String & data_string() const
Definition: otf.hh:58
unsigned units_per_em() const
Definition: otf.hh:62
int error() const
Definition: otf.hh:56
static uint32_t checksum(const uint8_t *, const uint8_t *)
Definition: otf.cc:163
String table(Tag tag) const
Definition: otf.cc:121
bool has_table(Tag tag) const
Definition: otf.cc:133
bool ok() const
Definition: otf.hh:54
int change(Glyph, bool)
Definition: otf.cc:1202
uint32_t * _v[VLEN]
Definition: otf.hh:236
GlyphSet & operator=(const GlyphSet &)
Definition: otf.cc:1220
bool operator[](Glyph g) const
Definition: otf.hh:364
void remove(Glyph g)
Definition: otf.hh:225
void insert(Glyph g)
Definition: otf.hh:224
bool covers(Glyph g) const
Definition: otf.hh:355
int check_script(Tag, int, ErrorHandler *) const
Definition: otf.cc:406
bool ok() const
Definition: otf.hh:91
int langsys_offset(Tag, Tag, ErrorHandler *=0) const
Definition: otf.cc:419
int language_systems(Vector< Tag > &scripts, Vector< Tag > &langsys, ErrorHandler *=0) const
Definition: otf.cc:448
int assign(const String &, ErrorHandler *=0)
Definition: otf.cc:366
int check_header(ErrorHandler *)
Definition: otf.cc:377
int script_offset(Tag) const
Definition: otf.cc:394
int features(Tag script, Tag langsys, int &required_fid, Vector< int > &fids, ErrorHandler *=0, bool clear_fids=true) const
Definition: otf.cc:474
const char * language_description() const
Definition: otfdescrip.cc:706
uint32_t value() const
Definition: otf.hh:30
const char * feature_description() const
Definition: otfdescrip.cc:712
String text() const
Definition: otf.cc:315
bool(Tag::* unspecified_bool_type)() const
Definition: otf.hh:23
bool null() const
Definition: otf.hh:24
Tag(uint32_t tag)
Definition: otf.hh:16
bool valid() const
Definition: otf.cc:305
static String langsys_text(Tag script, Tag langsys=Tag())
Definition: otf.cc:331
const uint8_t * table_entry(const uint8_t *table, int n, int entry_size) const
Definition: otf.cc:340
const char * script_description() const
Definition: otfdescrip.cc:700
uint32_t _tag
Definition: otf.hh:42
static Tag head_tag()
Definition: otf.hh:21
Error reporting class.
Definition: error.hh:86
Efficiently build up Strings from pieces.
Definition: straccum.hh:21
Definition: vector.hh:17
#define n
Definition: t4ht.c:1290
#define b
Definition: jpegint.h:372
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
size_t hashcode_t
Typical type for a hashcode() value.
Definition: hashcode.hh:5
static char * tags[]
Definition: htex.c:62
small capitals from c petite p scientific f u
Definition: afcover.h:88
small capitals from c petite p scientific i
Definition: afcover.h:80
xD9 x84 xD8 xAD xD9 x80 xF0 x90 xAC x9A xE0 xA7 xA6 xE0 xA7 xAA xF0 x91 x84 xA4 xF0 x91 x84 x89 xF0 x91 x84 x9B xF0 x90 x8A xAB xF0 x90 x8B x89 xE2 xB2 x9E xE2 xB2 x9F xD0 xBE xD0 x9E xF0 x90 x90 x84 xF0 x90 x90 xAC xE1 x83 x98 xE1 x83 x94 xE1 x83 x90 xE1 xB2 xBF xE2 xB0 x95 xE2 xB1 x85 xCE xBF xCE x9F xE0 xA8 xA0 xE0 xA8 xB0 xE0 xA9 xA6 Kayah xEA xA4 x8D xEA xA4 x80 Khmer xE1 xA7 xA1 xE1 xA7 xAA xE0 xBB x90 Latin Subscript xE2 x82 x92 xE2 x82 x80 xEA x93 xB3 xF0 x96 xB9 xA1 xF0 x96 xB9 x9B xF0 x96 xB9 xAF xE1 x80 x9D xE1 x80 x84 xE1 x80 x82 no script
Definition: afscript.h:271
#define const
Definition: ftzconf.h:91
unsigned int uint32_t
Definition: stdint.h:80
unsigned char uint8_t
Definition: stdint.h:78
#define length(c)
Definition: ctangleboot.c:65
bool operator>(Tag t1, uint32_t t2)
Definition: otf.hh:317
Vector< PermString > debug_glyph_names
Definition: otf.cc:32
bool operator==(Tag t1, uint32_t t2)
Definition: otf.hh:305
int Glyph
Definition: otf.hh:9
hashcode_t hashcode(const Tag &t)
Definition: otf.hh:45
bool operator<=(const Coverage &, const Coverage &)
Definition: otf.cc:1002
bool operator>=(const Coverage &a, const Coverage &b)
Definition: otf.hh:211
bool operator!=(Tag t1, uint32_t t2)
Definition: otf.hh:309
bool operator<(Tag t1, uint32_t t2)
Definition: otf.hh:313
Coverage operator&(const Coverage &, const Coverage &)
Definition: otf.cc:969
void results()
#define t1
#define t2
static int32_t last
Definition: ppagelist.c:29
static int32_t first
Definition: ppagelist.c:29
int g
Definition: ppmqvga.c:68
static ErrorHandler * errh
Definition: main.cc:71
#define str(s)
Definition: sh6.c:399
A string of characters.
Definition: t1part.c:49
const char * data() const
Return a pointer to the string's data.
Definition: string.hh:161
const unsigned char * udata() const
Return a pointer to the string's data as unsigned chars.
Definition: string.hh:169
int length() const
Return the string's length.
Definition: string.hh:153
Definition: tfm.c:163
Definition: zic.c:306
Definition: epdf.c:232
Definition: dvips.h:235
Definition: table.h:30
Definition: xmlparse.c:179
#define U(a)
Definition: twiddle.h:1