2 * Copyright (C) 2007,2008,2009 Red Hat, Inc.
4 * This is part of HarfBuzz, an OpenType Layout engine library.
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.
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
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.
24 * Red Hat Author(s): Behdad Esfahbod
27 #ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
28 #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
30 #include "hb-buffer-private.h"
31 #include "hb-ot-layout-gdef-private.hh"
34 #ifndef HB_DEBUG_APPLY
35 #define HB_DEBUG_APPLY HB_DEBUG
39 #define TRACE_APPLY_ARG_DEF , unsigned int apply_depth
40 #define TRACE_APPLY_ARG , apply_depth + 1
41 #define TRACE_APPLY_ARG_INIT , 1
42 #define TRACE_APPLY() \
44 if (apply_depth < HB_DEBUG_APPLY) \
45 fprintf (stderr, "APPLY(%p) %-*d-> %s\n", \
46 (CONST_CHARP (this) == NullPool) ? 0 : this, \
47 apply_depth, apply_depth, \
48 __PRETTY_FUNCTION__); \
51 #define TRACE_APPLY_ARG_DEF
52 #define TRACE_APPLY_ARG
53 #define TRACE_APPLY_ARG_INIT
54 #define TRACE_APPLY() HB_STMT_START {} HB_STMT_END
57 #define APPLY_ARG_DEF \
58 hb_ot_layout_context_t *context, \
59 hb_buffer_t *buffer, \
60 unsigned int context_length HB_GNUC_UNUSED, \
61 unsigned int nesting_level_left HB_GNUC_UNUSED, \
62 unsigned int lookup_flag, \
63 unsigned int property HB_GNUC_UNUSED /* propety of first glyph */ \
73 #define APPLY_ARG_INIT \
83 typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data);
84 typedef bool (*apply_lookup_func_t) (APPLY_ARG_DEF, unsigned int lookup_index);
89 apply_lookup_func_t apply;
93 static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data)
95 return glyph_id == value;
98 static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data)
100 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
101 return class_def.get_class (glyph_id) == value;
104 static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data)
106 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
107 return (data+coverage) (glyph_id) != NOT_COVERED;
111 static inline bool match_input (APPLY_ARG_DEF,
112 unsigned int count, /* Including the first glyph (not matched) */
113 const USHORT input[], /* Array of input values--start with second glyph */
114 match_func_t match_func,
116 unsigned int *context_length_out)
119 unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
120 if (HB_UNLIKELY (buffer->in_pos + count > end))
123 for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++)
125 while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, NULL))
127 if (HB_UNLIKELY (j + count - i == end))
132 if (HB_LIKELY (!match_func (IN_GLYPH (j), input[i - 1], match_data)))
136 *context_length_out = j - buffer->in_pos;
141 static inline bool match_backtrack (APPLY_ARG_DEF,
143 const USHORT backtrack[],
144 match_func_t match_func,
147 if (HB_UNLIKELY (buffer->out_pos < count))
150 for (unsigned int i = 0, j = buffer->out_pos - 1; i < count; i++, j--)
152 while (_hb_ot_layout_skip_mark (context->face, OUT_INFO (j), lookup_flag, NULL))
154 if (HB_UNLIKELY (j + 1 == count - i))
159 if (HB_LIKELY (!match_func (OUT_GLYPH (j), backtrack[i], match_data)))
166 static inline bool match_lookahead (APPLY_ARG_DEF,
168 const USHORT lookahead[],
169 match_func_t match_func,
174 unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
175 if (HB_UNLIKELY (buffer->in_pos + offset + count > end))
178 for (i = 0, j = buffer->in_pos + offset; i < count; i++, j++)
180 while (_hb_ot_layout_skip_mark (context->face, OUT_INFO (j), lookup_flag, NULL))
182 if (HB_UNLIKELY (j + count - i == end))
187 if (HB_LIKELY (!match_func (IN_GLYPH (j), lookahead[i], match_data)))
198 inline bool sanitize (SANITIZE_ARG_DEF) {
200 return SANITIZE_SELF ();
203 USHORT sequenceIndex; /* Index into current glyph
204 * sequence--first glyph = 0 */
205 USHORT lookupListIndex; /* Lookup to apply to that
206 * position--zero--based */
208 ASSERT_SIZE (LookupRecord, 4);
210 static inline bool apply_lookup (APPLY_ARG_DEF,
211 unsigned int count, /* Including the first glyph */
212 unsigned int lookupCount,
213 const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
214 apply_lookup_func_t apply_func)
216 unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length);
217 if (HB_UNLIKELY (buffer->in_pos + count > end))
220 /* TODO We don't support lookupRecord arrays that are not increasing:
221 * Should be easy for in_place ones at least. */
223 /* Note: If sublookup is reverse, i will underflow after the first loop
224 * and we jump out of it. Not entirely disastrous. So we don't check
225 * for reverse lookup here.
227 for (unsigned int i = 0; i < count; /* NOP */)
229 while (_hb_ot_layout_skip_mark (context->face, IN_CURINFO (), lookup_flag, NULL))
231 if (HB_UNLIKELY (buffer->in_pos == end))
233 /* No lookup applied for this index */
234 _hb_buffer_next_glyph (buffer);
237 if (lookupCount && i == lookupRecord->sequenceIndex)
239 unsigned int old_pos = buffer->in_pos;
242 bool done = apply_func (APPLY_ARG, lookupRecord->lookupListIndex);
246 /* Err, this is wrong if the lookup jumped over some glyphs */
247 i += buffer->in_pos - old_pos;
248 if (HB_UNLIKELY (buffer->in_pos == end))
257 /* No lookup applied for this index */
258 _hb_buffer_next_glyph (buffer);
267 /* Contextual lookups */
269 struct ContextLookupContext
275 static inline bool context_lookup (APPLY_ARG_DEF,
276 unsigned int inputCount, /* Including the first glyph (not matched) */
277 const USHORT input[], /* Array of input values--start with second glyph */
278 unsigned int lookupCount,
279 const LookupRecord lookupRecord[],
280 ContextLookupContext &lookup_context)
282 return match_input (APPLY_ARG,
284 lookup_context.funcs.match, lookup_context.match_data,
286 apply_lookup (APPLY_ARG,
288 lookupCount, lookupRecord,
289 lookup_context.funcs.apply);
294 friend struct RuleSet;
297 inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const
300 const LookupRecord *lookupRecord = &CONST_CAST (LookupRecord, input, sizeof (input[0]) * (inputCount ? inputCount - 1 : 0));
301 return context_lookup (APPLY_ARG,
303 lookupCount, lookupRecord,
308 inline bool sanitize (SANITIZE_ARG_DEF) {
310 if (!SANITIZE_SELF ()) return false;
311 return SANITIZE_MEM (input,
312 sizeof (input[0]) * inputCount +
313 sizeof (lookupRecordX[0]) * lookupCount);
317 USHORT inputCount; /* Total number of glyphs in input
318 * glyph sequence--includes the first
320 USHORT lookupCount; /* Number of LookupRecords */
321 USHORT input[]; /* Array of match inputs--start with
323 LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
326 ASSERT_SIZE (Rule, 4);
330 inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const
333 unsigned int num_rules = rule.len;
334 for (unsigned int i = 0; i < num_rules; i++)
336 if ((this+rule[i]).apply (APPLY_ARG, lookup_context))
343 inline bool sanitize (SANITIZE_ARG_DEF) {
345 return SANITIZE_THIS (rule);
350 rule; /* Array of Rule tables
351 * ordered by preference */
355 struct ContextFormat1
357 friend struct Context;
360 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
363 unsigned int index = (this+coverage) (IN_CURGLYPH ());
364 if (HB_LIKELY (index == NOT_COVERED))
367 const RuleSet &rule_set = this+ruleSet[index];
368 struct ContextLookupContext lookup_context = {
369 {match_glyph, apply_func},
372 return rule_set.apply (APPLY_ARG, lookup_context);
375 inline bool sanitize (SANITIZE_ARG_DEF) {
377 return SANITIZE_THIS2 (coverage, ruleSet);
381 USHORT format; /* Format identifier--format = 1 */
383 coverage; /* Offset to Coverage table--from
384 * beginning of table */
385 OffsetArrayOf<RuleSet>
386 ruleSet; /* Array of RuleSet tables
387 * ordered by Coverage Index */
389 ASSERT_SIZE (ContextFormat1, 6);
392 struct ContextFormat2
394 friend struct Context;
397 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
400 unsigned int index = (this+coverage) (IN_CURGLYPH ());
401 if (HB_LIKELY (index == NOT_COVERED))
404 const ClassDef &class_def = this+classDef;
405 index = class_def (IN_CURGLYPH ());
406 const RuleSet &rule_set = this+ruleSet[index];
407 /* LONGTERMTODO: Old code fetches glyph classes at most once and caches
408 * them across subrule lookups. Not sure it's worth it.
410 struct ContextLookupContext lookup_context = {
411 {match_class, apply_func},
412 DECONST_CHARP(&class_def)
414 return rule_set.apply (APPLY_ARG, lookup_context);
417 inline bool sanitize (SANITIZE_ARG_DEF) {
419 return SANITIZE_THIS3 (coverage, classDef, ruleSet);
423 USHORT format; /* Format identifier--format = 2 */
425 coverage; /* Offset to Coverage table--from
426 * beginning of table */
428 classDef; /* Offset to glyph ClassDef table--from
429 * beginning of table */
430 OffsetArrayOf<RuleSet>
431 ruleSet; /* Array of RuleSet tables
432 * ordered by class */
434 ASSERT_SIZE (ContextFormat2, 8);
437 struct ContextFormat3
439 friend struct Context;
442 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
445 unsigned int index = (this+coverage[0]) (IN_CURGLYPH ());
446 if (HB_LIKELY (index == NOT_COVERED))
449 const LookupRecord *lookupRecord = &CONST_CAST(LookupRecord, coverage, sizeof (coverage[0]) * glyphCount);
450 struct ContextLookupContext lookup_context = {
451 {match_coverage, apply_func},
454 return context_lookup (APPLY_ARG,
455 glyphCount, (const USHORT *) (coverage + 1),
456 lookupCount, lookupRecord,
460 inline bool sanitize (SANITIZE_ARG_DEF) {
462 if (!SANITIZE_SELF ()) return false;
463 unsigned int count = glyphCount;
464 for (unsigned int i = 0; i < count; i++)
465 if (!SANITIZE_THIS (coverage[i])) return false;
466 LookupRecord *lookupRecord = &CAST(LookupRecord, coverage, sizeof (coverage[0]) * glyphCount);
467 return SANITIZE_MEM (lookupRecord, sizeof (lookupRecord[0]) * lookupCount);
471 USHORT format; /* Format identifier--format = 3 */
472 USHORT glyphCount; /* Number of glyphs in the input glyph
474 USHORT lookupCount; /* Number of LookupRecords */
476 coverage[]; /* Array of offsets to Coverage
477 * table in glyph sequence order */
478 LookupRecord lookupRecordX[]; /* Array of LookupRecords--in
481 ASSERT_SIZE (ContextFormat3, 6);
486 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
490 case 1: return u.format1->apply (APPLY_ARG, apply_func);
491 case 2: return u.format2->apply (APPLY_ARG, apply_func);
492 case 3: return u.format3->apply (APPLY_ARG, apply_func);
493 default:return false;
497 inline bool sanitize (SANITIZE_ARG_DEF) {
499 if (!SANITIZE (u.format)) return false;
501 case 1: return u.format1->sanitize (SANITIZE_ARG);
502 case 2: return u.format2->sanitize (SANITIZE_ARG);
503 case 3: return u.format3->sanitize (SANITIZE_ARG);
510 USHORT format; /* Format identifier */
511 ContextFormat1 format1[];
512 ContextFormat2 format2[];
513 ContextFormat3 format3[];
516 ASSERT_SIZE (Context, 2);
519 /* Chaining Contextual lookups */
521 struct ChainContextLookupContext
527 static inline bool chain_context_lookup (APPLY_ARG_DEF,
528 unsigned int backtrackCount,
529 const USHORT backtrack[],
530 unsigned int inputCount, /* Including the first glyph (not matched) */
531 const USHORT input[], /* Array of input values--start with second glyph */
532 unsigned int lookaheadCount,
533 const USHORT lookahead[],
534 unsigned int lookupCount,
535 const LookupRecord lookupRecord[],
536 ChainContextLookupContext &lookup_context)
539 if (HB_UNLIKELY (buffer->out_pos < backtrackCount ||
540 buffer->in_pos + inputCount + lookaheadCount > buffer->in_length ||
541 inputCount + lookaheadCount > context_length))
545 return match_backtrack (APPLY_ARG,
546 backtrackCount, backtrack,
547 lookup_context.funcs.match, lookup_context.match_data[0]) &&
548 match_input (APPLY_ARG,
550 lookup_context.funcs.match, lookup_context.match_data[1],
552 match_lookahead (APPLY_ARG,
553 lookaheadCount, lookahead,
554 lookup_context.funcs.match, lookup_context.match_data[2],
556 (context_length = offset, true) &&
557 apply_lookup (APPLY_ARG,
559 lookupCount, lookupRecord,
560 lookup_context.funcs.apply);
565 friend struct ChainRuleSet;
568 inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const
571 const HeadlessArrayOf<USHORT> &input = CONST_NEXT (HeadlessArrayOf<USHORT>, backtrack);
572 const ArrayOf<USHORT> &lookahead = CONST_NEXT (ArrayOf<USHORT>, input);
573 const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead);
574 return chain_context_lookup (APPLY_ARG,
575 backtrack.len, backtrack.array,
576 input.len, input.array,
577 lookahead.len, lookahead.array,
578 lookup.len, lookup.array,
584 inline bool sanitize (SANITIZE_ARG_DEF) {
586 if (!SANITIZE (backtrack)) return false;
587 HeadlessArrayOf<USHORT> &input = NEXT (HeadlessArrayOf<USHORT>, backtrack);
588 if (!SANITIZE (input)) return false;
589 ArrayOf<USHORT> &lookahead = NEXT (ArrayOf<USHORT>, input);
590 if (!SANITIZE (lookahead)) return false;
591 ArrayOf<LookupRecord> &lookup = NEXT (ArrayOf<LookupRecord>, lookahead);
592 return SANITIZE (lookup);
597 backtrack; /* Array of backtracking values
598 * (to be matched before the input
600 HeadlessArrayOf<USHORT>
601 inputX; /* Array of input values (start with
604 lookaheadX; /* Array of lookahead values's (to be
605 * matched after the input sequence) */
606 ArrayOf<LookupRecord>
607 lookupX; /* Array of LookupRecords--in
610 ASSERT_SIZE (ChainRule, 8);
614 inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const
617 unsigned int num_rules = rule.len;
618 for (unsigned int i = 0; i < num_rules; i++)
620 if ((this+rule[i]).apply (APPLY_ARG, lookup_context))
627 inline bool sanitize (SANITIZE_ARG_DEF) {
629 return SANITIZE_THIS (rule);
633 OffsetArrayOf<ChainRule>
634 rule; /* Array of ChainRule tables
635 * ordered by preference */
637 ASSERT_SIZE (ChainRuleSet, 2);
639 struct ChainContextFormat1
641 friend struct ChainContext;
644 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
647 unsigned int index = (this+coverage) (IN_CURGLYPH ());
648 if (HB_LIKELY (index == NOT_COVERED))
651 const ChainRuleSet &rule_set = this+ruleSet[index];
652 struct ChainContextLookupContext lookup_context = {
653 {match_glyph, apply_func},
656 return rule_set.apply (APPLY_ARG, lookup_context);
659 inline bool sanitize (SANITIZE_ARG_DEF) {
661 return SANITIZE_THIS2 (coverage, ruleSet);
665 USHORT format; /* Format identifier--format = 1 */
667 coverage; /* Offset to Coverage table--from
668 * beginning of table */
669 OffsetArrayOf<ChainRuleSet>
670 ruleSet; /* Array of ChainRuleSet tables
671 * ordered by Coverage Index */
673 ASSERT_SIZE (ChainContextFormat1, 6);
675 struct ChainContextFormat2
677 friend struct ChainContext;
680 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
683 unsigned int index = (this+coverage) (IN_CURGLYPH ());
684 if (HB_LIKELY (index == NOT_COVERED))
687 const ClassDef &backtrack_class_def = this+backtrackClassDef;
688 const ClassDef &input_class_def = this+inputClassDef;
689 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
691 index = input_class_def (IN_CURGLYPH ());
692 const ChainRuleSet &rule_set = this+ruleSet[index];
693 /* LONGTERMTODO: Old code fetches glyph classes at most once and caches
694 * them across subrule lookups. Not sure it's worth it.
696 struct ChainContextLookupContext lookup_context = {
697 {match_class, apply_func},
698 {DECONST_CHARP(&backtrack_class_def),
699 DECONST_CHARP(&input_class_def),
700 DECONST_CHARP(&lookahead_class_def)}
702 return rule_set.apply (APPLY_ARG, lookup_context);
705 inline bool sanitize (SANITIZE_ARG_DEF) {
707 return SANITIZE_THIS2 (coverage, backtrackClassDef) &&
708 SANITIZE_THIS2 (inputClassDef, lookaheadClassDef) &&
709 SANITIZE_THIS (ruleSet);
713 USHORT format; /* Format identifier--format = 2 */
715 coverage; /* Offset to Coverage table--from
716 * beginning of table */
718 backtrackClassDef; /* Offset to glyph ClassDef table
719 * containing backtrack sequence
720 * data--from beginning of table */
722 inputClassDef; /* Offset to glyph ClassDef
723 * table containing input sequence
724 * data--from beginning of table */
726 lookaheadClassDef; /* Offset to glyph ClassDef table
727 * containing lookahead sequence
728 * data--from beginning of table */
729 OffsetArrayOf<ChainRuleSet>
730 ruleSet; /* Array of ChainRuleSet tables
731 * ordered by class */
733 ASSERT_SIZE (ChainContextFormat2, 12);
735 struct ChainContextFormat3
737 friend struct ChainContext;
741 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
744 const OffsetArrayOf<Coverage> &input = CONST_NEXT (OffsetArrayOf<Coverage>, backtrack);
746 unsigned int index = (this+input[0]) (IN_CURGLYPH ());
747 if (HB_LIKELY (index == NOT_COVERED))
750 const OffsetArrayOf<Coverage> &lookahead = CONST_NEXT (OffsetArrayOf<Coverage>, input);
751 const ArrayOf<LookupRecord> &lookup = CONST_NEXT (ArrayOf<LookupRecord>, lookahead);
752 struct ChainContextLookupContext lookup_context = {
753 {match_coverage, apply_func},
754 {DECONST_CHARP(this), DECONST_CHARP(this), DECONST_CHARP(this)}
756 return chain_context_lookup (APPLY_ARG,
757 backtrack.len, (USHORT *) backtrack.array,
758 input.len, (USHORT *) input.array + 1,
759 lookahead.len, (USHORT *) lookahead.array,
760 lookup.len, lookup.array,
765 inline bool sanitize (SANITIZE_ARG_DEF) {
767 if (!SANITIZE_THIS (backtrack)) return false;
768 OffsetArrayOf<Coverage> &input = NEXT (OffsetArrayOf<Coverage>, backtrack);
769 if (!SANITIZE_THIS (input)) return false;
770 OffsetArrayOf<Coverage> &lookahead = NEXT (OffsetArrayOf<Coverage>, input);
771 if (!SANITIZE_THIS (lookahead)) return false;
772 ArrayOf<LookupRecord> &lookup = NEXT (ArrayOf<LookupRecord>, lookahead);
773 return SANITIZE (lookup);
777 USHORT format; /* Format identifier--format = 3 */
778 OffsetArrayOf<Coverage>
779 backtrack; /* Array of coverage tables
780 * in backtracking sequence, in glyph
782 OffsetArrayOf<Coverage>
783 inputX ; /* Array of coverage
784 * tables in input sequence, in glyph
786 OffsetArrayOf<Coverage>
787 lookaheadX; /* Array of coverage tables
788 * in lookahead sequence, in glyph
790 ArrayOf<LookupRecord>
791 lookupX; /* Array of LookupRecords--in
794 ASSERT_SIZE (ChainContextFormat3, 10);
799 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const
803 case 1: return u.format1->apply (APPLY_ARG, apply_func);
804 case 2: return u.format2->apply (APPLY_ARG, apply_func);
805 case 3: return u.format3->apply (APPLY_ARG, apply_func);
806 default:return false;
810 inline bool sanitize (SANITIZE_ARG_DEF) {
812 if (!SANITIZE (u.format)) return false;
814 case 1: return u.format1->sanitize (SANITIZE_ARG);
815 case 2: return u.format2->sanitize (SANITIZE_ARG);
816 case 3: return u.format3->sanitize (SANITIZE_ARG);
823 USHORT format; /* Format identifier */
824 ChainContextFormat1 format1[];
825 ChainContextFormat2 format2[];
826 ChainContextFormat3 format3[];
829 ASSERT_SIZE (ChainContext, 2);
832 struct ExtensionFormat1
834 friend struct Extension;
837 inline unsigned int get_type (void) const { return extensionLookupType; }
838 inline unsigned int get_offset (void) const { return (extensionOffset[0] << 16) + extensionOffset[1]; }
839 inline const LookupSubTable& get_subtable (void) const
841 unsigned int offset = get_offset ();
842 if (HB_UNLIKELY (!offset)) return Null(LookupSubTable);
843 return CONST_CAST (LookupSubTable, *this, offset);
846 inline bool sanitize (SANITIZE_ARG_DEF) {
848 return SANITIZE_SELF ();
852 USHORT format; /* Format identifier. Set to 1. */
853 USHORT extensionLookupType; /* Lookup type of subtable referenced
854 * by ExtensionOffset (i.e. the
855 * extension subtable). */
856 USHORT extensionOffset[2]; /* Offset to the extension subtable,
857 * of lookup type subtable.
858 * Defined as two shorts to avoid
859 * alignment requirements. */
861 ASSERT_SIZE (ExtensionFormat1, 8);
865 inline unsigned int get_type (void) const
868 case 1: return u.format1->get_type ();
872 inline const LookupSubTable& get_subtable (void) const
875 case 1: return u.format1->get_subtable ();
876 default:return Null(LookupSubTable);
880 inline bool sanitize (SANITIZE_ARG_DEF) {
882 if (!SANITIZE (u.format)) return false;
884 case 1: return u.format1->sanitize (SANITIZE_ARG);
891 USHORT format; /* Format identifier */
892 ExtensionFormat1 format1[];
895 ASSERT_SIZE (Extension, 2);
904 static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB;
905 static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS;
907 STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GSUBGPOS, 1, 1);
909 inline unsigned int get_script_count (void) const
910 { return (this+scriptList).len; }
911 inline const Tag& get_script_tag (unsigned int i) const
912 { return (this+scriptList).get_tag (i); }
913 inline bool get_script_tags (unsigned int *script_count /* IN/OUT */,
914 hb_tag_t *script_tags /* OUT */) const
915 { return (this+scriptList).get_tags (script_count, script_tags); }
916 inline const Script& get_script (unsigned int i) const
917 { return (this+scriptList)[i]; }
918 inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
919 { return (this+scriptList).find_index (tag, index); }
921 inline unsigned int get_feature_count (void) const
922 { return (this+featureList).len; }
923 inline const Tag& get_feature_tag (unsigned int i) const
924 { return (this+featureList).get_tag (i); }
925 inline bool get_feature_tags (unsigned int *feature_count /* IN/OUT */,
926 hb_tag_t *feature_tags /* OUT */) const
927 { return (this+featureList).get_tags (feature_count, feature_tags); }
928 inline const Feature& get_feature (unsigned int i) const
929 { return (this+featureList)[i]; }
930 inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const
931 { return (this+featureList).find_index (tag, index); }
933 inline unsigned int get_lookup_count (void) const
934 { return (this+lookupList).len; }
935 inline const Lookup& get_lookup (unsigned int i) const
936 { return (this+lookupList)[i]; }
938 inline bool sanitize (SANITIZE_ARG_DEF) {
940 if (!SANITIZE (version)) return false;
941 if (version.major != 1) return true;
942 return SANITIZE_THIS3 (scriptList, featureList, lookupList);
946 FixedVersion version; /* Version of the GSUB/GPOS table--initially set
949 scriptList; /* ScriptList table */
950 OffsetTo<FeatureList>
951 featureList; /* FeatureList table */
953 lookupList; /* LookupList table */
955 ASSERT_SIZE (GSUBGPOS, 10);
958 #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */