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 | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 37 | #include "hb-ot-layout-gdef-table.hh" |
| 38 | #include "hb-ot-layout-gsub-table.hh" |
| 39 | #include "hb-ot-layout-gpos-table.hh" |
Behdad Esfahbod | 203dc44 | 2018-05-03 21:03:27 -0400 | [diff] [blame] | 40 | |
| 41 | // Just so we compile them; unused otherwise: |
| 42 | #include "hb-ot-layout-base-table.hh" |
| 43 | #include "hb-ot-layout-jstf-table.hh" |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 44 | #include "hb-ot-kern-table.hh" |
Behdad Esfahbod | 203dc44 | 2018-05-03 21:03:27 -0400 | [diff] [blame] | 45 | #include "hb-ot-name-table.hh" |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 46 | |
Behdad Esfahbod | aff831e | 2008-01-24 06:03:45 -0500 | [diff] [blame] | 47 | |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 48 | static const OT::kern::accelerator_t& _get_kern (hb_face_t *face) |
| 49 | { |
| 50 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::kern::accelerator_t); |
| 51 | return *hb_ot_face_data (face)->kern; |
| 52 | } |
Behdad Esfahbod | fee0f41 | 2018-08-28 18:27:41 -0700 | [diff] [blame] | 53 | const OT::GDEF& _get_gdef (hb_face_t *face) |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 54 | { |
Behdad Esfahbod | abc12f7 | 2018-05-08 02:23:36 -0700 | [diff] [blame] | 55 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GDEF); |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 56 | return *hb_ot_face_data (face)->GDEF->table; |
Behdad Esfahbod | 4096fbe | 2018-08-26 01:25:54 -0700 | [diff] [blame] | 57 | } |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 58 | static hb_blob_t * _get_gsub_blob (hb_face_t *face) |
Behdad Esfahbod | 4096fbe | 2018-08-26 01:25:54 -0700 | [diff] [blame] | 59 | { |
| 60 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 61 | return hb_ot_face_data (face)->GSUB->blob; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 62 | } |
Behdad Esfahbod | 3999094 | 2018-08-26 09:12:25 -0700 | [diff] [blame] | 63 | static inline const OT::GSUB& _get_gsub (hb_face_t *face) |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 64 | { |
Behdad Esfahbod | abc12f7 | 2018-05-08 02:23:36 -0700 | [diff] [blame] | 65 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GSUB); |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 66 | return *hb_ot_face_data (face)->GSUB->table; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 67 | } |
Behdad Esfahbod | fee0f41 | 2018-08-28 18:27:41 -0700 | [diff] [blame] | 68 | const OT::GSUB& _get_gsub_relaxed (hb_face_t *face) |
Behdad Esfahbod | 3999094 | 2018-08-26 09:12:25 -0700 | [diff] [blame] | 69 | { |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 70 | return *hb_ot_face_data (face)->GSUB.get_relaxed ()->table; |
Behdad Esfahbod | 3999094 | 2018-08-26 09:12:25 -0700 | [diff] [blame] | 71 | } |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 72 | static hb_blob_t * _get_gpos_blob (hb_face_t *face) |
Behdad Esfahbod | 4096fbe | 2018-08-26 01:25:54 -0700 | [diff] [blame] | 73 | { |
| 74 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 75 | return hb_ot_face_data (face)->GPOS->blob; |
Behdad Esfahbod | 4096fbe | 2018-08-26 01:25:54 -0700 | [diff] [blame] | 76 | } |
Behdad Esfahbod | 3999094 | 2018-08-26 09:12:25 -0700 | [diff] [blame] | 77 | static inline const OT::GPOS& _get_gpos (hb_face_t *face) |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 78 | { |
Behdad Esfahbod | abc12f7 | 2018-05-08 02:23:36 -0700 | [diff] [blame] | 79 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GPOS); |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 80 | return *hb_ot_face_data (face)->GPOS->table; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 81 | } |
Behdad Esfahbod | fee0f41 | 2018-08-28 18:27:41 -0700 | [diff] [blame] | 82 | const OT::GPOS& _get_gpos_relaxed (hb_face_t *face) |
Behdad Esfahbod | 3999094 | 2018-08-26 09:12:25 -0700 | [diff] [blame] | 83 | { |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 84 | return *hb_ot_face_data (face)->GPOS.get_relaxed ()->table; |
Behdad Esfahbod | 3999094 | 2018-08-26 09:12:25 -0700 | [diff] [blame] | 85 | } |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 86 | |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 87 | |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 88 | /* |
Behdad Esfahbod | a519588 | 2018-10-08 23:57:45 -0400 | [diff] [blame] | 89 | * kern |
| 90 | */ |
| 91 | |
| 92 | hb_bool_t |
| 93 | hb_ot_layout_has_kerning (hb_face_t *face) |
| 94 | { |
| 95 | return _get_kern (face).has_data (); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | hb_ot_layout_kern (hb_font_t *font, |
| 100 | hb_buffer_t *buffer, |
| 101 | hb_mask_t kern_mask) |
| 102 | { |
| 103 | _get_kern (font->face).apply (font, buffer, kern_mask); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /* |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 108 | * GDEF |
| 109 | */ |
| 110 | |
Behdad Esfahbod | d8c57e8 | 2018-08-26 09:03:31 -0700 | [diff] [blame] | 111 | static bool |
| 112 | _hb_ot_blacklist_gdef (unsigned int gdef_len, |
| 113 | unsigned int gsub_len, |
| 114 | unsigned int gpos_len) |
| 115 | { |
| 116 | /* The ugly business of blacklisting individual fonts' tables happen here! |
| 117 | * See this thread for why we finally had to bend in and do this: |
| 118 | * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html |
| 119 | * |
| 120 | * In certain versions of Times New Roman Italic and Bold Italic, |
| 121 | * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark) |
| 122 | * in GDEF. Many versions of Tahoma have bad GDEF tables that |
| 123 | * incorrectly classify some spacing marks such as certain IPA |
| 124 | * symbols as glyph class 3. So do older versions of Microsoft |
| 125 | * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04. |
| 126 | * |
| 127 | * Nuke the GDEF tables of to avoid unwanted width-zeroing. |
| 128 | * |
| 129 | * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 |
| 130 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693 |
| 131 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875 |
| 132 | */ |
| 133 | #define ENCODE(x,y,z) ((int64_t) (x) << 32 | (int64_t) (y) << 16 | (z)) |
| 134 | switch ENCODE(gdef_len, gsub_len, gpos_len) |
| 135 | { |
| 136 | /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */ |
| 137 | case ENCODE (442, 2874, 42038): |
| 138 | /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */ |
| 139 | case ENCODE (430, 2874, 40662): |
| 140 | /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */ |
| 141 | case ENCODE (442, 2874, 39116): |
| 142 | /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */ |
| 143 | case ENCODE (430, 2874, 39374): |
| 144 | /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */ |
| 145 | case ENCODE (490, 3046, 41638): |
| 146 | /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */ |
| 147 | case ENCODE (478, 3046, 41902): |
| 148 | /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */ |
| 149 | case ENCODE (898, 12554, 46470): |
| 150 | /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */ |
| 151 | case ENCODE (910, 12566, 47732): |
| 152 | /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */ |
| 153 | case ENCODE (928, 23298, 59332): |
| 154 | /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */ |
| 155 | case ENCODE (940, 23310, 60732): |
| 156 | /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 157 | case ENCODE (964, 23836, 60072): |
| 158 | /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 159 | case ENCODE (976, 23832, 61456): |
| 160 | /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */ |
| 161 | case ENCODE (994, 24474, 60336): |
| 162 | /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */ |
| 163 | case ENCODE (1006, 24470, 61740): |
| 164 | /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 165 | case ENCODE (1006, 24576, 61346): |
| 166 | /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
| 167 | case ENCODE (1018, 24572, 62828): |
| 168 | /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5 tahoma.ttf from Windows 10 AU */ |
| 169 | case ENCODE (1006, 24576, 61352): |
| 170 | /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2 tahomabd.ttf from Windows 10 AU */ |
| 171 | case ENCODE (1018, 24572, 62834): |
| 172 | /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */ |
| 173 | case ENCODE (832, 7324, 47162): |
| 174 | /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */ |
| 175 | case ENCODE (844, 7302, 45474): |
| 176 | /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc himalaya.ttf from Windows 7 */ |
| 177 | case ENCODE (180, 13054, 7254): |
| 178 | /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */ |
| 179 | case ENCODE (192, 12638, 7254): |
| 180 | /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */ |
| 181 | case ENCODE (192, 12690, 7254): |
| 182 | /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */ |
| 183 | /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */ |
| 184 | case ENCODE (188, 248, 3852): |
| 185 | /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */ |
| 186 | /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */ |
| 187 | case ENCODE (188, 264, 3426): |
| 188 | /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */ |
| 189 | case ENCODE (1058, 47032, 11818): |
| 190 | /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/ |
| 191 | case ENCODE (1046, 47030, 12600): |
| 192 | /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */ |
| 193 | case ENCODE (1058, 71796, 16770): |
| 194 | /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */ |
| 195 | case ENCODE (1046, 71790, 17862): |
| 196 | /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */ |
| 197 | case ENCODE (1046, 71788, 17112): |
| 198 | /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */ |
| 199 | case ENCODE (1058, 71794, 17514): |
| 200 | /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */ |
| 201 | case ENCODE (1330, 109904, 57938): |
| 202 | /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */ |
| 203 | case ENCODE (1330, 109904, 58972): |
| 204 | /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85 Padauk.ttf |
| 205 | * "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */ |
| 206 | case ENCODE (1004, 59092, 14836): |
| 207 | return true; |
| 208 | #undef ENCODE |
| 209 | } |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | inline void |
| 214 | OT::GDEF::accelerator_t::init (hb_face_t *face) |
| 215 | { |
| 216 | this->blob = hb_sanitize_context_t().reference_table<GDEF> (face); |
| 217 | |
| 218 | if (unlikely (_hb_ot_blacklist_gdef (this->blob->length, |
| 219 | _get_gsub_blob (face)->length, |
| 220 | _get_gpos_blob (face)->length))) |
| 221 | { |
| 222 | hb_blob_destroy (this->blob); |
| 223 | this->blob = hb_blob_get_empty (); |
| 224 | } |
| 225 | |
| 226 | table = this->blob->as<GDEF> (); |
| 227 | } |
| 228 | |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 229 | static void |
| 230 | _hb_ot_layout_set_glyph_props (hb_font_t *font, |
| 231 | hb_buffer_t *buffer) |
| 232 | { |
| 233 | _hb_buffer_assert_gsubgpos_vars (buffer); |
| 234 | |
| 235 | const OT::GDEF &gdef = _get_gdef (font->face); |
| 236 | unsigned int count = buffer->len; |
| 237 | for (unsigned int i = 0; i < count; i++) |
| 238 | { |
| 239 | _hb_glyph_info_set_glyph_props (&buffer->info[i], gdef.get_glyph_props (buffer->info[i].codepoint)); |
| 240 | _hb_glyph_info_clear_lig_props (&buffer->info[i]); |
| 241 | buffer->info[i].syllable() = 0; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* Public API */ |
| 246 | |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 247 | hb_bool_t |
Behdad Esfahbod | 52ea477 | 2009-11-06 17:45:38 -0500 | [diff] [blame] | 248 | hb_ot_layout_has_glyph_classes (hb_face_t *face) |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 249 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 250 | return _get_gdef (face).has_glyph_classes (); |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 253 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 254 | * hb_ot_layout_get_glyph_class: |
| 255 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 256 | * Since: 0.9.7 |
| 257 | **/ |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 258 | hb_ot_layout_glyph_class_t |
| 259 | hb_ot_layout_get_glyph_class (hb_face_t *face, |
| 260 | hb_codepoint_t glyph) |
| 261 | { |
| 262 | return (hb_ot_layout_glyph_class_t) _get_gdef (face).get_glyph_class (glyph); |
| 263 | } |
Behdad Esfahbod | 4a2d844 | 2010-11-03 15:28:56 -0400 | [diff] [blame] | 264 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 265 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 266 | * hb_ot_layout_get_glyphs_in_class: |
| 267 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 268 | * Since: 0.9.7 |
| 269 | **/ |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 270 | void |
| 271 | hb_ot_layout_get_glyphs_in_class (hb_face_t *face, |
| 272 | hb_ot_layout_glyph_class_t klass, |
| 273 | hb_set_t *glyphs /* OUT */) |
| 274 | { |
| 275 | return _get_gdef (face).get_glyphs_in_class (klass, glyphs); |
| 276 | } |
| 277 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 278 | unsigned int |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 279 | hb_ot_layout_get_attach_points (hb_face_t *face, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 280 | hb_codepoint_t glyph, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 281 | unsigned int start_offset, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 282 | unsigned int *point_count /* IN/OUT */, |
| 283 | unsigned int *point_array /* OUT */) |
| 284 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 285 | return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, point_array); |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 288 | unsigned int |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 289 | hb_ot_layout_get_ligature_carets (hb_font_t *font, |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 290 | hb_direction_t direction, |
| 291 | hb_codepoint_t glyph, |
| 292 | unsigned int start_offset, |
| 293 | unsigned int *caret_count /* IN/OUT */, |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 294 | hb_position_t *caret_array /* OUT */) |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 295 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 296 | return _get_gdef (font->face).get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 299 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 300 | /* |
| 301 | * GSUB/GPOS |
| 302 | */ |
| 303 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 304 | static const OT::GSUBGPOS& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 305 | get_gsubgpos_table (hb_face_t *face, |
| 306 | hb_tag_t table_tag) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 307 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 308 | switch (table_tag) { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 309 | case HB_OT_TAG_GSUB: return _get_gsub (face); |
| 310 | case HB_OT_TAG_GPOS: return _get_gpos (face); |
Behdad Esfahbod | abc12f7 | 2018-05-08 02:23:36 -0700 | [diff] [blame] | 311 | default: return Null(OT::GSUBGPOS); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 316 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 317 | hb_ot_layout_table_get_script_tags (hb_face_t *face, |
| 318 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 319 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 320 | unsigned int *script_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 321 | hb_tag_t *script_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 322 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 323 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 324 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 325 | return g.get_script_tags (start_offset, script_count, script_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 326 | } |
| 327 | |
Behdad Esfahbod | eb45c0a | 2013-01-16 22:07:50 -0600 | [diff] [blame] | 328 | #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
| 329 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 330 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 331 | hb_ot_layout_table_find_script (hb_face_t *face, |
| 332 | hb_tag_t table_tag, |
| 333 | hb_tag_t script_tag, |
| 334 | unsigned int *script_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 335 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 336 | 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] | 337 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 338 | |
| 339 | if (g.find_script_index (script_tag, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 340 | return true; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 341 | |
| 342 | /* try finding 'DFLT' */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 343 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 344 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 345 | |
Behdad Esfahbod | dca8aff | 2010-09-28 16:25:23 -0400 | [diff] [blame] | 346 | /* try with 'dflt'; MS site has had typos and many fonts use it now :(. |
| 347 | * including many versions of DejaVu Sans Mono! */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 348 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 349 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 350 | |
Behdad Esfahbod | eb45c0a | 2013-01-16 22:07:50 -0600 | [diff] [blame] | 351 | /* try with 'latn'; some old fonts put their features there even though |
| 352 | they're really trying to support Thai, for example :( */ |
| 353 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) |
| 354 | return false; |
| 355 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 356 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 357 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 358 | } |
| 359 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 360 | hb_bool_t |
| 361 | hb_ot_layout_table_choose_script (hb_face_t *face, |
| 362 | hb_tag_t table_tag, |
| 363 | const hb_tag_t *script_tags, |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 364 | unsigned int *script_index, |
| 365 | hb_tag_t *chosen_script) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 366 | { |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 367 | const hb_tag_t *t; |
| 368 | for (t = script_tags; *t; t++); |
| 369 | return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script); |
| 370 | } |
| 371 | |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 372 | /** |
| 373 | * hb_ot_layout_table_select_script: |
| 374 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 375 | * Since: 2.0.0 |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 376 | **/ |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 377 | hb_bool_t |
| 378 | hb_ot_layout_table_select_script (hb_face_t *face, |
| 379 | hb_tag_t table_tag, |
| 380 | unsigned int script_count, |
| 381 | const hb_tag_t *script_tags, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 382 | unsigned int *script_index /* OUT */, |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 383 | hb_tag_t *chosen_script /* OUT */) |
| 384 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 385 | 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] | 386 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 387 | unsigned int i; |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 388 | |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 389 | for (i = 0; i < script_count; i++) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 390 | { |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 391 | if (g.find_script_index (script_tags[i], script_index)) |
| 392 | { |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 393 | if (chosen_script) |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 394 | *chosen_script = script_tags[i]; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 395 | return true; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 396 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /* try finding 'DFLT' */ |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 400 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
| 401 | if (chosen_script) |
| 402 | *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 403 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 404 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 405 | |
| 406 | /* 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] | 407 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { |
| 408 | if (chosen_script) |
| 409 | *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 410 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 411 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 412 | |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 413 | /* try with 'latn'; some old fonts put their features there even though |
| 414 | they're really trying to support Thai, for example :( */ |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 415 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { |
| 416 | if (chosen_script) |
| 417 | *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 418 | return false; |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 419 | } |
| 420 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 421 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 422 | if (chosen_script) |
| 423 | *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 424 | return false; |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 425 | } |
| 426 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 427 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 428 | hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
| 429 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 430 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 431 | unsigned int *feature_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 432 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 433 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 434 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 435 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 436 | return g.get_feature_tags (start_offset, feature_count, feature_tags); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 437 | } |
| 438 | |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 439 | hb_bool_t |
| 440 | hb_ot_layout_table_find_feature (hb_face_t *face, |
| 441 | hb_tag_t table_tag, |
| 442 | hb_tag_t feature_tag, |
| 443 | unsigned int *feature_index) |
| 444 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 445 | 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] | 446 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 447 | |
| 448 | unsigned int num_features = g.get_feature_count (); |
| 449 | for (unsigned int i = 0; i < num_features; i++) |
| 450 | { |
| 451 | if (feature_tag == g.get_feature_tag (i)) { |
| 452 | if (feature_index) *feature_index = i; |
| 453 | return true; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
| 458 | return false; |
| 459 | } |
| 460 | |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 461 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 462 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 463 | hb_ot_layout_script_get_language_tags (hb_face_t *face, |
| 464 | hb_tag_t table_tag, |
| 465 | unsigned int script_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 466 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 467 | unsigned int *language_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 468 | hb_tag_t *language_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 469 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 470 | 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] | 471 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 472 | return s.get_lang_sys_tags (start_offset, language_count, language_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 476 | hb_ot_layout_script_find_language (hb_face_t *face, |
| 477 | hb_tag_t table_tag, |
| 478 | unsigned int script_index, |
| 479 | hb_tag_t language_tag, |
| 480 | unsigned int *language_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 481 | { |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 482 | return hb_ot_layout_script_select_language (face, table_tag, script_index, 1, &language_tag, language_index); |
| 483 | } |
| 484 | |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 485 | /** |
| 486 | * hb_ot_layout_script_select_language: |
| 487 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 488 | * Since: 2.0.0 |
Behdad Esfahbod | 8061664 | 2018-10-11 14:16:55 -0400 | [diff] [blame] | 489 | **/ |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 490 | hb_bool_t |
Behdad Esfahbod | cf975ac | 2018-10-11 14:07:44 -0400 | [diff] [blame] | 491 | hb_ot_layout_script_select_language (hb_face_t *face, |
| 492 | hb_tag_t table_tag, |
| 493 | unsigned int script_index, |
| 494 | unsigned int language_count, |
| 495 | const hb_tag_t *language_tags, |
| 496 | unsigned int *language_index /* OUT */) |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 497 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 498 | 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] | 499 | 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] | 500 | unsigned int i; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 501 | |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 502 | for (i = 0; i < language_count; i++) |
| 503 | { |
| 504 | if (s.find_lang_sys_index (language_tags[i], language_index)) |
| 505 | return true; |
| 506 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 507 | |
David Corbett | 9106771 | 2017-12-08 11:21:14 -0500 | [diff] [blame] | 508 | /* try finding 'dflt' */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 509 | 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] | 510 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 511 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 512 | if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 513 | return false; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 514 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 515 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 516 | hb_bool_t |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 517 | hb_ot_layout_language_get_required_feature_index (hb_face_t *face, |
| 518 | hb_tag_t table_tag, |
| 519 | unsigned int script_index, |
| 520 | unsigned int language_index, |
| 521 | unsigned int *feature_index) |
| 522 | { |
| 523 | return hb_ot_layout_language_get_required_feature (face, |
| 524 | table_tag, |
| 525 | script_index, |
| 526 | language_index, |
| 527 | feature_index, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 528 | nullptr); |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 529 | } |
| 530 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 531 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 532 | * hb_ot_layout_language_get_required_feature: |
| 533 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 534 | * Since: 0.9.30 |
| 535 | **/ |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 536 | hb_bool_t |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 537 | hb_ot_layout_language_get_required_feature (hb_face_t *face, |
| 538 | hb_tag_t table_tag, |
| 539 | unsigned int script_index, |
| 540 | unsigned int language_index, |
| 541 | unsigned int *feature_index, |
| 542 | hb_tag_t *feature_tag) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 543 | { |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 544 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 545 | 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] | 546 | |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 547 | unsigned int index = l.get_required_feature_index (); |
| 548 | if (feature_index) *feature_index = index; |
| 549 | if (feature_tag) *feature_tag = g.get_feature_tag (index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 550 | |
| 551 | return l.has_required_feature (); |
| 552 | } |
| 553 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 554 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 555 | hb_ot_layout_language_get_feature_indexes (hb_face_t *face, |
| 556 | hb_tag_t table_tag, |
| 557 | unsigned int script_index, |
| 558 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 559 | unsigned int start_offset, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 560 | unsigned int *feature_count /* IN/OUT */, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 561 | unsigned int *feature_indexes /* OUT */) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 562 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 563 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 564 | 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] | 565 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 566 | return l.get_feature_indexes (start_offset, feature_count, feature_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 567 | } |
| 568 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 569 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 570 | hb_ot_layout_language_get_feature_tags (hb_face_t *face, |
| 571 | hb_tag_t table_tag, |
| 572 | unsigned int script_index, |
| 573 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 574 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 575 | unsigned int *feature_count /* IN/OUT */, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 576 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 577 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 578 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 579 | 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] | 580 | |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 581 | static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), ""); |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 582 | 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] | 583 | |
Behdad Esfahbod | 9897749 | 2009-08-27 01:32:17 -0400 | [diff] [blame] | 584 | if (feature_tags) { |
| 585 | unsigned int count = *feature_count; |
| 586 | for (unsigned int i = 0; i < count; i++) |
| 587 | feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); |
| 588 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 589 | |
| 590 | return ret; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 591 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 592 | |
| 593 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 594 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 595 | hb_ot_layout_language_find_feature (hb_face_t *face, |
| 596 | hb_tag_t table_tag, |
| 597 | unsigned int script_index, |
| 598 | unsigned int language_index, |
| 599 | hb_tag_t feature_tag, |
| 600 | unsigned int *feature_index) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 601 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 602 | 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] | 603 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 604 | 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] | 605 | |
Behdad Esfahbod | f4c9514 | 2009-05-17 04:59:56 -0400 | [diff] [blame] | 606 | unsigned int num_features = l.get_feature_count (); |
| 607 | for (unsigned int i = 0; i < num_features; i++) { |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 608 | unsigned int f_index = l.get_feature_index (i); |
| 609 | |
| 610 | if (feature_tag == g.get_feature_tag (f_index)) { |
| 611 | if (feature_index) *feature_index = f_index; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 612 | return true; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 617 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 618 | } |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 619 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 620 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 621 | * hb_ot_layout_feature_get_lookups: |
| 622 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 623 | * Since: 0.9.7 |
| 624 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 625 | unsigned int |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 626 | hb_ot_layout_feature_get_lookups (hb_face_t *face, |
| 627 | hb_tag_t table_tag, |
| 628 | unsigned int feature_index, |
| 629 | unsigned int start_offset, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 630 | unsigned int *lookup_count /* IN/OUT */, |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 631 | unsigned int *lookup_indexes /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 632 | { |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 633 | return hb_ot_layout_feature_with_variations_get_lookups (face, |
| 634 | table_tag, |
| 635 | feature_index, |
| 636 | HB_OT_LAYOUT_NO_VARIATIONS_INDEX, |
| 637 | start_offset, |
| 638 | lookup_count, |
| 639 | lookup_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 640 | } |
| 641 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 642 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 643 | * hb_ot_layout_table_get_lookup_count: |
| 644 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 645 | * Since: 0.9.22 |
| 646 | **/ |
Behdad Esfahbod | 27674b4 | 2013-10-03 14:54:50 -0400 | [diff] [blame] | 647 | unsigned int |
| 648 | hb_ot_layout_table_get_lookup_count (hb_face_t *face, |
| 649 | hb_tag_t table_tag) |
| 650 | { |
Behdad Esfahbod | 96828b9 | 2018-10-25 20:34:29 -0700 | [diff] [blame] | 651 | return get_gsubgpos_table (face, table_tag).get_lookup_count (); |
Behdad Esfahbod | 27674b4 | 2013-10-03 14:54:50 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 654 | |
| 655 | struct hb_collect_features_context_t |
| 656 | { |
| 657 | hb_collect_features_context_t (hb_face_t *face, |
| 658 | hb_tag_t table_tag, |
| 659 | hb_set_t *feature_indexes_) |
| 660 | : g (get_gsubgpos_table (face, table_tag)), |
| 661 | feature_indexes (feature_indexes_) {} |
| 662 | |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 663 | bool inline visited (const OT::Script &s) |
| 664 | { |
| 665 | /* We might have Null() object here. Don't want to involve |
| 666 | * that in the memoize. So, detect empty objects and return. */ |
| 667 | if (unlikely (!s.has_default_lang_sys () && |
| 668 | !s.get_lang_sys_count ())) |
| 669 | return true; |
| 670 | |
| 671 | return visited (s, visited_script); |
| 672 | } |
| 673 | bool inline visited (const OT::LangSys &l) |
| 674 | { |
| 675 | /* We might have Null() object here. Don't want to involve |
| 676 | * that in the memoize. So, detect empty objects and return. */ |
| 677 | if (unlikely (!l.has_required_feature () && |
| 678 | !l.get_feature_count ())) |
| 679 | return true; |
| 680 | |
| 681 | return visited (l, visited_langsys); |
| 682 | } |
| 683 | |
| 684 | private: |
| 685 | template <typename T> |
| 686 | bool inline visited (const T &p, hb_set_t &visited_set) |
| 687 | { |
| 688 | hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g); |
| 689 | if (visited_set.has (delta)) |
| 690 | return true; |
| 691 | |
| 692 | visited_set.add (delta); |
| 693 | return false; |
| 694 | } |
| 695 | |
| 696 | public: |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 697 | const OT::GSUBGPOS &g; |
| 698 | hb_set_t *feature_indexes; |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 699 | |
| 700 | private: |
| 701 | hb_auto_t<hb_set_t> visited_script; |
| 702 | hb_auto_t<hb_set_t> visited_langsys; |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 703 | }; |
| 704 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 705 | static void |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 706 | langsys_collect_features (hb_collect_features_context_t *c, |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 707 | const OT::LangSys &l, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 708 | const hb_tag_t *features) |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 709 | { |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 710 | if (c->visited (l)) return; |
| 711 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 712 | if (!features) |
| 713 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 714 | /* All features. */ |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 715 | if (l.has_required_feature ()) |
| 716 | c->feature_indexes->add (l.get_required_feature_index ()); |
Behdad Esfahbod | 5f85c80 | 2013-06-26 20:14:18 -0400 | [diff] [blame] | 717 | |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 718 | l.add_feature_indexes_to (c->feature_indexes); |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 719 | } |
| 720 | else |
| 721 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 722 | /* Ugh. Any faster way? */ |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 723 | for (; *features; features++) |
| 724 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 725 | hb_tag_t feature_tag = *features; |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 726 | unsigned int num_features = l.get_feature_count (); |
| 727 | for (unsigned int i = 0; i < num_features; i++) |
| 728 | { |
| 729 | unsigned int feature_index = l.get_feature_index (i); |
| 730 | |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 731 | if (feature_tag == c->g.get_feature_tag (feature_index)) |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 732 | { |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 733 | c->feature_indexes->add (feature_index); |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 734 | break; |
| 735 | } |
| 736 | } |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | static void |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 742 | script_collect_features (hb_collect_features_context_t *c, |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 743 | const OT::Script &s, |
| 744 | const hb_tag_t *languages, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 745 | const hb_tag_t *features) |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 746 | { |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 747 | if (c->visited (s)) return; |
| 748 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 749 | if (!languages) |
| 750 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 751 | /* All languages. */ |
Behdad Esfahbod | eb44bfc | 2018-10-25 21:42:19 -0700 | [diff] [blame] | 752 | if (s.has_default_lang_sys ()) |
| 753 | langsys_collect_features (c, |
| 754 | s.get_default_lang_sys (), |
| 755 | features); |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 756 | |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 757 | unsigned int count = s.get_lang_sys_count (); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 758 | for (unsigned int language_index = 0; language_index < count; language_index++) |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 759 | langsys_collect_features (c, |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 760 | s.get_lang_sys (language_index), |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 761 | features); |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 762 | } |
| 763 | else |
| 764 | { |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 765 | for (; *languages; languages++) |
| 766 | { |
| 767 | unsigned int language_index; |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 768 | if (s.find_lang_sys_index (*languages, &language_index)) |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 769 | langsys_collect_features (c, |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 770 | s.get_lang_sys (language_index), |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 771 | features); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | /** |
Garret Rieger | 8973375 | 2018-07-30 18:10:43 -0700 | [diff] [blame] | 777 | * hb_ot_layout_collect_features: |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 778 | * |
Behdad Esfahbod | 44d1fb3 | 2018-08-01 14:51:51 -0700 | [diff] [blame] | 779 | * Since: 1.8.5 |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 780 | **/ |
| 781 | void |
| 782 | hb_ot_layout_collect_features (hb_face_t *face, |
| 783 | hb_tag_t table_tag, |
| 784 | const hb_tag_t *scripts, |
| 785 | const hb_tag_t *languages, |
| 786 | const hb_tag_t *features, |
| 787 | hb_set_t *feature_indexes /* OUT */) |
| 788 | { |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 789 | hb_collect_features_context_t c (face, table_tag, feature_indexes); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 790 | if (!scripts) |
| 791 | { |
Behdad Esfahbod | e8e6750 | 2018-10-25 20:48:20 -0700 | [diff] [blame] | 792 | /* All scripts. */ |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 793 | unsigned int count = c.g.get_script_count (); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 794 | for (unsigned int script_index = 0; script_index < count; script_index++) |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 795 | script_collect_features (&c, |
| 796 | c.g.get_script (script_index), |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 797 | languages, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 798 | features); |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 799 | } |
| 800 | else |
| 801 | { |
| 802 | for (; *scripts; scripts++) |
| 803 | { |
| 804 | unsigned int script_index; |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 805 | if (c.g.find_script_index (*scripts, &script_index)) |
| 806 | script_collect_features (&c, |
| 807 | c.g.get_script (script_index), |
Behdad Esfahbod | fe5520d | 2018-10-25 20:58:34 -0700 | [diff] [blame] | 808 | languages, |
Behdad Esfahbod | 941600a | 2018-10-25 21:26:08 -0700 | [diff] [blame] | 809 | features); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 814 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 815 | * hb_ot_layout_collect_lookups: |
| 816 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 817 | * Since: 0.9.8 |
| 818 | **/ |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 819 | void |
| 820 | hb_ot_layout_collect_lookups (hb_face_t *face, |
| 821 | hb_tag_t table_tag, |
| 822 | const hb_tag_t *scripts, |
| 823 | const hb_tag_t *languages, |
| 824 | const hb_tag_t *features, |
| 825 | hb_set_t *lookup_indexes /* OUT */) |
| 826 | { |
Behdad Esfahbod | e98af6d | 2018-10-25 22:25:29 -0700 | [diff] [blame] | 827 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 828 | |
Garret Rieger | 7d92bef | 2018-07-30 17:17:43 -0700 | [diff] [blame] | 829 | hb_auto_t<hb_set_t> feature_indexes; |
| 830 | 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] | 831 | |
Behdad Esfahbod | c237cdf | 2018-10-25 21:17:30 -0700 | [diff] [blame] | 832 | for (hb_codepoint_t feature_index = HB_SET_VALUE_INVALID; |
| 833 | hb_set_next (&feature_indexes, &feature_index);) |
Behdad Esfahbod | e98af6d | 2018-10-25 22:25:29 -0700 | [diff] [blame] | 834 | g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 835 | } |
| 836 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 837 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 838 | * hb_ot_layout_lookup_collect_glyphs: |
| 839 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 840 | * Since: 0.9.7 |
| 841 | **/ |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 842 | void |
| 843 | hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, |
| 844 | hb_tag_t table_tag, |
| 845 | unsigned int lookup_index, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 846 | hb_set_t *glyphs_before, /* OUT. May be NULL */ |
| 847 | hb_set_t *glyphs_input, /* OUT. May be NULL */ |
| 848 | hb_set_t *glyphs_after, /* OUT. May be NULL */ |
| 849 | hb_set_t *glyphs_output /* OUT. May be NULL */) |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 850 | { |
| 851 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; |
| 852 | |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 853 | OT::hb_collect_glyphs_context_t c (face, |
| 854 | glyphs_before, |
| 855 | glyphs_input, |
| 856 | glyphs_after, |
| 857 | glyphs_output); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 858 | |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 859 | switch (table_tag) |
| 860 | { |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 861 | case HB_OT_TAG_GSUB: |
| 862 | { |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 863 | const OT::SubstLookup& l = hb_ot_face_data (face)->GSUB->table->get_lookup (lookup_index); |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 864 | l.collect_glyphs (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 865 | return; |
| 866 | } |
| 867 | case HB_OT_TAG_GPOS: |
| 868 | { |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 869 | const OT::PosLookup& l = hb_ot_face_data (face)->GPOS->table->get_lookup (lookup_index); |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 870 | l.collect_glyphs (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 871 | return; |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 876 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 877 | /* Variations support */ |
| 878 | |
| 879 | hb_bool_t |
| 880 | hb_ot_layout_table_find_feature_variations (hb_face_t *face, |
| 881 | hb_tag_t table_tag, |
| 882 | const int *coords, |
| 883 | unsigned int num_coords, |
| 884 | unsigned int *variations_index /* out */) |
| 885 | { |
| 886 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 887 | |
| 888 | return g.find_variations_index (coords, num_coords, variations_index); |
| 889 | } |
| 890 | |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 891 | unsigned int |
| 892 | hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, |
| 893 | hb_tag_t table_tag, |
| 894 | unsigned int feature_index, |
| 895 | unsigned int variations_index, |
| 896 | unsigned int start_offset, |
| 897 | unsigned int *lookup_count /* IN/OUT */, |
| 898 | unsigned int *lookup_indexes /* OUT */) |
| 899 | { |
Behdad Esfahbod | 606bf57 | 2018-09-16 19:33:48 +0200 | [diff] [blame] | 900 | 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] | 901 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 902 | |
| 903 | const OT::Feature &f = g.get_feature_variation (feature_index, variations_index); |
| 904 | |
| 905 | return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); |
| 906 | } |
| 907 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 908 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 909 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 910 | * OT::GSUB |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 911 | */ |
| 912 | |
| 913 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 914 | hb_ot_layout_has_substitution (hb_face_t *face) |
| 915 | { |
Behdad Esfahbod | b912fbe | 2018-08-06 06:30:12 -0700 | [diff] [blame] | 916 | return _get_gsub (face).has_data (); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 917 | } |
| 918 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 919 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 920 | * hb_ot_layout_lookup_would_substitute: |
| 921 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 922 | * Since: 0.9.7 |
| 923 | **/ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 924 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 925 | hb_ot_layout_lookup_would_substitute (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 926 | unsigned int lookup_index, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 927 | const hb_codepoint_t *glyphs, |
| 928 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 929 | hb_bool_t zero_context) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 930 | { |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 931 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 932 | return hb_ot_layout_lookup_would_substitute_fast (face, lookup_index, glyphs, glyphs_length, zero_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 933 | } |
| 934 | |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 935 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 936 | hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 937 | unsigned int lookup_index, |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 938 | const hb_codepoint_t *glyphs, |
| 939 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 940 | hb_bool_t zero_context) |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 941 | { |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 942 | if (unlikely (lookup_index >= hb_ot_face_data (face)->GSUB->lookup_count)) return false; |
Behdad Esfahbod | ea512f7 | 2015-11-26 19:22:22 -0500 | [diff] [blame] | 943 | 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] | 944 | |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 945 | const OT::SubstLookup& l = hb_ot_face_data (face)->GSUB->table->get_lookup (lookup_index); |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 946 | |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 947 | return l.would_apply (&c, &hb_ot_face_data (face)->GSUB->accels[lookup_index]); |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 948 | } |
| 949 | |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 950 | void |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 951 | hb_ot_layout_substitute_start (hb_font_t *font, |
| 952 | hb_buffer_t *buffer) |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 953 | { |
Behdad Esfahbod | c624e18 | 2018-08-26 09:19:20 -0700 | [diff] [blame] | 954 | _hb_ot_layout_set_glyph_props (font, buffer); |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 957 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 958 | * hb_ot_layout_lookup_substitute_closure: |
| 959 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 960 | * Since: 0.9.7 |
| 961 | **/ |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 962 | void |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 963 | hb_ot_layout_lookup_substitute_closure (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 964 | unsigned int lookup_index, |
| 965 | hb_set_t *glyphs) |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 966 | { |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 967 | hb_auto_t<hb_map_t> done_lookups; |
| 968 | OT::hb_closure_context_t c (face, glyphs, &done_lookups); |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 969 | |
| 970 | const OT::SubstLookup& l = _get_gsub (face).get_lookup (lookup_index); |
| 971 | |
Garret Rieger | 45186b9 | 2018-06-05 17:14:42 -0700 | [diff] [blame] | 972 | l.closure (&c, lookup_index); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 973 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 974 | |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 975 | /** |
| 976 | * hb_ot_layout_lookups_substitute_closure: |
| 977 | * |
| 978 | * Compute the transitive closure of glyphs needed for all of the |
| 979 | * provided lookups. |
| 980 | * |
| 981 | * Since: 1.8.1 |
| 982 | **/ |
| 983 | void |
| 984 | hb_ot_layout_lookups_substitute_closure (hb_face_t *face, |
| 985 | const hb_set_t *lookups, |
| 986 | hb_set_t *glyphs) |
| 987 | { |
| 988 | hb_auto_t<hb_map_t> done_lookups; |
| 989 | OT::hb_closure_context_t c (face, glyphs, &done_lookups); |
| 990 | const OT::GSUB& gsub = _get_gsub (face); |
| 991 | |
Garret Rieger | 85646fd | 2018-07-23 15:37:18 -0700 | [diff] [blame] | 992 | unsigned int iteration_count = 0; |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 993 | unsigned int glyphs_length; |
| 994 | do |
| 995 | { |
| 996 | glyphs_length = glyphs->get_population (); |
Garret Rieger | feb2389 | 2018-06-07 14:32:34 -0700 | [diff] [blame] | 997 | if (lookups != nullptr) |
| 998 | { |
| 999 | for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);) |
| 1000 | gsub.get_lookup (lookup_index).closure (&c, lookup_index); |
Behdad Esfahbod | f56cd9d | 2018-06-11 22:02:38 -0400 | [diff] [blame] | 1001 | } |
| 1002 | else |
| 1003 | { |
Garret Rieger | feb2389 | 2018-06-07 14:32:34 -0700 | [diff] [blame] | 1004 | for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) |
| 1005 | gsub.get_lookup (i).closure (&c, i); |
| 1006 | } |
Garret Rieger | 85646fd | 2018-07-23 15:37:18 -0700 | [diff] [blame] | 1007 | iteration_count++; |
| 1008 | } while (iteration_count <= HB_CLOSURE_MAX_STAGES |
| 1009 | && glyphs_length != glyphs->get_population ()); |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1012 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1013 | * OT::GPOS |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1014 | */ |
| 1015 | |
| 1016 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1017 | hb_ot_layout_has_positioning (hb_face_t *face) |
| 1018 | { |
Behdad Esfahbod | b912fbe | 2018-08-06 06:30:12 -0700 | [diff] [blame] | 1019 | return _get_gpos (face).has_data (); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1020 | } |
| 1021 | |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 1022 | void |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 1023 | 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] | 1024 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1025 | OT::GPOS::position_start (font, buffer); |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 1028 | void |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 1029 | 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] | 1030 | { |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 1031 | OT::GPOS::position_finish_advances (font, buffer); |
| 1032 | } |
| 1033 | |
| 1034 | void |
| 1035 | hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) |
| 1036 | { |
| 1037 | OT::GPOS::position_finish_offsets (font, buffer); |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 1038 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1039 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1040 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 1041 | * hb_ot_layout_get_size_params: |
| 1042 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 1043 | * Since: 0.9.10 |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 1044 | **/ |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1045 | hb_bool_t |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 1046 | hb_ot_layout_get_size_params (hb_face_t *face, |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1047 | unsigned int *design_size, /* OUT. May be NULL */ |
| 1048 | unsigned int *subfamily_id, /* OUT. May be NULL */ |
| 1049 | unsigned int *subfamily_name_id, /* OUT. May be NULL */ |
| 1050 | unsigned int *range_start, /* OUT. May be NULL */ |
| 1051 | unsigned int *range_end /* OUT. May be NULL */) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1052 | { |
| 1053 | const OT::GPOS &gpos = _get_gpos (face); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1054 | const hb_tag_t tag = HB_TAG ('s','i','z','e'); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1055 | |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame] | 1056 | unsigned int num_features = gpos.get_feature_count (); |
| 1057 | for (unsigned int i = 0; i < num_features; i++) |
| 1058 | { |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1059 | if (tag == gpos.get_feature_tag (i)) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1060 | { |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame] | 1061 | const OT::Feature &f = gpos.get_feature (i); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1062 | const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1063 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1064 | if (params.designSize) |
Behdad Esfahbod | 85bc44b | 2012-12-12 11:38:49 -0500 | [diff] [blame] | 1065 | { |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1066 | if (design_size) *design_size = params.designSize; |
| 1067 | if (subfamily_id) *subfamily_id = params.subfamilyID; |
| 1068 | if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID; |
| 1069 | if (range_start) *range_start = params.rangeStart; |
| 1070 | if (range_end) *range_end = params.rangeEnd; |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1071 | |
| 1072 | return true; |
| 1073 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1077 | if (design_size) *design_size = 0; |
| 1078 | if (subfamily_id) *subfamily_id = 0; |
| 1079 | if (subfamily_name_id) *subfamily_name_id = 0; |
| 1080 | if (range_start) *range_start = 0; |
| 1081 | if (range_end) *range_end = 0; |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1082 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 1083 | return false; |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 1084 | } |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1085 | |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1086 | /** |
| 1087 | * hb_ot_layout_feature_get_name_ids: |
| 1088 | * @face: #hb_face_t to work upon |
Behdad Esfahbod | a5ad8c6 | 2018-10-20 16:52:55 -0700 | [diff] [blame] | 1089 | * @table_tag: table tag to query, "GSUB" or "GPOS". |
| 1090 | * @feature_index: index of feature to query. |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1091 | * @label_id: (out) (allow-none): The ‘name’ table name ID that specifies a string |
| 1092 | * for a user-interface label for this feature. (May be NULL.) |
| 1093 | * @tooltip_id: (out) (allow-none): The ‘name’ table name ID that specifies a string |
| 1094 | * that an application can use for tooltip text for this |
| 1095 | * feature. (May be NULL.) |
| 1096 | * @sample_id: (out) (allow-none): The ‘name’ table name ID that specifies sample text |
| 1097 | * that illustrates the effect of this feature. (May be NULL.) |
| 1098 | * @num_named_parameters: (out) (allow-none): Number of named parameters. (May be zero.) |
| 1099 | * @first_param_id: (out) (allow-none): The first ‘name’ table name ID used to specify |
| 1100 | * strings for user-interface labels for the feature |
| 1101 | * parameters. (Must be zero if numParameters is zero.) |
| 1102 | * |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1103 | * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or |
| 1104 | * "Character Variant" ('cvXX') features. |
| 1105 | * |
| 1106 | * Return value: true if data found, false otherwise |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1107 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 1108 | * Since: 2.0.0 |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1109 | **/ |
| 1110 | hb_bool_t |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1111 | hb_ot_layout_feature_get_name_ids (hb_face_t *face, |
| 1112 | hb_tag_t table_tag, |
| 1113 | unsigned int feature_index, |
| 1114 | hb_name_id_t *label_id, /* OUT. May be NULL */ |
| 1115 | hb_name_id_t *tooltip_id, /* OUT. May be NULL */ |
| 1116 | hb_name_id_t *sample_id, /* OUT. May be NULL */ |
| 1117 | unsigned int *num_named_parameters, /* OUT. May be NULL */ |
| 1118 | hb_name_id_t *first_param_id /* OUT. May be NULL */) |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1119 | { |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1120 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1121 | |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1122 | hb_tag_t feature_tag = g.get_feature_tag (feature_index); |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1123 | const OT::Feature &f = g.get_feature (feature_index); |
| 1124 | |
| 1125 | const OT::FeatureParams &feature_params = f.get_feature_params (); |
| 1126 | if (&feature_params != &Null (OT::FeatureParams)) |
| 1127 | { |
| 1128 | const OT::FeatureParamsStylisticSet& ss_params = |
| 1129 | feature_params.get_stylistic_set_params (feature_tag); |
| 1130 | if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */ |
| 1131 | { |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1132 | if (label_id) *label_id = ss_params.uiNameID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1133 | // ssXX features don't have the rest |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1134 | if (tooltip_id) *tooltip_id = HB_NAME_ID_INVALID; |
| 1135 | if (sample_id) *sample_id = HB_NAME_ID_INVALID; |
| 1136 | if (num_named_parameters) *num_named_parameters = 0; |
| 1137 | if (first_param_id) *first_param_id = HB_NAME_ID_INVALID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1138 | return true; |
| 1139 | } |
| 1140 | const OT::FeatureParamsCharacterVariants& cv_params = |
| 1141 | feature_params.get_character_variants_params (feature_tag); |
| 1142 | if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */ |
| 1143 | { |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1144 | if (label_id) *label_id = cv_params.featUILableNameID; |
| 1145 | if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID; |
| 1146 | if (sample_id) *sample_id = cv_params.sampleTextNameID; |
| 1147 | if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters; |
| 1148 | if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1149 | return true; |
| 1150 | } |
| 1151 | } |
| 1152 | |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1153 | if (label_id) *label_id = HB_NAME_ID_INVALID; |
| 1154 | if (tooltip_id) *tooltip_id = HB_NAME_ID_INVALID; |
| 1155 | if (sample_id) *sample_id = HB_NAME_ID_INVALID; |
| 1156 | if (num_named_parameters) *num_named_parameters = 0; |
| 1157 | if (first_param_id) *first_param_id = HB_NAME_ID_INVALID; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1158 | return false; |
| 1159 | } |
| 1160 | |
| 1161 | /** |
Behdad Esfahbod | a5ad8c6 | 2018-10-20 16:52:55 -0700 | [diff] [blame] | 1162 | * hb_ot_layout_feature_get_characters: |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1163 | * @face: #hb_face_t to work upon |
Behdad Esfahbod | a5ad8c6 | 2018-10-20 16:52:55 -0700 | [diff] [blame] | 1164 | * @table_tag: table tag to query, "GSUB" or "GPOS". |
| 1165 | * @feature_index: index of feature to query. |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1166 | * @start_offset: In case the resulting char_count was equal to its input value, there |
| 1167 | * is a chance there were more characters on the tag so this API can be |
| 1168 | * called with an offset till resulting char_count gets to a number |
| 1169 | * lower than input buffer (or consider using just a bigger buffer for |
| 1170 | * one shot copying). |
HinTak | 49bdb54 | 2018-10-17 00:36:04 +0100 | [diff] [blame] | 1171 | * @char_count: (inout) (allow-none): The count of characters for which this feature |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1172 | * provides glyph variants. (May be zero.) |
| 1173 | * @characters: (out) (allow-none): A buffer pointer. The Unicode Scalar Value |
| 1174 | * of the characters for which this feature provides glyph variants. |
| 1175 | * |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1176 | * Fetches characters listed by designer under feature parameters for "Character |
| 1177 | * Variant" ("cvXX") features. |
| 1178 | * |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1179 | * Return value: Number of total sample characters in the cvXX feature. |
| 1180 | * |
Behdad Esfahbod | 3d9a030 | 2018-10-18 05:58:17 -0700 | [diff] [blame] | 1181 | * Since: 2.0.0 |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1182 | **/ |
| 1183 | unsigned int |
| 1184 | hb_ot_layout_feature_get_characters (hb_face_t *face, |
| 1185 | hb_tag_t table_tag, |
| 1186 | unsigned int feature_index, |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1187 | unsigned int start_offset, |
| 1188 | unsigned int *char_count, /* IN/OUT. May be NULL */ |
| 1189 | hb_codepoint_t *characters /* OUT. May be NULL */) |
| 1190 | { |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1191 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 1192 | |
Behdad Esfahbod | c0a6814 | 2018-10-12 16:05:56 -0400 | [diff] [blame] | 1193 | hb_tag_t feature_tag = g.get_feature_tag (feature_index); |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1194 | const OT::Feature &f = g.get_feature (feature_index); |
| 1195 | |
| 1196 | const OT::FeatureParams &feature_params = f.get_feature_params (); |
| 1197 | |
| 1198 | const OT::FeatureParamsCharacterVariants& cv_params = |
| 1199 | feature_params.get_character_variants_params(feature_tag); |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1200 | |
| 1201 | unsigned int len = 0; |
| 1202 | if (char_count && characters && start_offset < cv_params.characters.len) |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1203 | { |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1204 | len = MIN (cv_params.characters.len - start_offset, *char_count); |
| 1205 | for (unsigned int i = 0; i < len; ++i) |
| 1206 | characters[i] = cv_params.characters[start_offset + i]; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1207 | } |
Ebrahim Byagowi | 6310943 | 2018-10-13 14:00:05 +0330 | [diff] [blame] | 1208 | if (char_count) *char_count = len; |
| 1209 | return cv_params.characters.len; |
Ebrahim Byagowi | dc49bd8 | 2018-10-12 03:00:59 +0330 | [diff] [blame] | 1210 | } |
| 1211 | |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1212 | |
| 1213 | /* |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1214 | * Parts of different types are implemented here such that they have direct |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1215 | * access to GSUB/GPOS lookups. |
| 1216 | */ |
| 1217 | |
| 1218 | |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1219 | struct GSUBProxy |
| 1220 | { |
Behdad Esfahbod | fda994e | 2018-09-07 15:02:57 -0400 | [diff] [blame] | 1221 | enum { table_index = 0 }; |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1222 | static const bool inplace = false; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1223 | typedef OT::SubstLookup Lookup; |
| 1224 | |
| 1225 | GSUBProxy (hb_face_t *face) : |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 1226 | table (*hb_ot_face_data (face)->GSUB->table), |
| 1227 | accels (hb_ot_face_data (face)->GSUB->accels) {} |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1228 | |
| 1229 | const OT::GSUB &table; |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1230 | const OT::hb_ot_layout_lookup_accelerator_t *accels; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1231 | }; |
| 1232 | |
| 1233 | struct GPOSProxy |
| 1234 | { |
Behdad Esfahbod | fda994e | 2018-09-07 15:02:57 -0400 | [diff] [blame] | 1235 | enum { table_index = 1 }; |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1236 | static const bool inplace = true; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1237 | typedef OT::PosLookup Lookup; |
| 1238 | |
| 1239 | GPOSProxy (hb_face_t *face) : |
Behdad Esfahbod | a268068 | 2018-08-26 15:18:46 -0700 | [diff] [blame] | 1240 | table (*hb_ot_face_data (face)->GPOS->table), |
| 1241 | accels (hb_ot_face_data (face)->GPOS->accels) {} |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1242 | |
| 1243 | const OT::GPOS &table; |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1244 | const OT::hb_ot_layout_lookup_accelerator_t *accels; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1245 | }; |
| 1246 | |
| 1247 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1248 | static inline bool |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1249 | apply_forward (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1250 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1251 | { |
| 1252 | bool ret = false; |
| 1253 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 1254 | while (buffer->idx < buffer->len && buffer->successful) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1255 | { |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1256 | bool applied = false; |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1257 | if (accel.may_have (buffer->cur().codepoint) && |
| 1258 | (buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1259 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1260 | { |
Behdad Esfahbod | e78549e | 2018-10-10 11:54:48 -0400 | [diff] [blame] | 1261 | applied = accel.apply (c); |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | if (applied) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1265 | ret = true; |
| 1266 | else |
| 1267 | buffer->next_glyph (); |
| 1268 | } |
| 1269 | return ret; |
| 1270 | } |
| 1271 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1272 | static inline bool |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1273 | apply_backward (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1274 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1275 | { |
| 1276 | bool ret = false; |
| 1277 | hb_buffer_t *buffer = c->buffer; |
| 1278 | do |
| 1279 | { |
| 1280 | if (accel.may_have (buffer->cur().codepoint) && |
| 1281 | (buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1282 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1283 | { |
Behdad Esfahbod | e78549e | 2018-10-10 11:54:48 -0400 | [diff] [blame] | 1284 | if (accel.apply (c)) |
| 1285 | ret = true; |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1286 | } |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1287 | /* The reverse lookup doesn't "advance" cursor (for good reason). */ |
| 1288 | buffer->idx--; |
| 1289 | |
| 1290 | } |
| 1291 | while ((int) buffer->idx >= 0); |
| 1292 | return ret; |
| 1293 | } |
| 1294 | |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1295 | template <typename Proxy> |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1296 | static inline void |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1297 | apply_string (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1298 | const typename Proxy::Lookup &lookup, |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1299 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1300 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1301 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1302 | |
Behdad Esfahbod | 5337db2 | 2015-11-06 16:18:09 -0800 | [diff] [blame] | 1303 | if (unlikely (!buffer->len || !c->lookup_mask)) |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1304 | return; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1305 | |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 1306 | c->set_lookup_props (lookup.get_props ()); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1307 | |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1308 | if (likely (!lookup.is_reverse ())) |
| 1309 | { |
| 1310 | /* in/out forward substitution/positioning */ |
| 1311 | if (Proxy::table_index == 0) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1312 | buffer->clear_output (); |
| 1313 | buffer->idx = 0; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1314 | |
Behdad Esfahbod | 640b66c | 2015-02-19 17:30:05 +0300 | [diff] [blame] | 1315 | bool ret; |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1316 | ret = apply_forward (c, accel); |
Behdad Esfahbod | 640b66c | 2015-02-19 17:30:05 +0300 | [diff] [blame] | 1317 | if (ret) |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1318 | { |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1319 | if (!Proxy::inplace) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1320 | buffer->swap_buffers (); |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1321 | else |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1322 | assert (!buffer->has_separate_output ()); |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1323 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1324 | } |
| 1325 | else |
| 1326 | { |
| 1327 | /* in-place backward substitution/positioning */ |
| 1328 | if (Proxy::table_index == 0) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1329 | buffer->remove_output (); |
| 1330 | buffer->idx = buffer->len - 1; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1331 | |
Behdad Esfahbod | 78c09bf | 2018-10-10 11:50:46 -0400 | [diff] [blame] | 1332 | apply_backward (c, accel); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1333 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1336 | template <typename Proxy> |
| 1337 | inline void hb_ot_map_t::apply (const Proxy &proxy, |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1338 | const hb_ot_shape_plan_t *plan, |
| 1339 | hb_font_t *font, |
| 1340 | hb_buffer_t *buffer) const |
| 1341 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1342 | const unsigned int table_index = proxy.table_index; |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1343 | unsigned int i = 0; |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1344 | OT::hb_ot_apply_context_t c (table_index, font, buffer); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1345 | c.set_recurse_func (Proxy::Lookup::apply_recurse_func); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1346 | |
| 1347 | for (unsigned int stage_index = 0; stage_index < stages[table_index].len; stage_index++) { |
| 1348 | const stage_map_t *stage = &stages[table_index][stage_index]; |
| 1349 | for (; i < stage->last_lookup; i++) |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1350 | { |
| 1351 | unsigned int lookup_index = lookups[table_index][i].index; |
Behdad Esfahbod | 0475ef2 | 2015-12-18 18:17:07 +0000 | [diff] [blame] | 1352 | if (!buffer->message (font, "start lookup %d", lookup_index)) continue; |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 1353 | c.set_lookup_index (lookup_index); |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1354 | c.set_lookup_mask (lookups[table_index][i].mask); |
| 1355 | c.set_auto_zwj (lookups[table_index][i].auto_zwj); |
Behdad Esfahbod | cdf1fd0 | 2017-07-14 12:43:34 +0100 | [diff] [blame] | 1356 | c.set_auto_zwnj (lookups[table_index][i].auto_zwnj); |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 1357 | if (lookups[table_index][i].random) |
| 1358 | { |
David Corbett | b545e27 | 2018-02-23 12:22:32 -0500 | [diff] [blame] | 1359 | c.set_random (true); |
David Corbett | c2a75e0 | 2018-01-25 14:22:03 -0500 | [diff] [blame] | 1360 | buffer->unsafe_to_break_all (); |
| 1361 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1362 | apply_string<Proxy> (&c, |
| 1363 | proxy.table.get_lookup (lookup_index), |
| 1364 | proxy.accels[lookup_index]); |
Behdad Esfahbod | 0475ef2 | 2015-12-18 18:17:07 +0000 | [diff] [blame] | 1365 | (void) buffer->message (font, "end lookup %d", lookup_index); |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1366 | } |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1367 | |
| 1368 | if (stage->pause_func) |
| 1369 | { |
| 1370 | buffer->clear_output (); |
| 1371 | stage->pause_func (plan, font, buffer); |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 1377 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1378 | GSUBProxy proxy (font->face); |
| 1379 | apply (proxy, plan, font, buffer); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 1383 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1384 | GPOSProxy proxy (font->face); |
| 1385 | apply (proxy, plan, font, buffer); |
| 1386 | } |
| 1387 | |
Behdad Esfahbod | cdab20d | 2018-02-10 15:45:17 -0600 | [diff] [blame] | 1388 | void |
Behdad Esfahbod | fd03449 | 2018-01-17 16:46:51 -0800 | [diff] [blame] | 1389 | hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1390 | const OT::SubstLookup &lookup, |
Behdad Esfahbod | 97e5913 | 2018-10-10 11:41:05 -0400 | [diff] [blame] | 1391 | const OT::hb_ot_layout_lookup_accelerator_t &accel) |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1392 | { |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1393 | apply_string<GSUBProxy> (c, lookup, accel); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1394 | } |