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-morx-table.hh"
55 #include "hb-aat-layout-opbd-table.hh" // Just so we compile it; unused otherwise.
58 * SECTION:hb-ot-layout
59 * @title: hb-ot-layout
60 * @short_description: OpenType Layout
63 * Functions for querying OpenType Layout features in the font face.
73 * hb_ot_layout_has_kerning:
74 * @face: The #hb_face_t to work on
76 * Tests whether a face includes any kerning data in the 'kern' table.
77 * Does NOT test for kerning lookups in the GPOS table.
79 * Return value: %true if data found, %false otherwise
83 hb_ot_layout_has_kerning (hb_face_t *face)
85 return face->table.kern->has_data ();
89 * hb_ot_layout_has_machine_kerning:
90 * @face: The #hb_face_t to work on
92 * Tests whether a face includes any state-machine kerning in the 'kern' table.
93 * Does NOT examine the GPOS table.
95 * Return value: %true if data found, %false otherwise
99 hb_ot_layout_has_machine_kerning (hb_face_t *face)
101 return face->table.kern->has_state_machine ();
105 * hb_ot_layout_has_cross_kerning:
106 * @face: The #hb_face_t to work on
108 * Tests whether a face has any cross-stream kerning (i.e., kerns
109 * that make adjustments perpendicular to the direction of the text
110 * flow: Y adjustments in horizontal text or X adjustments in
111 * vertical text) in the 'kern' table.
113 * Does NOT examine the GPOS table.
115 * Return value: %true is data found, %false otherwise
119 hb_ot_layout_has_cross_kerning (hb_face_t *face)
121 return face->table.kern->has_cross_stream ();
125 hb_ot_layout_kern (const hb_ot_shape_plan_t *plan,
129 hb_blob_t *blob = font->face->table.kern.get_blob ();
130 const AAT::kern& kern = *blob->as<AAT::kern> ();
132 AAT::hb_aat_apply_context_t c (plan, font, buffer, blob);
134 if (!buffer->message (font, "start table kern")) return;
136 (void) buffer->message (font, "end table kern");
146 OT::GDEF::is_blocklisted (hb_blob_t *blob,
147 hb_face_t *face) const
149 #ifdef HB_NO_OT_LAYOUT_BLOCKLIST
152 /* The ugly business of blocklisting 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) (optional): 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.
336 * Return value: Total number of attachment points for @glyph.
340 hb_ot_layout_get_attach_points (hb_face_t *face,
341 hb_codepoint_t glyph,
342 unsigned int start_offset,
343 unsigned int *point_count /* IN/OUT */,
344 unsigned int *point_array /* OUT */)
346 return face->table.GDEF->table->get_attach_points (glyph,
352 * hb_ot_layout_get_ligature_carets:
353 * @font: The #hb_font_t to work on
354 * @direction: The #hb_direction_t text direction to use
355 * @glyph: The #hb_codepoint_t code point to query
356 * @start_offset: offset of the first caret position to retrieve
357 * @caret_count: (inout) (optional): Input = the maximum number of caret positions to return;
358 * Output = the actual number of caret positions returned (may be zero)
359 * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query
361 * Fetches a list of the caret positions defined for a ligature glyph in the GDEF
362 * table of the font. The list returned will begin at the offset provided.
364 * Return value: Total number of ligature caret positions for @glyph.
368 hb_ot_layout_get_ligature_carets (hb_font_t *font,
369 hb_direction_t direction,
370 hb_codepoint_t glyph,
371 unsigned int start_offset,
372 unsigned int *caret_count /* IN/OUT */,
373 hb_position_t *caret_array /* OUT */)
375 return font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array);
385 OT::GSUB::is_blocklisted (hb_blob_t *blob HB_UNUSED,
386 hb_face_t *face) const
388 #ifdef HB_NO_OT_LAYOUT_BLOCKLIST
395 OT::GPOS::is_blocklisted (hb_blob_t *blob HB_UNUSED,
396 hb_face_t *face HB_UNUSED) const
398 #ifdef HB_NO_OT_LAYOUT_BLOCKLIST
404 static const OT::GSUBGPOS&
405 get_gsubgpos_table (hb_face_t *face,
409 case HB_OT_TAG_GSUB: return *face->table.GSUB->table;
410 case HB_OT_TAG_GPOS: return *face->table.GPOS->table;
411 default: return Null (OT::GSUBGPOS);
417 * hb_ot_layout_table_get_script_tags:
418 * @face: #hb_face_t to work upon
419 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
420 * @start_offset: offset of the first script tag to retrieve
421 * @script_count: (inout) (optional): Input = the maximum number of script tags to return;
422 * Output = the actual number of script tags returned (may be zero)
423 * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query
425 * Fetches a list of all scripts enumerated in the specified face's GSUB table
426 * or GPOS table. The list returned will begin at the offset provided.
428 * Return value: Total number of script tags.
432 hb_ot_layout_table_get_script_tags (hb_face_t *face,
434 unsigned int start_offset,
435 unsigned int *script_count /* IN/OUT */,
436 hb_tag_t *script_tags /* OUT */)
438 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
440 return g.get_script_tags (start_offset, script_count, script_tags);
443 #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n')
446 * hb_ot_layout_table_find_script:
447 * @face: #hb_face_t to work upon
448 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
449 * @script_tag: #hb_tag_t of the script tag requested
450 * @script_index: (out): The index of the requested script tag
452 * Fetches the index if a given script tag in the specified face's GSUB table
455 * Return value: %true if the script is found, %false otherwise
459 hb_ot_layout_table_find_script (hb_face_t *face,
462 unsigned int *script_index /* OUT */)
464 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
465 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
467 if (g.find_script_index (script_tag, script_index))
470 /* try finding 'DFLT' */
471 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
474 /* try with 'dflt'; MS site has had typos and many fonts use it now :(.
475 * including many versions of DejaVu Sans Mono! */
476 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
479 /* try with 'latn'; some old fonts put their features there even though
480 they're really trying to support Thai, for example :( */
481 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index))
484 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
488 #ifndef HB_DISABLE_DEPRECATED
490 * hb_ot_layout_table_choose_script:
491 * @face: #hb_face_t to work upon
492 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
493 * @script_tags: Array of #hb_tag_t script tags
494 * @script_index: (out): The index of the requested script tag
495 * @chosen_script: (out): #hb_tag_t of the script tag requested
497 * Deprecated since 2.0.0
500 hb_ot_layout_table_choose_script (hb_face_t *face,
502 const hb_tag_t *script_tags,
503 unsigned int *script_index /* OUT */,
504 hb_tag_t *chosen_script /* OUT */)
507 for (t = script_tags; *t; t++);
508 return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script);
513 * hb_ot_layout_table_select_script:
514 * @face: #hb_face_t to work upon
515 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
516 * @script_count: Number of script tags in the array
517 * @script_tags: Array of #hb_tag_t script tags
518 * @script_index: (out) (optional): The index of the requested script
519 * @chosen_script: (out) (optional): #hb_tag_t of the requested script
521 * Selects an OpenType script for @table_tag from the @script_tags array.
523 * If the table does not have any of the requested scripts, then `DFLT`,
524 * `dflt`, and `latn` tags are tried in that order. If the table still does not
525 * have any of these scripts, @script_index and @chosen_script are set to
526 * #HB_OT_LAYOUT_NO_SCRIPT_INDEX.
529 * %true if one of the requested scripts is selected, %false if a fallback
530 * script is selected or if no scripts are selected.
535 hb_ot_layout_table_select_script (hb_face_t *face,
537 unsigned int script_count,
538 const hb_tag_t *script_tags,
539 unsigned int *script_index /* OUT */,
540 hb_tag_t *chosen_script /* OUT */)
542 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
543 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
546 for (i = 0; i < script_count; i++)
548 if (g.find_script_index (script_tags[i], script_index))
551 *chosen_script = script_tags[i];
556 /* try finding 'DFLT' */
557 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) {
559 *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT;
563 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
564 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) {
566 *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE;
570 /* try with 'latn'; some old fonts put their features there even though
571 they're really trying to support Thai, for example :( */
572 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) {
574 *chosen_script = HB_OT_TAG_LATIN_SCRIPT;
578 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
580 *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
586 * hb_ot_layout_table_get_feature_tags:
587 * @face: #hb_face_t to work upon
588 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
589 * @start_offset: offset of the first feature tag to retrieve
590 * @feature_count: (inout) (optional): Input = the maximum number of feature tags to return;
591 * Output = the actual number of feature tags returned (may be zero)
592 * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table
594 * Fetches a list of all feature tags in the given face's GSUB or GPOS table.
596 * Return value: Total number of feature tags.
600 hb_ot_layout_table_get_feature_tags (hb_face_t *face,
602 unsigned int start_offset,
603 unsigned int *feature_count /* IN/OUT */,
604 hb_tag_t *feature_tags /* OUT */)
606 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
608 return g.get_feature_tags (start_offset, feature_count, feature_tags);
613 * hb_ot_layout_table_find_feature:
614 * @face: #hb_face_t to work upon
615 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
616 * @feature_tag: The #hb_tag_t of the requested feature tag
617 * @feature_index: (out): The index of the requested feature
619 * Fetches the index for a given feature tag in the specified face's GSUB table
622 * Return value: %true if the feature is found, %false otherwise
625 hb_ot_layout_table_find_feature (hb_face_t *face,
627 hb_tag_t feature_tag,
628 unsigned int *feature_index /* OUT */)
630 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
631 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
633 unsigned int num_features = g.get_feature_count ();
634 for (unsigned int i = 0; i < num_features; i++)
636 if (feature_tag == g.get_feature_tag (i)) {
637 if (feature_index) *feature_index = i;
642 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
648 * hb_ot_layout_script_get_language_tags:
649 * @face: #hb_face_t to work upon
650 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
651 * @script_index: The index of the requested script tag
652 * @start_offset: offset of the first language tag to retrieve
653 * @language_count: (inout) (optional): Input = the maximum number of language tags to return;
654 * Output = the actual number of language tags returned (may be zero)
655 * @language_tags: (out) (array length=language_count): Array of language tags found in the table
657 * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath
658 * the specified script index. The list returned will begin at the offset provided.
660 * Return value: Total number of language tags.
664 hb_ot_layout_script_get_language_tags (hb_face_t *face,
666 unsigned int script_index,
667 unsigned int start_offset,
668 unsigned int *language_count /* IN/OUT */,
669 hb_tag_t *language_tags /* OUT */)
671 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
673 return s.get_lang_sys_tags (start_offset, language_count, language_tags);
677 #ifndef HB_DISABLE_DEPRECATED
679 * hb_ot_layout_script_find_language:
680 * @face: #hb_face_t to work upon
681 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
682 * @script_index: The index of the requested script tag
683 * @language_tag: The #hb_tag_t of the requested language
684 * @language_index: The index of the requested language
686 * Fetches the index of a given language tag in the specified face's GSUB table
687 * or GPOS table, underneath the specified script tag.
689 * Return value: %true if the language tag is found, %false otherwise
695 hb_ot_layout_script_find_language (hb_face_t *face,
697 unsigned int script_index,
698 hb_tag_t language_tag,
699 unsigned int *language_index)
701 return hb_ot_layout_script_select_language (face,
712 * hb_ot_layout_script_select_language:
713 * @face: #hb_face_t to work upon
714 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
715 * @script_index: The index of the requested script tag
716 * @language_count: The number of languages in the specified script
717 * @language_tags: The array of language tags
718 * @language_index: (out): The index of the requested language
720 * Fetches the index of the first language tag fom @language_tags that is present
721 * in the specified face's GSUB or GPOS table, underneath the specified script
724 * If none of the given language tags is found, %false is returned and
725 * @language_index is set to the default language index.
727 * Return value: %true if one of the given language tags is found, %false otherwise
732 hb_ot_layout_script_select_language (hb_face_t *face,
734 unsigned int script_index,
735 unsigned int language_count,
736 const hb_tag_t *language_tags,
737 unsigned int *language_index /* OUT */)
739 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), "");
740 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
743 for (i = 0; i < language_count; i++)
745 if (s.find_lang_sys_index (language_tags[i], language_index))
749 /* try finding 'dflt' */
750 if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
754 *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
760 * hb_ot_layout_language_get_required_feature_index:
761 * @face: #hb_face_t to work upon
762 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
763 * @script_index: The index of the requested script tag
764 * @language_index: The index of the requested language tag
765 * @feature_index: (out): The index of the requested feature
767 * Fetches the index of a requested feature in the given face's GSUB or GPOS table,
768 * underneath the specified script and language.
770 * Return value: %true if the feature is found, %false otherwise
774 hb_ot_layout_language_get_required_feature_index (hb_face_t *face,
776 unsigned int script_index,
777 unsigned int language_index,
778 unsigned int *feature_index /* OUT */)
780 return hb_ot_layout_language_get_required_feature (face,
790 * hb_ot_layout_language_get_required_feature:
791 * @face: #hb_face_t to work upon
792 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
793 * @script_index: The index of the requested script tag
794 * @language_index: The index of the requested language tag
795 * @feature_index: (out): The index of the requested feature
796 * @feature_tag: (out): The #hb_tag_t of the requested feature
798 * Fetches the tag of a requested feature index in the given face's GSUB or GPOS table,
799 * underneath the specified script and language.
801 * Return value: %true if the feature is found, %false otherwise
806 hb_ot_layout_language_get_required_feature (hb_face_t *face,
808 unsigned int script_index,
809 unsigned int language_index,
810 unsigned int *feature_index /* OUT */,
811 hb_tag_t *feature_tag /* OUT */)
813 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
814 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
816 unsigned int index = l.get_required_feature_index ();
817 if (feature_index) *feature_index = index;
818 if (feature_tag) *feature_tag = g.get_feature_tag (index);
820 return l.has_required_feature ();
825 * hb_ot_layout_language_get_feature_indexes:
826 * @face: #hb_face_t to work upon
827 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
828 * @script_index: The index of the requested script tag
829 * @language_index: The index of the requested language tag
830 * @start_offset: offset of the first feature tag to retrieve
831 * @feature_count: (inout) (optional): Input = the maximum number of feature tags to return;
832 * Output: the actual number of feature tags returned (may be zero)
833 * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query
835 * Fetches a list of all features in the specified face's GSUB table
836 * or GPOS table, underneath the specified script and language. The list
837 * returned will begin at the offset provided.
839 * Return value: Total number of features.
842 hb_ot_layout_language_get_feature_indexes (hb_face_t *face,
844 unsigned int script_index,
845 unsigned int language_index,
846 unsigned int start_offset,
847 unsigned int *feature_count /* IN/OUT */,
848 unsigned int *feature_indexes /* OUT */)
850 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
851 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
853 return l.get_feature_indexes (start_offset, feature_count, feature_indexes);
858 * hb_ot_layout_language_get_feature_tags:
859 * @face: #hb_face_t to work upon
860 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
861 * @script_index: The index of the requested script tag
862 * @language_index: The index of the requested language tag
863 * @start_offset: offset of the first feature tag to retrieve
864 * @feature_count: (inout) (optional): Input = the maximum number of feature tags to return;
865 * Output = the actual number of feature tags returned (may be zero)
866 * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query
868 * Fetches a list of all features in the specified face's GSUB table
869 * or GPOS table, underneath the specified script and language. The list
870 * returned will begin at the offset provided.
872 * Return value: Total number of feature tags.
875 hb_ot_layout_language_get_feature_tags (hb_face_t *face,
877 unsigned int script_index,
878 unsigned int language_index,
879 unsigned int start_offset,
880 unsigned int *feature_count /* IN/OUT */,
881 hb_tag_t *feature_tags /* OUT */)
883 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
884 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
886 static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), "");
887 unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
890 unsigned int count = *feature_count;
891 for (unsigned int i = 0; i < count; i++)
892 feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]);
900 * hb_ot_layout_language_find_feature:
901 * @face: #hb_face_t to work upon
902 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
903 * @script_index: The index of the requested script tag
904 * @language_index: The index of the requested language tag
905 * @feature_tag: #hb_tag_t of the feature tag requested
906 * @feature_index: (out): The index of the requested feature
908 * Fetches the index of a given feature tag in the specified face's GSUB table
909 * or GPOS table, underneath the specified script and language.
911 * Return value: %true if the feature is found, %false otherwise
915 hb_ot_layout_language_find_feature (hb_face_t *face,
917 unsigned int script_index,
918 unsigned int language_index,
919 hb_tag_t feature_tag,
920 unsigned int *feature_index /* OUT */)
922 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
923 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
924 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
926 unsigned int num_features = l.get_feature_count ();
927 for (unsigned int i = 0; i < num_features; i++) {
928 unsigned int f_index = l.get_feature_index (i);
930 if (feature_tag == g.get_feature_tag (f_index)) {
931 if (feature_index) *feature_index = f_index;
936 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
942 * hb_ot_layout_feature_get_lookups:
943 * @face: #hb_face_t to work upon
944 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
945 * @feature_index: The index of the requested feature
946 * @start_offset: offset of the first lookup to retrieve
947 * @lookup_count: (inout) (optional): Input = the maximum number of lookups to return;
948 * Output = the actual number of lookups returned (may be zero)
949 * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query
951 * Fetches a list of all lookups enumerated for the specified feature, in
952 * the specified face's GSUB table or GPOS table. The list returned will
953 * begin at the offset provided.
955 * Return value: Total number of lookups.
960 hb_ot_layout_feature_get_lookups (hb_face_t *face,
962 unsigned int feature_index,
963 unsigned int start_offset,
964 unsigned int *lookup_count /* IN/OUT */,
965 unsigned int *lookup_indexes /* OUT */)
967 return hb_ot_layout_feature_with_variations_get_lookups (face,
970 HB_OT_LAYOUT_NO_VARIATIONS_INDEX,
978 * hb_ot_layout_table_get_lookup_count:
979 * @face: #hb_face_t to work upon
980 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
982 * Fetches the total number of lookups enumerated in the specified
983 * face's GSUB table or GPOS table.
985 * Return value: Total number of lookups.
990 hb_ot_layout_table_get_lookup_count (hb_face_t *face,
993 return get_gsubgpos_table (face, table_tag).get_lookup_count ();
997 struct hb_collect_features_context_t
999 hb_collect_features_context_t (hb_face_t *face,
1001 hb_set_t *feature_indices_,
1002 const hb_tag_t *features)
1004 : g (get_gsubgpos_table (face, table_tag)),
1005 feature_indices (feature_indices_),
1006 has_feature_filter (false),
1007 script_count (0),langsys_count (0), feature_index_count (0)
1009 compute_feature_filter (features);
1012 void compute_feature_filter (const hb_tag_t *features)
1014 if (features == nullptr)
1016 has_feature_filter = false;
1020 has_feature_filter = true;
1021 hb_set_t features_set;
1022 for (; *features; features++)
1023 features_set.add (*features);
1025 for (unsigned i = 0; i < g.get_feature_count (); i++)
1027 hb_tag_t tag = g.get_feature_tag (i);
1028 if (features_set.has (tag))
1029 feature_indices_filter.add(i);
1033 bool visited (const OT::Script &s)
1035 /* We might have Null() object here. Don't want to involve
1036 * that in the memoize. So, detect empty objects and return. */
1037 if (unlikely (!s.has_default_lang_sys () &&
1038 !s.get_lang_sys_count ()))
1041 if (script_count++ > HB_MAX_SCRIPTS)
1044 return visited (s, visited_script);
1046 bool visited (const OT::LangSys &l)
1048 /* We might have Null() object here. Don't want to involve
1049 * that in the memoize. So, detect empty objects and return. */
1050 if (unlikely (!l.has_required_feature () &&
1051 !l.get_feature_count ()))
1054 if (langsys_count++ > HB_MAX_LANGSYS)
1057 return visited (l, visited_langsys);
1060 bool visited_feature_indices (unsigned count)
1062 feature_index_count += count;
1063 return feature_index_count > HB_MAX_FEATURE_INDICES;
1067 template <typename T>
1068 bool visited (const T &p, hb_set_t &visited_set)
1070 hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g);
1071 if (visited_set.has (delta))
1074 visited_set.add (delta);
1079 const OT::GSUBGPOS &g;
1080 hb_set_t *feature_indices;
1081 hb_set_t feature_indices_filter;
1082 bool has_feature_filter;
1085 hb_set_t visited_script;
1086 hb_set_t visited_langsys;
1087 unsigned int script_count;
1088 unsigned int langsys_count;
1089 unsigned int feature_index_count;
1093 langsys_collect_features (hb_collect_features_context_t *c,
1094 const OT::LangSys &l)
1096 if (c->visited (l)) return;
1098 if (!c->has_feature_filter)
1101 if (l.has_required_feature () && !c->visited_feature_indices (1))
1102 c->feature_indices->add (l.get_required_feature_index ());
1104 // TODO(garretrieger): filter out indices >= feature count?
1105 if (!c->visited_feature_indices (l.featureIndex.len))
1106 l.add_feature_indexes_to (c->feature_indices);
1110 if (c->feature_indices_filter.is_empty()) return;
1111 unsigned int num_features = l.get_feature_count ();
1112 for (unsigned int i = 0; i < num_features; i++)
1114 unsigned int feature_index = l.get_feature_index (i);
1115 if (!c->feature_indices_filter.has (feature_index)) continue;
1117 c->feature_indices->add (feature_index);
1118 c->feature_indices_filter.del (feature_index);
1124 script_collect_features (hb_collect_features_context_t *c,
1125 const OT::Script &s,
1126 const hb_tag_t *languages)
1128 if (c->visited (s)) return;
1132 /* All languages. */
1133 if (s.has_default_lang_sys ())
1134 langsys_collect_features (c,
1135 s.get_default_lang_sys ());
1138 unsigned int count = s.get_lang_sys_count ();
1139 for (unsigned int language_index = 0; language_index < count; language_index++)
1140 langsys_collect_features (c,
1141 s.get_lang_sys (language_index));
1145 for (; *languages; languages++)
1147 unsigned int language_index;
1148 if (s.find_lang_sys_index (*languages, &language_index))
1149 langsys_collect_features (c,
1150 s.get_lang_sys (language_index));
1158 * hb_ot_layout_collect_features:
1159 * @face: #hb_face_t to work upon
1160 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1161 * @scripts: The array of scripts to collect features for
1162 * @languages: The array of languages to collect features for
1163 * @features: The array of features to collect
1164 * @feature_indexes: (out): The array of feature indexes found for the query
1166 * Fetches a list of all feature indexes in the specified face's GSUB table
1167 * or GPOS table, underneath the specified scripts, languages, and features.
1168 * If no list of scripts is provided, all scripts will be queried. If no list
1169 * of languages is provided, all languages will be queried. If no list of
1170 * features is provided, all features will be queried.
1175 hb_ot_layout_collect_features (hb_face_t *face,
1177 const hb_tag_t *scripts,
1178 const hb_tag_t *languages,
1179 const hb_tag_t *features,
1180 hb_set_t *feature_indexes /* OUT */)
1182 hb_collect_features_context_t c (face, table_tag, feature_indexes, features);
1186 unsigned int count = c.g.get_script_count ();
1187 for (unsigned int script_index = 0; script_index < count; script_index++)
1188 script_collect_features (&c,
1189 c.g.get_script (script_index),
1194 for (; *scripts; scripts++)
1196 unsigned int script_index;
1197 if (c.g.find_script_index (*scripts, &script_index))
1198 script_collect_features (&c,
1199 c.g.get_script (script_index),
1207 * hb_ot_layout_collect_lookups:
1208 * @face: #hb_face_t to work upon
1209 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1210 * @scripts: The array of scripts to collect lookups for
1211 * @languages: The array of languages to collect lookups for
1212 * @features: The array of features to collect lookups for
1213 * @lookup_indexes: (out): The array of lookup indexes found for the query
1215 * Fetches a list of all feature-lookup indexes in the specified face's GSUB
1216 * table or GPOS table, underneath the specified scripts, languages, and
1217 * features. If no list of scripts is provided, all scripts will be queried.
1218 * If no list of languages is provided, all languages will be queried. If no
1219 * list of features is provided, all features will be queried.
1224 hb_ot_layout_collect_lookups (hb_face_t *face,
1226 const hb_tag_t *scripts,
1227 const hb_tag_t *languages,
1228 const hb_tag_t *features,
1229 hb_set_t *lookup_indexes /* OUT */)
1231 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1233 hb_set_t feature_indexes;
1234 hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes);
1236 for (hb_codepoint_t feature_index = HB_SET_VALUE_INVALID;
1237 hb_set_next (&feature_indexes, &feature_index);)
1238 g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes);
1240 g.feature_variation_collect_lookups (&feature_indexes, lookup_indexes);
1244 #ifndef HB_NO_LAYOUT_COLLECT_GLYPHS
1246 * hb_ot_layout_lookup_collect_glyphs:
1247 * @face: #hb_face_t to work upon
1248 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1249 * @lookup_index: The index of the feature lookup to query
1250 * @glyphs_before: (out): Array of glyphs preceding the substitution range
1251 * @glyphs_input: (out): Array of input glyphs that would be substituted by the lookup
1252 * @glyphs_after: (out): Array of glyphs following the substitution range
1253 * @glyphs_output: (out): Array of glyphs that would be the substituted output of the lookup
1255 * Fetches a list of all glyphs affected by the specified lookup in the
1256 * specified face's GSUB table or GPOS table.
1261 hb_ot_layout_lookup_collect_glyphs (hb_face_t *face,
1263 unsigned int lookup_index,
1264 hb_set_t *glyphs_before, /* OUT. May be NULL */
1265 hb_set_t *glyphs_input, /* OUT. May be NULL */
1266 hb_set_t *glyphs_after, /* OUT. May be NULL */
1267 hb_set_t *glyphs_output /* OUT. May be NULL */)
1269 OT::hb_collect_glyphs_context_t c (face,
1277 case HB_OT_TAG_GSUB:
1279 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1280 l.collect_glyphs (&c);
1283 case HB_OT_TAG_GPOS:
1285 const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index);
1286 l.collect_glyphs (&c);
1294 /* Variations support */
1298 * hb_ot_layout_table_find_feature_variations:
1299 * @face: #hb_face_t to work upon
1300 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1301 * @coords: The variation coordinates to query
1302 * @num_coords: The number of variation coordinates
1303 * @variations_index: (out): The array of feature variations found for the query
1305 * Fetches a list of feature variations in the specified face's GSUB table
1306 * or GPOS table, at the specified variation coordinates.
1308 * Return value: %true if feature variations were found, %false otherwise.
1312 hb_ot_layout_table_find_feature_variations (hb_face_t *face,
1315 unsigned int num_coords,
1316 unsigned int *variations_index /* out */)
1318 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1320 return g.find_variations_index (coords, num_coords, variations_index);
1325 * hb_ot_layout_feature_with_variations_get_lookups:
1326 * @face: #hb_face_t to work upon
1327 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1328 * @feature_index: The index of the feature to query
1329 * @variations_index: The index of the feature variation to query
1330 * @start_offset: offset of the first lookup to retrieve
1331 * @lookup_count: (inout) (optional): Input = the maximum number of lookups to return;
1332 * Output = the actual number of lookups returned (may be zero)
1333 * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query
1335 * Fetches a list of all lookups enumerated for the specified feature, in
1336 * the specified face's GSUB table or GPOS table, enabled at the specified
1337 * variations index. The list returned will begin at the offset provided.
1339 * Return value: Total number of lookups.
1343 hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face,
1345 unsigned int feature_index,
1346 unsigned int variations_index,
1347 unsigned int start_offset,
1348 unsigned int *lookup_count /* IN/OUT */,
1349 unsigned int *lookup_indexes /* OUT */)
1351 static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "");
1352 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1354 const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
1356 return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
1366 * hb_ot_layout_has_substitution:
1367 * @face: #hb_face_t to work upon
1369 * Tests whether the specified face includes any GSUB substitutions.
1371 * Return value: %true if data found, %false otherwise
1375 hb_ot_layout_has_substitution (hb_face_t *face)
1377 return face->table.GSUB->table->has_data ();
1382 * hb_ot_layout_lookup_would_substitute:
1383 * @face: #hb_face_t to work upon
1384 * @lookup_index: The index of the lookup to query
1385 * @glyphs: The sequence of glyphs to query for substitution
1386 * @glyphs_length: The length of the glyph sequence
1387 * @zero_context: #hb_bool_t indicating whether pre-/post-context are disallowed
1390 * Tests whether a specified lookup in the specified face would
1391 * trigger a substitution on the given glyph sequence.
1393 * Return value: %true if a substitution would be triggered, %false otherwise
1398 hb_ot_layout_lookup_would_substitute (hb_face_t *face,
1399 unsigned int lookup_index,
1400 const hb_codepoint_t *glyphs,
1401 unsigned int glyphs_length,
1402 hb_bool_t zero_context)
1404 if (unlikely (lookup_index >= face->table.GSUB->lookup_count)) return false;
1405 OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context);
1407 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1408 return l.would_apply (&c, &face->table.GSUB->accels[lookup_index]);
1413 * hb_ot_layout_substitute_start:
1414 * @font: #hb_font_t to use
1415 * @buffer: #hb_buffer_t buffer to work upon
1417 * Called before substitution lookups are performed, to ensure that glyph
1418 * class and other properties are set on the glyphs in the buffer.
1422 hb_ot_layout_substitute_start (hb_font_t *font,
1423 hb_buffer_t *buffer)
1425 _hb_ot_layout_set_glyph_props (font, buffer);
1429 hb_ot_layout_delete_glyphs_inplace (hb_buffer_t *buffer,
1430 bool (*filter) (const hb_glyph_info_t *info))
1432 /* Merge clusters and delete filtered glyphs.
1433 * NOTE! We can't use out-buffer as we have positioning data. */
1435 unsigned int count = buffer->len;
1436 hb_glyph_info_t *info = buffer->info;
1437 hb_glyph_position_t *pos = buffer->pos;
1438 for (unsigned int i = 0; i < count; i++)
1440 if (filter (&info[i]))
1443 * Same logic as buffer->delete_glyph(), but for in-place removal. */
1445 unsigned int cluster = info[i].cluster;
1446 if (i + 1 < count && cluster == info[i + 1].cluster)
1447 continue; /* Cluster survives; do nothing. */
1451 /* Merge cluster backward. */
1452 if (cluster < info[j - 1].cluster)
1454 unsigned int mask = info[i].mask;
1455 unsigned int old_cluster = info[j - 1].cluster;
1456 for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--)
1457 buffer->set_cluster (info[k - 1], cluster, mask);
1463 buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */
1479 * hb_ot_layout_lookup_substitute_closure:
1480 * @face: #hb_face_t to work upon
1481 * @lookup_index: index of the feature lookup to query
1482 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup
1484 * Compute the transitive closure of glyphs needed for a
1490 hb_ot_layout_lookup_substitute_closure (hb_face_t *face,
1491 unsigned int lookup_index,
1492 hb_set_t *glyphs /* OUT */)
1494 hb_map_t done_lookups_glyph_count;
1495 hb_hashmap_t<unsigned, hb_set_t *> done_lookups_glyph_set;
1496 OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
1498 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1500 l.closure (&c, lookup_index);
1502 for (auto _ : done_lookups_glyph_set.iter ())
1503 hb_set_destroy (_.second);
1507 * hb_ot_layout_lookups_substitute_closure:
1508 * @face: #hb_face_t to work upon
1509 * @lookups: The set of lookups to query
1510 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups
1512 * Compute the transitive closure of glyphs needed for all of the
1518 hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
1519 const hb_set_t *lookups,
1520 hb_set_t *glyphs /* OUT */)
1522 hb_map_t done_lookups_glyph_count;
1523 hb_hashmap_t<unsigned, hb_set_t *> done_lookups_glyph_set;
1524 OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
1525 const OT::GSUB& gsub = *face->table.GSUB->table;
1527 unsigned int iteration_count = 0;
1528 unsigned int glyphs_length;
1531 c.reset_lookup_visit_count ();
1532 glyphs_length = glyphs->get_population ();
1535 for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);)
1536 gsub.get_lookup (lookup_index).closure (&c, lookup_index);
1540 for (unsigned int i = 0; i < gsub.get_lookup_count (); i++)
1541 gsub.get_lookup (i).closure (&c, i);
1543 } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES &&
1544 glyphs_length != glyphs->get_population ());
1546 for (auto _ : done_lookups_glyph_set.iter ())
1547 hb_set_destroy (_.second);
1556 * hb_ot_layout_has_positioning:
1557 * @face: #hb_face_t to work upon
1559 * Tests whether the specified face includes any GPOS positioning.
1561 * Return value: %true if the face has GPOS data, %false otherwise
1565 hb_ot_layout_has_positioning (hb_face_t *face)
1567 return face->table.GPOS->table->has_data ();
1571 * hb_ot_layout_position_start:
1572 * @font: #hb_font_t to use
1573 * @buffer: #hb_buffer_t buffer to work upon
1575 * Called before positioning lookups are performed, to ensure that glyph
1576 * attachment types and glyph-attachment chains are set for the glyphs in the buffer.
1580 hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer)
1582 OT::GPOS::position_start (font, buffer);
1587 * hb_ot_layout_position_finish_advances:
1588 * @font: #hb_font_t to use
1589 * @buffer: #hb_buffer_t buffer to work upon
1591 * Called after positioning lookups are performed, to finish glyph advances.
1595 hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer)
1597 OT::GPOS::position_finish_advances (font, buffer);
1601 * hb_ot_layout_position_finish_offsets:
1602 * @font: #hb_font_t to use
1603 * @buffer: #hb_buffer_t buffer to work upon
1605 * Called after positioning lookups are performed, to finish glyph offsets.
1609 hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
1611 OT::GPOS::position_finish_offsets (font, buffer);
1615 #ifndef HB_NO_LAYOUT_FEATURE_PARAMS
1617 * hb_ot_layout_get_size_params:
1618 * @face: #hb_face_t to work upon
1619 * @design_size: (out): The design size of the face
1620 * @subfamily_id: (out): The identifier of the face within the font subfamily
1621 * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily
1622 * @range_start: (out): The minimum size of the recommended size range for the face
1623 * @range_end: (out): The maximum size of the recommended size range for the face
1625 * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that
1626 * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id)
1627 * as used here are defined as pertaining only to fonts within a font family that differ
1628 * specifically in their respective size ranges; other ways to differentiate fonts within
1629 * a subfamily are not covered by the `size` feature.
1631 * For more information on this distinction, see the [`size` feature documentation](
1632 * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-size).
1634 * Return value: %true if data found, %false otherwise
1639 hb_ot_layout_get_size_params (hb_face_t *face,
1640 unsigned int *design_size, /* OUT. May be NULL */
1641 unsigned int *subfamily_id, /* OUT. May be NULL */
1642 hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */
1643 unsigned int *range_start, /* OUT. May be NULL */
1644 unsigned int *range_end /* OUT. May be NULL */)
1646 const OT::GPOS &gpos = *face->table.GPOS->table;
1647 const hb_tag_t tag = HB_TAG ('s','i','z','e');
1649 unsigned int num_features = gpos.get_feature_count ();
1650 for (unsigned int i = 0; i < num_features; i++)
1652 if (tag == gpos.get_feature_tag (i))
1654 const OT::Feature &f = gpos.get_feature (i);
1655 const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag);
1657 if (params.designSize)
1659 if (design_size) *design_size = params.designSize;
1660 if (subfamily_id) *subfamily_id = params.subfamilyID;
1661 if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID;
1662 if (range_start) *range_start = params.rangeStart;
1663 if (range_end) *range_end = params.rangeEnd;
1670 if (design_size) *design_size = 0;
1671 if (subfamily_id) *subfamily_id = 0;
1672 if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID;
1673 if (range_start) *range_start = 0;
1674 if (range_end) *range_end = 0;
1679 * hb_ot_layout_feature_get_name_ids:
1680 * @face: #hb_face_t to work upon
1681 * @table_tag: table tag to query, "GSUB" or "GPOS".
1682 * @feature_index: index of feature to query.
1683 * @label_id: (out) (optional): The ‘name’ table name ID that specifies a string
1684 * for a user-interface label for this feature. (May be NULL.)
1685 * @tooltip_id: (out) (optional): The ‘name’ table name ID that specifies a string
1686 * that an application can use for tooltip text for this
1687 * feature. (May be NULL.)
1688 * @sample_id: (out) (optional): The ‘name’ table name ID that specifies sample text
1689 * that illustrates the effect of this feature. (May be NULL.)
1690 * @num_named_parameters: (out) (optional): Number of named parameters. (May be zero.)
1691 * @first_param_id: (out) (optional): The first ‘name’ table name ID used to specify
1692 * strings for user-interface labels for the feature
1693 * parameters. (Must be zero if numParameters is zero.)
1695 * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or
1696 * "Character Variant" ('cvXX') features.
1698 * Return value: %true if data found, %false otherwise
1703 hb_ot_layout_feature_get_name_ids (hb_face_t *face,
1705 unsigned int feature_index,
1706 hb_ot_name_id_t *label_id, /* OUT. May be NULL */
1707 hb_ot_name_id_t *tooltip_id, /* OUT. May be NULL */
1708 hb_ot_name_id_t *sample_id, /* OUT. May be NULL */
1709 unsigned int *num_named_parameters, /* OUT. May be NULL */
1710 hb_ot_name_id_t *first_param_id /* OUT. May be NULL */)
1712 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1714 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1715 const OT::Feature &f = g.get_feature (feature_index);
1717 const OT::FeatureParams &feature_params = f.get_feature_params ();
1718 if (&feature_params != &Null (OT::FeatureParams))
1720 const OT::FeatureParamsStylisticSet& ss_params =
1721 feature_params.get_stylistic_set_params (feature_tag);
1722 if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */
1724 if (label_id) *label_id = ss_params.uiNameID;
1725 // ssXX features don't have the rest
1726 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1727 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1728 if (num_named_parameters) *num_named_parameters = 0;
1729 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1732 const OT::FeatureParamsCharacterVariants& cv_params =
1733 feature_params.get_character_variants_params (feature_tag);
1734 if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */
1736 if (label_id) *label_id = cv_params.featUILableNameID;
1737 if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID;
1738 if (sample_id) *sample_id = cv_params.sampleTextNameID;
1739 if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters;
1740 if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID;
1745 if (label_id) *label_id = HB_OT_NAME_ID_INVALID;
1746 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1747 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1748 if (num_named_parameters) *num_named_parameters = 0;
1749 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1753 * hb_ot_layout_feature_get_characters:
1754 * @face: #hb_face_t to work upon
1755 * @table_tag: table tag to query, "GSUB" or "GPOS".
1756 * @feature_index: index of feature to query.
1757 * @start_offset: offset of the first character to retrieve
1758 * @char_count: (inout) (optional): Input = the maximum number of characters to return;
1759 * Output = the actual number of characters returned (may be zero)
1760 * @characters: (out caller-allocates) (array length=char_count): A buffer pointer.
1761 * The Unicode codepoints of the characters for which this feature provides
1764 * Fetches a list of the characters defined as having a variant under the specified
1765 * "Character Variant" ("cvXX") feature tag.
1767 * Return value: Number of total sample characters in the cvXX feature.
1772 hb_ot_layout_feature_get_characters (hb_face_t *face,
1774 unsigned int feature_index,
1775 unsigned int start_offset,
1776 unsigned int *char_count, /* IN/OUT. May be NULL */
1777 hb_codepoint_t *characters /* OUT. May be NULL */)
1779 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1780 return g.get_feature (feature_index)
1781 .get_feature_params ()
1782 .get_character_variants_params(g.get_feature_tag (feature_index))
1783 .get_characters (start_offset, char_count, characters);
1789 * Parts of different types are implemented here such that they have direct
1790 * access to GSUB/GPOS lookups.
1796 static constexpr unsigned table_index = 0u;
1797 static constexpr bool inplace = false;
1798 typedef OT::SubstLookup Lookup;
1800 GSUBProxy (hb_face_t *face) :
1801 table (*face->table.GSUB->table),
1802 accels (face->table.GSUB->accels) {}
1804 const OT::GSUB &table;
1805 const OT::hb_ot_layout_lookup_accelerator_t *accels;
1810 static constexpr unsigned table_index = 1u;
1811 static constexpr bool inplace = true;
1812 typedef OT::PosLookup Lookup;
1814 GPOSProxy (hb_face_t *face) :
1815 table (*face->table.GPOS->table),
1816 accels (face->table.GPOS->accels) {}
1818 const OT::GPOS &table;
1819 const OT::hb_ot_layout_lookup_accelerator_t *accels;
1824 apply_forward (OT::hb_ot_apply_context_t *c,
1825 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1828 hb_buffer_t *buffer = c->buffer;
1829 while (buffer->idx < buffer->len && buffer->successful)
1831 bool applied = false;
1832 if (accel.may_have (buffer->cur().codepoint) &&
1833 (buffer->cur().mask & c->lookup_mask) &&
1834 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1836 applied = accel.apply (c);
1842 (void) buffer->next_glyph ();
1848 apply_backward (OT::hb_ot_apply_context_t *c,
1849 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1852 hb_buffer_t *buffer = c->buffer;
1855 if (accel.may_have (buffer->cur().codepoint) &&
1856 (buffer->cur().mask & c->lookup_mask) &&
1857 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1858 ret |= accel.apply (c);
1860 /* The reverse lookup doesn't "advance" cursor (for good reason). */
1864 while ((int) buffer->idx >= 0);
1868 template <typename Proxy>
1870 apply_string (OT::hb_ot_apply_context_t *c,
1871 const typename Proxy::Lookup &lookup,
1872 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1874 hb_buffer_t *buffer = c->buffer;
1876 if (unlikely (!buffer->len || !c->lookup_mask))
1879 c->set_lookup_props (lookup.get_props ());
1881 if (likely (!lookup.is_reverse ()))
1883 /* in/out forward substitution/positioning */
1884 if (!Proxy::inplace)
1885 buffer->clear_output ();
1888 apply_forward (c, accel);
1890 if (!Proxy::inplace)
1895 /* in-place backward substitution/positioning */
1896 assert (!buffer->have_output);
1897 buffer->idx = buffer->len - 1;
1898 apply_backward (c, accel);
1902 template <typename Proxy>
1903 inline void hb_ot_map_t::apply (const Proxy &proxy,
1904 const hb_ot_shape_plan_t *plan,
1906 hb_buffer_t *buffer) const
1908 const unsigned int table_index = proxy.table_index;
1910 OT::hb_ot_apply_context_t c (table_index, font, buffer);
1911 c.set_recurse_func (Proxy::Lookup::apply_recurse_func);
1913 for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++)
1915 const stage_map_t *stage = &stages[table_index][stage_index];
1916 for (; i < stage->last_lookup; i++)
1918 unsigned int lookup_index = lookups[table_index][i].index;
1919 if (!buffer->message (font, "start lookup %d", lookup_index)) continue;
1920 c.set_lookup_index (lookup_index);
1921 c.set_lookup_mask (lookups[table_index][i].mask);
1922 c.set_auto_zwj (lookups[table_index][i].auto_zwj);
1923 c.set_auto_zwnj (lookups[table_index][i].auto_zwnj);
1924 c.set_random (lookups[table_index][i].random);
1926 apply_string<Proxy> (&c,
1927 proxy.table.get_lookup (lookup_index),
1928 proxy.accels[lookup_index]);
1929 (void) buffer->message (font, "end lookup %d", lookup_index);
1932 if (stage->pause_func)
1933 stage->pause_func (plan, font, buffer);
1937 void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
1939 GSUBProxy proxy (font->face);
1940 if (!buffer->message (font, "start table GSUB")) return;
1941 apply (proxy, plan, font, buffer);
1942 (void) buffer->message (font, "end table GSUB");
1945 void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
1947 GPOSProxy proxy (font->face);
1948 if (!buffer->message (font, "start table GPOS")) return;
1949 apply (proxy, plan, font, buffer);
1950 (void) buffer->message (font, "end table GPOS");
1954 hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
1955 const OT::SubstLookup &lookup,
1956 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1958 apply_string<GSUBProxy> (c, lookup, accel);
1963 * hb_ot_layout_get_baseline:
1965 * @baseline_tag: a baseline tag
1966 * @direction: text direction.
1967 * @script_tag: script tag.
1968 * @language_tag: language tag, currently unused.
1969 * @coord: (out): baseline value if found.
1971 * Fetches a baseline value from the face.
1973 * Return value: %true if found baseline value in the font.
1978 hb_ot_layout_get_baseline (hb_font_t *font,
1979 hb_ot_layout_baseline_tag_t baseline_tag,
1980 hb_direction_t direction,
1981 hb_tag_t script_tag,
1982 hb_tag_t language_tag,
1983 hb_position_t *coord /* OUT. May be NULL. */)
1985 bool result = font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord);
1987 if (result && coord)
1988 *coord = HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_y (*coord) : font->em_scale_x (*coord);
1995 struct hb_get_glyph_alternates_dispatch_t :
1996 hb_dispatch_context_t<hb_get_glyph_alternates_dispatch_t, unsigned>
1998 static return_t default_return_value () { return 0; }
1999 bool stop_sublookup_iteration (return_t r) const { return r; }
2003 hb_get_glyph_alternates_dispatch_t (hb_face_t *face) :
2007 template <typename T, typename ...Ts> auto
2008 _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN
2009 ( obj.get_glyph_alternates (std::forward<Ts> (ds)...) )
2010 template <typename T, typename ...Ts> auto
2011 _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN
2012 ( default_return_value () )
2014 template <typename T, typename ...Ts> auto
2015 dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
2016 ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) )
2020 * hb_ot_layout_lookup_get_glyph_alternates:
2022 * @lookup_index: index of the feature lookup to query.
2023 * @glyph: a glyph id.
2024 * @start_offset: starting offset.
2025 * @alternate_count: (inout) (optional): Input = the maximum number of alternate glyphs to return;
2026 * Output = the actual number of alternate glyphs returned (may be zero).
2027 * @alternate_glyphs: (out caller-allocates) (array length=alternate_count): A glyphs buffer.
2028 * Alternate glyphs associated with the glyph id.
2030 * Fetches alternates of a glyph from a given GSUB lookup index.
2032 * Return value: Total number of alternates found in the specific lookup index for the given glyph id.
2037 hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face,
2038 unsigned lookup_index,
2039 hb_codepoint_t glyph,
2040 unsigned start_offset,
2041 unsigned *alternate_count /* IN/OUT. May be NULL. */,
2042 hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */)
2044 hb_get_glyph_alternates_dispatch_t c (face);
2045 const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index);
2046 auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs);
2047 if (!ret && alternate_count) *alternate_count = 0;