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"
41 #define TRACE_DISPATCH(this) \
42 hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \
43 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
46 #ifndef HB_DEBUG_CLOSURE
47 #define HB_DEBUG_CLOSURE (HB_DEBUG+0)
50 #define TRACE_CLOSURE(this) \
51 hb_auto_trace_t<HB_DEBUG_CLOSURE, hb_void_t> trace \
52 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
55 struct hb_closure_context_t
57 inline const char *get_name (void) { return "CLOSURE"; }
58 static const unsigned int max_debug_depth
= HB_DEBUG_CLOSURE
;
59 typedef hb_void_t return_t
;
60 typedef return_t (*recurse_func_t
) (hb_closure_context_t
*c
, unsigned int lookup_index
);
62 inline return_t
dispatch (const T
&obj
) { obj
.closure (this); return HB_VOID
; }
63 static return_t
default_return_value (void) { return HB_VOID
; }
64 bool stop_sublookup_iteration (return_t r HB_UNUSED
) const { return false; }
65 return_t
recurse (unsigned int lookup_index
)
67 if (unlikely (nesting_level_left
== 0 || !recurse_func
))
68 return default_return_value ();
71 recurse_func (this, lookup_index
);
78 recurse_func_t recurse_func
;
79 unsigned int nesting_level_left
;
80 unsigned int debug_depth
;
82 hb_closure_context_t (hb_face_t
*face_
,
84 unsigned int nesting_level_left_
= MAX_NESTING_LEVEL
) :
88 nesting_level_left (nesting_level_left_
),
91 void set_recurse_func (recurse_func_t func
) { recurse_func
= func
; }
96 #ifndef HB_DEBUG_WOULD_APPLY
97 #define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0)
100 #define TRACE_WOULD_APPLY(this) \
101 hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \
102 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
103 "%d glyphs", c->len);
105 struct hb_would_apply_context_t
107 inline const char *get_name (void) { return "WOULD_APPLY"; }
108 static const unsigned int max_debug_depth
= HB_DEBUG_WOULD_APPLY
;
109 typedef bool return_t
;
110 template <typename T
>
111 inline return_t
dispatch (const T
&obj
) { return obj
.would_apply (this); }
112 static return_t
default_return_value (void) { return false; }
113 bool stop_sublookup_iteration (return_t r
) const { return r
; }
116 const hb_codepoint_t
*glyphs
;
119 unsigned int debug_depth
;
121 hb_would_apply_context_t (hb_face_t
*face_
,
122 const hb_codepoint_t
*glyphs_
,
124 bool zero_context_
) :
128 zero_context (zero_context_
),
134 #ifndef HB_DEBUG_COLLECT_GLYPHS
135 #define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0)
138 #define TRACE_COLLECT_GLYPHS(this) \
139 hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, hb_void_t> trace \
140 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
143 struct hb_collect_glyphs_context_t
145 inline const char *get_name (void) { return "COLLECT_GLYPHS"; }
146 static const unsigned int max_debug_depth
= HB_DEBUG_COLLECT_GLYPHS
;
147 typedef hb_void_t return_t
;
148 typedef return_t (*recurse_func_t
) (hb_collect_glyphs_context_t
*c
, unsigned int lookup_index
);
149 template <typename T
>
150 inline return_t
dispatch (const T
&obj
) { obj
.collect_glyphs (this); return HB_VOID
; }
151 static return_t
default_return_value (void) { return HB_VOID
; }
152 bool stop_sublookup_iteration (return_t r HB_UNUSED
) const { return false; }
153 return_t
recurse (unsigned int lookup_index
)
155 if (unlikely (nesting_level_left
== 0 || !recurse_func
))
156 return default_return_value ();
158 /* Note that GPOS sets recurse_func to NULL already, so it doesn't get
159 * past the previous check. For GSUB, we only want to collect the output
160 * glyphs in the recursion. If output is not requested, we can go home now.
162 * Note further, that the above is not exactly correct. A recursed lookup
163 * is allowed to match input that is not matched in the context, but that's
164 * not how most fonts are built. It's possible to relax that and recurse
165 * with all sets here if it proves to be an issue.
168 if (output
== hb_set_get_empty ())
171 hb_set_t
*old_before
= before
;
172 hb_set_t
*old_input
= input
;
173 hb_set_t
*old_after
= after
;
174 before
= input
= after
= hb_set_get_empty ();
176 nesting_level_left
--;
177 recurse_func (this, lookup_index
);
178 nesting_level_left
++;
192 recurse_func_t recurse_func
;
193 unsigned int nesting_level_left
;
194 unsigned int debug_depth
;
196 hb_collect_glyphs_context_t (hb_face_t
*face_
,
197 hb_set_t
*glyphs_before
, /* OUT. May be NULL */
198 hb_set_t
*glyphs_input
, /* OUT. May be NULL */
199 hb_set_t
*glyphs_after
, /* OUT. May be NULL */
200 hb_set_t
*glyphs_output
, /* OUT. May be NULL */
201 unsigned int nesting_level_left_
= MAX_NESTING_LEVEL
) :
203 before (glyphs_before
? glyphs_before
: hb_set_get_empty ()),
204 input (glyphs_input
? glyphs_input
: hb_set_get_empty ()),
205 after (glyphs_after
? glyphs_after
: hb_set_get_empty ()),
206 output (glyphs_output
? glyphs_output
: hb_set_get_empty ()),
208 nesting_level_left (nesting_level_left_
),
211 void set_recurse_func (recurse_func_t func
) { recurse_func
= func
; }
216 struct hb_get_coverage_context_t
218 inline const char *get_name (void) { return "GET_COVERAGE"; }
219 static const unsigned int max_debug_depth
= 0;
220 typedef const Coverage
&return_t
;
221 template <typename T
>
222 inline return_t
dispatch (const T
&obj
) { return obj
.get_coverage (); }
223 static return_t
default_return_value (void) { return Null(Coverage
); }
225 hb_get_coverage_context_t (void) :
228 unsigned int debug_depth
;
233 #ifndef HB_DEBUG_APPLY
234 #define HB_DEBUG_APPLY (HB_DEBUG+0)
237 #define TRACE_APPLY(this) \
238 hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \
239 (&c->debug_depth, c->get_name (), this, HB_FUNC, \
240 "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
242 struct hb_apply_context_t
244 inline const char *get_name (void) { return "APPLY"; }
245 static const unsigned int max_debug_depth
= HB_DEBUG_APPLY
;
246 typedef bool return_t
;
247 typedef return_t (*recurse_func_t
) (hb_apply_context_t
*c
, unsigned int lookup_index
);
248 template <typename T
>
249 inline return_t
dispatch (const T
&obj
) { return obj
.apply (this); }
250 static return_t
default_return_value (void) { return false; }
251 bool stop_sublookup_iteration (return_t r
) const { return r
; }
252 return_t
recurse (unsigned int lookup_index
)
254 if (unlikely (nesting_level_left
== 0 || !recurse_func
))
255 return default_return_value ();
257 nesting_level_left
--;
258 bool ret
= recurse_func (this, lookup_index
);
259 nesting_level_left
++;
263 unsigned int table_index
; /* GSUB/GPOS */
267 hb_direction_t direction
;
268 hb_mask_t lookup_mask
;
270 recurse_func_t recurse_func
;
271 unsigned int nesting_level_left
;
272 unsigned int lookup_props
;
274 bool has_glyph_classes
;
275 unsigned int debug_depth
;
278 hb_apply_context_t (unsigned int table_index_
,
280 hb_buffer_t
*buffer_
) :
281 table_index (table_index_
),
282 font (font_
), face (font
->face
), buffer (buffer_
),
283 direction (buffer_
->props
.direction
),
287 nesting_level_left (MAX_NESTING_LEVEL
),
289 gdef (*hb_ot_layout_from_face (face
)->gdef
),
290 has_glyph_classes (gdef
.has_glyph_classes ()),
293 inline void set_lookup_mask (hb_mask_t mask
) { lookup_mask
= mask
; }
294 inline void set_auto_zwj (bool auto_zwj_
) { auto_zwj
= auto_zwj_
; }
295 inline void set_recurse_func (recurse_func_t func
) { recurse_func
= func
; }
296 inline void set_lookup_props (unsigned int lookup_props_
) { lookup_props
= lookup_props_
; }
297 inline void set_lookup (const Lookup
&l
) { lookup_props
= l
.get_props (); }
301 inline matcher_t (void) :
306 #define arg1(arg) (arg) /* Remove the macro to see why it's needed! */
310 match_data (NULL
) {};
312 typedef bool (*match_func_t
) (hb_codepoint_t glyph_id
, const USHORT
&value
, const void *data
);
314 inline void set_ignore_zwnj (bool ignore_zwnj_
) { ignore_zwnj
= ignore_zwnj_
; }
315 inline void set_ignore_zwj (bool ignore_zwj_
) { ignore_zwj
= ignore_zwj_
; }
316 inline void set_lookup_props (unsigned int lookup_props_
) { lookup_props
= lookup_props_
; }
317 inline void set_mask (hb_mask_t mask_
) { mask
= mask_
; }
318 inline void set_syllable (uint8_t syllable_
) { syllable
= syllable_
; }
319 inline void set_match_func (match_func_t match_func_
,
320 const void *match_data_
)
321 { match_func
= match_func_
; match_data
= match_data_
; }
329 inline may_match_t
may_match (const hb_glyph_info_t
&info
,
330 const USHORT
*glyph_data
) const
332 if (!(info
.mask
& mask
) ||
333 (syllable
&& syllable
!= info
.syllable ()))
337 return match_func (info
.codepoint
, *glyph_data
, match_data
) ? MATCH_YES
: MATCH_NO
;
349 may_skip (const hb_apply_context_t
*c
,
350 const hb_glyph_info_t
&info
) const
352 if (!c
->check_glyph_property (&info
, lookup_props
))
355 if (unlikely (_hb_glyph_info_is_default_ignorable (&info
) &&
356 (ignore_zwnj
|| !_hb_glyph_info_is_zwnj (&info
)) &&
357 (ignore_zwj
|| !_hb_glyph_info_is_zwj (&info
)) &&
358 !_hb_glyph_info_ligated (&info
)))
365 unsigned int lookup_props
;
370 match_func_t match_func
;
371 const void *match_data
;
374 struct skipping_forward_iterator_t
376 inline skipping_forward_iterator_t (hb_apply_context_t
*c_
,
377 unsigned int start_index_
,
378 unsigned int num_items_
,
379 bool context_match
= false) :
382 match_glyph_data (NULL
),
383 num_items (num_items_
),
386 matcher
.set_lookup_props (c
->lookup_props
);
387 /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
388 matcher
.set_ignore_zwnj (context_match
|| c
->table_index
== 1);
389 /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */
390 matcher
.set_ignore_zwj (context_match
|| c
->table_index
== 1 || c
->auto_zwj
);
392 matcher
.set_mask (c
->lookup_mask
);
393 matcher
.set_syllable (start_index_
== c
->buffer
->idx
? c
->buffer
->cur().syllable () : 0);
395 inline void set_lookup_props (unsigned int lookup_props
) { matcher
.set_lookup_props (lookup_props
); }
396 inline void set_syllable (unsigned int syllable
) { matcher
.set_syllable (syllable
); }
397 inline void set_match_func (matcher_t::match_func_t match_func
,
398 const void *match_data
,
399 const USHORT glyph_data
[])
401 matcher
.set_match_func (match_func
, match_data
);
402 match_glyph_data
= glyph_data
;
405 inline bool has_no_chance (void) const { return unlikely (num_items
&& idx
+ num_items
>= end
); }
406 inline void reject (void) { num_items
++; match_glyph_data
--; }
407 inline bool next (void)
409 assert (num_items
> 0);
410 while (!has_no_chance ())
413 const hb_glyph_info_t
&info
= c
->buffer
->info
[idx
];
415 matcher_t::may_skip_t skip
= matcher
.may_skip (c
, info
);
416 if (unlikely (skip
== matcher_t::SKIP_YES
))
419 matcher_t::may_match_t match
= matcher
.may_match (info
, match_glyph_data
);
420 if (match
== matcher_t::MATCH_YES
||
421 (match
== matcher_t::MATCH_MAYBE
&&
422 skip
== matcher_t::SKIP_NO
))
429 if (skip
== matcher_t::SKIP_NO
)
437 hb_apply_context_t
*c
;
439 const USHORT
*match_glyph_data
;
441 unsigned int num_items
;
445 struct skipping_backward_iterator_t
447 inline skipping_backward_iterator_t (hb_apply_context_t
*c_
,
448 unsigned int start_index_
,
449 unsigned int num_items_
,
450 bool context_match
= false) :
453 match_glyph_data (NULL
),
454 num_items (num_items_
)
456 matcher
.set_lookup_props (c
->lookup_props
);
457 /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
458 matcher
.set_ignore_zwnj (context_match
|| c
->table_index
== 1);
459 /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */
460 matcher
.set_ignore_zwj (context_match
|| c
->table_index
== 1 || c
->auto_zwj
);
462 matcher
.set_mask (c
->lookup_mask
);
463 matcher
.set_syllable (start_index_
== c
->buffer
->idx
? c
->buffer
->cur().syllable () : 0);
465 inline void set_lookup_props (unsigned int lookup_props
) { matcher
.set_lookup_props (lookup_props
); }
466 inline void set_syllable (unsigned int syllable
) { matcher
.set_syllable (syllable
); }
467 inline void set_match_func (matcher_t::match_func_t match_func
,
468 const void *match_data
,
469 const USHORT glyph_data
[])
471 matcher
.set_match_func (match_func
, match_data
);
472 match_glyph_data
= glyph_data
;
475 inline bool has_no_chance (void) const { return unlikely (idx
< num_items
); }
476 inline void reject (void) { num_items
++; }
477 inline bool prev (void)
479 assert (num_items
> 0);
480 while (!has_no_chance ())
483 const hb_glyph_info_t
&info
= c
->buffer
->out_info
[idx
];
485 matcher_t::may_skip_t skip
= matcher
.may_skip (c
, info
);
486 if (unlikely (skip
== matcher_t::SKIP_YES
))
489 matcher_t::may_match_t match
= matcher
.may_match (info
, match_glyph_data
);
490 if (match
== matcher_t::MATCH_YES
||
491 (match
== matcher_t::MATCH_MAYBE
&&
492 skip
== matcher_t::SKIP_NO
))
499 if (skip
== matcher_t::SKIP_NO
)
507 hb_apply_context_t
*c
;
509 const USHORT
*match_glyph_data
;
511 unsigned int num_items
;
515 match_properties_mark (hb_codepoint_t glyph
,
516 unsigned int glyph_props
,
517 unsigned int lookup_props
) const
519 /* If using mark filtering sets, the high short of
520 * lookup_props has the set index.
522 if (lookup_props
& LookupFlag::UseMarkFilteringSet
)
523 return gdef
.mark_set_covers (lookup_props
>> 16, glyph
);
525 /* The second byte of lookup_props has the meaning
526 * "ignore marks of attachment type different than
527 * the attachment type specified."
529 if (lookup_props
& LookupFlag::MarkAttachmentType
)
530 return (lookup_props
& LookupFlag::MarkAttachmentType
) == (glyph_props
& LookupFlag::MarkAttachmentType
);
536 check_glyph_property (const hb_glyph_info_t
*info
,
537 unsigned int lookup_props
) const
539 hb_codepoint_t glyph
= info
->codepoint
;
540 unsigned int glyph_props
= _hb_glyph_info_get_glyph_props (info
);
542 /* Not covered, if, for example, glyph class is ligature and
543 * lookup_props includes LookupFlags::IgnoreLigatures
545 if (glyph_props
& lookup_props
& LookupFlag::IgnoreFlags
)
548 if (unlikely (glyph_props
& HB_OT_LAYOUT_GLYPH_PROPS_MARK
))
549 return match_properties_mark (glyph
, glyph_props
, lookup_props
);
554 inline void _set_glyph_props (hb_codepoint_t glyph_index
,
555 unsigned int class_guess
= 0,
556 bool ligature
= false,
557 bool component
= false) const
559 unsigned int add_in
= _hb_glyph_info_get_glyph_props (&buffer
->cur()) &
560 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE
;
561 add_in
|= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED
;
564 add_in
|= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED
;
565 /* In the only place that the MULTIPLIED bit is used, Uniscribe
566 * seems to only care about the "last" transformation between
567 * Ligature and Multiple substitions. Ie. if you ligate, expand,
568 * and ligate again, it forgives the multiplication and acts as
569 * if only ligation happened. As such, clear MULTIPLIED bit.
571 add_in
&= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
;
574 add_in
|= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
;
575 if (likely (has_glyph_classes
))
576 _hb_glyph_info_set_glyph_props (&buffer
->cur(), add_in
| gdef
.get_glyph_props (glyph_index
));
577 else if (class_guess
)
578 _hb_glyph_info_set_glyph_props (&buffer
->cur(), add_in
| class_guess
);
581 inline void replace_glyph (hb_codepoint_t glyph_index
) const
583 _set_glyph_props (glyph_index
);
584 buffer
->replace_glyph (glyph_index
);
586 inline void replace_glyph_inplace (hb_codepoint_t glyph_index
) const
588 _set_glyph_props (glyph_index
);
589 buffer
->cur().codepoint
= glyph_index
;
591 inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index
,
592 unsigned int class_guess
) const
594 _set_glyph_props (glyph_index
, class_guess
, true);
595 buffer
->replace_glyph (glyph_index
);
597 inline void output_glyph_for_component (hb_codepoint_t glyph_index
,
598 unsigned int class_guess
) const
600 _set_glyph_props (glyph_index
, class_guess
, false, true);
601 buffer
->output_glyph (glyph_index
);
607 typedef bool (*intersects_func_t
) (hb_set_t
*glyphs
, const USHORT
&value
, const void *data
);
608 typedef void (*collect_glyphs_func_t
) (hb_set_t
*glyphs
, const USHORT
&value
, const void *data
);
609 typedef bool (*match_func_t
) (hb_codepoint_t glyph_id
, const USHORT
&value
, const void *data
);
611 struct ContextClosureFuncs
613 intersects_func_t intersects
;
615 struct ContextCollectGlyphsFuncs
617 collect_glyphs_func_t collect
;
619 struct ContextApplyFuncs
625 static inline bool intersects_glyph (hb_set_t
*glyphs
, const USHORT
&value
, const void *data HB_UNUSED
)
627 return glyphs
->has (value
);
629 static inline bool intersects_class (hb_set_t
*glyphs
, const USHORT
&value
, const void *data
)
631 const ClassDef
&class_def
= *reinterpret_cast<const ClassDef
*>(data
);
632 return class_def
.intersects_class (glyphs
, value
);
634 static inline bool intersects_coverage (hb_set_t
*glyphs
, const USHORT
&value
, const void *data
)
636 const OffsetTo
<Coverage
> &coverage
= (const OffsetTo
<Coverage
>&)value
;
637 return (data
+coverage
).intersects (glyphs
);
640 static inline bool intersects_array (hb_closure_context_t
*c
,
642 const USHORT values
[],
643 intersects_func_t intersects_func
,
644 const void *intersects_data
)
646 for (unsigned int i
= 0; i
< count
; i
++)
647 if (likely (!intersects_func (c
->glyphs
, values
[i
], intersects_data
)))
653 static inline void collect_glyph (hb_set_t
*glyphs
, const USHORT
&value
, const void *data HB_UNUSED
)
657 static inline void collect_class (hb_set_t
*glyphs
, const USHORT
&value
, const void *data
)
659 const ClassDef
&class_def
= *reinterpret_cast<const ClassDef
*>(data
);
660 class_def
.add_class (glyphs
, value
);
662 static inline void collect_coverage (hb_set_t
*glyphs
, const USHORT
&value
, const void *data
)
664 const OffsetTo
<Coverage
> &coverage
= (const OffsetTo
<Coverage
>&)value
;
665 (data
+coverage
).add_coverage (glyphs
);
667 static inline void collect_array (hb_collect_glyphs_context_t
*c HB_UNUSED
,
670 const USHORT values
[],
671 collect_glyphs_func_t collect_func
,
672 const void *collect_data
)
674 for (unsigned int i
= 0; i
< count
; i
++)
675 collect_func (glyphs
, values
[i
], collect_data
);
679 static inline bool match_glyph (hb_codepoint_t glyph_id
, const USHORT
&value
, const void *data HB_UNUSED
)
681 return glyph_id
== value
;
683 static inline bool match_class (hb_codepoint_t glyph_id
, const USHORT
&value
, const void *data
)
685 const ClassDef
&class_def
= *reinterpret_cast<const ClassDef
*>(data
);
686 return class_def
.get_class (glyph_id
) == value
;
688 static inline bool match_coverage (hb_codepoint_t glyph_id
, const USHORT
&value
, const void *data
)
690 const OffsetTo
<Coverage
> &coverage
= (const OffsetTo
<Coverage
>&)value
;
691 return (data
+coverage
).get_coverage (glyph_id
) != NOT_COVERED
;
694 static inline bool would_match_input (hb_would_apply_context_t
*c
,
695 unsigned int count
, /* Including the first glyph (not matched) */
696 const USHORT input
[], /* Array of input values--start with second glyph */
697 match_func_t match_func
,
698 const void *match_data
)
703 for (unsigned int i
= 1; i
< count
; i
++)
704 if (likely (!match_func (c
->glyphs
[i
], input
[i
- 1], match_data
)))
709 static inline bool match_input (hb_apply_context_t
*c
,
710 unsigned int count
, /* Including the first glyph (not matched) */
711 const USHORT input
[], /* Array of input values--start with second glyph */
712 match_func_t match_func
,
713 const void *match_data
,
714 unsigned int *end_offset
,
715 unsigned int match_positions
[MAX_CONTEXT_LENGTH
],
716 bool *p_is_mark_ligature
= NULL
,
717 unsigned int *p_total_component_count
= NULL
)
721 if (unlikely (count
> MAX_CONTEXT_LENGTH
)) TRACE_RETURN (false);
723 hb_buffer_t
*buffer
= c
->buffer
;
725 hb_apply_context_t::skipping_forward_iterator_t
skippy_iter (c
, buffer
->idx
, count
- 1);
726 skippy_iter
.set_match_func (match_func
, match_data
, input
);
727 if (skippy_iter
.has_no_chance ()) return TRACE_RETURN (false);
730 * This is perhaps the trickiest part of OpenType... Remarks:
732 * - If all components of the ligature were marks, we call this a mark ligature.
734 * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize
735 * it as a ligature glyph.
737 * - Ligatures cannot be formed across glyphs attached to different components
738 * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
739 * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother.
740 * However, it would be wrong to ligate that SHADDA,FATHA sequence.o
741 * There is an exception to this: If a ligature tries ligating with marks that
742 * belong to it itself, go ahead, assuming that the font designer knows what
743 * they are doing (otherwise it can break Indic stuff when a matra wants to
744 * ligate with a conjunct...)
747 bool is_mark_ligature
= _hb_glyph_info_is_mark (&buffer
->cur());
749 unsigned int total_component_count
= 0;
750 total_component_count
+= _hb_glyph_info_get_lig_num_comps (&buffer
->cur());
752 unsigned int first_lig_id
= _hb_glyph_info_get_lig_id (&buffer
->cur());
753 unsigned int first_lig_comp
= _hb_glyph_info_get_lig_comp (&buffer
->cur());
755 match_positions
[0] = buffer
->idx
;
756 for (unsigned int i
= 1; i
< count
; i
++)
758 if (!skippy_iter
.next ()) return TRACE_RETURN (false);
760 match_positions
[i
] = skippy_iter
.idx
;
762 unsigned int this_lig_id
= _hb_glyph_info_get_lig_id (&buffer
->info
[skippy_iter
.idx
]);
763 unsigned int this_lig_comp
= _hb_glyph_info_get_lig_comp (&buffer
->info
[skippy_iter
.idx
]);
765 if (first_lig_id
&& first_lig_comp
) {
766 /* If first component was attached to a previous ligature component,
767 * all subsequent components should be attached to the same ligature
768 * component, otherwise we shouldn't ligate them. */
769 if (first_lig_id
!= this_lig_id
|| first_lig_comp
!= this_lig_comp
)
770 return TRACE_RETURN (false);
772 /* If first component was NOT attached to a previous ligature component,
773 * all subsequent components should also NOT be attached to any ligature
774 * component, unless they are attached to the first component itself! */
775 if (this_lig_id
&& this_lig_comp
&& (this_lig_id
!= first_lig_id
))
776 return TRACE_RETURN (false);
779 is_mark_ligature
= is_mark_ligature
&& _hb_glyph_info_is_mark (&buffer
->info
[skippy_iter
.idx
]);
780 total_component_count
+= _hb_glyph_info_get_lig_num_comps (&buffer
->info
[skippy_iter
.idx
]);
783 *end_offset
= skippy_iter
.idx
- buffer
->idx
+ 1;
785 if (p_is_mark_ligature
)
786 *p_is_mark_ligature
= is_mark_ligature
;
788 if (p_total_component_count
)
789 *p_total_component_count
= total_component_count
;
791 return TRACE_RETURN (true);
793 static inline void ligate_input (hb_apply_context_t
*c
,
794 unsigned int count
, /* Including the first glyph */
795 unsigned int match_positions
[MAX_CONTEXT_LENGTH
], /* Including the first glyph */
796 unsigned int match_length
,
797 hb_codepoint_t lig_glyph
,
798 bool is_mark_ligature
,
799 unsigned int total_component_count
)
803 hb_buffer_t
*buffer
= c
->buffer
;
805 buffer
->merge_clusters (buffer
->idx
, buffer
->idx
+ match_length
);
808 * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
809 * the ligature to keep its old ligature id. This will allow it to attach to
810 * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
811 * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a
812 * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature
813 * later, we don't want them to lose their ligature id/component, otherwise
814 * GPOS will fail to correctly position the mark ligature on top of the
815 * LAM,LAM,HEH ligature. See:
816 * https://bugzilla.gnome.org/show_bug.cgi?id=676343
818 * - If a ligature is formed of components that some of which are also ligatures
819 * themselves, and those ligature components had marks attached to *their*
820 * components, we have to attach the marks to the new ligature component
821 * positions! Now *that*'s tricky! And these marks may be following the
822 * last component of the whole sequence, so we should loop forward looking
823 * for them and update them.
825 * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
826 * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
827 * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature
828 * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to
829 * the new ligature with a component value of 2.
831 * This in fact happened to a font... See:
832 * https://bugzilla.gnome.org/show_bug.cgi?id=437633
835 unsigned int klass
= is_mark_ligature
? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE
;
836 unsigned int lig_id
= is_mark_ligature
? 0 : _hb_allocate_lig_id (buffer
);
837 unsigned int last_lig_id
= _hb_glyph_info_get_lig_id (&buffer
->cur());
838 unsigned int last_num_components
= _hb_glyph_info_get_lig_num_comps (&buffer
->cur());
839 unsigned int components_so_far
= last_num_components
;
841 if (!is_mark_ligature
)
843 _hb_glyph_info_set_lig_props_for_ligature (&buffer
->cur(), lig_id
, total_component_count
);
844 if (_hb_glyph_info_get_general_category (&buffer
->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK
)
846 _hb_glyph_info_set_general_category (&buffer
->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER
);
847 _hb_glyph_info_set_modified_combining_class (&buffer
->cur(), 0);
850 c
->replace_glyph_with_ligature (lig_glyph
, klass
);
852 for (unsigned int i
= 1; i
< count
; i
++)
854 while (buffer
->idx
< match_positions
[i
])
856 if (!is_mark_ligature
) {
857 unsigned int new_lig_comp
= components_so_far
- last_num_components
+
858 MIN (MAX (_hb_glyph_info_get_lig_comp (&buffer
->cur()), 1u), last_num_components
);
859 _hb_glyph_info_set_lig_props_for_mark (&buffer
->cur(), lig_id
, new_lig_comp
);
861 buffer
->next_glyph ();
864 last_lig_id
= _hb_glyph_info_get_lig_id (&buffer
->cur());
865 last_num_components
= _hb_glyph_info_get_lig_num_comps (&buffer
->cur());
866 components_so_far
+= last_num_components
;
868 /* Skip the base glyph */
872 if (!is_mark_ligature
&& last_lig_id
) {
873 /* Re-adjust components for any marks following. */
874 for (unsigned int i
= buffer
->idx
; i
< buffer
->len
; i
++) {
875 if (last_lig_id
== _hb_glyph_info_get_lig_id (&buffer
->info
[i
])) {
876 unsigned int new_lig_comp
= components_so_far
- last_num_components
+
877 MIN (MAX (_hb_glyph_info_get_lig_comp (&buffer
->info
[i
]), 1u), last_num_components
);
878 _hb_glyph_info_set_lig_props_for_mark (&buffer
->info
[i
], lig_id
, new_lig_comp
);
886 static inline bool match_backtrack (hb_apply_context_t
*c
,
888 const USHORT backtrack
[],
889 match_func_t match_func
,
890 const void *match_data
)
894 hb_apply_context_t::skipping_backward_iterator_t
skippy_iter (c
, c
->buffer
->backtrack_len (), count
, true);
895 skippy_iter
.set_match_func (match_func
, match_data
, backtrack
);
896 if (skippy_iter
.has_no_chance ()) return TRACE_RETURN (false);
898 for (unsigned int i
= 0; i
< count
; i
++)
899 if (!skippy_iter
.prev ())
900 return TRACE_RETURN (false);
902 return TRACE_RETURN (true);
905 static inline bool match_lookahead (hb_apply_context_t
*c
,
907 const USHORT lookahead
[],
908 match_func_t match_func
,
909 const void *match_data
,
914 hb_apply_context_t::skipping_forward_iterator_t
skippy_iter (c
, c
->buffer
->idx
+ offset
- 1, count
, true);
915 skippy_iter
.set_match_func (match_func
, match_data
, lookahead
);
916 if (skippy_iter
.has_no_chance ()) return TRACE_RETURN (false);
918 for (unsigned int i
= 0; i
< count
; i
++)
919 if (!skippy_iter
.next ())
920 return TRACE_RETURN (false);
922 return TRACE_RETURN (true);
929 inline bool sanitize (hb_sanitize_context_t
*c
) {
930 TRACE_SANITIZE (this);
931 return TRACE_RETURN (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
[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
; i
++)
978 unsigned int idx
= lookupRecord
[i
].sequenceIndex
;
982 buffer
->move_to (match_positions
[idx
]);
984 unsigned int orig_len
= buffer
->backtrack_len () + buffer
->lookahead_len ();
985 if (!c
->recurse (lookupRecord
[i
].lookupListIndex
))
988 unsigned int new_len
= buffer
->backtrack_len () + buffer
->lookahead_len ();
989 int delta
= new_len
- orig_len
;
994 /* Recursed lookup changed buffer len. Adjust. */
996 /* end can't go back past the current match position.
997 * Note: this is only true because we do NOT allow MultipleSubst
998 * with zero sequence len. */
999 end
= MAX ((int) match_positions
[idx
] + 1, int (end
) + delta
);
1001 unsigned int next
= idx
+ 1; /* next now is the position after the recursed lookup. */
1005 if (unlikely (delta
+ count
> MAX_CONTEXT_LENGTH
))
1010 /* NOTE: delta is negative. */
1011 delta
= MAX (delta
, (int) next
- (int) count
);
1016 memmove (match_positions
+ next
+ delta
, match_positions
+ next
,
1017 (count
- next
) * sizeof (match_positions
[0]));
1021 /* Fill in new entries. */
1022 for (unsigned int j
= idx
+ 1; j
< next
; j
++)
1023 match_positions
[j
] = match_positions
[j
- 1] + 1;
1025 /* And fixup the rest. */
1026 for (; next
< count
; next
++)
1027 match_positions
[next
] += delta
;
1030 buffer
->move_to (end
);
1032 return TRACE_RETURN (true);
1037 /* Contextual lookups */
1039 struct ContextClosureLookupContext
1041 ContextClosureFuncs funcs
;
1042 const void *intersects_data
;
1045 struct ContextCollectGlyphsLookupContext
1047 ContextCollectGlyphsFuncs funcs
;
1048 const void *collect_data
;
1051 struct ContextApplyLookupContext
1053 ContextApplyFuncs funcs
;
1054 const void *match_data
;
1057 static inline void context_closure_lookup (hb_closure_context_t
*c
,
1058 unsigned int inputCount
, /* Including the first glyph (not matched) */
1059 const USHORT input
[], /* Array of input values--start with second glyph */
1060 unsigned int lookupCount
,
1061 const LookupRecord lookupRecord
[],
1062 ContextClosureLookupContext
&lookup_context
)
1064 if (intersects_array (c
,
1065 inputCount
? inputCount
- 1 : 0, input
,
1066 lookup_context
.funcs
.intersects
, lookup_context
.intersects_data
))
1068 lookupCount
, lookupRecord
);
1071 static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t
*c
,
1072 unsigned int inputCount
, /* Including the first glyph (not matched) */
1073 const USHORT input
[], /* Array of input values--start with second glyph */
1074 unsigned int lookupCount
,
1075 const LookupRecord lookupRecord
[],
1076 ContextCollectGlyphsLookupContext
&lookup_context
)
1078 collect_array (c
, c
->input
,
1079 inputCount
? inputCount
- 1 : 0, input
,
1080 lookup_context
.funcs
.collect
, lookup_context
.collect_data
);
1082 lookupCount
, lookupRecord
);
1085 static inline bool context_would_apply_lookup (hb_would_apply_context_t
*c
,
1086 unsigned int inputCount
, /* Including the first glyph (not matched) */
1087 const USHORT input
[], /* Array of input values--start with second glyph */
1088 unsigned int lookupCount HB_UNUSED
,
1089 const LookupRecord lookupRecord
[] HB_UNUSED
,
1090 ContextApplyLookupContext
&lookup_context
)
1092 return would_match_input (c
,
1094 lookup_context
.funcs
.match
, lookup_context
.match_data
);
1096 static inline bool context_apply_lookup (hb_apply_context_t
*c
,
1097 unsigned int inputCount
, /* Including the first glyph (not matched) */
1098 const USHORT input
[], /* Array of input values--start with second glyph */
1099 unsigned int lookupCount
,
1100 const LookupRecord lookupRecord
[],
1101 ContextApplyLookupContext
&lookup_context
)
1103 unsigned int match_length
= 0;
1104 unsigned int match_positions
[MAX_CONTEXT_LENGTH
];
1105 return match_input (c
,
1107 lookup_context
.funcs
.match
, lookup_context
.match_data
,
1108 &match_length
, match_positions
)
1110 inputCount
, match_positions
,
1111 lookupCount
, lookupRecord
,
1117 inline void closure (hb_closure_context_t
*c
, ContextClosureLookupContext
&lookup_context
) const
1119 TRACE_CLOSURE (this);
1120 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (input
, input
[0].static_size
* (inputCount
? inputCount
- 1 : 0));
1121 context_closure_lookup (c
,
1123 lookupCount
, lookupRecord
,
1127 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
, ContextCollectGlyphsLookupContext
&lookup_context
) const
1129 TRACE_COLLECT_GLYPHS (this);
1130 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (input
, input
[0].static_size
* (inputCount
? inputCount
- 1 : 0));
1131 context_collect_glyphs_lookup (c
,
1133 lookupCount
, lookupRecord
,
1137 inline bool would_apply (hb_would_apply_context_t
*c
, ContextApplyLookupContext
&lookup_context
) const
1139 TRACE_WOULD_APPLY (this);
1140 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (input
, input
[0].static_size
* (inputCount
? inputCount
- 1 : 0));
1141 return TRACE_RETURN (context_would_apply_lookup (c
, inputCount
, input
, lookupCount
, lookupRecord
, lookup_context
));
1144 inline bool apply (hb_apply_context_t
*c
, ContextApplyLookupContext
&lookup_context
) const
1147 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (input
, input
[0].static_size
* (inputCount
? inputCount
- 1 : 0));
1148 return TRACE_RETURN (context_apply_lookup (c
, inputCount
, input
, lookupCount
, lookupRecord
, lookup_context
));
1152 inline bool sanitize (hb_sanitize_context_t
*c
) {
1153 TRACE_SANITIZE (this);
1154 return inputCount
.sanitize (c
)
1155 && lookupCount
.sanitize (c
)
1156 && c
->check_range (input
,
1157 input
[0].static_size
* inputCount
1158 + lookupRecordX
[0].static_size
* lookupCount
);
1162 USHORT inputCount
; /* Total number of glyphs in input
1163 * glyph sequence--includes the first
1165 USHORT lookupCount
; /* Number of LookupRecords */
1166 USHORT input
[VAR
]; /* Array of match inputs--start with
1168 LookupRecord lookupRecordX
[VAR
]; /* Array of LookupRecords--in
1171 DEFINE_SIZE_ARRAY2 (4, input
, lookupRecordX
);
1176 inline void closure (hb_closure_context_t
*c
, ContextClosureLookupContext
&lookup_context
) const
1178 TRACE_CLOSURE (this);
1179 unsigned int num_rules
= rule
.len
;
1180 for (unsigned int i
= 0; i
< num_rules
; i
++)
1181 (this+rule
[i
]).closure (c
, lookup_context
);
1184 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
, ContextCollectGlyphsLookupContext
&lookup_context
) const
1186 TRACE_COLLECT_GLYPHS (this);
1187 unsigned int num_rules
= rule
.len
;
1188 for (unsigned int i
= 0; i
< num_rules
; i
++)
1189 (this+rule
[i
]).collect_glyphs (c
, lookup_context
);
1192 inline bool would_apply (hb_would_apply_context_t
*c
, ContextApplyLookupContext
&lookup_context
) const
1194 TRACE_WOULD_APPLY (this);
1195 unsigned int num_rules
= rule
.len
;
1196 for (unsigned int i
= 0; i
< num_rules
; i
++)
1198 if ((this+rule
[i
]).would_apply (c
, lookup_context
))
1199 return TRACE_RETURN (true);
1201 return TRACE_RETURN (false);
1204 inline bool apply (hb_apply_context_t
*c
, ContextApplyLookupContext
&lookup_context
) const
1207 unsigned int num_rules
= rule
.len
;
1208 for (unsigned int i
= 0; i
< num_rules
; i
++)
1210 if ((this+rule
[i
]).apply (c
, lookup_context
))
1211 return TRACE_RETURN (true);
1213 return TRACE_RETURN (false);
1216 inline bool sanitize (hb_sanitize_context_t
*c
) {
1217 TRACE_SANITIZE (this);
1218 return TRACE_RETURN (rule
.sanitize (c
, this));
1223 rule
; /* Array of Rule tables
1224 * ordered by preference */
1226 DEFINE_SIZE_ARRAY (2, rule
);
1230 struct ContextFormat1
1232 inline void closure (hb_closure_context_t
*c
) const
1234 TRACE_CLOSURE (this);
1236 const Coverage
&cov
= (this+coverage
);
1238 struct ContextClosureLookupContext lookup_context
= {
1243 unsigned int count
= ruleSet
.len
;
1244 for (unsigned int i
= 0; i
< count
; i
++)
1245 if (cov
.intersects_coverage (c
->glyphs
, i
)) {
1246 const RuleSet
&rule_set
= this+ruleSet
[i
];
1247 rule_set
.closure (c
, lookup_context
);
1251 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
) const
1253 TRACE_COLLECT_GLYPHS (this);
1254 (this+coverage
).add_coverage (c
->input
);
1256 struct ContextCollectGlyphsLookupContext lookup_context
= {
1261 unsigned int count
= ruleSet
.len
;
1262 for (unsigned int i
= 0; i
< count
; i
++)
1263 (this+ruleSet
[i
]).collect_glyphs (c
, lookup_context
);
1266 inline bool would_apply (hb_would_apply_context_t
*c
) const
1268 TRACE_WOULD_APPLY (this);
1270 const RuleSet
&rule_set
= this+ruleSet
[(this+coverage
).get_coverage (c
->glyphs
[0])];
1271 struct ContextApplyLookupContext lookup_context
= {
1275 return TRACE_RETURN (rule_set
.would_apply (c
, lookup_context
));
1278 inline const Coverage
&get_coverage (void) const
1280 return this+coverage
;
1283 inline bool apply (hb_apply_context_t
*c
) const
1286 unsigned int index
= (this+coverage
).get_coverage (c
->buffer
->cur().codepoint
);
1287 if (likely (index
== NOT_COVERED
))
1288 return TRACE_RETURN (false);
1290 const RuleSet
&rule_set
= this+ruleSet
[index
];
1291 struct ContextApplyLookupContext lookup_context
= {
1295 return TRACE_RETURN (rule_set
.apply (c
, lookup_context
));
1298 inline bool sanitize (hb_sanitize_context_t
*c
) {
1299 TRACE_SANITIZE (this);
1300 return TRACE_RETURN (coverage
.sanitize (c
, this) && ruleSet
.sanitize (c
, this));
1304 USHORT format
; /* Format identifier--format = 1 */
1306 coverage
; /* Offset to Coverage table--from
1307 * beginning of table */
1308 OffsetArrayOf
<RuleSet
>
1309 ruleSet
; /* Array of RuleSet tables
1310 * ordered by Coverage Index */
1312 DEFINE_SIZE_ARRAY (6, ruleSet
);
1316 struct ContextFormat2
1318 inline void closure (hb_closure_context_t
*c
) const
1320 TRACE_CLOSURE (this);
1321 if (!(this+coverage
).intersects (c
->glyphs
))
1324 const ClassDef
&class_def
= this+classDef
;
1326 struct ContextClosureLookupContext lookup_context
= {
1331 unsigned int count
= ruleSet
.len
;
1332 for (unsigned int i
= 0; i
< count
; i
++)
1333 if (class_def
.intersects_class (c
->glyphs
, i
)) {
1334 const RuleSet
&rule_set
= this+ruleSet
[i
];
1335 rule_set
.closure (c
, lookup_context
);
1339 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
) const
1341 TRACE_COLLECT_GLYPHS (this);
1342 (this+coverage
).add_coverage (c
->input
);
1344 const ClassDef
&class_def
= this+classDef
;
1345 struct ContextCollectGlyphsLookupContext lookup_context
= {
1350 unsigned int count
= ruleSet
.len
;
1351 for (unsigned int i
= 0; i
< count
; i
++)
1352 (this+ruleSet
[i
]).collect_glyphs (c
, lookup_context
);
1355 inline bool would_apply (hb_would_apply_context_t
*c
) const
1357 TRACE_WOULD_APPLY (this);
1359 const ClassDef
&class_def
= this+classDef
;
1360 unsigned int index
= class_def
.get_class (c
->glyphs
[0]);
1361 const RuleSet
&rule_set
= this+ruleSet
[index
];
1362 struct ContextApplyLookupContext lookup_context
= {
1366 return TRACE_RETURN (rule_set
.would_apply (c
, lookup_context
));
1369 inline const Coverage
&get_coverage (void) const
1371 return this+coverage
;
1374 inline bool apply (hb_apply_context_t
*c
) const
1377 unsigned int index
= (this+coverage
).get_coverage (c
->buffer
->cur().codepoint
);
1378 if (likely (index
== NOT_COVERED
)) return TRACE_RETURN (false);
1380 const ClassDef
&class_def
= this+classDef
;
1381 index
= class_def
.get_class (c
->buffer
->cur().codepoint
);
1382 const RuleSet
&rule_set
= this+ruleSet
[index
];
1383 struct ContextApplyLookupContext lookup_context
= {
1387 return TRACE_RETURN (rule_set
.apply (c
, lookup_context
));
1390 inline bool sanitize (hb_sanitize_context_t
*c
) {
1391 TRACE_SANITIZE (this);
1392 return TRACE_RETURN (coverage
.sanitize (c
, this) && classDef
.sanitize (c
, this) && ruleSet
.sanitize (c
, this));
1396 USHORT format
; /* Format identifier--format = 2 */
1398 coverage
; /* Offset to Coverage table--from
1399 * beginning of table */
1401 classDef
; /* Offset to glyph ClassDef table--from
1402 * beginning of table */
1403 OffsetArrayOf
<RuleSet
>
1404 ruleSet
; /* Array of RuleSet tables
1405 * ordered by class */
1407 DEFINE_SIZE_ARRAY (8, ruleSet
);
1411 struct ContextFormat3
1413 inline void closure (hb_closure_context_t
*c
) const
1415 TRACE_CLOSURE (this);
1416 if (!(this+coverage
[0]).intersects (c
->glyphs
))
1419 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (coverage
, coverage
[0].static_size
* glyphCount
);
1420 struct ContextClosureLookupContext lookup_context
= {
1421 {intersects_coverage
},
1424 context_closure_lookup (c
,
1425 glyphCount
, (const USHORT
*) (coverage
+ 1),
1426 lookupCount
, lookupRecord
,
1430 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
) const
1432 TRACE_COLLECT_GLYPHS (this);
1433 (this+coverage
[0]).add_coverage (c
->input
);
1435 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (coverage
, coverage
[0].static_size
* glyphCount
);
1436 struct ContextCollectGlyphsLookupContext lookup_context
= {
1441 context_collect_glyphs_lookup (c
,
1442 glyphCount
, (const USHORT
*) (coverage
+ 1),
1443 lookupCount
, lookupRecord
,
1447 inline bool would_apply (hb_would_apply_context_t
*c
) const
1449 TRACE_WOULD_APPLY (this);
1451 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (coverage
, coverage
[0].static_size
* glyphCount
);
1452 struct ContextApplyLookupContext lookup_context
= {
1456 return TRACE_RETURN (context_would_apply_lookup (c
, glyphCount
, (const USHORT
*) (coverage
+ 1), lookupCount
, lookupRecord
, lookup_context
));
1459 inline const Coverage
&get_coverage (void) const
1461 return this+coverage
[0];
1464 inline bool apply (hb_apply_context_t
*c
) const
1467 unsigned int index
= (this+coverage
[0]).get_coverage (c
->buffer
->cur().codepoint
);
1468 if (likely (index
== NOT_COVERED
)) return TRACE_RETURN (false);
1470 const LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (coverage
, coverage
[0].static_size
* glyphCount
);
1471 struct ContextApplyLookupContext lookup_context
= {
1475 return TRACE_RETURN (context_apply_lookup (c
, glyphCount
, (const USHORT
*) (coverage
+ 1), lookupCount
, lookupRecord
, lookup_context
));
1478 inline bool sanitize (hb_sanitize_context_t
*c
) {
1479 TRACE_SANITIZE (this);
1480 if (!c
->check_struct (this)) return TRACE_RETURN (false);
1481 unsigned int count
= glyphCount
;
1482 if (!c
->check_array (coverage
, coverage
[0].static_size
, count
)) return TRACE_RETURN (false);
1483 for (unsigned int i
= 0; i
< count
; i
++)
1484 if (!coverage
[i
].sanitize (c
, this)) return TRACE_RETURN (false);
1485 LookupRecord
*lookupRecord
= &StructAtOffset
<LookupRecord
> (coverage
, coverage
[0].static_size
* count
);
1486 return TRACE_RETURN (c
->check_array (lookupRecord
, lookupRecord
[0].static_size
, lookupCount
));
1490 USHORT format
; /* Format identifier--format = 3 */
1491 USHORT glyphCount
; /* Number of glyphs in the input glyph
1493 USHORT lookupCount
; /* Number of LookupRecords */
1495 coverage
[VAR
]; /* Array of offsets to Coverage
1496 * table in glyph sequence order */
1497 LookupRecord lookupRecordX
[VAR
]; /* Array of LookupRecords--in
1500 DEFINE_SIZE_ARRAY2 (6, coverage
, lookupRecordX
);
1505 template <typename context_t
>
1506 inline typename
context_t::return_t
dispatch (context_t
*c
) const
1508 TRACE_DISPATCH (this);
1510 case 1: return TRACE_RETURN (c
->dispatch (u
.format1
));
1511 case 2: return TRACE_RETURN (c
->dispatch (u
.format2
));
1512 case 3: return TRACE_RETURN (c
->dispatch (u
.format3
));
1513 default:return TRACE_RETURN (c
->default_return_value ());
1517 inline bool sanitize (hb_sanitize_context_t
*c
) {
1518 TRACE_SANITIZE (this);
1519 if (!u
.format
.sanitize (c
)) return TRACE_RETURN (false);
1521 case 1: return TRACE_RETURN (u
.format1
.sanitize (c
));
1522 case 2: return TRACE_RETURN (u
.format2
.sanitize (c
));
1523 case 3: return TRACE_RETURN (u
.format3
.sanitize (c
));
1524 default:return TRACE_RETURN (true);
1530 USHORT format
; /* Format identifier */
1531 ContextFormat1 format1
;
1532 ContextFormat2 format2
;
1533 ContextFormat3 format3
;
1538 /* Chaining Contextual lookups */
1540 struct ChainContextClosureLookupContext
1542 ContextClosureFuncs funcs
;
1543 const void *intersects_data
[3];
1546 struct ChainContextCollectGlyphsLookupContext
1548 ContextCollectGlyphsFuncs funcs
;
1549 const void *collect_data
[3];
1552 struct ChainContextApplyLookupContext
1554 ContextApplyFuncs funcs
;
1555 const void *match_data
[3];
1558 static inline void chain_context_closure_lookup (hb_closure_context_t
*c
,
1559 unsigned int backtrackCount
,
1560 const USHORT backtrack
[],
1561 unsigned int inputCount
, /* Including the first glyph (not matched) */
1562 const USHORT input
[], /* Array of input values--start with second glyph */
1563 unsigned int lookaheadCount
,
1564 const USHORT lookahead
[],
1565 unsigned int lookupCount
,
1566 const LookupRecord lookupRecord
[],
1567 ChainContextClosureLookupContext
&lookup_context
)
1569 if (intersects_array (c
,
1570 backtrackCount
, backtrack
,
1571 lookup_context
.funcs
.intersects
, lookup_context
.intersects_data
[0])
1572 && intersects_array (c
,
1573 inputCount
? inputCount
- 1 : 0, input
,
1574 lookup_context
.funcs
.intersects
, lookup_context
.intersects_data
[1])
1575 && intersects_array (c
,
1576 lookaheadCount
, lookahead
,
1577 lookup_context
.funcs
.intersects
, lookup_context
.intersects_data
[2]))
1579 lookupCount
, lookupRecord
);
1582 static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t
*c
,
1583 unsigned int backtrackCount
,
1584 const USHORT backtrack
[],
1585 unsigned int inputCount
, /* Including the first glyph (not matched) */
1586 const USHORT input
[], /* Array of input values--start with second glyph */
1587 unsigned int lookaheadCount
,
1588 const USHORT lookahead
[],
1589 unsigned int lookupCount
,
1590 const LookupRecord lookupRecord
[],
1591 ChainContextCollectGlyphsLookupContext
&lookup_context
)
1593 collect_array (c
, c
->before
,
1594 backtrackCount
, backtrack
,
1595 lookup_context
.funcs
.collect
, lookup_context
.collect_data
[0]);
1596 collect_array (c
, c
->input
,
1597 inputCount
? inputCount
- 1 : 0, input
,
1598 lookup_context
.funcs
.collect
, lookup_context
.collect_data
[1]);
1599 collect_array (c
, c
->after
,
1600 lookaheadCount
, lookahead
,
1601 lookup_context
.funcs
.collect
, lookup_context
.collect_data
[2]);
1603 lookupCount
, lookupRecord
);
1606 static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t
*c
,
1607 unsigned int backtrackCount
,
1608 const USHORT backtrack
[] HB_UNUSED
,
1609 unsigned int inputCount
, /* Including the first glyph (not matched) */
1610 const USHORT input
[], /* Array of input values--start with second glyph */
1611 unsigned int lookaheadCount
,
1612 const USHORT lookahead
[] HB_UNUSED
,
1613 unsigned int lookupCount HB_UNUSED
,
1614 const LookupRecord lookupRecord
[] HB_UNUSED
,
1615 ChainContextApplyLookupContext
&lookup_context
)
1617 return (c
->zero_context
? !backtrackCount
&& !lookaheadCount
: true)
1618 && would_match_input (c
,
1620 lookup_context
.funcs
.match
, lookup_context
.match_data
[1]);
1623 static inline bool chain_context_apply_lookup (hb_apply_context_t
*c
,
1624 unsigned int backtrackCount
,
1625 const USHORT backtrack
[],
1626 unsigned int inputCount
, /* Including the first glyph (not matched) */
1627 const USHORT input
[], /* Array of input values--start with second glyph */
1628 unsigned int lookaheadCount
,
1629 const USHORT lookahead
[],
1630 unsigned int lookupCount
,
1631 const LookupRecord lookupRecord
[],
1632 ChainContextApplyLookupContext
&lookup_context
)
1634 unsigned int match_length
= 0;
1635 unsigned int match_positions
[MAX_CONTEXT_LENGTH
];
1636 return match_input (c
,
1638 lookup_context
.funcs
.match
, lookup_context
.match_data
[1],
1639 &match_length
, match_positions
)
1640 && match_backtrack (c
,
1641 backtrackCount
, backtrack
,
1642 lookup_context
.funcs
.match
, lookup_context
.match_data
[0])
1643 && match_lookahead (c
,
1644 lookaheadCount
, lookahead
,
1645 lookup_context
.funcs
.match
, lookup_context
.match_data
[2],
1648 inputCount
, match_positions
,
1649 lookupCount
, lookupRecord
,
1655 inline void closure (hb_closure_context_t
*c
, ChainContextClosureLookupContext
&lookup_context
) const
1657 TRACE_CLOSURE (this);
1658 const HeadlessArrayOf
<USHORT
> &input
= StructAfter
<HeadlessArrayOf
<USHORT
> > (backtrack
);
1659 const ArrayOf
<USHORT
> &lookahead
= StructAfter
<ArrayOf
<USHORT
> > (input
);
1660 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
1661 chain_context_closure_lookup (c
,
1662 backtrack
.len
, backtrack
.array
,
1663 input
.len
, input
.array
,
1664 lookahead
.len
, lookahead
.array
,
1665 lookup
.len
, lookup
.array
,
1669 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
, ChainContextCollectGlyphsLookupContext
&lookup_context
) const
1671 TRACE_COLLECT_GLYPHS (this);
1672 const HeadlessArrayOf
<USHORT
> &input
= StructAfter
<HeadlessArrayOf
<USHORT
> > (backtrack
);
1673 const ArrayOf
<USHORT
> &lookahead
= StructAfter
<ArrayOf
<USHORT
> > (input
);
1674 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
1675 chain_context_collect_glyphs_lookup (c
,
1676 backtrack
.len
, backtrack
.array
,
1677 input
.len
, input
.array
,
1678 lookahead
.len
, lookahead
.array
,
1679 lookup
.len
, lookup
.array
,
1683 inline bool would_apply (hb_would_apply_context_t
*c
, ChainContextApplyLookupContext
&lookup_context
) const
1685 TRACE_WOULD_APPLY (this);
1686 const HeadlessArrayOf
<USHORT
> &input
= StructAfter
<HeadlessArrayOf
<USHORT
> > (backtrack
);
1687 const ArrayOf
<USHORT
> &lookahead
= StructAfter
<ArrayOf
<USHORT
> > (input
);
1688 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
1689 return TRACE_RETURN (chain_context_would_apply_lookup (c
,
1690 backtrack
.len
, backtrack
.array
,
1691 input
.len
, input
.array
,
1692 lookahead
.len
, lookahead
.array
, lookup
.len
,
1693 lookup
.array
, lookup_context
));
1696 inline bool apply (hb_apply_context_t
*c
, ChainContextApplyLookupContext
&lookup_context
) const
1699 const HeadlessArrayOf
<USHORT
> &input
= StructAfter
<HeadlessArrayOf
<USHORT
> > (backtrack
);
1700 const ArrayOf
<USHORT
> &lookahead
= StructAfter
<ArrayOf
<USHORT
> > (input
);
1701 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
1702 return TRACE_RETURN (chain_context_apply_lookup (c
,
1703 backtrack
.len
, backtrack
.array
,
1704 input
.len
, input
.array
,
1705 lookahead
.len
, lookahead
.array
, lookup
.len
,
1706 lookup
.array
, lookup_context
));
1709 inline bool sanitize (hb_sanitize_context_t
*c
) {
1710 TRACE_SANITIZE (this);
1711 if (!backtrack
.sanitize (c
)) return TRACE_RETURN (false);
1712 HeadlessArrayOf
<USHORT
> &input
= StructAfter
<HeadlessArrayOf
<USHORT
> > (backtrack
);
1713 if (!input
.sanitize (c
)) return TRACE_RETURN (false);
1714 ArrayOf
<USHORT
> &lookahead
= StructAfter
<ArrayOf
<USHORT
> > (input
);
1715 if (!lookahead
.sanitize (c
)) return TRACE_RETURN (false);
1716 ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
1717 return TRACE_RETURN (lookup
.sanitize (c
));
1722 backtrack
; /* Array of backtracking values
1723 * (to be matched before the input
1725 HeadlessArrayOf
<USHORT
>
1726 inputX
; /* Array of input values (start with
1729 lookaheadX
; /* Array of lookahead values's (to be
1730 * matched after the input sequence) */
1731 ArrayOf
<LookupRecord
>
1732 lookupX
; /* Array of LookupRecords--in
1735 DEFINE_SIZE_MIN (8);
1740 inline void closure (hb_closure_context_t
*c
, ChainContextClosureLookupContext
&lookup_context
) const
1742 TRACE_CLOSURE (this);
1743 unsigned int num_rules
= rule
.len
;
1744 for (unsigned int i
= 0; i
< num_rules
; i
++)
1745 (this+rule
[i
]).closure (c
, lookup_context
);
1748 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
, ChainContextCollectGlyphsLookupContext
&lookup_context
) const
1750 TRACE_COLLECT_GLYPHS (this);
1751 unsigned int num_rules
= rule
.len
;
1752 for (unsigned int i
= 0; i
< num_rules
; i
++)
1753 (this+rule
[i
]).collect_glyphs (c
, lookup_context
);
1756 inline bool would_apply (hb_would_apply_context_t
*c
, ChainContextApplyLookupContext
&lookup_context
) const
1758 TRACE_WOULD_APPLY (this);
1759 unsigned int num_rules
= rule
.len
;
1760 for (unsigned int i
= 0; i
< num_rules
; i
++)
1761 if ((this+rule
[i
]).would_apply (c
, lookup_context
))
1762 return TRACE_RETURN (true);
1764 return TRACE_RETURN (false);
1767 inline bool apply (hb_apply_context_t
*c
, ChainContextApplyLookupContext
&lookup_context
) const
1770 unsigned int num_rules
= rule
.len
;
1771 for (unsigned int i
= 0; i
< num_rules
; i
++)
1772 if ((this+rule
[i
]).apply (c
, lookup_context
))
1773 return TRACE_RETURN (true);
1775 return TRACE_RETURN (false);
1778 inline bool sanitize (hb_sanitize_context_t
*c
) {
1779 TRACE_SANITIZE (this);
1780 return TRACE_RETURN (rule
.sanitize (c
, this));
1784 OffsetArrayOf
<ChainRule
>
1785 rule
; /* Array of ChainRule tables
1786 * ordered by preference */
1788 DEFINE_SIZE_ARRAY (2, rule
);
1791 struct ChainContextFormat1
1793 inline void closure (hb_closure_context_t
*c
) const
1795 TRACE_CLOSURE (this);
1796 const Coverage
&cov
= (this+coverage
);
1798 struct ChainContextClosureLookupContext lookup_context
= {
1803 unsigned int count
= ruleSet
.len
;
1804 for (unsigned int i
= 0; i
< count
; i
++)
1805 if (cov
.intersects_coverage (c
->glyphs
, i
)) {
1806 const ChainRuleSet
&rule_set
= this+ruleSet
[i
];
1807 rule_set
.closure (c
, lookup_context
);
1811 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
) const
1813 TRACE_COLLECT_GLYPHS (this);
1814 (this+coverage
).add_coverage (c
->input
);
1816 struct ChainContextCollectGlyphsLookupContext lookup_context
= {
1821 unsigned int count
= ruleSet
.len
;
1822 for (unsigned int i
= 0; i
< count
; i
++)
1823 (this+ruleSet
[i
]).collect_glyphs (c
, lookup_context
);
1826 inline bool would_apply (hb_would_apply_context_t
*c
) const
1828 TRACE_WOULD_APPLY (this);
1830 const ChainRuleSet
&rule_set
= this+ruleSet
[(this+coverage
).get_coverage (c
->glyphs
[0])];
1831 struct ChainContextApplyLookupContext lookup_context
= {
1835 return TRACE_RETURN (rule_set
.would_apply (c
, lookup_context
));
1838 inline const Coverage
&get_coverage (void) const
1840 return this+coverage
;
1843 inline bool apply (hb_apply_context_t
*c
) const
1846 unsigned int index
= (this+coverage
).get_coverage (c
->buffer
->cur().codepoint
);
1847 if (likely (index
== NOT_COVERED
)) return TRACE_RETURN (false);
1849 const ChainRuleSet
&rule_set
= this+ruleSet
[index
];
1850 struct ChainContextApplyLookupContext lookup_context
= {
1854 return TRACE_RETURN (rule_set
.apply (c
, lookup_context
));
1857 inline bool sanitize (hb_sanitize_context_t
*c
) {
1858 TRACE_SANITIZE (this);
1859 return TRACE_RETURN (coverage
.sanitize (c
, this) && ruleSet
.sanitize (c
, this));
1863 USHORT format
; /* Format identifier--format = 1 */
1865 coverage
; /* Offset to Coverage table--from
1866 * beginning of table */
1867 OffsetArrayOf
<ChainRuleSet
>
1868 ruleSet
; /* Array of ChainRuleSet tables
1869 * ordered by Coverage Index */
1871 DEFINE_SIZE_ARRAY (6, ruleSet
);
1874 struct ChainContextFormat2
1876 inline void closure (hb_closure_context_t
*c
) const
1878 TRACE_CLOSURE (this);
1879 if (!(this+coverage
).intersects (c
->glyphs
))
1882 const ClassDef
&backtrack_class_def
= this+backtrackClassDef
;
1883 const ClassDef
&input_class_def
= this+inputClassDef
;
1884 const ClassDef
&lookahead_class_def
= this+lookaheadClassDef
;
1886 struct ChainContextClosureLookupContext lookup_context
= {
1888 {&backtrack_class_def
,
1890 &lookahead_class_def
}
1893 unsigned int count
= ruleSet
.len
;
1894 for (unsigned int i
= 0; i
< count
; i
++)
1895 if (input_class_def
.intersects_class (c
->glyphs
, i
)) {
1896 const ChainRuleSet
&rule_set
= this+ruleSet
[i
];
1897 rule_set
.closure (c
, lookup_context
);
1901 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
) const
1903 TRACE_COLLECT_GLYPHS (this);
1904 (this+coverage
).add_coverage (c
->input
);
1906 const ClassDef
&backtrack_class_def
= this+backtrackClassDef
;
1907 const ClassDef
&input_class_def
= this+inputClassDef
;
1908 const ClassDef
&lookahead_class_def
= this+lookaheadClassDef
;
1910 struct ChainContextCollectGlyphsLookupContext lookup_context
= {
1912 {&backtrack_class_def
,
1914 &lookahead_class_def
}
1917 unsigned int count
= ruleSet
.len
;
1918 for (unsigned int i
= 0; i
< count
; i
++)
1919 (this+ruleSet
[i
]).collect_glyphs (c
, lookup_context
);
1922 inline bool would_apply (hb_would_apply_context_t
*c
) const
1924 TRACE_WOULD_APPLY (this);
1926 const ClassDef
&backtrack_class_def
= this+backtrackClassDef
;
1927 const ClassDef
&input_class_def
= this+inputClassDef
;
1928 const ClassDef
&lookahead_class_def
= this+lookaheadClassDef
;
1930 unsigned int index
= input_class_def
.get_class (c
->glyphs
[0]);
1931 const ChainRuleSet
&rule_set
= this+ruleSet
[index
];
1932 struct ChainContextApplyLookupContext lookup_context
= {
1934 {&backtrack_class_def
,
1936 &lookahead_class_def
}
1938 return TRACE_RETURN (rule_set
.would_apply (c
, lookup_context
));
1941 inline const Coverage
&get_coverage (void) const
1943 return this+coverage
;
1946 inline bool apply (hb_apply_context_t
*c
) const
1949 unsigned int index
= (this+coverage
).get_coverage (c
->buffer
->cur().codepoint
);
1950 if (likely (index
== NOT_COVERED
)) return TRACE_RETURN (false);
1952 const ClassDef
&backtrack_class_def
= this+backtrackClassDef
;
1953 const ClassDef
&input_class_def
= this+inputClassDef
;
1954 const ClassDef
&lookahead_class_def
= this+lookaheadClassDef
;
1956 index
= input_class_def
.get_class (c
->buffer
->cur().codepoint
);
1957 const ChainRuleSet
&rule_set
= this+ruleSet
[index
];
1958 struct ChainContextApplyLookupContext lookup_context
= {
1960 {&backtrack_class_def
,
1962 &lookahead_class_def
}
1964 return TRACE_RETURN (rule_set
.apply (c
, lookup_context
));
1967 inline bool sanitize (hb_sanitize_context_t
*c
) {
1968 TRACE_SANITIZE (this);
1969 return TRACE_RETURN (coverage
.sanitize (c
, this) && backtrackClassDef
.sanitize (c
, this) &&
1970 inputClassDef
.sanitize (c
, this) && lookaheadClassDef
.sanitize (c
, this) &&
1971 ruleSet
.sanitize (c
, this));
1975 USHORT format
; /* Format identifier--format = 2 */
1977 coverage
; /* Offset to Coverage table--from
1978 * beginning of table */
1980 backtrackClassDef
; /* Offset to glyph ClassDef table
1981 * containing backtrack sequence
1982 * data--from beginning of table */
1984 inputClassDef
; /* Offset to glyph ClassDef
1985 * table containing input sequence
1986 * data--from beginning of table */
1988 lookaheadClassDef
; /* Offset to glyph ClassDef table
1989 * containing lookahead sequence
1990 * data--from beginning of table */
1991 OffsetArrayOf
<ChainRuleSet
>
1992 ruleSet
; /* Array of ChainRuleSet tables
1993 * ordered by class */
1995 DEFINE_SIZE_ARRAY (12, ruleSet
);
1998 struct ChainContextFormat3
2000 inline void closure (hb_closure_context_t
*c
) const
2002 TRACE_CLOSURE (this);
2003 const OffsetArrayOf
<Coverage
> &input
= StructAfter
<OffsetArrayOf
<Coverage
> > (backtrack
);
2005 if (!(this+input
[0]).intersects (c
->glyphs
))
2008 const OffsetArrayOf
<Coverage
> &lookahead
= StructAfter
<OffsetArrayOf
<Coverage
> > (input
);
2009 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
2010 struct ChainContextClosureLookupContext lookup_context
= {
2011 {intersects_coverage
},
2014 chain_context_closure_lookup (c
,
2015 backtrack
.len
, (const USHORT
*) backtrack
.array
,
2016 input
.len
, (const USHORT
*) input
.array
+ 1,
2017 lookahead
.len
, (const USHORT
*) lookahead
.array
,
2018 lookup
.len
, lookup
.array
,
2022 inline void collect_glyphs (hb_collect_glyphs_context_t
*c
) const
2024 TRACE_COLLECT_GLYPHS (this);
2025 const OffsetArrayOf
<Coverage
> &input
= StructAfter
<OffsetArrayOf
<Coverage
> > (backtrack
);
2027 (this+input
[0]).add_coverage (c
->input
);
2029 const OffsetArrayOf
<Coverage
> &lookahead
= StructAfter
<OffsetArrayOf
<Coverage
> > (input
);
2030 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
2031 struct ChainContextCollectGlyphsLookupContext lookup_context
= {
2035 chain_context_collect_glyphs_lookup (c
,
2036 backtrack
.len
, (const USHORT
*) backtrack
.array
,
2037 input
.len
, (const USHORT
*) input
.array
+ 1,
2038 lookahead
.len
, (const USHORT
*) lookahead
.array
,
2039 lookup
.len
, lookup
.array
,
2043 inline bool would_apply (hb_would_apply_context_t
*c
) const
2045 TRACE_WOULD_APPLY (this);
2047 const OffsetArrayOf
<Coverage
> &input
= StructAfter
<OffsetArrayOf
<Coverage
> > (backtrack
);
2048 const OffsetArrayOf
<Coverage
> &lookahead
= StructAfter
<OffsetArrayOf
<Coverage
> > (input
);
2049 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
2050 struct ChainContextApplyLookupContext lookup_context
= {
2054 return TRACE_RETURN (chain_context_would_apply_lookup (c
,
2055 backtrack
.len
, (const USHORT
*) backtrack
.array
,
2056 input
.len
, (const USHORT
*) input
.array
+ 1,
2057 lookahead
.len
, (const USHORT
*) lookahead
.array
,
2058 lookup
.len
, lookup
.array
, lookup_context
));
2061 inline const Coverage
&get_coverage (void) const
2063 const OffsetArrayOf
<Coverage
> &input
= StructAfter
<OffsetArrayOf
<Coverage
> > (backtrack
);
2064 return this+input
[0];
2067 inline bool apply (hb_apply_context_t
*c
) const
2070 const OffsetArrayOf
<Coverage
> &input
= StructAfter
<OffsetArrayOf
<Coverage
> > (backtrack
);
2072 unsigned int index
= (this+input
[0]).get_coverage (c
->buffer
->cur().codepoint
);
2073 if (likely (index
== NOT_COVERED
)) return TRACE_RETURN (false);
2075 const OffsetArrayOf
<Coverage
> &lookahead
= StructAfter
<OffsetArrayOf
<Coverage
> > (input
);
2076 const ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
2077 struct ChainContextApplyLookupContext lookup_context
= {
2081 return TRACE_RETURN (chain_context_apply_lookup (c
,
2082 backtrack
.len
, (const USHORT
*) backtrack
.array
,
2083 input
.len
, (const USHORT
*) input
.array
+ 1,
2084 lookahead
.len
, (const USHORT
*) lookahead
.array
,
2085 lookup
.len
, lookup
.array
, lookup_context
));
2088 inline bool sanitize (hb_sanitize_context_t
*c
) {
2089 TRACE_SANITIZE (this);
2090 if (!backtrack
.sanitize (c
, this)) return TRACE_RETURN (false);
2091 OffsetArrayOf
<Coverage
> &input
= StructAfter
<OffsetArrayOf
<Coverage
> > (backtrack
);
2092 if (!input
.sanitize (c
, this)) return TRACE_RETURN (false);
2093 OffsetArrayOf
<Coverage
> &lookahead
= StructAfter
<OffsetArrayOf
<Coverage
> > (input
);
2094 if (!lookahead
.sanitize (c
, this)) return TRACE_RETURN (false);
2095 ArrayOf
<LookupRecord
> &lookup
= StructAfter
<ArrayOf
<LookupRecord
> > (lookahead
);
2096 return TRACE_RETURN (lookup
.sanitize (c
));
2100 USHORT format
; /* Format identifier--format = 3 */
2101 OffsetArrayOf
<Coverage
>
2102 backtrack
; /* Array of coverage tables
2103 * in backtracking sequence, in glyph
2105 OffsetArrayOf
<Coverage
>
2106 inputX
; /* Array of coverage
2107 * tables in input sequence, in glyph
2109 OffsetArrayOf
<Coverage
>
2110 lookaheadX
; /* Array of coverage tables
2111 * in lookahead sequence, in glyph
2113 ArrayOf
<LookupRecord
>
2114 lookupX
; /* Array of LookupRecords--in
2117 DEFINE_SIZE_MIN (10);
2122 template <typename context_t
>
2123 inline typename
context_t::return_t
dispatch (context_t
*c
) const
2125 TRACE_DISPATCH (this);
2127 case 1: return TRACE_RETURN (c
->dispatch (u
.format1
));
2128 case 2: return TRACE_RETURN (c
->dispatch (u
.format2
));
2129 case 3: return TRACE_RETURN (c
->dispatch (u
.format3
));
2130 default:return TRACE_RETURN (c
->default_return_value ());
2134 inline bool sanitize (hb_sanitize_context_t
*c
) {
2135 TRACE_SANITIZE (this);
2136 if (!u
.format
.sanitize (c
)) return TRACE_RETURN (false);
2138 case 1: return TRACE_RETURN (u
.format1
.sanitize (c
));
2139 case 2: return TRACE_RETURN (u
.format2
.sanitize (c
));
2140 case 3: return TRACE_RETURN (u
.format3
.sanitize (c
));
2141 default:return TRACE_RETURN (true);
2147 USHORT format
; /* Format identifier */
2148 ChainContextFormat1 format1
;
2149 ChainContextFormat2 format2
;
2150 ChainContextFormat3 format3
;
2155 struct ExtensionFormat1
2157 inline unsigned int get_type (void) const { return extensionLookupType
; }
2158 inline unsigned int get_offset (void) const { return extensionOffset
; }
2160 inline bool sanitize (hb_sanitize_context_t
*c
) {
2161 TRACE_SANITIZE (this);
2162 return TRACE_RETURN (c
->check_struct (this));
2166 USHORT format
; /* Format identifier. Set to 1. */
2167 USHORT extensionLookupType
; /* Lookup type of subtable referenced
2168 * by ExtensionOffset (i.e. the
2169 * extension subtable). */
2170 ULONG extensionOffset
; /* Offset to the extension subtable,
2171 * of lookup type subtable. */
2173 DEFINE_SIZE_STATIC (8);
2176 template <typename T
>
2179 inline unsigned int get_type (void) const
2182 case 1: return u
.format1
.get_type ();
2186 inline unsigned int get_offset (void) const
2189 case 1: return u
.format1
.get_offset ();
2194 template <typename X
>
2195 inline const X
& get_subtable (void) const
2197 unsigned int offset
= get_offset ();
2198 if (unlikely (!offset
)) return Null(typename
T::LookupSubTable
);
2199 return StructAtOffset
<typename
T::LookupSubTable
> (this, offset
);
2202 template <typename context_t
>
2203 inline typename
context_t::return_t
dispatch (context_t
*c
) const
2205 return get_subtable
<typename
T::LookupSubTable
> ().dispatch (c
, get_type ());
2208 inline bool sanitize_self (hb_sanitize_context_t
*c
) {
2209 TRACE_SANITIZE (this);
2210 if (!u
.format
.sanitize (c
)) return TRACE_RETURN (false);
2212 case 1: return TRACE_RETURN (u
.format1
.sanitize (c
));
2213 default:return TRACE_RETURN (true);
2217 inline bool sanitize (hb_sanitize_context_t
*c
) {
2218 TRACE_SANITIZE (this);
2219 if (!sanitize_self (c
)) return TRACE_RETURN (false);
2220 unsigned int offset
= get_offset ();
2221 if (unlikely (!offset
)) return TRACE_RETURN (true);
2222 return TRACE_RETURN (StructAtOffset
<typename
T::LookupSubTable
> (this, offset
).sanitize (c
, get_type ()));
2227 USHORT format
; /* Format identifier */
2228 ExtensionFormat1 format1
;
2239 static const hb_tag_t GSUBTag
= HB_OT_TAG_GSUB
;
2240 static const hb_tag_t GPOSTag
= HB_OT_TAG_GPOS
;
2242 inline unsigned int get_script_count (void) const
2243 { return (this+scriptList
).len
; }
2244 inline const Tag
& get_script_tag (unsigned int i
) const
2245 { return (this+scriptList
).get_tag (i
); }
2246 inline unsigned int get_script_tags (unsigned int start_offset
,
2247 unsigned int *script_count
/* IN/OUT */,
2248 hb_tag_t
*script_tags
/* OUT */) const
2249 { return (this+scriptList
).get_tags (start_offset
, script_count
, script_tags
); }
2250 inline const Script
& get_script (unsigned int i
) const
2251 { return (this+scriptList
)[i
]; }
2252 inline bool find_script_index (hb_tag_t tag
, unsigned int *index
) const
2253 { return (this+scriptList
).find_index (tag
, index
); }
2255 inline unsigned int get_feature_count (void) const
2256 { return (this+featureList
).len
; }
2257 inline hb_tag_t
get_feature_tag (unsigned int i
) const
2258 { return i
== Index::NOT_FOUND_INDEX
? HB_TAG_NONE
: (this+featureList
).get_tag (i
); }
2259 inline unsigned int get_feature_tags (unsigned int start_offset
,
2260 unsigned int *feature_count
/* IN/OUT */,
2261 hb_tag_t
*feature_tags
/* OUT */) const
2262 { return (this+featureList
).get_tags (start_offset
, feature_count
, feature_tags
); }
2263 inline const Feature
& get_feature (unsigned int i
) const
2264 { return (this+featureList
)[i
]; }
2265 inline bool find_feature_index (hb_tag_t tag
, unsigned int *index
) const
2266 { return (this+featureList
).find_index (tag
, index
); }
2268 inline unsigned int get_lookup_count (void) const
2269 { return (this+lookupList
).len
; }
2270 inline const Lookup
& get_lookup (unsigned int i
) const
2271 { return (this+lookupList
)[i
]; }
2273 inline bool sanitize (hb_sanitize_context_t
*c
) {
2274 TRACE_SANITIZE (this);
2275 return TRACE_RETURN (version
.sanitize (c
) && likely (version
.major
== 1) &&
2276 scriptList
.sanitize (c
, this) &&
2277 featureList
.sanitize (c
, this) &&
2278 lookupList
.sanitize (c
, this));
2282 FixedVersion version
; /* Version of the GSUB/GPOS table--initially set
2284 OffsetTo
<ScriptList
>
2285 scriptList
; /* ScriptList table */
2286 OffsetTo
<FeatureList
>
2287 featureList
; /* FeatureList table */
2288 OffsetTo
<LookupList
>
2289 lookupList
; /* LookupList table */
2291 DEFINE_SIZE_STATIC (10);
2295 } /* namespace OT */
2298 #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */