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)  

otfgsub.hh
Go to the documentation of this file.
1 // -*- related-file-name: "../../libefont/otfgsub.cc" -*-
2 #ifndef EFONT_OTFGSUB_HH
3 #define EFONT_OTFGSUB_HH
4 #include <efont/otf.hh>
5 #include <efont/otfdata.hh>
6 namespace Efont { namespace OpenType {
7 class GsubLookup;
8 class Substitution;
9 
10 class Gsub { public:
11 
12  Gsub(const Data &, const Font *, ErrorHandler * = 0);
13  // default destructor
14 
15  const ScriptList &script_list() const { return _script_list; }
16  const FeatureList &feature_list() const { return _feature_list; }
18 
19  int nlookups() const;
20  GsubLookup lookup(unsigned) const;
21 
22  enum { HEADERSIZE = 10 };
23 
24  private:
25 
30 
31 };
32 
33 class GsubLookup { public:
34  GsubLookup(const Data &);
35  int type() const { return _type; }
36  uint16_t flags() const { return _d.u16(2); }
37  void mark_out_glyphs(const Gsub &gsub, Vector<bool> &gmap) const;
38  bool unparse_automatics(const Gsub &gsub, Vector<Substitution> &subs, const Coverage &limit) const;
39  bool apply(const Glyph *, int pos, int n, Substitution &) const;
40  enum {
41  HEADERSIZE = 6, RECSIZE = 2,
44  };
45  private:
47  int _type;
48  Data subtable(int i) const;
49 };
50 
51 class GsubSingle { public:
52  GsubSingle(const Data &);
53  // default destructor
54  Coverage coverage() const noexcept;
55  Glyph map(Glyph) const;
56  void mark_out_glyphs(Vector<bool> &gmap) const;
57  void unparse(Vector<Substitution> &subs, const Coverage &limit) const;
58  bool apply(const Glyph *, int pos, int n, Substitution &) const;
59  enum { HEADERSIZE = 6, FORMAT2_RECSIZE = 2 };
60  private:
62 };
63 
64 class GsubMultiple { public:
65  GsubMultiple(const Data &);
66  // default destructor
67  Coverage coverage() const noexcept;
68  bool map(Glyph, Vector<Glyph> &) const;
69  void mark_out_glyphs(Vector<bool> &gmap) const;
70  void unparse(Vector<Substitution> &, bool alternate = false) const;
71  bool apply(const Glyph *, int pos, int n, Substitution &, bool alternate = false) const;
72  enum { HEADERSIZE = 6, RECSIZE = 2,
74  private:
76 };
77 
78 class GsubLigature { public:
79  GsubLigature(const Data &);
80  // default destructor
81  Coverage coverage() const noexcept;
82  bool map(const Vector<Glyph> &, Glyph &, int &) const;
83  void mark_out_glyphs(Vector<bool> &gmap) const;
84  void unparse(Vector<Substitution> &) const;
85  bool apply(const Glyph *, int pos, int n, Substitution &) const;
86  enum { HEADERSIZE = 6, RECSIZE = 2,
89  private:
91 };
92 
93 class GsubContext { public:
94  GsubContext(const Data &);
95  // default destructor
96  Coverage coverage() const noexcept;
97  void mark_out_glyphs(const Gsub &gsub, Vector<bool> &gmap) const;
98  bool unparse(const Gsub &gsub, Vector<Substitution> &out_subs, const Coverage &limit) const;
99  enum { F3_HSIZE = 6, SUBRECSIZE = 4 };
100  private:
102  static void subruleset_mark_out_glyphs(const Data &data, int nsub, int subtab_offset, const Gsub &gsub, Vector<bool> &gmap);
103  static bool f1_unparse(const Data& data,
104  int nsub, int subtab_offset,
105  const Gsub& gsub, Vector<Substitution>& outsubs,
106  Substitution prototype_sub);
107  static bool f3_unparse(const Data &data,
108  int nglyph, int glyphtab_offset, const Coverage &limit,
109  int nsub, int subtab_offset,
110  const Gsub &gsub, Vector<Substitution> &outsubs,
111  const Substitution &prototype_sub);
112  friend class GsubChainContext;
113 };
114 
115 class GsubChainContext { public:
116  GsubChainContext(const Data &);
117  // default destructor
118  Coverage coverage() const noexcept;
119  void mark_out_glyphs(const Gsub &gsub, Vector<bool> &gmap) const;
120  bool unparse(const Gsub &gsub, Vector<Substitution> &subs, const Coverage &limit) const;
121  enum { F1_HEADERSIZE = 6, F1_RECSIZE = 2,
124  private:
126  bool f1_unparse(const Gsub &gsub, Vector<Substitution> &subs, const Coverage &limit) const;
127  bool f3_unparse(const Gsub &gsub, Vector<Substitution> &subs, const Coverage &limit) const;
128 };
129 
130 class Substitution { public:
131 
132  Substitution();
133  Substitution(const Substitution &);
134 
135  // single substitution
137 
138  // multiple substitution
139  Substitution(Glyph in, const Vector<Glyph> &out, bool is_alternate = false);
140 
141  // ligature substitution
142  Substitution(Glyph in1, Glyph in2, Glyph out);
144  Substitution(int nin, const Glyph *in, Glyph out);
145 
146  // space
147  Substitution(int nleft, int nin, int nout, int nright);
148 
149  ~Substitution();
150 
152 
153  bool context_in(const Coverage &) const;
154  bool context_in(const GlyphSet &) const;
155 
156  // types
157  inline operator bool() const;
158  bool is_noop() const;
159  inline bool is_single() const;
160  inline bool is_multiple() const;
161  inline bool is_alternate() const;
162  inline bool is_ligature() const;
163  inline bool is_simple_context() const;
164  inline bool is_single_lcontext() const;
165  inline bool is_single_rcontext() const;
166  inline bool is_lcontext() const;
167  inline bool is_rcontext() const;
168 
169  // extract data
170  inline Glyph left_glyph() const;
171  inline int left_nglyphs() const;
172  inline Glyph *left_glyphptr();
173  inline const Glyph *left_glyphptr() const;
174 
175  inline Glyph in_glyph() const;
176  inline Glyph in_glyph(int pos) const;
177  inline bool in_glyphs(Vector<Glyph> &) const;
178  inline int in_nglyphs() const;
179  inline Glyph *in_glyphptr();
180  inline const Glyph *in_glyphptr() const;
181 
182  inline bool in_matches(int pos, Glyph) const;
183 
184  inline Glyph out_glyph() const;
185  inline Glyph out_glyph(int pos) const;
186  inline bool out_glyphs(Vector<Glyph> &) const;
187  inline Glyph *out_glyphptr();
188  inline const Glyph *out_glyphptr() const;
189 
190  inline int out_nglyphs() const;
191  inline Glyph right_glyph() const;
192  inline Glyph *right_glyphptr();
193  inline const Glyph *right_glyphptr() const;
194 
195  bool all_in_glyphs(Vector<Glyph> &gs) const;
196  bool all_out_glyphs(Vector<Glyph> &gs) const;
197 
198  // alter
199  void add_outer_left(Glyph);
200  void remove_outer_left();
202  bool out_alter(const Substitution &, int) noexcept;
203  void add_outer_right(Glyph);
204  void remove_outer_right();
205 
206  void unparse(StringAccum &, const Vector<PermString> * = &debug_glyph_names) const;
208 
209  private:
210 
212  typedef union {
214  Glyph *gids; // first entry is a count
216  } Substitute;
217 
222 
227 
228  bool _alternate : 1;
229 
230  static void clear(Substitute &, uint8_t &);
231  static void assign_space(Substitute &, uint8_t &, int);
232  static void assign(Substitute &, uint8_t &, Glyph);
233  static void assign(Substitute &, uint8_t &, int, const Glyph *);
234  static void assign(Substitute &, uint8_t &, const Coverage &);
235  static void assign(Substitute &, uint8_t &, const Substitute &, uint8_t);
236  static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, const Substitute &, uint8_t);
237  static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, Glyph);
238  static bool substitute_in(const Substitute &, uint8_t, const Coverage &);
239  static bool substitute_in(const Substitute &, uint8_t, const GlyphSet &);
240 
241  static Glyph extract_glyph(const Substitute &, uint8_t) noexcept;
242  static Glyph extract_glyph(const Substitute &, int which, uint8_t) noexcept;
243  static bool extract_glyphs(const Substitute &, uint8_t, Vector<Glyph> &, bool coverage_ok) noexcept;
244  static Glyph *extract_glyphptr(const Substitute &, uint8_t) noexcept;
245  static int extract_nglyphs(const Substitute &, uint8_t, bool coverage_ok) noexcept;
246  static bool matches(const Substitute &, uint8_t, int pos, Glyph) noexcept;
247 
248  static void unparse_glyphids(StringAccum &, const Substitute &, uint8_t, const Vector<PermString> *) noexcept;
249 
250 };
251 
253  : _left_is(T_NONE), _in_is(T_NONE), _out_is(T_NONE), _right_is(T_NONE)
254 {
255 }
256 
257 /* Single 1: u16 format, offset coverage, u16 glyphdelta
258  Single 2: u16 format, offset coverage, u16 count, glyph subst[]
259  Multiple 1: u16 format, offset coverage, u16 count, offset sequence[];
260  sequence is: u16 count, glyph subst[]
261  Alternate 1: u16 format, offset coverage, u16 count, offset alternates[];
262  alternate is: u16 count, glyph alts[]
263  Ligature 1: u16 format, offset coverage, u16 count, offset sets[];
264  set is: u16 count, offset ligatures[];
265  ligature is: glyph result, u16 count, glyph components[]
266 */
267 
268 inline Substitution::operator bool() const
269 {
270  return !(_left_is == T_NONE && _in_is == T_NONE && _out_is == T_NONE && _right_is == T_NONE);
271 }
272 
273 inline bool Substitution::is_single() const
274 {
275  return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_NONE;
276 }
277 
278 inline bool Substitution::is_multiple() const
279 {
280  return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPHS && _right_is == T_NONE && !_alternate;
281 }
282 
283 inline bool Substitution::is_alternate() const
284 {
285  return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPHS && _right_is == T_NONE && _alternate;
286 }
287 
288 inline bool Substitution::is_ligature() const
289 {
290  return _left_is == T_NONE && _in_is == T_GLYPHS && _out_is == T_GLYPH && _right_is == T_NONE;
291 }
292 
294 {
295  return _left_is != T_COVERAGE && (_in_is == T_GLYPH || _in_is == T_GLYPHS) && (_out_is == T_GLYPH || _out_is == T_GLYPHS) && _right_is != T_COVERAGE;
296 }
297 
299 {
300  return _left_is == T_GLYPH && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_NONE;
301 }
302 
304 {
305  return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_GLYPH;
306 }
307 
309 {
310  return extract_glyph(_left, _left_is);
311 }
312 
313 inline int Substitution::left_nglyphs() const
314 {
315  return extract_nglyphs(_left, _left_is, false);
316 }
317 
319 {
320  return extract_glyph(_in, _in_is);
321 }
322 
323 inline Glyph Substitution::in_glyph(int which) const
324 {
325  return extract_glyph(_in, which, _in_is);
326 }
327 
329 {
330  return extract_glyphs(_in, _in_is, v, true);
331 }
332 
333 inline int Substitution::in_nglyphs() const
334 {
335  return extract_nglyphs(_in, _in_is, true);
336 }
337 
338 inline bool Substitution::in_matches(int pos, Glyph g) const
339 {
340  return matches(_in, _in_is, pos, g);
341 }
342 
344 {
345  return extract_glyph(_out, _out_is);
346 }
347 
348 inline Glyph Substitution::out_glyph(int which) const
349 {
350  return extract_glyph(_out, which, _out_is);
351 }
352 
354 {
355  return extract_glyphs(_out, _out_is, v, false);
356 }
357 
358 inline int Substitution::out_nglyphs() const
359 {
360  return extract_nglyphs(_out, _out_is, false);
361 }
362 
364 {
365  return extract_glyph(_right, _right_is);
366 }
367 
368 inline const Glyph *Substitution::left_glyphptr() const
369 {
371 }
372 
374 {
376 }
377 
378 inline const Glyph *Substitution::in_glyphptr() const
379 {
380  return extract_glyphptr(_in, _in_is);
381 }
382 
384 {
385  return extract_glyphptr(_in, _in_is);
386 }
387 
388 inline const Glyph *Substitution::out_glyphptr() const
389 {
390  return extract_glyphptr(_out, _out_is);
391 }
392 
394 {
395  return extract_glyphptr(_out, _out_is);
396 }
397 
398 inline const Glyph *Substitution::right_glyphptr() const
399 {
401 }
402 
404 {
406 }
407 
409 {
410  sub.unparse(sa);
411  return sa;
412 }
413 
414 }}
415 #endif
static char gmap[128]
Definition: asciitopgm.c:19
#define bool
Definition: autosp.c:101
static uint16_t u16(const unsigned char *s)
Definition: otfdata.hh:116
Coverage coverage() const noexcept
Definition: otfgsub.cc:1204
bool f1_unparse(const Gsub &gsub, Vector< Substitution > &subs, const Coverage &limit) const
Definition: otfgsub.cc:1261
void mark_out_glyphs(const Gsub &gsub, Vector< bool > &gmap) const
Definition: otfgsub.cc:1220
bool unparse(const Gsub &gsub, Vector< Substitution > &subs, const Coverage &limit) const
Definition: otfgsub.cc:1387
bool f3_unparse(const Gsub &gsub, Vector< Substitution > &subs, const Coverage &limit) const
Definition: otfgsub.cc:1310
Coverage coverage() const noexcept
Definition: otfgsub.cc:1065
static bool f3_unparse(const Data &data, int nglyph, int glyphtab_offset, const Coverage &limit, int nsub, int subtab_offset, const Gsub &gsub, Vector< Substitution > &outsubs, const Substitution &prototype_sub)
Definition: otfgsub.cc:1115
static void subruleset_mark_out_glyphs(const Data &data, int nsub, int subtab_offset, const Gsub &gsub, Vector< bool > &gmap)
Definition: otfgsub.cc:1074
bool unparse(const Gsub &gsub, Vector< Substitution > &out_subs, const Coverage &limit) const
Definition: otfgsub.cc:1159
static bool f1_unparse(const Data &data, int nsub, int subtab_offset, const Gsub &gsub, Vector< Substitution > &outsubs, Substitution prototype_sub)
Definition: otfgsub.cc:1095
void mark_out_glyphs(const Gsub &gsub, Vector< bool > &gmap) const
Definition: otfgsub.cc:1085
void mark_out_glyphs(Vector< bool > &gmap) const
Definition: otfgsub.cc:983
bool map(const Vector< Glyph > &, Glyph &, int &) const
Definition: otfgsub.cc:956
GsubLigature(const Data &)
Definition: otfgsub.cc:937
void unparse(Vector< Substitution > &) const
Definition: otfgsub.cc:997
bool apply(const Glyph *, int pos, int n, Substitution &) const
Definition: otfgsub.cc:1015
Coverage coverage() const noexcept
Definition: otfgsub.cc:950
bool unparse_automatics(const Gsub &gsub, Vector< Substitution > &subs, const Coverage &limit) const
Definition: otfgsub.cc:689
uint16_t flags() const
Definition: otfgsub.hh:36
GsubLookup(const Data &)
Definition: otfgsub.cc:618
Data subtable(int i) const
Definition: otfgsub.cc:633
void mark_out_glyphs(const Gsub &gsub, Vector< bool > &gmap) const
Definition: otfgsub.cc:645
bool apply(const Glyph *, int pos, int n, Substitution &) const
Definition: otfgsub.cc:739
Coverage coverage() const noexcept
Definition: otfgsub.cc:872
GsubMultiple(const Data &)
Definition: otfgsub.cc:860
bool apply(const Glyph *, int pos, int n, Substitution &, bool alternate=false) const
Definition: otfgsub.cc:917
bool map(Glyph, Vector< Glyph > &) const
Definition: otfgsub.cc:878
void unparse(Vector< Substitution > &, bool alternate=false) const
Definition: otfgsub.cc:904
void mark_out_glyphs(Vector< bool > &gmap) const
Definition: otfgsub.cc:894
GsubSingle(const Data &)
Definition: otfgsub.cc:782
Coverage coverage() const noexcept
Definition: otfgsub.cc:795
bool apply(const Glyph *, int pos, int n, Substitution &) const
Definition: otfgsub.cc:841
void mark_out_glyphs(Vector< bool > &gmap) const
Definition: otfgsub.cc:813
Glyph map(Glyph) const
Definition: otfgsub.cc:801
void unparse(Vector< Substitution > &subs, const Coverage &limit) const
Definition: otfgsub.cc:826
const FeatureList & feature_list() const
Definition: otfgsub.hh:16
const ScriptList & script_list() const
Definition: otfgsub.hh:15
bool _chaincontext_reverse_backtrack
Definition: otfgsub.hh:29
int nlookups() const
Definition: otfgsub.cc:598
bool chaincontext_reverse_backtrack() const
Definition: otfgsub.hh:17
FeatureList _feature_list
Definition: otfgsub.hh:27
Gsub(const Data &, const Font *, ErrorHandler *=0)
Definition: otfgsub.cc:568
GsubLookup lookup(unsigned) const
Definition: otfgsub.cc:604
ScriptList _script_list
Definition: otfgsub.hh:26
static bool substitute_in(const Substitute &, uint8_t, const Coverage &)
Definition: otfgsub.cc:197
bool is_single_rcontext() const
Definition: otfgsub.hh:303
static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, const Substitute &, uint8_t)
Definition: otfgsub.cc:382
static Glyph extract_glyph(const Substitute &, uint8_t) noexcept
Definition: otfgsub.cc:258
Substitution & operator=(const Substitution &)
Definition: otfgsub.cc:186
static bool matches(const Substitute &, uint8_t, int pos, Glyph) noexcept
Definition: otfgsub.cc:333
bool all_out_glyphs(Vector< Glyph > &gs) const
Definition: otfgsub.cc:370
bool in_glyphs(Vector< Glyph > &) const
Definition: otfgsub.hh:328
static Glyph * extract_glyphptr(const Substitute &, uint8_t) noexcept
Definition: otfgsub.cc:305
bool in_matches(int pos, Glyph) const
Definition: otfgsub.hh:338
bool is_simple_context() const
Definition: otfgsub.hh:293
static void unparse_glyphids(StringAccum &, const Substitute &, uint8_t, const Vector< PermString > *) noexcept
Definition: otfgsub.cc:502
bool is_single_lcontext() const
Definition: otfgsub.hh:298
bool out_glyphs(Vector< Glyph > &) const
Definition: otfgsub.hh:353
static void assign_space(Substitute &, uint8_t &, int)
Definition: otfgsub.cc:45
static bool extract_glyphs(const Substitute &, uint8_t, Vector< Glyph > &, bool coverage_ok) noexcept
Definition: otfgsub.cc:282
bool all_in_glyphs(Vector< Glyph > &gs) const
Definition: otfgsub.cc:357
static int extract_nglyphs(const Substitute &, uint8_t, bool coverage_ok) noexcept
Definition: otfgsub.cc:318
bool out_alter(const Substitution &, int) noexcept
Definition: otfgsub.cc:464
bool context_in(const Coverage &) const
Definition: otfgsub.cc:242
static void clear(Substitute &, uint8_t &)
Definition: otfgsub.cc:31
static void assign(Substitute &, uint8_t &, Glyph)
Definition: otfgsub.cc:58
Substitution in_out_append_glyph(Glyph) const
Definition: otfgsub.cc:411
void unparse(StringAccum &, const Vector< PermString > *=&debug_glyph_names) const
Definition: otfgsub.cc:519
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
int v
Definition: dviconv.c:10
struct rect data
Definition: dvipdfm.c:64
short nleft
Definition: globals.h:117
FILE * out
Definition: hbf2gf.c:286
@ T_NONE
Definition: hpcdtoppm.c:92
small capitals from c petite p scientific i
Definition: afcover.h:80
unsigned short uint16_t
Definition: stdint.h:79
unsigned char uint8_t
Definition: stdint.h:78
const int * pos
Definition: combiners.h:905
Vector< PermString > debug_glyph_names
Definition: otf.cc:32
int Glyph
Definition: otf.hh:9
StringAccum & operator<<(StringAccum &sa, const Substitution &sub)
Definition: otfgsub.hh:408
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF sub
int g
Definition: ppmqvga.c:68
#define subs(p, n, t)
Definition: interp.c:107
static FILE * in
Definition: squeeze.c:36
A string of characters.
Definition: t1part.c:49
#define limit(x)
Definition: yuvsplittoppm.c:26