[HB] Fix context_length checking
[framework/uifw/harfbuzz.git] / src / hb-ot-layout-gsubgpos-private.h
1 /*
2  * Copyright (C) 2007,2008,2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, an OpenType Layout engine library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_H
28 #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_H
29
30 #include "hb-ot-layout-gdef-private.h"
31 #include "harfbuzz-buffer-private.h" /* XXX */
32
33
34 #define LOOKUP_ARGS_DEF \
35         hb_ot_layout_t *layout, \
36         hb_buffer_t    *buffer, \
37         unsigned int    context_length HB_GNUC_UNUSED, \
38         unsigned int    nesting_level_left HB_GNUC_UNUSED, \
39         unsigned int    lookup_flag, \
40         unsigned int    property HB_GNUC_UNUSED /* propety of first glyph */
41 #define LOOKUP_ARGS \
42         layout, \
43         buffer, \
44         context_length, \
45         nesting_level_left, \
46         lookup_flag, \
47         property
48
49
50 typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data);
51 typedef bool (*apply_lookup_func_t) (LOOKUP_ARGS_DEF, unsigned int lookup_index);
52
53 struct ContextFuncs {
54   match_func_t match;
55   apply_lookup_func_t apply;
56 };
57
58
59 static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
60   return glyph_id == value;
61 }
62
63 static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
64   const ClassDef &class_def = * (const ClassDef *) data;
65   return class_def.get_class (glyph_id) == value;
66 }
67
68 static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
69   const OffsetTo<Coverage> &coverage = * (const OffsetTo<Coverage> *) &value;
70   return (data+coverage) (glyph_id) != NOT_COVERED;
71 }
72
73
74 static inline bool match_input (LOOKUP_ARGS_DEF,
75                                 unsigned int count, /* Including the first glyph (not matched) */
76                                 const USHORT input[], /* Array of input values--start with second glyph */
77                                 match_func_t match_func,
78                                 char *match_data,
79                                 unsigned int *context_length_out)
80 {
81   unsigned int i, j;
82   unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
83   if (HB_UNLIKELY (buffer->in_pos + count > end))
84     return false;
85
86   for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++) {
87     while (!_hb_ot_layout_check_glyph_property (layout, IN_ITEM (j), lookup_flag, &property)) {
88       if (HB_UNLIKELY (j + count - i == end))
89         return false;
90       j++;
91     }
92
93     if (HB_LIKELY (!match_func (IN_GLYPH(j), input[i - 1], match_data)))
94       return false;
95   }
96
97   *context_length_out = j - buffer->in_pos;
98
99   return true;
100 }
101
102 static inline bool match_backtrack (LOOKUP_ARGS_DEF,
103                                     unsigned int count,
104                                     const USHORT backtrack[],
105                                     match_func_t match_func,
106                                     char *match_data)
107 {
108   if (HB_UNLIKELY (buffer->out_pos < count))
109     return false;
110
111   for (unsigned int i = 0, j = buffer->out_pos - 1; i < count; i++, j--) {
112     while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property)) {
113       if (HB_UNLIKELY (j + 1 == count - i))
114         return false;
115       j--;
116     }
117
118     if (HB_LIKELY (!match_func (OUT_GLYPH(j), backtrack[i], match_data)))
119       return false;
120   }
121
122   return true;
123 }
124
125 static inline bool match_lookahead (LOOKUP_ARGS_DEF,
126                                     unsigned int count,
127                                     const USHORT lookahead[],
128                                     match_func_t match_func,
129                                     char *match_data,
130                                     unsigned int offset)
131 {
132   unsigned int i, j;
133   unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
134   if (HB_UNLIKELY (buffer->in_pos + offset + count > end))
135     return false;
136
137   for (i = 0, j = buffer->in_pos + offset; i < count; i++, j++) {
138     while (!_hb_ot_layout_check_glyph_property (layout, OUT_ITEM (j), lookup_flag, &property)) {
139       if (HB_UNLIKELY (j + count - i == end))
140         return false;
141       j++;
142     }
143
144     if (HB_LIKELY (!match_func (IN_GLYPH(j), lookahead[i], match_data)))
145       return false;
146   }
147
148   return true;
149 }
150
151
152 struct LookupRecord {
153
154   USHORT        sequenceIndex;          /* Index into current glyph
155                                          * sequence--first glyph = 0 */
156   USHORT        lookupListIndex;        /* Lookup to apply to that
157                                          * position--zero--based */
158 };
159 ASSERT_SIZE (LookupRecord, 4);
160
161 static inline bool apply_lookup (LOOKUP_ARGS_DEF,
162                                  unsigned int count, /* Including the first glyph */
163                                  unsigned int lookupCount,
164                                  const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
165                                  apply_lookup_func_t apply_func)
166 {
167   unsigned int record_count = lookupCount;
168   const LookupRecord *record = lookupRecord;
169
170   /* XXX We have to jump non-matching glyphs when applying too, right? */
171   /* TODO We don't support lookupRecord arrays that are not increasing:
172    *      Should be easy for in_place ones at least. */
173   for (unsigned int i = 0; i < count;)
174   {
175     if (record_count && i == record->sequenceIndex)
176     {
177       unsigned int old_pos = buffer->in_pos;
178
179       /* Apply a lookup */
180       bool done = apply_func (LOOKUP_ARGS, record->lookupListIndex);
181
182       record++;
183       record_count--;
184       i += buffer->in_pos - old_pos;
185
186       if (!done)
187         goto not_applied;
188     }
189     else
190     {
191     not_applied:
192       /* No lookup applied for this index */
193       _hb_buffer_next_glyph (buffer);
194       i++;
195     }
196   }
197
198   return true;
199 }
200
201
202 /* Contextual lookups */
203
204 struct ContextLookupContext {
205   ContextFuncs funcs;
206   char *match_data;
207 };
208
209 static inline bool context_lookup (LOOKUP_ARGS_DEF,
210                                    unsigned int inputCount, /* Including the first glyph (not matched) */
211                                    const USHORT input[], /* Array of input values--start with second glyph */
212                                    unsigned int lookupCount,
213                                    const LookupRecord lookupRecord[],
214                                    ContextLookupContext &context)
215 {
216   /* First guess */
217   if (HB_UNLIKELY (buffer->in_pos + inputCount > buffer->in_length ||
218                    context_length < inputCount))
219     return false;
220
221   return match_input (LOOKUP_ARGS,
222                       inputCount, input,
223                       context.funcs.match, context.match_data,
224                       &context_length) &&
225          apply_lookup (LOOKUP_ARGS,
226                        inputCount,
227                        lookupCount, lookupRecord,
228                        context.funcs.apply);
229 }
230
231 struct Rule {
232
233   friend struct RuleSet;
234
235   private:
236   inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const {
237     const LookupRecord *lookupRecord = (const LookupRecord *)
238                                        ((const char *) input +
239                                         sizeof (input[0]) * (inputCount ? inputCount - 1 : 0));
240     return context_lookup (LOOKUP_ARGS,
241                            inputCount,
242                            input,
243                            lookupCount,
244                            lookupRecord,
245                            context);
246   }
247
248   private:
249   USHORT        inputCount;             /* Total number of glyphs in input
250                                          * glyph sequence--includes the  first
251                                          * glyph */
252   USHORT        lookupCount;            /* Number of LookupRecords */
253   USHORT        input[];                /* Array of match inputs--start with
254                                          * second glyph */
255   LookupRecord  lookupRecordX[];        /* Array of LookupRecords--in
256                                          * design order */
257 };
258 ASSERT_SIZE (Rule, 4);
259
260 struct RuleSet {
261
262   inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const {
263
264     unsigned int num_rules = rule.len;
265     for (unsigned int i = 0; i < num_rules; i++) {
266       if ((this+rule[i]).apply (LOOKUP_ARGS, context))
267         return true;
268     }
269
270     return false;
271   }
272
273   private:
274   OffsetArrayOf<Rule>
275                 rule;                   /* Array of Rule tables
276                                          * ordered by preference */
277 };
278
279
280 struct ContextFormat1 {
281
282   friend struct Context;
283
284   private:
285   inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
286
287     unsigned int index = (this+coverage) (IN_CURGLYPH ());
288     if (G_LIKELY (index == NOT_COVERED))
289       return false;
290
291     const RuleSet &rule_set = this+ruleSet[index];
292     struct ContextLookupContext context = {
293       {match_glyph, apply_func},
294       NULL
295     };
296     return rule_set.apply (LOOKUP_ARGS, context);
297   }
298
299   private:
300   USHORT        format;                 /* Format identifier--format = 1 */
301   OffsetTo<Coverage>
302                 coverage;               /* Offset to Coverage table--from
303                                          * beginning of table */
304   OffsetArrayOf<RuleSet>
305                 ruleSet;                /* Array of RuleSet tables
306                                          * ordered by Coverage Index */
307 };
308 ASSERT_SIZE (ContextFormat1, 6);
309
310
311 struct ContextFormat2 {
312
313   friend struct Context;
314
315   private:
316   inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
317
318     unsigned int index = (this+coverage) (IN_CURGLYPH ());
319     if (G_LIKELY (index == NOT_COVERED))
320       return false;
321
322     const ClassDef &class_def = this+classDef;
323     index = class_def (IN_CURGLYPH ());
324     const RuleSet &rule_set = this+ruleSet[index];
325     /* LONGTERMTODO: Old code fetches glyph classes at most once and caches
326      * them across subrule lookups.  Not sure it's worth it.
327      */
328     struct ContextLookupContext context = {
329      {match_class, apply_func},
330       (char *) &class_def
331     };
332     return rule_set.apply (LOOKUP_ARGS, context);
333   }
334
335   private:
336   USHORT        format;                 /* Format identifier--format = 2 */
337   OffsetTo<Coverage>
338                 coverage;               /* Offset to Coverage table--from
339                                          * beginning of table */
340   OffsetTo<ClassDef>
341                 classDef;               /* Offset to glyph ClassDef table--from
342                                          * beginning of table */
343   OffsetArrayOf<RuleSet>
344                 ruleSet;                /* Array of RuleSet tables
345                                          * ordered by class */
346 };
347 ASSERT_SIZE (ContextFormat2, 8);
348
349
350 struct ContextFormat3 {
351
352   friend struct Context;
353
354   private:
355   inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
356
357     unsigned int index = (this+coverage[0]) (IN_CURGLYPH ());
358     if (G_LIKELY (index == NOT_COVERED))
359       return false;
360
361     const LookupRecord *lookupRecord = (const LookupRecord *)
362                                        ((const char *) coverage +
363                                         sizeof (coverage[0]) * glyphCount);
364     struct ContextLookupContext context = {
365       {match_coverage, apply_func},
366       (char *) this
367     };
368     return context_lookup (LOOKUP_ARGS,
369                            glyphCount,
370                            (const USHORT *) (coverage + 1),
371                            lookupCount,
372                            lookupRecord,
373                            context);
374   }
375
376   private:
377   USHORT        format;                 /* Format identifier--format = 3 */
378   USHORT        glyphCount;             /* Number of glyphs in the input glyph
379                                          * sequence */
380   USHORT        lookupCount;            /* Number of LookupRecords */
381   OffsetTo<Coverage>
382                 coverage[];             /* Array of offsets to Coverage
383                                          * table in glyph sequence order */
384   LookupRecord  lookupRecordX[];        /* Array of LookupRecords--in
385                                          * design order */
386 };
387 ASSERT_SIZE (ContextFormat3, 6);
388
389 struct Context {
390
391   protected:
392   bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
393     switch (u.format) {
394     case 1: return u.format1->apply (LOOKUP_ARGS, apply_func);
395     case 2: return u.format2->apply (LOOKUP_ARGS, apply_func);
396     case 3: return u.format3->apply (LOOKUP_ARGS, apply_func);
397     default:return false;
398     }
399   }
400
401   private:
402   union {
403   USHORT                format;         /* Format identifier */
404   ContextFormat1        format1[];
405   ContextFormat2        format2[];
406   ContextFormat3        format3[];
407   } u;
408 };
409 ASSERT_SIZE (Context, 2);
410
411
412 /* Chaining Contextual lookups */
413
414 struct ChainContextLookupContext {
415   ContextFuncs funcs;
416   char *match_data[3];
417 };
418
419 static inline bool chain_context_lookup (LOOKUP_ARGS_DEF,
420                                          unsigned int backtrackCount,
421                                          const USHORT backtrack[],
422                                          unsigned int inputCount, /* Including the first glyph (not matched) */
423                                          const USHORT input[], /* Array of input values--start with second glyph */
424                                          unsigned int lookaheadCount,
425                                          const USHORT lookahead[],
426                                          unsigned int lookupCount,
427                                          const LookupRecord lookupRecord[],
428                                          ChainContextLookupContext &context)
429 {
430   /* First guess */
431   if (HB_UNLIKELY (buffer->out_pos < backtrackCount ||
432                    buffer->in_pos + inputCount + lookaheadCount > buffer->in_length))
433     return false;
434
435   unsigned int offset;
436   return match_backtrack (LOOKUP_ARGS,
437                           backtrackCount, backtrack,
438                           context.funcs.match, context.match_data[0]) &&
439          match_input (LOOKUP_ARGS,
440                       inputCount, input,
441                       context.funcs.match, context.match_data[1],
442                       &offset) &&
443          match_lookahead (LOOKUP_ARGS,
444                           lookaheadCount, lookahead,
445                           context.funcs.match, context.match_data[2],
446                           offset) &&
447          (context_length = offset, true) &&
448          apply_lookup (LOOKUP_ARGS,
449                        inputCount,
450                        lookupCount, lookupRecord,
451                        context.funcs.apply);
452 }
453
454 struct ChainRule {
455
456   friend struct ChainRuleSet;
457
458   private:
459   inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const {
460     const HeadlessArrayOf<USHORT> &input = * (const HeadlessArrayOf<USHORT> *)
461                                              ((const char *) &backtrack + backtrack.get_size ());
462     const ArrayOf<USHORT> &lookahead = * (const ArrayOf<USHORT> *)
463                                          ((const char *) &input + input.get_size ());
464     const ArrayOf<LookupRecord> &lookup = * (const ArrayOf<LookupRecord> *)
465                                             ((const char *) &lookahead + lookahead.get_size ());
466     return chain_context_lookup (LOOKUP_ARGS,
467                                  backtrack.len,
468                                  backtrack.array,
469                                  input.len,
470                                  input.array + 1,
471                                  lookahead.len,
472                                  lookahead.array,
473                                  lookup.len,
474                                  lookup.array,
475                                  context);
476     return false;
477   }
478
479
480   private:
481   ArrayOf<USHORT>
482                 backtrack;              /* Array of backtracking values
483                                          * (to be matched before the input
484                                          * sequence) */
485   HeadlessArrayOf<USHORT>
486                 inputX;                 /* Array of input values (start with
487                                          * second glyph) */
488   ArrayOf<USHORT>
489                 lookaheadX;             /* Array of lookahead values's (to be
490                                          * matched after the input sequence) */
491   ArrayOf<LookupRecord>
492                 lookupX;                /* Array of LookupRecords--in
493                                          * design order) */
494 };
495 ASSERT_SIZE (ChainRule, 8);
496
497 struct ChainRuleSet {
498
499   inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const {
500
501     unsigned int num_rules = rule.len;
502     for (unsigned int i = 0; i < num_rules; i++) {
503       if ((this+rule[i]).apply (LOOKUP_ARGS, context))
504         return true;
505     }
506
507     return false;
508   }
509
510   private:
511   OffsetArrayOf<ChainRule>
512                 rule;                   /* Array of ChainRule tables
513                                          * ordered by preference */
514 };
515 ASSERT_SIZE (ChainRuleSet, 2);
516
517 struct ChainContextFormat1 {
518
519   friend struct ChainContext;
520
521   private:
522   inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
523
524     unsigned int index = (this+coverage) (IN_CURGLYPH ());
525     if (G_LIKELY (index == NOT_COVERED))
526       return false;
527
528     const ChainRuleSet &rule_set = this+ruleSet[index];
529     struct ChainContextLookupContext context = {
530       {match_glyph, apply_func},
531       {NULL, NULL, NULL}
532     };
533     return rule_set.apply (LOOKUP_ARGS, context);
534   }
535   private:
536   USHORT        format;                 /* Format identifier--format = 1 */
537   OffsetTo<Coverage>
538                 coverage;               /* Offset to Coverage table--from
539                                          * beginning of table */
540   OffsetArrayOf<ChainRuleSet>
541                 ruleSet;                /* Array of ChainRuleSet tables
542                                          * ordered by Coverage Index */
543 };
544 ASSERT_SIZE (ChainContextFormat1, 6);
545
546 struct ChainContextFormat2 {
547
548   friend struct ChainContext;
549
550   private:
551   inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
552
553     unsigned int index = (this+coverage) (IN_CURGLYPH ());
554     if (G_LIKELY (index == NOT_COVERED))
555       return false;
556
557     const ClassDef &backtrack_class_def = this+backtrackClassDef;
558     const ClassDef &input_class_def = this+inputClassDef;
559     const ClassDef &lookahead_class_def = this+lookaheadClassDef;
560
561     index = input_class_def (IN_CURGLYPH ());
562     const ChainRuleSet &rule_set = this+ruleSet[index];
563     /* LONGTERMTODO: Old code fetches glyph classes at most once and caches
564      * them across subrule lookups.  Not sure it's worth it.
565      */
566     struct ChainContextLookupContext context = {
567      {match_class, apply_func},
568      {(char *) &backtrack_class_def,
569       (char *) &input_class_def,
570       (char *) &lookahead_class_def}
571     };
572     return rule_set.apply (LOOKUP_ARGS, context);
573   }
574
575   private:
576   USHORT        format;                 /* Format identifier--format = 2 */
577   OffsetTo<Coverage>
578                 coverage;               /* Offset to Coverage table--from
579                                          * beginning of table */
580   OffsetTo<ClassDef>
581                 backtrackClassDef;      /* Offset to glyph ClassDef table
582                                          * containing backtrack sequence
583                                          * data--from beginning of table */
584   OffsetTo<ClassDef>
585                 inputClassDef;          /* Offset to glyph ClassDef
586                                          * table containing input sequence
587                                          * data--from beginning of table */
588   OffsetTo<ClassDef>
589                 lookaheadClassDef;      /* Offset to glyph ClassDef table
590                                          * containing lookahead sequence
591                                          * data--from beginning of table */
592   OffsetArrayOf<ChainRuleSet>
593                 ruleSet;                /* Array of ChainRuleSet tables
594                                          * ordered by class */
595 };
596 ASSERT_SIZE (ChainContextFormat2, 12);
597
598 struct ChainContextFormat3 {
599
600   friend struct ChainContext;
601
602   private:
603
604   inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
605   }
606
607   inline bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
608
609     const OffsetArrayOf<Coverage> &input = * (const OffsetArrayOf<Coverage> *)
610                                              ((const char *) &backtrack + backtrack.get_size ());
611
612     unsigned int index = (this+input[0]) (IN_CURGLYPH ());
613     if (G_LIKELY (index == NOT_COVERED))
614       return false;
615
616     const OffsetArrayOf<Coverage> &lookahead = * (const OffsetArrayOf<Coverage> *)
617                                          ((const char *) &input + input.get_size ());
618     const ArrayOf<LookupRecord> &lookup = * (const ArrayOf<LookupRecord> *)
619                                             ((const char *) &lookahead + lookahead.get_size ());
620     struct ChainContextLookupContext context = {
621       {match_coverage, apply_func},
622       {(char *) this, (char *) this, (char *) this}
623     };
624     return chain_context_lookup (LOOKUP_ARGS,
625                                  backtrack.len,
626                                  (USHORT *) backtrack.array,
627                                  input.len,
628                                  (USHORT *) input.array,
629                                  lookahead.len,
630                                  (USHORT *) lookahead.array,
631                                  lookup.len,
632                                  lookup.array,
633                                  context);
634     return false;
635   }
636
637   private:
638   USHORT        format;                 /* Format identifier--format = 3 */
639   OffsetArrayOf<Coverage>
640                 backtrack;              /* Array of coverage tables
641                                          * in backtracking sequence, in  glyph
642                                          * sequence order */
643   OffsetArrayOf<Coverage>
644                 inputX          ;       /* Array of coverage
645                                          * tables in input sequence, in glyph
646                                          * sequence order */
647   OffsetArrayOf<Coverage>
648                 lookaheadX;             /* Array of coverage tables
649                                          * in lookahead sequence, in glyph
650                                          * sequence order */
651   ArrayOf<LookupRecord>
652                 lookupX;                /* Array of LookupRecords--in
653                                          * design order) */
654 };
655 ASSERT_SIZE (ChainContextFormat3, 10);
656
657 struct ChainContext {
658
659   protected:
660   bool apply (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
661     switch (u.format) {
662     case 1: return u.format1->apply (LOOKUP_ARGS, apply_func);
663     case 2: return u.format2->apply (LOOKUP_ARGS, apply_func);
664     case 3: return u.format3->apply (LOOKUP_ARGS, apply_func);
665     default:return false;
666     }
667   }
668
669   private:
670   union {
671   USHORT                format; /* Format identifier */
672   ChainContextFormat1   format1[];
673   ChainContextFormat2   format2[];
674   ChainContextFormat3   format3[];
675   } u;
676 };
677 ASSERT_SIZE (ChainContext, 2);
678
679
680 /*
681  * GSUB/GPOS Common
682  */
683
684 struct GSUBGPOS {
685   static const hb_tag_t GSUBTag         = HB_TAG ('G','S','U','B');
686   static const hb_tag_t GPOSTag         = HB_TAG ('G','P','O','S');
687
688   STATIC_DEFINE_GET_FOR_DATA (GSUBGPOS);
689   /* XXX check version here? */
690
691   DEFINE_TAG_LIST_INTERFACE (Script,  script ); /* get_script_count (), get_script (i), get_script_tag (i) */
692   DEFINE_TAG_LIST_INTERFACE (Feature, feature); /* get_feature_count(), get_feature(i), get_feature_tag(i) */
693   DEFINE_LIST_INTERFACE     (Lookup,  lookup ); /* get_lookup_count (), get_lookup (i) */
694
695   // LONGTERMTODO bsearch
696   DEFINE_TAG_FIND_INTERFACE (Script,  script ); /* find_script_index (), get_script_by_tag (tag) */
697   DEFINE_TAG_FIND_INTERFACE (Feature, feature); /* find_feature_index(), get_feature_by_tag(tag) */
698
699   private:
700   Fixed_Version version;        /* Version of the GSUB/GPOS table--initially set
701                                  * to 0x00010000 */
702   OffsetTo<ScriptList>
703                 scriptList;     /* ScriptList table */
704   OffsetTo<FeatureList>
705                 featureList;    /* FeatureList table */
706   OffsetTo<LookupList>
707                 lookupList;     /* LookupList table */
708 };
709 ASSERT_SIZE (GSUBGPOS, 10);
710
711
712 #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_H */