Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 1998-2004 David Turner and Werner Lemberg |
| 3 | * Copyright © 2006 Behdad Esfahbod |
| 4 | * Copyright © 2007,2008,2009 Red Hat, Inc. |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 5 | * Copyright © 2012,2013 Google, Inc. |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 6 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 7 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 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 |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 28 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 29 | */ |
| 30 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 31 | #include "hb-open-type.hh" |
| 32 | #include "hb-ot-layout.hh" |
Behdad Esfahbod | b929100 | 2018-08-26 01:15:47 -0700 | [diff] [blame] | 33 | #include "hb-ot-face.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 34 | #include "hb-ot-map.hh" |
| 35 | #include "hb-map.hh" |
Ebrahim Byagowi | 5b9c234 | 2018-02-27 22:56:17 +0330 | [diff] [blame] | 36 | |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 37 | #include "hb-ot-kern-table.hh" |
Ebrahim Byagowi | 8f80e53 | 2018-12-05 13:51:14 +0330 | [diff] [blame] | 38 | #include "hb-ot-gasp-table.hh" // Just so we compile it; unused otherwise. |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 39 | #include "hb-ot-layout-gdef-table.hh" |
| 40 | #include "hb-ot-layout-gsub-table.hh" |
| 41 | #include "hb-ot-layout-gpos-table.hh" |
Ebrahim Byagowi | 8f80e53 | 2018-12-05 13:51:14 +0330 | [diff] [blame] | 42 | #include "hb-ot-layout-base-table.hh" // Just so we compile it; unused otherwise. |
| 43 | #include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise. |
Behdad Esfahbod | 203dc44 | 2018-05-03 21:03:27 -0400 | [diff] [blame] | 44 | #include "hb-ot-name-table.hh" |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 45 | #include "hb-ot-os2-table.hh" |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 46 | |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 47 | #include "hb-aat-layout-lcar-table.hh" |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 48 | #include "hb-aat-layout-morx-table.hh" |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 49 | |
Behdad Esfahbod | aff831e | 2008-01-24 06:03:45 -0500 | [diff] [blame] | 50 | |
Behdad Esfahbod | 80d9a42 | 2018-10-27 04:58:32 -0700 | [diff] [blame] | 51 | /** |
| 52 | * SECTION:hb-ot-layout |
| 53 | * @title: hb-ot-layout |
| 54 | * @short_description: OpenType Layout |
| 55 | * @include: hb-ot.h |
| 56 | * |
| 57 | * Functions for querying OpenType Layout features in the font face. |
| 58 | **/ |
| 59 | |
| 60 | |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 61 | /* |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 62 | * kern |
| 63 | */ |
| 64 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 65 | /** |
| 66 | * hb_ot_layout_has_kerning: |
| 67 | * @face: The #hb_face_t to work on |
| 68 | * |
Nathan Willis | d3178aa | 2019-03-17 14:27:27 +0000 | [diff] [blame] | 69 | * Tests whether a face includes any kerning data in the 'kern' table. |
| 70 | * Does NOT test for kerning lookups in the GPOS table. |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 71 | * |
| 72 | * Return value: true if data found, false otherwise |
| 73 | * |
| 74 | **/ |
Behdad Esfahbod | 385f78b | 2018-11-07 17:19:21 -0500 | [diff] [blame] | 75 | bool |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 76 | hb_ot_layout_has_kerning (hb_face_t *face) |
| 77 | { |
Behdad Esfahbod | a35c92c | 2018-11-05 22:58:43 -0500 | [diff] [blame] | 78 | return face->table.kern->has_data (); |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 79 | } |
| 80 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * hb_ot_layout_has_machine_kerning: |
| 84 | * @face: The #hb_face_t to work on |
| 85 | * |
Nathan Willis | d3178aa | 2019-03-17 14:27:27 +0000 | [diff] [blame] | 86 | * Tests whether a face includes any state-machine kerning in the 'kern' table. |
| 87 | * Does NOT examine the GPOS table. |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 88 | * |
| 89 | * Return value: true if data found, false otherwise |
| 90 | * |
| 91 | **/ |
Behdad Esfahbod | 385f78b | 2018-11-07 17:19:21 -0500 | [diff] [blame] | 92 | bool |
Behdad Esfahbod | 7489622 | 2018-11-23 11:10:17 -0500 | [diff] [blame] | 93 | hb_ot_layout_has_machine_kerning (hb_face_t *face) |
| 94 | { |
| 95 | return face->table.kern->has_state_machine (); |
| 96 | } |
| 97 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * hb_ot_layout_has_cross_kerning: |
| 101 | * @face: The #hb_face_t to work on |
| 102 | * |
| 103 | * Tests whether a face has any cross-stream kerning (i.e., kerns |
| 104 | * that make adjustments perpendicular to the direction of the text |
| 105 | * flow: Y adjustments in horizontal text or X adjustments in |
Nathan Willis | d3178aa | 2019-03-17 14:27:27 +0000 | [diff] [blame] | 106 | * vertical text) in the 'kern' table. |
| 107 | * |
| 108 | * Does NOT examine the GPOS table. |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 109 | * |
| 110 | * Return value: true is data found, false otherwise |
| 111 | * |
| 112 | **/ |
Behdad Esfahbod | 7489622 | 2018-11-23 11:10:17 -0500 | [diff] [blame] | 113 | bool |
Behdad Esfahbod | ca23567 | 2018-11-07 16:19:51 -0500 | [diff] [blame] | 114 | hb_ot_layout_has_cross_kerning (hb_face_t *face) |
| 115 | { |
| 116 | return face->table.kern->has_cross_stream (); |
| 117 | } |
| 118 | |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 119 | void |
Behdad Esfahbod | c221dc0 | 2018-11-14 14:49:34 -0500 | [diff] [blame] | 120 | hb_ot_layout_kern (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 095f5ad | 2018-11-02 13:23:54 -0400 | [diff] [blame] | 121 | hb_font_t *font, |
| 122 | hb_buffer_t *buffer) |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 123 | { |
Behdad Esfahbod | a35c92c | 2018-11-05 22:58:43 -0500 | [diff] [blame] | 124 | hb_blob_t *blob = font->face->table.kern.get_blob (); |
Behdad Esfahbod | fa3ebf8 | 2018-11-05 23:34:07 -0500 | [diff] [blame] | 125 | const AAT::kern& kern = *blob->as<AAT::kern> (); |
Behdad Esfahbod | 095f5ad | 2018-11-02 13:23:54 -0400 | [diff] [blame] | 126 | |
| 127 | AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); |
| 128 | |
| 129 | kern.apply (&c); |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | /* |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 134 | * GDEF |
| 135 | */ |
| 136 | |
Behdad Esfahbod | 4f21703 | 2018-11-25 15:59:18 -0500 | [diff] [blame] | 137 | bool |
| 138 | OT::GDEF::is_blacklisted (hb_blob_t *blob, |
| 139 | hb_face_t *face) const |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 140 | { |
Behdad Esfahbod | 227d85e | 2019-05-10 23:15:58 -0700 | [diff] [blame] | 141 | #ifdef HB_NO_OT_LAYOUT_BLACKLIST |
Behdad Esfahbod | 9ddbfa0 | 2019-04-12 09:33:25 -0400 | [diff] [blame] | 142 | return false; |
| 143 | #endif |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 144 | /* The ugly business of blacklisting individual fonts' tables happen here! |
| 145 | * See this thread for why we finally had to bend in and do this: |
| 146 | * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html |
| 147 | * |
| 148 | * In certain versions of Times New Roman Italic and Bold Italic, |
| 149 | * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark) |
| 150 | * in GDEF. Many versions of Tahoma have bad GDEF tables that |
| 151 | * incorrectly classify some spacing marks such as certain IPA |
| 152 | * symbols as glyph class 3. So do older versions of Microsoft |
| 153 | * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04. |
| 154 | * |
| 155 | * Nuke the GDEF tables of to avoid unwanted width-zeroing. |
| 156 | * |
| 157 | * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 |
| 158 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693 |
| 159 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875 |
| 160 | */ |
Behdad Esfahbod | 4ed9fb1 | 2018-11-25 15:51:01 -0500 | [diff] [blame] | 161 | #define ENCODE(x,y,z) (((uint64_t) (x) << 48) | ((uint64_t) (y) << 24) | (uint64_t) (z)) |
Behdad Esfahbod | 4f21703 | 2018-11-25 15:59:18 -0500 | [diff] [blame] | 162 | switch ENCODE(blob->length, |
| 163 | face->table.GSUB->table.get_length (), |
| 164 | face->table.GPOS->table.get_length ()) |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 165 | { |
| 166 | /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */ |
| 167 | case ENCODE (442, 2874, 42038): |
| 168 | /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */ |
| 169 | case ENCODE (430, 2874, 40662): |
| 170 | /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */ |
| 171 | case ENCODE (442, 2874, 39116): |
| 172 | /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */ |
| 173 | case ENCODE (430, 2874, 39374): |
| 174 | /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */ |
| 175 | case ENCODE (490, 3046, 41638): |
| 176 | /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */ |
| 177 | case ENCODE (478, 3046, 41902): |
| 178 | /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */ |
| 179 | case ENCODE (898, 12554, 46470): |
| 180 | /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */ |
| 181 | case ENCODE (910, 12566, 47732): |
| 182 | /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */ |
| 183 | case ENCODE (928, 23298, 59332): |
| 184 | /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */ |
| 185 | case ENCODE (940, 23310, 60732): |
| 186 | /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 187 | case ENCODE (964, 23836, 60072): |
| 188 | /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 189 | case ENCODE (976, 23832, 61456): |
| 190 | /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */ |
| 191 | case ENCODE (994, 24474, 60336): |
| 192 | /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */ |
| 193 | case ENCODE (1006, 24470, 61740): |
| 194 | /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 195 | case ENCODE (1006, 24576, 61346): |
| 196 | /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 197 | case ENCODE (1018, 24572, 62828): |
| 198 | /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5 tahoma.ttf from Windows 10 AU */ |
| 199 | case ENCODE (1006, 24576, 61352): |
| 200 | /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2 tahomabd.ttf from Windows 10 AU */ |
| 201 | case ENCODE (1018, 24572, 62834): |
| 202 | /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */ |
| 203 | case ENCODE (832, 7324, 47162): |
| 204 | /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */ |
| 205 | case ENCODE (844, 7302, 45474): |
| 206 | /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc himalaya.ttf from Windows 7 */ |
| 207 | case ENCODE (180, 13054, 7254): |
| 208 | /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */ |
| 209 | case ENCODE (192, 12638, 7254): |
| 210 | /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */ |
| 211 | case ENCODE (192, 12690, 7254): |
| 212 | /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */ |
| 213 | /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */ |
| 214 | case ENCODE (188, 248, 3852): |
| 215 | /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */ |
| 216 | /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */ |
| 217 | case ENCODE (188, 264, 3426): |
| 218 | /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */ |
| 219 | case ENCODE (1058, 47032, 11818): |
| 220 | /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/ |
| 221 | case ENCODE (1046, 47030, 12600): |
| 222 | /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */ |
| 223 | case ENCODE (1058, 71796, 16770): |
| 224 | /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */ |
| 225 | case ENCODE (1046, 71790, 17862): |
| 226 | /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */ |
| 227 | case ENCODE (1046, 71788, 17112): |
| 228 | /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */ |
| 229 | case ENCODE (1058, 71794, 17514): |
| 230 | /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */ |
| 231 | case ENCODE (1330, 109904, 57938): |
| 232 | /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */ |
| 233 | case ENCODE (1330, 109904, 58972): |
| 234 | /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85 Padauk.ttf |
| 235 | * "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */ |
| 236 | case ENCODE (1004, 59092, 14836): |
| 237 | return true; |
| 238 | #undef ENCODE |
| 239 | } |
| 240 | return false; |
| 241 | } |
| 242 | |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 243 | static void |
| 244 | _hb_ot_layout_set_glyph_props (hb_font_t *font, |
| 245 | hb_buffer_t *buffer) |
| 246 | { |
| 247 | _hb_buffer_assert_gsubgpos_vars (buffer); |
| 248 | |
Behdad Esfahbod | 5e68cec | 2018-11-05 23:23:57 -0500 | [diff] [blame] | 249 | const OT::GDEF &gdef = *font->face->table.GDEF->table; |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 250 | unsigned int count = buffer->len; |
| 251 | for (unsigned int i = 0; i < count; i++) |
| 252 | { |
| 253 | _hb_glyph_info_set_glyph_props (&buffer->info[i], gdef.get_glyph_props (buffer->info[i].codepoint)); |
| 254 | _hb_glyph_info_clear_lig_props (&buffer->info[i]); |
| 255 | buffer->info[i].syllable() = 0; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /* Public API */ |
| 260 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 261 | /** |
| 262 | * hb_ot_layout_has_glyph_classes: |
| 263 | * @face: #hb_face_t to work upon |
| 264 | * |
| 265 | * Tests whether a face has any glyph classes defined in its GDEF table. |
| 266 | * |
| 267 | * Return value: true if data found, false otherwise |
| 268 | * |
| 269 | **/ |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 270 | hb_bool_t |
Behdad Esfahbod | 52ea477 | 2009-11-06 17:45:38 -0500 | [diff] [blame] | 271 | hb_ot_layout_has_glyph_classes (hb_face_t *face) |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 272 | { |
Behdad Esfahbod | 5e68cec | 2018-11-05 23:23:57 -0500 | [diff] [blame] | 273 | return face->table.GDEF->table->has_glyph_classes (); |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 274 | } |
| 275 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 276 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 277 | * hb_ot_layout_get_glyph_class: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 278 | * @face: The #hb_face_t to work on |
| 279 | * @glyph: The #hb_codepoint_t code point to query |
| 280 | * |
| 281 | * Fetches the GDEF class of the requested glyph in the specified face. |
| 282 | * |
Nathan Willis | c08ddbd | 2019-03-24 15:07:07 +0000 | [diff] [blame] | 283 | * Return value: The #hb_ot_layout_glyph_class_t glyph class of the given code |
| 284 | * point in the GDEF table of the face. |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 285 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 286 | * Since: 0.9.7 |
| 287 | **/ |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 288 | hb_ot_layout_glyph_class_t |
| 289 | hb_ot_layout_get_glyph_class (hb_face_t *face, |
| 290 | hb_codepoint_t glyph) |
| 291 | { |
Behdad Esfahbod | 5e68cec | 2018-11-05 23:23:57 -0500 | [diff] [blame] | 292 | return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph); |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 293 | } |
Behdad Esfahbod | 4a2d844 | 2010-11-03 15:28:56 -0400 | [diff] [blame] | 294 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 295 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 296 | * hb_ot_layout_get_glyphs_in_class: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 297 | * @face: The #hb_face_t to work on |
| 298 | * @klass: The #hb_ot_layout_glyph_class_t GDEF class to retrieve |
| 299 | * @glyphs: (out): The #hb_set_t set of all glyphs belonging to the requested |
| 300 | * class. |
| 301 | * |
| 302 | * Retrieves the set of all glyphs from the face that belong to the requested |
| 303 | * glyph class in the face's GDEF table. |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 304 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 305 | * Since: 0.9.7 |
| 306 | **/ |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 307 | void |
| 308 | hb_ot_layout_get_glyphs_in_class (hb_face_t *face, |
| 309 | hb_ot_layout_glyph_class_t klass, |
| 310 | hb_set_t *glyphs /* OUT */) |
| 311 | { |
Behdad Esfahbod | 5e68cec | 2018-11-05 23:23:57 -0500 | [diff] [blame] | 312 | return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs); |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * hb_ot_layout_get_attach_points: |
| 318 | * @face: The #hb_face_t to work on |
| 319 | * @glyph: The #hb_codepoint_t code point to query |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 320 | * @start_offset: offset of the first attachment point to retrieve |
| 321 | * @point_count: (inout) (allow-none): Input = the maximum number of attachment points to return; |
| 322 | * Output = the actual number of attachment points returned (may be zero) |
| 323 | * @point_array: (out) (array length=point_count): The array of attachment points found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 324 | * |
| 325 | * Fetches a list of all attachment points for the specified glyph in the GDEF |
| 326 | * table of the face. The list returned will begin at the offset provided. |
| 327 | * |
| 328 | * Useful if the client program wishes to cache the list. |
| 329 | * |
| 330 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 331 | unsigned int |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 332 | hb_ot_layout_get_attach_points (hb_face_t *face, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 333 | hb_codepoint_t glyph, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 334 | unsigned int start_offset, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 335 | unsigned int *point_count /* IN/OUT */, |
| 336 | unsigned int *point_array /* OUT */) |
| 337 | { |
Behdad Esfahbod | 5a48611 | 2019-05-11 00:19:03 -0700 | [diff] [blame] | 338 | #ifdef HB_NO_OT_LAYOUT_UNUSED |
| 339 | if (point_count) |
| 340 | *point_count = 0; |
| 341 | return 0; |
| 342 | #endif |
| 343 | |
Behdad Esfahbod | 5e68cec | 2018-11-05 23:23:57 -0500 | [diff] [blame] | 344 | return face->table.GDEF->table->get_attach_points (glyph, |
| 345 | start_offset, |
| 346 | point_count, |
| 347 | point_array); |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 350 | |
| 351 | /** |
| 352 | * hb_ot_layout_get_ligature_carets: |
| 353 | * @font: The #hb_font_t to work on |
| 354 | * @direction: The #hb_direction_t text direction to use |
| 355 | * @glyph: The #hb_codepoint_t code point to query |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 356 | * @start_offset: offset of the first caret position to retrieve |
| 357 | * @caret_count: (inout) (allow-none): Input = the maximum number of caret positions to return; |
| 358 | * Output = the actual number of caret positions returned (may be zero) |
| 359 | * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 360 | * |
| 361 | * Fetches a list of the caret positions defined for a ligature glyph in the GDEF |
| 362 | * table of the font. The list returned will begin at the offset provided. |
| 363 | * |
| 364 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 365 | unsigned int |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 366 | hb_ot_layout_get_ligature_carets (hb_font_t *font, |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 367 | hb_direction_t direction, |
| 368 | hb_codepoint_t glyph, |
| 369 | unsigned int start_offset, |
| 370 | unsigned int *caret_count /* IN/OUT */, |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 371 | hb_position_t *caret_array /* OUT */) |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 372 | { |
Behdad Esfahbod | 5a48611 | 2019-05-11 00:19:03 -0700 | [diff] [blame] | 373 | #ifdef HB_NO_OT_LAYOUT_UNUSED |
| 374 | if (caret_count) |
| 375 | *caret_count = 0; |
| 376 | return 0; |
| 377 | #endif |
| 378 | |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 379 | unsigned int result_caret_count = 0; |
| 380 | unsigned int result = font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, &result_caret_count, caret_array); |
| 381 | if (result) |
| 382 | { |
| 383 | if (caret_count) *caret_count = result_caret_count; |
| 384 | } |
| 385 | else |
| 386 | result = font->face->table.lcar->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); |
| 387 | return result; |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 390 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 391 | /* |
| 392 | * GSUB/GPOS |
| 393 | */ |
| 394 | |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 395 | bool |
| 396 | OT::GSUB::is_blacklisted (hb_blob_t *blob HB_UNUSED, |
| 397 | hb_face_t *face) const |
| 398 | { |
Behdad Esfahbod | 227d85e | 2019-05-10 23:15:58 -0700 | [diff] [blame] | 399 | #ifdef HB_NO_OT_LAYOUT_BLACKLIST |
Behdad Esfahbod | 9ddbfa0 | 2019-04-12 09:33:25 -0400 | [diff] [blame] | 400 | return false; |
| 401 | #endif |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 402 | /* Mac OS X prefers morx over GSUB. It also ships with various Indic fonts, |
| 403 | * all by 'MUTF' foundry (Tamil MN, Tamil Sangam MN, etc.), that have broken |
| 404 | * GSUB/GPOS tables. Some have GSUB with zero scripts, those are ignored by |
| 405 | * our morx/GSUB preference code. But if GSUB has non-zero scripts, we tend |
| 406 | * to prefer it over morx because we want to be consistent with other OpenType |
| 407 | * shapers. |
| 408 | * |
| 409 | * To work around broken Indic Mac system fonts, we ignore GSUB table if |
| 410 | * OS/2 VendorId is 'MUTF' and font has morx table as well. |
| 411 | * |
| 412 | * https://github.com/harfbuzz/harfbuzz/issues/1410 |
| 413 | * https://github.com/harfbuzz/harfbuzz/issues/1348 |
| 414 | * https://github.com/harfbuzz/harfbuzz/issues/1391 |
| 415 | */ |
| 416 | if (unlikely (face->table.OS2->achVendID == HB_TAG ('M','U','T','F') && |
| 417 | face->table.morx->has_data ())) |
| 418 | return true; |
| 419 | |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | bool |
| 424 | OT::GPOS::is_blacklisted (hb_blob_t *blob HB_UNUSED, |
| 425 | hb_face_t *face HB_UNUSED) const |
| 426 | { |
Behdad Esfahbod | 227d85e | 2019-05-10 23:15:58 -0700 | [diff] [blame] | 427 | #ifdef HB_NO_OT_LAYOUT_BLACKLIST |
Behdad Esfahbod | 9ddbfa0 | 2019-04-12 09:33:25 -0400 | [diff] [blame] | 428 | return false; |
| 429 | #endif |
Behdad Esfahbod | 574d888 | 2018-11-25 16:51:22 -0500 | [diff] [blame] | 430 | return false; |
| 431 | } |
| 432 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 433 | static const OT::GSUBGPOS& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 434 | get_gsubgpos_table (hb_face_t *face, |
| 435 | hb_tag_t table_tag) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 436 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 437 | switch (table_tag) { |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 438 | case HB_OT_TAG_GSUB: return *face->table.GSUB->table; |
| 439 | case HB_OT_TAG_GPOS: return *face->table.GPOS->table; |
Behdad Esfahbod | abc12f7 | 2018-05-08 02:23:36 -0700 | [diff] [blame] | 440 | default: return Null(OT::GSUBGPOS); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
| 444 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 445 | /** |
| 446 | * hb_ot_layout_table_get_script_tags: |
| 447 | * @face: #hb_face_t to work upon |
| 448 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 449 | * @start_offset: offset of the first script tag to retrieve |
| 450 | * @script_count: (inout) (allow-none): Input = the maximum number of script tags to return; |
| 451 | * Output = the actual number of script tags returned (may be zero) |
| 452 | * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 453 | * |
| 454 | * Fetches a list of all scripts enumerated in the specified face's GSUB table |
| 455 | * or GPOS table. The list returned will begin at the offset provided. |
| 456 | * |
| 457 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 458 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 459 | hb_ot_layout_table_get_script_tags (hb_face_t *face, |
| 460 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 461 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 462 | unsigned int *script_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 463 | hb_tag_t *script_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 464 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 465 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 466 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 467 | return g.get_script_tags (start_offset, script_count, script_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 468 | } |
| 469 | |
Behdad Esfahbod | eb45c0a | 2013-01-16 22:07:50 -0600 | [diff] [blame] | 470 | #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
| 471 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 472 | /** |
| 473 | * hb_ot_layout_table_find_script: |
| 474 | * @face: #hb_face_t to work upon |
| 475 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 476 | * @script_tag: #hb_tag_t of the script tag requested |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 477 | * @script_index: (out): The index of the requested script tag |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 478 | * |
| 479 | * Fetches the index if a given script tag in the specified face's GSUB table |
| 480 | * or GPOS table. |
| 481 | * |
| 482 | * Return value: true if the script is found, false otherwise |
| 483 | * |
| 484 | **/ |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 485 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 486 | hb_ot_layout_table_find_script (hb_face_t *face, |
| 487 | hb_tag_t table_tag, |
| 488 | hb_tag_t script_tag, |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 489 | unsigned int *script_index /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 490 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 491 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), ""); |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 492 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 493 | |
| 494 | if (g.find_script_index (script_tag, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 495 | return true; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 496 | |
| 497 | /* try finding 'DFLT' */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 498 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 499 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 500 | |
Behdad Esfahbod | dca8aff | 2010-09-28 16:25:23 -0400 | [diff] [blame] | 501 | /* try with 'dflt'; MS site has had typos and many fonts use it now :(. |
| 502 | * including many versions of DejaVu Sans Mono! */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 503 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 504 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 505 | |
Behdad Esfahbod | eb45c0a | 2013-01-16 22:07:50 -0600 | [diff] [blame] | 506 | /* try with 'latn'; some old fonts put their features there even though |
| 507 | they're really trying to support Thai, for example :( */ |
| 508 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) |
| 509 | return false; |
| 510 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 511 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 512 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame^] | 515 | #ifndef HB_DISABLE_DEPRECATED |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 516 | /** |
| 517 | * hb_ot_layout_table_choose_script: |
| 518 | * @face: #hb_face_t to work upon |
| 519 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 520 | * @script_tags: Array of #hb_tag_t script tags |
Nathan Willis | 6c0a1e8 | 2019-03-17 14:50:47 +0000 | [diff] [blame] | 521 | * @script_index: (out): The index of the requested script tag |
| 522 | * @chosen_script: (out): #hb_tag_t of the script tag requested |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 523 | * |
Nathan Willis | c08ddbd | 2019-03-24 15:07:07 +0000 | [diff] [blame] | 524 | * Deprecated since 2.0.0 |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 525 | **/ |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 526 | hb_bool_t |
| 527 | hb_ot_layout_table_choose_script (hb_face_t *face, |
| 528 | hb_tag_t table_tag, |
| 529 | const hb_tag_t *script_tags, |
Nathan Willis | 6c0a1e8 | 2019-03-17 14:50:47 +0000 | [diff] [blame] | 530 | unsigned int *script_index /* OUT */, |
| 531 | hb_tag_t *chosen_script /* OUT */) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 532 | { |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 533 | const hb_tag_t *t; |
| 534 | for (t = script_tags; *t; t++); |
| 535 | return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script); |
| 536 | } |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame^] | 537 | #endif |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 538 | |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 539 | /** |
| 540 | * hb_ot_layout_table_select_script: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 541 | * @face: #hb_face_t to work upon |
| 542 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 543 | * @script_count: Number of script tags in the array |
| 544 | * @script_tags: Array of #hb_tag_t script tags |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 545 | * @script_index: (out): The index of the requested script |
| 546 | * @chosen_script: (out): #hb_tag_t of the requested script |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 547 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 548 | * Since: 2.0.0 |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 549 | **/ |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 550 | hb_bool_t |
| 551 | hb_ot_layout_table_select_script (hb_face_t *face, |
| 552 | hb_tag_t table_tag, |
| 553 | unsigned int script_count, |
| 554 | const hb_tag_t *script_tags, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 555 | unsigned int *script_index /* OUT */, |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 556 | hb_tag_t *chosen_script /* OUT */) |
| 557 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 558 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), ""); |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 559 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 560 | unsigned int i; |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 561 | |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 562 | for (i = 0; i < script_count; i++) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 563 | { |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 564 | if (g.find_script_index (script_tags[i], script_index)) |
| 565 | { |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 566 | if (chosen_script) |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 567 | *chosen_script = script_tags[i]; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 568 | return true; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 569 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /* try finding 'DFLT' */ |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 573 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
| 574 | if (chosen_script) |
| 575 | *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 576 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 577 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 578 | |
| 579 | /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 580 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { |
| 581 | if (chosen_script) |
| 582 | *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 583 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 584 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 585 | |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 586 | /* try with 'latn'; some old fonts put their features there even though |
| 587 | they're really trying to support Thai, for example :( */ |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 588 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { |
| 589 | if (chosen_script) |
| 590 | *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 591 | return false; |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 594 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 595 | if (chosen_script) |
| 596 | *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 597 | return false; |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * hb_ot_layout_table_get_feature_tags: |
| 603 | * @face: #hb_face_t to work upon |
| 604 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 605 | * @start_offset: offset of the first feature tag to retrieve |
| 606 | * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return; |
| 607 | * Output = the actual number of feature tags returned (may be zero) |
| 608 | * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 609 | * |
| 610 | * Fetches a list of all feature tags in the given face's GSUB or GPOS table. |
| 611 | * |
| 612 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 613 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 614 | hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
| 615 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 616 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 617 | unsigned int *feature_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 618 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 619 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 620 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 621 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 622 | return g.get_feature_tags (start_offset, feature_count, feature_tags); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 623 | } |
| 624 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 625 | |
| 626 | /** |
| 627 | * hb_ot_layout_table_find_feature: |
| 628 | * @face: #hb_face_t to work upon |
| 629 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 630 | * @feature_tag: The #hb_tag_t og the requested feature tag |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 631 | * @feature_index: (out): The index of the requested feature |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 632 | * |
| 633 | * Fetches the index for a given feature tag in the specified face's GSUB table |
| 634 | * or GPOS table. |
| 635 | * |
| 636 | * Return value: true if the feature is found, false otherwise |
| 637 | **/ |
Behdad Esfahbod | 385f78b | 2018-11-07 17:19:21 -0500 | [diff] [blame] | 638 | bool |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 639 | hb_ot_layout_table_find_feature (hb_face_t *face, |
| 640 | hb_tag_t table_tag, |
| 641 | hb_tag_t feature_tag, |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 642 | unsigned int *feature_index /* OUT */) |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 643 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 644 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), ""); |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 645 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 646 | |
| 647 | unsigned int num_features = g.get_feature_count (); |
| 648 | for (unsigned int i = 0; i < num_features; i++) |
| 649 | { |
| 650 | if (feature_tag == g.get_feature_tag (i)) { |
| 651 | if (feature_index) *feature_index = i; |
| 652 | return true; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
| 657 | return false; |
| 658 | } |
| 659 | |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 660 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 661 | /** |
| 662 | * hb_ot_layout_script_get_language_tags: |
| 663 | * @face: #hb_face_t to work upon |
| 664 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 665 | * @script_index: The index of the requested script tag |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 666 | * @start_offset: offset of the first language tag to retrieve |
| 667 | * @language_count: (inout) (allow-none): Input = the maximum number of language tags to return; |
| 668 | * Output = the actual number of language tags returned (may be zero) |
| 669 | * @language_tags: (out) (array length=language_count): Array of language tags found in the table |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 670 | * |
| 671 | * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath |
| 672 | * the specified script index. The list returned will begin at the offset provided. |
| 673 | * |
| 674 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 675 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 676 | hb_ot_layout_script_get_language_tags (hb_face_t *face, |
| 677 | hb_tag_t table_tag, |
| 678 | unsigned int script_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 679 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 680 | unsigned int *language_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 681 | hb_tag_t *language_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 682 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 683 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 684 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 685 | return s.get_lang_sys_tags (start_offset, language_count, language_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 686 | } |
| 687 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 688 | |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame^] | 689 | #ifndef HB_DISABLE_DEPRECATED |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 690 | /** |
| 691 | * hb_ot_layout_script_find_language: |
| 692 | * @face: #hb_face_t to work upon |
| 693 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 694 | * @script_index: The index of the requested script tag |
| 695 | * @language_tag: The #hb_tag_t of the requested language |
| 696 | * @language_index: The index of the requested language |
| 697 | * |
| 698 | * Fetches the index of a given language tag in the specified face's GSUB table |
| 699 | * or GPOS table, underneath the specified script tag. |
| 700 | * |
| 701 | * Return value: true if the language tag is found, false otherwise |
| 702 | * |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame^] | 703 | * Since: ?? |
| 704 | * Deprecated: ?? |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 705 | **/ |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 706 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 707 | hb_ot_layout_script_find_language (hb_face_t *face, |
| 708 | hb_tag_t table_tag, |
| 709 | unsigned int script_index, |
| 710 | hb_tag_t language_tag, |
| 711 | unsigned int *language_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 712 | { |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 713 | return hb_ot_layout_script_select_language (face, |
| 714 | table_tag, |
| 715 | script_index, |
| 716 | 1, |
| 717 | &language_tag, |
| 718 | language_index); |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 719 | } |
Behdad Esfahbod | fca2786 | 2019-05-11 00:37:01 -0700 | [diff] [blame^] | 720 | #endif |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 721 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 722 | |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 723 | /** |
| 724 | * hb_ot_layout_script_select_language: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 725 | * @face: #hb_face_t to work upon |
| 726 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 727 | * @script_index: The index of the requested script tag |
| 728 | * @language_count: The number of languages in the specified script |
| 729 | * @language_tags: The array of language tags |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 730 | * @language_index: (out): The index of the requested language |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 731 | * |
| 732 | * Fetches the index of a given language tag in the specified face's GSUB table |
| 733 | * or GPOS table, underneath the specified script index. |
| 734 | * |
| 735 | * Return value: true if the language tag is found, false otherwise |
| 736 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 737 | * Since: 2.0.0 |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 738 | **/ |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 739 | hb_bool_t |
Behdad Esfahbod | cf975ac | 2018-10-11 14:07:44 -0400 | [diff] [blame] | 740 | hb_ot_layout_script_select_language (hb_face_t *face, |
| 741 | hb_tag_t table_tag, |
| 742 | unsigned int script_index, |
| 743 | unsigned int language_count, |
| 744 | const hb_tag_t *language_tags, |
| 745 | unsigned int *language_index /* OUT */) |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 746 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 747 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), ""); |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 748 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 749 | unsigned int i; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 750 | |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 751 | for (i = 0; i < language_count; i++) |
| 752 | { |
| 753 | if (s.find_lang_sys_index (language_tags[i], language_index)) |
| 754 | return true; |
| 755 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 756 | |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 757 | /* try finding 'dflt' */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 758 | if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 759 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 760 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 761 | if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 762 | return false; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 763 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 764 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 765 | |
| 766 | /** |
| 767 | * hb_ot_layout_language_get_required_feature_index: |
| 768 | * @face: #hb_face_t to work upon |
| 769 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 770 | * @script_index: The index of the requested script tag |
| 771 | * @language_index: The index of the requested language tag |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 772 | * @feature_index: (out): The index of the requested feature |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 773 | * |
| 774 | * Fetches the index of a requested feature in the given face's GSUB or GPOS table, |
| 775 | * underneath the specified script and language. |
| 776 | * |
| 777 | * Return value: true if the feature is found, false otherwise |
| 778 | * |
| 779 | **/ |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 780 | hb_bool_t |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 781 | hb_ot_layout_language_get_required_feature_index (hb_face_t *face, |
| 782 | hb_tag_t table_tag, |
| 783 | unsigned int script_index, |
| 784 | unsigned int language_index, |
| 785 | unsigned int *feature_index) |
| 786 | { |
| 787 | return hb_ot_layout_language_get_required_feature (face, |
| 788 | table_tag, |
| 789 | script_index, |
| 790 | language_index, |
| 791 | feature_index, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 792 | nullptr); |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 793 | } |
| 794 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 795 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 796 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 797 | * hb_ot_layout_language_get_required_feature: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 798 | * @face: #hb_face_t to work upon |
| 799 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 800 | * @script_index: The index of the requested script tag |
| 801 | * @language_index: The index of the requested language tag |
| 802 | * @feature_index: The index of the requested feature |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 803 | * @feature_tag: (out): The #hb_tag_t of the requested feature |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 804 | * |
| 805 | * Fetches the tag of a requested feature index in the given face's GSUB or GPOS table, |
| 806 | * underneath the specified script and language. |
| 807 | * |
| 808 | * Return value: true if the feature is found, false otherwise |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 809 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 810 | * Since: 0.9.30 |
| 811 | **/ |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 812 | hb_bool_t |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 813 | hb_ot_layout_language_get_required_feature (hb_face_t *face, |
| 814 | hb_tag_t table_tag, |
| 815 | unsigned int script_index, |
| 816 | unsigned int language_index, |
| 817 | unsigned int *feature_index, |
| 818 | hb_tag_t *feature_tag) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 819 | { |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 820 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 821 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 822 | |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 823 | unsigned int index = l.get_required_feature_index (); |
| 824 | if (feature_index) *feature_index = index; |
| 825 | if (feature_tag) *feature_tag = g.get_feature_tag (index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 826 | |
| 827 | return l.has_required_feature (); |
| 828 | } |
| 829 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 830 | |
| 831 | /** |
| 832 | * hb_ot_layout_language_get_feature_indexes: |
| 833 | * @face: #hb_face_t to work upon |
| 834 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 835 | * @script_index: The index of the requested script tag |
| 836 | * @language_index: The index of the requested language tag |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 837 | * @start_offset: offset of the first feature tag to retrieve |
| 838 | * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return; |
| 839 | * Output: the actual number of feature tags returned (may be zero) |
| 840 | * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 841 | * |
| 842 | * Fetches a list of all features in the specified face's GSUB table |
| 843 | * or GPOS table, underneath the specified script and language. The list |
| 844 | * returned will begin at the offset provided. |
| 845 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 846 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 847 | hb_ot_layout_language_get_feature_indexes (hb_face_t *face, |
| 848 | hb_tag_t table_tag, |
| 849 | unsigned int script_index, |
| 850 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 851 | unsigned int start_offset, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 852 | unsigned int *feature_count /* IN/OUT */, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 853 | unsigned int *feature_indexes /* OUT */) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 854 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 855 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 856 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 857 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 858 | return l.get_feature_indexes (start_offset, feature_count, feature_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 859 | } |
| 860 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 861 | |
| 862 | /** |
| 863 | * hb_ot_layout_language_get_feature_tags: |
| 864 | * @face: #hb_face_t to work upon |
| 865 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 866 | * @script_index: The index of the requested script tag |
| 867 | * @language_index: The index of the requested language tag |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 868 | * @start_offset: offset of the first feature tag to retrieve |
| 869 | * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return; |
| 870 | * Output = the actual number of feature tags returned (may be zero) |
| 871 | * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 872 | * |
| 873 | * Fetches a list of all features in the specified face's GSUB table |
| 874 | * or GPOS table, underneath the specified script and language. The list |
| 875 | * returned will begin at the offset provided. |
| 876 | * |
| 877 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 878 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 879 | hb_ot_layout_language_get_feature_tags (hb_face_t *face, |
| 880 | hb_tag_t table_tag, |
| 881 | unsigned int script_index, |
| 882 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 883 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 884 | unsigned int *feature_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 885 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 886 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 887 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 888 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 889 | |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 890 | static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), ""); |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 891 | unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags); |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 892 | |
Behdad Esfahbod | 9897749 | 2009-08-27 01:32:17 -0400 | [diff] [blame] | 893 | if (feature_tags) { |
| 894 | unsigned int count = *feature_count; |
| 895 | for (unsigned int i = 0; i < count; i++) |
| 896 | feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); |
| 897 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 898 | |
| 899 | return ret; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 900 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 901 | |
| 902 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 903 | /** |
| 904 | * hb_ot_layout_language_find_feature: |
| 905 | * @face: #hb_face_t to work upon |
| 906 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 907 | * @script_index: The index of the requested script tag |
| 908 | * @language_index: The index of the requested language tag |
| 909 | * @feature_tag: #hb_tag_t of the feature tag requested |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 910 | * @feature_index: (out): The index of the requested feature |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 911 | * |
| 912 | * Fetches the index of a given feature tag in the specified face's GSUB table |
| 913 | * or GPOS table, underneath the specified script and language. |
| 914 | * |
| 915 | * Return value: true if the feature is found, false otherwise |
| 916 | * |
| 917 | **/ |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 918 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 919 | hb_ot_layout_language_find_feature (hb_face_t *face, |
| 920 | hb_tag_t table_tag, |
| 921 | unsigned int script_index, |
| 922 | unsigned int language_index, |
| 923 | hb_tag_t feature_tag, |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 924 | unsigned int *feature_index /* OUT */) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 925 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 926 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), ""); |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 927 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 928 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 929 | |
Behdad Esfahbod | f4c9514 | 2009-05-17 04:59:56 -0400 | [diff] [blame] | 930 | unsigned int num_features = l.get_feature_count (); |
| 931 | for (unsigned int i = 0; i < num_features; i++) { |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 932 | unsigned int f_index = l.get_feature_index (i); |
| 933 | |
| 934 | if (feature_tag == g.get_feature_tag (f_index)) { |
| 935 | if (feature_index) *feature_index = f_index; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 936 | return true; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
| 940 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 941 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 942 | } |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 943 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 944 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 945 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 946 | * hb_ot_layout_feature_get_lookups: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 947 | * @face: #hb_face_t to work upon |
| 948 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 949 | * @feature_index: The index of the requested feature |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 950 | * @start_offset: offset of the first lookup to retrieve |
| 951 | * @lookup_count: (inout) (allow-none): Input = the maximum number of lookups to return; |
| 952 | * Output = the actual number of lookups returned (may be zero) |
| 953 | * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 954 | * |
| 955 | * Fetches a list of all lookups enumerated for the specified feature, in |
| 956 | * the specified face's GSUB table or GPOS table. The list returned will |
| 957 | * begin at the offset provided. |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 958 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 959 | * Since: 0.9.7 |
| 960 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 961 | unsigned int |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 962 | hb_ot_layout_feature_get_lookups (hb_face_t *face, |
| 963 | hb_tag_t table_tag, |
| 964 | unsigned int feature_index, |
| 965 | unsigned int start_offset, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 966 | unsigned int *lookup_count /* IN/OUT */, |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 967 | unsigned int *lookup_indexes /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 968 | { |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 969 | return hb_ot_layout_feature_with_variations_get_lookups (face, |
| 970 | table_tag, |
| 971 | feature_index, |
| 972 | HB_OT_LAYOUT_NO_VARIATIONS_INDEX, |
| 973 | start_offset, |
| 974 | lookup_count, |
| 975 | lookup_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 976 | } |
| 977 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 978 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 979 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 980 | * hb_ot_layout_table_get_lookup_count: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 981 | * @face: #hb_face_t to work upon |
| 982 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 983 | * |
| 984 | * Fetches the total number of lookups enumerated in the specified |
| 985 | * face's GSUB table or GPOS table. |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 986 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 987 | * Since: 0.9.22 |
| 988 | **/ |
Behdad Esfahbod | 27674b4 | 2013-10-03 14:54:50 -0400 | [diff] [blame] | 989 | unsigned int |
| 990 | hb_ot_layout_table_get_lookup_count (hb_face_t *face, |
| 991 | hb_tag_t table_tag) |
| 992 | { |
Behdad Esfahbod | 96828b9 | 2018-10-25 20:34:29 -0700 | [diff] [blame] | 993 | return get_gsubgpos_table (face, table_tag).get_lookup_count (); |
Behdad Esfahbod | 27674b4 | 2013-10-03 14:54:50 -0400 | [diff] [blame] | 994 | } |
| 995 | |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 996 | |
| 997 | struct hb_collect_features_context_t |
| 998 | { |
| 999 | hb_collect_features_context_t (hb_face_t *face, |
| 1000 | hb_tag_t table_tag, |
| 1001 | hb_set_t *feature_indexes_) |
| 1002 | : g (get_gsubgpos_table (face, table_tag)), |
Garret Rieger | 0e1ad5a | 2018-10-30 11:29:58 -0700 | [diff] [blame] | 1003 | feature_indexes (feature_indexes_), |
Behdad Esfahbod | bfd549d | 2018-10-30 14:47:27 -0700 | [diff] [blame] | 1004 | script_count(0),langsys_count(0) {} |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1005 | |
Ebrahim Byagowi | d0a706c | 2018-12-22 19:47:48 +0330 | [diff] [blame] | 1006 | bool visited (const OT::Script &s) |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1007 | { |
| 1008 | /* We might have Null() object here. Don't want to involve |
| 1009 | * that in the memoize. So, detect empty objects and return. */ |
| 1010 | if (unlikely (!s.has_default_lang_sys () && |
| 1011 | !s.get_lang_sys_count ())) |
| 1012 | return true; |
| 1013 | |
Garret Rieger | 0e1ad5a | 2018-10-30 11:29:58 -0700 | [diff] [blame] | 1014 | if (script_count++ > HB_MAX_SCRIPTS) |
| 1015 | return true; |
| 1016 | |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1017 | return visited (s, visited_script); |
| 1018 | } |
Ebrahim Byagowi | d0a706c | 2018-12-22 19:47:48 +0330 | [diff] [blame] | 1019 | bool visited (const OT::LangSys &l) |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1020 | { |
| 1021 | /* We might have Null() object here. Don't want to involve |
| 1022 | * that in the memoize. So, detect empty objects and return. */ |
| 1023 | if (unlikely (!l.has_required_feature () && |
| 1024 | !l.get_feature_count ())) |
| 1025 | return true; |
| 1026 | |
Garret Rieger | 0e1ad5a | 2018-10-30 11:29:58 -0700 | [diff] [blame] | 1027 | if (langsys_count++ > HB_MAX_LANGSYS) |
| 1028 | return true; |
| 1029 | |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1030 | return visited (l, visited_langsys); |
| 1031 | } |
| 1032 | |
| 1033 | private: |
| 1034 | template <typename T> |
Ebrahim Byagowi | d0a706c | 2018-12-22 19:47:48 +0330 | [diff] [blame] | 1035 | bool visited (const T &p, hb_set_t &visited_set) |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1036 | { |
| 1037 | hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g); |
| 1038 | if (visited_set.has (delta)) |
| 1039 | return true; |
| 1040 | |
| 1041 | visited_set.add (delta); |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | public: |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1046 | const OT::GSUBGPOS &g; |
| 1047 | hb_set_t *feature_indexes; |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1048 | |
| 1049 | private: |
Behdad Esfahbod | 3a4e5dd | 2018-10-29 18:05:25 -0700 | [diff] [blame] | 1050 | hb_set_t visited_script; |
| 1051 | hb_set_t visited_langsys; |
Garret Rieger | 0e1ad5a | 2018-10-30 11:29:58 -0700 | [diff] [blame] | 1052 | unsigned int script_count; |
| 1053 | unsigned int langsys_count; |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1054 | }; |
| 1055 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1056 | static void |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1057 | langsys_collect_features (hb_collect_features_context_t *c, |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1058 | const OT::LangSys &l, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1059 | const hb_tag_t *features) |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1060 | { |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1061 | if (c->visited (l)) return; |
| 1062 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1063 | if (!features) |
| 1064 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1065 | /* All features. */ |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1066 | if (l.has_required_feature ()) |
| 1067 | c->feature_indexes->add (l.get_required_feature_index ()); |
Behdad Esfahbod | 5f85c80 | 2013-06-26 20:14:18 -0400 | [diff] [blame] | 1068 | |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1069 | l.add_feature_indexes_to (c->feature_indexes); |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 1070 | } |
| 1071 | else |
| 1072 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1073 | /* Ugh. Any faster way? */ |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1074 | for (; *features; features++) |
| 1075 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1076 | hb_tag_t feature_tag = *features; |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1077 | unsigned int num_features = l.get_feature_count (); |
| 1078 | for (unsigned int i = 0; i < num_features; i++) |
| 1079 | { |
| 1080 | unsigned int feature_index = l.get_feature_index (i); |
| 1081 | |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1082 | if (feature_tag == c->g.get_feature_tag (feature_index)) |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1083 | { |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1084 | c->feature_indexes->add (feature_index); |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1085 | break; |
| 1086 | } |
| 1087 | } |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | static void |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1093 | script_collect_features (hb_collect_features_context_t *c, |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1094 | const OT::Script &s, |
| 1095 | const hb_tag_t *languages, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1096 | const hb_tag_t *features) |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1097 | { |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1098 | if (c->visited (s)) return; |
| 1099 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1100 | if (!languages) |
| 1101 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1102 | /* All languages. */ |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 1103 | if (s.has_default_lang_sys ()) |
| 1104 | langsys_collect_features (c, |
| 1105 | s.get_default_lang_sys (), |
| 1106 | features); |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1107 | |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1108 | unsigned int count = s.get_lang_sys_count (); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1109 | for (unsigned int language_index = 0; language_index < count; language_index++) |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1110 | langsys_collect_features (c, |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1111 | s.get_lang_sys (language_index), |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1112 | features); |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 1113 | } |
| 1114 | else |
| 1115 | { |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1116 | for (; *languages; languages++) |
| 1117 | { |
| 1118 | unsigned int language_index; |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1119 | if (s.find_lang_sys_index (*languages, &language_index)) |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1120 | langsys_collect_features (c, |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1121 | s.get_lang_sys (language_index), |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1122 | features); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1127 | |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1128 | /** |
Garret Rieger | 8973375 | 2018-07-30 18:10:43 -0700 | [diff] [blame] | 1129 | * hb_ot_layout_collect_features: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1130 | * @face: #hb_face_t to work upon |
| 1131 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 1132 | * @scripts: The array of scripts to collect features for |
| 1133 | * @languages: The array of languages to collect features for |
| 1134 | * @features: The array of features to collect |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 1135 | * @feature_indexes: (out): The array of feature indexes found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1136 | * |
| 1137 | * Fetches a list of all feature indexes in the specified face's GSUB table |
| 1138 | * or GPOS table, underneath the specified scripts, languages, and features. |
| 1139 | * If no list of scripts is provided, all scripts will be queried. If no list |
| 1140 | * of languages is provided, all languages will be queried. If no list of |
| 1141 | * features is provided, all features will be queried. |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1142 | * |
Behdad Esfahbod | 44d1fb3 | 2018-08-01 14:51:51 -0700 | [diff] [blame] | 1143 | * Since: 1.8.5 |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1144 | **/ |
| 1145 | void |
| 1146 | hb_ot_layout_collect_features (hb_face_t *face, |
| 1147 | hb_tag_t table_tag, |
| 1148 | const hb_tag_t *scripts, |
| 1149 | const hb_tag_t *languages, |
| 1150 | const hb_tag_t *features, |
| 1151 | hb_set_t *feature_indexes /* OUT */) |
| 1152 | { |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1153 | hb_collect_features_context_t c (face, table_tag, feature_indexes); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1154 | if (!scripts) |
| 1155 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 1156 | /* All scripts. */ |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1157 | unsigned int count = c.g.get_script_count (); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1158 | for (unsigned int script_index = 0; script_index < count; script_index++) |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1159 | script_collect_features (&c, |
| 1160 | c.g.get_script (script_index), |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1161 | languages, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1162 | features); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1163 | } |
| 1164 | else |
| 1165 | { |
| 1166 | for (; *scripts; scripts++) |
| 1167 | { |
| 1168 | unsigned int script_index; |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1169 | if (c.g.find_script_index (*scripts, &script_index)) |
| 1170 | script_collect_features (&c, |
| 1171 | c.g.get_script (script_index), |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 1172 | languages, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 1173 | features); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1178 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1179 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1180 | * hb_ot_layout_collect_lookups: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1181 | * @face: #hb_face_t to work upon |
| 1182 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 1183 | * @scripts: The array of scripts to collect lookups for |
| 1184 | * @languages: The array of languages to collect lookups for |
| 1185 | * @features: The array of features to collect lookups for |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 1186 | * @lookup_indexes: (out): The array of lookup indexes found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1187 | * |
| 1188 | * Fetches a list of all feature-lookup indexes in the specified face's GSUB |
| 1189 | * table or GPOS table, underneath the specified scripts, languages, and |
| 1190 | * features. If no list of scripts is provided, all scripts will be queried. |
| 1191 | * If no list of languages is provided, all languages will be queried. If no |
| 1192 | * list of features is provided, all features will be queried. |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1193 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1194 | * Since: 0.9.8 |
| 1195 | **/ |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1196 | void |
| 1197 | hb_ot_layout_collect_lookups (hb_face_t *face, |
| 1198 | hb_tag_t table_tag, |
| 1199 | const hb_tag_t *scripts, |
| 1200 | const hb_tag_t *languages, |
| 1201 | const hb_tag_t *features, |
| 1202 | hb_set_t *lookup_indexes /* OUT */) |
| 1203 | { |
Behdad Esfahbod | e98af6d | 2018-10-25 22:25:29 -0700 | [diff] [blame] | 1204 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1205 | |
Behdad Esfahbod | 3a4e5dd | 2018-10-29 18:05:25 -0700 | [diff] [blame] | 1206 | hb_set_t feature_indexes; |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 1207 | hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes); |
Behdad Esfahbod | e98af6d | 2018-10-25 22:25:29 -0700 | [diff] [blame] | 1208 | |
Behdad Esfahbod | c237cdf | 2018-10-25 21:17:30 -0700 | [diff] [blame] | 1209 | for (hb_codepoint_t feature_index = HB_SET_VALUE_INVALID; |
| 1210 | hb_set_next (&feature_indexes, &feature_index);) |
Behdad Esfahbod | e98af6d | 2018-10-25 22:25:29 -0700 | [diff] [blame] | 1211 | g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 1212 | } |
| 1213 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1214 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1215 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1216 | * hb_ot_layout_lookup_collect_glyphs: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1217 | * @face: #hb_face_t to work upon |
| 1218 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 1219 | * @lookup_index: The index of the feature lookup to query |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 1220 | * @glyphs_before: (out): Array of glyphs preceding the substitution range |
| 1221 | * @glyphs_input: (out): Array of input glyphs that would be substituted by the lookup |
| 1222 | * @glyphs_after: (out): Array of glyphs following the substition range |
| 1223 | * @glyphs_output: (out): Array of glyphs that would be the substitued output of the lookup |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1224 | * |
| 1225 | * Fetches a list of all glyphs affected by the specified lookup in the |
| 1226 | * specified face's GSUB table of GPOS table. |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1227 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1228 | * Since: 0.9.7 |
| 1229 | **/ |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 1230 | void |
| 1231 | hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, |
| 1232 | hb_tag_t table_tag, |
| 1233 | unsigned int lookup_index, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1234 | hb_set_t *glyphs_before, /* OUT. May be NULL */ |
| 1235 | hb_set_t *glyphs_input, /* OUT. May be NULL */ |
| 1236 | hb_set_t *glyphs_after, /* OUT. May be NULL */ |
| 1237 | hb_set_t *glyphs_output /* OUT. May be NULL */) |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 1238 | { |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 1239 | OT::hb_collect_glyphs_context_t c (face, |
| 1240 | glyphs_before, |
| 1241 | glyphs_input, |
| 1242 | glyphs_after, |
| 1243 | glyphs_output); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 1244 | |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 1245 | switch (table_tag) |
| 1246 | { |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 1247 | case HB_OT_TAG_GSUB: |
| 1248 | { |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1249 | const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 1250 | l.collect_glyphs (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 1251 | return; |
| 1252 | } |
| 1253 | case HB_OT_TAG_GPOS: |
| 1254 | { |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1255 | const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index); |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 1256 | l.collect_glyphs (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 1257 | return; |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1262 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1263 | /* Variations support */ |
| 1264 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1265 | |
| 1266 | /** |
| 1267 | * hb_ot_layout_table_find_feature_variations: |
| 1268 | * @face: #hb_face_t to work upon |
| 1269 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 1270 | * @coords: The variation coordinates to query |
| 1271 | * @num_coords: The number of variation coorinates |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1272 | * @variations_index: (out): The array of feature variations found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1273 | * |
| 1274 | * Fetches a list of feature variations in the specified face's GSUB table |
| 1275 | * or GPOS table, at the specified variation coordinates. |
| 1276 | * |
| 1277 | **/ |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1278 | hb_bool_t |
| 1279 | hb_ot_layout_table_find_feature_variations (hb_face_t *face, |
| 1280 | hb_tag_t table_tag, |
| 1281 | const int *coords, |
| 1282 | unsigned int num_coords, |
| 1283 | unsigned int *variations_index /* out */) |
| 1284 | { |
| 1285 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1286 | |
| 1287 | return g.find_variations_index (coords, num_coords, variations_index); |
| 1288 | } |
| 1289 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1290 | |
| 1291 | /** |
| 1292 | * hb_ot_layout_feature_with_variations_get_lookups: |
| 1293 | * @face: #hb_face_t to work upon |
| 1294 | * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS |
| 1295 | * @feature_index: The index of the feature to query |
| 1296 | * @variations_index: The index of the feature variation to query |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1297 | * @start_offset: offset of the first lookup to retrieve |
| 1298 | * @lookup_count: (inout) (allow-none): Input = the maximum number of lookups to return; |
| 1299 | * Output = the actual number of lookups returned (may be zero) |
| 1300 | * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1301 | * |
| 1302 | * Fetches a list of all lookups enumerated for the specified feature, in |
| 1303 | * the specified face's GSUB table or GPOS table, enabled at the specified |
| 1304 | * variations index. The list returned will begin at the offset provided. |
| 1305 | * |
| 1306 | **/ |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1307 | unsigned int |
| 1308 | hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, |
| 1309 | hb_tag_t table_tag, |
| 1310 | unsigned int feature_index, |
| 1311 | unsigned int variations_index, |
| 1312 | unsigned int start_offset, |
| 1313 | unsigned int *lookup_count /* IN/OUT */, |
| 1314 | unsigned int *lookup_indexes /* OUT */) |
| 1315 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 1316 | static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), ""); |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1317 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1318 | |
| 1319 | const OT::Feature &f = g.get_feature_variation (feature_index, variations_index); |
| 1320 | |
| 1321 | return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); |
| 1322 | } |
| 1323 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1324 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1325 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1326 | * OT::GSUB |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1327 | */ |
| 1328 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1329 | |
| 1330 | /** |
| 1331 | * hb_ot_layout_has_substitution: |
| 1332 | * @face: #hb_face_t to work upon |
| 1333 | * |
| 1334 | * Tests whether the specified face includes any GSUB substitutions. |
| 1335 | * |
| 1336 | * Return value: true if data found, false otherwise |
| 1337 | * |
| 1338 | **/ |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1339 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1340 | hb_ot_layout_has_substitution (hb_face_t *face) |
| 1341 | { |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 1342 | return face->table.GSUB->table->has_data (); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1345 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1346 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1347 | * hb_ot_layout_lookup_would_substitute: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1348 | * @face: #hb_face_t to work upon |
| 1349 | * @lookup_index: The index of the lookup to query |
| 1350 | * @glyphs: The sequence of glyphs to query for substitution |
| 1351 | * @glyphs_length: The length of the glyph sequence |
| 1352 | * @zero_context: #hb_bool_t indicating whether substitutions should be context-free |
| 1353 | * |
| 1354 | * Tests whether a specified lookup in the specified face would |
| 1355 | * trigger a substitution on the given glyph sequence. |
| 1356 | * |
| 1357 | * Return value: true if a substitution would be triggered, false otherwise |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1358 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1359 | * Since: 0.9.7 |
| 1360 | **/ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1361 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 1362 | hb_ot_layout_lookup_would_substitute (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 1363 | unsigned int lookup_index, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1364 | const hb_codepoint_t *glyphs, |
| 1365 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 1366 | hb_bool_t zero_context) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1367 | { |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1368 | if (unlikely (lookup_index >= face->table.GSUB->lookup_count)) return false; |
Behdad Esfahbod | ea512f7 | 2015-11-26 19:22:22 -0500 | [diff] [blame] | 1369 | OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context); |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1370 | |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1371 | const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1372 | |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1373 | return l.would_apply (&c, &face->table.GSUB->accels[lookup_index]); |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1376 | |
| 1377 | /** |
| 1378 | * hb_ot_layout_substitute_start: |
| 1379 | * @font: #hb_font_t to use |
| 1380 | * @buffer: #hb_buffer_t buffer to work upon |
| 1381 | * |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1382 | * Called before substitution lookups are performed, to ensure that glyph |
| 1383 | * class and other properties are set on the glyphs in the buffer. |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1384 | * |
| 1385 | **/ |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 1386 | void |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 1387 | hb_ot_layout_substitute_start (hb_font_t *font, |
| 1388 | hb_buffer_t *buffer) |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 1389 | { |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 1390 | _hb_ot_layout_set_glyph_props (font, buffer); |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 1391 | } |
| 1392 | |
Behdad Esfahbod | 385f78b | 2018-11-07 17:19:21 -0500 | [diff] [blame] | 1393 | void |
| 1394 | hb_ot_layout_delete_glyphs_inplace (hb_buffer_t *buffer, |
| 1395 | bool (*filter) (const hb_glyph_info_t *info)) |
| 1396 | { |
| 1397 | /* Merge clusters and delete filtered glyphs. |
| 1398 | * NOTE! We can't use out-buffer as we have positioning data. */ |
| 1399 | unsigned int j = 0; |
| 1400 | unsigned int count = buffer->len; |
| 1401 | hb_glyph_info_t *info = buffer->info; |
| 1402 | hb_glyph_position_t *pos = buffer->pos; |
| 1403 | for (unsigned int i = 0; i < count; i++) |
| 1404 | { |
| 1405 | if (filter (&info[i])) |
| 1406 | { |
| 1407 | /* Merge clusters. |
| 1408 | * Same logic as buffer->delete_glyph(), but for in-place removal. */ |
| 1409 | |
| 1410 | unsigned int cluster = info[i].cluster; |
| 1411 | if (i + 1 < count && cluster == info[i + 1].cluster) |
| 1412 | continue; /* Cluster survives; do nothing. */ |
| 1413 | |
| 1414 | if (j) |
| 1415 | { |
| 1416 | /* Merge cluster backward. */ |
| 1417 | if (cluster < info[j - 1].cluster) |
| 1418 | { |
| 1419 | unsigned int mask = info[i].mask; |
| 1420 | unsigned int old_cluster = info[j - 1].cluster; |
| 1421 | for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--) |
| 1422 | buffer->set_cluster (info[k - 1], cluster, mask); |
| 1423 | } |
| 1424 | continue; |
| 1425 | } |
| 1426 | |
| 1427 | if (i + 1 < count) |
| 1428 | buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */ |
| 1429 | |
| 1430 | continue; |
| 1431 | } |
| 1432 | |
| 1433 | if (j != i) |
| 1434 | { |
| 1435 | info[j] = info[i]; |
| 1436 | pos[j] = pos[i]; |
| 1437 | } |
| 1438 | j++; |
| 1439 | } |
| 1440 | buffer->len = j; |
| 1441 | } |
| 1442 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1443 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1444 | * hb_ot_layout_lookup_substitute_closure: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1445 | * @face: #hb_face_t to work upon |
| 1446 | * @lookup_index: index of the feature lookup to query |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 1447 | * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1448 | * |
| 1449 | * Compute the transitive closure of glyphs needed for a |
| 1450 | * specified lookup. |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1451 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1452 | * Since: 0.9.7 |
| 1453 | **/ |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1454 | void |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 1455 | hb_ot_layout_lookup_substitute_closure (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 1456 | unsigned int lookup_index, |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1457 | hb_set_t *glyphs /* OUT */) |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1458 | { |
Behdad Esfahbod | 3a4e5dd | 2018-10-29 18:05:25 -0700 | [diff] [blame] | 1459 | hb_map_t done_lookups; |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 1460 | OT::hb_closure_context_t c (face, glyphs, &done_lookups); |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 1461 | |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 1462 | const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 1463 | |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 1464 | l.closure (&c, lookup_index); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1465 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 1466 | |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1467 | /** |
| 1468 | * hb_ot_layout_lookups_substitute_closure: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1469 | * @face: #hb_face_t to work upon |
| 1470 | * @lookups: The set of lookups to query |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 1471 | * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1472 | * |
| 1473 | * Compute the transitive closure of glyphs needed for all of the |
| 1474 | * provided lookups. |
| 1475 | * |
| 1476 | * Since: 1.8.1 |
| 1477 | **/ |
| 1478 | void |
| 1479 | hb_ot_layout_lookups_substitute_closure (hb_face_t *face, |
| 1480 | const hb_set_t *lookups, |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1481 | hb_set_t *glyphs /* OUT */) |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1482 | { |
Behdad Esfahbod | 3a4e5dd | 2018-10-29 18:05:25 -0700 | [diff] [blame] | 1483 | hb_map_t done_lookups; |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1484 | OT::hb_closure_context_t c (face, glyphs, &done_lookups); |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 1485 | const OT::GSUB& gsub = *face->table.GSUB->table; |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1486 | |
Garret Rieger | 85646fd | 2018-07-23 15:37:18 -0700 | [diff] [blame] | 1487 | unsigned int iteration_count = 0; |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1488 | unsigned int glyphs_length; |
| 1489 | do |
| 1490 | { |
| 1491 | glyphs_length = glyphs->get_population (); |
Garret Rieger | feb2389 | 2018-06-07 14:32:34 -0700 | [diff] [blame] | 1492 | if (lookups != nullptr) |
| 1493 | { |
| 1494 | for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);) |
| 1495 | gsub.get_lookup (lookup_index).closure (&c, lookup_index); |
Behdad Esfahbod | f56cd9d | 2018-06-11 22:02:38 -0400 | [diff] [blame] | 1496 | } |
| 1497 | else |
| 1498 | { |
Garret Rieger | feb2389 | 2018-06-07 14:32:34 -0700 | [diff] [blame] | 1499 | for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) |
| 1500 | gsub.get_lookup (i).closure (&c, i); |
| 1501 | } |
Behdad Esfahbod | e44046e | 2018-11-10 22:41:35 -0500 | [diff] [blame] | 1502 | } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES && |
| 1503 | glyphs_length != glyphs->get_population ()); |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1506 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1507 | * OT::GPOS |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1508 | */ |
| 1509 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1510 | |
| 1511 | /** |
| 1512 | * hb_ot_layout_has_positioning: |
| 1513 | * @face: #hb_face_t to work upon |
| 1514 | * |
| 1515 | * Return value: true if the face has GPOS data, false otherwise |
| 1516 | * |
| 1517 | **/ |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1518 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1519 | hb_ot_layout_has_positioning (hb_face_t *face) |
| 1520 | { |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 1521 | return face->table.GPOS->table->has_data (); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1522 | } |
| 1523 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1524 | /** |
| 1525 | * hb_ot_layout_position_start: |
| 1526 | * @font: #hb_font_t to use |
| 1527 | * @buffer: #hb_buffer_t buffer to work upon |
| 1528 | * |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1529 | * Called before positioning lookups are performed, to ensure that glyph |
| 1530 | * attachment types and glyph-attachment chains are set for the glyphs in the buffer. |
| 1531 | * |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1532 | **/ |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 1533 | void |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 1534 | hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 1535 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1536 | OT::GPOS::position_start (font, buffer); |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1539 | |
| 1540 | /** |
| 1541 | * hb_ot_layout_position_finish_advances: |
| 1542 | * @font: #hb_font_t to use |
| 1543 | * @buffer: #hb_buffer_t buffer to work upon |
| 1544 | * |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1545 | * Called after positioning lookups are performed, to finish glyph advances. |
| 1546 | * |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1547 | **/ |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 1548 | void |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 1549 | hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 1550 | { |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 1551 | OT::GPOS::position_finish_advances (font, buffer); |
| 1552 | } |
| 1553 | |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1554 | /** |
| 1555 | * hb_ot_layout_position_finish_offsets: |
| 1556 | * @font: #hb_font_t to use |
| 1557 | * @buffer: #hb_buffer_t buffer to work upon |
| 1558 | * |
| 1559 | * Called after positioning lookups are performed, to finish glyph offsets. |
| 1560 | * |
| 1561 | **/ |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 1562 | void |
| 1563 | hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) |
| 1564 | { |
| 1565 | OT::GPOS::position_finish_offsets (font, buffer); |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 1566 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1567 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1568 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1569 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1570 | * hb_ot_layout_get_size_params: |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1571 | * @face: #hb_face_t to work upon |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 1572 | * @design_size: (out): The design size of the face |
| 1573 | * @subfamily_id: (out): The identifier of the face within the font subfamily |
Nathan Willis | c08ddbd | 2019-03-24 15:07:07 +0000 | [diff] [blame] | 1574 | * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1575 | * @range_start: (out): The minimum size of the recommended size range for the face |
| 1576 | * @range_end: (out): The maximum size of the recommended size range for the face |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1577 | * |
Nathan Willis | c08ddbd | 2019-03-24 15:07:07 +0000 | [diff] [blame] | 1578 | * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that |
| 1579 | * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id) |
| 1580 | * as used here are defined as pertaining only to fonts within a font family that differ |
| 1581 | * specifically in their respective size ranges; other ways to differentiate fonts within |
| 1582 | * a subfamily are not covered by the `size` feature. |
| 1583 | * |
| 1584 | * For more information on this distinction, see the `size` documentation at |
| 1585 | * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-39size39 |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1586 | * |
| 1587 | * Return value: true if data found, false otherwise |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1588 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 1589 | * Since: 0.9.10 |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1590 | **/ |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1591 | hb_bool_t |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1592 | hb_ot_layout_get_size_params (hb_face_t *face, |
| 1593 | unsigned int *design_size, /* OUT. May be NULL */ |
| 1594 | unsigned int *subfamily_id, /* OUT. May be NULL */ |
| 1595 | hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */ |
| 1596 | unsigned int *range_start, /* OUT. May be NULL */ |
| 1597 | unsigned int *range_end /* OUT. May be NULL */) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1598 | { |
Behdad Esfahbod | 737efbe | 2018-11-05 23:26:29 -0500 | [diff] [blame] | 1599 | const OT::GPOS &gpos = *face->table.GPOS->table; |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1600 | const hb_tag_t tag = HB_TAG ('s','i','z','e'); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1601 | |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame] | 1602 | unsigned int num_features = gpos.get_feature_count (); |
| 1603 | for (unsigned int i = 0; i < num_features; i++) |
| 1604 | { |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1605 | if (tag == gpos.get_feature_tag (i)) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1606 | { |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame] | 1607 | const OT::Feature &f = gpos.get_feature (i); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1608 | const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1609 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1610 | if (params.designSize) |
Behdad Esfahbod | 85bc44b | 2012-12-12 11:38:49 -0500 | [diff] [blame] | 1611 | { |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1612 | if (design_size) *design_size = params.designSize; |
| 1613 | if (subfamily_id) *subfamily_id = params.subfamilyID; |
Behdad Esfahbod | 6ce49a9 | 2018-10-28 08:26:30 -0700 | [diff] [blame] | 1614 | if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID; |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1615 | if (range_start) *range_start = params.rangeStart; |
| 1616 | if (range_end) *range_end = params.rangeEnd; |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1617 | |
| 1618 | return true; |
| 1619 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1623 | if (design_size) *design_size = 0; |
| 1624 | if (subfamily_id) *subfamily_id = 0; |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1625 | if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID; |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1626 | if (range_start) *range_start = 0; |
| 1627 | if (range_end) *range_end = 0; |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1628 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1629 | return false; |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1630 | } |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1631 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1632 | |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1633 | /** |
| 1634 | * hb_ot_layout_feature_get_name_ids: |
| 1635 | * @face: #hb_face_t to work upon |
Behdad Esfahbod | a5ad8c6 | 2018-10-20 16:52:55 -0700 | [diff] [blame] | 1636 | * @table_tag: table tag to query, "GSUB" or "GPOS". |
| 1637 | * @feature_index: index of feature to query. |
Nathan Willis | af5230b | 2019-03-18 14:03:16 +0000 | [diff] [blame] | 1638 | * @label_id: (out) (allow-none): The ‘name’ table name ID that specifies a string |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1639 | * for a user-interface label for this feature. (May be NULL.) |
Nathan Willis | af5230b | 2019-03-18 14:03:16 +0000 | [diff] [blame] | 1640 | * @tooltip_id: (out) (allow-none): The ‘name’ table name ID that specifies a string |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1641 | * that an application can use for tooltip text for this |
| 1642 | * feature. (May be NULL.) |
Nathan Willis | af5230b | 2019-03-18 14:03:16 +0000 | [diff] [blame] | 1643 | * @sample_id: (out) (allow-none): The ‘name’ table name ID that specifies sample text |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1644 | * that illustrates the effect of this feature. (May be NULL.) |
Nathan Willis | af5230b | 2019-03-18 14:03:16 +0000 | [diff] [blame] | 1645 | * @num_named_parameters: (out) (allow-none): Number of named parameters. (May be zero.) |
| 1646 | * @first_param_id: (out) (allow-none): The first ‘name’ table name ID used to specify |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1647 | * strings for user-interface labels for the feature |
| 1648 | * parameters. (Must be zero if numParameters is zero.) |
| 1649 | * |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1650 | * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or |
| 1651 | * "Character Variant" ('cvXX') features. |
| 1652 | * |
| 1653 | * Return value: true if data found, false otherwise |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1654 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 1655 | * Since: 2.0.0 |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1656 | **/ |
| 1657 | hb_bool_t |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1658 | hb_ot_layout_feature_get_name_ids (hb_face_t *face, |
| 1659 | hb_tag_t table_tag, |
| 1660 | unsigned int feature_index, |
| 1661 | hb_ot_name_id_t *label_id, /* OUT. May be NULL */ |
| 1662 | hb_ot_name_id_t *tooltip_id, /* OUT. May be NULL */ |
| 1663 | hb_ot_name_id_t *sample_id, /* OUT. May be NULL */ |
| 1664 | unsigned int *num_named_parameters, /* OUT. May be NULL */ |
| 1665 | hb_ot_name_id_t *first_param_id /* OUT. May be NULL */) |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1666 | { |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1667 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1668 | |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1669 | hb_tag_t feature_tag = g.get_feature_tag (feature_index); |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1670 | const OT::Feature &f = g.get_feature (feature_index); |
| 1671 | |
| 1672 | const OT::FeatureParams &feature_params = f.get_feature_params (); |
| 1673 | if (&feature_params != &Null (OT::FeatureParams)) |
| 1674 | { |
| 1675 | const OT::FeatureParamsStylisticSet& ss_params = |
| 1676 | feature_params.get_stylistic_set_params (feature_tag); |
| 1677 | if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */ |
| 1678 | { |
Behdad Esfahbod | 6ce49a9 | 2018-10-28 08:26:30 -0700 | [diff] [blame] | 1679 | if (label_id) *label_id = ss_params.uiNameID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1680 | // ssXX features don't have the rest |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1681 | if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID; |
| 1682 | if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID; |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1683 | if (num_named_parameters) *num_named_parameters = 0; |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1684 | if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1685 | return true; |
| 1686 | } |
| 1687 | const OT::FeatureParamsCharacterVariants& cv_params = |
| 1688 | feature_params.get_character_variants_params (feature_tag); |
| 1689 | if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */ |
| 1690 | { |
Behdad Esfahbod | 6ce49a9 | 2018-10-28 08:26:30 -0700 | [diff] [blame] | 1691 | if (label_id) *label_id = cv_params.featUILableNameID; |
| 1692 | if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID; |
| 1693 | if (sample_id) *sample_id = cv_params.sampleTextNameID; |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1694 | if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters; |
Behdad Esfahbod | 6ce49a9 | 2018-10-28 08:26:30 -0700 | [diff] [blame] | 1695 | if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1696 | return true; |
| 1697 | } |
| 1698 | } |
| 1699 | |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1700 | if (label_id) *label_id = HB_OT_NAME_ID_INVALID; |
| 1701 | if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID; |
| 1702 | if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID; |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1703 | if (num_named_parameters) *num_named_parameters = 0; |
Behdad Esfahbod | a7aba99 | 2018-10-30 14:04:09 -0700 | [diff] [blame] | 1704 | if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1705 | return false; |
| 1706 | } |
| 1707 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1708 | |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1709 | /** |
Behdad Esfahbod | a5ad8c6 | 2018-10-20 16:52:55 -0700 | [diff] [blame] | 1710 | * hb_ot_layout_feature_get_characters: |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1711 | * @face: #hb_face_t to work upon |
Behdad Esfahbod | a5ad8c6 | 2018-10-20 16:52:55 -0700 | [diff] [blame] | 1712 | * @table_tag: table tag to query, "GSUB" or "GPOS". |
| 1713 | * @feature_index: index of feature to query. |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1714 | * @start_offset: offset of the first character to retrieve |
| 1715 | * @char_count: (inout) (allow-none): Input = the maximum number of characters to return; |
| 1716 | * Output = the actual number of characters returned (may be zero) |
| 1717 | * @characters: (out caller-allocates) (array length=char_count): A buffer pointer. |
| 1718 | * The Unicode codepoints of the characters for which this feature provides |
| 1719 | * glyph variants. |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1720 | * |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1721 | * Fetches a list of the characters defined as having a variant under the specified |
| 1722 | * "Character Variant" ("cvXX") feature tag. |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1723 | * |
Nathan Willis | 3db2272 | 2019-04-02 18:49:40 +0100 | [diff] [blame] | 1724 | * <note>Note: If the char_count output value is equal to its input value, then there |
| 1725 | * is a chance there were more characters defined under the feature tag than were |
| 1726 | * returned. This function can be called with incrementally larger start_offset |
| 1727 | * until the char_count output value is lower than its input value, or the size |
| 1728 | * of the characters array can be increased.</note> |
| 1729 | * |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1730 | * Return value: Number of total sample characters in the cvXX feature. |
| 1731 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 1732 | * Since: 2.0.0 |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1733 | **/ |
| 1734 | unsigned int |
| 1735 | hb_ot_layout_feature_get_characters (hb_face_t *face, |
| 1736 | hb_tag_t table_tag, |
| 1737 | unsigned int feature_index, |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1738 | unsigned int start_offset, |
| 1739 | unsigned int *char_count, /* IN/OUT. May be NULL */ |
| 1740 | hb_codepoint_t *characters /* OUT. May be NULL */) |
| 1741 | { |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1742 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1743 | |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1744 | hb_tag_t feature_tag = g.get_feature_tag (feature_index); |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1745 | const OT::Feature &f = g.get_feature (feature_index); |
| 1746 | |
| 1747 | const OT::FeatureParams &feature_params = f.get_feature_params (); |
| 1748 | |
| 1749 | const OT::FeatureParamsCharacterVariants& cv_params = |
| 1750 | feature_params.get_character_variants_params(feature_tag); |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1751 | |
| 1752 | unsigned int len = 0; |
| 1753 | if (char_count && characters && start_offset < cv_params.characters.len) |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1754 | { |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1755 | len = hb_min (cv_params.characters.len - start_offset, *char_count); |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1756 | for (unsigned int i = 0; i < len; ++i) |
| 1757 | characters[i] = cv_params.characters[start_offset + i]; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1758 | } |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1759 | if (char_count) *char_count = len; |
| 1760 | return cv_params.characters.len; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1761 | } |
| 1762 | |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1763 | |
| 1764 | /* |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1765 | * Parts of different types are implemented here such that they have direct |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1766 | * access to GSUB/GPOS lookups. |
| 1767 | */ |
| 1768 | |
| 1769 | |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1770 | struct GSUBProxy |
| 1771 | { |
Behdad Esfahbod | 5d4b037 | 2019-01-22 12:11:24 +0100 | [diff] [blame] | 1772 | static constexpr unsigned table_index = 0u; |
Behdad Esfahbod | 39e1b6d | 2019-01-22 12:07:43 +0100 | [diff] [blame] | 1773 | static constexpr bool inplace = false; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1774 | typedef OT::SubstLookup Lookup; |
| 1775 | |
| 1776 | GSUBProxy (hb_face_t *face) : |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1777 | table (*face->table.GSUB->table), |
| 1778 | accels (face->table.GSUB->accels) {} |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1779 | |
| 1780 | const OT::GSUB &table; |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1781 | const OT::hb_ot_layout_lookup_accelerator_t *accels; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1782 | }; |
| 1783 | |
| 1784 | struct GPOSProxy |
| 1785 | { |
Behdad Esfahbod | 5d4b037 | 2019-01-22 12:11:24 +0100 | [diff] [blame] | 1786 | static constexpr unsigned table_index = 1u; |
Behdad Esfahbod | 39e1b6d | 2019-01-22 12:07:43 +0100 | [diff] [blame] | 1787 | static constexpr bool inplace = true; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1788 | typedef OT::PosLookup Lookup; |
| 1789 | |
| 1790 | GPOSProxy (hb_face_t *face) : |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1791 | table (*face->table.GPOS->table), |
| 1792 | accels (face->table.GPOS->accels) {} |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1793 | |
| 1794 | const OT::GPOS &table; |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1795 | const OT::hb_ot_layout_lookup_accelerator_t *accels; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1796 | }; |
| 1797 | |
| 1798 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1799 | static inline bool |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1800 | apply_forward (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1801 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1802 | { |
| 1803 | bool ret = false; |
| 1804 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 1805 | while (buffer->idx < buffer->len && buffer->successful) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1806 | { |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1807 | bool applied = false; |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1808 | if (accel.may_have (buffer->cur().codepoint) && |
| 1809 | (buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1810 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1811 | { |
Behdad Esfahbod | e78549e | 2018-10-10 11:54:48 -0400 | [diff] [blame] | 1812 | applied = accel.apply (c); |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | if (applied) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1816 | ret = true; |
| 1817 | else |
| 1818 | buffer->next_glyph (); |
| 1819 | } |
| 1820 | return ret; |
| 1821 | } |
| 1822 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1823 | static inline bool |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1824 | apply_backward (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1825 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1826 | { |
| 1827 | bool ret = false; |
| 1828 | hb_buffer_t *buffer = c->buffer; |
| 1829 | do |
| 1830 | { |
| 1831 | if (accel.may_have (buffer->cur().codepoint) && |
| 1832 | (buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1833 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
Behdad Esfahbod | 9af983a | 2018-11-07 16:03:09 -0500 | [diff] [blame] | 1834 | ret |= accel.apply (c); |
| 1835 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1836 | /* The reverse lookup doesn't "advance" cursor (for good reason). */ |
| 1837 | buffer->idx--; |
| 1838 | |
| 1839 | } |
| 1840 | while ((int) buffer->idx >= 0); |
| 1841 | return ret; |
| 1842 | } |
| 1843 | |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1844 | template <typename Proxy> |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1845 | static inline void |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1846 | apply_string (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1847 | const typename Proxy::Lookup &lookup, |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1848 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1849 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1850 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1851 | |
Behdad Esfahbod | 5337db2 | 2015-11-06 16:18:09 -0800 | [diff] [blame] | 1852 | if (unlikely (!buffer->len || !c->lookup_mask)) |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1853 | return; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1854 | |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 1855 | c->set_lookup_props (lookup.get_props ()); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1856 | |
| 1857 | if (likely (!lookup.is_reverse ())) |
| 1858 | { |
| 1859 | /* in/out forward substitution/positioning */ |
Behdad Esfahbod | 271cb7c | 2019-01-22 12:05:35 +0100 | [diff] [blame] | 1860 | if (Proxy::table_index == 0u) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1861 | buffer->clear_output (); |
| 1862 | buffer->idx = 0; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1863 | |
Behdad Esfahbod | 640b66c | 2015-02-19 17:30:05 +0300 | [diff] [blame] | 1864 | bool ret; |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1865 | ret = apply_forward (c, accel); |
Behdad Esfahbod | 640b66c | 2015-02-19 17:30:05 +0300 | [diff] [blame] | 1866 | if (ret) |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1867 | { |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1868 | if (!Proxy::inplace) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1869 | buffer->swap_buffers (); |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1870 | else |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1871 | assert (!buffer->has_separate_output ()); |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1872 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1873 | } |
| 1874 | else |
| 1875 | { |
| 1876 | /* in-place backward substitution/positioning */ |
Behdad Esfahbod | 271cb7c | 2019-01-22 12:05:35 +0100 | [diff] [blame] | 1877 | if (Proxy::table_index == 0u) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1878 | buffer->remove_output (); |
| 1879 | buffer->idx = buffer->len - 1; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1880 | |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1881 | apply_backward (c, accel); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1882 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1883 | } |
| 1884 | |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1885 | template <typename Proxy> |
| 1886 | inline void hb_ot_map_t::apply (const Proxy &proxy, |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1887 | const hb_ot_shape_plan_t *plan, |
| 1888 | hb_font_t *font, |
| 1889 | hb_buffer_t *buffer) const |
| 1890 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1891 | const unsigned int table_index = proxy.table_index; |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1892 | unsigned int i = 0; |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1893 | OT::hb_ot_apply_context_t c (table_index, font, buffer); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1894 | c.set_recurse_func (Proxy::Lookup::apply_recurse_func); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1895 | |
Behdad Esfahbod | 474a120 | 2018-12-21 18:46:51 -0500 | [diff] [blame] | 1896 | for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++) { |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1897 | const stage_map_t *stage = &stages[table_index][stage_index]; |
| 1898 | for (; i < stage->last_lookup; i++) |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1899 | { |
| 1900 | unsigned int lookup_index = lookups[table_index][i].index; |
Behdad Esfahbod | 0475ef2 | 2015-12-18 18:17:07 +0000 | [diff] [blame] | 1901 | if (!buffer->message (font, "start lookup %d", lookup_index)) continue; |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 1902 | c.set_lookup_index (lookup_index); |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1903 | c.set_lookup_mask (lookups[table_index][i].mask); |
| 1904 | c.set_auto_zwj (lookups[table_index][i].auto_zwj); |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 1905 | c.set_auto_zwnj (lookups[table_index][i].auto_zwnj); |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 1906 | if (lookups[table_index][i].random) |
| 1907 | { |
David Corbett | b545e27 | 2018-02-23 12:22:32 -0500 | [diff] [blame] | 1908 | c.set_random (true); |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 1909 | buffer->unsafe_to_break_all (); |
| 1910 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1911 | apply_string<Proxy> (&c, |
| 1912 | proxy.table.get_lookup (lookup_index), |
| 1913 | proxy.accels[lookup_index]); |
Behdad Esfahbod | 0475ef2 | 2015-12-18 18:17:07 +0000 | [diff] [blame] | 1914 | (void) buffer->message (font, "end lookup %d", lookup_index); |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1915 | } |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1916 | |
| 1917 | if (stage->pause_func) |
| 1918 | { |
| 1919 | buffer->clear_output (); |
| 1920 | stage->pause_func (plan, font, buffer); |
| 1921 | } |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 1926 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1927 | GSUBProxy proxy (font->face); |
| 1928 | apply (proxy, plan, font, buffer); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 1932 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1933 | GPOSProxy proxy (font->face); |
| 1934 | apply (proxy, plan, font, buffer); |
| 1935 | } |
| 1936 | |
Behdad Esfahbod | cdab20d | 2018-02-10 15:45:17 -0600 | [diff] [blame] | 1937 | void |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1938 | hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1939 | const OT::SubstLookup &lookup, |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1940 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1941 | { |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1942 | apply_string<GSUBProxy> (c, lookup, accel); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1943 | } |
Ebrahim Byagowi | b8a78ce | 2018-11-03 22:28:30 +0330 | [diff] [blame] | 1944 | |
| 1945 | #if 0 |
| 1946 | static const OT::BASE& _get_base (hb_face_t *face) |
| 1947 | { |
Behdad Esfahbod | 0fe7a74 | 2018-11-05 23:08:33 -0500 | [diff] [blame] | 1948 | return *face->table.BASE; |
Ebrahim Byagowi | b8a78ce | 2018-11-03 22:28:30 +0330 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | hb_bool_t |
| 1952 | hb_ot_layout_get_baseline (hb_font_t *font, |
| 1953 | hb_ot_layout_baseline_t baseline, |
| 1954 | hb_direction_t direction, |
| 1955 | hb_tag_t script_tag, |
| 1956 | hb_tag_t language_tag, |
| 1957 | hb_position_t *coord /* OUT. May be NULL. */) |
| 1958 | { |
| 1959 | const OT::BASE &base = _get_base (font->face); |
| 1960 | bool result = base.get_baseline (font, baseline, direction, script_tag, |
| 1961 | language_tag, coord); |
| 1962 | |
| 1963 | /* TODO: Simulate https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags#ideographic-em-box */ |
| 1964 | if (!result && coord) *coord = 0; |
| 1965 | |
| 1966 | if (coord) *coord = font->em_scale_dir (*coord, direction); |
| 1967 | |
| 1968 | return result; |
| 1969 | } |
| 1970 | |
| 1971 | /* To be moved to public header */ |
| 1972 | /* |
| 1973 | * BASE |
| 1974 | */ |
| 1975 | |
| 1976 | /** |
| 1977 | * hb_ot_layout_baseline_t: |
| 1978 | * |
| 1979 | * https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags |
| 1980 | * |
| 1981 | * Since: DONTREPLACEME |
| 1982 | */ |
| 1983 | typedef enum { |
| 1984 | HB_OT_LAYOUT_BASELINE_HANG = HB_TAG('h','a','n','g'), |
| 1985 | HB_OT_LAYOUT_BASELINE_ICFB = HB_TAG('i','c','f','b'), |
| 1986 | HB_OT_LAYOUT_BASELINE_ICFT = HB_TAG('i','c','f','t'), |
| 1987 | HB_OT_LAYOUT_BASELINE_IDEO = HB_TAG('i','d','e','o'), |
| 1988 | HB_OT_LAYOUT_BASELINE_IDTB = HB_TAG('i','d','t','b'), |
| 1989 | HB_OT_LAYOUT_BASELINE_MATH = HB_TAG('m','a','t','h'), |
| 1990 | HB_OT_LAYOUT_BASELINE_ROMN = HB_TAG('r','o','m','n') |
| 1991 | } hb_ot_layout_baseline_t; |
| 1992 | |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1993 | |
| 1994 | /** |
| 1995 | * hb_ot_layout_get_baseline: |
| 1996 | * @font: The #hb_font_t to work upon |
| 1997 | * @baseline: The #hb_ot_layout_baseline_t to query |
Nathan Willis | c08ddbd | 2019-03-24 15:07:07 +0000 | [diff] [blame] | 1998 | * @direction: The #hb_direction_t text direction to use (horizontal or vertical) |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 1999 | * @script_tag: #hb_tag_t of the script to use |
| 2000 | * @language_tag: #hb_tag_t of the language to use |
Nathan Willis | 5122805 | 2019-03-17 14:43:06 +0000 | [diff] [blame] | 2001 | * @coord: (out): The position of the requested baseline |
Nathan Willis | 930f6fc | 2019-03-16 15:10:21 +0000 | [diff] [blame] | 2002 | * |
| 2003 | * Fetches the coordinates of the specified baseline in the face, underneath |
| 2004 | * the specified script and language and in the specified text direction. |
| 2005 | * |
| 2006 | * Return value: true if the baseline is found for the settings queried, false otherwise |
| 2007 | * |
| 2008 | **/ |
Ebrahim Byagowi | b8a78ce | 2018-11-03 22:28:30 +0330 | [diff] [blame] | 2009 | HB_EXTERN hb_bool_t |
| 2010 | hb_ot_layout_get_baseline (hb_font_t *font, |
| 2011 | hb_ot_layout_baseline_t baseline, |
| 2012 | hb_direction_t direction, |
| 2013 | hb_tag_t script_tag, |
| 2014 | hb_tag_t language_tag, |
| 2015 | hb_position_t *coord /* OUT. May be NULL. */); |
| 2016 | |
| 2017 | #endif |