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"
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.
57 using OT::Layout::GSUB;
58 using OT::Layout::GPOS;
61 * SECTION:hb-ot-layout
62 * @title: hb-ot-layout
63 * @short_description: OpenType Layout
66 * Functions for querying OpenType Layout features in the font face.
67 * See the [OpenType specification](http://www.microsoft.com/typography/otspec/)
78 * hb_ot_layout_has_kerning:
79 * @face: The #hb_face_t to work on
81 * Tests whether a face includes any kerning data in the 'kern' table.
82 * Does NOT test for kerning lookups in the GPOS table.
84 * Return value: `true` if data found, `false` otherwise
88 hb_ot_layout_has_kerning (hb_face_t *face)
90 return face->table.kern->has_data ();
94 * hb_ot_layout_has_machine_kerning:
95 * @face: The #hb_face_t to work on
97 * Tests whether a face includes any state-machine kerning in the 'kern' table.
98 * Does NOT examine the GPOS table.
100 * Return value: `true` if data found, `false` otherwise
104 hb_ot_layout_has_machine_kerning (hb_face_t *face)
106 return face->table.kern->has_state_machine ();
110 * hb_ot_layout_has_cross_kerning:
111 * @face: The #hb_face_t to work on
113 * Tests whether a face has any cross-stream kerning (i.e., kerns
114 * that make adjustments perpendicular to the direction of the text
115 * flow: Y adjustments in horizontal text or X adjustments in
116 * vertical text) in the 'kern' table.
118 * Does NOT examine the GPOS table.
120 * Return value: `true` is data found, `false` otherwise
124 hb_ot_layout_has_cross_kerning (hb_face_t *face)
126 return face->table.kern->has_cross_stream ();
130 hb_ot_layout_kern (const hb_ot_shape_plan_t *plan,
134 hb_blob_t *blob = font->face->table.kern.get_blob ();
135 const AAT::kern& kern = *blob->as<AAT::kern> ();
137 AAT::hb_aat_apply_context_t c (plan, font, buffer, blob);
139 if (!buffer->message (font, "start table kern")) return;
141 (void) buffer->message (font, "end table kern");
151 OT::GDEF::is_blocklisted (hb_blob_t *blob,
152 hb_face_t *face) const
154 #ifdef HB_NO_OT_LAYOUT_BLOCKLIST
157 /* The ugly business of blocklisting individual fonts' tables happen here!
158 * See this thread for why we finally had to bend in and do this:
159 * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html
161 * In certain versions of Times New Roman Italic and Bold Italic,
162 * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark)
163 * in GDEF. Many versions of Tahoma have bad GDEF tables that
164 * incorrectly classify some spacing marks such as certain IPA
165 * symbols as glyph class 3. So do older versions of Microsoft
166 * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04.
168 * Nuke the GDEF tables of to avoid unwanted width-zeroing.
170 * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925
171 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693
172 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875
174 switch HB_CODEPOINT_ENCODE3(blob->length,
175 face->table.GSUB->table.get_length (),
176 face->table.GPOS->table.get_length ())
178 /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */
179 case HB_CODEPOINT_ENCODE3 (442, 2874, 42038):
180 /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */
181 case HB_CODEPOINT_ENCODE3 (430, 2874, 40662):
182 /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */
183 case HB_CODEPOINT_ENCODE3 (442, 2874, 39116):
184 /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */
185 case HB_CODEPOINT_ENCODE3 (430, 2874, 39374):
186 /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */
187 case HB_CODEPOINT_ENCODE3 (490, 3046, 41638):
188 /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */
189 case HB_CODEPOINT_ENCODE3 (478, 3046, 41902):
190 /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */
191 case HB_CODEPOINT_ENCODE3 (898, 12554, 46470):
192 /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */
193 case HB_CODEPOINT_ENCODE3 (910, 12566, 47732):
194 /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */
195 case HB_CODEPOINT_ENCODE3 (928, 23298, 59332):
196 /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */
197 case HB_CODEPOINT_ENCODE3 (940, 23310, 60732):
198 /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
199 case HB_CODEPOINT_ENCODE3 (964, 23836, 60072):
200 /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
201 case HB_CODEPOINT_ENCODE3 (976, 23832, 61456):
202 /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */
203 case HB_CODEPOINT_ENCODE3 (994, 24474, 60336):
204 /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */
205 case HB_CODEPOINT_ENCODE3 (1006, 24470, 61740):
206 /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
207 case HB_CODEPOINT_ENCODE3 (1006, 24576, 61346):
208 /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
209 case HB_CODEPOINT_ENCODE3 (1018, 24572, 62828):
210 /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5 tahoma.ttf from Windows 10 AU */
211 case HB_CODEPOINT_ENCODE3 (1006, 24576, 61352):
212 /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2 tahomabd.ttf from Windows 10 AU */
213 case HB_CODEPOINT_ENCODE3 (1018, 24572, 62834):
214 /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */
215 case HB_CODEPOINT_ENCODE3 (832, 7324, 47162):
216 /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */
217 case HB_CODEPOINT_ENCODE3 (844, 7302, 45474):
218 /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc himalaya.ttf from Windows 7 */
219 case HB_CODEPOINT_ENCODE3 (180, 13054, 7254):
220 /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */
221 case HB_CODEPOINT_ENCODE3 (192, 12638, 7254):
222 /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */
223 case HB_CODEPOINT_ENCODE3 (192, 12690, 7254):
224 /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */
225 /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */
226 case HB_CODEPOINT_ENCODE3 (188, 248, 3852):
227 /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */
228 /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */
229 case HB_CODEPOINT_ENCODE3 (188, 264, 3426):
230 /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */
231 case HB_CODEPOINT_ENCODE3 (1058, 47032, 11818):
232 /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/
233 case HB_CODEPOINT_ENCODE3 (1046, 47030, 12600):
234 /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */
235 case HB_CODEPOINT_ENCODE3 (1058, 71796, 16770):
236 /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */
237 case HB_CODEPOINT_ENCODE3 (1046, 71790, 17862):
238 /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */
239 case HB_CODEPOINT_ENCODE3 (1046, 71788, 17112):
240 /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */
241 case HB_CODEPOINT_ENCODE3 (1058, 71794, 17514):
242 /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */
243 case HB_CODEPOINT_ENCODE3 (1330, 109904, 57938):
244 /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */
245 case HB_CODEPOINT_ENCODE3 (1330, 109904, 58972):
246 /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85 Padauk.ttf
247 * "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */
248 case HB_CODEPOINT_ENCODE3 (1004, 59092, 14836):
255 _hb_ot_layout_set_glyph_props (hb_font_t *font,
258 _hb_buffer_assert_gsubgpos_vars (buffer);
260 const auto &gdef = *font->face->table.GDEF;
261 unsigned int count = buffer->len;
262 hb_glyph_info_t *info = buffer->info;
263 for (unsigned int i = 0; i < count; i++)
265 _hb_glyph_info_set_glyph_props (&info[i], gdef.get_glyph_props (info[i].codepoint));
266 _hb_glyph_info_clear_lig_props (&info[i]);
273 * hb_ot_layout_has_glyph_classes:
274 * @face: #hb_face_t to work upon
276 * Tests whether a face has any glyph classes defined in its GDEF table.
278 * Return value: `true` if data found, `false` otherwise
282 hb_ot_layout_has_glyph_classes (hb_face_t *face)
284 return face->table.GDEF->table->has_glyph_classes ();
288 * hb_ot_layout_get_glyph_class:
289 * @face: The #hb_face_t to work on
290 * @glyph: The #hb_codepoint_t code point to query
292 * Fetches the GDEF class of the requested glyph in the specified face.
294 * Return value: The #hb_ot_layout_glyph_class_t glyph class of the given code
295 * point in the GDEF table of the face.
299 hb_ot_layout_glyph_class_t
300 hb_ot_layout_get_glyph_class (hb_face_t *face,
301 hb_codepoint_t glyph)
303 return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph);
307 * hb_ot_layout_get_glyphs_in_class:
308 * @face: The #hb_face_t to work on
309 * @klass: The #hb_ot_layout_glyph_class_t GDEF class to retrieve
310 * @glyphs: (out): The #hb_set_t set of all glyphs belonging to the requested
313 * Retrieves the set of all glyphs from the face that belong to the requested
314 * glyph class in the face's GDEF table.
319 hb_ot_layout_get_glyphs_in_class (hb_face_t *face,
320 hb_ot_layout_glyph_class_t klass,
321 hb_set_t *glyphs /* OUT */)
323 return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs);
326 #ifndef HB_NO_LAYOUT_UNUSED
328 * hb_ot_layout_get_attach_points:
329 * @face: The #hb_face_t to work on
330 * @glyph: The #hb_codepoint_t code point to query
331 * @start_offset: offset of the first attachment point to retrieve
332 * @point_count: (inout) (optional): Input = the maximum number of attachment points to return;
333 * Output = the actual number of attachment points returned (may be zero)
334 * @point_array: (out) (array length=point_count): The array of attachment points found for the query
336 * Fetches a list of all attachment points for the specified glyph in the GDEF
337 * table of the face. The list returned will begin at the offset provided.
339 * Useful if the client program wishes to cache the list.
341 * Return value: Total number of attachment points for @glyph.
345 hb_ot_layout_get_attach_points (hb_face_t *face,
346 hb_codepoint_t glyph,
347 unsigned int start_offset,
348 unsigned int *point_count /* IN/OUT */,
349 unsigned int *point_array /* OUT */)
351 return face->table.GDEF->table->get_attach_points (glyph,
357 * hb_ot_layout_get_ligature_carets:
358 * @font: The #hb_font_t to work on
359 * @direction: The #hb_direction_t text direction to use
360 * @glyph: The #hb_codepoint_t code point to query
361 * @start_offset: offset of the first caret position to retrieve
362 * @caret_count: (inout) (optional): Input = the maximum number of caret positions to return;
363 * Output = the actual number of caret positions returned (may be zero)
364 * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query
366 * Fetches a list of the caret positions defined for a ligature glyph in the GDEF
367 * table of the font. The list returned will begin at the offset provided.
369 * Note that a ligature that is formed from n characters will have n-1
370 * caret positions. The first character is not represented in the array,
371 * since its caret position is the glyph position.
373 * The positions returned by this function are 'unshaped', and will have to
374 * be fixed up for kerning that may be applied to the ligature glyph.
376 * Return value: Total number of ligature caret positions for @glyph.
380 hb_ot_layout_get_ligature_carets (hb_font_t *font,
381 hb_direction_t direction,
382 hb_codepoint_t glyph,
383 unsigned int start_offset,
384 unsigned int *caret_count /* IN/OUT */,
385 hb_position_t *caret_array /* OUT */)
387 return font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array);
397 GSUB::is_blocklisted (hb_blob_t *blob HB_UNUSED,
398 hb_face_t *face) const
400 #ifdef HB_NO_OT_LAYOUT_BLOCKLIST
407 GPOS::is_blocklisted (hb_blob_t *blob HB_UNUSED,
408 hb_face_t *face HB_UNUSED) const
410 #ifdef HB_NO_OT_LAYOUT_BLOCKLIST
416 static const OT::GSUBGPOS&
417 get_gsubgpos_table (hb_face_t *face,
421 case HB_OT_TAG_GSUB: return *face->table.GSUB->table;
422 case HB_OT_TAG_GPOS: return *face->table.GPOS->table;
423 default: return Null (OT::GSUBGPOS);
429 * hb_ot_layout_table_get_script_tags:
430 * @face: #hb_face_t to work upon
431 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
432 * @start_offset: offset of the first script tag to retrieve
433 * @script_count: (inout) (optional): Input = the maximum number of script tags to return;
434 * Output = the actual number of script tags returned (may be zero)
435 * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query
437 * Fetches a list of all scripts enumerated in the specified face's GSUB table
438 * or GPOS table. The list returned will begin at the offset provided.
440 * Return value: Total number of script tags.
444 hb_ot_layout_table_get_script_tags (hb_face_t *face,
446 unsigned int start_offset,
447 unsigned int *script_count /* IN/OUT */,
448 hb_tag_t *script_tags /* OUT */)
450 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
452 return g.get_script_tags (start_offset, script_count, script_tags);
455 #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n')
458 * hb_ot_layout_table_find_script:
459 * @face: #hb_face_t to work upon
460 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
461 * @script_tag: #hb_tag_t of the script tag requested
462 * @script_index: (out): The index of the requested script tag
464 * Fetches the index if a given script tag in the specified face's GSUB table
467 * Return value: `true` if the script is found, `false` otherwise
471 hb_ot_layout_table_find_script (hb_face_t *face,
474 unsigned int *script_index /* OUT */)
476 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
477 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
479 if (g.find_script_index (script_tag, script_index))
482 /* try finding 'DFLT' */
483 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
486 /* try with 'dflt'; MS site has had typos and many fonts use it now :(.
487 * including many versions of DejaVu Sans Mono! */
488 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
491 /* try with 'latn'; some old fonts put their features there even though
492 they're really trying to support Thai, for example :( */
493 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index))
496 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
500 #ifndef HB_DISABLE_DEPRECATED
502 * hb_ot_layout_table_choose_script:
503 * @face: #hb_face_t to work upon
504 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
505 * @script_tags: Array of #hb_tag_t script tags
506 * @script_index: (out): The index of the chosen script
507 * @chosen_script: (out): #hb_tag_t of the chosen script
509 * Deprecated since 2.0.0
512 hb_ot_layout_table_choose_script (hb_face_t *face,
514 const hb_tag_t *script_tags,
515 unsigned int *script_index /* OUT */,
516 hb_tag_t *chosen_script /* OUT */)
519 for (t = script_tags; *t; t++);
520 return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script);
525 * hb_ot_layout_table_select_script:
526 * @face: #hb_face_t to work upon
527 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
528 * @script_count: Number of script tags in the array
529 * @script_tags: Array of #hb_tag_t script tags
530 * @script_index: (out) (optional): The index of the requested script
531 * @chosen_script: (out) (optional): #hb_tag_t of the requested script
533 * Selects an OpenType script for @table_tag from the @script_tags array.
535 * If the table does not have any of the requested scripts, then `DFLT`,
536 * `dflt`, and `latn` tags are tried in that order. If the table still does not
537 * have any of these scripts, @script_index is set to
538 * #HB_OT_LAYOUT_NO_SCRIPT_INDEX and @chosen_script is set to #HB_TAG_NONE.
541 * `true` if one of the requested scripts is selected, `false` if a fallback
542 * script is selected or if no scripts are selected.
547 hb_ot_layout_table_select_script (hb_face_t *face,
549 unsigned int script_count,
550 const hb_tag_t *script_tags,
551 unsigned int *script_index /* OUT */,
552 hb_tag_t *chosen_script /* OUT */)
554 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
555 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
558 for (i = 0; i < script_count; i++)
560 if (g.find_script_index (script_tags[i], script_index))
563 *chosen_script = script_tags[i];
568 /* try finding 'DFLT' */
569 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) {
571 *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT;
575 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
576 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) {
578 *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE;
582 /* try with 'latn'; some old fonts put their features there even though
583 they're really trying to support Thai, for example :( */
584 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) {
586 *chosen_script = HB_OT_TAG_LATIN_SCRIPT;
590 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
592 *chosen_script = HB_TAG_NONE;
598 * hb_ot_layout_table_get_feature_tags:
599 * @face: #hb_face_t to work upon
600 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
601 * @start_offset: offset of the first feature tag to retrieve
602 * @feature_count: (inout) (optional): Input = the maximum number of feature tags to return;
603 * Output = the actual number of feature tags returned (may be zero)
604 * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table
606 * Fetches a list of all feature tags in the given face's GSUB or GPOS table.
607 * Note that there might be duplicate feature tags, belonging to different
608 * script/language-system pairs of the table.
610 * Return value: Total number of feature tags.
616 hb_ot_layout_table_get_feature_tags (hb_face_t *face,
618 unsigned int start_offset,
619 unsigned int *feature_count /* IN/OUT */,
620 hb_tag_t *feature_tags /* OUT */)
622 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
624 return g.get_feature_tags (start_offset, feature_count, feature_tags);
629 * hb_ot_layout_table_find_feature:
630 * @face: #hb_face_t to work upon
631 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
632 * @feature_tag: The #hb_tag_t of the requested feature tag
633 * @feature_index: (out): The index of the requested feature
635 * Fetches the index for a given feature tag in the specified face's GSUB table
638 * Return value: `true` if the feature is found, `false` otherwise
644 hb_ot_layout_table_find_feature (hb_face_t *face,
646 hb_tag_t feature_tag,
647 unsigned int *feature_index /* OUT */)
649 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
650 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
652 unsigned int num_features = g.get_feature_count ();
653 for (unsigned int i = 0; i < num_features; i++)
655 if (feature_tag == g.get_feature_tag (i)) {
656 if (feature_index) *feature_index = i;
661 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
667 * hb_ot_layout_script_get_language_tags:
668 * @face: #hb_face_t to work upon
669 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
670 * @script_index: The index of the requested script tag
671 * @start_offset: offset of the first language tag to retrieve
672 * @language_count: (inout) (optional): Input = the maximum number of language tags to return;
673 * Output = the actual number of language tags returned (may be zero)
674 * @language_tags: (out) (array length=language_count): Array of language tags found in the table
676 * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath
677 * the specified script index. The list returned will begin at the offset provided.
679 * Return value: Total number of language tags.
685 hb_ot_layout_script_get_language_tags (hb_face_t *face,
687 unsigned int script_index,
688 unsigned int start_offset,
689 unsigned int *language_count /* IN/OUT */,
690 hb_tag_t *language_tags /* OUT */)
692 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
694 return s.get_lang_sys_tags (start_offset, language_count, language_tags);
698 #ifndef HB_DISABLE_DEPRECATED
700 * hb_ot_layout_script_find_language:
701 * @face: #hb_face_t to work upon
702 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
703 * @script_index: The index of the requested script tag
704 * @language_tag: The #hb_tag_t of the requested language
705 * @language_index: The index of the requested language
707 * Fetches the index of a given language tag in the specified face's GSUB table
708 * or GPOS table, underneath the specified script tag.
710 * Return value: `true` if the language tag is found, `false` otherwise
716 hb_ot_layout_script_find_language (hb_face_t *face,
718 unsigned int script_index,
719 hb_tag_t language_tag,
720 unsigned int *language_index)
722 return hb_ot_layout_script_select_language (face,
733 * hb_ot_layout_script_select_language2:
734 * @face: #hb_face_t to work upon
735 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
736 * @script_index: The index of the requested script tag
737 * @language_count: The number of languages in the specified script
738 * @language_tags: The array of language tags
739 * @language_index: (out): The index of the chosen language
740 * @chosen_language: (out): #hb_tag_t of the chosen language
742 * Fetches the index of the first language tag fom @language_tags that is present
743 * in the specified face's GSUB or GPOS table, underneath the specified script
746 * If none of the given language tags is found, `false` is returned and
747 * @language_index is set to #HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX and
748 * @chosen_language is set to #HB_TAG_NONE.
750 * Return value: `true` if one of the given language tags is found, `false` otherwise
755 hb_ot_layout_script_select_language2 (hb_face_t *face,
757 unsigned int script_index,
758 unsigned int language_count,
759 const hb_tag_t *language_tags,
760 unsigned int *language_index /* OUT */,
761 hb_tag_t *chosen_language /* OUT */)
763 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), "");
764 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
767 for (i = 0; i < language_count; i++)
769 if (s.find_lang_sys_index (language_tags[i], language_index))
772 *chosen_language = language_tags[i];
777 /* try finding 'dflt' */
778 if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
781 *chosen_language = HB_OT_TAG_DEFAULT_LANGUAGE;
786 *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
788 *chosen_language = HB_TAG_NONE;
793 * hb_ot_layout_script_select_language:
794 * @face: #hb_face_t to work upon
795 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
796 * @script_index: The index of the requested script tag
797 * @language_count: The number of languages in the specified script
798 * @language_tags: The array of language tags
799 * @language_index: (out): The index of the requested language
801 * Fetches the index of the first language tag fom @language_tags that is present
802 * in the specified face's GSUB or GPOS table, underneath the specified script
805 * If none of the given language tags is found, `false` is returned and
806 * @language_index is set to the default language index.
808 * Return value: `true` if one of the given language tags is found, `false` otherwise
813 hb_ot_layout_script_select_language (hb_face_t *face,
815 unsigned int script_index,
816 unsigned int language_count,
817 const hb_tag_t *language_tags,
818 unsigned int *language_index /* OUT */)
820 return hb_ot_layout_script_select_language2 (face, table_tag,
822 language_count, language_tags,
823 language_index, nullptr);
827 * hb_ot_layout_language_get_required_feature_index:
828 * @face: #hb_face_t to work upon
829 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
830 * @script_index: The index of the requested script tag
831 * @language_index: The index of the requested language tag
832 * @feature_index: (out): The index of the requested feature
834 * Fetches the index of a requested feature in the given face's GSUB or GPOS table,
835 * underneath the specified script and language.
837 * Return value: `true` if the feature is found, `false` otherwise
843 hb_ot_layout_language_get_required_feature_index (hb_face_t *face,
845 unsigned int script_index,
846 unsigned int language_index,
847 unsigned int *feature_index /* OUT */)
849 return hb_ot_layout_language_get_required_feature (face,
859 * hb_ot_layout_language_get_required_feature:
860 * @face: #hb_face_t to work upon
861 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
862 * @script_index: The index of the requested script tag
863 * @language_index: The index of the requested language tag
864 * @feature_index: (out): The index of the requested feature
865 * @feature_tag: (out): The #hb_tag_t of the requested feature
867 * Fetches the tag of a requested feature index in the given face's GSUB or GPOS table,
868 * underneath the specified script and language.
870 * Return value: `true` if the feature is found, `false` otherwise
875 hb_ot_layout_language_get_required_feature (hb_face_t *face,
877 unsigned int script_index,
878 unsigned int language_index,
879 unsigned int *feature_index /* OUT */,
880 hb_tag_t *feature_tag /* OUT */)
882 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
883 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
885 unsigned int index = l.get_required_feature_index ();
886 if (feature_index) *feature_index = index;
887 if (feature_tag) *feature_tag = g.get_feature_tag (index);
889 return l.has_required_feature ();
894 * hb_ot_layout_language_get_feature_indexes:
895 * @face: #hb_face_t to work upon
896 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
897 * @script_index: The index of the requested script tag
898 * @language_index: The index of the requested language tag
899 * @start_offset: offset of the first feature tag to retrieve
900 * @feature_count: (inout) (optional): Input = the maximum number of feature tags to return;
901 * Output: the actual number of feature tags returned (may be zero)
902 * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query
904 * Fetches a list of all features in the specified face's GSUB table
905 * or GPOS table, underneath the specified script and language. The list
906 * returned will begin at the offset provided.
908 * Return value: Total number of features.
914 hb_ot_layout_language_get_feature_indexes (hb_face_t *face,
916 unsigned int script_index,
917 unsigned int language_index,
918 unsigned int start_offset,
919 unsigned int *feature_count /* IN/OUT */,
920 unsigned int *feature_indexes /* OUT */)
922 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
923 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
925 return l.get_feature_indexes (start_offset, feature_count, feature_indexes);
930 * hb_ot_layout_language_get_feature_tags:
931 * @face: #hb_face_t to work upon
932 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
933 * @script_index: The index of the requested script tag
934 * @language_index: The index of the requested language tag
935 * @start_offset: offset of the first feature tag to retrieve
936 * @feature_count: (inout) (optional): Input = the maximum number of feature tags to return;
937 * Output = the actual number of feature tags returned (may be zero)
938 * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query
940 * Fetches a list of all features in the specified face's GSUB table
941 * or GPOS table, underneath the specified script and language. The list
942 * returned will begin at the offset provided.
944 * Return value: Total number of feature tags.
950 hb_ot_layout_language_get_feature_tags (hb_face_t *face,
952 unsigned int script_index,
953 unsigned int language_index,
954 unsigned int start_offset,
955 unsigned int *feature_count /* IN/OUT */,
956 hb_tag_t *feature_tags /* OUT */)
958 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
959 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
961 static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), "");
962 unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
965 unsigned int count = *feature_count;
966 for (unsigned int i = 0; i < count; i++)
967 feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]);
975 * hb_ot_layout_language_find_feature:
976 * @face: #hb_face_t to work upon
977 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
978 * @script_index: The index of the requested script tag
979 * @language_index: The index of the requested language tag
980 * @feature_tag: #hb_tag_t of the feature tag requested
981 * @feature_index: (out): The index of the requested feature
983 * Fetches the index of a given feature tag in the specified face's GSUB table
984 * or GPOS table, underneath the specified script and language.
986 * Return value: `true` if the feature is found, `false` otherwise
992 hb_ot_layout_language_find_feature (hb_face_t *face,
994 unsigned int script_index,
995 unsigned int language_index,
996 hb_tag_t feature_tag,
997 unsigned int *feature_index /* OUT */)
999 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
1000 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1001 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
1003 unsigned int num_features = l.get_feature_count ();
1004 for (unsigned int i = 0; i < num_features; i++) {
1005 unsigned int f_index = l.get_feature_index (i);
1007 if (feature_tag == g.get_feature_tag (f_index)) {
1008 if (feature_index) *feature_index = f_index;
1013 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
1019 * hb_ot_layout_feature_get_lookups:
1020 * @face: #hb_face_t to work upon
1021 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1022 * @feature_index: The index of the requested feature
1023 * @start_offset: offset of the first lookup to retrieve
1024 * @lookup_count: (inout) (optional): Input = the maximum number of lookups to return;
1025 * Output = the actual number of lookups returned (may be zero)
1026 * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query
1028 * Fetches a list of all lookups enumerated for the specified feature, in
1029 * the specified face's GSUB table or GPOS table. The list returned will
1030 * begin at the offset provided.
1032 * Return value: Total number of lookups.
1037 hb_ot_layout_feature_get_lookups (hb_face_t *face,
1039 unsigned int feature_index,
1040 unsigned int start_offset,
1041 unsigned int *lookup_count /* IN/OUT */,
1042 unsigned int *lookup_indexes /* OUT */)
1044 return hb_ot_layout_feature_with_variations_get_lookups (face,
1047 HB_OT_LAYOUT_NO_VARIATIONS_INDEX,
1055 * hb_ot_layout_table_get_lookup_count:
1056 * @face: #hb_face_t to work upon
1057 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1059 * Fetches the total number of lookups enumerated in the specified
1060 * face's GSUB table or GPOS table.
1062 * Return value: Total number of lookups.
1067 hb_ot_layout_table_get_lookup_count (hb_face_t *face,
1070 return get_gsubgpos_table (face, table_tag).get_lookup_count ();
1074 struct hb_collect_features_context_t
1076 hb_collect_features_context_t (hb_face_t *face,
1078 hb_set_t *feature_indices_,
1079 const hb_tag_t *features)
1081 : g (get_gsubgpos_table (face, table_tag)),
1082 feature_indices (feature_indices_),
1083 has_feature_filter (false),
1084 script_count (0),langsys_count (0), feature_index_count (0)
1086 compute_feature_filter (features);
1089 void compute_feature_filter (const hb_tag_t *features)
1091 if (features == nullptr)
1093 has_feature_filter = false;
1097 has_feature_filter = true;
1098 hb_set_t features_set;
1099 for (; *features; features++)
1100 features_set.add (*features);
1102 for (unsigned i = 0; i < g.get_feature_count (); i++)
1104 hb_tag_t tag = g.get_feature_tag (i);
1105 if (features_set.has (tag))
1106 feature_indices_filter.add(i);
1110 bool visited (const OT::Script &s)
1112 /* We might have Null() object here. Don't want to involve
1113 * that in the memoize. So, detect empty objects and return. */
1114 if (unlikely (!s.has_default_lang_sys () &&
1115 !s.get_lang_sys_count ()))
1118 if (script_count++ > HB_MAX_SCRIPTS)
1121 return visited (s, visited_script);
1123 bool visited (const OT::LangSys &l)
1125 /* We might have Null() object here. Don't want to involve
1126 * that in the memoize. So, detect empty objects and return. */
1127 if (unlikely (!l.has_required_feature () &&
1128 !l.get_feature_count ()))
1131 if (langsys_count++ > HB_MAX_LANGSYS)
1134 return visited (l, visited_langsys);
1137 bool visited_feature_indices (unsigned count)
1139 feature_index_count += count;
1140 return feature_index_count > HB_MAX_FEATURE_INDICES;
1144 template <typename T>
1145 bool visited (const T &p, hb_set_t &visited_set)
1147 hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g);
1148 if (visited_set.has (delta))
1151 visited_set.add (delta);
1156 const OT::GSUBGPOS &g;
1157 hb_set_t *feature_indices;
1158 hb_set_t feature_indices_filter;
1159 bool has_feature_filter;
1162 hb_set_t visited_script;
1163 hb_set_t visited_langsys;
1164 unsigned int script_count;
1165 unsigned int langsys_count;
1166 unsigned int feature_index_count;
1170 langsys_collect_features (hb_collect_features_context_t *c,
1171 const OT::LangSys &l)
1173 if (c->visited (l)) return;
1175 if (!c->has_feature_filter)
1178 if (l.has_required_feature () && !c->visited_feature_indices (1))
1179 c->feature_indices->add (l.get_required_feature_index ());
1181 // TODO(garretrieger): filter out indices >= feature count?
1182 if (!c->visited_feature_indices (l.featureIndex.len))
1183 l.add_feature_indexes_to (c->feature_indices);
1187 if (c->feature_indices_filter.is_empty()) return;
1188 unsigned int num_features = l.get_feature_count ();
1189 for (unsigned int i = 0; i < num_features; i++)
1191 unsigned int feature_index = l.get_feature_index (i);
1192 if (!c->feature_indices_filter.has (feature_index)) continue;
1194 c->feature_indices->add (feature_index);
1195 c->feature_indices_filter.del (feature_index);
1201 script_collect_features (hb_collect_features_context_t *c,
1202 const OT::Script &s,
1203 const hb_tag_t *languages)
1205 if (c->visited (s)) return;
1209 /* All languages. */
1210 if (s.has_default_lang_sys ())
1211 langsys_collect_features (c,
1212 s.get_default_lang_sys ());
1215 unsigned int count = s.get_lang_sys_count ();
1216 for (unsigned int language_index = 0; language_index < count; language_index++)
1217 langsys_collect_features (c,
1218 s.get_lang_sys (language_index));
1222 for (; *languages; languages++)
1224 unsigned int language_index;
1225 if (s.find_lang_sys_index (*languages, &language_index))
1226 langsys_collect_features (c,
1227 s.get_lang_sys (language_index));
1235 * hb_ot_layout_collect_features:
1236 * @face: #hb_face_t to work upon
1237 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1238 * @scripts: (nullable) (array zero-terminated=1): The array of scripts to collect features for,
1239 * terminated by %HB_TAG_NONE
1240 * @languages: (nullable) (array zero-terminated=1): The array of languages to collect features for,
1241 * terminated by %HB_TAG_NONE
1242 * @features: (nullable) (array zero-terminated=1): The array of features to collect,
1243 * terminated by %HB_TAG_NONE
1244 * @feature_indexes: (out): The set of feature indexes found for the query
1246 * Fetches a list of all feature indexes in the specified face's GSUB table
1247 * or GPOS table, underneath the specified scripts, languages, and features.
1248 * If no list of scripts is provided, all scripts will be queried. If no list
1249 * of languages is provided, all languages will be queried. If no list of
1250 * features is provided, all features will be queried.
1255 hb_ot_layout_collect_features (hb_face_t *face,
1257 const hb_tag_t *scripts,
1258 const hb_tag_t *languages,
1259 const hb_tag_t *features,
1260 hb_set_t *feature_indexes /* OUT */)
1262 hb_collect_features_context_t c (face, table_tag, feature_indexes, features);
1266 unsigned int count = c.g.get_script_count ();
1267 for (unsigned int script_index = 0; script_index < count; script_index++)
1268 script_collect_features (&c,
1269 c.g.get_script (script_index),
1274 for (; *scripts; scripts++)
1276 unsigned int script_index;
1277 if (c.g.find_script_index (*scripts, &script_index))
1278 script_collect_features (&c,
1279 c.g.get_script (script_index),
1286 * hb_ot_layout_collect_features_map:
1287 * @face: #hb_face_t to work upon
1288 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1289 * @script_index: The index of the requested script tag
1290 * @language_index: The index of the requested language tag
1291 * @feature_map: (out): The map of feature tag to feature index.
1293 * Fetches the mapping from feature tags to feature indexes for
1294 * the specified script and language.
1299 hb_ot_layout_collect_features_map (hb_face_t *face,
1301 unsigned script_index,
1302 unsigned language_index,
1303 hb_map_t *feature_map /* OUT */)
1305 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1306 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
1308 unsigned int count = l.get_feature_indexes (0, nullptr, nullptr);
1309 feature_map->alloc (count);
1311 /* Loop in reverse, such that earlier entries win. That emulates
1312 * a linear search, which seems to be what other implementations do.
1313 * We found that with arialuni_t.ttf, the "ur" language system has
1314 * duplicate features, and the earlier ones work but not later ones.
1316 for (unsigned int i = count; i; i--)
1318 unsigned feature_index = 0;
1319 unsigned feature_count = 1;
1320 l.get_feature_indexes (i - 1, &feature_count, &feature_index);
1323 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1324 feature_map->set (feature_tag, feature_index);
1330 * hb_ot_layout_collect_lookups:
1331 * @face: #hb_face_t to work upon
1332 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1333 * @scripts: (nullable) (array zero-terminated=1): The array of scripts to collect lookups for,
1334 * terminated by %HB_TAG_NONE
1335 * @languages: (nullable) (array zero-terminated=1): The array of languages to collect lookups for,
1336 * terminated by %HB_TAG_NONE
1337 * @features: (nullable) (array zero-terminated=1): The array of features to collect lookups for,
1338 * terminated by %HB_TAG_NONE
1339 * @lookup_indexes: (out): The array of lookup indexes found for the query
1341 * Fetches a list of all feature-lookup indexes in the specified face's GSUB
1342 * table or GPOS table, underneath the specified scripts, languages, and
1343 * features. If no list of scripts is provided, all scripts will be queried.
1344 * If no list of languages is provided, all languages will be queried. If no
1345 * list of features is provided, all features will be queried.
1350 hb_ot_layout_collect_lookups (hb_face_t *face,
1352 const hb_tag_t *scripts,
1353 const hb_tag_t *languages,
1354 const hb_tag_t *features,
1355 hb_set_t *lookup_indexes /* OUT */)
1357 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1359 hb_set_t feature_indexes;
1360 hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes);
1362 for (auto feature_index : feature_indexes)
1363 g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes);
1365 g.feature_variation_collect_lookups (&feature_indexes, nullptr, lookup_indexes);
1369 #ifndef HB_NO_LAYOUT_COLLECT_GLYPHS
1371 * hb_ot_layout_lookup_collect_glyphs:
1372 * @face: #hb_face_t to work upon
1373 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1374 * @lookup_index: The index of the feature lookup to query
1375 * @glyphs_before: (out): Array of glyphs preceding the substitution range
1376 * @glyphs_input: (out): Array of input glyphs that would be substituted by the lookup
1377 * @glyphs_after: (out): Array of glyphs following the substitution range
1378 * @glyphs_output: (out): Array of glyphs that would be the substituted output of the lookup
1380 * Fetches a list of all glyphs affected by the specified lookup in the
1381 * specified face's GSUB table or GPOS table.
1386 hb_ot_layout_lookup_collect_glyphs (hb_face_t *face,
1388 unsigned int lookup_index,
1389 hb_set_t *glyphs_before, /* OUT. May be NULL */
1390 hb_set_t *glyphs_input, /* OUT. May be NULL */
1391 hb_set_t *glyphs_after, /* OUT. May be NULL */
1392 hb_set_t *glyphs_output /* OUT. May be NULL */)
1394 OT::hb_collect_glyphs_context_t c (face,
1402 case HB_OT_TAG_GSUB:
1404 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1405 l.collect_glyphs (&c);
1408 case HB_OT_TAG_GPOS:
1410 const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index);
1411 l.collect_glyphs (&c);
1419 /* Variations support */
1423 * hb_ot_layout_table_find_feature_variations:
1424 * @face: #hb_face_t to work upon
1425 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1426 * @coords: The variation coordinates to query
1427 * @num_coords: The number of variation coordinates
1428 * @variations_index: (out): The array of feature variations found for the query
1430 * Fetches a list of feature variations in the specified face's GSUB table
1431 * or GPOS table, at the specified variation coordinates.
1433 * Return value: `true` if feature variations were found, `false` otherwise.
1439 hb_ot_layout_table_find_feature_variations (hb_face_t *face,
1442 unsigned int num_coords,
1443 unsigned int *variations_index /* out */)
1445 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1447 return g.find_variations_index (coords, num_coords, variations_index);
1452 * hb_ot_layout_feature_with_variations_get_lookups:
1453 * @face: #hb_face_t to work upon
1454 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1455 * @feature_index: The index of the feature to query
1456 * @variations_index: The index of the feature variation to query
1457 * @start_offset: offset of the first lookup to retrieve
1458 * @lookup_count: (inout) (optional): Input = the maximum number of lookups to return;
1459 * Output = the actual number of lookups returned (may be zero)
1460 * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query
1462 * Fetches a list of all lookups enumerated for the specified feature, in
1463 * the specified face's GSUB table or GPOS table, enabled at the specified
1464 * variations index. The list returned will begin at the offset provided.
1466 * Return value: Total number of lookups.
1472 hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face,
1474 unsigned int feature_index,
1475 unsigned int variations_index,
1476 unsigned int start_offset,
1477 unsigned int *lookup_count /* IN/OUT */,
1478 unsigned int *lookup_indexes /* OUT */)
1480 static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "");
1481 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1483 const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
1485 return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
1495 * hb_ot_layout_has_substitution:
1496 * @face: #hb_face_t to work upon
1498 * Tests whether the specified face includes any GSUB substitutions.
1500 * Return value: `true` if data found, `false` otherwise
1506 hb_ot_layout_has_substitution (hb_face_t *face)
1508 return face->table.GSUB->table->has_data ();
1513 * hb_ot_layout_lookup_would_substitute:
1514 * @face: #hb_face_t to work upon
1515 * @lookup_index: The index of the lookup to query
1516 * @glyphs: The sequence of glyphs to query for substitution
1517 * @glyphs_length: The length of the glyph sequence
1518 * @zero_context: #hb_bool_t indicating whether pre-/post-context are disallowed
1521 * Tests whether a specified lookup in the specified face would
1522 * trigger a substitution on the given glyph sequence.
1524 * Return value: `true` if a substitution would be triggered, `false` otherwise
1529 hb_ot_layout_lookup_would_substitute (hb_face_t *face,
1530 unsigned int lookup_index,
1531 const hb_codepoint_t *glyphs,
1532 unsigned int glyphs_length,
1533 hb_bool_t zero_context)
1535 auto &gsub = face->table.GSUB;
1536 if (unlikely (lookup_index >= gsub->lookup_count)) return false;
1537 OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context);
1539 const OT::SubstLookup& l = gsub->table->get_lookup (lookup_index);
1540 auto *accel = gsub->get_accel (lookup_index);
1541 return accel && l.would_apply (&c, accel);
1546 * hb_ot_layout_substitute_start:
1547 * @font: #hb_font_t to use
1548 * @buffer: #hb_buffer_t buffer to work upon
1550 * Called before substitution lookups are performed, to ensure that glyph
1551 * class and other properties are set on the glyphs in the buffer.
1555 hb_ot_layout_substitute_start (hb_font_t *font,
1556 hb_buffer_t *buffer)
1558 _hb_ot_layout_set_glyph_props (font, buffer);
1562 * hb_ot_layout_lookup_substitute_closure:
1563 * @face: #hb_face_t to work upon
1564 * @lookup_index: index of the feature lookup to query
1565 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup
1567 * Compute the transitive closure of glyphs needed for a
1573 hb_ot_layout_lookup_substitute_closure (hb_face_t *face,
1574 unsigned int lookup_index,
1575 hb_set_t *glyphs /* OUT */)
1577 hb_map_t done_lookups_glyph_count;
1578 hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> done_lookups_glyph_set;
1579 OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
1581 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1583 l.closure (&c, lookup_index);
1587 * hb_ot_layout_lookups_substitute_closure:
1588 * @face: #hb_face_t to work upon
1589 * @lookups: The set of lookups to query
1590 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups
1592 * Compute the transitive closure of glyphs needed for all of the
1598 hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
1599 const hb_set_t *lookups,
1600 hb_set_t *glyphs /* OUT */)
1602 hb_map_t done_lookups_glyph_count;
1603 hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> done_lookups_glyph_set;
1604 OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
1605 const GSUB& gsub = *face->table.GSUB->table;
1607 unsigned int iteration_count = 0;
1608 unsigned int glyphs_length;
1611 c.reset_lookup_visit_count ();
1612 glyphs_length = glyphs->get_population ();
1615 for (auto lookup_index : *lookups)
1616 gsub.get_lookup (lookup_index).closure (&c, lookup_index);
1620 for (unsigned int i = 0; i < gsub.get_lookup_count (); i++)
1621 gsub.get_lookup (i).closure (&c, i);
1623 } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES &&
1624 glyphs_length != glyphs->get_population ());
1633 * hb_ot_layout_has_positioning:
1634 * @face: #hb_face_t to work upon
1636 * Tests whether the specified face includes any GPOS positioning.
1638 * Return value: `true` if the face has GPOS data, `false` otherwise
1642 hb_ot_layout_has_positioning (hb_face_t *face)
1644 return face->table.GPOS->table->has_data ();
1648 * hb_ot_layout_position_start:
1649 * @font: #hb_font_t to use
1650 * @buffer: #hb_buffer_t buffer to work upon
1652 * Called before positioning lookups are performed, to ensure that glyph
1653 * attachment types and glyph-attachment chains are set for the glyphs in the buffer.
1657 hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer)
1659 GPOS::position_start (font, buffer);
1664 * hb_ot_layout_position_finish_advances:
1665 * @font: #hb_font_t to use
1666 * @buffer: #hb_buffer_t buffer to work upon
1668 * Called after positioning lookups are performed, to finish glyph advances.
1672 hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer)
1674 GPOS::position_finish_advances (font, buffer);
1678 * hb_ot_layout_position_finish_offsets:
1679 * @font: #hb_font_t to use
1680 * @buffer: #hb_buffer_t buffer to work upon
1682 * Called after positioning lookups are performed, to finish glyph offsets.
1686 hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
1688 GPOS::position_finish_offsets (font, buffer);
1692 #ifndef HB_NO_LAYOUT_FEATURE_PARAMS
1694 * hb_ot_layout_get_size_params:
1695 * @face: #hb_face_t to work upon
1696 * @design_size: (out): The design size of the face
1697 * @subfamily_id: (out): The identifier of the face within the font subfamily
1698 * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily
1699 * @range_start: (out): The minimum size of the recommended size range for the face
1700 * @range_end: (out): The maximum size of the recommended size range for the face
1702 * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that
1703 * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id)
1704 * as used here are defined as pertaining only to fonts within a font family that differ
1705 * specifically in their respective size ranges; other ways to differentiate fonts within
1706 * a subfamily are not covered by the `size` feature.
1708 * For more information on this distinction, see the [`size` feature documentation](
1709 * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-size).
1711 * Return value: `true` if data found, `false` otherwise
1716 hb_ot_layout_get_size_params (hb_face_t *face,
1717 unsigned int *design_size, /* OUT. May be NULL */
1718 unsigned int *subfamily_id, /* OUT. May be NULL */
1719 hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */
1720 unsigned int *range_start, /* OUT. May be NULL */
1721 unsigned int *range_end /* OUT. May be NULL */)
1723 const GPOS &gpos = *face->table.GPOS->table;
1724 const hb_tag_t tag = HB_TAG ('s','i','z','e');
1726 unsigned int num_features = gpos.get_feature_count ();
1727 for (unsigned int i = 0; i < num_features; i++)
1729 if (tag == gpos.get_feature_tag (i))
1731 const OT::Feature &f = gpos.get_feature (i);
1732 const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag);
1734 if (params.designSize)
1736 if (design_size) *design_size = params.designSize;
1737 if (subfamily_id) *subfamily_id = params.subfamilyID;
1738 if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID;
1739 if (range_start) *range_start = params.rangeStart;
1740 if (range_end) *range_end = params.rangeEnd;
1747 if (design_size) *design_size = 0;
1748 if (subfamily_id) *subfamily_id = 0;
1749 if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID;
1750 if (range_start) *range_start = 0;
1751 if (range_end) *range_end = 0;
1758 * hb_ot_layout_feature_get_name_ids:
1759 * @face: #hb_face_t to work upon
1760 * @table_tag: table tag to query, "GSUB" or "GPOS".
1761 * @feature_index: index of feature to query.
1762 * @label_id: (out) (optional): The ‘name’ table name ID that specifies a string
1763 * for a user-interface label for this feature. (May be NULL.)
1764 * @tooltip_id: (out) (optional): The ‘name’ table name ID that specifies a string
1765 * that an application can use for tooltip text for this
1766 * feature. (May be NULL.)
1767 * @sample_id: (out) (optional): The ‘name’ table name ID that specifies sample text
1768 * that illustrates the effect of this feature. (May be NULL.)
1769 * @num_named_parameters: (out) (optional): Number of named parameters. (May be zero.)
1770 * @first_param_id: (out) (optional): The first ‘name’ table name ID used to specify
1771 * strings for user-interface labels for the feature
1772 * parameters. (Must be zero if numParameters is zero.)
1774 * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or
1775 * "Character Variant" ('cvXX') features.
1777 * Return value: `true` if data found, `false` otherwise
1782 hb_ot_layout_feature_get_name_ids (hb_face_t *face,
1784 unsigned int feature_index,
1785 hb_ot_name_id_t *label_id, /* OUT. May be NULL */
1786 hb_ot_name_id_t *tooltip_id, /* OUT. May be NULL */
1787 hb_ot_name_id_t *sample_id, /* OUT. May be NULL */
1788 unsigned int *num_named_parameters, /* OUT. May be NULL */
1789 hb_ot_name_id_t *first_param_id /* OUT. May be NULL */)
1791 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1793 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1794 const OT::Feature &f = g.get_feature (feature_index);
1796 const OT::FeatureParams &feature_params = f.get_feature_params ();
1797 if (&feature_params != &Null (OT::FeatureParams))
1799 const OT::FeatureParamsStylisticSet& ss_params =
1800 feature_params.get_stylistic_set_params (feature_tag);
1801 if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */
1803 if (label_id) *label_id = ss_params.uiNameID;
1804 // ssXX features don't have the rest
1805 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1806 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1807 if (num_named_parameters) *num_named_parameters = 0;
1808 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1811 const OT::FeatureParamsCharacterVariants& cv_params =
1812 feature_params.get_character_variants_params (feature_tag);
1813 if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */
1815 if (label_id) *label_id = cv_params.featUILableNameID;
1816 if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID;
1817 if (sample_id) *sample_id = cv_params.sampleTextNameID;
1818 if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters;
1819 if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID;
1824 if (label_id) *label_id = HB_OT_NAME_ID_INVALID;
1825 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1826 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1827 if (num_named_parameters) *num_named_parameters = 0;
1828 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1832 * hb_ot_layout_feature_get_characters:
1833 * @face: #hb_face_t to work upon
1834 * @table_tag: table tag to query, "GSUB" or "GPOS".
1835 * @feature_index: index of feature to query.
1836 * @start_offset: offset of the first character to retrieve
1837 * @char_count: (inout) (optional): Input = the maximum number of characters to return;
1838 * Output = the actual number of characters returned (may be zero)
1839 * @characters: (out caller-allocates) (array length=char_count): A buffer pointer.
1840 * The Unicode codepoints of the characters for which this feature provides
1843 * Fetches a list of the characters defined as having a variant under the specified
1844 * "Character Variant" ("cvXX") feature tag.
1846 * Return value: Number of total sample characters in the cvXX feature.
1851 hb_ot_layout_feature_get_characters (hb_face_t *face,
1853 unsigned int feature_index,
1854 unsigned int start_offset,
1855 unsigned int *char_count, /* IN/OUT. May be NULL */
1856 hb_codepoint_t *characters /* OUT. May be NULL */)
1858 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1859 return g.get_feature (feature_index)
1860 .get_feature_params ()
1861 .get_character_variants_params(g.get_feature_tag (feature_index))
1862 .get_characters (start_offset, char_count, characters);
1868 * Parts of different types are implemented here such that they have direct
1869 * access to GSUB/GPOS lookups.
1875 static constexpr unsigned table_index = 0u;
1876 static constexpr bool always_inplace = false;
1877 typedef OT::SubstLookup Lookup;
1879 GSUBProxy (hb_face_t *face) :
1880 accel (*face->table.GSUB) {}
1882 const GSUB::accelerator_t &accel;
1887 static constexpr unsigned table_index = 1u;
1888 static constexpr bool always_inplace = true;
1889 typedef OT::PosLookup Lookup;
1891 GPOSProxy (hb_face_t *face) :
1892 accel (*face->table.GPOS) {}
1894 const GPOS::accelerator_t &accel;
1899 apply_forward (OT::hb_ot_apply_context_t *c,
1900 const OT::hb_ot_layout_lookup_accelerator_t &accel,
1901 unsigned subtable_count)
1903 bool use_cache = accel.cache_enter (c);
1906 hb_buffer_t *buffer = c->buffer;
1907 while (buffer->idx < buffer->len && buffer->successful)
1909 bool applied = false;
1910 if (accel.digest.may_have (buffer->cur().codepoint) &&
1911 (buffer->cur().mask & c->lookup_mask) &&
1912 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1914 applied = accel.apply (c, subtable_count, use_cache);
1920 (void) buffer->next_glyph ();
1924 accel.cache_leave (c);
1930 apply_backward (OT::hb_ot_apply_context_t *c,
1931 const OT::hb_ot_layout_lookup_accelerator_t &accel,
1932 unsigned subtable_count)
1935 hb_buffer_t *buffer = c->buffer;
1938 if (accel.digest.may_have (buffer->cur().codepoint) &&
1939 (buffer->cur().mask & c->lookup_mask) &&
1940 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1941 ret |= accel.apply (c, subtable_count, false);
1943 /* The reverse lookup doesn't "advance" cursor (for good reason). */
1947 while ((int) buffer->idx >= 0);
1951 template <typename Proxy>
1953 apply_string (OT::hb_ot_apply_context_t *c,
1954 const typename Proxy::Lookup &lookup,
1955 const OT::hb_ot_layout_lookup_accelerator_t &accel)
1957 hb_buffer_t *buffer = c->buffer;
1958 unsigned subtable_count = lookup.get_subtable_count ();
1960 if (unlikely (!buffer->len || !c->lookup_mask))
1965 c->set_lookup_props (lookup.get_props ());
1967 if (likely (!lookup.is_reverse ()))
1969 /* in/out forward substitution/positioning */
1970 if (!Proxy::always_inplace)
1971 buffer->clear_output ();
1974 ret = apply_forward (c, accel, subtable_count);
1976 if (!Proxy::always_inplace)
1981 /* in-place backward substitution/positioning */
1982 assert (!buffer->have_output);
1983 buffer->idx = buffer->len - 1;
1984 ret = apply_backward (c, accel, subtable_count);
1990 template <typename Proxy>
1991 inline void hb_ot_map_t::apply (const Proxy &proxy,
1992 const hb_ot_shape_plan_t *plan,
1994 hb_buffer_t *buffer) const
1996 const unsigned int table_index = proxy.table_index;
1998 OT::hb_ot_apply_context_t c (table_index, font, buffer, proxy.accel.get_blob ());
1999 c.set_recurse_func (Proxy::Lookup::template dispatch_recurse_func<OT::hb_ot_apply_context_t>);
2001 for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++)
2003 const stage_map_t *stage = &stages[table_index][stage_index];
2004 for (; i < stage->last_lookup; i++)
2006 auto &lookup = lookups[table_index][i];
2008 unsigned int lookup_index = lookup.index;
2010 auto *accel = proxy.accel.get_accel (lookup_index);
2011 if (unlikely (!accel)) continue;
2013 if (buffer->messaging () &&
2014 !buffer->message (font, "start lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag))) continue;
2016 /* c.digest is a digest of all the current glyphs in the buffer
2017 * (plus some past glyphs).
2019 * Only try applying the lookup if there is any overlap. */
2020 if (accel->digest.may_have (c.digest))
2022 c.set_lookup_index (lookup_index);
2023 c.set_lookup_mask (lookup.mask, false);
2024 c.set_auto_zwj (lookup.auto_zwj, false);
2025 c.set_auto_zwnj (lookup.auto_zwnj, false);
2026 c.set_random (lookup.random);
2027 c.set_per_syllable (lookup.per_syllable, false);
2028 /* apply_string's set_lookup_props initializes the iterators. */
2030 apply_string<Proxy> (&c,
2031 proxy.accel.table->get_lookup (lookup_index),
2034 else if (buffer->messaging ())
2035 (void) buffer->message (font, "skipped lookup %u feature '%c%c%c%c' because no glyph matches", lookup_index, HB_UNTAG (lookup.feature_tag));
2037 if (buffer->messaging ())
2038 (void) buffer->message (font, "end lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag));
2041 if (stage->pause_func)
2043 if (stage->pause_func (plan, font, buffer))
2045 /* Refresh working buffer digest since buffer changed. */
2046 c.digest = buffer->digest ();
2052 void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
2054 GSUBProxy proxy (font->face);
2055 if (buffer->messaging () &&
2056 !buffer->message (font, "start table GSUB script tag '%c%c%c%c'", HB_UNTAG (chosen_script[0]))) return;
2057 apply (proxy, plan, font, buffer);
2058 if (buffer->messaging ())
2059 (void) buffer->message (font, "end table GSUB script tag '%c%c%c%c'", HB_UNTAG (chosen_script[0]));
2062 void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
2064 GPOSProxy proxy (font->face);
2065 if (buffer->messaging () &&
2066 !buffer->message (font, "start table GPOS script tag '%c%c%c%c'", HB_UNTAG (chosen_script[1]))) return;
2067 apply (proxy, plan, font, buffer);
2068 if (buffer->messaging ())
2069 (void) buffer->message (font, "end table GPOS script tag '%c%c%c%c'", HB_UNTAG (chosen_script[1]));
2073 hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
2074 const OT::SubstLookup &lookup,
2075 const OT::hb_ot_layout_lookup_accelerator_t &accel)
2077 apply_string<GSUBProxy> (c, lookup, accel);
2083 choose_base_tags (hb_script_t script,
2084 hb_language_t language,
2085 hb_tag_t *script_tag,
2086 hb_tag_t *language_tag)
2088 hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
2089 unsigned script_count = ARRAY_LENGTH (script_tags);
2091 hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
2092 unsigned language_count = ARRAY_LENGTH (language_tags);
2094 hb_ot_tags_from_script_and_language (script, language,
2095 &script_count, script_tags,
2096 &language_count, language_tags);
2098 *script_tag = script_count ? script_tags[script_count - 1] : HB_OT_TAG_DEFAULT_SCRIPT;
2099 *language_tag = language_count ? language_tags[language_count - 1] : HB_OT_TAG_DEFAULT_LANGUAGE;
2103 * hb_ot_layout_get_font_extents:
2105 * @direction: text direction.
2106 * @script_tag: script tag.
2107 * @language_tag: language tag.
2108 * @extents: (out) (nullable): font extents if found.
2110 * Fetches script/language-specific font extents. These values are
2111 * looked up in the `BASE` table's `MinMax` records.
2113 * If no such extents are found, the default extents for the font are
2114 * fetched. As such, the return value of this function can for the
2115 * most part be ignored. Note that the per-script/language extents
2116 * do not have a line-gap value, and the line-gap is set to zero in
2119 * Return value: `true` if found script/language-specific font extents.
2124 hb_ot_layout_get_font_extents (hb_font_t *font,
2125 hb_direction_t direction,
2126 hb_tag_t script_tag,
2127 hb_tag_t language_tag,
2128 hb_font_extents_t *extents)
2130 hb_position_t min, max;
2131 if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE,
2136 extents->ascender = max;
2137 extents->descender = min;
2138 extents->line_gap = 0;
2143 hb_font_get_extents_for_direction (font, direction, extents);
2148 * hb_ot_layout_get_font_extents2:
2150 * @direction: text direction.
2152 * @language: (nullable): language.
2153 * @extents: (out) (nullable): font extents if found.
2155 * Fetches script/language-specific font extents. These values are
2156 * looked up in the `BASE` table's `MinMax` records.
2158 * If no such extents are found, the default extents for the font are
2159 * fetched. As such, the return value of this function can for the
2160 * most part be ignored. Note that the per-script/language extents
2161 * do not have a line-gap value, and the line-gap is set to zero in
2164 * This function is like hb_ot_layout_get_font_extents() but takes
2165 * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t.
2167 * Return value: `true` if found script/language-specific font extents.
2172 hb_ot_layout_get_font_extents2 (hb_font_t *font,
2173 hb_direction_t direction,
2175 hb_language_t language,
2176 hb_font_extents_t *extents)
2178 hb_tag_t script_tag, language_tag;
2179 choose_base_tags (script, language, &script_tag, &language_tag);
2180 return hb_ot_layout_get_font_extents (font,
2188 * hb_ot_layout_get_horizontal_baseline_tag_for_script:
2189 * @script: a script tag.
2191 * Fetches the dominant horizontal baseline tag used by @script.
2193 * Return value: dominant baseline tag for the @script.
2197 hb_ot_layout_baseline_tag_t
2198 hb_ot_layout_get_horizontal_baseline_tag_for_script (hb_script_t script)
2200 /* Keep in sync with hb_ot_layout_get_baseline_with_fallback */
2201 switch ((int) script)
2203 /* Unicode-1.1 additions */
2204 case HB_SCRIPT_BENGALI:
2205 case HB_SCRIPT_DEVANAGARI:
2206 case HB_SCRIPT_GUJARATI:
2207 case HB_SCRIPT_GURMUKHI:
2208 /* Unicode-2.0 additions */
2209 case HB_SCRIPT_TIBETAN:
2210 /* Unicode-4.0 additions */
2211 case HB_SCRIPT_LIMBU:
2212 /* Unicode-4.1 additions */
2213 case HB_SCRIPT_SYLOTI_NAGRI:
2214 /* Unicode-5.0 additions */
2215 case HB_SCRIPT_PHAGS_PA:
2216 /* Unicode-5.2 additions */
2217 case HB_SCRIPT_MEETEI_MAYEK:
2218 /* Unicode-6.1 additions */
2219 case HB_SCRIPT_SHARADA:
2220 case HB_SCRIPT_TAKRI:
2221 /* Unicode-7.0 additions */
2222 case HB_SCRIPT_MODI:
2223 case HB_SCRIPT_SIDDHAM:
2224 case HB_SCRIPT_TIRHUTA:
2225 /* Unicode-9.0 additions */
2226 case HB_SCRIPT_MARCHEN:
2227 case HB_SCRIPT_NEWA:
2228 /* Unicode-10.0 additions */
2229 case HB_SCRIPT_SOYOMBO:
2230 case HB_SCRIPT_ZANABAZAR_SQUARE:
2231 /* Unicode-11.0 additions */
2232 case HB_SCRIPT_DOGRA:
2233 case HB_SCRIPT_GUNJALA_GONDI:
2234 /* Unicode-12.0 additions */
2235 case HB_SCRIPT_NANDINAGARI:
2236 return HB_OT_LAYOUT_BASELINE_TAG_HANGING;
2238 /* Unicode-1.1 additions */
2239 case HB_SCRIPT_HANGUL:
2241 case HB_SCRIPT_HIRAGANA:
2242 case HB_SCRIPT_KATAKANA:
2243 /* Unicode-3.0 additions */
2244 case HB_SCRIPT_BOPOMOFO:
2245 /* Unicode-9.0 additions */
2246 case HB_SCRIPT_TANGUT:
2247 /* Unicode-10.0 additions */
2248 case HB_SCRIPT_NUSHU:
2249 /* Unicode-13.0 additions */
2250 case HB_SCRIPT_KHITAN_SMALL_SCRIPT:
2251 return HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT;
2254 return HB_OT_LAYOUT_BASELINE_TAG_ROMAN;
2259 * hb_ot_layout_get_baseline:
2261 * @baseline_tag: a baseline tag
2262 * @direction: text direction.
2263 * @script_tag: script tag.
2264 * @language_tag: language tag, currently unused.
2265 * @coord: (out) (nullable): baseline value if found.
2267 * Fetches a baseline value from the face.
2269 * Return value: `true` if found baseline value in the font.
2274 hb_ot_layout_get_baseline (hb_font_t *font,
2275 hb_ot_layout_baseline_tag_t baseline_tag,
2276 hb_direction_t direction,
2277 hb_tag_t script_tag,
2278 hb_tag_t language_tag,
2279 hb_position_t *coord /* OUT. May be NULL. */)
2281 return font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord);
2285 * hb_ot_layout_get_baseline2:
2287 * @baseline_tag: a baseline tag
2288 * @direction: text direction.
2290 * @language: (nullable): language, currently unused.
2291 * @coord: (out) (nullable): baseline value if found.
2293 * Fetches a baseline value from the face.
2295 * This function is like hb_ot_layout_get_baseline() but takes
2296 * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t.
2298 * Return value: `true` if found baseline value in the font.
2303 hb_ot_layout_get_baseline2 (hb_font_t *font,
2304 hb_ot_layout_baseline_tag_t baseline_tag,
2305 hb_direction_t direction,
2307 hb_language_t language,
2308 hb_position_t *coord /* OUT. May be NULL. */)
2310 hb_tag_t script_tag, language_tag;
2311 choose_base_tags (script, language, &script_tag, &language_tag);
2312 return hb_ot_layout_get_baseline (font,
2321 * hb_ot_layout_get_baseline_with_fallback:
2323 * @baseline_tag: a baseline tag
2324 * @direction: text direction.
2325 * @script_tag: script tag.
2326 * @language_tag: language tag, currently unused.
2327 * @coord: (out): baseline value if found.
2329 * Fetches a baseline value from the face, and synthesizes
2330 * it if the font does not have it.
2335 hb_ot_layout_get_baseline_with_fallback (hb_font_t *font,
2336 hb_ot_layout_baseline_tag_t baseline_tag,
2337 hb_direction_t direction,
2338 hb_tag_t script_tag,
2339 hb_tag_t language_tag,
2340 hb_position_t *coord /* OUT */)
2342 if (hb_ot_layout_get_baseline (font,
2350 /* Synthesize missing baselines.
2351 * See https://www.w3.org/TR/css-inline-3/#baseline-synthesis-fonts
2353 switch (baseline_tag)
2355 case HB_OT_LAYOUT_BASELINE_TAG_ROMAN:
2356 *coord = 0; // FIXME origin ?
2359 case HB_OT_LAYOUT_BASELINE_TAG_MATH:
2361 hb_codepoint_t glyph;
2362 hb_glyph_extents_t extents;
2363 if (HB_DIRECTION_IS_HORIZONTAL (direction) &&
2364 (hb_font_get_nominal_glyph (font, 0x2212u, &glyph) ||
2365 hb_font_get_nominal_glyph (font, '-', &glyph)) &&
2366 hb_font_get_glyph_extents (font, glyph, &extents))
2368 *coord = extents.y_bearing + extents.height / 2;
2372 hb_position_t x_height = font->y_scale / 2;
2373 #ifndef HB_NO_METRICS
2374 hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_X_HEIGHT, &x_height);
2376 *coord = x_height / 2;
2381 case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT:
2382 case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT:
2384 hb_position_t embox_top, embox_bottom;
2386 hb_ot_layout_get_baseline_with_fallback (font,
2387 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT,
2392 hb_ot_layout_get_baseline_with_fallback (font,
2393 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT,
2399 if (baseline_tag == HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT)
2400 *coord = embox_top + (embox_bottom - embox_top) / 10;
2402 *coord = embox_bottom + (embox_top - embox_bottom) / 10;
2406 case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT:
2407 if (hb_ot_layout_get_baseline (font,
2408 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT,
2413 *coord += HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale;
2416 hb_font_extents_t font_extents;
2417 hb_font_get_extents_for_direction (font, direction, &font_extents);
2418 *coord = font_extents.ascender;
2422 case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT:
2423 if (hb_ot_layout_get_baseline (font,
2424 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT,
2429 *coord -= HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale;
2432 hb_font_extents_t font_extents;
2433 hb_font_get_extents_for_direction (font, direction, &font_extents);
2434 *coord = font_extents.descender;
2438 case HB_OT_LAYOUT_BASELINE_TAG_HANGING:
2439 if (HB_DIRECTION_IS_HORIZONTAL (direction))
2442 hb_codepoint_t glyph;
2443 hb_glyph_extents_t extents;
2445 /* Keep in sync with hb_ot_layout_get_horizontal_baseline_for_script */
2446 switch ((int) script_tag)
2448 /* Unicode-1.1 additions */
2449 case HB_SCRIPT_BENGALI: ch = 0x0995u; break;
2450 case HB_SCRIPT_DEVANAGARI: ch = 0x0915u; break;
2451 case HB_SCRIPT_GUJARATI: ch = 0x0a95u; break;
2452 case HB_SCRIPT_GURMUKHI: ch = 0x0a15u; break;
2453 /* Unicode-2.0 additions */
2454 case HB_SCRIPT_TIBETAN: ch = 0x0f40u; break;
2455 /* Unicode-4.0 additions */
2456 case HB_SCRIPT_LIMBU: ch = 0x1901u; break;
2457 /* Unicode-4.1 additions */
2458 case HB_SCRIPT_SYLOTI_NAGRI: ch = 0xa807u; break;
2459 /* Unicode-5.0 additions */
2460 case HB_SCRIPT_PHAGS_PA: ch = 0xa840u; break;
2461 /* Unicode-5.2 additions */
2462 case HB_SCRIPT_MEETEI_MAYEK: ch = 0xabc0u; break;
2463 /* Unicode-6.1 additions */
2464 case HB_SCRIPT_SHARADA: ch = 0x11191u; break;
2465 case HB_SCRIPT_TAKRI: ch = 0x1168cu; break;
2466 /* Unicode-7.0 additions */
2467 case HB_SCRIPT_MODI: ch = 0x1160eu;break;
2468 case HB_SCRIPT_SIDDHAM: ch = 0x11590u; break;
2469 case HB_SCRIPT_TIRHUTA: ch = 0x1148fu; break;
2470 /* Unicode-9.0 additions */
2471 case HB_SCRIPT_MARCHEN: ch = 0x11c72u; break;
2472 case HB_SCRIPT_NEWA: ch = 0x1140eu; break;
2473 /* Unicode-10.0 additions */
2474 case HB_SCRIPT_SOYOMBO: ch = 0x11a5cu; break;
2475 case HB_SCRIPT_ZANABAZAR_SQUARE: ch = 0x11a0bu; break;
2476 /* Unicode-11.0 additions */
2477 case HB_SCRIPT_DOGRA: ch = 0x1180au; break;
2478 case HB_SCRIPT_GUNJALA_GONDI: ch = 0x11d6cu; break;
2479 /* Unicode-12.0 additions */
2480 case HB_SCRIPT_NANDINAGARI: ch = 0x119b0u; break;
2481 default: ch = 0; break;
2485 hb_font_get_nominal_glyph (font, ch, &glyph) &&
2486 hb_font_get_glyph_extents (font, glyph, &extents))
2487 *coord = extents.y_bearing;
2489 *coord = font->y_scale * 6 / 10; // FIXME makes assumptions about origin
2492 *coord = font->x_scale * 6 / 10; // FIXME makes assumptions about origin
2495 case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL:
2497 hb_position_t top, bottom;
2498 hb_ot_layout_get_baseline_with_fallback (font,
2499 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT,
2504 hb_ot_layout_get_baseline_with_fallback (font,
2505 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT,
2510 *coord = (top + bottom) / 2;
2515 case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL:
2517 hb_position_t top, bottom;
2518 hb_ot_layout_get_baseline_with_fallback (font,
2519 HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT,
2524 hb_ot_layout_get_baseline_with_fallback (font,
2525 HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT,
2530 *coord = (top + bottom) / 2;
2535 case _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE:
2543 * hb_ot_layout_get_baseline_with_fallback2:
2545 * @baseline_tag: a baseline tag
2546 * @direction: text direction.
2548 * @language: (nullable): language, currently unused.
2549 * @coord: (out): baseline value if found.
2551 * Fetches a baseline value from the face, and synthesizes
2552 * it if the font does not have it.
2554 * This function is like hb_ot_layout_get_baseline_with_fallback() but takes
2555 * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t.
2560 hb_ot_layout_get_baseline_with_fallback2 (hb_font_t *font,
2561 hb_ot_layout_baseline_tag_t baseline_tag,
2562 hb_direction_t direction,
2564 hb_language_t language,
2565 hb_position_t *coord /* OUT */)
2567 hb_tag_t script_tag, language_tag;
2568 choose_base_tags (script, language, &script_tag, &language_tag);
2569 hb_ot_layout_get_baseline_with_fallback (font,
2580 struct hb_get_glyph_alternates_dispatch_t :
2581 hb_dispatch_context_t<hb_get_glyph_alternates_dispatch_t, unsigned>
2583 static return_t default_return_value () { return 0; }
2584 bool stop_sublookup_iteration (return_t r) const { return r; }
2587 template <typename T, typename ...Ts> auto
2588 _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN
2589 ( obj.get_glyph_alternates (std::forward<Ts> (ds)...) )
2590 template <typename T, typename ...Ts> auto
2591 _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN
2592 ( default_return_value () )
2594 template <typename T, typename ...Ts> auto
2595 dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
2596 ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) )
2599 #ifndef HB_NO_LAYOUT_RARELY_USED
2601 * hb_ot_layout_lookup_get_glyph_alternates:
2603 * @lookup_index: index of the feature lookup to query.
2604 * @glyph: a glyph id.
2605 * @start_offset: starting offset.
2606 * @alternate_count: (inout) (optional): Input = the maximum number of alternate glyphs to return;
2607 * Output = the actual number of alternate glyphs returned (may be zero).
2608 * @alternate_glyphs: (out caller-allocates) (array length=alternate_count): A glyphs buffer.
2609 * Alternate glyphs associated with the glyph id.
2611 * Fetches alternates of a glyph from a given GSUB lookup index.
2613 * Return value: Total number of alternates found in the specific lookup index for the given glyph id.
2618 hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face,
2619 unsigned lookup_index,
2620 hb_codepoint_t glyph,
2621 unsigned start_offset,
2622 unsigned *alternate_count /* IN/OUT. May be NULL. */,
2623 hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */)
2625 hb_get_glyph_alternates_dispatch_t c;
2626 const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index);
2627 auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs);
2628 if (!ret && alternate_count) *alternate_count = 0;
2633 struct hb_position_single_dispatch_t :
2634 hb_dispatch_context_t<hb_position_single_dispatch_t, bool>
2636 static return_t default_return_value () { return false; }
2637 bool stop_sublookup_iteration (return_t r) const { return r; }
2640 template <typename T, typename ...Ts> auto
2641 _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN
2642 ( obj.position_single (std::forward<Ts> (ds)...) )
2643 template <typename T, typename ...Ts> auto
2644 _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN
2645 ( default_return_value () )
2647 template <typename T, typename ...Ts> auto
2648 dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
2649 ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) )
2653 * hb_ot_layout_lookup_get_optical_bound:
2655 * @lookup_index: index of the feature lookup to query.
2656 * @direction: edge of the glyph to query.
2657 * @glyph: a glyph id.
2659 * Fetches the optical bound of a glyph positioned at the margin of text.
2660 * The direction identifies which edge of the glyph to query.
2662 * Return value: Adjustment value. Negative values mean the glyph will stick out of the margin.
2667 hb_ot_layout_lookup_get_optical_bound (hb_font_t *font,
2668 unsigned lookup_index,
2669 hb_direction_t direction,
2670 hb_codepoint_t glyph)
2672 const OT::PosLookup &lookup = font->face->table.GPOS->table->get_lookup (lookup_index);
2673 hb_blob_t *blob = font->face->table.GPOS->get_blob ();
2674 hb_glyph_position_t pos = {0};
2675 hb_position_single_dispatch_t c;
2676 lookup.dispatch (&c, font, blob, direction, glyph, pos);
2677 hb_position_t ret = 0;
2680 case HB_DIRECTION_LTR:
2683 case HB_DIRECTION_RTL:
2684 ret = pos.x_advance - pos.x_offset;
2686 case HB_DIRECTION_TTB:
2689 case HB_DIRECTION_BTT:
2690 ret = pos.y_advance - pos.y_offset;
2692 case HB_DIRECTION_INVALID: