1 /*
2  * Copyright © 2007,2008,2009  Red Hat, Inc.
3  * Copyright © 2012,2013  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
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.
12  *
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
17  * DAMAGE.
18  *
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.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod
27  */
28 
29 #ifndef HB_OT_LAYOUT_HH
30 #define HB_OT_LAYOUT_HH
31 
32 #include "hb.hh"
33 
34 #include "hb-font.hh"
35 #include "hb-buffer.hh"
36 #include "hb-open-type.hh"
37 #include "hb-ot-shape.hh"
38 #include "hb-set-digest.hh"
39 
40 struct hb_ot_shape_plan_t;
41 
42 /*
43  * kern
44  */
45 
46 HB_INTERNAL bool hb_ot_layout_has_kerning(hb_face_t *face);
47 
48 HB_INTERNAL bool hb_ot_layout_has_machine_kerning(hb_face_t *face);
49 
50 HB_INTERNAL bool hb_ot_layout_has_cross_kerning(hb_face_t *face);
51 
52 HB_INTERNAL void hb_ot_layout_kern(const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer);
53 
54 /* Private API corresponding to hb-ot-layout.h: */
55 
56 HB_INTERNAL bool
57 hb_ot_layout_table_find_feature(hb_face_t *face, hb_tag_t table_tag, hb_tag_t feature_tag, unsigned int *feature_index);
58 
59 /*
60  * GDEF
61  */
62 
63 enum hb_ot_layout_glyph_props_flags_t {
64     /* The following three match LookupFlags::Ignore* numbers. */
65     HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u,
66     HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u,
67     HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u,
68 
69     HB_OT_LAYOUT_GLYPH_PROPS_CLASS_MASK =
70         HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH | HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE | HB_OT_LAYOUT_GLYPH_PROPS_MARK,
71 
72     /* The following are used internally; not derived from GDEF. */
73     HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u,
74     HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u,
75     HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED = 0x40u,
76 };
77 HB_MARK_AS_FLAG_T(hb_ot_layout_glyph_props_flags_t);
78 
79 /*
80  * GSUB/GPOS
81  */
82 
83 /* Should be called before all the substitute_lookup's are done. */
84 HB_INTERNAL void hb_ot_layout_substitute_start(hb_font_t *font, hb_buffer_t *buffer);
85 
86 HB_INTERNAL void hb_ot_layout_delete_glyphs_inplace(hb_buffer_t *buffer, bool (*filter)(const hb_glyph_info_t *info));
87 
88 namespace OT {
89 struct hb_ot_apply_context_t;
90 struct SubstLookup;
91 struct hb_ot_layout_lookup_accelerator_t;
92 } // namespace OT
93 
94 HB_INTERNAL void hb_ot_layout_substitute_lookup(OT::hb_ot_apply_context_t *c,
95                                                 const OT::SubstLookup &lookup,
96                                                 const OT::hb_ot_layout_lookup_accelerator_t &accel);
97 
98 /* Should be called before all the position_lookup's are done. */
99 HB_INTERNAL void hb_ot_layout_position_start(hb_font_t *font, hb_buffer_t *buffer);
100 
101 /* Should be called after all the position_lookup's are done, to fini advances. */
102 HB_INTERNAL void hb_ot_layout_position_finish_advances(hb_font_t *font, hb_buffer_t *buffer);
103 
104 /* Should be called after hb_ot_layout_position_finish_advances, to fini offsets. */
105 HB_INTERNAL void hb_ot_layout_position_finish_offsets(hb_font_t *font, hb_buffer_t *buffer);
106 
107 /*
108  * Buffer var routines.
109  */
110 
111 /* buffer var allocations, used during the entire shaping process */
112 #define unicode_props() var2.u16[0]
113 
114 /* buffer var allocations, used during the GSUB/GPOS processing */
115 #define glyph_props() var1.u16[0] /* GDEF glyph properties */
116 #define lig_props() var1.u8[2]    /* GSUB/GPOS ligature tracking */
117 #define syllable() var1.u8[3]     /* GSUB/GPOS shaping boundaries */
118 
119 /* Loop over syllables. Based on foreach_cluster(). */
120 #define foreach_syllable(buffer, start, end)                                                                           \
121     for (unsigned int _count = buffer->len, start = 0, end = _count ? _hb_next_syllable(buffer, 0) : 0;                \
122          start < _count;                                                                                               \
123          start = end, end = _hb_next_syllable(buffer, start))
124 
_hb_next_syllable(hb_buffer_t * buffer,unsigned int start)125 static inline unsigned int _hb_next_syllable(hb_buffer_t *buffer, unsigned int start)
126 {
127     hb_glyph_info_t *info = buffer->info;
128     unsigned int count = buffer->len;
129 
130     unsigned int syllable = info[start].syllable();
131     while (++start < count && syllable == info[start].syllable())
132         ;
133 
134     return start;
135 }
136 
137 static inline void
_hb_clear_syllables(const hb_ot_shape_plan_t * plan HB_UNUSED,hb_font_t * font HB_UNUSED,hb_buffer_t * buffer)138 _hb_clear_syllables(const hb_ot_shape_plan_t *plan HB_UNUSED, hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
139 {
140     hb_glyph_info_t *info = buffer->info;
141     unsigned int count = buffer->len;
142     for (unsigned int i = 0; i < count; i++)
143         info[i].syllable() = 0;
144 }
145 
146 /* unicode_props */
147 
148 /* Design:
149  * unicode_props() is a two-byte number.  The low byte includes:
150  * - General_Category: 5 bits.
151  * - A bit each for:
152  *   * Is it Default_Ignorable(); we have a modified Default_Ignorable().
153  *   * Whether it's one of the three Mongolian Free Variation Selectors,
154  *     CGJ, or other characters that are hidden but should not be ignored
155  *     like most other Default_Ignorable()s do during matching.
156  *   * Whether it's a grapheme continuation.
157  *
158  * The high-byte has different meanings, switched by the Gen-Cat:
159  * - For Mn,Mc,Me: the modified Combining_Class.
160  * - For Cf: whether it's ZWJ, ZWNJ, or something else.
161  * - For Ws: index of which space character this is, if space fallback
162  *   is needed, ie. we don't set this by default, only if asked to.
163  */
164 
165 enum hb_unicode_props_flags_t {
166     UPROPS_MASK_GEN_CAT = 0x001Fu,
167     UPROPS_MASK_IGNORABLE = 0x0020u,
168     UPROPS_MASK_HIDDEN = 0x0040u, /* MONGOLIAN FREE VARIATION SELECTOR 1..3, or TAG characters */
169     UPROPS_MASK_CONTINUATION = 0x0080u,
170 
171     /* If GEN_CAT=FORMAT, top byte masks: */
172     UPROPS_MASK_Cf_ZWJ = 0x0100u,
173     UPROPS_MASK_Cf_ZWNJ = 0x0200u
174 };
175 HB_MARK_AS_FLAG_T(hb_unicode_props_flags_t);
176 
_hb_glyph_info_set_unicode_props(hb_glyph_info_t * info,hb_buffer_t * buffer)177 static inline void _hb_glyph_info_set_unicode_props(hb_glyph_info_t *info, hb_buffer_t *buffer)
178 {
179     hb_unicode_funcs_t *unicode = buffer->unicode;
180     unsigned int u = info->codepoint;
181     unsigned int gen_cat = (unsigned int)unicode->general_category(u);
182     unsigned int props = gen_cat;
183 
184     if (u >= 0x80u) {
185         buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII;
186 
187         if (unlikely(unicode->is_default_ignorable(u))) {
188             buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES;
189             props |= UPROPS_MASK_IGNORABLE;
190             if (u == 0x200Cu)
191                 props |= UPROPS_MASK_Cf_ZWNJ;
192             else if (u == 0x200Du)
193                 props |= UPROPS_MASK_Cf_ZWJ;
194             /* Mongolian Free Variation Selectors need to be remembered
195              * because although we need to hide them like default-ignorables,
196              * they need to non-ignorable during shaping.  This is similar to
197              * what we do for joiners in Indic-like shapers, but since the
198              * FVSes are GC=Mn, we have use a separate bit to remember them.
199              * Fixes:
200              * https://github.com/harfbuzz/harfbuzz/issues/234 */
201             else if (unlikely(hb_in_range<hb_codepoint_t>(u, 0x180Bu, 0x180Du)))
202                 props |= UPROPS_MASK_HIDDEN;
203             /* TAG characters need similar treatment. Fixes:
204              * https://github.com/harfbuzz/harfbuzz/issues/463 */
205             else if (unlikely(hb_in_range<hb_codepoint_t>(u, 0xE0020u, 0xE007Fu)))
206                 props |= UPROPS_MASK_HIDDEN;
207             /* COMBINING GRAPHEME JOINER should not be skipped; at least some times.
208              * https://github.com/harfbuzz/harfbuzz/issues/554 */
209             else if (unlikely(u == 0x034Fu)) {
210                 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_CGJ;
211                 props |= UPROPS_MASK_HIDDEN;
212             }
213         }
214 
215         if (unlikely(HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat))) {
216             props |= UPROPS_MASK_CONTINUATION;
217             props |= unicode->modified_combining_class(u) << 8;
218         }
219     }
220 
221     info->unicode_props() = props;
222 }
223 
_hb_glyph_info_set_general_category(hb_glyph_info_t * info,hb_unicode_general_category_t gen_cat)224 static inline void _hb_glyph_info_set_general_category(hb_glyph_info_t *info, hb_unicode_general_category_t gen_cat)
225 {
226     /* Clears top-byte. */
227     info->unicode_props() = (unsigned int)gen_cat | (info->unicode_props() & (0xFF & ~UPROPS_MASK_GEN_CAT));
228 }
229 
_hb_glyph_info_get_general_category(const hb_glyph_info_t * info)230 static inline hb_unicode_general_category_t _hb_glyph_info_get_general_category(const hb_glyph_info_t *info)
231 {
232     return (hb_unicode_general_category_t)(info->unicode_props() & UPROPS_MASK_GEN_CAT);
233 }
234 
_hb_glyph_info_is_unicode_mark(const hb_glyph_info_t * info)235 static inline bool _hb_glyph_info_is_unicode_mark(const hb_glyph_info_t *info)
236 {
237     return HB_UNICODE_GENERAL_CATEGORY_IS_MARK(info->unicode_props() & UPROPS_MASK_GEN_CAT);
238 }
_hb_glyph_info_set_modified_combining_class(hb_glyph_info_t * info,unsigned int modified_class)239 static inline void _hb_glyph_info_set_modified_combining_class(hb_glyph_info_t *info, unsigned int modified_class)
240 {
241     if (unlikely(!_hb_glyph_info_is_unicode_mark(info)))
242         return;
243     info->unicode_props() = (modified_class << 8) | (info->unicode_props() & 0xFF);
244 }
_hb_glyph_info_get_modified_combining_class(const hb_glyph_info_t * info)245 static inline unsigned int _hb_glyph_info_get_modified_combining_class(const hb_glyph_info_t *info)
246 {
247     return _hb_glyph_info_is_unicode_mark(info) ? info->unicode_props() >> 8 : 0;
248 }
249 #define info_cc(info) (_hb_glyph_info_get_modified_combining_class(&(info)))
250 
_hb_glyph_info_is_unicode_space(const hb_glyph_info_t * info)251 static inline bool _hb_glyph_info_is_unicode_space(const hb_glyph_info_t *info)
252 {
253     return _hb_glyph_info_get_general_category(info) == HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR;
254 }
_hb_glyph_info_set_unicode_space_fallback_type(hb_glyph_info_t * info,hb_unicode_funcs_t::space_t s)255 static inline void _hb_glyph_info_set_unicode_space_fallback_type(hb_glyph_info_t *info, hb_unicode_funcs_t::space_t s)
256 {
257     if (unlikely(!_hb_glyph_info_is_unicode_space(info)))
258         return;
259     info->unicode_props() = (((unsigned int)s) << 8) | (info->unicode_props() & 0xFF);
260 }
_hb_glyph_info_get_unicode_space_fallback_type(const hb_glyph_info_t * info)261 static inline hb_unicode_funcs_t::space_t _hb_glyph_info_get_unicode_space_fallback_type(const hb_glyph_info_t *info)
262 {
263     return _hb_glyph_info_is_unicode_space(info) ? (hb_unicode_funcs_t::space_t)(info->unicode_props() >> 8)
264                                                  : hb_unicode_funcs_t::NOT_SPACE;
265 }
266 
267 static inline bool _hb_glyph_info_ligated(const hb_glyph_info_t *info);
268 
_hb_glyph_info_is_default_ignorable(const hb_glyph_info_t * info)269 static inline bool _hb_glyph_info_is_default_ignorable(const hb_glyph_info_t *info)
270 {
271     return (info->unicode_props() & UPROPS_MASK_IGNORABLE) && !_hb_glyph_info_ligated(info);
272 }
_hb_glyph_info_is_default_ignorable_and_not_hidden(const hb_glyph_info_t * info)273 static inline bool _hb_glyph_info_is_default_ignorable_and_not_hidden(const hb_glyph_info_t *info)
274 {
275     return ((info->unicode_props() & (UPROPS_MASK_IGNORABLE | UPROPS_MASK_HIDDEN)) == UPROPS_MASK_IGNORABLE) &&
276            !_hb_glyph_info_ligated(info);
277 }
_hb_glyph_info_unhide(hb_glyph_info_t * info)278 static inline void _hb_glyph_info_unhide(hb_glyph_info_t *info)
279 {
280     info->unicode_props() &= ~UPROPS_MASK_HIDDEN;
281 }
282 
_hb_glyph_info_set_continuation(hb_glyph_info_t * info)283 static inline void _hb_glyph_info_set_continuation(hb_glyph_info_t *info)
284 {
285     info->unicode_props() |= UPROPS_MASK_CONTINUATION;
286 }
_hb_glyph_info_reset_continuation(hb_glyph_info_t * info)287 static inline void _hb_glyph_info_reset_continuation(hb_glyph_info_t *info)
288 {
289     info->unicode_props() &= ~UPROPS_MASK_CONTINUATION;
290 }
_hb_glyph_info_is_continuation(const hb_glyph_info_t * info)291 static inline bool _hb_glyph_info_is_continuation(const hb_glyph_info_t *info)
292 {
293     return info->unicode_props() & UPROPS_MASK_CONTINUATION;
294 }
295 /* Loop over grapheme. Based on foreach_cluster(). */
296 #define foreach_grapheme(buffer, start, end)                                                                           \
297     for (unsigned int _count = buffer->len, start = 0, end = _count ? _hb_next_grapheme(buffer, 0) : 0;                \
298          start < _count;                                                                                               \
299          start = end, end = _hb_next_grapheme(buffer, start))
300 
_hb_next_grapheme(hb_buffer_t * buffer,unsigned int start)301 static inline unsigned int _hb_next_grapheme(hb_buffer_t *buffer, unsigned int start)
302 {
303     hb_glyph_info_t *info = buffer->info;
304     unsigned int count = buffer->len;
305 
306     while (++start < count && _hb_glyph_info_is_continuation(&info[start]))
307         ;
308 
309     return start;
310 }
311 
_hb_glyph_info_is_unicode_format(const hb_glyph_info_t * info)312 static inline bool _hb_glyph_info_is_unicode_format(const hb_glyph_info_t *info)
313 {
314     return _hb_glyph_info_get_general_category(info) == HB_UNICODE_GENERAL_CATEGORY_FORMAT;
315 }
_hb_glyph_info_is_zwnj(const hb_glyph_info_t * info)316 static inline bool _hb_glyph_info_is_zwnj(const hb_glyph_info_t *info)
317 {
318     return _hb_glyph_info_is_unicode_format(info) && (info->unicode_props() & UPROPS_MASK_Cf_ZWNJ);
319 }
_hb_glyph_info_is_zwj(const hb_glyph_info_t * info)320 static inline bool _hb_glyph_info_is_zwj(const hb_glyph_info_t *info)
321 {
322     return _hb_glyph_info_is_unicode_format(info) && (info->unicode_props() & UPROPS_MASK_Cf_ZWJ);
323 }
_hb_glyph_info_is_joiner(const hb_glyph_info_t * info)324 static inline bool _hb_glyph_info_is_joiner(const hb_glyph_info_t *info)
325 {
326     return _hb_glyph_info_is_unicode_format(info) &&
327            (info->unicode_props() & (UPROPS_MASK_Cf_ZWNJ | UPROPS_MASK_Cf_ZWJ));
328 }
_hb_glyph_info_flip_joiners(hb_glyph_info_t * info)329 static inline void _hb_glyph_info_flip_joiners(hb_glyph_info_t *info)
330 {
331     if (!_hb_glyph_info_is_unicode_format(info))
332         return;
333     info->unicode_props() ^= UPROPS_MASK_Cf_ZWNJ | UPROPS_MASK_Cf_ZWJ;
334 }
335 
336 /* lig_props: aka lig_id / lig_comp
337  *
338  * When a ligature is formed:
339  *
340  *   - The ligature glyph and any marks in between all the same newly allocated
341  *     lig_id,
342  *   - The ligature glyph will get lig_num_comps set to the number of components
343  *   - The marks get lig_comp > 0, reflecting which component of the ligature
344  *     they were applied to.
345  *   - This is used in GPOS to attach marks to the right component of a ligature
346  *     in MarkLigPos,
347  *   - Note that when marks are ligated together, much of the above is skipped
348  *     and the current lig_id reused.
349  *
350  * When a multiple-substitution is done:
351  *
352  *   - All resulting glyphs will have lig_id = 0,
353  *   - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
354  *   - This is used in GPOS to attach marks to the first component of a
355  *     multiple substitution in MarkBasePos.
356  *
357  * The numbers are also used in GPOS to do mark-to-mark positioning only
358  * to marks that belong to the same component of the same ligature.
359  */
360 
_hb_glyph_info_clear_lig_props(hb_glyph_info_t * info)361 static inline void _hb_glyph_info_clear_lig_props(hb_glyph_info_t *info)
362 {
363     info->lig_props() = 0;
364 }
365 
366 #define IS_LIG_BASE 0x10
367 
368 static inline void
_hb_glyph_info_set_lig_props_for_ligature(hb_glyph_info_t * info,unsigned int lig_id,unsigned int lig_num_comps)369 _hb_glyph_info_set_lig_props_for_ligature(hb_glyph_info_t *info, unsigned int lig_id, unsigned int lig_num_comps)
370 {
371     info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F);
372 }
373 
374 static inline void
_hb_glyph_info_set_lig_props_for_mark(hb_glyph_info_t * info,unsigned int lig_id,unsigned int lig_comp)375 _hb_glyph_info_set_lig_props_for_mark(hb_glyph_info_t *info, unsigned int lig_id, unsigned int lig_comp)
376 {
377     info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F);
378 }
379 
_hb_glyph_info_set_lig_props_for_component(hb_glyph_info_t * info,unsigned int comp)380 static inline void _hb_glyph_info_set_lig_props_for_component(hb_glyph_info_t *info, unsigned int comp)
381 {
382     _hb_glyph_info_set_lig_props_for_mark(info, 0, comp);
383 }
384 
_hb_glyph_info_get_lig_id(const hb_glyph_info_t * info)385 static inline unsigned int _hb_glyph_info_get_lig_id(const hb_glyph_info_t *info)
386 {
387     return info->lig_props() >> 5;
388 }
389 
_hb_glyph_info_ligated_internal(const hb_glyph_info_t * info)390 static inline bool _hb_glyph_info_ligated_internal(const hb_glyph_info_t *info)
391 {
392     return !!(info->lig_props() & IS_LIG_BASE);
393 }
394 
_hb_glyph_info_get_lig_comp(const hb_glyph_info_t * info)395 static inline unsigned int _hb_glyph_info_get_lig_comp(const hb_glyph_info_t *info)
396 {
397     if (_hb_glyph_info_ligated_internal(info))
398         return 0;
399     else
400         return info->lig_props() & 0x0F;
401 }
402 
_hb_glyph_info_get_lig_num_comps(const hb_glyph_info_t * info)403 static inline unsigned int _hb_glyph_info_get_lig_num_comps(const hb_glyph_info_t *info)
404 {
405     if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) && _hb_glyph_info_ligated_internal(info))
406         return info->lig_props() & 0x0F;
407     else
408         return 1;
409 }
410 
_hb_allocate_lig_id(hb_buffer_t * buffer)411 static inline uint8_t _hb_allocate_lig_id(hb_buffer_t *buffer)
412 {
413     uint8_t lig_id = buffer->next_serial() & 0x07;
414     if (unlikely(!lig_id))
415         lig_id = _hb_allocate_lig_id(buffer); /* in case of overflow */
416     return lig_id;
417 }
418 
419 /* glyph_props: */
420 
_hb_glyph_info_set_glyph_props(hb_glyph_info_t * info,unsigned int props)421 static inline void _hb_glyph_info_set_glyph_props(hb_glyph_info_t *info, unsigned int props)
422 {
423     info->glyph_props() = props;
424 }
425 
_hb_glyph_info_get_glyph_props(const hb_glyph_info_t * info)426 static inline unsigned int _hb_glyph_info_get_glyph_props(const hb_glyph_info_t *info)
427 {
428     return info->glyph_props();
429 }
430 
_hb_glyph_info_is_base_glyph(const hb_glyph_info_t * info)431 static inline bool _hb_glyph_info_is_base_glyph(const hb_glyph_info_t *info)
432 {
433     return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH);
434 }
435 
_hb_glyph_info_is_ligature(const hb_glyph_info_t * info)436 static inline bool _hb_glyph_info_is_ligature(const hb_glyph_info_t *info)
437 {
438     return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE);
439 }
440 
_hb_glyph_info_is_mark(const hb_glyph_info_t * info)441 static inline bool _hb_glyph_info_is_mark(const hb_glyph_info_t *info)
442 {
443     return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
444 }
445 
_hb_glyph_info_substituted(const hb_glyph_info_t * info)446 static inline bool _hb_glyph_info_substituted(const hb_glyph_info_t *info)
447 {
448     return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
449 }
450 
_hb_glyph_info_ligated(const hb_glyph_info_t * info)451 static inline bool _hb_glyph_info_ligated(const hb_glyph_info_t *info)
452 {
453     return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED);
454 }
455 
_hb_glyph_info_multiplied(const hb_glyph_info_t * info)456 static inline bool _hb_glyph_info_multiplied(const hb_glyph_info_t *info)
457 {
458     return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
459 }
460 
_hb_glyph_info_ligated_and_didnt_multiply(const hb_glyph_info_t * info)461 static inline bool _hb_glyph_info_ligated_and_didnt_multiply(const hb_glyph_info_t *info)
462 {
463     return _hb_glyph_info_ligated(info) && !_hb_glyph_info_multiplied(info);
464 }
465 
_hb_glyph_info_clear_ligated_and_multiplied(hb_glyph_info_t * info)466 static inline void _hb_glyph_info_clear_ligated_and_multiplied(hb_glyph_info_t *info)
467 {
468     info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_LIGATED | HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
469 }
470 
_hb_glyph_info_clear_substituted(hb_glyph_info_t * info)471 static inline void _hb_glyph_info_clear_substituted(hb_glyph_info_t *info)
472 {
473     info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
474 }
475 
476 static inline void
_hb_clear_substitution_flags(const hb_ot_shape_plan_t * plan HB_UNUSED,hb_font_t * font HB_UNUSED,hb_buffer_t * buffer)477 _hb_clear_substitution_flags(const hb_ot_shape_plan_t *plan HB_UNUSED, hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
478 {
479     hb_glyph_info_t *info = buffer->info;
480     unsigned int count = buffer->len;
481     for (unsigned int i = 0; i < count; i++)
482         _hb_glyph_info_clear_substituted(&info[i]);
483 }
484 
485 /* Allocation / deallocation. */
486 
_hb_buffer_allocate_unicode_vars(hb_buffer_t * buffer)487 static inline void _hb_buffer_allocate_unicode_vars(hb_buffer_t *buffer)
488 {
489     HB_BUFFER_ALLOCATE_VAR(buffer, unicode_props);
490 }
491 
_hb_buffer_deallocate_unicode_vars(hb_buffer_t * buffer)492 static inline void _hb_buffer_deallocate_unicode_vars(hb_buffer_t *buffer)
493 {
494     HB_BUFFER_DEALLOCATE_VAR(buffer, unicode_props);
495 }
496 
_hb_buffer_assert_unicode_vars(hb_buffer_t * buffer)497 static inline void _hb_buffer_assert_unicode_vars(hb_buffer_t *buffer)
498 {
499     HB_BUFFER_ASSERT_VAR(buffer, unicode_props);
500 }
501 
_hb_buffer_allocate_gsubgpos_vars(hb_buffer_t * buffer)502 static inline void _hb_buffer_allocate_gsubgpos_vars(hb_buffer_t *buffer)
503 {
504     HB_BUFFER_ALLOCATE_VAR(buffer, glyph_props);
505     HB_BUFFER_ALLOCATE_VAR(buffer, lig_props);
506     HB_BUFFER_ALLOCATE_VAR(buffer, syllable);
507 }
508 
_hb_buffer_deallocate_gsubgpos_vars(hb_buffer_t * buffer)509 static inline void _hb_buffer_deallocate_gsubgpos_vars(hb_buffer_t *buffer)
510 {
511     HB_BUFFER_DEALLOCATE_VAR(buffer, syllable);
512     HB_BUFFER_DEALLOCATE_VAR(buffer, lig_props);
513     HB_BUFFER_DEALLOCATE_VAR(buffer, glyph_props);
514 }
515 
_hb_buffer_assert_gsubgpos_vars(hb_buffer_t * buffer)516 static inline void _hb_buffer_assert_gsubgpos_vars(hb_buffer_t *buffer)
517 {
518     HB_BUFFER_ASSERT_VAR(buffer, glyph_props);
519     HB_BUFFER_ASSERT_VAR(buffer, lig_props);
520     HB_BUFFER_ASSERT_VAR(buffer, syllable);
521 }
522 
523 /* Make sure no one directly touches our props... */
524 #undef unicode_props0
525 #undef unicode_props1
526 #undef lig_props
527 #undef glyph_props
528 
529 #endif /* HB_OT_LAYOUT_HH */
530