2 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2006 Behdad Esfahbod
4 * Copyright © 2007,2008,2009 Red Hat, Inc.
5 * Copyright © 2012,2013 Google, Inc.
7 * This is part of HarfBuzz, a text shaping library.
9 * Permission is hereby granted, without written agreement and without
10 * license or royalty fees, to use, copy, modify, and distribute this
11 * software and its documentation for any purpose, provided that the
12 * above copyright notice and the following two paragraphs appear in
13 * all copies of this software.
15 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
16 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
17 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
18 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
21 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
22 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
23 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
24 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
25 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27 * Red Hat Author(s): Behdad Esfahbod
28 * Google Author(s): Behdad Esfahbod
33 #ifndef HB_NO_OT_LAYOUT
36 #error "Cannot compile hb-ot-layout.cc with HB_NO_OT_TAG."
39 #include "hb-open-type.hh"
40 #include "hb-ot-layout.hh"
41 #include "hb-ot-face.hh"
42 #include "hb-ot-map.hh"
45 #include "hb-ot-kern-table.hh"
46 #include "hb-ot-layout-gdef-table.hh"
47 #include "hb-ot-layout-gsub-table.hh"
48 #include "hb-ot-layout-gpos-table.hh"
49 #include "hb-ot-layout-base-table.hh" // Just so we compile it; unused otherwise.
50 #include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise.
51 #include "hb-ot-name-table.hh"
52 #include "hb-ot-os2-table.hh"
54 #include "hb-aat-layout-lcar-table.hh"
55 #include "hb-aat-layout-morx-table.hh"
57 #include "hb-aat-layout-opbd-table.hh" // Just so we compile it; unused otherwise.
60 * SECTION:hb-ot-layout
61 * @title: hb-ot-layout
62 * @short_description: OpenType Layout
65 * Functions for querying OpenType Layout features in the font face.
75 * hb_ot_layout_has_kerning:
76 * @face: The #hb_face_t to work on
78 * Tests whether a face includes any kerning data in the 'kern' table.
79 * Does NOT test for kerning lookups in the GPOS table.
81 * Return value: true if data found, false otherwise
85 hb_ot_layout_has_kerning (hb_face_t *face)
87 return face->table.kern->has_data ();
91 * hb_ot_layout_has_machine_kerning:
92 * @face: The #hb_face_t to work on
94 * Tests whether a face includes any state-machine kerning in the 'kern' table.
95 * Does NOT examine the GPOS table.
97 * Return value: true if data found, false otherwise
101 hb_ot_layout_has_machine_kerning (hb_face_t *face)
103 return face->table.kern->has_state_machine ();
107 * hb_ot_layout_has_cross_kerning:
108 * @face: The #hb_face_t to work on
110 * Tests whether a face has any cross-stream kerning (i.e., kerns
111 * that make adjustments perpendicular to the direction of the text
112 * flow: Y adjustments in horizontal text or X adjustments in
113 * vertical text) in the 'kern' table.
115 * Does NOT examine the GPOS table.
117 * Return value: true is data found, false otherwise
121 hb_ot_layout_has_cross_kerning (hb_face_t *face)
123 return face->table.kern->has_cross_stream ();
127 hb_ot_layout_kern (const hb_ot_shape_plan_t *plan,
131 hb_blob_t *blob = font->face->table.kern.get_blob ();
132 const AAT::kern& kern = *blob->as<AAT::kern> ();
134 AAT::hb_aat_apply_context_t c (plan, font, buffer, blob);
146 OT::GDEF::is_blacklisted (hb_blob_t *blob,
147 hb_face_t *face) const
149 #ifdef HB_NO_OT_LAYOUT_BLACKLIST
152 /* The ugly business of blacklisting individual fonts' tables happen here!
153 * See this thread for why we finally had to bend in and do this:
154 * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html
156 * In certain versions of Times New Roman Italic and Bold Italic,
157 * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark)
158 * in GDEF. Many versions of Tahoma have bad GDEF tables that
159 * incorrectly classify some spacing marks such as certain IPA
160 * symbols as glyph class 3. So do older versions of Microsoft
161 * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04.
163 * Nuke the GDEF tables of to avoid unwanted width-zeroing.
165 * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925
166 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693
167 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875
169 switch HB_CODEPOINT_ENCODE3(blob->length,
170 face->table.GSUB->table.get_length (),
171 face->table.GPOS->table.get_length ())
173 /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */
174 case HB_CODEPOINT_ENCODE3 (442, 2874, 42038):
175 /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */
176 case HB_CODEPOINT_ENCODE3 (430, 2874, 40662):
177 /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */
178 case HB_CODEPOINT_ENCODE3 (442, 2874, 39116):
179 /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */
180 case HB_CODEPOINT_ENCODE3 (430, 2874, 39374):
181 /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */
182 case HB_CODEPOINT_ENCODE3 (490, 3046, 41638):
183 /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */
184 case HB_CODEPOINT_ENCODE3 (478, 3046, 41902):
185 /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */
186 case HB_CODEPOINT_ENCODE3 (898, 12554, 46470):
187 /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */
188 case HB_CODEPOINT_ENCODE3 (910, 12566, 47732):
189 /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */
190 case HB_CODEPOINT_ENCODE3 (928, 23298, 59332):
191 /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */
192 case HB_CODEPOINT_ENCODE3 (940, 23310, 60732):
193 /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
194 case HB_CODEPOINT_ENCODE3 (964, 23836, 60072):
195 /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
196 case HB_CODEPOINT_ENCODE3 (976, 23832, 61456):
197 /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */
198 case HB_CODEPOINT_ENCODE3 (994, 24474, 60336):
199 /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */
200 case HB_CODEPOINT_ENCODE3 (1006, 24470, 61740):
201 /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
202 case HB_CODEPOINT_ENCODE3 (1006, 24576, 61346):
203 /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
204 case HB_CODEPOINT_ENCODE3 (1018, 24572, 62828):
205 /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5 tahoma.ttf from Windows 10 AU */
206 case HB_CODEPOINT_ENCODE3 (1006, 24576, 61352):
207 /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2 tahomabd.ttf from Windows 10 AU */
208 case HB_CODEPOINT_ENCODE3 (1018, 24572, 62834):
209 /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */
210 case HB_CODEPOINT_ENCODE3 (832, 7324, 47162):
211 /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */
212 case HB_CODEPOINT_ENCODE3 (844, 7302, 45474):
213 /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc himalaya.ttf from Windows 7 */
214 case HB_CODEPOINT_ENCODE3 (180, 13054, 7254):
215 /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */
216 case HB_CODEPOINT_ENCODE3 (192, 12638, 7254):
217 /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */
218 case HB_CODEPOINT_ENCODE3 (192, 12690, 7254):
219 /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */
220 /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */
221 case HB_CODEPOINT_ENCODE3 (188, 248, 3852):
222 /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */
223 /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */
224 case HB_CODEPOINT_ENCODE3 (188, 264, 3426):
225 /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */
226 case HB_CODEPOINT_ENCODE3 (1058, 47032, 11818):
227 /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/
228 case HB_CODEPOINT_ENCODE3 (1046, 47030, 12600):
229 /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */
230 case HB_CODEPOINT_ENCODE3 (1058, 71796, 16770):
231 /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */
232 case HB_CODEPOINT_ENCODE3 (1046, 71790, 17862):
233 /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */
234 case HB_CODEPOINT_ENCODE3 (1046, 71788, 17112):
235 /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */
236 case HB_CODEPOINT_ENCODE3 (1058, 71794, 17514):
237 /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */
238 case HB_CODEPOINT_ENCODE3 (1330, 109904, 57938):
239 /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */
240 case HB_CODEPOINT_ENCODE3 (1330, 109904, 58972):
241 /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85 Padauk.ttf
242 * "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */
243 case HB_CODEPOINT_ENCODE3 (1004, 59092, 14836):
250 _hb_ot_layout_set_glyph_props (hb_font_t *font,
253 _hb_buffer_assert_gsubgpos_vars (buffer);
255 const OT::GDEF &gdef = *font->face->table.GDEF->table;
256 unsigned int count = buffer->len;
257 for (unsigned int i = 0; i < count; i++)
259 _hb_glyph_info_set_glyph_props (&buffer->info[i], gdef.get_glyph_props (buffer->info[i].codepoint));
260 _hb_glyph_info_clear_lig_props (&buffer->info[i]);
261 buffer->info[i].syllable() = 0;
268 * hb_ot_layout_has_glyph_classes:
269 * @face: #hb_face_t to work upon
271 * Tests whether a face has any glyph classes defined in its GDEF table.
273 * Return value: true if data found, false otherwise
277 hb_ot_layout_has_glyph_classes (hb_face_t *face)
279 return face->table.GDEF->table->has_glyph_classes ();
283 * hb_ot_layout_get_glyph_class:
284 * @face: The #hb_face_t to work on
285 * @glyph: The #hb_codepoint_t code point to query
287 * Fetches the GDEF class of the requested glyph in the specified face.
289 * Return value: The #hb_ot_layout_glyph_class_t glyph class of the given code
290 * point in the GDEF table of the face.
294 hb_ot_layout_glyph_class_t
295 hb_ot_layout_get_glyph_class (hb_face_t *face,
296 hb_codepoint_t glyph)
298 return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph);
302 * hb_ot_layout_get_glyphs_in_class:
303 * @face: The #hb_face_t to work on
304 * @klass: The #hb_ot_layout_glyph_class_t GDEF class to retrieve
305 * @glyphs: (out): The #hb_set_t set of all glyphs belonging to the requested
308 * Retrieves the set of all glyphs from the face that belong to the requested
309 * glyph class in the face's GDEF table.
314 hb_ot_layout_get_glyphs_in_class (hb_face_t *face,
315 hb_ot_layout_glyph_class_t klass,
316 hb_set_t *glyphs /* OUT */)
318 return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs);
321 #ifndef HB_NO_LAYOUT_UNUSED
323 * hb_ot_layout_get_attach_points:
324 * @face: The #hb_face_t to work on
325 * @glyph: The #hb_codepoint_t code point to query
326 * @start_offset: offset of the first attachment point to retrieve
327 * @point_count: (inout) (allow-none): Input = the maximum number of attachment points to return;
328 * Output = the actual number of attachment points returned (may be zero)
329 * @point_array: (out) (array length=point_count): The array of attachment points found for the query
331 * Fetches a list of all attachment points for the specified glyph in the GDEF
332 * table of the face. The list returned will begin at the offset provided.
334 * Useful if the client program wishes to cache the list.
338 hb_ot_layout_get_attach_points (hb_face_t *face,
339 hb_codepoint_t glyph,
340 unsigned int start_offset,
341 unsigned int *point_count /* IN/OUT */,
342 unsigned int *point_array /* OUT */)
344 return face->table.GDEF->table->get_attach_points (glyph,
350 * hb_ot_layout_get_ligature_carets:
351 * @font: The #hb_font_t to work on
352 * @direction: The #hb_direction_t text direction to use
353 * @glyph: The #hb_codepoint_t code point to query
354 * @start_offset: offset of the first caret position to retrieve
355 * @caret_count: (inout) (allow-none): Input = the maximum number of caret positions to return;
356 * Output = the actual number of caret positions returned (may be zero)
357 * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query
359 * Fetches a list of the caret positions defined for a ligature glyph in the GDEF
360 * table of the font. The list returned will begin at the offset provided.
364 hb_ot_layout_get_ligature_carets (hb_font_t *font,
365 hb_direction_t direction,
366 hb_codepoint_t glyph,
367 unsigned int start_offset,
368 unsigned int *caret_count /* IN/OUT */,
369 hb_position_t *caret_array /* OUT */)
371 unsigned int result_caret_count = caret_count ? *caret_count : 0;
372 unsigned int result = font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, &result_caret_count, caret_array);
375 if (caret_count) *caret_count = result_caret_count;
380 result = font->face->table.lcar->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array);
382 if (caret_count) *caret_count = 0;
395 OT::GSUB::is_blacklisted (hb_blob_t *blob HB_UNUSED,
396 hb_face_t *face) const
398 #ifdef HB_NO_OT_LAYOUT_BLACKLIST
405 OT::GPOS::is_blacklisted (hb_blob_t *blob HB_UNUSED,
406 hb_face_t *face HB_UNUSED) const
408 #ifdef HB_NO_OT_LAYOUT_BLACKLIST
414 static const OT::GSUBGPOS&
415 get_gsubgpos_table (hb_face_t *face,
419 case HB_OT_TAG_GSUB: return *face->table.GSUB->table;
420 case HB_OT_TAG_GPOS: return *face->table.GPOS->table;
421 default: return Null (OT::GSUBGPOS);
427 * hb_ot_layout_table_get_script_tags:
428 * @face: #hb_face_t to work upon
429 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
430 * @start_offset: offset of the first script tag to retrieve
431 * @script_count: (inout) (allow-none): Input = the maximum number of script tags to return;
432 * Output = the actual number of script tags returned (may be zero)
433 * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query
435 * Fetches a list of all scripts enumerated in the specified face's GSUB table
436 * or GPOS table. The list returned will begin at the offset provided.
440 hb_ot_layout_table_get_script_tags (hb_face_t *face,
442 unsigned int start_offset,
443 unsigned int *script_count /* IN/OUT */,
444 hb_tag_t *script_tags /* OUT */)
446 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
448 return g.get_script_tags (start_offset, script_count, script_tags);
451 #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n')
454 * hb_ot_layout_table_find_script:
455 * @face: #hb_face_t to work upon
456 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
457 * @script_tag: #hb_tag_t of the script tag requested
458 * @script_index: (out): The index of the requested script tag
460 * Fetches the index if a given script tag in the specified face's GSUB table
463 * Return value: true if the script is found, false otherwise
467 hb_ot_layout_table_find_script (hb_face_t *face,
470 unsigned int *script_index /* OUT */)
472 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
473 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
475 if (g.find_script_index (script_tag, script_index))
478 /* try finding 'DFLT' */
479 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
482 /* try with 'dflt'; MS site has had typos and many fonts use it now :(.
483 * including many versions of DejaVu Sans Mono! */
484 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
487 /* try with 'latn'; some old fonts put their features there even though
488 they're really trying to support Thai, for example :( */
489 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index))
492 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
496 #ifndef HB_DISABLE_DEPRECATED
498 * hb_ot_layout_table_choose_script:
499 * @face: #hb_face_t to work upon
500 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
501 * @script_tags: Array of #hb_tag_t script tags
502 * @script_index: (out): The index of the requested script tag
503 * @chosen_script: (out): #hb_tag_t of the script tag requested
505 * Deprecated since 2.0.0
508 hb_ot_layout_table_choose_script (hb_face_t *face,
510 const hb_tag_t *script_tags,
511 unsigned int *script_index /* OUT */,
512 hb_tag_t *chosen_script /* OUT */)
515 for (t = script_tags; *t; t++);
516 return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script);
521 * hb_ot_layout_table_select_script:
522 * @face: #hb_face_t to work upon
523 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
524 * @script_count: Number of script tags in the array
525 * @script_tags: Array of #hb_tag_t script tags
526 * @script_index: (out): The index of the requested script
527 * @chosen_script: (out): #hb_tag_t of the requested script
532 hb_ot_layout_table_select_script (hb_face_t *face,
534 unsigned int script_count,
535 const hb_tag_t *script_tags,
536 unsigned int *script_index /* OUT */,
537 hb_tag_t *chosen_script /* OUT */)
539 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
540 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
543 for (i = 0; i < script_count; i++)
545 if (g.find_script_index (script_tags[i], script_index))
548 *chosen_script = script_tags[i];
553 /* try finding 'DFLT' */
554 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) {
556 *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT;
560 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
561 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) {
563 *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE;
567 /* try with 'latn'; some old fonts put their features there even though
568 they're really trying to support Thai, for example :( */
569 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) {
571 *chosen_script = HB_OT_TAG_LATIN_SCRIPT;
575 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
577 *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
583 * hb_ot_layout_table_get_feature_tags:
584 * @face: #hb_face_t to work upon
585 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
586 * @start_offset: offset of the first feature tag to retrieve
587 * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return;
588 * Output = the actual number of feature tags returned (may be zero)
589 * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table
591 * Fetches a list of all feature tags in the given face's GSUB or GPOS table.
595 hb_ot_layout_table_get_feature_tags (hb_face_t *face,
597 unsigned int start_offset,
598 unsigned int *feature_count /* IN/OUT */,
599 hb_tag_t *feature_tags /* OUT */)
601 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
603 return g.get_feature_tags (start_offset, feature_count, feature_tags);
608 * hb_ot_layout_table_find_feature:
609 * @face: #hb_face_t to work upon
610 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
611 * @feature_tag: The #hb_tag_t og the requested feature tag
612 * @feature_index: (out): The index of the requested feature
614 * Fetches the index for a given feature tag in the specified face's GSUB table
617 * Return value: true if the feature is found, false otherwise
620 hb_ot_layout_table_find_feature (hb_face_t *face,
622 hb_tag_t feature_tag,
623 unsigned int *feature_index /* OUT */)
625 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
626 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
628 unsigned int num_features = g.get_feature_count ();
629 for (unsigned int i = 0; i < num_features; i++)
631 if (feature_tag == g.get_feature_tag (i)) {
632 if (feature_index) *feature_index = i;
637 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
643 * hb_ot_layout_script_get_language_tags:
644 * @face: #hb_face_t to work upon
645 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
646 * @script_index: The index of the requested script tag
647 * @start_offset: offset of the first language tag to retrieve
648 * @language_count: (inout) (allow-none): Input = the maximum number of language tags to return;
649 * Output = the actual number of language tags returned (may be zero)
650 * @language_tags: (out) (array length=language_count): Array of language tags found in the table
652 * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath
653 * the specified script index. The list returned will begin at the offset provided.
657 hb_ot_layout_script_get_language_tags (hb_face_t *face,
659 unsigned int script_index,
660 unsigned int start_offset,
661 unsigned int *language_count /* IN/OUT */,
662 hb_tag_t *language_tags /* OUT */)
664 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
666 return s.get_lang_sys_tags (start_offset, language_count, language_tags);
670 #ifndef HB_DISABLE_DEPRECATED
672 * hb_ot_layout_script_find_language:
673 * @face: #hb_face_t to work upon
674 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
675 * @script_index: The index of the requested script tag
676 * @language_tag: The #hb_tag_t of the requested language
677 * @language_index: The index of the requested language
679 * Fetches the index of a given language tag in the specified face's GSUB table
680 * or GPOS table, underneath the specified script tag.
682 * Return value: true if the language tag is found, false otherwise
688 hb_ot_layout_script_find_language (hb_face_t *face,
690 unsigned int script_index,
691 hb_tag_t language_tag,
692 unsigned int *language_index)
694 return hb_ot_layout_script_select_language (face,
705 * hb_ot_layout_script_select_language:
706 * @face: #hb_face_t to work upon
707 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
708 * @script_index: The index of the requested script tag
709 * @language_count: The number of languages in the specified script
710 * @language_tags: The array of language tags
711 * @language_index: (out): The index of the requested language
713 * Fetches the index of a given language tag in the specified face's GSUB table
714 * or GPOS table, underneath the specified script index.
716 * Return value: true if the language tag is found, false otherwise
721 hb_ot_layout_script_select_language (hb_face_t *face,
723 unsigned int script_index,
724 unsigned int language_count,
725 const hb_tag_t *language_tags,
726 unsigned int *language_index /* OUT */)
728 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), "");
729 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
732 for (i = 0; i < language_count; i++)
734 if (s.find_lang_sys_index (language_tags[i], language_index))
738 /* try finding 'dflt' */
739 if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
742 if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
748 * hb_ot_layout_language_get_required_feature_index:
749 * @face: #hb_face_t to work upon
750 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
751 * @script_index: The index of the requested script tag
752 * @language_index: The index of the requested language tag
753 * @feature_index: (out): The index of the requested feature
755 * Fetches the index of a requested feature in the given face's GSUB or GPOS table,
756 * underneath the specified script and language.
758 * Return value: true if the feature is found, false otherwise
762 hb_ot_layout_language_get_required_feature_index (hb_face_t *face,
764 unsigned int script_index,
765 unsigned int language_index,
766 unsigned int *feature_index /* OUT */)
768 return hb_ot_layout_language_get_required_feature (face,
778 * hb_ot_layout_language_get_required_feature:
779 * @face: #hb_face_t to work upon
780 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
781 * @script_index: The index of the requested script tag
782 * @language_index: The index of the requested language tag
783 * @feature_index: (out): The index of the requested feature
784 * @feature_tag: (out): The #hb_tag_t of the requested feature
786 * Fetches the tag of a requested feature index in the given face's GSUB or GPOS table,
787 * underneath the specified script and language.
789 * Return value: true if the feature is found, false otherwise
794 hb_ot_layout_language_get_required_feature (hb_face_t *face,
796 unsigned int script_index,
797 unsigned int language_index,
798 unsigned int *feature_index /* OUT */,
799 hb_tag_t *feature_tag /* OUT */)
801 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
802 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
804 unsigned int index = l.get_required_feature_index ();
805 if (feature_index) *feature_index = index;
806 if (feature_tag) *feature_tag = g.get_feature_tag (index);
808 return l.has_required_feature ();
813 * hb_ot_layout_language_get_feature_indexes:
814 * @face: #hb_face_t to work upon
815 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
816 * @script_index: The index of the requested script tag
817 * @language_index: The index of the requested language tag
818 * @start_offset: offset of the first feature tag to retrieve
819 * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return;
820 * Output: the actual number of feature tags returned (may be zero)
821 * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query
823 * Fetches a list of all features in the specified face's GSUB table
824 * or GPOS table, underneath the specified script and language. The list
825 * returned will begin at the offset provided.
828 hb_ot_layout_language_get_feature_indexes (hb_face_t *face,
830 unsigned int script_index,
831 unsigned int language_index,
832 unsigned int start_offset,
833 unsigned int *feature_count /* IN/OUT */,
834 unsigned int *feature_indexes /* OUT */)
836 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
837 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
839 return l.get_feature_indexes (start_offset, feature_count, feature_indexes);
844 * hb_ot_layout_language_get_feature_tags:
845 * @face: #hb_face_t to work upon
846 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
847 * @script_index: The index of the requested script tag
848 * @language_index: The index of the requested language tag
849 * @start_offset: offset of the first feature tag to retrieve
850 * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return;
851 * Output = the actual number of feature tags returned (may be zero)
852 * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query
854 * Fetches a list of all features in the specified face's GSUB table
855 * or GPOS table, underneath the specified script and language. The list
856 * returned will begin at the offset provided.
860 hb_ot_layout_language_get_feature_tags (hb_face_t *face,
862 unsigned int script_index,
863 unsigned int language_index,
864 unsigned int start_offset,
865 unsigned int *feature_count /* IN/OUT */,
866 hb_tag_t *feature_tags /* OUT */)
868 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
869 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
871 static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), "");
872 unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
875 unsigned int count = *feature_count;
876 for (unsigned int i = 0; i < count; i++)
877 feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]);
885 * hb_ot_layout_language_find_feature:
886 * @face: #hb_face_t to work upon
887 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
888 * @script_index: The index of the requested script tag
889 * @language_index: The index of the requested language tag
890 * @feature_tag: #hb_tag_t of the feature tag requested
891 * @feature_index: (out): The index of the requested feature
893 * Fetches the index of a given feature tag in the specified face's GSUB table
894 * or GPOS table, underneath the specified script and language.
896 * Return value: true if the feature is found, false otherwise
900 hb_ot_layout_language_find_feature (hb_face_t *face,
902 unsigned int script_index,
903 unsigned int language_index,
904 hb_tag_t feature_tag,
905 unsigned int *feature_index /* OUT */)
907 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
908 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
909 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
911 unsigned int num_features = l.get_feature_count ();
912 for (unsigned int i = 0; i < num_features; i++) {
913 unsigned int f_index = l.get_feature_index (i);
915 if (feature_tag == g.get_feature_tag (f_index)) {
916 if (feature_index) *feature_index = f_index;
921 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
927 * hb_ot_layout_feature_get_lookups:
928 * @face: #hb_face_t to work upon
929 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
930 * @feature_index: The index of the requested feature
931 * @start_offset: offset of the first lookup to retrieve
932 * @lookup_count: (inout) (allow-none): Input = the maximum number of lookups to return;
933 * Output = the actual number of lookups returned (may be zero)
934 * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query
936 * Fetches a list of all lookups enumerated for the specified feature, in
937 * the specified face's GSUB table or GPOS table. The list returned will
938 * begin at the offset provided.
943 hb_ot_layout_feature_get_lookups (hb_face_t *face,
945 unsigned int feature_index,
946 unsigned int start_offset,
947 unsigned int *lookup_count /* IN/OUT */,
948 unsigned int *lookup_indexes /* OUT */)
950 return hb_ot_layout_feature_with_variations_get_lookups (face,
953 HB_OT_LAYOUT_NO_VARIATIONS_INDEX,
961 * hb_ot_layout_table_get_lookup_count:
962 * @face: #hb_face_t to work upon
963 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
965 * Fetches the total number of lookups enumerated in the specified
966 * face's GSUB table or GPOS table.
971 hb_ot_layout_table_get_lookup_count (hb_face_t *face,
974 return get_gsubgpos_table (face, table_tag).get_lookup_count ();
978 struct hb_collect_features_context_t
980 hb_collect_features_context_t (hb_face_t *face,
982 hb_set_t *feature_indexes_)
983 : g (get_gsubgpos_table (face, table_tag)),
984 feature_indexes (feature_indexes_),
985 script_count (0),langsys_count (0), feature_index_count (0) {}
987 bool visited (const OT::Script &s)
989 /* We might have Null() object here. Don't want to involve
990 * that in the memoize. So, detect empty objects and return. */
991 if (unlikely (!s.has_default_lang_sys () &&
992 !s.get_lang_sys_count ()))
995 if (script_count++ > HB_MAX_SCRIPTS)
998 return visited (s, visited_script);
1000 bool visited (const OT::LangSys &l)
1002 /* We might have Null() object here. Don't want to involve
1003 * that in the memoize. So, detect empty objects and return. */
1004 if (unlikely (!l.has_required_feature () &&
1005 !l.get_feature_count ()))
1008 if (langsys_count++ > HB_MAX_LANGSYS)
1011 return visited (l, visited_langsys);
1014 bool visited_feature_indices (unsigned count)
1016 feature_index_count += count;
1017 return feature_index_count > HB_MAX_FEATURE_INDICES;
1021 template <typename T>
1022 bool visited (const T &p, hb_set_t &visited_set)
1024 hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g);
1025 if (visited_set.has (delta))
1028 visited_set.add (delta);
1033 const OT::GSUBGPOS &g;
1034 hb_set_t *feature_indexes;
1037 hb_set_t visited_script;
1038 hb_set_t visited_langsys;
1039 unsigned int script_count;
1040 unsigned int langsys_count;
1041 unsigned int feature_index_count;
1045 langsys_collect_features (hb_collect_features_context_t *c,
1046 const OT::LangSys &l,
1047 const hb_tag_t *features)
1049 if (c->visited (l)) return;
1054 if (l.has_required_feature () && !c->visited_feature_indices (1))
1055 c->feature_indexes->add (l.get_required_feature_index ());
1057 if (!c->visited_feature_indices (l.featureIndex.len))
1058 l.add_feature_indexes_to (c->feature_indexes);
1062 /* Ugh. Any faster way? */
1063 for (; *features; features++)
1065 hb_tag_t feature_tag = *features;
1066 unsigned int num_features = l.get_feature_count ();
1067 for (unsigned int i = 0; i < num_features; i++)
1069 unsigned int feature_index = l.get_feature_index (i);
1071 if (feature_tag == c->g.get_feature_tag (feature_index))
1073 c->feature_indexes->add (feature_index);
1082 script_collect_features (hb_collect_features_context_t *c,
1083 const OT::Script &s,
1084 const hb_tag_t *languages,
1085 const hb_tag_t *features)
1087 if (c->visited (s)) return;
1091 /* All languages. */
1092 if (s.has_default_lang_sys ())
1093 langsys_collect_features (c,
1094 s.get_default_lang_sys (),
1097 unsigned int count = s.get_lang_sys_count ();
1098 for (unsigned int language_index = 0; language_index < count; language_index++)
1099 langsys_collect_features (c,
1100 s.get_lang_sys (language_index),
1105 for (; *languages; languages++)
1107 unsigned int language_index;
1108 if (s.find_lang_sys_index (*languages, &language_index))
1109 langsys_collect_features (c,
1110 s.get_lang_sys (language_index),
1118 * hb_ot_layout_collect_features:
1119 * @face: #hb_face_t to work upon
1120 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1121 * @scripts: The array of scripts to collect features for
1122 * @languages: The array of languages to collect features for
1123 * @features: The array of features to collect
1124 * @feature_indexes: (out): The array of feature indexes found for the query
1126 * Fetches a list of all feature indexes in the specified face's GSUB table
1127 * or GPOS table, underneath the specified scripts, languages, and features.
1128 * If no list of scripts is provided, all scripts will be queried. If no list
1129 * of languages is provided, all languages will be queried. If no list of
1130 * features is provided, all features will be queried.
1135 hb_ot_layout_collect_features (hb_face_t *face,
1137 const hb_tag_t *scripts,
1138 const hb_tag_t *languages,
1139 const hb_tag_t *features,
1140 hb_set_t *feature_indexes /* OUT */)
1142 hb_collect_features_context_t c (face, table_tag, feature_indexes);
1146 unsigned int count = c.g.get_script_count ();
1147 for (unsigned int script_index = 0; script_index < count; script_index++)
1148 script_collect_features (&c,
1149 c.g.get_script (script_index),
1155 for (; *scripts; scripts++)
1157 unsigned int script_index;
1158 if (c.g.find_script_index (*scripts, &script_index))
1159 script_collect_features (&c,
1160 c.g.get_script (script_index),
1169 * hb_ot_layout_collect_lookups:
1170 * @face: #hb_face_t to work upon
1171 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1172 * @scripts: The array of scripts to collect lookups for
1173 * @languages: The array of languages to collect lookups for
1174 * @features: The array of features to collect lookups for
1175 * @lookup_indexes: (out): The array of lookup indexes found for the query
1177 * Fetches a list of all feature-lookup indexes in the specified face's GSUB
1178 * table or GPOS table, underneath the specified scripts, languages, and
1179 * features. If no list of scripts is provided, all scripts will be queried.
1180 * If no list of languages is provided, all languages will be queried. If no
1181 * list of features is provided, all features will be queried.
1186 hb_ot_layout_collect_lookups (hb_face_t *face,
1188 const hb_tag_t *scripts,
1189 const hb_tag_t *languages,
1190 const hb_tag_t *features,
1191 hb_set_t *lookup_indexes /* OUT */)
1193 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1195 hb_set_t feature_indexes;
1196 hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes);
1198 for (hb_codepoint_t feature_index = HB_SET_VALUE_INVALID;
1199 hb_set_next (&feature_indexes, &feature_index);)
1200 g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes);
1202 g.feature_variation_collect_lookups (&feature_indexes, lookup_indexes);
1205 #ifdef HB_EXPERIMENTAL_API
1207 * hb_ot_layout_closure_lookups:
1208 * @face: #hb_face_t to work upon
1209 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1210 * @lookup_indexes: (inout): lookup_indices collected from feature
1213 * Returns all inactive lookups reachable from lookup_indices
1215 * Since: EXPERIMENTAL
1218 hb_ot_layout_closure_lookups (hb_face_t *face,
1220 const hb_set_t *glyphs,
1221 hb_set_t *lookup_indexes /* IN/OUT */)
1223 hb_set_t visited_lookups, inactive_lookups;
1224 OT::hb_closure_lookups_context_t c (face, glyphs, &visited_lookups, &inactive_lookups);
1226 for (unsigned lookup_index : + hb_iter (lookup_indexes))
1230 case HB_OT_TAG_GSUB:
1232 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1233 l.closure_lookups (&c, lookup_index);
1236 case HB_OT_TAG_GPOS:
1238 const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index);
1239 l.closure_lookups (&c, lookup_index);
1245 hb_set_union (lookup_indexes, &visited_lookups);
1246 hb_set_subtract (lookup_indexes, &inactive_lookups);
1250 * hb_ot_layout_closure_features:
1251 * @face: #hb_face_t to work upon
1252 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1253 * @lookup_indexes: (in): collected active lookup_indices
1254 * @feature_indexes: (out): all active feature indexes collected
1256 * Returns all active feature indexes
1258 * Since: EXPERIMENTAL
1261 hb_ot_layout_closure_features (hb_face_t *face,
1263 const hb_map_t *lookup_indexes, /* IN */
1264 hb_set_t *feature_indexes /* OUT */)
1266 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1267 g.closure_features (lookup_indexes, feature_indexes);
1272 #ifndef HB_NO_LAYOUT_COLLECT_GLYPHS
1274 * hb_ot_layout_lookup_collect_glyphs:
1275 * @face: #hb_face_t to work upon
1276 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1277 * @lookup_index: The index of the feature lookup to query
1278 * @glyphs_before: (out): Array of glyphs preceding the substitution range
1279 * @glyphs_input: (out): Array of input glyphs that would be substituted by the lookup
1280 * @glyphs_after: (out): Array of glyphs following the substitution range
1281 * @glyphs_output: (out): Array of glyphs that would be the substitued output of the lookup
1283 * Fetches a list of all glyphs affected by the specified lookup in the
1284 * specified face's GSUB table or GPOS table.
1289 hb_ot_layout_lookup_collect_glyphs (hb_face_t *face,
1291 unsigned int lookup_index,
1292 hb_set_t *glyphs_before, /* OUT. May be NULL */
1293 hb_set_t *glyphs_input, /* OUT. May be NULL */
1294 hb_set_t *glyphs_after, /* OUT. May be NULL */
1295 hb_set_t *glyphs_output /* OUT. May be NULL */)
1297 OT::hb_collect_glyphs_context_t c (face,
1305 case HB_OT_TAG_GSUB:
1307 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1308 l.collect_glyphs (&c);
1311 case HB_OT_TAG_GPOS:
1313 const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index);
1314 l.collect_glyphs (&c);
1322 /* Variations support */
1326 * hb_ot_layout_table_find_feature_variations:
1327 * @face: #hb_face_t to work upon
1328 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1329 * @coords: The variation coordinates to query
1330 * @num_coords: The number of variation coorinates
1331 * @variations_index: (out): The array of feature variations found for the query
1333 * Fetches a list of feature variations in the specified face's GSUB table
1334 * or GPOS table, at the specified variation coordinates.
1338 hb_ot_layout_table_find_feature_variations (hb_face_t *face,
1341 unsigned int num_coords,
1342 unsigned int *variations_index /* out */)
1344 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1346 return g.find_variations_index (coords, num_coords, variations_index);
1351 * hb_ot_layout_feature_with_variations_get_lookups:
1352 * @face: #hb_face_t to work upon
1353 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1354 * @feature_index: The index of the feature to query
1355 * @variations_index: The index of the feature variation to query
1356 * @start_offset: offset of the first lookup to retrieve
1357 * @lookup_count: (inout) (allow-none): Input = the maximum number of lookups to return;
1358 * Output = the actual number of lookups returned (may be zero)
1359 * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query
1361 * Fetches a list of all lookups enumerated for the specified feature, in
1362 * the specified face's GSUB table or GPOS table, enabled at the specified
1363 * variations index. The list returned will begin at the offset provided.
1367 hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face,
1369 unsigned int feature_index,
1370 unsigned int variations_index,
1371 unsigned int start_offset,
1372 unsigned int *lookup_count /* IN/OUT */,
1373 unsigned int *lookup_indexes /* OUT */)
1375 static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "");
1376 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1378 const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
1380 return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
1390 * hb_ot_layout_has_substitution:
1391 * @face: #hb_face_t to work upon
1393 * Tests whether the specified face includes any GSUB substitutions.
1395 * Return value: true if data found, false otherwise
1399 hb_ot_layout_has_substitution (hb_face_t *face)
1401 return face->table.GSUB->table->has_data ();
1406 * hb_ot_layout_lookup_would_substitute:
1407 * @face: #hb_face_t to work upon
1408 * @lookup_index: The index of the lookup to query
1409 * @glyphs: The sequence of glyphs to query for substitution
1410 * @glyphs_length: The length of the glyph sequence
1411 * @zero_context: #hb_bool_t indicating whether substitutions should be context-free
1413 * Tests whether a specified lookup in the specified face would
1414 * trigger a substitution on the given glyph sequence.
1416 * Return value: true if a substitution would be triggered, false otherwise
1421 hb_ot_layout_lookup_would_substitute (hb_face_t *face,
1422 unsigned int lookup_index,
1423 const hb_codepoint_t *glyphs,
1424 unsigned int glyphs_length,
1425 hb_bool_t zero_context)
1427 if (unlikely (lookup_index >= face->table.GSUB->lookup_count)) return false;
1428 OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context);
1430 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1432 return l.would_apply (&c, &face->table.GSUB->accels[lookup_index]);
1437 * hb_ot_layout_substitute_start:
1438 * @font: #hb_font_t to use
1439 * @buffer: #hb_buffer_t buffer to work upon
1441 * Called before substitution lookups are performed, to ensure that glyph
1442 * class and other properties are set on the glyphs in the buffer.
1446 hb_ot_layout_substitute_start (hb_font_t *font,
1447 hb_buffer_t *buffer)
1449 _hb_ot_layout_set_glyph_props (font, buffer);
1453 hb_ot_layout_delete_glyphs_inplace (hb_buffer_t *buffer,
1454 bool (*filter) (const hb_glyph_info_t *info))
1456 /* Merge clusters and delete filtered glyphs.
1457 * NOTE! We can't use out-buffer as we have positioning data. */
1459 unsigned int count = buffer->len;
1460 hb_glyph_info_t *info = buffer->info;
1461 hb_glyph_position_t *pos = buffer->pos;
1462 for (unsigned int i = 0; i < count; i++)
1464 if (filter (&info[i]))
1467 * Same logic as buffer->delete_glyph(), but for in-place removal. */
1469 unsigned int cluster = info[i].cluster;
1470 if (i + 1 < count && cluster == info[i + 1].cluster)
1471 continue; /* Cluster survives; do nothing. */
1475 /* Merge cluster backward. */
1476 if (cluster < info[j - 1].cluster)
1478 unsigned int mask = info[i].mask;
1479 unsigned int old_cluster = info[j - 1].cluster;
1480 for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--)
1481 buffer->set_cluster (info[k - 1], cluster, mask);
1487 buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */
1503 * hb_ot_layout_lookup_substitute_closure:
1504 * @face: #hb_face_t to work upon
1505 * @lookup_index: index of the feature lookup to query
1506 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup
1508 * Compute the transitive closure of glyphs needed for a
1514 hb_ot_layout_lookup_substitute_closure (hb_face_t *face,
1515 unsigned int lookup_index,
1516 hb_set_t *glyphs /* OUT */)
1518 hb_map_t done_lookups;
1519 OT::hb_closure_context_t c (face, glyphs, &done_lookups);
1521 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1523 l.closure (&c, lookup_index);
1527 * hb_ot_layout_lookups_substitute_closure:
1528 * @face: #hb_face_t to work upon
1529 * @lookups: The set of lookups to query
1530 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups
1532 * Compute the transitive closure of glyphs needed for all of the
1538 hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
1539 const hb_set_t *lookups,
1540 hb_set_t *glyphs /* OUT */)
1542 hb_map_t done_lookups;
1543 OT::hb_closure_context_t c (face, glyphs, &done_lookups);
1544 const OT::GSUB& gsub = *face->table.GSUB->table;
1546 unsigned int iteration_count = 0;
1547 unsigned int glyphs_length;
1550 glyphs_length = glyphs->get_population ();
1553 for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);)
1554 gsub.get_lookup (lookup_index).closure (&c, lookup_index);
1558 for (unsigned int i = 0; i < gsub.get_lookup_count (); i++)
1559 gsub.get_lookup (i).closure (&c, i);
1561 } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES &&
1562 glyphs_length != glyphs->get_population ());
1571 * hb_ot_layout_has_positioning:
1572 * @face: #hb_face_t to work upon
1574 * Return value: true if the face has GPOS data, false otherwise
1578 hb_ot_layout_has_positioning (hb_face_t *face)
1580 return face->table.GPOS->table->has_data ();
1584 * hb_ot_layout_position_start:
1585 * @font: #hb_font_t to use
1586 * @buffer: #hb_buffer_t buffer to work upon
1588 * Called before positioning lookups are performed, to ensure that glyph
1589 * attachment types and glyph-attachment chains are set for the glyphs in the buffer.
1593 hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer)
1595 OT::GPOS::position_start (font, buffer);
1600 * hb_ot_layout_position_finish_advances:
1601 * @font: #hb_font_t to use
1602 * @buffer: #hb_buffer_t buffer to work upon
1604 * Called after positioning lookups are performed, to finish glyph advances.
1608 hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer)
1610 OT::GPOS::position_finish_advances (font, buffer);
1614 * hb_ot_layout_position_finish_offsets:
1615 * @font: #hb_font_t to use
1616 * @buffer: #hb_buffer_t buffer to work upon
1618 * Called after positioning lookups are performed, to finish glyph offsets.
1622 hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
1624 OT::GPOS::position_finish_offsets (font, buffer);
1628 #ifndef HB_NO_LAYOUT_FEATURE_PARAMS
1630 * hb_ot_layout_get_size_params:
1631 * @face: #hb_face_t to work upon
1632 * @design_size: (out): The design size of the face
1633 * @subfamily_id: (out): The identifier of the face within the font subfamily
1634 * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily
1635 * @range_start: (out): The minimum size of the recommended size range for the face
1636 * @range_end: (out): The maximum size of the recommended size range for the face
1638 * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that
1639 * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id)
1640 * as used here are defined as pertaining only to fonts within a font family that differ
1641 * specifically in their respective size ranges; other ways to differentiate fonts within
1642 * a subfamily are not covered by the `size` feature.
1644 * For more information on this distinction, see the [`size` feature documentation](
1645 * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-size).
1647 * Return value: true if data found, false otherwise
1652 hb_ot_layout_get_size_params (hb_face_t *face,
1653 unsigned int *design_size, /* OUT. May be NULL */
1654 unsigned int *subfamily_id, /* OUT. May be NULL */
1655 hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */
1656 unsigned int *range_start, /* OUT. May be NULL */
1657 unsigned int *range_end /* OUT. May be NULL */)
1659 const OT::GPOS &gpos = *face->table.GPOS->table;
1660 const hb_tag_t tag = HB_TAG ('s','i','z','e');
1662 unsigned int num_features = gpos.get_feature_count ();
1663 for (unsigned int i = 0; i < num_features; i++)
1665 if (tag == gpos.get_feature_tag (i))
1667 const OT::Feature &f = gpos.get_feature (i);
1668 const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag);
1670 if (params.designSize)
1672 if (design_size) *design_size = params.designSize;
1673 if (subfamily_id) *subfamily_id = params.subfamilyID;
1674 if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID;
1675 if (range_start) *range_start = params.rangeStart;
1676 if (range_end) *range_end = params.rangeEnd;
1683 if (design_size) *design_size = 0;
1684 if (subfamily_id) *subfamily_id = 0;
1685 if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID;
1686 if (range_start) *range_start = 0;
1687 if (range_end) *range_end = 0;
1692 * hb_ot_layout_feature_get_name_ids:
1693 * @face: #hb_face_t to work upon
1694 * @table_tag: table tag to query, "GSUB" or "GPOS".
1695 * @feature_index: index of feature to query.
1696 * @label_id: (out) (allow-none): The ‘name’ table name ID that specifies a string
1697 * for a user-interface label for this feature. (May be NULL.)
1698 * @tooltip_id: (out) (allow-none): The ‘name’ table name ID that specifies a string
1699 * that an application can use for tooltip text for this
1700 * feature. (May be NULL.)
1701 * @sample_id: (out) (allow-none): The ‘name’ table name ID that specifies sample text
1702 * that illustrates the effect of this feature. (May be NULL.)
1703 * @num_named_parameters: (out) (allow-none): Number of named parameters. (May be zero.)
1704 * @first_param_id: (out) (allow-none): The first ‘name’ table name ID used to specify
1705 * strings for user-interface labels for the feature
1706 * parameters. (Must be zero if numParameters is zero.)
1708 * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or
1709 * "Character Variant" ('cvXX') features.
1711 * Return value: true if data found, false otherwise
1716 hb_ot_layout_feature_get_name_ids (hb_face_t *face,
1718 unsigned int feature_index,
1719 hb_ot_name_id_t *label_id, /* OUT. May be NULL */
1720 hb_ot_name_id_t *tooltip_id, /* OUT. May be NULL */
1721 hb_ot_name_id_t *sample_id, /* OUT. May be NULL */
1722 unsigned int *num_named_parameters, /* OUT. May be NULL */
1723 hb_ot_name_id_t *first_param_id /* OUT. May be NULL */)
1725 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1727 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1728 const OT::Feature &f = g.get_feature (feature_index);
1730 const OT::FeatureParams &feature_params = f.get_feature_params ();
1731 if (&feature_params != &Null (OT::FeatureParams))
1733 const OT::FeatureParamsStylisticSet& ss_params =
1734 feature_params.get_stylistic_set_params (feature_tag);
1735 if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */
1737 if (label_id) *label_id = ss_params.uiNameID;
1738 // ssXX features don't have the rest
1739 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1740 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1741 if (num_named_parameters) *num_named_parameters = 0;
1742 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1745 const OT::FeatureParamsCharacterVariants& cv_params =
1746 feature_params.get_character_variants_params (feature_tag);
1747 if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */
1749 if (label_id) *label_id = cv_params.featUILableNameID;
1750 if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID;
1751 if (sample_id) *sample_id = cv_params.sampleTextNameID;
1752 if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters;
1753 if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID;
1758 if (label_id) *label_id = HB_OT_NAME_ID_INVALID;
1759 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1760 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1761 if (num_named_parameters) *num_named_parameters = 0;
1762 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1766 * hb_ot_layout_feature_get_characters:
1767 * @face: #hb_face_t to work upon
1768 * @table_tag: table tag to query, "GSUB" or "GPOS".
1769 * @feature_index: index of feature to query.
1770 * @start_offset: offset of the first character to retrieve
1771 * @char_count: (inout) (allow-none): Input = the maximum number of characters to return;
1772 * Output = the actual number of characters returned (may be zero)
1773 * @characters: (out caller-allocates) (array length=char_count): A buffer pointer.
1774 * The Unicode codepoints of the characters for which this feature provides
1777 * Fetches a list of the characters defined as having a variant under the specified
1778 * "Character Variant" ("cvXX") feature tag.
1780 * <note>Note: If the char_count output value is equal to its input value, then there
1781 * is a chance there were more characters defined under the feature tag than were
1782 * returned. This function can be called with incrementally larger start_offset
1783 * until the char_count output value is lower than its input value, or the size
1784 * of the characters array can be increased.</note>
1786 * Return value: Number of total sample characters in the cvXX feature.
1791 hb_ot_layout_feature_get_characters (hb_face_t *face,
1793 unsigned int feature_index,
1794 unsigned int start_offset,
1795 unsigned int *char_count, /* IN/OUT. May be NULL */
1796 hb_codepoint_t *characters /* OUT. May be NULL */)
1798 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1800 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1801 const OT::Feature &f = g.get_feature (feature_index);
1803 const OT::FeatureParams &feature_params = f.get_feature_params ();
1805 const OT::FeatureParamsCharacterVariants& cv_params =
1806 feature_params.get_character_variants_params(feature_tag);
1808 unsigned int len = 0;
1809 if (char_count && characters && start_offset < cv_params.characters.len)
1811 len = hb_min (cv_params.characters.len - start_offset, *char_count);
1812 for (unsigned int i = 0; i < len; ++i)
1813 characters[i] = cv_params.characters[start_offset + i];
1815 if (char_count) *char_count = len;
1816 return cv_params.characters.len;
1822 * Parts of different types are implemented here such that they have direct
1823 * access to GSUB/GPOS lookups.
1829 static constexpr unsigned table_index = 0u;
1830 static constexpr bool inplace = false;
1831 typedef OT::SubstLookup Lookup;
1833 GSUBProxy (hb_face_t *face) :
1834 table (*face->table.GSUB->table),
1835 accels (face->table.GSUB->accels) {}
1837 const OT::GSUB &table;
1838 const OT::hb_ot_layout_lookup_accelerator_t *accels;
1843 static constexpr unsigned table_index = 1u;
1844 static constexpr bool inplace = true;
1845 typedef OT::PosLookup Lookup;
1847 GPOSProxy (hb_face_t *face) :
1848 table (*face->table.GPOS->table),
1849 accels (face->table.GPOS->accels) {}
1851 const OT::GPOS &table;
1852 const OT::hb_ot_layout_lookup_accelerator_t *accels;
1857 apply_forward (OT::hb_ot_apply_context_t *c,
1858 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1861 hb_buffer_t *buffer = c->buffer;
1862 while (buffer->idx < buffer->len && buffer->successful)
1864 bool applied = false;
1865 if (accel.may_have (buffer->cur().codepoint) &&
1866 (buffer->cur().mask & c->lookup_mask) &&
1867 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1869 applied = accel.apply (c);
1875 buffer->next_glyph ();
1881 apply_backward (OT::hb_ot_apply_context_t *c,
1882 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1885 hb_buffer_t *buffer = c->buffer;
1888 if (accel.may_have (buffer->cur().codepoint) &&
1889 (buffer->cur().mask & c->lookup_mask) &&
1890 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1891 ret |= accel.apply (c);
1893 /* The reverse lookup doesn't "advance" cursor (for good reason). */
1897 while ((int) buffer->idx >= 0);
1901 template <typename Proxy>
1903 apply_string (OT::hb_ot_apply_context_t *c,
1904 const typename Proxy::Lookup &lookup,
1905 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1907 hb_buffer_t *buffer = c->buffer;
1909 if (unlikely (!buffer->len || !c->lookup_mask))
1912 c->set_lookup_props (lookup.get_props ());
1914 if (likely (!lookup.is_reverse ()))
1916 /* in/out forward substitution/positioning */
1917 if (Proxy::table_index == 0u)
1918 buffer->clear_output ();
1922 ret = apply_forward (c, accel);
1925 if (!Proxy::inplace)
1926 buffer->swap_buffers ();
1928 assert (!buffer->has_separate_output ());
1933 /* in-place backward substitution/positioning */
1934 if (Proxy::table_index == 0u)
1935 buffer->remove_output ();
1936 buffer->idx = buffer->len - 1;
1938 apply_backward (c, accel);
1942 template <typename Proxy>
1943 inline void hb_ot_map_t::apply (const Proxy &proxy,
1944 const hb_ot_shape_plan_t *plan,
1946 hb_buffer_t *buffer) const
1948 const unsigned int table_index = proxy.table_index;
1950 OT::hb_ot_apply_context_t c (table_index, font, buffer);
1951 c.set_recurse_func (Proxy::Lookup::apply_recurse_func);
1953 for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++) {
1954 const stage_map_t *stage = &stages[table_index][stage_index];
1955 for (; i < stage->last_lookup; i++)
1957 unsigned int lookup_index = lookups[table_index][i].index;
1958 if (!buffer->message (font, "start lookup %d", lookup_index)) continue;
1959 c.set_lookup_index (lookup_index);
1960 c.set_lookup_mask (lookups[table_index][i].mask);
1961 c.set_auto_zwj (lookups[table_index][i].auto_zwj);
1962 c.set_auto_zwnj (lookups[table_index][i].auto_zwnj);
1963 if (lookups[table_index][i].random)
1965 c.set_random (true);
1966 buffer->unsafe_to_break_all ();
1968 apply_string<Proxy> (&c,
1969 proxy.table.get_lookup (lookup_index),
1970 proxy.accels[lookup_index]);
1971 (void) buffer->message (font, "end lookup %d", lookup_index);
1974 if (stage->pause_func)
1976 buffer->clear_output ();
1977 stage->pause_func (plan, font, buffer);
1982 void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
1984 GSUBProxy proxy (font->face);
1985 apply (proxy, plan, font, buffer);
1988 void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
1990 GPOSProxy proxy (font->face);
1991 apply (proxy, plan, font, buffer);
1995 hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
1996 const OT::SubstLookup &lookup,
1997 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1999 apply_string<GSUBProxy> (c, lookup, accel);
2004 * hb_ot_layout_get_baseline:
2006 * @baseline_tag: a baseline tag
2007 * @direction: text direction.
2008 * @script_tag: script tag.
2009 * @language_tag: language tag.
2010 * @coord: (out): baseline value if found.
2012 * Fetches a baseline value from the face.
2014 * Return value: if found baseline value in the font.
2019 hb_ot_layout_get_baseline (hb_font_t *font,
2020 hb_ot_layout_baseline_tag_t baseline_tag,
2021 hb_direction_t direction,
2022 hb_tag_t script_tag,
2023 hb_tag_t language_tag,
2024 hb_position_t *coord /* OUT. May be NULL. */)
2026 bool result = font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord);
2028 if (result && coord)
2029 *coord = HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_y (*coord) : font->em_scale_x (*coord);