2 * Copyright © 2007,2008,2009,2010 Red Hat, Inc.
3 * Copyright © 2010,2012 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
30 #define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
32 #include "hb-buffer-private.hh"
33 #include "hb-ot-layout-gdef-table.hh"
34 #include "hb-set-private.hh"
40 #ifndef HB_DEBUG_CLOSURE
41 #define HB_DEBUG_CLOSURE (HB_DEBUG+0)
44 #define TRACE_CLOSURE(this) \
45 hb_auto_trace_t<HB_DEBUG_CLOSURE, hb_void_t> trace \
46 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
49 struct hb_closure_context_t :
50 hb_dispatch_context_t<hb_closure_context_t, hb_void_t, HB_DEBUG_CLOSURE>
52 inline const char *get_name (void) { return "CLOSURE"; }
53 typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index);
55 inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; }
56 static return_t default_return_value (void) { return HB_VOID; }
57 bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
58 return_t recurse (unsigned int lookup_index)
60 if (unlikely (nesting_level_left == 0 || !recurse_func))
61 return default_return_value ();
64 recurse_func (this, lookup_index);
71 recurse_func_t recurse_func;
72 unsigned int nesting_level_left;
73 unsigned int debug_depth;
75 hb_closure_context_t (hb_face_t *face_,
77 unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
81 nesting_level_left (nesting_level_left_),
84 void set_recurse_func (recurse_func_t func) { recurse_func = func; }
89 #ifndef HB_DEBUG_WOULD_APPLY
90 #define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0)
93 #define TRACE_WOULD_APPLY(this) \
94 hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \
95 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
98 struct hb_would_apply_context_t :
99 hb_dispatch_context_t<hb_would_apply_context_t, bool, HB_DEBUG_WOULD_APPLY>
101 inline const char *get_name (void) { return "WOULD_APPLY"; }
102 template <typename T>
103 inline return_t dispatch (const T &obj) { return obj.would_apply (this); }
104 static return_t default_return_value (void) { return false; }
105 bool stop_sublookup_iteration (return_t r) const { return r; }
108 const hb_codepoint_t *glyphs;
111 unsigned int debug_depth;
113 hb_would_apply_context_t (hb_face_t *face_,
114 const hb_codepoint_t *glyphs_,
116 bool zero_context_) :
120 zero_context (zero_context_),
126 #ifndef HB_DEBUG_COLLECT_GLYPHS
127 #define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0)
130 #define TRACE_COLLECT_GLYPHS(this) \
131 hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, hb_void_t> trace \
132 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
135 struct hb_collect_glyphs_context_t :
136 hb_dispatch_context_t<hb_collect_glyphs_context_t, hb_void_t, HB_DEBUG_COLLECT_GLYPHS>
138 inline const char *get_name (void) { return "COLLECT_GLYPHS"; }
139 typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index);
140 template <typename T>
141 inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; }
142 static return_t default_return_value (void) { return HB_VOID; }
143 bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
144 return_t recurse (unsigned int lookup_index)
146 if (unlikely (nesting_level_left == 0 || !recurse_func))
147 return default_return_value ();
149 /* Note that GPOS sets recurse_func to NULL already, so it doesn't get
150 * past the previous check. For GSUB, we only want to collect the output
151 * glyphs in the recursion. If output is not requested, we can go home now.
153 * Note further, that the above is not exactly correct. A recursed lookup
154 * is allowed to match input that is not matched in the context, but that's
155 * not how most fonts are built. It's possible to relax that and recurse
156 * with all sets here if it proves to be an issue.
159 if (output == hb_set_get_empty ())
162 /* Return if new lookup was recursed to before. */
163 if (recursed_lookups.has (lookup_index))
166 hb_set_t *old_before = before;
167 hb_set_t *old_input = input;
168 hb_set_t *old_after = after;
169 before = input = after = hb_set_get_empty ();
171 nesting_level_left--;
172 recurse_func (this, lookup_index);
173 nesting_level_left++;
179 recursed_lookups.add (lookup_index);
189 recurse_func_t recurse_func;
190 hb_set_t recursed_lookups;
191 unsigned int nesting_level_left;
192 unsigned int debug_depth;
194 hb_collect_glyphs_context_t (hb_face_t *face_,
195 hb_set_t *glyphs_before, /* OUT. May be NULL */
196 hb_set_t *glyphs_input, /* OUT. May be NULL */
197 hb_set_t *glyphs_after, /* OUT. May be NULL */
198 hb_set_t *glyphs_output, /* OUT. May be NULL */
199 unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
201 before (glyphs_before ? glyphs_before : hb_set_get_empty ()),
202 input (glyphs_input ? glyphs_input : hb_set_get_empty ()),
203 after (glyphs_after ? glyphs_after : hb_set_get_empty ()),
204 output (glyphs_output ? glyphs_output : hb_set_get_empty ()),
207 nesting_level_left (nesting_level_left_),
210 recursed_lookups.init ();
212 ~hb_collect_glyphs_context_t (void)
214 recursed_lookups.fini ();
217 void set_recurse_func (recurse_func_t func) { recurse_func = func; }
222 #ifndef HB_DEBUG_GET_COVERAGE
223 #define HB_DEBUG_GET_COVERAGE (HB_DEBUG+0)
226 /* XXX Can we remove this? */
228 template <typename set_t>
229 struct hb_add_coverage_context_t :
230 hb_dispatch_context_t<hb_add_coverage_context_t<set_t>, const Coverage &, HB_DEBUG_GET_COVERAGE>
232 inline const char *get_name (void) { return "GET_COVERAGE"; }
233 typedef const Coverage &return_t;
234 template <typename T>
235 inline return_t dispatch (const T &obj) { return obj.get_coverage (); }
236 static return_t default_return_value (void) { return Null(Coverage); }
237 bool stop_sublookup_iteration (return_t r) const
239 r.add_coverage (set);
243 hb_add_coverage_context_t (set_t *set_) :
248 unsigned int debug_depth;
253 #ifndef HB_DEBUG_APPLY
254 #define HB_DEBUG_APPLY (HB_DEBUG+0)
257 #define TRACE_APPLY(this) \
258 hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \
259 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
260 "idx %d gid %u lookup %d", \
261 c->buffer->idx, c->buffer->cur().codepoint, (int) c->lookup_index);
263 struct hb_apply_context_t :
264 hb_dispatch_context_t<hb_apply_context_t, bool, HB_DEBUG_APPLY>
268 inline matcher_t (void) :
273 #define arg1(arg) (arg) /* Remove the macro to see why it's needed! */
277 match_data (NULL) {};
279 typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data);
281 inline void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; }
282 inline void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; }
283 inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
284 inline void set_mask (hb_mask_t mask_) { mask = mask_; }
285 inline void set_syllable (uint8_t syllable_) { syllable = syllable_; }
286 inline void set_match_func (match_func_t match_func_,
287 const void *match_data_)
288 { match_func = match_func_; match_data = match_data_; }
296 inline may_match_t may_match (const hb_glyph_info_t &info,
297 const USHORT *glyph_data) const
299 if (!(info.mask & mask) ||
300 (syllable && syllable != info.syllable ()))
304 return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO;
316 may_skip (const hb_apply_context_t *c,
317 const hb_glyph_info_t &info) const
319 if (!c->check_glyph_property (&info, lookup_props))
322 if (unlikely (_hb_glyph_info_is_default_ignorable_and_not_fvs (&info) &&
323 (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) &&
324 (ignore_zwj || !_hb_glyph_info_is_zwj (&info))))
331 unsigned int lookup_props;
336 match_func_t match_func;
337 const void *match_data;
340 struct skipping_iterator_t
342 inline void init (hb_apply_context_t *c_, bool context_match = false)
345 match_glyph_data = NULL;
346 matcher.set_match_func (NULL, NULL);
347 matcher.set_lookup_props (c->lookup_props);
348 /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
349 matcher.set_ignore_zwnj (context_match || c->table_index == 1);
350 /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */
351 matcher.set_ignore_zwj (context_match || c->table_index == 1 || c->auto_zwj);
352 matcher.set_mask (context_match ? -1 : c->lookup_mask);
354 inline void set_lookup_props (unsigned int lookup_props)
356 matcher.set_lookup_props (lookup_props);
358 inline void set_match_func (matcher_t::match_func_t match_func_,
359 const void *match_data_,
360 const USHORT glyph_data[])
362 matcher.set_match_func (match_func_, match_data_);
363 match_glyph_data = glyph_data;
366 inline void reset (unsigned int start_index_,
367 unsigned int num_items_)
370 num_items = num_items_;
371 end = c->buffer->len;
372 matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0);
375 inline void reject (void) { num_items++; match_glyph_data--; }
377 inline bool next (void)
379 assert (num_items > 0);
380 while (idx + num_items < end)
383 const hb_glyph_info_t &info = c->buffer->info[idx];
385 matcher_t::may_skip_t skip = matcher.may_skip (c, info);
386 if (unlikely (skip == matcher_t::SKIP_YES))
389 matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
390 if (match == matcher_t::MATCH_YES ||
391 (match == matcher_t::MATCH_MAYBE &&
392 skip == matcher_t::SKIP_NO))
399 if (skip == matcher_t::SKIP_NO)
404 inline bool prev (void)
406 assert (num_items > 0);
407 while (idx >= num_items)
410 const hb_glyph_info_t &info = c->buffer->out_info[idx];
412 matcher_t::may_skip_t skip = matcher.may_skip (c, info);
413 if (unlikely (skip == matcher_t::SKIP_YES))
416 matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
417 if (match == matcher_t::MATCH_YES ||
418 (match == matcher_t::MATCH_MAYBE &&
419 skip == matcher_t::SKIP_NO))
426 if (skip == matcher_t::SKIP_NO)
434 hb_apply_context_t *c;
436 const USHORT *match_glyph_data;
438 unsigned int num_items;
443 inline const char *get_name (void) { return "APPLY"; }
444 typedef return_t (*recurse_func_t) (hb_apply_context_t *c, unsigned int lookup_index);
445 template <typename T>
446 inline return_t dispatch (const T &obj) { return obj.apply (this); }
447 static return_t default_return_value (void) { return false; }
448 bool stop_sublookup_iteration (return_t r) const { return r; }
449 return_t recurse (unsigned int lookup_index)
451 if (unlikely (nesting_level_left == 0 || !recurse_func))
452 return default_return_value ();
454 nesting_level_left--;
455 bool ret = recurse_func (this, lookup_index);
456 nesting_level_left++;
460 unsigned int table_index; /* GSUB/GPOS */
464 hb_direction_t direction;
465 hb_mask_t lookup_mask;
467 recurse_func_t recurse_func;
468 unsigned int nesting_level_left;
469 unsigned int lookup_props;
471 bool has_glyph_classes;
472 const VariationStore &var_store;
473 skipping_iterator_t iter_input, iter_context;
474 unsigned int lookup_index;
475 unsigned int debug_depth;
478 hb_apply_context_t (unsigned int table_index_,
480 hb_buffer_t *buffer_) :
481 table_index (table_index_),
482 font (font_), face (font->face), buffer (buffer_),
483 direction (buffer_->props.direction),
487 nesting_level_left (HB_MAX_NESTING_LEVEL),
489 gdef (*hb_ot_layout_from_face (face)->gdef),
490 has_glyph_classes (gdef.has_glyph_classes ()),
491 var_store (gdef.get_var_store ()),
494 lookup_index ((unsigned int) -1),
497 inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; }
498 inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; }
499 inline void set_recurse_func (recurse_func_t func) { recurse_func = func; }
500 inline void set_lookup_index (unsigned int lookup_index_) { lookup_index = lookup_index_; }
501 inline void set_lookup_props (unsigned int lookup_props_)
503 lookup_props = lookup_props_;
504 iter_input.init (this, false);
505 iter_context.init (this, true);
509 match_properties_mark (hb_codepoint_t glyph,
510 unsigned int glyph_props,
511 unsigned int match_props) const
513 /* If using mark filtering sets, the high short of
514 * match_props has the set index.
516 if (match_props & LookupFlag::UseMarkFilteringSet)
517 return gdef.mark_set_covers (match_props >> 16, glyph);
519 /* The second byte of match_props has the meaning
520 * "ignore marks of attachment type different than
521 * the attachment type specified."
523 if (match_props & LookupFlag::MarkAttachmentType)
524 return (match_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType);
530 check_glyph_property (const hb_glyph_info_t *info,
531 unsigned int match_props) const
533 hb_codepoint_t glyph = info->codepoint;
534 unsigned int glyph_props = _hb_glyph_info_get_glyph_props (info);
536 /* Not covered, if, for example, glyph class is ligature and
537 * match_props includes LookupFlags::IgnoreLigatures
539 if (glyph_props & match_props & LookupFlag::IgnoreFlags)
542 if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK))
543 return match_properties_mark (glyph, glyph_props, match_props);
548 inline void _set_glyph_props (hb_codepoint_t glyph_index,
549 unsigned int class_guess = 0,
550 bool ligature = false,
551 bool component = false) const
553 unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) &
554 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE;
555 add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED;
558 add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED;
559 /* In the only place that the MULTIPLIED bit is used, Uniscribe
560 * seems to only care about the "last" transformation between
561 * Ligature and Multiple substitions. Ie. if you ligate, expand,
562 * and ligate again, it forgives the multiplication and acts as
563 * if only ligation happened. As such, clear MULTIPLIED bit.
565 add_in &= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
568 add_in |= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
569 if (likely (has_glyph_classes))
570 _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | gdef.get_glyph_props (glyph_index));
571 else if (class_guess)
572 _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess);
575 inline void replace_glyph (hb_codepoint_t glyph_index) const
577 _set_glyph_props (glyph_index);
578 buffer->replace_glyph (glyph_index);
580 inline void replace_glyph_inplace (hb_codepoint_t glyph_index) const
582 _set_glyph_props (glyph_index);
583 buffer->cur().codepoint = glyph_index;
585 inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index,
586 unsigned int class_guess) const
588 _set_glyph_props (glyph_index, class_guess, true);
589 buffer->replace_glyph (glyph_index);
591 inline void output_glyph_for_component (hb_codepoint_t glyph_index,
592 unsigned int class_guess) const
594 _set_glyph_props (glyph_index, class_guess, false, true);
595 buffer->output_glyph (glyph_index);
601 typedef bool (*intersects_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data);
602 typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data);
603 typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data);
605 struct ContextClosureFuncs
607 intersects_func_t intersects;
609 struct ContextCollectGlyphsFuncs
611 collect_glyphs_func_t collect;
613 struct ContextApplyFuncs
619 static inline bool intersects_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED)
621 return glyphs->has (value);
623 static inline bool intersects_class (hb_set_t *glyphs, const USHORT &value, const void *data)
625 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
626 return class_def.intersects_class (glyphs, value);
628 static inline bool intersects_coverage (hb_set_t *glyphs, const USHORT &value, const void *data)
630 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
631 return (data+coverage).intersects (glyphs);
634 static inline bool intersects_array (hb_closure_context_t *c,
636 const USHORT values[],
637 intersects_func_t intersects_func,
638 const void *intersects_data)
640 for (unsigned int i = 0; i < count; i++)
641 if (likely (!intersects_func (c->glyphs, values[i], intersects_data)))
647 static inline void collect_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED)
651 static inline void collect_class (hb_set_t *glyphs, const USHORT &value, const void *data)
653 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
654 class_def.add_class (glyphs, value);
656 static inline void collect_coverage (hb_set_t *glyphs, const USHORT &value, const void *data)
658 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
659 (data+coverage).add_coverage (glyphs);
661 static inline void collect_array (hb_collect_glyphs_context_t *c HB_UNUSED,
664 const USHORT values[],
665 collect_glyphs_func_t collect_func,
666 const void *collect_data)
668 for (unsigned int i = 0; i < count; i++)
669 collect_func (glyphs, values[i], collect_data);
673 static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, const void *data HB_UNUSED)
675 return glyph_id == value;
677 static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, const void *data)
679 const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
680 return class_def.get_class (glyph_id) == value;
682 static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, const void *data)
684 const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
685 return (data+coverage).get_coverage (glyph_id) != NOT_COVERED;
688 static inline bool would_match_input (hb_would_apply_context_t *c,
689 unsigned int count, /* Including the first glyph (not matched) */
690 const USHORT input[], /* Array of input values--start with second glyph */
691 match_func_t match_func,
692 const void *match_data)
697 for (unsigned int i = 1; i < count; i++)
698 if (likely (!match_func (c->glyphs[i], input[i - 1], match_data)))
703 static inline bool match_input (hb_apply_context_t *c,
704 unsigned int count, /* Including the first glyph (not matched) */
705 const USHORT input[], /* Array of input values--start with second glyph */
706 match_func_t match_func,
707 const void *match_data,
708 unsigned int *end_offset,
709 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH],
710 bool *p_is_mark_ligature = NULL,
711 unsigned int *p_total_component_count = NULL)
715 if (unlikely (count > HB_MAX_CONTEXT_LENGTH)) return_trace (false);
717 hb_buffer_t *buffer = c->buffer;
719 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
720 skippy_iter.reset (buffer->idx, count - 1);
721 skippy_iter.set_match_func (match_func, match_data, input);
724 * This is perhaps the trickiest part of OpenType... Remarks:
726 * - If all components of the ligature were marks, we call this a mark ligature.
728 * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize
729 * it as a ligature glyph.
731 * - Ligatures cannot be formed across glyphs attached to different components
732 * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
733 * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother.
734 * However, it would be wrong to ligate that SHADDA,FATHA sequence.o
735 * There is an exception to this: If a ligature tries ligating with marks that
736 * belong to it itself, go ahead, assuming that the font designer knows what
737 * they are doing (otherwise it can break Indic stuff when a matra wants to
738 * ligate with a conjunct...)
741 bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->cur());
743 unsigned int total_component_count = 0;
744 total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur());
746 unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
747 unsigned int first_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
749 match_positions[0] = buffer->idx;
750 for (unsigned int i = 1; i < count; i++)
752 if (!skippy_iter.next ()) return_trace (false);
754 match_positions[i] = skippy_iter.idx;
756 unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]);
757 unsigned int this_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]);
759 if (first_lig_id && first_lig_comp) {
760 /* If first component was attached to a previous ligature component,
761 * all subsequent components should be attached to the same ligature
762 * component, otherwise we shouldn't ligate them. */
763 if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp)
764 return_trace (false);
766 /* If first component was NOT attached to a previous ligature component,
767 * all subsequent components should also NOT be attached to any ligature
768 * component, unless they are attached to the first component itself! */
769 if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id))
770 return_trace (false);
773 is_mark_ligature = is_mark_ligature && _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx]);
774 total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->info[skippy_iter.idx]);
777 *end_offset = skippy_iter.idx - buffer->idx + 1;
779 if (p_is_mark_ligature)
780 *p_is_mark_ligature = is_mark_ligature;
782 if (p_total_component_count)
783 *p_total_component_count = total_component_count;
787 static inline bool ligate_input (hb_apply_context_t *c,
788 unsigned int count, /* Including the first glyph */
789 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */
790 unsigned int match_length,
791 hb_codepoint_t lig_glyph,
792 bool is_mark_ligature,
793 unsigned int total_component_count)
797 hb_buffer_t *buffer = c->buffer;
799 buffer->merge_clusters (buffer->idx, buffer->idx + match_length);
802 * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
803 * the ligature to keep its old ligature id. This will allow it to attach to
804 * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
805 * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a
806 * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature
807 * later, we don't want them to lose their ligature id/component, otherwise
808 * GPOS will fail to correctly position the mark ligature on top of the
809 * LAM,LAM,HEH ligature. See:
810 * https://bugzilla.gnome.org/show_bug.cgi?id=676343
812 * - If a ligature is formed of components that some of which are also ligatures
813 * themselves, and those ligature components had marks attached to *their*
814 * components, we have to attach the marks to the new ligature component
815 * positions! Now *that*'s tricky! And these marks may be following the
816 * last component of the whole sequence, so we should loop forward looking
817 * for them and update them.
819 * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
820 * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
821 * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature
822 * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to
823 * the new ligature with a component value of 2.
825 * This in fact happened to a font... See:
826 * https://bugzilla.gnome.org/show_bug.cgi?id=437633
829 unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
830 unsigned int lig_id = is_mark_ligature ? 0 : _hb_allocate_lig_id (buffer);
831 unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
832 unsigned int last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
833 unsigned int components_so_far = last_num_components;
835 if (!is_mark_ligature)
837 _hb_glyph_info_set_lig_props_for_ligature (&buffer->cur(), lig_id, total_component_count);
838 if (_hb_glyph_info_get_general_category (&buffer->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
840 _hb_glyph_info_set_general_category (&buffer->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER);
843 c->replace_glyph_with_ligature (lig_glyph, klass);
845 for (unsigned int i = 1; i < count; i++)
847 while (buffer->idx < match_positions[i] && !buffer->in_error)
849 if (!is_mark_ligature) {
850 unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
852 this_comp = last_num_components;
853 unsigned int new_lig_comp = components_so_far - last_num_components +
854 MIN (this_comp, last_num_components);
855 _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp);
857 buffer->next_glyph ();
860 last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
861 last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
862 components_so_far += last_num_components;
864 /* Skip the base glyph */
868 if (!is_mark_ligature && last_lig_id) {
869 /* Re-adjust components for any marks following. */
870 for (unsigned int i = buffer->idx; i < buffer->len; i++) {
871 if (last_lig_id == _hb_glyph_info_get_lig_id (&buffer->info[i])) {
872 unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->info[i]);
875 unsigned int new_lig_comp = components_so_far - last_num_components +
876 MIN (this_comp, last_num_components);
877 _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp);
885 static inline bool match_backtrack (hb_apply_context_t *c,
887 const USHORT backtrack[],
888 match_func_t match_func,
889 const void *match_data)
893 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
894 skippy_iter.reset (c->buffer->backtrack_len (), count);
895 skippy_iter.set_match_func (match_func, match_data, backtrack);
897 for (unsigned int i = 0; i < count; i++)
898 if (!skippy_iter.prev ())
899 return_trace (false);
904 static inline bool match_lookahead (hb_apply_context_t *c,
906 const USHORT lookahead[],
907 match_func_t match_func,
908 const void *match_data,
913 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
914 skippy_iter.reset (c->buffer->idx + offset - 1, count);
915 skippy_iter.set_match_func (match_func, match_data, lookahead);
917 for (unsigned int i = 0; i < count; i++)
918 if (!skippy_iter.next ())
919 return_trace (false);
928 inline bool sanitize (hb_sanitize_context_t *c) const
930 TRACE_SANITIZE (this);
931 return_trace (c->check_struct (this));
934 USHORT sequenceIndex; /* Index into current glyph
935 * sequence--first glyph = 0 */
936 USHORT lookupListIndex; /* Lookup to apply to that
937 * position--zero--based */
939 DEFINE_SIZE_STATIC (4);
943 template <typename context_t>
944 static inline void recurse_lookups (context_t *c,
945 unsigned int lookupCount,
946 const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
948 for (unsigned int i = 0; i < lookupCount; i++)
949 c->recurse (lookupRecord[i].lookupListIndex);
952 static inline bool apply_lookup (hb_apply_context_t *c,
953 unsigned int count, /* Including the first glyph */
954 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */
955 unsigned int lookupCount,
956 const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
957 unsigned int match_length)
961 hb_buffer_t *buffer = c->buffer;
964 /* All positions are distance from beginning of *output* buffer.
967 unsigned int bl = buffer->backtrack_len ();
968 end = bl + match_length;
970 int delta = bl - buffer->idx;
971 /* Convert positions to new indexing. */
972 for (unsigned int j = 0; j < count; j++)
973 match_positions[j] += delta;
976 for (unsigned int i = 0; i < lookupCount && !buffer->in_error; i++)
978 unsigned int idx = lookupRecord[i].sequenceIndex;
982 /* Don't recurse to ourself at same position.
983 * Note that this test is too naive, it doesn't catch longer loops. */
984 if (idx == 0 && lookupRecord[i].lookupListIndex == c->lookup_index)
987 buffer->move_to (match_positions[idx]);
989 unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len ();
990 if (!c->recurse (lookupRecord[i].lookupListIndex))
993 unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len ();
994 int delta = new_len - orig_len;
999 /* Recursed lookup changed buffer len. Adjust.
1003 * Right now, if buffer length increased by n, we assume n new glyphs
1004 * were added right after the current position, and if buffer length
1005 * was decreased by n, we assume n match positions after the current
1006 * one where removed. The former (buffer length increased) case is
1007 * fine, but the decrease case can be improved in at least two ways,
1008 * both of which are significant:
1010 * - If recursed-to lookup is MultipleSubst and buffer length
1011 * decreased, then it's current match position that was deleted,
1012 * NOT the one after it.
1014 * - If buffer length was decreased by n, it does not necessarily
1015 * mean that n match positions where removed, as there might
1016 * have been marks and default-ignorables in the sequence. We
1017 * should instead drop match positions between current-position
1018 * and current-position + n instead.
1020 * It should be possible to construct tests for both of these cases.
1024 if (end <= int (match_positions[idx]))
1026 /* End might end up being smaller than match_positions[idx] if the recursed
1027 * lookup ended up removing many items, more than we have had matched.
1028 * Just never rewind end back and get out of here.
1029 * https://bugs.chromium.org/p/chromium/issues/detail?id=659496 */
1030 end = match_positions[idx];
1031 /* There can't be any further changes. */
1035 unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */
1039 if (unlikely (delta + count > HB_MAX_CONTEXT_LENGTH))
1044 /* NOTE: delta is negative. */
1045 delta = MAX (delta, (int) next - (int) count);
1050 memmove (match_positions + next + delta, match_positions + next,
1051 (count - next) * sizeof (match_positions[0]));
1055 /* Fill in new entries. */
1056 for (unsigned int j = idx + 1; j < next; j++)
1057 match_positions[j] = match_positions[j - 1] + 1;
1059 /* And fixup the rest. */
1060 for (; next < count; next++)
1061 match_positions[next] += delta;
1064 buffer->move_to (end);
1066 return_trace (true);
1071 /* Contextual lookups */
1073 struct ContextClosureLookupContext
1075 ContextClosureFuncs funcs;
1076 const void *intersects_data;
1079 struct ContextCollectGlyphsLookupContext
1081 ContextCollectGlyphsFuncs funcs;
1082 const void *collect_data;
1085 struct ContextApplyLookupContext
1087 ContextApplyFuncs funcs;
1088 const void *match_data;
1091 static inline void context_closure_lookup (hb_closure_context_t *c,
1092 unsigned int inputCount, /* Including the first glyph (not matched) */
1093 const USHORT input[], /* Array of input values--start with second glyph */
1094 unsigned int lookupCount,
1095 const LookupRecord lookupRecord[],
1096 ContextClosureLookupContext &lookup_context)
1098 if (intersects_array (c,
1099 inputCount ? inputCount - 1 : 0, input,
1100 lookup_context.funcs.intersects, lookup_context.intersects_data))
1102 lookupCount, lookupRecord);
1105 static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c,
1106 unsigned int inputCount, /* Including the first glyph (not matched) */
1107 const USHORT input[], /* Array of input values--start with second glyph */
1108 unsigned int lookupCount,
1109 const LookupRecord lookupRecord[],
1110 ContextCollectGlyphsLookupContext &lookup_context)
1112 collect_array (c, c->input,
1113 inputCount ? inputCount - 1 : 0, input,
1114 lookup_context.funcs.collect, lookup_context.collect_data);
1116 lookupCount, lookupRecord);
1119 static inline bool context_would_apply_lookup (hb_would_apply_context_t *c,
1120 unsigned int inputCount, /* Including the first glyph (not matched) */
1121 const USHORT input[], /* Array of input values--start with second glyph */
1122 unsigned int lookupCount HB_UNUSED,
1123 const LookupRecord lookupRecord[] HB_UNUSED,
1124 ContextApplyLookupContext &lookup_context)
1126 return would_match_input (c,
1128 lookup_context.funcs.match, lookup_context.match_data);
1130 static inline bool context_apply_lookup (hb_apply_context_t *c,
1131 unsigned int inputCount, /* Including the first glyph (not matched) */
1132 const USHORT input[], /* Array of input values--start with second glyph */
1133 unsigned int lookupCount,
1134 const LookupRecord lookupRecord[],
1135 ContextApplyLookupContext &lookup_context)
1137 unsigned int match_length = 0;
1138 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
1139 return match_input (c,
1141 lookup_context.funcs.match, lookup_context.match_data,
1142 &match_length, match_positions)
1144 inputCount, match_positions,
1145 lookupCount, lookupRecord,
1151 inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
1153 TRACE_CLOSURE (this);
1154 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
1155 context_closure_lookup (c,
1157 lookupCount, lookupRecord,
1161 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
1163 TRACE_COLLECT_GLYPHS (this);
1164 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
1165 context_collect_glyphs_lookup (c,
1167 lookupCount, lookupRecord,
1171 inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
1173 TRACE_WOULD_APPLY (this);
1174 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
1175 return_trace (context_would_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
1178 inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
1181 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
1182 return_trace (context_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
1186 inline bool sanitize (hb_sanitize_context_t *c) const
1188 TRACE_SANITIZE (this);
1189 return inputCount.sanitize (c)
1190 && lookupCount.sanitize (c)
1191 && c->check_range (inputZ,
1192 inputZ[0].static_size * inputCount
1193 + lookupRecordX[0].static_size * lookupCount);
1197 USHORT inputCount; /* Total number of glyphs in input
1198 * glyph sequence--includes the first
1200 USHORT lookupCount; /* Number of LookupRecords */
1201 USHORT inputZ[VAR]; /* Array of match inputs--start with
1203 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
1206 DEFINE_SIZE_ARRAY2 (4, inputZ, lookupRecordX);
1211 inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
1213 TRACE_CLOSURE (this);
1214 unsigned int num_rules = rule.len;
1215 for (unsigned int i = 0; i < num_rules; i++)
1216 (this+rule[i]).closure (c, lookup_context);
1219 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
1221 TRACE_COLLECT_GLYPHS (this);
1222 unsigned int num_rules = rule.len;
1223 for (unsigned int i = 0; i < num_rules; i++)
1224 (this+rule[i]).collect_glyphs (c, lookup_context);
1227 inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
1229 TRACE_WOULD_APPLY (this);
1230 unsigned int num_rules = rule.len;
1231 for (unsigned int i = 0; i < num_rules; i++)
1233 if ((this+rule[i]).would_apply (c, lookup_context))
1234 return_trace (true);
1236 return_trace (false);
1239 inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
1242 unsigned int num_rules = rule.len;
1243 for (unsigned int i = 0; i < num_rules; i++)
1245 if ((this+rule[i]).apply (c, lookup_context))
1246 return_trace (true);
1248 return_trace (false);
1251 inline bool sanitize (hb_sanitize_context_t *c) const
1253 TRACE_SANITIZE (this);
1254 return_trace (rule.sanitize (c, this));
1259 rule; /* Array of Rule tables
1260 * ordered by preference */
1262 DEFINE_SIZE_ARRAY (2, rule);
1266 struct ContextFormat1
1268 inline void closure (hb_closure_context_t *c) const
1270 TRACE_CLOSURE (this);
1272 const Coverage &cov = (this+coverage);
1274 struct ContextClosureLookupContext lookup_context = {
1279 unsigned int count = ruleSet.len;
1280 for (unsigned int i = 0; i < count; i++)
1281 if (cov.intersects_coverage (c->glyphs, i)) {
1282 const RuleSet &rule_set = this+ruleSet[i];
1283 rule_set.closure (c, lookup_context);
1287 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1289 TRACE_COLLECT_GLYPHS (this);
1290 (this+coverage).add_coverage (c->input);
1292 struct ContextCollectGlyphsLookupContext lookup_context = {
1297 unsigned int count = ruleSet.len;
1298 for (unsigned int i = 0; i < count; i++)
1299 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
1302 inline bool would_apply (hb_would_apply_context_t *c) const
1304 TRACE_WOULD_APPLY (this);
1306 const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
1307 struct ContextApplyLookupContext lookup_context = {
1311 return_trace (rule_set.would_apply (c, lookup_context));
1314 inline const Coverage &get_coverage (void) const
1316 return this+coverage;
1319 inline bool apply (hb_apply_context_t *c) const
1322 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
1323 if (likely (index == NOT_COVERED))
1324 return_trace (false);
1326 const RuleSet &rule_set = this+ruleSet[index];
1327 struct ContextApplyLookupContext lookup_context = {
1331 return_trace (rule_set.apply (c, lookup_context));
1334 inline bool sanitize (hb_sanitize_context_t *c) const
1336 TRACE_SANITIZE (this);
1337 return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
1341 USHORT format; /* Format identifier--format = 1 */
1343 coverage; /* Offset to Coverage table--from
1344 * beginning of table */
1345 OffsetArrayOf<RuleSet>
1346 ruleSet; /* Array of RuleSet tables
1347 * ordered by Coverage Index */
1349 DEFINE_SIZE_ARRAY (6, ruleSet);
1353 struct ContextFormat2
1355 inline void closure (hb_closure_context_t *c) const
1357 TRACE_CLOSURE (this);
1358 if (!(this+coverage).intersects (c->glyphs))
1361 const ClassDef &class_def = this+classDef;
1363 struct ContextClosureLookupContext lookup_context = {
1368 unsigned int count = ruleSet.len;
1369 for (unsigned int i = 0; i < count; i++)
1370 if (class_def.intersects_class (c->glyphs, i)) {
1371 const RuleSet &rule_set = this+ruleSet[i];
1372 rule_set.closure (c, lookup_context);
1376 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1378 TRACE_COLLECT_GLYPHS (this);
1379 (this+coverage).add_coverage (c->input);
1381 const ClassDef &class_def = this+classDef;
1382 struct ContextCollectGlyphsLookupContext lookup_context = {
1387 unsigned int count = ruleSet.len;
1388 for (unsigned int i = 0; i < count; i++)
1389 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
1392 inline bool would_apply (hb_would_apply_context_t *c) const
1394 TRACE_WOULD_APPLY (this);
1396 const ClassDef &class_def = this+classDef;
1397 unsigned int index = class_def.get_class (c->glyphs[0]);
1398 const RuleSet &rule_set = this+ruleSet[index];
1399 struct ContextApplyLookupContext lookup_context = {
1403 return_trace (rule_set.would_apply (c, lookup_context));
1406 inline const Coverage &get_coverage (void) const
1408 return this+coverage;
1411 inline bool apply (hb_apply_context_t *c) const
1414 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
1415 if (likely (index == NOT_COVERED)) return_trace (false);
1417 const ClassDef &class_def = this+classDef;
1418 index = class_def.get_class (c->buffer->cur().codepoint);
1419 const RuleSet &rule_set = this+ruleSet[index];
1420 struct ContextApplyLookupContext lookup_context = {
1424 return_trace (rule_set.apply (c, lookup_context));
1427 inline bool sanitize (hb_sanitize_context_t *c) const
1429 TRACE_SANITIZE (this);
1430 return_trace (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this));
1434 USHORT format; /* Format identifier--format = 2 */
1436 coverage; /* Offset to Coverage table--from
1437 * beginning of table */
1439 classDef; /* Offset to glyph ClassDef table--from
1440 * beginning of table */
1441 OffsetArrayOf<RuleSet>
1442 ruleSet; /* Array of RuleSet tables
1443 * ordered by class */
1445 DEFINE_SIZE_ARRAY (8, ruleSet);
1449 struct ContextFormat3
1451 inline void closure (hb_closure_context_t *c) const
1453 TRACE_CLOSURE (this);
1454 if (!(this+coverageZ[0]).intersects (c->glyphs))
1457 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
1458 struct ContextClosureLookupContext lookup_context = {
1459 {intersects_coverage},
1462 context_closure_lookup (c,
1463 glyphCount, (const USHORT *) (coverageZ + 1),
1464 lookupCount, lookupRecord,
1468 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1470 TRACE_COLLECT_GLYPHS (this);
1471 (this+coverageZ[0]).add_coverage (c->input);
1473 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
1474 struct ContextCollectGlyphsLookupContext lookup_context = {
1479 context_collect_glyphs_lookup (c,
1480 glyphCount, (const USHORT *) (coverageZ + 1),
1481 lookupCount, lookupRecord,
1485 inline bool would_apply (hb_would_apply_context_t *c) const
1487 TRACE_WOULD_APPLY (this);
1489 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
1490 struct ContextApplyLookupContext lookup_context = {
1494 return_trace (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
1497 inline const Coverage &get_coverage (void) const
1499 return this+coverageZ[0];
1502 inline bool apply (hb_apply_context_t *c) const
1505 unsigned int index = (this+coverageZ[0]).get_coverage (c->buffer->cur().codepoint);
1506 if (likely (index == NOT_COVERED)) return_trace (false);
1508 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
1509 struct ContextApplyLookupContext lookup_context = {
1513 return_trace (context_apply_lookup (c, glyphCount, (const USHORT *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
1516 inline bool sanitize (hb_sanitize_context_t *c) const
1518 TRACE_SANITIZE (this);
1519 if (!c->check_struct (this)) return_trace (false);
1520 unsigned int count = glyphCount;
1521 if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */
1522 if (!c->check_array (coverageZ, coverageZ[0].static_size, count)) return_trace (false);
1523 for (unsigned int i = 0; i < count; i++)
1524 if (!coverageZ[i].sanitize (c, this)) return_trace (false);
1525 const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * count);
1526 return_trace (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
1530 USHORT format; /* Format identifier--format = 3 */
1531 USHORT glyphCount; /* Number of glyphs in the input glyph
1533 USHORT lookupCount; /* Number of LookupRecords */
1535 coverageZ[VAR]; /* Array of offsets to Coverage
1536 * table in glyph sequence order */
1537 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
1540 DEFINE_SIZE_ARRAY2 (6, coverageZ, lookupRecordX);
1545 template <typename context_t>
1546 inline typename context_t::return_t dispatch (context_t *c) const
1548 TRACE_DISPATCH (this, u.format);
1549 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
1551 case 1: return_trace (c->dispatch (u.format1));
1552 case 2: return_trace (c->dispatch (u.format2));
1553 case 3: return_trace (c->dispatch (u.format3));
1554 default:return_trace (c->default_return_value ());
1560 USHORT format; /* Format identifier */
1561 ContextFormat1 format1;
1562 ContextFormat2 format2;
1563 ContextFormat3 format3;
1568 /* Chaining Contextual lookups */
1570 struct ChainContextClosureLookupContext
1572 ContextClosureFuncs funcs;
1573 const void *intersects_data[3];
1576 struct ChainContextCollectGlyphsLookupContext
1578 ContextCollectGlyphsFuncs funcs;
1579 const void *collect_data[3];
1582 struct ChainContextApplyLookupContext
1584 ContextApplyFuncs funcs;
1585 const void *match_data[3];
1588 static inline void chain_context_closure_lookup (hb_closure_context_t *c,
1589 unsigned int backtrackCount,
1590 const USHORT backtrack[],
1591 unsigned int inputCount, /* Including the first glyph (not matched) */
1592 const USHORT input[], /* Array of input values--start with second glyph */
1593 unsigned int lookaheadCount,
1594 const USHORT lookahead[],
1595 unsigned int lookupCount,
1596 const LookupRecord lookupRecord[],
1597 ChainContextClosureLookupContext &lookup_context)
1599 if (intersects_array (c,
1600 backtrackCount, backtrack,
1601 lookup_context.funcs.intersects, lookup_context.intersects_data[0])
1602 && intersects_array (c,
1603 inputCount ? inputCount - 1 : 0, input,
1604 lookup_context.funcs.intersects, lookup_context.intersects_data[1])
1605 && intersects_array (c,
1606 lookaheadCount, lookahead,
1607 lookup_context.funcs.intersects, lookup_context.intersects_data[2]))
1609 lookupCount, lookupRecord);
1612 static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c,
1613 unsigned int backtrackCount,
1614 const USHORT backtrack[],
1615 unsigned int inputCount, /* Including the first glyph (not matched) */
1616 const USHORT input[], /* Array of input values--start with second glyph */
1617 unsigned int lookaheadCount,
1618 const USHORT lookahead[],
1619 unsigned int lookupCount,
1620 const LookupRecord lookupRecord[],
1621 ChainContextCollectGlyphsLookupContext &lookup_context)
1623 collect_array (c, c->before,
1624 backtrackCount, backtrack,
1625 lookup_context.funcs.collect, lookup_context.collect_data[0]);
1626 collect_array (c, c->input,
1627 inputCount ? inputCount - 1 : 0, input,
1628 lookup_context.funcs.collect, lookup_context.collect_data[1]);
1629 collect_array (c, c->after,
1630 lookaheadCount, lookahead,
1631 lookup_context.funcs.collect, lookup_context.collect_data[2]);
1633 lookupCount, lookupRecord);
1636 static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c,
1637 unsigned int backtrackCount,
1638 const USHORT backtrack[] HB_UNUSED,
1639 unsigned int inputCount, /* Including the first glyph (not matched) */
1640 const USHORT input[], /* Array of input values--start with second glyph */
1641 unsigned int lookaheadCount,
1642 const USHORT lookahead[] HB_UNUSED,
1643 unsigned int lookupCount HB_UNUSED,
1644 const LookupRecord lookupRecord[] HB_UNUSED,
1645 ChainContextApplyLookupContext &lookup_context)
1647 return (c->zero_context ? !backtrackCount && !lookaheadCount : true)
1648 && would_match_input (c,
1650 lookup_context.funcs.match, lookup_context.match_data[1]);
1653 static inline bool chain_context_apply_lookup (hb_apply_context_t *c,
1654 unsigned int backtrackCount,
1655 const USHORT backtrack[],
1656 unsigned int inputCount, /* Including the first glyph (not matched) */
1657 const USHORT input[], /* Array of input values--start with second glyph */
1658 unsigned int lookaheadCount,
1659 const USHORT lookahead[],
1660 unsigned int lookupCount,
1661 const LookupRecord lookupRecord[],
1662 ChainContextApplyLookupContext &lookup_context)
1664 unsigned int match_length = 0;
1665 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
1666 return match_input (c,
1668 lookup_context.funcs.match, lookup_context.match_data[1],
1669 &match_length, match_positions)
1670 && match_backtrack (c,
1671 backtrackCount, backtrack,
1672 lookup_context.funcs.match, lookup_context.match_data[0])
1673 && match_lookahead (c,
1674 lookaheadCount, lookahead,
1675 lookup_context.funcs.match, lookup_context.match_data[2],
1678 inputCount, match_positions,
1679 lookupCount, lookupRecord,
1685 inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
1687 TRACE_CLOSURE (this);
1688 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1689 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1690 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1691 chain_context_closure_lookup (c,
1692 backtrack.len, backtrack.array,
1693 input.len, input.array,
1694 lookahead.len, lookahead.array,
1695 lookup.len, lookup.array,
1699 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
1701 TRACE_COLLECT_GLYPHS (this);
1702 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1703 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1704 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1705 chain_context_collect_glyphs_lookup (c,
1706 backtrack.len, backtrack.array,
1707 input.len, input.array,
1708 lookahead.len, lookahead.array,
1709 lookup.len, lookup.array,
1713 inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
1715 TRACE_WOULD_APPLY (this);
1716 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1717 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1718 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1719 return_trace (chain_context_would_apply_lookup (c,
1720 backtrack.len, backtrack.array,
1721 input.len, input.array,
1722 lookahead.len, lookahead.array, lookup.len,
1723 lookup.array, lookup_context));
1726 inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
1729 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1730 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1731 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1732 return_trace (chain_context_apply_lookup (c,
1733 backtrack.len, backtrack.array,
1734 input.len, input.array,
1735 lookahead.len, lookahead.array, lookup.len,
1736 lookup.array, lookup_context));
1739 inline bool sanitize (hb_sanitize_context_t *c) const
1741 TRACE_SANITIZE (this);
1742 if (!backtrack.sanitize (c)) return_trace (false);
1743 const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack);
1744 if (!input.sanitize (c)) return_trace (false);
1745 const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
1746 if (!lookahead.sanitize (c)) return_trace (false);
1747 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
1748 return_trace (lookup.sanitize (c));
1753 backtrack; /* Array of backtracking values
1754 * (to be matched before the input
1756 HeadlessArrayOf<USHORT>
1757 inputX; /* Array of input values (start with
1760 lookaheadX; /* Array of lookahead values's (to be
1761 * matched after the input sequence) */
1762 ArrayOf<LookupRecord>
1763 lookupX; /* Array of LookupRecords--in
1766 DEFINE_SIZE_MIN (8);
1771 inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
1773 TRACE_CLOSURE (this);
1774 unsigned int num_rules = rule.len;
1775 for (unsigned int i = 0; i < num_rules; i++)
1776 (this+rule[i]).closure (c, lookup_context);
1779 inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
1781 TRACE_COLLECT_GLYPHS (this);
1782 unsigned int num_rules = rule.len;
1783 for (unsigned int i = 0; i < num_rules; i++)
1784 (this+rule[i]).collect_glyphs (c, lookup_context);
1787 inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
1789 TRACE_WOULD_APPLY (this);
1790 unsigned int num_rules = rule.len;
1791 for (unsigned int i = 0; i < num_rules; i++)
1792 if ((this+rule[i]).would_apply (c, lookup_context))
1793 return_trace (true);
1795 return_trace (false);
1798 inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
1801 unsigned int num_rules = rule.len;
1802 for (unsigned int i = 0; i < num_rules; i++)
1803 if ((this+rule[i]).apply (c, lookup_context))
1804 return_trace (true);
1806 return_trace (false);
1809 inline bool sanitize (hb_sanitize_context_t *c) const
1811 TRACE_SANITIZE (this);
1812 return_trace (rule.sanitize (c, this));
1816 OffsetArrayOf<ChainRule>
1817 rule; /* Array of ChainRule tables
1818 * ordered by preference */
1820 DEFINE_SIZE_ARRAY (2, rule);
1823 struct ChainContextFormat1
1825 inline void closure (hb_closure_context_t *c) const
1827 TRACE_CLOSURE (this);
1828 const Coverage &cov = (this+coverage);
1830 struct ChainContextClosureLookupContext lookup_context = {
1835 unsigned int count = ruleSet.len;
1836 for (unsigned int i = 0; i < count; i++)
1837 if (cov.intersects_coverage (c->glyphs, i)) {
1838 const ChainRuleSet &rule_set = this+ruleSet[i];
1839 rule_set.closure (c, lookup_context);
1843 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1845 TRACE_COLLECT_GLYPHS (this);
1846 (this+coverage).add_coverage (c->input);
1848 struct ChainContextCollectGlyphsLookupContext lookup_context = {
1853 unsigned int count = ruleSet.len;
1854 for (unsigned int i = 0; i < count; i++)
1855 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
1858 inline bool would_apply (hb_would_apply_context_t *c) const
1860 TRACE_WOULD_APPLY (this);
1862 const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
1863 struct ChainContextApplyLookupContext lookup_context = {
1867 return_trace (rule_set.would_apply (c, lookup_context));
1870 inline const Coverage &get_coverage (void) const
1872 return this+coverage;
1875 inline bool apply (hb_apply_context_t *c) const
1878 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
1879 if (likely (index == NOT_COVERED)) return_trace (false);
1881 const ChainRuleSet &rule_set = this+ruleSet[index];
1882 struct ChainContextApplyLookupContext lookup_context = {
1886 return_trace (rule_set.apply (c, lookup_context));
1889 inline bool sanitize (hb_sanitize_context_t *c) const
1891 TRACE_SANITIZE (this);
1892 return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
1896 USHORT format; /* Format identifier--format = 1 */
1898 coverage; /* Offset to Coverage table--from
1899 * beginning of table */
1900 OffsetArrayOf<ChainRuleSet>
1901 ruleSet; /* Array of ChainRuleSet tables
1902 * ordered by Coverage Index */
1904 DEFINE_SIZE_ARRAY (6, ruleSet);
1907 struct ChainContextFormat2
1909 inline void closure (hb_closure_context_t *c) const
1911 TRACE_CLOSURE (this);
1912 if (!(this+coverage).intersects (c->glyphs))
1915 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1916 const ClassDef &input_class_def = this+inputClassDef;
1917 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1919 struct ChainContextClosureLookupContext lookup_context = {
1921 {&backtrack_class_def,
1923 &lookahead_class_def}
1926 unsigned int count = ruleSet.len;
1927 for (unsigned int i = 0; i < count; i++)
1928 if (input_class_def.intersects_class (c->glyphs, i)) {
1929 const ChainRuleSet &rule_set = this+ruleSet[i];
1930 rule_set.closure (c, lookup_context);
1934 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1936 TRACE_COLLECT_GLYPHS (this);
1937 (this+coverage).add_coverage (c->input);
1939 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1940 const ClassDef &input_class_def = this+inputClassDef;
1941 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1943 struct ChainContextCollectGlyphsLookupContext lookup_context = {
1945 {&backtrack_class_def,
1947 &lookahead_class_def}
1950 unsigned int count = ruleSet.len;
1951 for (unsigned int i = 0; i < count; i++)
1952 (this+ruleSet[i]).collect_glyphs (c, lookup_context);
1955 inline bool would_apply (hb_would_apply_context_t *c) const
1957 TRACE_WOULD_APPLY (this);
1959 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1960 const ClassDef &input_class_def = this+inputClassDef;
1961 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1963 unsigned int index = input_class_def.get_class (c->glyphs[0]);
1964 const ChainRuleSet &rule_set = this+ruleSet[index];
1965 struct ChainContextApplyLookupContext lookup_context = {
1967 {&backtrack_class_def,
1969 &lookahead_class_def}
1971 return_trace (rule_set.would_apply (c, lookup_context));
1974 inline const Coverage &get_coverage (void) const
1976 return this+coverage;
1979 inline bool apply (hb_apply_context_t *c) const
1982 unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
1983 if (likely (index == NOT_COVERED)) return_trace (false);
1985 const ClassDef &backtrack_class_def = this+backtrackClassDef;
1986 const ClassDef &input_class_def = this+inputClassDef;
1987 const ClassDef &lookahead_class_def = this+lookaheadClassDef;
1989 index = input_class_def.get_class (c->buffer->cur().codepoint);
1990 const ChainRuleSet &rule_set = this+ruleSet[index];
1991 struct ChainContextApplyLookupContext lookup_context = {
1993 {&backtrack_class_def,
1995 &lookahead_class_def}
1997 return_trace (rule_set.apply (c, lookup_context));
2000 inline bool sanitize (hb_sanitize_context_t *c) const
2002 TRACE_SANITIZE (this);
2003 return_trace (coverage.sanitize (c, this) &&
2004 backtrackClassDef.sanitize (c, this) &&
2005 inputClassDef.sanitize (c, this) &&
2006 lookaheadClassDef.sanitize (c, this) &&
2007 ruleSet.sanitize (c, this));
2011 USHORT format; /* Format identifier--format = 2 */
2013 coverage; /* Offset to Coverage table--from
2014 * beginning of table */
2016 backtrackClassDef; /* Offset to glyph ClassDef table
2017 * containing backtrack sequence
2018 * data--from beginning of table */
2020 inputClassDef; /* Offset to glyph ClassDef
2021 * table containing input sequence
2022 * data--from beginning of table */
2024 lookaheadClassDef; /* Offset to glyph ClassDef table
2025 * containing lookahead sequence
2026 * data--from beginning of table */
2027 OffsetArrayOf<ChainRuleSet>
2028 ruleSet; /* Array of ChainRuleSet tables
2029 * ordered by class */
2031 DEFINE_SIZE_ARRAY (12, ruleSet);
2034 struct ChainContextFormat3
2036 inline void closure (hb_closure_context_t *c) const
2038 TRACE_CLOSURE (this);
2039 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2041 if (!(this+input[0]).intersects (c->glyphs))
2044 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2045 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2046 struct ChainContextClosureLookupContext lookup_context = {
2047 {intersects_coverage},
2050 chain_context_closure_lookup (c,
2051 backtrack.len, (const USHORT *) backtrack.array,
2052 input.len, (const USHORT *) input.array + 1,
2053 lookahead.len, (const USHORT *) lookahead.array,
2054 lookup.len, lookup.array,
2058 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
2060 TRACE_COLLECT_GLYPHS (this);
2061 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2063 (this+input[0]).add_coverage (c->input);
2065 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2066 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2067 struct ChainContextCollectGlyphsLookupContext lookup_context = {
2071 chain_context_collect_glyphs_lookup (c,
2072 backtrack.len, (const USHORT *) backtrack.array,
2073 input.len, (const USHORT *) input.array + 1,
2074 lookahead.len, (const USHORT *) lookahead.array,
2075 lookup.len, lookup.array,
2079 inline bool would_apply (hb_would_apply_context_t *c) const
2081 TRACE_WOULD_APPLY (this);
2083 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2084 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2085 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2086 struct ChainContextApplyLookupContext lookup_context = {
2090 return_trace (chain_context_would_apply_lookup (c,
2091 backtrack.len, (const USHORT *) backtrack.array,
2092 input.len, (const USHORT *) input.array + 1,
2093 lookahead.len, (const USHORT *) lookahead.array,
2094 lookup.len, lookup.array, lookup_context));
2097 inline const Coverage &get_coverage (void) const
2099 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2100 return this+input[0];
2103 inline bool apply (hb_apply_context_t *c) const
2106 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2108 unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint);
2109 if (likely (index == NOT_COVERED)) return_trace (false);
2111 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2112 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2113 struct ChainContextApplyLookupContext lookup_context = {
2117 return_trace (chain_context_apply_lookup (c,
2118 backtrack.len, (const USHORT *) backtrack.array,
2119 input.len, (const USHORT *) input.array + 1,
2120 lookahead.len, (const USHORT *) lookahead.array,
2121 lookup.len, lookup.array, lookup_context));
2124 inline bool sanitize (hb_sanitize_context_t *c) const
2126 TRACE_SANITIZE (this);
2127 if (!backtrack.sanitize (c, this)) return_trace (false);
2128 const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
2129 if (!input.sanitize (c, this)) return_trace (false);
2130 if (!input.len) return_trace (false); /* To be consistent with Context. */
2131 const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
2132 if (!lookahead.sanitize (c, this)) return_trace (false);
2133 const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
2134 return_trace (lookup.sanitize (c));
2138 USHORT format; /* Format identifier--format = 3 */
2139 OffsetArrayOf<Coverage>
2140 backtrack; /* Array of coverage tables
2141 * in backtracking sequence, in glyph
2143 OffsetArrayOf<Coverage>
2144 inputX ; /* Array of coverage
2145 * tables in input sequence, in glyph
2147 OffsetArrayOf<Coverage>
2148 lookaheadX; /* Array of coverage tables
2149 * in lookahead sequence, in glyph
2151 ArrayOf<LookupRecord>
2152 lookupX; /* Array of LookupRecords--in
2155 DEFINE_SIZE_MIN (10);
2160 template <typename context_t>
2161 inline typename context_t::return_t dispatch (context_t *c) const
2163 TRACE_DISPATCH (this, u.format);
2164 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
2166 case 1: return_trace (c->dispatch (u.format1));
2167 case 2: return_trace (c->dispatch (u.format2));
2168 case 3: return_trace (c->dispatch (u.format3));
2169 default:return_trace (c->default_return_value ());
2175 USHORT format; /* Format identifier */
2176 ChainContextFormat1 format1;
2177 ChainContextFormat2 format2;
2178 ChainContextFormat3 format3;
2183 template <typename T>
2184 struct ExtensionFormat1
2186 inline unsigned int get_type (void) const { return extensionLookupType; }
2188 template <typename X>
2189 inline const X& get_subtable (void) const
2191 unsigned int offset = extensionOffset;
2192 if (unlikely (!offset)) return Null(typename T::LookupSubTable);
2193 return StructAtOffset<typename T::LookupSubTable> (this, offset);
2196 template <typename context_t>
2197 inline typename context_t::return_t dispatch (context_t *c) const
2199 TRACE_DISPATCH (this, format);
2200 if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ());
2201 return_trace (get_subtable<typename T::LookupSubTable> ().dispatch (c, get_type ()));
2204 /* This is called from may_dispatch() above with hb_sanitize_context_t. */
2205 inline bool sanitize (hb_sanitize_context_t *c) const
2207 TRACE_SANITIZE (this);
2208 return_trace (c->check_struct (this) && extensionOffset != 0);
2212 USHORT format; /* Format identifier. Set to 1. */
2213 USHORT extensionLookupType; /* Lookup type of subtable referenced
2214 * by ExtensionOffset (i.e. the
2215 * extension subtable). */
2216 ULONG extensionOffset; /* Offset to the extension subtable,
2217 * of lookup type subtable. */
2219 DEFINE_SIZE_STATIC (8);
2222 template <typename T>
2225 inline unsigned int get_type (void) const
2228 case 1: return u.format1.get_type ();
2232 template <typename X>
2233 inline const X& get_subtable (void) const
2236 case 1: return u.format1.template get_subtable<typename T::LookupSubTable> ();
2237 default:return Null(typename T::LookupSubTable);
2241 template <typename context_t>
2242 inline typename context_t::return_t dispatch (context_t *c) const
2244 TRACE_DISPATCH (this, u.format);
2245 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
2247 case 1: return_trace (u.format1.dispatch (c));
2248 default:return_trace (c->default_return_value ());
2254 USHORT format; /* Format identifier */
2255 ExtensionFormat1<T> format1;
2266 static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB;
2267 static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS;
2269 inline unsigned int get_script_count (void) const
2270 { return (this+scriptList).len; }
2271 inline const Tag& get_script_tag (unsigned int i) const
2272 { return (this+scriptList).get_tag (i); }
2273 inline unsigned int get_script_tags (unsigned int start_offset,
2274 unsigned int *script_count /* IN/OUT */,
2275 hb_tag_t *script_tags /* OUT */) const
2276 { return (this+scriptList).get_tags (start_offset, script_count, script_tags); }
2277 inline const Script& get_script (unsigned int i) const
2278 { return (this+scriptList)[i]; }
2279 inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
2280 { return (this+scriptList).find_index (tag, index); }
2282 inline unsigned int get_feature_count (void) const
2283 { return (this+featureList).len; }
2284 inline hb_tag_t get_feature_tag (unsigned int i) const
2285 { return i == Index::NOT_FOUND_INDEX ? HB_TAG_NONE : (this+featureList).get_tag (i); }
2286 inline unsigned int get_feature_tags (unsigned int start_offset,
2287 unsigned int *feature_count /* IN/OUT */,
2288 hb_tag_t *feature_tags /* OUT */) const
2289 { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); }
2290 inline const Feature& get_feature (unsigned int i) const
2291 { return (this+featureList)[i]; }
2292 inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const
2293 { return (this+featureList).find_index (tag, index); }
2295 inline unsigned int get_lookup_count (void) const
2296 { return (this+lookupList).len; }
2297 inline const Lookup& get_lookup (unsigned int i) const
2298 { return (this+lookupList)[i]; }
2300 inline bool find_variations_index (const int *coords, unsigned int num_coords,
2301 unsigned int *index) const
2302 { return (version.to_int () >= 0x00010001u ? this+featureVars : Null(FeatureVariations))
2303 .find_index (coords, num_coords, index); }
2304 inline const Feature& get_feature_variation (unsigned int feature_index,
2305 unsigned int variations_index) const
2307 if (FeatureVariations::NOT_FOUND_INDEX != variations_index &&
2308 version.to_int () >= 0x00010001u)
2310 const Feature *feature = (this+featureVars).find_substitute (variations_index,
2315 return get_feature (feature_index);
2318 inline bool sanitize (hb_sanitize_context_t *c) const
2320 TRACE_SANITIZE (this);
2321 return_trace (version.sanitize (c) &&
2322 likely (version.major == 1) &&
2323 scriptList.sanitize (c, this) &&
2324 featureList.sanitize (c, this) &&
2325 lookupList.sanitize (c, this) &&
2326 (version.to_int () < 0x00010001u || featureVars.sanitize (c, this)));
2330 FixedVersion<>version; /* Version of the GSUB/GPOS table--initially set
2332 OffsetTo<ScriptList>
2333 scriptList; /* ScriptList table */
2334 OffsetTo<FeatureList>
2335 featureList; /* FeatureList table */
2336 OffsetTo<LookupList>
2337 lookupList; /* LookupList table */
2338 LOffsetTo<FeatureVariations>
2339 featureVars; /* Offset to Feature Variations
2340 table--from beginning of table
2341 * (may be NULL). Introduced
2342 * in version 0x00010001. */
2344 DEFINE_SIZE_MIN (10);
2348 } /* namespace OT */
2351 #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */