blob: 64b3d7480d67b2466ab10a133f9dfc0592d11349 [file] [log] [blame]
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -05001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2007,2008,2009 Red Hat, Inc.
Behdad Esfahbod46952462013-10-17 21:01:57 +02003 * Copyright © 2012,2013 Google, Inc.
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -05004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -05006 *
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
Behdad Esfahbodf8603662012-07-30 02:38:39 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -050027 */
28
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070029#ifndef HB_OT_LAYOUT_HH
30#define HB_OT_LAYOUT_HH
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -050031
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070032#include "hb.hh"
Behdad Esfahbod2c802962009-08-02 15:20:22 -040033
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070034#include "hb-font.hh"
35#include "hb-buffer.hh"
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070036#include "hb-open-type.hh"
Behdad Esfahbod963413f2018-08-26 00:47:55 -070037#include "hb-set-digest.hh"
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -050038
Behdad Esfahbod23c86aa2009-08-03 21:40:20 -040039
Behdad Esfahbodb9291002018-08-26 01:15:47 -070040namespace OT
41{
42 struct GDEF;
43 struct GSUB;
44 struct GPOS;
45}
46
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -070047HB_INTERNAL const OT::GDEF& _get_gdef (hb_face_t *face);
Behdad Esfahbod39990942018-08-26 09:12:25 -070048HB_INTERNAL const OT::GSUB& _get_gsub_relaxed (hb_face_t *face);
49HB_INTERNAL const OT::GPOS& _get_gpos_relaxed (hb_face_t *face);
Behdad Esfahbodb9291002018-08-26 01:15:47 -070050
51
Behdad Esfahboda5195882018-10-08 23:57:45 -040052/*
53 * kern
54 */
55
56HB_INTERNAL hb_bool_t
57hb_ot_layout_has_kerning (hb_face_t *face);
58
59HB_INTERNAL void
60hb_ot_layout_kern (hb_font_t *font,
61 hb_buffer_t *buffer,
62 hb_mask_t kern_mask);
63
64
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +010065/* Private API corresponding to hb-ot-layout.h: */
66
67HB_INTERNAL hb_bool_t
68hb_ot_layout_table_find_feature (hb_face_t *face,
69 hb_tag_t table_tag,
70 hb_tag_t feature_tag,
71 unsigned int *feature_index);
72
73
Behdad Esfahbod266b3442011-05-03 00:35:53 -040074/*
75 * GDEF
76 */
77
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -080078enum hb_ot_layout_glyph_props_flags_t
Behdad Esfahbod05ad6b52013-10-18 00:45:59 +020079{
Behdad Esfahbod03058c32013-10-17 20:55:34 +020080 /* The following three match LookupFlags::Ignore* numbers. */
Behdad Esfahbod941b6992013-10-17 20:47:33 +020081 HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u,
82 HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u,
Behdad Esfahbod05ad6b52013-10-18 00:45:59 +020083 HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u,
84
85 /* The following are used internally; not derived from GDEF. */
Behdad Esfahbod09675a82013-10-18 01:05:58 +020086 HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u,
87 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u,
Behdad Esfahbod832a6f92014-06-04 16:57:42 -040088 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED = 0x40u,
Behdad Esfahbod03058c32013-10-17 20:55:34 +020089
Behdad Esfahbod09675a82013-10-18 01:05:58 +020090 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED |
Behdad Esfahbod832a6f92014-06-04 16:57:42 -040091 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
92 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -080093};
Chun-wei Fan167c3272015-11-09 17:17:56 +080094HB_MARK_AS_FLAG_T (hb_ot_layout_glyph_props_flags_t);
Behdad Esfahbod5a08ecf2012-11-16 13:34:29 -080095
Behdad Esfahbodead428d2008-01-24 03:54:09 -050096
Behdad Esfahbod49c5ec52012-07-23 20:14:13 -040097/*
98 * GSUB/GPOS
99 */
100
Behdad Esfahbodf8603662012-07-30 02:38:39 -0400101HB_INTERNAL hb_bool_t
Behdad Esfahbod362a9902012-11-15 14:57:31 -0800102hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -0400103 unsigned int lookup_index,
Behdad Esfahbodf8603662012-07-30 02:38:39 -0400104 const hb_codepoint_t *glyphs,
105 unsigned int glyphs_length,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -0400106 hb_bool_t zero_context);
Behdad Esfahbodf8603662012-07-30 02:38:39 -0400107
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400108
109/* Should be called before all the substitute_lookup's are done. */
110HB_INTERNAL void
Behdad Esfahbodafbcc242012-08-02 08:36:40 -0400111hb_ot_layout_substitute_start (hb_font_t *font,
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400112 hb_buffer_t *buffer);
Behdad Esfahbodf8603662012-07-30 02:38:39 -0400113
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -0400114
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -0400115namespace OT {
Behdad Esfahbodfd034492018-01-17 16:46:51 -0800116 struct hb_ot_apply_context_t;
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -0400117 struct SubstLookup;
Behdad Esfahbod97e59132018-10-10 11:41:05 -0400118 struct hb_ot_layout_lookup_accelerator_t;
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -0400119}
120
121HB_INTERNAL void
Behdad Esfahbodfd034492018-01-17 16:46:51 -0800122hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -0400123 const OT::SubstLookup &lookup,
Behdad Esfahbod97e59132018-10-10 11:41:05 -0400124 const OT::hb_ot_layout_lookup_accelerator_t &accel);
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -0400125
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400126
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +0700127/* Should be called before all the position_lookup's are done. */
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400128HB_INTERNAL void
129hb_ot_layout_position_start (hb_font_t *font,
130 hb_buffer_t *buffer);
131
Behdad Esfahboda60ba792018-05-01 19:01:25 -0400132/* Should be called after all the position_lookup's are done, to fini advances. */
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400133HB_INTERNAL void
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +0700134hb_ot_layout_position_finish_advances (hb_font_t *font,
135 hb_buffer_t *buffer);
136
Behdad Esfahboda60ba792018-05-01 19:01:25 -0400137/* Should be called after hb_ot_layout_position_finish_advances, to fini offsets. */
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +0700138HB_INTERNAL void
139hb_ot_layout_position_finish_offsets (hb_font_t *font,
140 hb_buffer_t *buffer);
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400141
Behdad Esfahbodf8603662012-07-30 02:38:39 -0400142
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200143/*
144 * Buffer var routines.
145 */
146
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200147/* buffer var allocations, used during the entire shaping process */
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800148#define unicode_props() var2.u16[0]
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200149
150/* buffer var allocations, used during the GSUB/GPOS processing */
151#define glyph_props() var1.u16[0] /* GDEF glyph properties */
152#define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */
153#define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */
154
Behdad Esfahbodac596512015-07-22 11:54:02 +0100155
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700156/* Loop over syllables. Based on foreach_cluster(). */
Behdad Esfahbodac596512015-07-22 11:54:02 +0100157#define foreach_syllable(buffer, start, end) \
158 for (unsigned int \
159 _count = buffer->len, \
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200160 start = 0, end = _count ? _hb_next_syllable (buffer, 0) : 0; \
Behdad Esfahbodac596512015-07-22 11:54:02 +0100161 start < _count; \
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200162 start = end, end = _hb_next_syllable (buffer, start))
Behdad Esfahbodac596512015-07-22 11:54:02 +0100163
164static inline unsigned int
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200165_hb_next_syllable (hb_buffer_t *buffer, unsigned int start)
Behdad Esfahbodac596512015-07-22 11:54:02 +0100166{
167 hb_glyph_info_t *info = buffer->info;
168 unsigned int count = buffer->len;
169
170 unsigned int syllable = info[start].syllable();
171 while (++start < count && syllable == info[start].syllable())
172 ;
173
174 return start;
175}
176
177
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200178/* unicode_props */
179
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800180/* Design:
181 * unicode_props() is a two-byte number. The low byte includes:
182 * - General_Category: 5 bits.
183 * - A bit each for:
184 * * Is it Default_Ignorable(); we have a modified Default_Ignorable().
Behdad Esfahbod81e2b9b2017-10-15 10:48:19 +0200185 * * Whether it's one of the three Mongolian Free Variation Selectors,
186 * CGJ, or other characters that are hidden but should not be ignored
187 * like most other Default_Ignorable()s do during matching.
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200188 * * Whether it's a grapheme continuation.
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800189 *
190 * The high-byte has different meanings, switched by the Gen-Cat:
191 * - For Mn,Mc,Me: the modified Combining_Class.
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700192 * - For Cf: whether it's ZWJ, ZWNJ, or something else.
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800193 * - For Ws: index of which space character this is, if space fallback
194 * is needed, ie. we don't set this by default, only if asked to.
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800195 */
196
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -0800197enum hb_unicode_props_flags_t {
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700198 UPROPS_MASK_GEN_CAT = 0x001Fu,
199 UPROPS_MASK_IGNORABLE = 0x0020u,
Behdad Esfahbod68106b12018-10-03 20:50:12 +0200200 UPROPS_MASK_HIDDEN = 0x0040u, /* MONGOLIAN FREE VARIATION SELECTOR 1..3, or TAG characters */
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200201 UPROPS_MASK_CONTINUATION=0x0080u,
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700202
203 /* If GEN_CAT=FORMAT, top byte masks: */
204 UPROPS_MASK_Cf_ZWJ = 0x0100u,
205 UPROPS_MASK_Cf_ZWNJ = 0x0200u
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200206};
Chun-wei Fan167c3272015-11-09 17:17:56 +0800207HB_MARK_AS_FLAG_T (hb_unicode_props_flags_t);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200208
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700209static inline void
Behdad Esfahbod69862082015-11-04 18:46:22 -0800210_hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200211{
Behdad Esfahbod69862082015-11-04 18:46:22 -0800212 hb_unicode_funcs_t *unicode = buffer->unicode;
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800213 unsigned int u = info->codepoint;
Behdad Esfahbodb710ea42018-10-03 21:17:59 +0200214 unsigned int gen_cat = (unsigned int) unicode->general_category (u);
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800215 unsigned int props = gen_cat;
216
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800217 if (u >= 0x80)
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800218 {
Behdad Esfahbode3e4bb02015-11-04 18:58:02 -0800219 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII;
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200220
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800221 if (unlikely (unicode->is_default_ignorable (u)))
222 {
Behdad Esfahbod69862082015-11-04 18:46:22 -0800223 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES;
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800224 props |= UPROPS_MASK_IGNORABLE;
Behdad Esfahbodc36f3f52018-10-02 14:34:29 +0200225 if (u == 0x200Cu) props |= UPROPS_MASK_Cf_ZWNJ;
226 else if (u == 0x200Du) props |= UPROPS_MASK_Cf_ZWJ;
Behdad Esfahbodb2030502016-04-26 16:41:17 -0700227 /* Mongolian Free Variation Selectors need to be remembered
228 * because although we need to hide them like default-ignorables,
229 * they need to non-ignorable during shaping. This is similar to
230 * what we do for joiners in Indic-like shapers, but since the
231 * FVSes are GC=Mn, we have use a separate bit to remember them.
232 * Fixes:
ebraminio7c6937e2017-11-20 14:49:22 -0500233 * https://github.com/harfbuzz/harfbuzz/issues/234 */
Behdad Esfahbod81e2b9b2017-10-15 10:48:19 +0200234 else if (unlikely (hb_in_range (u, 0x180Bu, 0x180Du))) props |= UPROPS_MASK_HIDDEN;
Khaled Hosny06cfe3f2017-05-17 21:32:47 +0300235 /* TAG characters need similar treatment. Fixes:
ebraminio7c6937e2017-11-20 14:49:22 -0500236 * https://github.com/harfbuzz/harfbuzz/issues/463 */
Behdad Esfahbod81e2b9b2017-10-15 10:48:19 +0200237 else if (unlikely (hb_in_range (u, 0xE0020u, 0xE007Fu))) props |= UPROPS_MASK_HIDDEN;
238 /* COMBINING GRAPHEME JOINER should not be skipped; at least some times.
ebraminio7c6937e2017-11-20 14:49:22 -0500239 * https://github.com/harfbuzz/harfbuzz/issues/554 */
Behdad Esfahbod8c0d1912018-01-05 12:46:12 +0000240 else if (unlikely (u == 0x034Fu))
241 {
242 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_CGJ;
243 props |= UPROPS_MASK_HIDDEN;
244 }
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800245 }
Behdad Esfahbodaae28472016-02-18 17:06:25 +0700246
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200247 if (unlikely (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (gen_cat)))
248 {
249 props |= UPROPS_MASK_CONTINUATION;
Behdad Esfahbod6ebbf512018-09-14 12:15:53 +0200250 props |= unicode->modified_combining_class (u)<<8;
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800251 }
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800252 }
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800253
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800254 info->unicode_props() = props;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200255}
256
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700257static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200258_hb_glyph_info_set_general_category (hb_glyph_info_t *info,
259 hb_unicode_general_category_t gen_cat)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200260{
Behdad Esfahbodcc5d3a32015-11-04 13:21:25 -0800261 /* Clears top-byte. */
262 info->unicode_props() = (unsigned int) gen_cat | (info->unicode_props() & (0xFF & ~UPROPS_MASK_GEN_CAT));
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200263}
264
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700265static inline hb_unicode_general_category_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200266_hb_glyph_info_get_general_category (const hb_glyph_info_t *info)
267{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800268 return (hb_unicode_general_category_t) (info->unicode_props() & UPROPS_MASK_GEN_CAT);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200269}
270
Behdad Esfahbod2f38dde2015-11-04 13:17:33 -0800271static inline bool
272_hb_glyph_info_is_unicode_mark (const hb_glyph_info_t *info)
273{
274 return HB_UNICODE_GENERAL_CATEGORY_IS_MARK (info->unicode_props() & UPROPS_MASK_GEN_CAT);
275}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700276static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200277_hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info,
278 unsigned int modified_class)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200279{
Behdad Esfahbod8249ec32015-11-04 13:26:17 -0800280 if (unlikely (!_hb_glyph_info_is_unicode_mark (info)))
281 return;
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800282 info->unicode_props() = (modified_class<<8) | (info->unicode_props() & 0xFF);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200283}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700284static inline unsigned int
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200285_hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info)
286{
Behdad Esfahbod8249ec32015-11-04 13:26:17 -0800287 return _hb_glyph_info_is_unicode_mark (info) ? info->unicode_props()>>8 : 0;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200288}
Behdad Esfahbodb6fe0ab2017-10-04 13:37:08 +0200289#define info_cc(info) (_hb_glyph_info_get_modified_combining_class (&(info)))
290
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800291static inline bool
292_hb_glyph_info_is_unicode_space (const hb_glyph_info_t *info)
293{
294 return _hb_glyph_info_get_general_category (info) ==
295 HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR;
296}
297static inline void
Behdad Esfahbod7793aad2015-11-04 14:48:46 -0800298_hb_glyph_info_set_unicode_space_fallback_type (hb_glyph_info_t *info, hb_unicode_funcs_t::space_t s)
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800299{
300 if (unlikely (!_hb_glyph_info_is_unicode_space (info)))
301 return;
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800302 info->unicode_props() = (((unsigned int) s)<<8) | (info->unicode_props() & 0xFF);
303}
Behdad Esfahbod7793aad2015-11-04 14:48:46 -0800304static inline hb_unicode_funcs_t::space_t
305_hb_glyph_info_get_unicode_space_fallback_type (const hb_glyph_info_t *info)
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800306{
Behdad Esfahbod7793aad2015-11-04 14:48:46 -0800307 return _hb_glyph_info_is_unicode_space (info) ?
308 (hb_unicode_funcs_t::space_t) (info->unicode_props()>>8) :
309 hb_unicode_funcs_t::NOT_SPACE;
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800310}
311
Behdad Esfahbod4ba796b2015-07-22 17:41:31 +0100312static inline bool _hb_glyph_info_ligated (const hb_glyph_info_t *info);
313
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700314static inline hb_bool_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200315_hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info)
316{
Behdad Esfahbodb2030502016-04-26 16:41:17 -0700317 return (info->unicode_props() & UPROPS_MASK_IGNORABLE) &&
318 !_hb_glyph_info_ligated (info);
319}
320static inline hb_bool_t
Khaled Hosny06cfe3f2017-05-17 21:32:47 +0300321_hb_glyph_info_is_default_ignorable_and_not_hidden (const hb_glyph_info_t *info)
Behdad Esfahbodb2030502016-04-26 16:41:17 -0700322{
Khaled Hosny06cfe3f2017-05-17 21:32:47 +0300323 return ((info->unicode_props() & (UPROPS_MASK_IGNORABLE|UPROPS_MASK_HIDDEN))
Behdad Esfahbodb2030502016-04-26 16:41:17 -0700324 == UPROPS_MASK_IGNORABLE) &&
325 !_hb_glyph_info_ligated (info);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200326}
Behdad Esfahbod8c0d1912018-01-05 12:46:12 +0000327static inline void
328_hb_glyph_info_unhide (hb_glyph_info_t *info)
329{
330 info->unicode_props() &= ~ UPROPS_MASK_HIDDEN;
331}
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200332
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200333static inline void
334_hb_glyph_info_set_continuation (hb_glyph_info_t *info)
335{
336 info->unicode_props() |= UPROPS_MASK_CONTINUATION;
337}
Behdad Esfahbod6f39c222018-10-03 20:06:32 +0200338static inline void
339_hb_glyph_info_reset_continuation (hb_glyph_info_t *info)
340{
341 info->unicode_props() &= ~ UPROPS_MASK_CONTINUATION;
342}
Behdad Esfahbod3b783182018-10-03 19:44:15 +0200343static inline bool
344_hb_glyph_info_is_continuation (const hb_glyph_info_t *info)
345{
346 return info->unicode_props() & UPROPS_MASK_CONTINUATION;
347}
348/* Loop over grapheme. Based on foreach_cluster(). */
349#define foreach_grapheme(buffer, start, end) \
350 for (unsigned int \
351 _count = buffer->len, \
352 start = 0, end = _count ? _hb_next_grapheme (buffer, 0) : 0; \
353 start < _count; \
354 start = end, end = _hb_next_grapheme (buffer, start))
355
356static inline unsigned int
357_hb_next_grapheme (hb_buffer_t *buffer, unsigned int start)
358{
359 hb_glyph_info_t *info = buffer->info;
360 unsigned int count = buffer->len;
361
362 while (++start < count && _hb_glyph_info_is_continuation (&info[start]))
363 ;
364
365 return start;
366}
367
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700368static inline bool
369_hb_glyph_info_is_unicode_format (const hb_glyph_info_t *info)
370{
371 return _hb_glyph_info_get_general_category (info) ==
372 HB_UNICODE_GENERAL_CATEGORY_FORMAT;
373}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700374static inline hb_bool_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200375_hb_glyph_info_is_zwnj (const hb_glyph_info_t *info)
376{
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700377 return _hb_glyph_info_is_unicode_format (info) && (info->unicode_props() & UPROPS_MASK_Cf_ZWNJ);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200378}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700379static inline hb_bool_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200380_hb_glyph_info_is_zwj (const hb_glyph_info_t *info)
381{
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700382 return _hb_glyph_info_is_unicode_format (info) && (info->unicode_props() & UPROPS_MASK_Cf_ZWJ);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200383}
Behdad Esfahbod815bdd72016-02-22 18:22:44 +0900384static inline hb_bool_t
385_hb_glyph_info_is_joiner (const hb_glyph_info_t *info)
386{
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700387 return _hb_glyph_info_is_unicode_format (info) && (info->unicode_props() & (UPROPS_MASK_Cf_ZWNJ|UPROPS_MASK_Cf_ZWJ));
Behdad Esfahbod815bdd72016-02-22 18:22:44 +0900388}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700389static inline void
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200390_hb_glyph_info_flip_joiners (hb_glyph_info_t *info)
391{
Behdad Esfahbod21ab5502016-04-26 16:02:04 -0700392 if (!_hb_glyph_info_is_unicode_format (info))
393 return;
394 info->unicode_props() ^= UPROPS_MASK_Cf_ZWNJ | UPROPS_MASK_Cf_ZWJ;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200395}
396
397/* lig_props: aka lig_id / lig_comp
398 *
399 * When a ligature is formed:
400 *
401 * - The ligature glyph and any marks in between all the same newly allocated
402 * lig_id,
403 * - The ligature glyph will get lig_num_comps set to the number of components
404 * - The marks get lig_comp > 0, reflecting which component of the ligature
405 * they were applied to.
406 * - This is used in GPOS to attach marks to the right component of a ligature
407 * in MarkLigPos,
408 * - Note that when marks are ligated together, much of the above is skipped
409 * and the current lig_id reused.
410 *
411 * When a multiple-substitution is done:
412 *
413 * - All resulting glyphs will have lig_id = 0,
414 * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
415 * - This is used in GPOS to attach marks to the first component of a
416 * multiple substitution in MarkBasePos.
417 *
418 * The numbers are also used in GPOS to do mark-to-mark positioning only
419 * to marks that belong to the same component of the same ligature.
420 */
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200421
422static inline void
423_hb_glyph_info_clear_lig_props (hb_glyph_info_t *info)
424{
425 info->lig_props() = 0;
426}
427
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200428#define IS_LIG_BASE 0x10
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200429
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200430static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200431_hb_glyph_info_set_lig_props_for_ligature (hb_glyph_info_t *info,
432 unsigned int lig_id,
433 unsigned int lig_num_comps)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200434{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200435 info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200436}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200437
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200438static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200439_hb_glyph_info_set_lig_props_for_mark (hb_glyph_info_t *info,
440 unsigned int lig_id,
441 unsigned int lig_comp)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200442{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200443 info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200444}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200445
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200446static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200447_hb_glyph_info_set_lig_props_for_component (hb_glyph_info_t *info, unsigned int comp)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200448{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200449 _hb_glyph_info_set_lig_props_for_mark (info, 0, comp);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200450}
451
452static inline unsigned int
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200453_hb_glyph_info_get_lig_id (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200454{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200455 return info->lig_props() >> 5;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200456}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200457
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200458static inline bool
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200459_hb_glyph_info_ligated_internal (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200460{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200461 return !!(info->lig_props() & IS_LIG_BASE);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200462}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200463
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200464static inline unsigned int
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200465_hb_glyph_info_get_lig_comp (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200466{
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200467 if (_hb_glyph_info_ligated_internal (info))
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200468 return 0;
469 else
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200470 return info->lig_props() & 0x0F;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200471}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200472
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200473static inline unsigned int
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200474_hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200475{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200476 if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) &&
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200477 _hb_glyph_info_ligated_internal (info))
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200478 return info->lig_props() & 0x0F;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200479 else
480 return 1;
481}
482
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200483static inline uint8_t
484_hb_allocate_lig_id (hb_buffer_t *buffer) {
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200485 uint8_t lig_id = buffer->next_serial () & 0x07;
486 if (unlikely (!lig_id))
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200487 lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200488 return lig_id;
489}
490
Behdad Esfahbod91689de2013-10-18 00:21:59 +0200491/* glyph_props: */
492
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700493static inline void
Behdad Esfahbod91689de2013-10-18 00:21:59 +0200494_hb_glyph_info_set_glyph_props (hb_glyph_info_t *info, unsigned int props)
495{
496 info->glyph_props() = props;
497}
498
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700499static inline unsigned int
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200500_hb_glyph_info_get_glyph_props (const hb_glyph_info_t *info)
501{
502 return info->glyph_props();
503}
Behdad Esfahbod91689de2013-10-18 00:21:59 +0200504
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700505static inline bool
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200506_hb_glyph_info_is_base_glyph (const hb_glyph_info_t *info)
507{
508 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH);
509}
510
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700511static inline bool
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200512_hb_glyph_info_is_ligature (const hb_glyph_info_t *info)
513{
514 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE);
515}
516
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700517static inline bool
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200518_hb_glyph_info_is_mark (const hb_glyph_info_t *info)
519{
520 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
521}
522
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200523static inline bool
Behdad Esfahbod85702732013-10-18 01:11:05 +0200524_hb_glyph_info_substituted (const hb_glyph_info_t *info)
525{
526 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
527}
528
529static inline bool
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200530_hb_glyph_info_ligated (const hb_glyph_info_t *info)
531{
532 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED);
533}
534
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400535static inline bool
536_hb_glyph_info_multiplied (const hb_glyph_info_t *info)
537{
538 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
539}
540
541static inline bool
542_hb_glyph_info_ligated_and_didnt_multiply (const hb_glyph_info_t *info)
543{
544 return _hb_glyph_info_ligated (info) && !_hb_glyph_info_multiplied (info);
545}
546
Behdad Esfahbod04dc52f2014-06-06 17:28:38 -0400547static inline void
548_hb_glyph_info_clear_ligated_and_multiplied (hb_glyph_info_t *info)
549{
550 info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
551 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
552}
553
Behdad Esfahbod595936e2015-07-21 14:15:35 +0100554static inline void
Behdad Esfahbod2ab0de92015-12-17 11:59:15 +0000555_hb_glyph_info_clear_substituted (hb_glyph_info_t *info)
Behdad Esfahbod595936e2015-07-21 14:15:35 +0100556{
Behdad Esfahbod2ab0de92015-12-17 11:59:15 +0000557 info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
Behdad Esfahbod595936e2015-07-21 14:15:35 +0100558}
559
Behdad Esfahbod04dc52f2014-06-06 17:28:38 -0400560
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200561/* Allocation / deallocation. */
562
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700563static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200564_hb_buffer_allocate_unicode_vars (hb_buffer_t *buffer)
565{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800566 HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props);
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200567}
568
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700569static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200570_hb_buffer_deallocate_unicode_vars (hb_buffer_t *buffer)
571{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800572 HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props);
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200573}
574
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700575static inline void
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -0400576_hb_buffer_assert_unicode_vars (hb_buffer_t *buffer)
577{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800578 HB_BUFFER_ASSERT_VAR (buffer, unicode_props);
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -0400579}
580
581static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200582_hb_buffer_allocate_gsubgpos_vars (hb_buffer_t *buffer)
583{
584 HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props);
585 HB_BUFFER_ALLOCATE_VAR (buffer, lig_props);
586 HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
587}
588
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700589static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200590_hb_buffer_deallocate_gsubgpos_vars (hb_buffer_t *buffer)
591{
592 HB_BUFFER_DEALLOCATE_VAR (buffer, syllable);
593 HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props);
594 HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props);
595}
596
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -0400597static inline void
598_hb_buffer_assert_gsubgpos_vars (hb_buffer_t *buffer)
599{
600 HB_BUFFER_ASSERT_VAR (buffer, glyph_props);
601 HB_BUFFER_ASSERT_VAR (buffer, lig_props);
602 HB_BUFFER_ASSERT_VAR (buffer, syllable);
603}
604
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200605/* Make sure no one directly touches our props... */
606#undef unicode_props0
607#undef unicode_props1
608#undef lig_props
609#undef glyph_props
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200610
Behdad Esfahbodc77ae402018-08-25 22:36:36 -0700611#endif /* HB_OT_LAYOUT_HH */