| 1 | /* |
| 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. |
| 6 | * |
| 7 | * This is part of HarfBuzz, a text shaping library. |
| 8 | * |
| 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. |
| 14 | * |
| 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 |
| 19 | * DAMAGE. |
| 20 | * |
| 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. |
| 26 | * |
| 27 | * Red Hat Author(s): Behdad Esfahbod |
| 28 | * Google Author(s): Behdad Esfahbod |
| 29 | */ |
| 30 | |
| 31 | #include "hb.hh" |
| 32 | |
| 33 | #ifndef HB_NO_OT_LAYOUT |
| 34 | |
| 35 | #ifdef HB_NO_OT_TAG |
| 36 | #error "Cannot compile hb-ot-layout.cc with HB_NO_OT_TAG." |
| 37 | #endif |
| 38 | |
| 39 | #include "hb-open-type.hh" |
| 40 | #include "hb-ot-layout.hh" |
| 41 | #include "hb-ot-face.hh" |
| 42 | #include "hb-ot-map.hh" |
| 43 | #include "hb-map.hh" |
| 44 | |
| 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" |
| 53 | |
| 54 | #include "hb-aat-layout-morx-table.hh" |
| 55 | #include "hb-aat-layout-opbd-table.hh" // Just so we compile it; unused otherwise. |
| 56 | |
| 57 | using OT::Layout::GSUB; |
| 58 | using OT::Layout::GPOS; |
| 59 | |
| 60 | /** |
| 61 | * SECTION:hb-ot-layout |
| 62 | * @title: hb-ot-layout |
| 63 | * @short_description: OpenType Layout |
| 64 | * @include: hb-ot.h |
| 65 | * |
| 66 | * Functions for querying OpenType Layout features in the font face. |
| 67 | * See the [OpenType specification](http://www.microsoft.com/typography/otspec/) |
| 68 | * for details. |
| 69 | **/ |
| 70 | |
| 71 | |
| 72 | /* |
| 73 | * kern |
| 74 | */ |
| 75 | |
| 76 | #ifndef HB_NO_OT_KERN |
| 77 | /** |
| 78 | * hb_ot_layout_has_kerning: |
| 79 | * @face: The #hb_face_t to work on |
| 80 | * |
| 81 | * Tests whether a face includes any kerning data in the 'kern' table. |
| 82 | * Does NOT test for kerning lookups in the GPOS table. |
| 83 | * |
| 84 | * Return value: `true` if data found, `false` otherwise |
| 85 | * |
| 86 | **/ |
| 87 | bool |
| 88 | hb_ot_layout_has_kerning (hb_face_t *face) |
| 89 | { |
| 90 | return face->table.kern->has_data (); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * hb_ot_layout_has_machine_kerning: |
| 95 | * @face: The #hb_face_t to work on |
| 96 | * |
| 97 | * Tests whether a face includes any state-machine kerning in the 'kern' table. |
| 98 | * Does NOT examine the GPOS table. |
| 99 | * |
| 100 | * Return value: `true` if data found, `false` otherwise |
| 101 | * |
| 102 | **/ |
| 103 | bool |
| 104 | hb_ot_layout_has_machine_kerning (hb_face_t *face) |
| 105 | { |
| 106 | return face->table.kern->has_state_machine (); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * hb_ot_layout_has_cross_kerning: |
| 111 | * @face: The #hb_face_t to work on |
| 112 | * |
| 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. |
| 117 | * |
| 118 | * Does NOT examine the GPOS table. |
| 119 | * |
| 120 | * Return value: `true` is data found, `false` otherwise |
| 121 | * |
| 122 | **/ |
| 123 | bool |
| 124 | hb_ot_layout_has_cross_kerning (hb_face_t *face) |
| 125 | { |
| 126 | return face->table.kern->has_cross_stream (); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | hb_ot_layout_kern (const hb_ot_shape_plan_t *plan, |
| 131 | hb_font_t *font, |
| 132 | hb_buffer_t *buffer) |
| 133 | { |
| 134 | hb_blob_t *blob = font->face->table.kern.get_blob (); |
| 135 | const AAT::kern& kern = *blob->as<AAT::kern> (); |
| 136 | |
| 137 | AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); |
| 138 | |
| 139 | if (!buffer->message (font, "start table kern" )) return; |
| 140 | kern.apply (&c); |
| 141 | (void) buffer->message (font, "end table kern" ); |
| 142 | } |
| 143 | #endif |
| 144 | |
| 145 | |
| 146 | /* |
| 147 | * GDEF |
| 148 | */ |
| 149 | |
| 150 | bool |
| 151 | OT::GDEF::is_blocklisted (hb_blob_t *blob, |
| 152 | hb_face_t *face) const |
| 153 | { |
| 154 | #ifdef HB_NO_OT_LAYOUT_BLOCKLIST |
| 155 | return false; |
| 156 | #endif |
| 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 |
| 160 | * |
| 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. |
| 167 | * |
| 168 | * Nuke the GDEF tables of to avoid unwanted width-zeroing. |
| 169 | * |
| 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 |
| 173 | */ |
| 174 | switch HB_CODEPOINT_ENCODE3(blob->length, |
| 175 | face->table.GSUB->table.get_length (), |
| 176 | face->table.GPOS->table.get_length ()) |
| 177 | { |
| 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): |
| 249 | return true; |
| 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | static void |
| 255 | _hb_ot_layout_set_glyph_props (hb_font_t *font, |
| 256 | hb_buffer_t *buffer) |
| 257 | { |
| 258 | _hb_buffer_assert_gsubgpos_vars (buffer); |
| 259 | |
| 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++) |
| 264 | { |
| 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]); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /* Public API */ |
| 271 | |
| 272 | /** |
| 273 | * hb_ot_layout_has_glyph_classes: |
| 274 | * @face: #hb_face_t to work upon |
| 275 | * |
| 276 | * Tests whether a face has any glyph classes defined in its GDEF table. |
| 277 | * |
| 278 | * Return value: `true` if data found, `false` otherwise |
| 279 | * |
| 280 | **/ |
| 281 | hb_bool_t |
| 282 | hb_ot_layout_has_glyph_classes (hb_face_t *face) |
| 283 | { |
| 284 | return face->table.GDEF->table->has_glyph_classes (); |
| 285 | } |
| 286 | |
| 287 | /** |
| 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 |
| 291 | * |
| 292 | * Fetches the GDEF class of the requested glyph in the specified face. |
| 293 | * |
| 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. |
| 296 | * |
| 297 | * Since: 0.9.7 |
| 298 | **/ |
| 299 | hb_ot_layout_glyph_class_t |
| 300 | hb_ot_layout_get_glyph_class (hb_face_t *face, |
| 301 | hb_codepoint_t glyph) |
| 302 | { |
| 303 | return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph); |
| 304 | } |
| 305 | |
| 306 | /** |
| 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 |
| 311 | * class. |
| 312 | * |
| 313 | * Retrieves the set of all glyphs from the face that belong to the requested |
| 314 | * glyph class in the face's GDEF table. |
| 315 | * |
| 316 | * Since: 0.9.7 |
| 317 | **/ |
| 318 | void |
| 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 */) |
| 322 | { |
| 323 | return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs); |
| 324 | } |
| 325 | |
| 326 | #ifndef HB_NO_LAYOUT_UNUSED |
| 327 | /** |
| 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 |
| 335 | * |
| 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. |
| 338 | * |
| 339 | * Useful if the client program wishes to cache the list. |
| 340 | * |
| 341 | * Return value: Total number of attachment points for @glyph. |
| 342 | * |
| 343 | **/ |
| 344 | unsigned int |
| 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 */) |
| 350 | { |
| 351 | return face->table.GDEF->table->get_attach_points (glyph, |
| 352 | start_offset, |
| 353 | point_count, |
| 354 | point_array); |
| 355 | } |
| 356 | /** |
| 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 |
| 365 | * |
| 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. |
| 368 | * |
| 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. |
| 372 | * |
| 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. |
| 375 | * |
| 376 | * Return value: Total number of ligature caret positions for @glyph. |
| 377 | * |
| 378 | **/ |
| 379 | unsigned int |
| 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 */) |
| 386 | { |
| 387 | return font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); |
| 388 | } |
| 389 | #endif |
| 390 | |
| 391 | |
| 392 | /* |
| 393 | * GSUB/GPOS |
| 394 | */ |
| 395 | |
| 396 | bool |
| 397 | GSUB::is_blocklisted (hb_blob_t *blob HB_UNUSED, |
| 398 | hb_face_t *face) const |
| 399 | { |
| 400 | #ifdef HB_NO_OT_LAYOUT_BLOCKLIST |
| 401 | return false; |
| 402 | #endif |
| 403 | return false; |
| 404 | } |
| 405 | |
| 406 | bool |
| 407 | GPOS::is_blocklisted (hb_blob_t *blob HB_UNUSED, |
| 408 | hb_face_t *face HB_UNUSED) const |
| 409 | { |
| 410 | #ifdef HB_NO_OT_LAYOUT_BLOCKLIST |
| 411 | return false; |
| 412 | #endif |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | static const OT::GSUBGPOS& |
| 417 | get_gsubgpos_table (hb_face_t *face, |
| 418 | hb_tag_t table_tag) |
| 419 | { |
| 420 | switch (table_tag) { |
| 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); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | |
| 428 | /** |
| 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 |
| 436 | * |
| 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. |
| 439 | * |
| 440 | * Return value: Total number of script tags. |
| 441 | * |
| 442 | **/ |
| 443 | unsigned int |
| 444 | hb_ot_layout_table_get_script_tags (hb_face_t *face, |
| 445 | hb_tag_t table_tag, |
| 446 | unsigned int start_offset, |
| 447 | unsigned int *script_count /* IN/OUT */, |
| 448 | hb_tag_t *script_tags /* OUT */) |
| 449 | { |
| 450 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 451 | |
| 452 | return g.get_script_tags (start_offset, script_count, script_tags); |
| 453 | } |
| 454 | |
| 455 | #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
| 456 | |
| 457 | /** |
| 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 |
| 463 | * |
| 464 | * Fetches the index if a given script tag in the specified face's GSUB table |
| 465 | * or GPOS table. |
| 466 | * |
| 467 | * Return value: `true` if the script is found, `false` otherwise |
| 468 | * |
| 469 | **/ |
| 470 | hb_bool_t |
| 471 | hb_ot_layout_table_find_script (hb_face_t *face, |
| 472 | hb_tag_t table_tag, |
| 473 | hb_tag_t script_tag, |
| 474 | unsigned int *script_index /* OUT */) |
| 475 | { |
| 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); |
| 478 | |
| 479 | if (g.find_script_index (script_tag, script_index)) |
| 480 | return true; |
| 481 | |
| 482 | /* try finding 'DFLT' */ |
| 483 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) |
| 484 | return false; |
| 485 | |
| 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)) |
| 489 | return false; |
| 490 | |
| 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)) |
| 494 | return false; |
| 495 | |
| 496 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | #ifndef HB_DISABLE_DEPRECATED |
| 501 | /** |
| 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 |
| 508 | * |
| 509 | * Deprecated since 2.0.0 |
| 510 | **/ |
| 511 | hb_bool_t |
| 512 | hb_ot_layout_table_choose_script (hb_face_t *face, |
| 513 | hb_tag_t table_tag, |
| 514 | const hb_tag_t *script_tags, |
| 515 | unsigned int *script_index /* OUT */, |
| 516 | hb_tag_t *chosen_script /* OUT */) |
| 517 | { |
| 518 | const hb_tag_t *t; |
| 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); |
| 521 | } |
| 522 | #endif |
| 523 | |
| 524 | /** |
| 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 |
| 532 | * |
| 533 | * Selects an OpenType script for @table_tag from the @script_tags array. |
| 534 | * |
| 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. |
| 539 | * |
| 540 | * Return value: |
| 541 | * `true` if one of the requested scripts is selected, `false` if a fallback |
| 542 | * script is selected or if no scripts are selected. |
| 543 | * |
| 544 | * Since: 2.0.0 |
| 545 | **/ |
| 546 | hb_bool_t |
| 547 | hb_ot_layout_table_select_script (hb_face_t *face, |
| 548 | hb_tag_t table_tag, |
| 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 */) |
| 553 | { |
| 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); |
| 556 | unsigned int i; |
| 557 | |
| 558 | for (i = 0; i < script_count; i++) |
| 559 | { |
| 560 | if (g.find_script_index (script_tags[i], script_index)) |
| 561 | { |
| 562 | if (chosen_script) |
| 563 | *chosen_script = script_tags[i]; |
| 564 | return true; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | /* try finding 'DFLT' */ |
| 569 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
| 570 | if (chosen_script) |
| 571 | *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
| 572 | return false; |
| 573 | } |
| 574 | |
| 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)) { |
| 577 | if (chosen_script) |
| 578 | *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
| 579 | return false; |
| 580 | } |
| 581 | |
| 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)) { |
| 585 | if (chosen_script) |
| 586 | *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
| 591 | if (chosen_script) |
| 592 | *chosen_script = HB_TAG_NONE; |
| 593 | return false; |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /** |
| 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 |
| 605 | * |
| 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. |
| 609 | * |
| 610 | * Return value: Total number of feature tags. |
| 611 | * |
| 612 | * Since: 0.6.0 |
| 613 | * |
| 614 | **/ |
| 615 | unsigned int |
| 616 | hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
| 617 | hb_tag_t table_tag, |
| 618 | unsigned int start_offset, |
| 619 | unsigned int *feature_count /* IN/OUT */, |
| 620 | hb_tag_t *feature_tags /* OUT */) |
| 621 | { |
| 622 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 623 | |
| 624 | return g.get_feature_tags (start_offset, feature_count, feature_tags); |
| 625 | } |
| 626 | |
| 627 | |
| 628 | /** |
| 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 |
| 634 | * |
| 635 | * Fetches the index for a given feature tag in the specified face's GSUB table |
| 636 | * or GPOS table. |
| 637 | * |
| 638 | * Return value: `true` if the feature is found, `false` otherwise |
| 639 | * |
| 640 | * Since: 0.6.0 |
| 641 | * |
| 642 | **/ |
| 643 | bool |
| 644 | hb_ot_layout_table_find_feature (hb_face_t *face, |
| 645 | hb_tag_t table_tag, |
| 646 | hb_tag_t feature_tag, |
| 647 | unsigned int *feature_index /* OUT */) |
| 648 | { |
| 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); |
| 651 | |
| 652 | unsigned int num_features = g.get_feature_count (); |
| 653 | for (unsigned int i = 0; i < num_features; i++) |
| 654 | { |
| 655 | if (feature_tag == g.get_feature_tag (i)) { |
| 656 | if (feature_index) *feature_index = i; |
| 657 | return true; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
| 662 | return false; |
| 663 | } |
| 664 | |
| 665 | |
| 666 | /** |
| 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 |
| 675 | * |
| 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. |
| 678 | * |
| 679 | * Return value: Total number of language tags. |
| 680 | * |
| 681 | * Since: 0.6.0 |
| 682 | * |
| 683 | **/ |
| 684 | unsigned int |
| 685 | hb_ot_layout_script_get_language_tags (hb_face_t *face, |
| 686 | hb_tag_t table_tag, |
| 687 | unsigned int script_index, |
| 688 | unsigned int start_offset, |
| 689 | unsigned int *language_count /* IN/OUT */, |
| 690 | hb_tag_t *language_tags /* OUT */) |
| 691 | { |
| 692 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
| 693 | |
| 694 | return s.get_lang_sys_tags (start_offset, language_count, language_tags); |
| 695 | } |
| 696 | |
| 697 | |
| 698 | #ifndef HB_DISABLE_DEPRECATED |
| 699 | /** |
| 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 |
| 706 | * |
| 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. |
| 709 | * |
| 710 | * Return value: `true` if the language tag is found, `false` otherwise |
| 711 | * |
| 712 | * Since: 0.6.0 |
| 713 | * Deprecated: 2.0.0 |
| 714 | **/ |
| 715 | hb_bool_t |
| 716 | hb_ot_layout_script_find_language (hb_face_t *face, |
| 717 | hb_tag_t table_tag, |
| 718 | unsigned int script_index, |
| 719 | hb_tag_t language_tag, |
| 720 | unsigned int *language_index) |
| 721 | { |
| 722 | return hb_ot_layout_script_select_language (face, |
| 723 | table_tag, |
| 724 | script_index, |
| 725 | 1, |
| 726 | &language_tag, |
| 727 | language_index); |
| 728 | } |
| 729 | #endif |
| 730 | |
| 731 | |
| 732 | /** |
| 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 |
| 741 | * |
| 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 |
| 744 | * index. |
| 745 | * |
| 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. |
| 749 | * |
| 750 | * Return value: `true` if one of the given language tags is found, `false` otherwise |
| 751 | * |
| 752 | * Since: 7.0.0 |
| 753 | **/ |
| 754 | hb_bool_t |
| 755 | hb_ot_layout_script_select_language2 (hb_face_t *face, |
| 756 | hb_tag_t table_tag, |
| 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 */) |
| 762 | { |
| 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); |
| 765 | unsigned int i; |
| 766 | |
| 767 | for (i = 0; i < language_count; i++) |
| 768 | { |
| 769 | if (s.find_lang_sys_index (language_tags[i], language_index)) |
| 770 | { |
| 771 | if (chosen_language) |
| 772 | *chosen_language = language_tags[i]; |
| 773 | return true; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | /* try finding 'dflt' */ |
| 778 | if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index)) |
| 779 | { |
| 780 | if (chosen_language) |
| 781 | *chosen_language = HB_OT_TAG_DEFAULT_LANGUAGE; |
| 782 | return false; |
| 783 | } |
| 784 | |
| 785 | if (language_index) |
| 786 | *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
| 787 | if (chosen_language) |
| 788 | *chosen_language = HB_TAG_NONE; |
| 789 | return false; |
| 790 | } |
| 791 | |
| 792 | /** |
| 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 |
| 800 | * |
| 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 |
| 803 | * index. |
| 804 | * |
| 805 | * If none of the given language tags is found, `false` is returned and |
| 806 | * @language_index is set to the default language index. |
| 807 | * |
| 808 | * Return value: `true` if one of the given language tags is found, `false` otherwise |
| 809 | * |
| 810 | * Since: 2.0.0 |
| 811 | **/ |
| 812 | hb_bool_t |
| 813 | hb_ot_layout_script_select_language (hb_face_t *face, |
| 814 | hb_tag_t table_tag, |
| 815 | unsigned int script_index, |
| 816 | unsigned int language_count, |
| 817 | const hb_tag_t *language_tags, |
| 818 | unsigned int *language_index /* OUT */) |
| 819 | { |
| 820 | return hb_ot_layout_script_select_language2 (face, table_tag, |
| 821 | script_index, |
| 822 | language_count, language_tags, |
| 823 | language_index, nullptr); |
| 824 | } |
| 825 | |
| 826 | /** |
| 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 |
| 833 | * |
| 834 | * Fetches the index of a requested feature in the given face's GSUB or GPOS table, |
| 835 | * underneath the specified script and language. |
| 836 | * |
| 837 | * Return value: `true` if the feature is found, `false` otherwise |
| 838 | * |
| 839 | * Since: 0.6.0 |
| 840 | * |
| 841 | **/ |
| 842 | hb_bool_t |
| 843 | hb_ot_layout_language_get_required_feature_index (hb_face_t *face, |
| 844 | hb_tag_t table_tag, |
| 845 | unsigned int script_index, |
| 846 | unsigned int language_index, |
| 847 | unsigned int *feature_index /* OUT */) |
| 848 | { |
| 849 | return hb_ot_layout_language_get_required_feature (face, |
| 850 | table_tag, |
| 851 | script_index, |
| 852 | language_index, |
| 853 | feature_index, |
| 854 | nullptr); |
| 855 | } |
| 856 | |
| 857 | |
| 858 | /** |
| 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 |
| 866 | * |
| 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. |
| 869 | * |
| 870 | * Return value: `true` if the feature is found, `false` otherwise |
| 871 | * |
| 872 | * Since: 0.9.30 |
| 873 | **/ |
| 874 | hb_bool_t |
| 875 | hb_ot_layout_language_get_required_feature (hb_face_t *face, |
| 876 | hb_tag_t table_tag, |
| 877 | unsigned int script_index, |
| 878 | unsigned int language_index, |
| 879 | unsigned int *feature_index /* OUT */, |
| 880 | hb_tag_t *feature_tag /* OUT */) |
| 881 | { |
| 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); |
| 884 | |
| 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); |
| 888 | |
| 889 | return l.has_required_feature (); |
| 890 | } |
| 891 | |
| 892 | |
| 893 | /** |
| 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 |
| 903 | * |
| 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. |
| 907 | * |
| 908 | * Return value: Total number of features. |
| 909 | * |
| 910 | * Since: 0.6.0 |
| 911 | * |
| 912 | **/ |
| 913 | unsigned int |
| 914 | hb_ot_layout_language_get_feature_indexes (hb_face_t *face, |
| 915 | hb_tag_t table_tag, |
| 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 */) |
| 921 | { |
| 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); |
| 924 | |
| 925 | return l.get_feature_indexes (start_offset, feature_count, feature_indexes); |
| 926 | } |
| 927 | |
| 928 | |
| 929 | /** |
| 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 |
| 939 | * |
| 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. |
| 943 | * |
| 944 | * Return value: Total number of feature tags. |
| 945 | * |
| 946 | * Since: 0.6.0 |
| 947 | * |
| 948 | **/ |
| 949 | unsigned int |
| 950 | hb_ot_layout_language_get_feature_tags (hb_face_t *face, |
| 951 | hb_tag_t table_tag, |
| 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 */) |
| 957 | { |
| 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); |
| 960 | |
| 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); |
| 963 | |
| 964 | if (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]); |
| 968 | } |
| 969 | |
| 970 | return ret; |
| 971 | } |
| 972 | |
| 973 | |
| 974 | /** |
| 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 |
| 982 | * |
| 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. |
| 985 | * |
| 986 | * Return value: `true` if the feature is found, `false` otherwise |
| 987 | * |
| 988 | * Since: 0.6.0 |
| 989 | * |
| 990 | **/ |
| 991 | hb_bool_t |
| 992 | hb_ot_layout_language_find_feature (hb_face_t *face, |
| 993 | hb_tag_t table_tag, |
| 994 | unsigned int script_index, |
| 995 | unsigned int language_index, |
| 996 | hb_tag_t feature_tag, |
| 997 | unsigned int *feature_index /* OUT */) |
| 998 | { |
| 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); |
| 1002 | |
| 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); |
| 1006 | |
| 1007 | if (feature_tag == g.get_feature_tag (f_index)) { |
| 1008 | if (feature_index) *feature_index = f_index; |
| 1009 | return true; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | /** |
| 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 |
| 1027 | * |
| 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. |
| 1031 | * |
| 1032 | * Return value: Total number of lookups. |
| 1033 | * |
| 1034 | * Since: 0.9.7 |
| 1035 | **/ |
| 1036 | unsigned int |
| 1037 | hb_ot_layout_feature_get_lookups (hb_face_t *face, |
| 1038 | hb_tag_t table_tag, |
| 1039 | unsigned int feature_index, |
| 1040 | unsigned int start_offset, |
| 1041 | unsigned int *lookup_count /* IN/OUT */, |
| 1042 | unsigned int *lookup_indexes /* OUT */) |
| 1043 | { |
| 1044 | return hb_ot_layout_feature_with_variations_get_lookups (face, |
| 1045 | table_tag, |
| 1046 | feature_index, |
| 1047 | HB_OT_LAYOUT_NO_VARIATIONS_INDEX, |
| 1048 | start_offset, |
| 1049 | lookup_count, |
| 1050 | lookup_indexes); |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | /** |
| 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 |
| 1058 | * |
| 1059 | * Fetches the total number of lookups enumerated in the specified |
| 1060 | * face's GSUB table or GPOS table. |
| 1061 | * |
| 1062 | * Return value: Total number of lookups. |
| 1063 | * |
| 1064 | * Since: 0.9.22 |
| 1065 | **/ |
| 1066 | unsigned int |
| 1067 | hb_ot_layout_table_get_lookup_count (hb_face_t *face, |
| 1068 | hb_tag_t table_tag) |
| 1069 | { |
| 1070 | return get_gsubgpos_table (face, table_tag).get_lookup_count (); |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | struct hb_collect_features_context_t |
| 1075 | { |
| 1076 | hb_collect_features_context_t (hb_face_t *face, |
| 1077 | hb_tag_t table_tag, |
| 1078 | hb_set_t *feature_indices_, |
| 1079 | const hb_tag_t *features) |
| 1080 | |
| 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) |
| 1085 | { |
| 1086 | compute_feature_filter (features); |
| 1087 | } |
| 1088 | |
| 1089 | void compute_feature_filter (const hb_tag_t *features) |
| 1090 | { |
| 1091 | if (features == nullptr) |
| 1092 | { |
| 1093 | has_feature_filter = false; |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | has_feature_filter = true; |
| 1098 | hb_set_t features_set; |
| 1099 | for (; *features; features++) |
| 1100 | features_set.add (*features); |
| 1101 | |
| 1102 | for (unsigned i = 0; i < g.get_feature_count (); i++) |
| 1103 | { |
| 1104 | hb_tag_t tag = g.get_feature_tag (i); |
| 1105 | if (features_set.has (tag)) |
| 1106 | feature_indices_filter.add(i); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | bool visited (const OT::Script &s) |
| 1111 | { |
| 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 ())) |
| 1116 | return true; |
| 1117 | |
| 1118 | if (script_count++ > HB_MAX_SCRIPTS) |
| 1119 | return true; |
| 1120 | |
| 1121 | return visited (s, visited_script); |
| 1122 | } |
| 1123 | bool visited (const OT::LangSys &l) |
| 1124 | { |
| 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 ())) |
| 1129 | return true; |
| 1130 | |
| 1131 | if (langsys_count++ > HB_MAX_LANGSYS) |
| 1132 | return true; |
| 1133 | |
| 1134 | return visited (l, visited_langsys); |
| 1135 | } |
| 1136 | |
| 1137 | bool visited_feature_indices (unsigned count) |
| 1138 | { |
| 1139 | feature_index_count += count; |
| 1140 | return feature_index_count > HB_MAX_FEATURE_INDICES; |
| 1141 | } |
| 1142 | |
| 1143 | private: |
| 1144 | template <typename T> |
| 1145 | bool visited (const T &p, hb_set_t &visited_set) |
| 1146 | { |
| 1147 | hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g); |
| 1148 | if (visited_set.has (delta)) |
| 1149 | return true; |
| 1150 | |
| 1151 | visited_set.add (delta); |
| 1152 | return false; |
| 1153 | } |
| 1154 | |
| 1155 | public: |
| 1156 | const OT::GSUBGPOS &g; |
| 1157 | hb_set_t *feature_indices; |
| 1158 | hb_set_t feature_indices_filter; |
| 1159 | bool has_feature_filter; |
| 1160 | |
| 1161 | private: |
| 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; |
| 1167 | }; |
| 1168 | |
| 1169 | static void |
| 1170 | langsys_collect_features (hb_collect_features_context_t *c, |
| 1171 | const OT::LangSys &l) |
| 1172 | { |
| 1173 | if (c->visited (l)) return; |
| 1174 | |
| 1175 | if (!c->has_feature_filter) |
| 1176 | { |
| 1177 | /* All features. */ |
| 1178 | if (l.has_required_feature () && !c->visited_feature_indices (1)) |
| 1179 | c->feature_indices->add (l.get_required_feature_index ()); |
| 1180 | |
| 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); |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| 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++) |
| 1190 | { |
| 1191 | unsigned int feature_index = l.get_feature_index (i); |
| 1192 | if (!c->feature_indices_filter.has (feature_index)) continue; |
| 1193 | |
| 1194 | c->feature_indices->add (feature_index); |
| 1195 | c->feature_indices_filter.del (feature_index); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | static void |
| 1201 | script_collect_features (hb_collect_features_context_t *c, |
| 1202 | const OT::Script &s, |
| 1203 | const hb_tag_t *languages) |
| 1204 | { |
| 1205 | if (c->visited (s)) return; |
| 1206 | |
| 1207 | if (!languages) |
| 1208 | { |
| 1209 | /* All languages. */ |
| 1210 | if (s.has_default_lang_sys ()) |
| 1211 | langsys_collect_features (c, |
| 1212 | s.get_default_lang_sys ()); |
| 1213 | |
| 1214 | |
| 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)); |
| 1219 | } |
| 1220 | else |
| 1221 | { |
| 1222 | for (; *languages; languages++) |
| 1223 | { |
| 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)); |
| 1228 | |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | |
| 1234 | /** |
| 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 |
| 1245 | * |
| 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. |
| 1251 | * |
| 1252 | * Since: 1.8.5 |
| 1253 | **/ |
| 1254 | void |
| 1255 | hb_ot_layout_collect_features (hb_face_t *face, |
| 1256 | hb_tag_t table_tag, |
| 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 */) |
| 1261 | { |
| 1262 | hb_collect_features_context_t c (face, table_tag, feature_indexes, features); |
| 1263 | if (!scripts) |
| 1264 | { |
| 1265 | /* All scripts. */ |
| 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), |
| 1270 | languages); |
| 1271 | } |
| 1272 | else |
| 1273 | { |
| 1274 | for (; *scripts; scripts++) |
| 1275 | { |
| 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), |
| 1280 | languages); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 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. |
| 1292 | * |
| 1293 | * Fetches the mapping from feature tags to feature indexes for |
| 1294 | * the specified script and language. |
| 1295 | * |
| 1296 | * Since: 8.1.0 |
| 1297 | **/ |
| 1298 | void |
| 1299 | hb_ot_layout_collect_features_map (hb_face_t *face, |
| 1300 | hb_tag_t table_tag, |
| 1301 | unsigned script_index, |
| 1302 | unsigned language_index, |
| 1303 | hb_map_t *feature_map /* OUT */) |
| 1304 | { |
| 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); |
| 1307 | |
| 1308 | unsigned int count = l.get_feature_indexes (0, nullptr, nullptr); |
| 1309 | feature_map->alloc (count); |
| 1310 | |
| 1311 | for (unsigned int i = 0; i < count; i++) |
| 1312 | { |
| 1313 | unsigned feature_index = 0; |
| 1314 | unsigned feature_count = 1; |
| 1315 | l.get_feature_indexes (i, &feature_count, &feature_index); |
| 1316 | if (!feature_count) |
| 1317 | break; |
| 1318 | hb_tag_t feature_tag = g.get_feature_tag (feature_index); |
| 1319 | feature_map->set (feature_tag, feature_index); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | /** |
| 1325 | * hb_ot_layout_collect_lookups: |
| 1326 | * @face: #hb_face_t to work upon |
| 1327 | * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS |
| 1328 | * @scripts: (nullable) (array zero-terminated=1): The array of scripts to collect lookups for, |
| 1329 | * terminated by %HB_TAG_NONE |
| 1330 | * @languages: (nullable) (array zero-terminated=1): The array of languages to collect lookups for, |
| 1331 | * terminated by %HB_TAG_NONE |
| 1332 | * @features: (nullable) (array zero-terminated=1): The array of features to collect lookups for, |
| 1333 | * terminated by %HB_TAG_NONE |
| 1334 | * @lookup_indexes: (out): The array of lookup indexes found for the query |
| 1335 | * |
| 1336 | * Fetches a list of all feature-lookup indexes in the specified face's GSUB |
| 1337 | * table or GPOS table, underneath the specified scripts, languages, and |
| 1338 | * features. If no list of scripts is provided, all scripts will be queried. |
| 1339 | * If no list of languages is provided, all languages will be queried. If no |
| 1340 | * list of features is provided, all features will be queried. |
| 1341 | * |
| 1342 | * Since: 0.9.8 |
| 1343 | **/ |
| 1344 | void |
| 1345 | hb_ot_layout_collect_lookups (hb_face_t *face, |
| 1346 | hb_tag_t table_tag, |
| 1347 | const hb_tag_t *scripts, |
| 1348 | const hb_tag_t *languages, |
| 1349 | const hb_tag_t *features, |
| 1350 | hb_set_t *lookup_indexes /* OUT */) |
| 1351 | { |
| 1352 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1353 | |
| 1354 | hb_set_t feature_indexes; |
| 1355 | hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes); |
| 1356 | |
| 1357 | for (auto feature_index : feature_indexes) |
| 1358 | g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes); |
| 1359 | |
| 1360 | g.feature_variation_collect_lookups (&feature_indexes, nullptr, lookup_indexes); |
| 1361 | } |
| 1362 | |
| 1363 | |
| 1364 | #ifndef HB_NO_LAYOUT_COLLECT_GLYPHS |
| 1365 | /** |
| 1366 | * hb_ot_layout_lookup_collect_glyphs: |
| 1367 | * @face: #hb_face_t to work upon |
| 1368 | * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS |
| 1369 | * @lookup_index: The index of the feature lookup to query |
| 1370 | * @glyphs_before: (out): Array of glyphs preceding the substitution range |
| 1371 | * @glyphs_input: (out): Array of input glyphs that would be substituted by the lookup |
| 1372 | * @glyphs_after: (out): Array of glyphs following the substitution range |
| 1373 | * @glyphs_output: (out): Array of glyphs that would be the substituted output of the lookup |
| 1374 | * |
| 1375 | * Fetches a list of all glyphs affected by the specified lookup in the |
| 1376 | * specified face's GSUB table or GPOS table. |
| 1377 | * |
| 1378 | * Since: 0.9.7 |
| 1379 | **/ |
| 1380 | void |
| 1381 | hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, |
| 1382 | hb_tag_t table_tag, |
| 1383 | unsigned int lookup_index, |
| 1384 | hb_set_t *glyphs_before, /* OUT. May be NULL */ |
| 1385 | hb_set_t *glyphs_input, /* OUT. May be NULL */ |
| 1386 | hb_set_t *glyphs_after, /* OUT. May be NULL */ |
| 1387 | hb_set_t *glyphs_output /* OUT. May be NULL */) |
| 1388 | { |
| 1389 | OT::hb_collect_glyphs_context_t c (face, |
| 1390 | glyphs_before, |
| 1391 | glyphs_input, |
| 1392 | glyphs_after, |
| 1393 | glyphs_output); |
| 1394 | |
| 1395 | switch (table_tag) |
| 1396 | { |
| 1397 | case HB_OT_TAG_GSUB: |
| 1398 | { |
| 1399 | const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); |
| 1400 | l.collect_glyphs (&c); |
| 1401 | return; |
| 1402 | } |
| 1403 | case HB_OT_TAG_GPOS: |
| 1404 | { |
| 1405 | const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index); |
| 1406 | l.collect_glyphs (&c); |
| 1407 | return; |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | #endif |
| 1412 | |
| 1413 | |
| 1414 | /* Variations support */ |
| 1415 | |
| 1416 | |
| 1417 | /** |
| 1418 | * hb_ot_layout_table_find_feature_variations: |
| 1419 | * @face: #hb_face_t to work upon |
| 1420 | * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS |
| 1421 | * @coords: The variation coordinates to query |
| 1422 | * @num_coords: The number of variation coordinates |
| 1423 | * @variations_index: (out): The array of feature variations found for the query |
| 1424 | * |
| 1425 | * Fetches a list of feature variations in the specified face's GSUB table |
| 1426 | * or GPOS table, at the specified variation coordinates. |
| 1427 | * |
| 1428 | * Return value: `true` if feature variations were found, `false` otherwise. |
| 1429 | * |
| 1430 | * Since: 1.4.0 |
| 1431 | * |
| 1432 | **/ |
| 1433 | hb_bool_t |
| 1434 | hb_ot_layout_table_find_feature_variations (hb_face_t *face, |
| 1435 | hb_tag_t table_tag, |
| 1436 | const int *coords, |
| 1437 | unsigned int num_coords, |
| 1438 | unsigned int *variations_index /* out */) |
| 1439 | { |
| 1440 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1441 | |
| 1442 | return g.find_variations_index (coords, num_coords, variations_index); |
| 1443 | } |
| 1444 | |
| 1445 | |
| 1446 | /** |
| 1447 | * hb_ot_layout_feature_with_variations_get_lookups: |
| 1448 | * @face: #hb_face_t to work upon |
| 1449 | * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS |
| 1450 | * @feature_index: The index of the feature to query |
| 1451 | * @variations_index: The index of the feature variation to query |
| 1452 | * @start_offset: offset of the first lookup to retrieve |
| 1453 | * @lookup_count: (inout) (optional): Input = the maximum number of lookups to return; |
| 1454 | * Output = the actual number of lookups returned (may be zero) |
| 1455 | * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query |
| 1456 | * |
| 1457 | * Fetches a list of all lookups enumerated for the specified feature, in |
| 1458 | * the specified face's GSUB table or GPOS table, enabled at the specified |
| 1459 | * variations index. The list returned will begin at the offset provided. |
| 1460 | * |
| 1461 | * Return value: Total number of lookups. |
| 1462 | * |
| 1463 | * Since: 1.4.0 |
| 1464 | * |
| 1465 | **/ |
| 1466 | unsigned int |
| 1467 | hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, |
| 1468 | hb_tag_t table_tag, |
| 1469 | unsigned int feature_index, |
| 1470 | unsigned int variations_index, |
| 1471 | unsigned int start_offset, |
| 1472 | unsigned int *lookup_count /* IN/OUT */, |
| 1473 | unsigned int *lookup_indexes /* OUT */) |
| 1474 | { |
| 1475 | static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "" ); |
| 1476 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1477 | |
| 1478 | const OT::Feature &f = g.get_feature_variation (feature_index, variations_index); |
| 1479 | |
| 1480 | return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); |
| 1481 | } |
| 1482 | |
| 1483 | |
| 1484 | /* |
| 1485 | * OT::GSUB |
| 1486 | */ |
| 1487 | |
| 1488 | |
| 1489 | /** |
| 1490 | * hb_ot_layout_has_substitution: |
| 1491 | * @face: #hb_face_t to work upon |
| 1492 | * |
| 1493 | * Tests whether the specified face includes any GSUB substitutions. |
| 1494 | * |
| 1495 | * Return value: `true` if data found, `false` otherwise |
| 1496 | * |
| 1497 | * Since: 0.6.0 |
| 1498 | * |
| 1499 | **/ |
| 1500 | hb_bool_t |
| 1501 | hb_ot_layout_has_substitution (hb_face_t *face) |
| 1502 | { |
| 1503 | return face->table.GSUB->table->has_data (); |
| 1504 | } |
| 1505 | |
| 1506 | |
| 1507 | /** |
| 1508 | * hb_ot_layout_lookup_would_substitute: |
| 1509 | * @face: #hb_face_t to work upon |
| 1510 | * @lookup_index: The index of the lookup to query |
| 1511 | * @glyphs: The sequence of glyphs to query for substitution |
| 1512 | * @glyphs_length: The length of the glyph sequence |
| 1513 | * @zero_context: #hb_bool_t indicating whether pre-/post-context are disallowed |
| 1514 | * in substitutions |
| 1515 | * |
| 1516 | * Tests whether a specified lookup in the specified face would |
| 1517 | * trigger a substitution on the given glyph sequence. |
| 1518 | * |
| 1519 | * Return value: `true` if a substitution would be triggered, `false` otherwise |
| 1520 | * |
| 1521 | * Since: 0.9.7 |
| 1522 | **/ |
| 1523 | hb_bool_t |
| 1524 | hb_ot_layout_lookup_would_substitute (hb_face_t *face, |
| 1525 | unsigned int lookup_index, |
| 1526 | const hb_codepoint_t *glyphs, |
| 1527 | unsigned int glyphs_length, |
| 1528 | hb_bool_t zero_context) |
| 1529 | { |
| 1530 | auto &gsub = face->table.GSUB; |
| 1531 | if (unlikely (lookup_index >= gsub->lookup_count)) return false; |
| 1532 | OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context); |
| 1533 | |
| 1534 | const OT::SubstLookup& l = gsub->table->get_lookup (lookup_index); |
| 1535 | auto *accel = gsub->get_accel (lookup_index); |
| 1536 | return accel && l.would_apply (&c, accel); |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | /** |
| 1541 | * hb_ot_layout_substitute_start: |
| 1542 | * @font: #hb_font_t to use |
| 1543 | * @buffer: #hb_buffer_t buffer to work upon |
| 1544 | * |
| 1545 | * Called before substitution lookups are performed, to ensure that glyph |
| 1546 | * class and other properties are set on the glyphs in the buffer. |
| 1547 | * |
| 1548 | **/ |
| 1549 | void |
| 1550 | hb_ot_layout_substitute_start (hb_font_t *font, |
| 1551 | hb_buffer_t *buffer) |
| 1552 | { |
| 1553 | _hb_ot_layout_set_glyph_props (font, buffer); |
| 1554 | } |
| 1555 | |
| 1556 | /** |
| 1557 | * hb_ot_layout_lookup_substitute_closure: |
| 1558 | * @face: #hb_face_t to work upon |
| 1559 | * @lookup_index: index of the feature lookup to query |
| 1560 | * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup |
| 1561 | * |
| 1562 | * Compute the transitive closure of glyphs needed for a |
| 1563 | * specified lookup. |
| 1564 | * |
| 1565 | * Since: 0.9.7 |
| 1566 | **/ |
| 1567 | void |
| 1568 | hb_ot_layout_lookup_substitute_closure (hb_face_t *face, |
| 1569 | unsigned int lookup_index, |
| 1570 | hb_set_t *glyphs /* OUT */) |
| 1571 | { |
| 1572 | hb_map_t done_lookups_glyph_count; |
| 1573 | hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> done_lookups_glyph_set; |
| 1574 | OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set); |
| 1575 | |
| 1576 | const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); |
| 1577 | |
| 1578 | l.closure (&c, lookup_index); |
| 1579 | } |
| 1580 | |
| 1581 | /** |
| 1582 | * hb_ot_layout_lookups_substitute_closure: |
| 1583 | * @face: #hb_face_t to work upon |
| 1584 | * @lookups: The set of lookups to query |
| 1585 | * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups |
| 1586 | * |
| 1587 | * Compute the transitive closure of glyphs needed for all of the |
| 1588 | * provided lookups. |
| 1589 | * |
| 1590 | * Since: 1.8.1 |
| 1591 | **/ |
| 1592 | void |
| 1593 | hb_ot_layout_lookups_substitute_closure (hb_face_t *face, |
| 1594 | const hb_set_t *lookups, |
| 1595 | hb_set_t *glyphs /* OUT */) |
| 1596 | { |
| 1597 | hb_map_t done_lookups_glyph_count; |
| 1598 | hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> done_lookups_glyph_set; |
| 1599 | OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set); |
| 1600 | const GSUB& gsub = *face->table.GSUB->table; |
| 1601 | |
| 1602 | unsigned int iteration_count = 0; |
| 1603 | unsigned int glyphs_length; |
| 1604 | do |
| 1605 | { |
| 1606 | c.reset_lookup_visit_count (); |
| 1607 | glyphs_length = glyphs->get_population (); |
| 1608 | if (lookups) |
| 1609 | { |
| 1610 | for (auto lookup_index : *lookups) |
| 1611 | gsub.get_lookup (lookup_index).closure (&c, lookup_index); |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) |
| 1616 | gsub.get_lookup (i).closure (&c, i); |
| 1617 | } |
| 1618 | } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES && |
| 1619 | glyphs_length != glyphs->get_population ()); |
| 1620 | } |
| 1621 | |
| 1622 | /* |
| 1623 | * GPOS |
| 1624 | */ |
| 1625 | |
| 1626 | |
| 1627 | /** |
| 1628 | * hb_ot_layout_has_positioning: |
| 1629 | * @face: #hb_face_t to work upon |
| 1630 | * |
| 1631 | * Tests whether the specified face includes any GPOS positioning. |
| 1632 | * |
| 1633 | * Return value: `true` if the face has GPOS data, `false` otherwise |
| 1634 | * |
| 1635 | **/ |
| 1636 | hb_bool_t |
| 1637 | hb_ot_layout_has_positioning (hb_face_t *face) |
| 1638 | { |
| 1639 | return face->table.GPOS->table->has_data (); |
| 1640 | } |
| 1641 | |
| 1642 | /** |
| 1643 | * hb_ot_layout_position_start: |
| 1644 | * @font: #hb_font_t to use |
| 1645 | * @buffer: #hb_buffer_t buffer to work upon |
| 1646 | * |
| 1647 | * Called before positioning lookups are performed, to ensure that glyph |
| 1648 | * attachment types and glyph-attachment chains are set for the glyphs in the buffer. |
| 1649 | * |
| 1650 | **/ |
| 1651 | void |
| 1652 | hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer) |
| 1653 | { |
| 1654 | GPOS::position_start (font, buffer); |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | /** |
| 1659 | * hb_ot_layout_position_finish_advances: |
| 1660 | * @font: #hb_font_t to use |
| 1661 | * @buffer: #hb_buffer_t buffer to work upon |
| 1662 | * |
| 1663 | * Called after positioning lookups are performed, to finish glyph advances. |
| 1664 | * |
| 1665 | **/ |
| 1666 | void |
| 1667 | hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer) |
| 1668 | { |
| 1669 | GPOS::position_finish_advances (font, buffer); |
| 1670 | } |
| 1671 | |
| 1672 | /** |
| 1673 | * hb_ot_layout_position_finish_offsets: |
| 1674 | * @font: #hb_font_t to use |
| 1675 | * @buffer: #hb_buffer_t buffer to work upon |
| 1676 | * |
| 1677 | * Called after positioning lookups are performed, to finish glyph offsets. |
| 1678 | * |
| 1679 | **/ |
| 1680 | void |
| 1681 | hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) |
| 1682 | { |
| 1683 | GPOS::position_finish_offsets (font, buffer); |
| 1684 | } |
| 1685 | |
| 1686 | |
| 1687 | #ifndef HB_NO_LAYOUT_FEATURE_PARAMS |
| 1688 | /** |
| 1689 | * hb_ot_layout_get_size_params: |
| 1690 | * @face: #hb_face_t to work upon |
| 1691 | * @design_size: (out): The design size of the face |
| 1692 | * @subfamily_id: (out): The identifier of the face within the font subfamily |
| 1693 | * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily |
| 1694 | * @range_start: (out): The minimum size of the recommended size range for the face |
| 1695 | * @range_end: (out): The maximum size of the recommended size range for the face |
| 1696 | * |
| 1697 | * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that |
| 1698 | * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id) |
| 1699 | * as used here are defined as pertaining only to fonts within a font family that differ |
| 1700 | * specifically in their respective size ranges; other ways to differentiate fonts within |
| 1701 | * a subfamily are not covered by the `size` feature. |
| 1702 | * |
| 1703 | * For more information on this distinction, see the [`size` feature documentation]( |
| 1704 | * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-size). |
| 1705 | * |
| 1706 | * Return value: `true` if data found, `false` otherwise |
| 1707 | * |
| 1708 | * Since: 0.9.10 |
| 1709 | **/ |
| 1710 | hb_bool_t |
| 1711 | hb_ot_layout_get_size_params (hb_face_t *face, |
| 1712 | unsigned int *design_size, /* OUT. May be NULL */ |
| 1713 | unsigned int *subfamily_id, /* OUT. May be NULL */ |
| 1714 | hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */ |
| 1715 | unsigned int *range_start, /* OUT. May be NULL */ |
| 1716 | unsigned int *range_end /* OUT. May be NULL */) |
| 1717 | { |
| 1718 | const GPOS &gpos = *face->table.GPOS->table; |
| 1719 | const hb_tag_t tag = HB_TAG ('s','i','z','e'); |
| 1720 | |
| 1721 | unsigned int num_features = gpos.get_feature_count (); |
| 1722 | for (unsigned int i = 0; i < num_features; i++) |
| 1723 | { |
| 1724 | if (tag == gpos.get_feature_tag (i)) |
| 1725 | { |
| 1726 | const OT::Feature &f = gpos.get_feature (i); |
| 1727 | const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag); |
| 1728 | |
| 1729 | if (params.designSize) |
| 1730 | { |
| 1731 | if (design_size) *design_size = params.designSize; |
| 1732 | if (subfamily_id) *subfamily_id = params.subfamilyID; |
| 1733 | if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID; |
| 1734 | if (range_start) *range_start = params.rangeStart; |
| 1735 | if (range_end) *range_end = params.rangeEnd; |
| 1736 | |
| 1737 | return true; |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | if (design_size) *design_size = 0; |
| 1743 | if (subfamily_id) *subfamily_id = 0; |
| 1744 | if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID; |
| 1745 | if (range_start) *range_start = 0; |
| 1746 | if (range_end) *range_end = 0; |
| 1747 | |
| 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | |
| 1752 | /** |
| 1753 | * hb_ot_layout_feature_get_name_ids: |
| 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 | * @label_id: (out) (optional): The ‘name’ table name ID that specifies a string |
| 1758 | * for a user-interface label for this feature. (May be NULL.) |
| 1759 | * @tooltip_id: (out) (optional): The ‘name’ table name ID that specifies a string |
| 1760 | * that an application can use for tooltip text for this |
| 1761 | * feature. (May be NULL.) |
| 1762 | * @sample_id: (out) (optional): The ‘name’ table name ID that specifies sample text |
| 1763 | * that illustrates the effect of this feature. (May be NULL.) |
| 1764 | * @num_named_parameters: (out) (optional): Number of named parameters. (May be zero.) |
| 1765 | * @first_param_id: (out) (optional): The first ‘name’ table name ID used to specify |
| 1766 | * strings for user-interface labels for the feature |
| 1767 | * parameters. (Must be zero if numParameters is zero.) |
| 1768 | * |
| 1769 | * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or |
| 1770 | * "Character Variant" ('cvXX') features. |
| 1771 | * |
| 1772 | * Return value: `true` if data found, `false` otherwise |
| 1773 | * |
| 1774 | * Since: 2.0.0 |
| 1775 | **/ |
| 1776 | hb_bool_t |
| 1777 | hb_ot_layout_feature_get_name_ids (hb_face_t *face, |
| 1778 | hb_tag_t table_tag, |
| 1779 | unsigned int feature_index, |
| 1780 | hb_ot_name_id_t *label_id, /* OUT. May be NULL */ |
| 1781 | hb_ot_name_id_t *tooltip_id, /* OUT. May be NULL */ |
| 1782 | hb_ot_name_id_t *sample_id, /* OUT. May be NULL */ |
| 1783 | unsigned int *num_named_parameters, /* OUT. May be NULL */ |
| 1784 | hb_ot_name_id_t *first_param_id /* OUT. May be NULL */) |
| 1785 | { |
| 1786 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1787 | |
| 1788 | hb_tag_t feature_tag = g.get_feature_tag (feature_index); |
| 1789 | const OT::Feature &f = g.get_feature (feature_index); |
| 1790 | |
| 1791 | const OT::FeatureParams &feature_params = f.get_feature_params (); |
| 1792 | if (&feature_params != &Null (OT::FeatureParams)) |
| 1793 | { |
| 1794 | const OT::FeatureParamsStylisticSet& ss_params = |
| 1795 | feature_params.get_stylistic_set_params (feature_tag); |
| 1796 | if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */ |
| 1797 | { |
| 1798 | if (label_id) *label_id = ss_params.uiNameID; |
| 1799 | // ssXX features don't have the rest |
| 1800 | if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID; |
| 1801 | if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID; |
| 1802 | if (num_named_parameters) *num_named_parameters = 0; |
| 1803 | if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID; |
| 1804 | return true; |
| 1805 | } |
| 1806 | const OT::FeatureParamsCharacterVariants& cv_params = |
| 1807 | feature_params.get_character_variants_params (feature_tag); |
| 1808 | if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */ |
| 1809 | { |
| 1810 | if (label_id) *label_id = cv_params.featUILableNameID; |
| 1811 | if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID; |
| 1812 | if (sample_id) *sample_id = cv_params.sampleTextNameID; |
| 1813 | if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters; |
| 1814 | if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID; |
| 1815 | return true; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | if (label_id) *label_id = HB_OT_NAME_ID_INVALID; |
| 1820 | if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID; |
| 1821 | if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID; |
| 1822 | if (num_named_parameters) *num_named_parameters = 0; |
| 1823 | if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID; |
| 1824 | return false; |
| 1825 | } |
| 1826 | /** |
| 1827 | * hb_ot_layout_feature_get_characters: |
| 1828 | * @face: #hb_face_t to work upon |
| 1829 | * @table_tag: table tag to query, "GSUB" or "GPOS". |
| 1830 | * @feature_index: index of feature to query. |
| 1831 | * @start_offset: offset of the first character to retrieve |
| 1832 | * @char_count: (inout) (optional): Input = the maximum number of characters to return; |
| 1833 | * Output = the actual number of characters returned (may be zero) |
| 1834 | * @characters: (out caller-allocates) (array length=char_count): A buffer pointer. |
| 1835 | * The Unicode codepoints of the characters for which this feature provides |
| 1836 | * glyph variants. |
| 1837 | * |
| 1838 | * Fetches a list of the characters defined as having a variant under the specified |
| 1839 | * "Character Variant" ("cvXX") feature tag. |
| 1840 | * |
| 1841 | * Return value: Number of total sample characters in the cvXX feature. |
| 1842 | * |
| 1843 | * Since: 2.0.0 |
| 1844 | **/ |
| 1845 | unsigned int |
| 1846 | hb_ot_layout_feature_get_characters (hb_face_t *face, |
| 1847 | hb_tag_t table_tag, |
| 1848 | unsigned int feature_index, |
| 1849 | unsigned int start_offset, |
| 1850 | unsigned int *char_count, /* IN/OUT. May be NULL */ |
| 1851 | hb_codepoint_t *characters /* OUT. May be NULL */) |
| 1852 | { |
| 1853 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1854 | return g.get_feature (feature_index) |
| 1855 | .get_feature_params () |
| 1856 | .get_character_variants_params(g.get_feature_tag (feature_index)) |
| 1857 | .get_characters (start_offset, char_count, characters); |
| 1858 | } |
| 1859 | #endif |
| 1860 | |
| 1861 | |
| 1862 | /* |
| 1863 | * Parts of different types are implemented here such that they have direct |
| 1864 | * access to GSUB/GPOS lookups. |
| 1865 | */ |
| 1866 | |
| 1867 | |
| 1868 | struct GSUBProxy |
| 1869 | { |
| 1870 | static constexpr unsigned table_index = 0u; |
| 1871 | static constexpr bool always_inplace = false; |
| 1872 | typedef OT::SubstLookup Lookup; |
| 1873 | |
| 1874 | GSUBProxy (hb_face_t *face) : |
| 1875 | accel (*face->table.GSUB) {} |
| 1876 | |
| 1877 | const GSUB::accelerator_t &accel; |
| 1878 | }; |
| 1879 | |
| 1880 | struct GPOSProxy |
| 1881 | { |
| 1882 | static constexpr unsigned table_index = 1u; |
| 1883 | static constexpr bool always_inplace = true; |
| 1884 | typedef OT::PosLookup Lookup; |
| 1885 | |
| 1886 | GPOSProxy (hb_face_t *face) : |
| 1887 | accel (*face->table.GPOS) {} |
| 1888 | |
| 1889 | const GPOS::accelerator_t &accel; |
| 1890 | }; |
| 1891 | |
| 1892 | |
| 1893 | static inline bool |
| 1894 | apply_forward (OT::hb_ot_apply_context_t *c, |
| 1895 | const OT::hb_ot_layout_lookup_accelerator_t &accel, |
| 1896 | unsigned subtable_count) |
| 1897 | { |
| 1898 | bool use_cache = accel.cache_enter (c); |
| 1899 | |
| 1900 | bool ret = false; |
| 1901 | hb_buffer_t *buffer = c->buffer; |
| 1902 | while (buffer->idx < buffer->len && buffer->successful) |
| 1903 | { |
| 1904 | bool applied = false; |
| 1905 | if (accel.digest.may_have (buffer->cur().codepoint) && |
| 1906 | (buffer->cur().mask & c->lookup_mask) && |
| 1907 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1908 | { |
| 1909 | applied = accel.apply (c, subtable_count, use_cache); |
| 1910 | } |
| 1911 | |
| 1912 | if (applied) |
| 1913 | ret = true; |
| 1914 | else |
| 1915 | (void) buffer->next_glyph (); |
| 1916 | } |
| 1917 | |
| 1918 | if (use_cache) |
| 1919 | accel.cache_leave (c); |
| 1920 | |
| 1921 | return ret; |
| 1922 | } |
| 1923 | |
| 1924 | static inline bool |
| 1925 | apply_backward (OT::hb_ot_apply_context_t *c, |
| 1926 | const OT::hb_ot_layout_lookup_accelerator_t &accel, |
| 1927 | unsigned subtable_count) |
| 1928 | { |
| 1929 | bool ret = false; |
| 1930 | hb_buffer_t *buffer = c->buffer; |
| 1931 | do |
| 1932 | { |
| 1933 | if (accel.digest.may_have (buffer->cur().codepoint) && |
| 1934 | (buffer->cur().mask & c->lookup_mask) && |
| 1935 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1936 | ret |= accel.apply (c, subtable_count, false); |
| 1937 | |
| 1938 | /* The reverse lookup doesn't "advance" cursor (for good reason). */ |
| 1939 | buffer->idx--; |
| 1940 | |
| 1941 | } |
| 1942 | while ((int) buffer->idx >= 0); |
| 1943 | return ret; |
| 1944 | } |
| 1945 | |
| 1946 | template <typename Proxy> |
| 1947 | static inline bool |
| 1948 | apply_string (OT::hb_ot_apply_context_t *c, |
| 1949 | const typename Proxy::Lookup &lookup, |
| 1950 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
| 1951 | { |
| 1952 | hb_buffer_t *buffer = c->buffer; |
| 1953 | unsigned subtable_count = lookup.get_subtable_count (); |
| 1954 | |
| 1955 | if (unlikely (!buffer->len || !c->lookup_mask)) |
| 1956 | return false; |
| 1957 | |
| 1958 | bool ret = false; |
| 1959 | |
| 1960 | c->set_lookup_props (lookup.get_props ()); |
| 1961 | |
| 1962 | if (likely (!lookup.is_reverse ())) |
| 1963 | { |
| 1964 | /* in/out forward substitution/positioning */ |
| 1965 | if (!Proxy::always_inplace) |
| 1966 | buffer->clear_output (); |
| 1967 | |
| 1968 | buffer->idx = 0; |
| 1969 | ret = apply_forward (c, accel, subtable_count); |
| 1970 | |
| 1971 | if (!Proxy::always_inplace) |
| 1972 | buffer->sync (); |
| 1973 | } |
| 1974 | else |
| 1975 | { |
| 1976 | /* in-place backward substitution/positioning */ |
| 1977 | assert (!buffer->have_output); |
| 1978 | buffer->idx = buffer->len - 1; |
| 1979 | ret = apply_backward (c, accel, subtable_count); |
| 1980 | } |
| 1981 | |
| 1982 | return ret; |
| 1983 | } |
| 1984 | |
| 1985 | template <typename Proxy> |
| 1986 | inline void hb_ot_map_t::apply (const Proxy &proxy, |
| 1987 | const hb_ot_shape_plan_t *plan, |
| 1988 | hb_font_t *font, |
| 1989 | hb_buffer_t *buffer) const |
| 1990 | { |
| 1991 | const unsigned int table_index = proxy.table_index; |
| 1992 | unsigned int i = 0; |
| 1993 | OT::hb_ot_apply_context_t c (table_index, font, buffer, proxy.accel.get_blob ()); |
| 1994 | c.set_recurse_func (Proxy::Lookup::template dispatch_recurse_func<OT::hb_ot_apply_context_t>); |
| 1995 | |
| 1996 | for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++) |
| 1997 | { |
| 1998 | const stage_map_t *stage = &stages[table_index][stage_index]; |
| 1999 | for (; i < stage->last_lookup; i++) |
| 2000 | { |
| 2001 | auto &lookup = lookups[table_index][i]; |
| 2002 | |
| 2003 | unsigned int lookup_index = lookup.index; |
| 2004 | |
| 2005 | auto *accel = proxy.accel.get_accel (lookup_index); |
| 2006 | if (unlikely (!accel)) continue; |
| 2007 | |
| 2008 | if (buffer->messaging () && |
| 2009 | !buffer->message (font, "start lookup %u feature '%c%c%c%c'" , lookup_index, HB_UNTAG (lookup.feature_tag))) continue; |
| 2010 | |
| 2011 | /* c.digest is a digest of all the current glyphs in the buffer |
| 2012 | * (plus some past glyphs). |
| 2013 | * |
| 2014 | * Only try applying the lookup if there is any overlap. */ |
| 2015 | if (accel->digest.may_have (c.digest)) |
| 2016 | { |
| 2017 | c.set_lookup_index (lookup_index); |
| 2018 | c.set_lookup_mask (lookup.mask, false); |
| 2019 | c.set_auto_zwj (lookup.auto_zwj, false); |
| 2020 | c.set_auto_zwnj (lookup.auto_zwnj, false); |
| 2021 | c.set_random (lookup.random); |
| 2022 | c.set_per_syllable (lookup.per_syllable, false); |
| 2023 | /* apply_string's set_lookup_props initializes the iterators. */ |
| 2024 | |
| 2025 | apply_string<Proxy> (&c, |
| 2026 | proxy.accel.table->get_lookup (lookup_index), |
| 2027 | *accel); |
| 2028 | } |
| 2029 | else if (buffer->messaging ()) |
| 2030 | (void) buffer->message (font, "skipped lookup %u feature '%c%c%c%c' because no glyph matches" , lookup_index, HB_UNTAG (lookup.feature_tag)); |
| 2031 | |
| 2032 | if (buffer->messaging ()) |
| 2033 | (void) buffer->message (font, "end lookup %u feature '%c%c%c%c'" , lookup_index, HB_UNTAG (lookup.feature_tag)); |
| 2034 | } |
| 2035 | |
| 2036 | if (stage->pause_func) |
| 2037 | { |
| 2038 | if (stage->pause_func (plan, font, buffer)) |
| 2039 | { |
| 2040 | /* Refresh working buffer digest since buffer changed. */ |
| 2041 | c.digest = buffer->digest (); |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 2048 | { |
| 2049 | GSUBProxy proxy (font->face); |
| 2050 | if (buffer->messaging () && |
| 2051 | !buffer->message (font, "start table GSUB script tag '%c%c%c%c'" , HB_UNTAG (chosen_script[0]))) return; |
| 2052 | apply (proxy, plan, font, buffer); |
| 2053 | if (buffer->messaging ()) |
| 2054 | (void) buffer->message (font, "end table GSUB script tag '%c%c%c%c'" , HB_UNTAG (chosen_script[0])); |
| 2055 | } |
| 2056 | |
| 2057 | void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 2058 | { |
| 2059 | GPOSProxy proxy (font->face); |
| 2060 | if (buffer->messaging () && |
| 2061 | !buffer->message (font, "start table GPOS script tag '%c%c%c%c'" , HB_UNTAG (chosen_script[1]))) return; |
| 2062 | apply (proxy, plan, font, buffer); |
| 2063 | if (buffer->messaging ()) |
| 2064 | (void) buffer->message (font, "end table GPOS script tag '%c%c%c%c'" , HB_UNTAG (chosen_script[1])); |
| 2065 | } |
| 2066 | |
| 2067 | void |
| 2068 | hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, |
| 2069 | const OT::SubstLookup &lookup, |
| 2070 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
| 2071 | { |
| 2072 | apply_string<GSUBProxy> (c, lookup, accel); |
| 2073 | } |
| 2074 | |
| 2075 | #ifndef HB_NO_BASE |
| 2076 | |
| 2077 | static void |
| 2078 | choose_base_tags (hb_script_t script, |
| 2079 | hb_language_t language, |
| 2080 | hb_tag_t *script_tag, |
| 2081 | hb_tag_t *language_tag) |
| 2082 | { |
| 2083 | hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT]; |
| 2084 | unsigned script_count = ARRAY_LENGTH (script_tags); |
| 2085 | |
| 2086 | hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE]; |
| 2087 | unsigned language_count = ARRAY_LENGTH (language_tags); |
| 2088 | |
| 2089 | hb_ot_tags_from_script_and_language (script, language, |
| 2090 | &script_count, script_tags, |
| 2091 | &language_count, language_tags); |
| 2092 | |
| 2093 | *script_tag = script_count ? script_tags[script_count - 1] : HB_OT_TAG_DEFAULT_SCRIPT; |
| 2094 | *language_tag = language_count ? language_tags[language_count - 1] : HB_OT_TAG_DEFAULT_LANGUAGE; |
| 2095 | } |
| 2096 | |
| 2097 | /** |
| 2098 | * hb_ot_layout_get_font_extents: |
| 2099 | * @font: a font |
| 2100 | * @direction: text direction. |
| 2101 | * @script_tag: script tag. |
| 2102 | * @language_tag: language tag. |
| 2103 | * @extents: (out) (nullable): font extents if found. |
| 2104 | * |
| 2105 | * Fetches script/language-specific font extents. These values are |
| 2106 | * looked up in the `BASE` table's `MinMax` records. |
| 2107 | * |
| 2108 | * If no such extents are found, the default extents for the font are |
| 2109 | * fetched. As such, the return value of this function can for the |
| 2110 | * most part be ignored. Note that the per-script/language extents |
| 2111 | * do not have a line-gap value, and the line-gap is set to zero in |
| 2112 | * that case. |
| 2113 | * |
| 2114 | * Return value: `true` if found script/language-specific font extents. |
| 2115 | * |
| 2116 | * Since: 8.0.0 |
| 2117 | **/ |
| 2118 | hb_bool_t |
| 2119 | hb_ot_layout_get_font_extents (hb_font_t *font, |
| 2120 | hb_direction_t direction, |
| 2121 | hb_tag_t script_tag, |
| 2122 | hb_tag_t language_tag, |
| 2123 | hb_font_extents_t *extents) |
| 2124 | { |
| 2125 | hb_position_t min, max; |
| 2126 | if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE, |
| 2127 | &min, &max)) |
| 2128 | { |
| 2129 | if (extents) |
| 2130 | { |
| 2131 | extents->ascender = max; |
| 2132 | extents->descender = min; |
| 2133 | extents->line_gap = 0; |
| 2134 | } |
| 2135 | return true; |
| 2136 | } |
| 2137 | |
| 2138 | hb_font_get_extents_for_direction (font, direction, extents); |
| 2139 | return false; |
| 2140 | } |
| 2141 | |
| 2142 | /** |
| 2143 | * hb_ot_layout_get_font_extents2: |
| 2144 | * @font: a font |
| 2145 | * @direction: text direction. |
| 2146 | * @script: script. |
| 2147 | * @language: (nullable): language. |
| 2148 | * @extents: (out) (nullable): font extents if found. |
| 2149 | * |
| 2150 | * Fetches script/language-specific font extents. These values are |
| 2151 | * looked up in the `BASE` table's `MinMax` records. |
| 2152 | * |
| 2153 | * If no such extents are found, the default extents for the font are |
| 2154 | * fetched. As such, the return value of this function can for the |
| 2155 | * most part be ignored. Note that the per-script/language extents |
| 2156 | * do not have a line-gap value, and the line-gap is set to zero in |
| 2157 | * that case. |
| 2158 | * |
| 2159 | * This function is like hb_ot_layout_get_font_extents() but takes |
| 2160 | * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. |
| 2161 | * |
| 2162 | * Return value: `true` if found script/language-specific font extents. |
| 2163 | * |
| 2164 | * Since: 8.0.0 |
| 2165 | **/ |
| 2166 | hb_bool_t |
| 2167 | hb_ot_layout_get_font_extents2 (hb_font_t *font, |
| 2168 | hb_direction_t direction, |
| 2169 | hb_script_t script, |
| 2170 | hb_language_t language, |
| 2171 | hb_font_extents_t *extents) |
| 2172 | { |
| 2173 | hb_tag_t script_tag, language_tag; |
| 2174 | choose_base_tags (script, language, &script_tag, &language_tag); |
| 2175 | return hb_ot_layout_get_font_extents (font, |
| 2176 | direction, |
| 2177 | script_tag, |
| 2178 | language_tag, |
| 2179 | extents); |
| 2180 | } |
| 2181 | |
| 2182 | /** |
| 2183 | * hb_ot_layout_get_horizontal_baseline_tag_for_script: |
| 2184 | * @script: a script tag. |
| 2185 | * |
| 2186 | * Fetches the dominant horizontal baseline tag used by @script. |
| 2187 | * |
| 2188 | * Return value: dominant baseline tag for the @script. |
| 2189 | * |
| 2190 | * Since: 4.0.0 |
| 2191 | **/ |
| 2192 | hb_ot_layout_baseline_tag_t |
| 2193 | hb_ot_layout_get_horizontal_baseline_tag_for_script (hb_script_t script) |
| 2194 | { |
| 2195 | /* Keep in sync with hb_ot_layout_get_baseline_with_fallback */ |
| 2196 | switch ((int) script) |
| 2197 | { |
| 2198 | /* Unicode-1.1 additions */ |
| 2199 | case HB_SCRIPT_BENGALI: |
| 2200 | case HB_SCRIPT_DEVANAGARI: |
| 2201 | case HB_SCRIPT_GUJARATI: |
| 2202 | case HB_SCRIPT_GURMUKHI: |
| 2203 | /* Unicode-2.0 additions */ |
| 2204 | case HB_SCRIPT_TIBETAN: |
| 2205 | /* Unicode-4.0 additions */ |
| 2206 | case HB_SCRIPT_LIMBU: |
| 2207 | /* Unicode-4.1 additions */ |
| 2208 | case HB_SCRIPT_SYLOTI_NAGRI: |
| 2209 | /* Unicode-5.0 additions */ |
| 2210 | case HB_SCRIPT_PHAGS_PA: |
| 2211 | /* Unicode-5.2 additions */ |
| 2212 | case HB_SCRIPT_MEETEI_MAYEK: |
| 2213 | /* Unicode-6.1 additions */ |
| 2214 | case HB_SCRIPT_SHARADA: |
| 2215 | case HB_SCRIPT_TAKRI: |
| 2216 | /* Unicode-7.0 additions */ |
| 2217 | case HB_SCRIPT_MODI: |
| 2218 | case HB_SCRIPT_SIDDHAM: |
| 2219 | case HB_SCRIPT_TIRHUTA: |
| 2220 | /* Unicode-9.0 additions */ |
| 2221 | case HB_SCRIPT_MARCHEN: |
| 2222 | case HB_SCRIPT_NEWA: |
| 2223 | /* Unicode-10.0 additions */ |
| 2224 | case HB_SCRIPT_SOYOMBO: |
| 2225 | case HB_SCRIPT_ZANABAZAR_SQUARE: |
| 2226 | /* Unicode-11.0 additions */ |
| 2227 | case HB_SCRIPT_DOGRA: |
| 2228 | case HB_SCRIPT_GUNJALA_GONDI: |
| 2229 | /* Unicode-12.0 additions */ |
| 2230 | case HB_SCRIPT_NANDINAGARI: |
| 2231 | return HB_OT_LAYOUT_BASELINE_TAG_HANGING; |
| 2232 | |
| 2233 | /* Unicode-1.1 additions */ |
| 2234 | case HB_SCRIPT_HANGUL: |
| 2235 | case HB_SCRIPT_HAN: |
| 2236 | case HB_SCRIPT_HIRAGANA: |
| 2237 | case HB_SCRIPT_KATAKANA: |
| 2238 | /* Unicode-3.0 additions */ |
| 2239 | case HB_SCRIPT_BOPOMOFO: |
| 2240 | /* Unicode-9.0 additions */ |
| 2241 | case HB_SCRIPT_TANGUT: |
| 2242 | /* Unicode-10.0 additions */ |
| 2243 | case HB_SCRIPT_NUSHU: |
| 2244 | /* Unicode-13.0 additions */ |
| 2245 | case HB_SCRIPT_KHITAN_SMALL_SCRIPT: |
| 2246 | return HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT; |
| 2247 | |
| 2248 | default: |
| 2249 | return HB_OT_LAYOUT_BASELINE_TAG_ROMAN; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * hb_ot_layout_get_baseline: |
| 2255 | * @font: a font |
| 2256 | * @baseline_tag: a baseline tag |
| 2257 | * @direction: text direction. |
| 2258 | * @script_tag: script tag. |
| 2259 | * @language_tag: language tag, currently unused. |
| 2260 | * @coord: (out) (nullable): baseline value if found. |
| 2261 | * |
| 2262 | * Fetches a baseline value from the face. |
| 2263 | * |
| 2264 | * Return value: `true` if found baseline value in the font. |
| 2265 | * |
| 2266 | * Since: 2.6.0 |
| 2267 | **/ |
| 2268 | hb_bool_t |
| 2269 | hb_ot_layout_get_baseline (hb_font_t *font, |
| 2270 | hb_ot_layout_baseline_tag_t baseline_tag, |
| 2271 | hb_direction_t direction, |
| 2272 | hb_tag_t script_tag, |
| 2273 | hb_tag_t language_tag, |
| 2274 | hb_position_t *coord /* OUT. May be NULL. */) |
| 2275 | { |
| 2276 | return font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord); |
| 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * hb_ot_layout_get_baseline2: |
| 2281 | * @font: a font |
| 2282 | * @baseline_tag: a baseline tag |
| 2283 | * @direction: text direction. |
| 2284 | * @script: script. |
| 2285 | * @language: (nullable): language, currently unused. |
| 2286 | * @coord: (out) (nullable): baseline value if found. |
| 2287 | * |
| 2288 | * Fetches a baseline value from the face. |
| 2289 | * |
| 2290 | * This function is like hb_ot_layout_get_baseline() but takes |
| 2291 | * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. |
| 2292 | * |
| 2293 | * Return value: `true` if found baseline value in the font. |
| 2294 | * |
| 2295 | * Since: 8.0.0 |
| 2296 | **/ |
| 2297 | hb_bool_t |
| 2298 | hb_ot_layout_get_baseline2 (hb_font_t *font, |
| 2299 | hb_ot_layout_baseline_tag_t baseline_tag, |
| 2300 | hb_direction_t direction, |
| 2301 | hb_script_t script, |
| 2302 | hb_language_t language, |
| 2303 | hb_position_t *coord /* OUT. May be NULL. */) |
| 2304 | { |
| 2305 | hb_tag_t script_tag, language_tag; |
| 2306 | choose_base_tags (script, language, &script_tag, &language_tag); |
| 2307 | return hb_ot_layout_get_baseline (font, |
| 2308 | baseline_tag, |
| 2309 | direction, |
| 2310 | script_tag, |
| 2311 | language_tag, |
| 2312 | coord); |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * hb_ot_layout_get_baseline_with_fallback: |
| 2317 | * @font: a font |
| 2318 | * @baseline_tag: a baseline tag |
| 2319 | * @direction: text direction. |
| 2320 | * @script_tag: script tag. |
| 2321 | * @language_tag: language tag, currently unused. |
| 2322 | * @coord: (out): baseline value if found. |
| 2323 | * |
| 2324 | * Fetches a baseline value from the face, and synthesizes |
| 2325 | * it if the font does not have it. |
| 2326 | * |
| 2327 | * Since: 4.0.0 |
| 2328 | **/ |
| 2329 | void |
| 2330 | hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, |
| 2331 | hb_ot_layout_baseline_tag_t baseline_tag, |
| 2332 | hb_direction_t direction, |
| 2333 | hb_tag_t script_tag, |
| 2334 | hb_tag_t language_tag, |
| 2335 | hb_position_t *coord /* OUT */) |
| 2336 | { |
| 2337 | if (hb_ot_layout_get_baseline (font, |
| 2338 | baseline_tag, |
| 2339 | direction, |
| 2340 | script_tag, |
| 2341 | language_tag, |
| 2342 | coord)) |
| 2343 | return; |
| 2344 | |
| 2345 | /* Synthesize missing baselines. |
| 2346 | * See https://www.w3.org/TR/css-inline-3/#baseline-synthesis-fonts |
| 2347 | */ |
| 2348 | switch (baseline_tag) |
| 2349 | { |
| 2350 | case HB_OT_LAYOUT_BASELINE_TAG_ROMAN: |
| 2351 | *coord = 0; // FIXME origin ? |
| 2352 | break; |
| 2353 | |
| 2354 | case HB_OT_LAYOUT_BASELINE_TAG_MATH: |
| 2355 | { |
| 2356 | hb_codepoint_t glyph; |
| 2357 | hb_glyph_extents_t extents; |
| 2358 | if (HB_DIRECTION_IS_HORIZONTAL (direction) && |
| 2359 | (hb_font_get_nominal_glyph (font, 0x2212u, &glyph) || |
| 2360 | hb_font_get_nominal_glyph (font, '-', &glyph)) && |
| 2361 | hb_font_get_glyph_extents (font, glyph, &extents)) |
| 2362 | { |
| 2363 | *coord = extents.y_bearing + extents.height / 2; |
| 2364 | } |
| 2365 | else |
| 2366 | { |
| 2367 | hb_position_t x_height = font->y_scale / 2; |
| 2368 | #ifndef HB_NO_METRICS |
| 2369 | hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_X_HEIGHT, &x_height); |
| 2370 | #endif |
| 2371 | *coord = x_height / 2; |
| 2372 | } |
| 2373 | } |
| 2374 | break; |
| 2375 | |
| 2376 | case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT: |
| 2377 | case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT: |
| 2378 | { |
| 2379 | hb_position_t embox_top, embox_bottom; |
| 2380 | |
| 2381 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2382 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, |
| 2383 | direction, |
| 2384 | script_tag, |
| 2385 | language_tag, |
| 2386 | &embox_top); |
| 2387 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2388 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT, |
| 2389 | direction, |
| 2390 | script_tag, |
| 2391 | language_tag, |
| 2392 | &embox_bottom); |
| 2393 | |
| 2394 | if (baseline_tag == HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT) |
| 2395 | *coord = embox_top + (embox_bottom - embox_top) / 10; |
| 2396 | else |
| 2397 | *coord = embox_bottom + (embox_top - embox_bottom) / 10; |
| 2398 | } |
| 2399 | break; |
| 2400 | |
| 2401 | case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT: |
| 2402 | if (hb_ot_layout_get_baseline (font, |
| 2403 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT, |
| 2404 | direction, |
| 2405 | script_tag, |
| 2406 | language_tag, |
| 2407 | coord)) |
| 2408 | *coord += HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale; |
| 2409 | else |
| 2410 | { |
| 2411 | hb_font_extents_t font_extents; |
| 2412 | hb_font_get_extents_for_direction (font, direction, &font_extents); |
| 2413 | *coord = font_extents.ascender; |
| 2414 | } |
| 2415 | break; |
| 2416 | |
| 2417 | case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT: |
| 2418 | if (hb_ot_layout_get_baseline (font, |
| 2419 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, |
| 2420 | direction, |
| 2421 | script_tag, |
| 2422 | language_tag, |
| 2423 | coord)) |
| 2424 | *coord -= HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale; |
| 2425 | else |
| 2426 | { |
| 2427 | hb_font_extents_t font_extents; |
| 2428 | hb_font_get_extents_for_direction (font, direction, &font_extents); |
| 2429 | *coord = font_extents.descender; |
| 2430 | } |
| 2431 | break; |
| 2432 | |
| 2433 | case HB_OT_LAYOUT_BASELINE_TAG_HANGING: |
| 2434 | if (HB_DIRECTION_IS_HORIZONTAL (direction)) |
| 2435 | { |
| 2436 | hb_codepoint_t ch; |
| 2437 | hb_codepoint_t glyph; |
| 2438 | hb_glyph_extents_t extents; |
| 2439 | |
| 2440 | /* Keep in sync with hb_ot_layout_get_horizontal_baseline_for_script */ |
| 2441 | switch ((int) script_tag) |
| 2442 | { |
| 2443 | /* Unicode-1.1 additions */ |
| 2444 | case HB_SCRIPT_BENGALI: ch = 0x0995u; break; |
| 2445 | case HB_SCRIPT_DEVANAGARI: ch = 0x0915u; break; |
| 2446 | case HB_SCRIPT_GUJARATI: ch = 0x0a95u; break; |
| 2447 | case HB_SCRIPT_GURMUKHI: ch = 0x0a15u; break; |
| 2448 | /* Unicode-2.0 additions */ |
| 2449 | case HB_SCRIPT_TIBETAN: ch = 0x0f40u; break; |
| 2450 | /* Unicode-4.0 additions */ |
| 2451 | case HB_SCRIPT_LIMBU: ch = 0x1901u; break; |
| 2452 | /* Unicode-4.1 additions */ |
| 2453 | case HB_SCRIPT_SYLOTI_NAGRI: ch = 0xa807u; break; |
| 2454 | /* Unicode-5.0 additions */ |
| 2455 | case HB_SCRIPT_PHAGS_PA: ch = 0xa840u; break; |
| 2456 | /* Unicode-5.2 additions */ |
| 2457 | case HB_SCRIPT_MEETEI_MAYEK: ch = 0xabc0u; break; |
| 2458 | /* Unicode-6.1 additions */ |
| 2459 | case HB_SCRIPT_SHARADA: ch = 0x11191u; break; |
| 2460 | case HB_SCRIPT_TAKRI: ch = 0x1168cu; break; |
| 2461 | /* Unicode-7.0 additions */ |
| 2462 | case HB_SCRIPT_MODI: ch = 0x1160eu;break; |
| 2463 | case HB_SCRIPT_SIDDHAM: ch = 0x11590u; break; |
| 2464 | case HB_SCRIPT_TIRHUTA: ch = 0x1148fu; break; |
| 2465 | /* Unicode-9.0 additions */ |
| 2466 | case HB_SCRIPT_MARCHEN: ch = 0x11c72u; break; |
| 2467 | case HB_SCRIPT_NEWA: ch = 0x1140eu; break; |
| 2468 | /* Unicode-10.0 additions */ |
| 2469 | case HB_SCRIPT_SOYOMBO: ch = 0x11a5cu; break; |
| 2470 | case HB_SCRIPT_ZANABAZAR_SQUARE: ch = 0x11a0bu; break; |
| 2471 | /* Unicode-11.0 additions */ |
| 2472 | case HB_SCRIPT_DOGRA: ch = 0x1180au; break; |
| 2473 | case HB_SCRIPT_GUNJALA_GONDI: ch = 0x11d6cu; break; |
| 2474 | /* Unicode-12.0 additions */ |
| 2475 | case HB_SCRIPT_NANDINAGARI: ch = 0x119b0u; break; |
| 2476 | default: ch = 0; break; |
| 2477 | } |
| 2478 | |
| 2479 | if (ch && |
| 2480 | hb_font_get_nominal_glyph (font, ch, &glyph) && |
| 2481 | hb_font_get_glyph_extents (font, glyph, &extents)) |
| 2482 | *coord = extents.y_bearing; |
| 2483 | else |
| 2484 | *coord = font->y_scale * 6 / 10; // FIXME makes assumptions about origin |
| 2485 | } |
| 2486 | else |
| 2487 | *coord = font->x_scale * 6 / 10; // FIXME makes assumptions about origin |
| 2488 | break; |
| 2489 | |
| 2490 | case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL: |
| 2491 | { |
| 2492 | hb_position_t top, bottom; |
| 2493 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2494 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT, |
| 2495 | direction, |
| 2496 | script_tag, |
| 2497 | language_tag, |
| 2498 | &top); |
| 2499 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2500 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT, |
| 2501 | direction, |
| 2502 | script_tag, |
| 2503 | language_tag, |
| 2504 | &bottom); |
| 2505 | *coord = (top + bottom) / 2; |
| 2506 | |
| 2507 | } |
| 2508 | break; |
| 2509 | |
| 2510 | case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL: |
| 2511 | { |
| 2512 | hb_position_t top, bottom; |
| 2513 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2514 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT, |
| 2515 | direction, |
| 2516 | script_tag, |
| 2517 | language_tag, |
| 2518 | &top); |
| 2519 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2520 | HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT, |
| 2521 | direction, |
| 2522 | script_tag, |
| 2523 | language_tag, |
| 2524 | &bottom); |
| 2525 | *coord = (top + bottom) / 2; |
| 2526 | |
| 2527 | } |
| 2528 | break; |
| 2529 | |
| 2530 | case _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE: |
| 2531 | default: |
| 2532 | *coord = 0; |
| 2533 | break; |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | /** |
| 2538 | * hb_ot_layout_get_baseline_with_fallback2: |
| 2539 | * @font: a font |
| 2540 | * @baseline_tag: a baseline tag |
| 2541 | * @direction: text direction. |
| 2542 | * @script: script. |
| 2543 | * @language: (nullable): language, currently unused. |
| 2544 | * @coord: (out): baseline value if found. |
| 2545 | * |
| 2546 | * Fetches a baseline value from the face, and synthesizes |
| 2547 | * it if the font does not have it. |
| 2548 | * |
| 2549 | * This function is like hb_ot_layout_get_baseline_with_fallback() but takes |
| 2550 | * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t. |
| 2551 | * |
| 2552 | * Since: 8.0.0 |
| 2553 | **/ |
| 2554 | void |
| 2555 | hb_ot_layout_get_baseline_with_fallback2 (hb_font_t *font, |
| 2556 | hb_ot_layout_baseline_tag_t baseline_tag, |
| 2557 | hb_direction_t direction, |
| 2558 | hb_script_t script, |
| 2559 | hb_language_t language, |
| 2560 | hb_position_t *coord /* OUT */) |
| 2561 | { |
| 2562 | hb_tag_t script_tag, language_tag; |
| 2563 | choose_base_tags (script, language, &script_tag, &language_tag); |
| 2564 | hb_ot_layout_get_baseline_with_fallback (font, |
| 2565 | baseline_tag, |
| 2566 | direction, |
| 2567 | script_tag, |
| 2568 | language_tag, |
| 2569 | coord); |
| 2570 | } |
| 2571 | |
| 2572 | #endif |
| 2573 | |
| 2574 | |
| 2575 | struct hb_get_glyph_alternates_dispatch_t : |
| 2576 | hb_dispatch_context_t<hb_get_glyph_alternates_dispatch_t, unsigned> |
| 2577 | { |
| 2578 | static return_t default_return_value () { return 0; } |
| 2579 | bool stop_sublookup_iteration (return_t r) const { return r; } |
| 2580 | |
| 2581 | private: |
| 2582 | template <typename T, typename ...Ts> auto |
| 2583 | _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN |
| 2584 | ( obj.get_glyph_alternates (std::forward<Ts> (ds)...) ) |
| 2585 | template <typename T, typename ...Ts> auto |
| 2586 | _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN |
| 2587 | ( default_return_value () ) |
| 2588 | public: |
| 2589 | template <typename T, typename ...Ts> auto |
| 2590 | dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN |
| 2591 | ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) ) |
| 2592 | }; |
| 2593 | |
| 2594 | #ifndef HB_NO_LAYOUT_RARELY_USED |
| 2595 | /** |
| 2596 | * hb_ot_layout_lookup_get_glyph_alternates: |
| 2597 | * @face: a face. |
| 2598 | * @lookup_index: index of the feature lookup to query. |
| 2599 | * @glyph: a glyph id. |
| 2600 | * @start_offset: starting offset. |
| 2601 | * @alternate_count: (inout) (optional): Input = the maximum number of alternate glyphs to return; |
| 2602 | * Output = the actual number of alternate glyphs returned (may be zero). |
| 2603 | * @alternate_glyphs: (out caller-allocates) (array length=alternate_count): A glyphs buffer. |
| 2604 | * Alternate glyphs associated with the glyph id. |
| 2605 | * |
| 2606 | * Fetches alternates of a glyph from a given GSUB lookup index. |
| 2607 | * |
| 2608 | * Return value: Total number of alternates found in the specific lookup index for the given glyph id. |
| 2609 | * |
| 2610 | * Since: 2.6.8 |
| 2611 | **/ |
| 2612 | HB_EXTERN unsigned |
| 2613 | hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, |
| 2614 | unsigned lookup_index, |
| 2615 | hb_codepoint_t glyph, |
| 2616 | unsigned start_offset, |
| 2617 | unsigned *alternate_count /* IN/OUT. May be NULL. */, |
| 2618 | hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) |
| 2619 | { |
| 2620 | hb_get_glyph_alternates_dispatch_t c; |
| 2621 | const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); |
| 2622 | auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs); |
| 2623 | if (!ret && alternate_count) *alternate_count = 0; |
| 2624 | return ret; |
| 2625 | } |
| 2626 | |
| 2627 | |
| 2628 | struct hb_position_single_dispatch_t : |
| 2629 | hb_dispatch_context_t<hb_position_single_dispatch_t, bool> |
| 2630 | { |
| 2631 | static return_t default_return_value () { return false; } |
| 2632 | bool stop_sublookup_iteration (return_t r) const { return r; } |
| 2633 | |
| 2634 | private: |
| 2635 | template <typename T, typename ...Ts> auto |
| 2636 | _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN |
| 2637 | ( obj.position_single (std::forward<Ts> (ds)...) ) |
| 2638 | template <typename T, typename ...Ts> auto |
| 2639 | _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN |
| 2640 | ( default_return_value () ) |
| 2641 | public: |
| 2642 | template <typename T, typename ...Ts> auto |
| 2643 | dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN |
| 2644 | ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) ) |
| 2645 | }; |
| 2646 | |
| 2647 | /** |
| 2648 | * hb_ot_layout_lookup_get_optical_bound: |
| 2649 | * @font: a font. |
| 2650 | * @lookup_index: index of the feature lookup to query. |
| 2651 | * @direction: edge of the glyph to query. |
| 2652 | * @glyph: a glyph id. |
| 2653 | * |
| 2654 | * Fetches the optical bound of a glyph positioned at the margin of text. |
| 2655 | * The direction identifies which edge of the glyph to query. |
| 2656 | * |
| 2657 | * Return value: Adjustment value. Negative values mean the glyph will stick out of the margin. |
| 2658 | * |
| 2659 | * Since: 5.3.0 |
| 2660 | **/ |
| 2661 | hb_position_t |
| 2662 | hb_ot_layout_lookup_get_optical_bound (hb_font_t *font, |
| 2663 | unsigned lookup_index, |
| 2664 | hb_direction_t direction, |
| 2665 | hb_codepoint_t glyph) |
| 2666 | { |
| 2667 | const OT::PosLookup &lookup = font->face->table.GPOS->table->get_lookup (lookup_index); |
| 2668 | hb_blob_t *blob = font->face->table.GPOS->get_blob (); |
| 2669 | hb_glyph_position_t pos = {0}; |
| 2670 | hb_position_single_dispatch_t c; |
| 2671 | lookup.dispatch (&c, font, blob, direction, glyph, pos); |
| 2672 | hb_position_t ret = 0; |
| 2673 | switch (direction) |
| 2674 | { |
| 2675 | case HB_DIRECTION_LTR: |
| 2676 | ret = pos.x_offset; |
| 2677 | break; |
| 2678 | case HB_DIRECTION_RTL: |
| 2679 | ret = pos.x_advance - pos.x_offset; |
| 2680 | break; |
| 2681 | case HB_DIRECTION_TTB: |
| 2682 | ret = pos.y_offset; |
| 2683 | break; |
| 2684 | case HB_DIRECTION_BTT: |
| 2685 | ret = pos.y_advance - pos.y_offset; |
| 2686 | break; |
| 2687 | case HB_DIRECTION_INVALID: |
| 2688 | default: |
| 2689 | break; |
| 2690 | } |
| 2691 | return ret; |
| 2692 | } |
| 2693 | #endif |
| 2694 | |
| 2695 | |
| 2696 | #endif |
| 2697 | |