blob: 45897ed5a81c5e29fe4830f3e96495e10e126d29 [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 Esfahbod0f0cd9d2010-06-09 06:32:56 -040029#ifndef HB_OT_LAYOUT_PRIVATE_HH
30#define HB_OT_LAYOUT_PRIVATE_HH
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -050031
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040032#include "hb-private.hh"
Behdad Esfahbod2c802962009-08-02 15:20:22 -040033
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040034#include "hb-font-private.hh"
Behdad Esfahbod22da7fd2010-05-12 18:23:21 -040035#include "hb-buffer-private.hh"
Behdad Esfahbod1336ecd2012-08-01 21:46:36 -040036#include "hb-set-private.hh"
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -050037
Behdad Esfahbod23c86aa2009-08-03 21:40:20 -040038
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +010039/* Private API corresponding to hb-ot-layout.h: */
40
41HB_INTERNAL hb_bool_t
42hb_ot_layout_table_find_feature (hb_face_t *face,
43 hb_tag_t table_tag,
44 hb_tag_t feature_tag,
45 unsigned int *feature_index);
46
47
Behdad Esfahbod266b3442011-05-03 00:35:53 -040048/*
49 * GDEF
50 */
51
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -080052enum hb_ot_layout_glyph_props_flags_t
Behdad Esfahbod05ad6b52013-10-18 00:45:59 +020053{
Behdad Esfahbod03058c32013-10-17 20:55:34 +020054 /* The following three match LookupFlags::Ignore* numbers. */
Behdad Esfahbod941b6992013-10-17 20:47:33 +020055 HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u,
56 HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u,
Behdad Esfahbod05ad6b52013-10-18 00:45:59 +020057 HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u,
58
59 /* The following are used internally; not derived from GDEF. */
Behdad Esfahbod09675a82013-10-18 01:05:58 +020060 HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u,
61 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u,
Behdad Esfahbod832a6f92014-06-04 16:57:42 -040062 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED = 0x40u,
Behdad Esfahbod03058c32013-10-17 20:55:34 +020063
Behdad Esfahbod09675a82013-10-18 01:05:58 +020064 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED |
Behdad Esfahbod832a6f92014-06-04 16:57:42 -040065 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
66 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -080067};
Chun-wei Fan167c3272015-11-09 17:17:56 +080068HB_MARK_AS_FLAG_T (hb_ot_layout_glyph_props_flags_t);
Behdad Esfahbod5a08ecf2012-11-16 13:34:29 -080069
Behdad Esfahbodead428d2008-01-24 03:54:09 -050070
Behdad Esfahbod49c5ec52012-07-23 20:14:13 -040071/*
72 * GSUB/GPOS
73 */
74
Behdad Esfahbodf8603662012-07-30 02:38:39 -040075HB_INTERNAL hb_bool_t
Behdad Esfahbod362a9902012-11-15 14:57:31 -080076hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -040077 unsigned int lookup_index,
Behdad Esfahbodf8603662012-07-30 02:38:39 -040078 const hb_codepoint_t *glyphs,
79 unsigned int glyphs_length,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -040080 hb_bool_t zero_context);
Behdad Esfahbodf8603662012-07-30 02:38:39 -040081
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -040082
83/* Should be called before all the substitute_lookup's are done. */
84HB_INTERNAL void
Behdad Esfahbodafbcc242012-08-02 08:36:40 -040085hb_ot_layout_substitute_start (hb_font_t *font,
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -040086 hb_buffer_t *buffer);
Behdad Esfahbodf8603662012-07-30 02:38:39 -040087
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -040088
89struct hb_ot_layout_lookup_accelerator_t;
90
91namespace OT {
92 struct hb_apply_context_t;
93 struct SubstLookup;
94}
95
96HB_INTERNAL void
97hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c,
98 const OT::SubstLookup &lookup,
99 const hb_ot_layout_lookup_accelerator_t &accel);
100
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400101
102/* Should be called after all the substitute_lookup's are done */
103HB_INTERNAL void
Behdad Esfahbodafbcc242012-08-02 08:36:40 -0400104hb_ot_layout_substitute_finish (hb_font_t *font,
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400105 hb_buffer_t *buffer);
106
107
108/* Should be called before all the position_lookup's are done. Resets positions to zero. */
109HB_INTERNAL void
110hb_ot_layout_position_start (hb_font_t *font,
111 hb_buffer_t *buffer);
112
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400113/* Should be called after all the position_lookup's are done */
114HB_INTERNAL void
115hb_ot_layout_position_finish (hb_font_t *font,
Behdad Esfahbod56800022013-02-12 09:44:57 -0500116 hb_buffer_t *buffer);
Behdad Esfahbodb0e6a262012-08-02 08:11:14 -0400117
Behdad Esfahbodf8603662012-07-30 02:38:39 -0400118
119
Behdad Esfahbod266b3442011-05-03 00:35:53 -0400120/*
121 * hb_ot_layout_t
122 */
123
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400124namespace OT {
125 struct GDEF;
126 struct GSUB;
127 struct GPOS;
128}
129
Behdad Esfahbod45fd9422013-05-02 18:06:51 -0400130struct hb_ot_layout_lookup_accelerator_t
131{
132 template <typename TLookup>
133 inline void init (const TLookup &lookup)
134 {
135 digest.init ();
136 lookup.add_coverage (&digest);
137 }
138
Behdad Esfahbod395b3592014-12-28 16:03:26 -0800139 inline void fini (void)
Behdad Esfahbod45fd9422013-05-02 18:06:51 -0400140 {
141 }
142
Behdad Esfahbod241eac92015-01-28 20:55:42 -0800143 inline bool may_have (hb_codepoint_t g) const {
144 return digest.may_have (g);
145 }
146
147 private:
Behdad Esfahbod45fd9422013-05-02 18:06:51 -0400148 hb_set_digest_t digest;
149};
150
Behdad Esfahbod266b3442011-05-03 00:35:53 -0400151struct hb_ot_layout_t
152{
153 hb_blob_t *gdef_blob;
154 hb_blob_t *gsub_blob;
155 hb_blob_t *gpos_blob;
Behdad Esfahbod266b3442011-05-03 00:35:53 -0400156
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400157 const struct OT::GDEF *gdef;
158 const struct OT::GSUB *gsub;
159 const struct OT::GPOS *gpos;
Behdad Esfahbod1336ecd2012-08-01 21:46:36 -0400160
Behdad Esfahbod6f761132012-08-02 04:00:31 -0400161 unsigned int gsub_lookup_count;
162 unsigned int gpos_lookup_count;
163
Behdad Esfahbod45fd9422013-05-02 18:06:51 -0400164 hb_ot_layout_lookup_accelerator_t *gsub_accels;
165 hb_ot_layout_lookup_accelerator_t *gpos_accels;
Behdad Esfahbod266b3442011-05-03 00:35:53 -0400166};
167
Behdad Esfahbod266b3442011-05-03 00:35:53 -0400168
169HB_INTERNAL hb_ot_layout_t *
170_hb_ot_layout_create (hb_face_t *face);
171
172HB_INTERNAL void
173_hb_ot_layout_destroy (hb_ot_layout_t *layout);
174
175
Behdad Esfahbod46952462013-10-17 21:01:57 +0200176#define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot)
177
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -0500178
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200179/*
180 * Buffer var routines.
181 */
182
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200183/* buffer var allocations, used during the entire shaping process */
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800184#define unicode_props() var2.u16[0]
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200185
186/* buffer var allocations, used during the GSUB/GPOS processing */
187#define glyph_props() var1.u16[0] /* GDEF glyph properties */
188#define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */
189#define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */
190
Behdad Esfahbodac596512015-07-22 11:54:02 +0100191
192/* loop over syllables */
193
194#define foreach_syllable(buffer, start, end) \
195 for (unsigned int \
196 _count = buffer->len, \
197 start = 0, end = _count ? _next_syllable (buffer, 0) : 0; \
198 start < _count; \
199 start = end, end = _next_syllable (buffer, start))
200
201static inline unsigned int
202_next_syllable (hb_buffer_t *buffer, unsigned int start)
203{
204 hb_glyph_info_t *info = buffer->info;
205 unsigned int count = buffer->len;
206
207 unsigned int syllable = info[start].syllable();
208 while (++start < count && syllable == info[start].syllable())
209 ;
210
211 return start;
212}
213
214
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200215/* unicode_props */
216
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800217/* Design:
218 * unicode_props() is a two-byte number. The low byte includes:
219 * - General_Category: 5 bits.
220 * - A bit each for:
221 * * Is it Default_Ignorable(); we have a modified Default_Ignorable().
222 * * Is it U+200D ZWJ?
223 * * Is it U+200C ZWNJ?
224 *
225 * The high-byte has different meanings, switched by the Gen-Cat:
226 * - For Mn,Mc,Me: the modified Combining_Class.
227 * - For Ws: index of which space character this is, if space fallback
228 * is needed, ie. we don't set this by default, only if asked to.
229 *
230 * If needed, we can use the ZWJ/ZWNJ to use the high byte as well,
231 * freeing two more bits.
232 */
233
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -0800234enum hb_unicode_props_flags_t {
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800235 UPROPS_MASK_ZWJ = 0x20u,
236 UPROPS_MASK_ZWNJ = 0x40u,
237 UPROPS_MASK_IGNORABLE = 0x80u,
238 UPROPS_MASK_GEN_CAT = 0x1Fu
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200239};
Chun-wei Fan167c3272015-11-09 17:17:56 +0800240HB_MARK_AS_FLAG_T (hb_unicode_props_flags_t);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200241
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700242static inline void
Behdad Esfahbod69862082015-11-04 18:46:22 -0800243_hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200244{
Behdad Esfahbod69862082015-11-04 18:46:22 -0800245 hb_unicode_funcs_t *unicode = buffer->unicode;
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800246 unsigned int u = info->codepoint;
247 unsigned int gen_cat = (unsigned int) unicode->general_category (u);
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800248 unsigned int props = gen_cat;
249
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800250 if (u >= 0x80)
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800251 {
Behdad Esfahbode3e4bb02015-11-04 18:58:02 -0800252 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII;
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800253 if (unlikely (unicode->is_default_ignorable (u)))
254 {
Behdad Esfahbod69862082015-11-04 18:46:22 -0800255 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES;
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800256 props |= UPROPS_MASK_IGNORABLE;
257 if (u == 0x200Cu) props |= UPROPS_MASK_ZWNJ;
258 if (u == 0x200Du) props |= UPROPS_MASK_ZWJ;
259 }
Behdad Esfahbod90d75f92015-11-03 12:58:12 -0800260 else if (unlikely (HB_UNICODE_GENERAL_CATEGORY_IS_NON_ENCLOSING_MARK (gen_cat)))
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800261 {
Behdad Esfahbod90d75f92015-11-03 12:58:12 -0800262 /* Only Mn and Mc can have non-zero ccc:
263 * http://www.unicode.org/policies/stability_policy.html#Property_Value
264 * """
265 * Canonical_Combining_Class, General_Category
266 * All characters other than those with General_Category property values
267 * Spacing_Mark (Mc) and Nonspacing_Mark (Mn) have the Canonical_Combining_Class
268 * property value 0.
269 * 1.1.5+
270 * """
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800271 *
272 * Also, all Mn's that are Default_Ignorable, have ccc=0, hence
273 * the "else if".
Behdad Esfahbod90d75f92015-11-03 12:58:12 -0800274 */
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800275 props |= unicode->modified_combining_class (info->codepoint)<<8;
276 }
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800277 }
Behdad Esfahboded2024e2015-11-02 17:58:12 -0800278
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800279 info->unicode_props() = props;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200280}
281
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700282static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200283_hb_glyph_info_set_general_category (hb_glyph_info_t *info,
284 hb_unicode_general_category_t gen_cat)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200285{
Behdad Esfahbodcc5d3a32015-11-04 13:21:25 -0800286 /* Clears top-byte. */
287 info->unicode_props() = (unsigned int) gen_cat | (info->unicode_props() & (0xFF & ~UPROPS_MASK_GEN_CAT));
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200288}
289
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700290static inline hb_unicode_general_category_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200291_hb_glyph_info_get_general_category (const hb_glyph_info_t *info)
292{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800293 return (hb_unicode_general_category_t) (info->unicode_props() & UPROPS_MASK_GEN_CAT);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200294}
295
Behdad Esfahbod2f38dde2015-11-04 13:17:33 -0800296static inline bool
297_hb_glyph_info_is_unicode_mark (const hb_glyph_info_t *info)
298{
299 return HB_UNICODE_GENERAL_CATEGORY_IS_MARK (info->unicode_props() & UPROPS_MASK_GEN_CAT);
300}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700301static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200302_hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info,
303 unsigned int modified_class)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200304{
Behdad Esfahbod8249ec32015-11-04 13:26:17 -0800305 if (unlikely (!_hb_glyph_info_is_unicode_mark (info)))
306 return;
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800307 info->unicode_props() = (modified_class<<8) | (info->unicode_props() & 0xFF);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200308}
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700309static inline unsigned int
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200310_hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info)
311{
Behdad Esfahbod8249ec32015-11-04 13:26:17 -0800312 return _hb_glyph_info_is_unicode_mark (info) ? info->unicode_props()>>8 : 0;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200313}
314
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800315static inline bool
316_hb_glyph_info_is_unicode_space (const hb_glyph_info_t *info)
317{
318 return _hb_glyph_info_get_general_category (info) ==
319 HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR;
320}
321static inline void
Behdad Esfahbod7793aad2015-11-04 14:48:46 -0800322_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 -0800323{
324 if (unlikely (!_hb_glyph_info_is_unicode_space (info)))
325 return;
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800326 info->unicode_props() = (((unsigned int) s)<<8) | (info->unicode_props() & 0xFF);
327}
Behdad Esfahbod7793aad2015-11-04 14:48:46 -0800328static inline hb_unicode_funcs_t::space_t
329_hb_glyph_info_get_unicode_space_fallback_type (const hb_glyph_info_t *info)
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800330{
Behdad Esfahbod7793aad2015-11-04 14:48:46 -0800331 return _hb_glyph_info_is_unicode_space (info) ?
332 (hb_unicode_funcs_t::space_t) (info->unicode_props()>>8) :
333 hb_unicode_funcs_t::NOT_SPACE;
Behdad Esfahbod9ac4b962015-11-04 14:18:39 -0800334}
335
Behdad Esfahbod4ba796b2015-07-22 17:41:31 +0100336static inline bool _hb_glyph_info_ligated (const hb_glyph_info_t *info);
337
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700338static inline hb_bool_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200339_hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info)
340{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800341 return (info->unicode_props() & UPROPS_MASK_IGNORABLE) && !_hb_glyph_info_ligated (info);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200342}
343
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700344static inline hb_bool_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200345_hb_glyph_info_is_zwnj (const hb_glyph_info_t *info)
346{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800347 return !!(info->unicode_props() & UPROPS_MASK_ZWNJ);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200348}
349
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700350static inline hb_bool_t
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200351_hb_glyph_info_is_zwj (const hb_glyph_info_t *info)
352{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800353 return !!(info->unicode_props() & UPROPS_MASK_ZWJ);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200354}
355
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700356static inline void
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200357_hb_glyph_info_flip_joiners (hb_glyph_info_t *info)
358{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800359 info->unicode_props() ^= UPROPS_MASK_ZWNJ | UPROPS_MASK_ZWJ;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200360}
361
362/* lig_props: aka lig_id / lig_comp
363 *
364 * When a ligature is formed:
365 *
366 * - The ligature glyph and any marks in between all the same newly allocated
367 * lig_id,
368 * - The ligature glyph will get lig_num_comps set to the number of components
369 * - The marks get lig_comp > 0, reflecting which component of the ligature
370 * they were applied to.
371 * - This is used in GPOS to attach marks to the right component of a ligature
372 * in MarkLigPos,
373 * - Note that when marks are ligated together, much of the above is skipped
374 * and the current lig_id reused.
375 *
376 * When a multiple-substitution is done:
377 *
378 * - All resulting glyphs will have lig_id = 0,
379 * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
380 * - This is used in GPOS to attach marks to the first component of a
381 * multiple substitution in MarkBasePos.
382 *
383 * The numbers are also used in GPOS to do mark-to-mark positioning only
384 * to marks that belong to the same component of the same ligature.
385 */
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200386
387static inline void
388_hb_glyph_info_clear_lig_props (hb_glyph_info_t *info)
389{
390 info->lig_props() = 0;
391}
392
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200393#define IS_LIG_BASE 0x10
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200394
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200395static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200396_hb_glyph_info_set_lig_props_for_ligature (hb_glyph_info_t *info,
397 unsigned int lig_id,
398 unsigned int lig_num_comps)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200399{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200400 info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200401}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200402
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200403static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200404_hb_glyph_info_set_lig_props_for_mark (hb_glyph_info_t *info,
405 unsigned int lig_id,
406 unsigned int lig_comp)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200407{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200408 info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200409}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200410
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200411static inline void
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200412_hb_glyph_info_set_lig_props_for_component (hb_glyph_info_t *info, unsigned int comp)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200413{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200414 _hb_glyph_info_set_lig_props_for_mark (info, 0, comp);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200415}
416
417static inline unsigned int
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200418_hb_glyph_info_get_lig_id (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200419{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200420 return info->lig_props() >> 5;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200421}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200422
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200423static inline bool
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200424_hb_glyph_info_ligated_internal (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200425{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200426 return !!(info->lig_props() & IS_LIG_BASE);
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200427}
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200428
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200429static inline unsigned int
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200430_hb_glyph_info_get_lig_comp (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200431{
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200432 if (_hb_glyph_info_ligated_internal (info))
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200433 return 0;
434 else
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200435 return info->lig_props() & 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 unsigned int
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200439_hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info)
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200440{
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200441 if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) &&
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200442 _hb_glyph_info_ligated_internal (info))
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200443 return info->lig_props() & 0x0F;
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200444 else
445 return 1;
446}
447
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200448static inline uint8_t
449_hb_allocate_lig_id (hb_buffer_t *buffer) {
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200450 uint8_t lig_id = buffer->next_serial () & 0x07;
451 if (unlikely (!lig_id))
Behdad Esfahbod3ddf8922013-10-18 00:02:43 +0200452 lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200453 return lig_id;
454}
455
Behdad Esfahbod91689de2013-10-18 00:21:59 +0200456/* glyph_props: */
457
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700458static inline void
Behdad Esfahbod91689de2013-10-18 00:21:59 +0200459_hb_glyph_info_set_glyph_props (hb_glyph_info_t *info, unsigned int props)
460{
461 info->glyph_props() = props;
462}
463
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700464static inline unsigned int
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200465_hb_glyph_info_get_glyph_props (const hb_glyph_info_t *info)
466{
467 return info->glyph_props();
468}
Behdad Esfahbod91689de2013-10-18 00:21:59 +0200469
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700470static inline bool
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200471_hb_glyph_info_is_base_glyph (const hb_glyph_info_t *info)
472{
473 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH);
474}
475
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700476static inline bool
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200477_hb_glyph_info_is_ligature (const hb_glyph_info_t *info)
478{
479 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE);
480}
481
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700482static inline bool
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200483_hb_glyph_info_is_mark (const hb_glyph_info_t *info)
484{
485 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
486}
487
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200488static inline bool
Behdad Esfahbod85702732013-10-18 01:11:05 +0200489_hb_glyph_info_substituted (const hb_glyph_info_t *info)
490{
491 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
492}
493
494static inline bool
Behdad Esfahboda1f7b282013-10-18 01:09:08 +0200495_hb_glyph_info_ligated (const hb_glyph_info_t *info)
496{
497 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED);
498}
499
Behdad Esfahbod832a6f92014-06-04 16:57:42 -0400500static inline bool
501_hb_glyph_info_multiplied (const hb_glyph_info_t *info)
502{
503 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
504}
505
506static inline bool
507_hb_glyph_info_ligated_and_didnt_multiply (const hb_glyph_info_t *info)
508{
509 return _hb_glyph_info_ligated (info) && !_hb_glyph_info_multiplied (info);
510}
511
Behdad Esfahbod04dc52f2014-06-06 17:28:38 -0400512static inline void
513_hb_glyph_info_clear_ligated_and_multiplied (hb_glyph_info_t *info)
514{
515 info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
516 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
517}
518
Behdad Esfahbod595936e2015-07-21 14:15:35 +0100519static inline void
520_hb_glyph_info_clear_substituted_and_ligated_and_multiplied (hb_glyph_info_t *info)
521{
522 info->glyph_props() &= ~(HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED |
523 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
524 HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED);
525}
526
Behdad Esfahbod04dc52f2014-06-06 17:28:38 -0400527
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200528/* Allocation / deallocation. */
529
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700530static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200531_hb_buffer_allocate_unicode_vars (hb_buffer_t *buffer)
532{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800533 HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props);
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200534}
535
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700536static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200537_hb_buffer_deallocate_unicode_vars (hb_buffer_t *buffer)
538{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800539 HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props);
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200540}
541
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700542static inline void
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -0400543_hb_buffer_assert_unicode_vars (hb_buffer_t *buffer)
544{
Behdad Esfahbod9382c472015-11-02 17:36:51 -0800545 HB_BUFFER_ASSERT_VAR (buffer, unicode_props);
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -0400546}
547
548static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200549_hb_buffer_allocate_gsubgpos_vars (hb_buffer_t *buffer)
550{
551 HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props);
552 HB_BUFFER_ALLOCATE_VAR (buffer, lig_props);
553 HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
554}
555
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -0700556static inline void
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200557_hb_buffer_deallocate_gsubgpos_vars (hb_buffer_t *buffer)
558{
559 HB_BUFFER_DEALLOCATE_VAR (buffer, syllable);
560 HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props);
561 HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props);
562}
563
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -0400564static inline void
565_hb_buffer_assert_gsubgpos_vars (hb_buffer_t *buffer)
566{
567 HB_BUFFER_ASSERT_VAR (buffer, glyph_props);
568 HB_BUFFER_ASSERT_VAR (buffer, lig_props);
569 HB_BUFFER_ASSERT_VAR (buffer, syllable);
570}
571
Behdad Esfahbod101303d2013-10-18 00:42:39 +0200572/* Make sure no one directly touches our props... */
573#undef unicode_props0
574#undef unicode_props1
575#undef lig_props
576#undef glyph_props
Behdad Esfahbod2e96d2c2013-10-17 21:16:20 +0200577
578
Behdad Esfahbod0f0cd9d2010-06-09 06:32:56 -0400579#endif /* HB_OT_LAYOUT_PRIVATE_HH */