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