Add an exponential backoff to rechecking the app list doodle.
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-ot-layout-private.hh
blob47fecd216d3045d4909234fcc566823ae710a186
1 /*
2 * Copyright © 2007,2008,2009 Red Hat, Inc.
3 * Copyright © 2012,2013 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
17 * DAMAGE.
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_PRIVATE_HH
30 #define HB_OT_LAYOUT_PRIVATE_HH
32 #include "hb-private.hh"
34 #include "hb-font-private.hh"
35 #include "hb-buffer-private.hh"
36 #include "hb-set-private.hh"
40 * GDEF
43 typedef enum
45 /* The following three match LookupFlags::Ignore* numbers. */
46 HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u,
47 HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u,
48 HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u,
50 /* The following are used internally; not derived from GDEF. */
51 HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u,
52 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u,
53 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED = 0x40u,
55 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED |
56 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
57 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
58 } hb_ot_layout_glyph_class_mask_t;
62 * GSUB/GPOS
65 HB_INTERNAL hb_bool_t
66 hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face,
67 unsigned int lookup_index,
68 const hb_codepoint_t *glyphs,
69 unsigned int glyphs_length,
70 hb_bool_t zero_context);
73 /* Should be called before all the substitute_lookup's are done. */
74 HB_INTERNAL void
75 hb_ot_layout_substitute_start (hb_font_t *font,
76 hb_buffer_t *buffer);
79 struct hb_ot_layout_lookup_accelerator_t;
81 namespace OT {
82 struct hb_apply_context_t;
83 struct SubstLookup;
86 HB_INTERNAL void
87 hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c,
88 const OT::SubstLookup &lookup,
89 const hb_ot_layout_lookup_accelerator_t &accel);
92 /* Should be called after all the substitute_lookup's are done */
93 HB_INTERNAL void
94 hb_ot_layout_substitute_finish (hb_font_t *font,
95 hb_buffer_t *buffer);
98 /* Should be called before all the position_lookup's are done. Resets positions to zero. */
99 HB_INTERNAL void
100 hb_ot_layout_position_start (hb_font_t *font,
101 hb_buffer_t *buffer);
103 /* Should be called after all the position_lookup's are done */
104 HB_INTERNAL void
105 hb_ot_layout_position_finish (hb_font_t *font,
106 hb_buffer_t *buffer);
111 * hb_ot_layout_t
114 namespace OT {
115 struct GDEF;
116 struct GSUB;
117 struct GPOS;
120 struct hb_ot_layout_lookup_accelerator_t
122 template <typename TLookup>
123 inline void init (const TLookup &lookup)
125 digest.init ();
126 lookup.add_coverage (&digest);
129 inline void fini (void)
133 inline bool may_have (hb_codepoint_t g) const {
134 return digest.may_have (g);
137 private:
138 hb_set_digest_t digest;
141 struct hb_ot_layout_t
143 hb_blob_t *gdef_blob;
144 hb_blob_t *gsub_blob;
145 hb_blob_t *gpos_blob;
147 const struct OT::GDEF *gdef;
148 const struct OT::GSUB *gsub;
149 const struct OT::GPOS *gpos;
151 unsigned int gsub_lookup_count;
152 unsigned int gpos_lookup_count;
154 hb_ot_layout_lookup_accelerator_t *gsub_accels;
155 hb_ot_layout_lookup_accelerator_t *gpos_accels;
159 HB_INTERNAL hb_ot_layout_t *
160 _hb_ot_layout_create (hb_face_t *face);
162 HB_INTERNAL void
163 _hb_ot_layout_destroy (hb_ot_layout_t *layout);
166 #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot)
170 * Buffer var routines.
173 /* buffer var allocations, used during the entire shaping process */
174 #define unicode_props0() var2.u8[0]
175 #define unicode_props1() var2.u8[1]
177 /* buffer var allocations, used during the GSUB/GPOS processing */
178 #define glyph_props() var1.u16[0] /* GDEF glyph properties */
179 #define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */
180 #define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */
182 /* unicode_props */
184 enum {
185 MASK0_ZWJ = 0x20u,
186 MASK0_ZWNJ = 0x40u,
187 MASK0_IGNORABLE = 0x80u,
188 MASK0_GEN_CAT = 0x1Fu
191 static inline void
192 _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode)
194 /* XXX This shouldn't be inlined, or at least not while is_default_ignorable() is inline. */
195 info->unicode_props0() = ((unsigned int) unicode->general_category (info->codepoint)) |
196 (unicode->is_default_ignorable (info->codepoint) ? MASK0_IGNORABLE : 0) |
197 (info->codepoint == 0x200Cu ? MASK0_ZWNJ : 0) |
198 (info->codepoint == 0x200Du ? MASK0_ZWJ : 0);
199 info->unicode_props1() = unicode->modified_combining_class (info->codepoint);
202 static inline void
203 _hb_glyph_info_set_general_category (hb_glyph_info_t *info,
204 hb_unicode_general_category_t gen_cat)
206 info->unicode_props0() = (unsigned int) gen_cat | ((info->unicode_props0()) & ~MASK0_GEN_CAT);
209 static inline hb_unicode_general_category_t
210 _hb_glyph_info_get_general_category (const hb_glyph_info_t *info)
212 return (hb_unicode_general_category_t) (info->unicode_props0() & MASK0_GEN_CAT);
215 static inline void
216 _hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info,
217 unsigned int modified_class)
219 info->unicode_props1() = modified_class;
222 static inline unsigned int
223 _hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info)
225 return info->unicode_props1();
228 static inline hb_bool_t
229 _hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info)
231 return !!(info->unicode_props0() & MASK0_IGNORABLE);
234 static inline hb_bool_t
235 _hb_glyph_info_is_zwnj (const hb_glyph_info_t *info)
237 return !!(info->unicode_props0() & MASK0_ZWNJ);
240 static inline hb_bool_t
241 _hb_glyph_info_is_zwj (const hb_glyph_info_t *info)
243 return !!(info->unicode_props0() & MASK0_ZWJ);
246 static inline void
247 _hb_glyph_info_flip_joiners (hb_glyph_info_t *info)
249 info->unicode_props0() ^= MASK0_ZWNJ | MASK0_ZWJ;
252 /* lig_props: aka lig_id / lig_comp
254 * When a ligature is formed:
256 * - The ligature glyph and any marks in between all the same newly allocated
257 * lig_id,
258 * - The ligature glyph will get lig_num_comps set to the number of components
259 * - The marks get lig_comp > 0, reflecting which component of the ligature
260 * they were applied to.
261 * - This is used in GPOS to attach marks to the right component of a ligature
262 * in MarkLigPos,
263 * - Note that when marks are ligated together, much of the above is skipped
264 * and the current lig_id reused.
266 * When a multiple-substitution is done:
268 * - All resulting glyphs will have lig_id = 0,
269 * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
270 * - This is used in GPOS to attach marks to the first component of a
271 * multiple substitution in MarkBasePos.
273 * The numbers are also used in GPOS to do mark-to-mark positioning only
274 * to marks that belong to the same component of the same ligature.
277 static inline void
278 _hb_glyph_info_clear_lig_props (hb_glyph_info_t *info)
280 info->lig_props() = 0;
283 #define IS_LIG_BASE 0x10
285 static inline void
286 _hb_glyph_info_set_lig_props_for_ligature (hb_glyph_info_t *info,
287 unsigned int lig_id,
288 unsigned int lig_num_comps)
290 info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F);
293 static inline void
294 _hb_glyph_info_set_lig_props_for_mark (hb_glyph_info_t *info,
295 unsigned int lig_id,
296 unsigned int lig_comp)
298 info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F);
301 static inline void
302 _hb_glyph_info_set_lig_props_for_component (hb_glyph_info_t *info, unsigned int comp)
304 _hb_glyph_info_set_lig_props_for_mark (info, 0, comp);
307 static inline unsigned int
308 _hb_glyph_info_get_lig_id (const hb_glyph_info_t *info)
310 return info->lig_props() >> 5;
313 static inline bool
314 _hb_glyph_info_ligated_internal (const hb_glyph_info_t *info)
316 return !!(info->lig_props() & IS_LIG_BASE);
319 static inline unsigned int
320 _hb_glyph_info_get_lig_comp (const hb_glyph_info_t *info)
322 if (_hb_glyph_info_ligated_internal (info))
323 return 0;
324 else
325 return info->lig_props() & 0x0F;
328 static inline unsigned int
329 _hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info)
331 if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) &&
332 _hb_glyph_info_ligated_internal (info))
333 return info->lig_props() & 0x0F;
334 else
335 return 1;
338 static inline uint8_t
339 _hb_allocate_lig_id (hb_buffer_t *buffer) {
340 uint8_t lig_id = buffer->next_serial () & 0x07;
341 if (unlikely (!lig_id))
342 lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */
343 return lig_id;
346 /* glyph_props: */
348 static inline void
349 _hb_glyph_info_set_glyph_props (hb_glyph_info_t *info, unsigned int props)
351 info->glyph_props() = props;
354 static inline unsigned int
355 _hb_glyph_info_get_glyph_props (const hb_glyph_info_t *info)
357 return info->glyph_props();
360 static inline bool
361 _hb_glyph_info_is_base_glyph (const hb_glyph_info_t *info)
363 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH);
366 static inline bool
367 _hb_glyph_info_is_ligature (const hb_glyph_info_t *info)
369 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE);
372 static inline bool
373 _hb_glyph_info_is_mark (const hb_glyph_info_t *info)
375 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
378 static inline bool
379 _hb_glyph_info_substituted (const hb_glyph_info_t *info)
381 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
384 static inline bool
385 _hb_glyph_info_ligated (const hb_glyph_info_t *info)
387 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED);
390 static inline bool
391 _hb_glyph_info_multiplied (const hb_glyph_info_t *info)
393 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
396 static inline bool
397 _hb_glyph_info_ligated_and_didnt_multiply (const hb_glyph_info_t *info)
399 return _hb_glyph_info_ligated (info) && !_hb_glyph_info_multiplied (info);
402 static inline void
403 _hb_glyph_info_clear_ligated_and_multiplied (hb_glyph_info_t *info)
405 info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
406 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
410 /* Allocation / deallocation. */
412 static inline void
413 _hb_buffer_allocate_unicode_vars (hb_buffer_t *buffer)
415 HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props0);
416 HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props1);
419 static inline void
420 _hb_buffer_deallocate_unicode_vars (hb_buffer_t *buffer)
422 HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props0);
423 HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props1);
426 static inline void
427 _hb_buffer_assert_unicode_vars (hb_buffer_t *buffer)
429 HB_BUFFER_ASSERT_VAR (buffer, unicode_props0);
430 HB_BUFFER_ASSERT_VAR (buffer, unicode_props1);
433 static inline void
434 _hb_buffer_allocate_gsubgpos_vars (hb_buffer_t *buffer)
436 HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props);
437 HB_BUFFER_ALLOCATE_VAR (buffer, lig_props);
438 HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
441 static inline void
442 _hb_buffer_deallocate_gsubgpos_vars (hb_buffer_t *buffer)
444 HB_BUFFER_DEALLOCATE_VAR (buffer, syllable);
445 HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props);
446 HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props);
449 static inline void
450 _hb_buffer_assert_gsubgpos_vars (hb_buffer_t *buffer)
452 HB_BUFFER_ASSERT_VAR (buffer, glyph_props);
453 HB_BUFFER_ASSERT_VAR (buffer, lig_props);
454 HB_BUFFER_ASSERT_VAR (buffer, syllable);
457 /* Make sure no one directly touches our props... */
458 #undef unicode_props0
459 #undef unicode_props1
460 #undef lig_props
461 #undef glyph_props
464 #endif /* HB_OT_LAYOUT_PRIVATE_HH */