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 | 77a1a2b | 2015-10-09 12:20:58 -0400 | [diff] [blame] | 31 | #include "hb-open-type-private.hh" |
Behdad Esfahbod | 22da7fd | 2010-05-12 18:23:21 -0400 | [diff] [blame] | 32 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 33 | |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 34 | #include "hb-ot-layout-gdef-table.hh" |
| 35 | #include "hb-ot-layout-gsub-table.hh" |
| 36 | #include "hb-ot-layout-gpos-table.hh" |
Behdad Esfahbod | 113393e | 2017-01-21 15:12:03 -0800 | [diff] [blame] | 37 | #include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise. |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 38 | |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 39 | #include "hb-ot-map-private.hh" |
| 40 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 41 | |
Behdad Esfahbod | cfe9882 | 2012-07-27 03:06:30 -0400 | [diff] [blame] | 42 | HB_SHAPER_DATA_ENSURE_DECLARE(ot, face) |
Behdad Esfahbod | 11f4c87 | 2012-07-30 02:36:46 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 44 | hb_ot_layout_t * |
Behdad Esfahbod | 266b344 | 2011-05-03 00:35:53 -0400 | [diff] [blame] | 45 | _hb_ot_layout_create (hb_face_t *face) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 46 | { |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 47 | hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)); |
Behdad Esfahbod | 3dcbdc2 | 2012-07-30 19:31:17 -0400 | [diff] [blame] | 48 | if (unlikely (!layout)) |
| 49 | return NULL; |
Behdad Esfahbod | 555d112 | 2010-01-26 12:58:59 -0500 | [diff] [blame] | 50 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 51 | layout->gdef_blob = OT::Sanitizer<OT::GDEF>::sanitize (face->reference_table (HB_OT_TAG_GDEF)); |
| 52 | layout->gdef = OT::Sanitizer<OT::GDEF>::lock_instance (layout->gdef_blob); |
Behdad Esfahbod | 70e0f2a | 2009-08-03 22:01:47 -0400 | [diff] [blame] | 53 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 54 | layout->gsub_blob = OT::Sanitizer<OT::GSUB>::sanitize (face->reference_table (HB_OT_TAG_GSUB)); |
| 55 | layout->gsub = OT::Sanitizer<OT::GSUB>::lock_instance (layout->gsub_blob); |
Behdad Esfahbod | 70e0f2a | 2009-08-03 22:01:47 -0400 | [diff] [blame] | 56 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 57 | layout->gpos_blob = OT::Sanitizer<OT::GPOS>::sanitize (face->reference_table (HB_OT_TAG_GPOS)); |
| 58 | layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob); |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 59 | |
Behdad Esfahbod | 1f810da | 2017-01-09 23:50:56 -0800 | [diff] [blame] | 60 | layout->math.init (face); |
Behdad Esfahbod | 55d42fd | 2017-01-19 19:35:48 -0800 | [diff] [blame] | 61 | layout->fvar.init (face); |
| 62 | layout->avar.init (face); |
Frédéric Wang | 5fbcb99 | 2016-08-25 10:47:15 +0200 | [diff] [blame] | 63 | |
Behdad Esfahbod | e23cf90 | 2016-02-25 11:11:15 +0900 | [diff] [blame] | 64 | { |
| 65 | /* |
| 66 | * The ugly business of blacklisting individual fonts' tables happen here! |
| 67 | * See this thread for why we finally had to bend in and do this: |
| 68 | * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html |
| 69 | */ |
| 70 | unsigned int gdef_len = hb_blob_get_length (layout->gdef_blob); |
| 71 | unsigned int gsub_len = hb_blob_get_length (layout->gsub_blob); |
| 72 | unsigned int gpos_len = hb_blob_get_length (layout->gpos_blob); |
| 73 | if (0 |
Behdad Esfahbod | 2939388 | 2016-04-26 10:35:23 -0700 | [diff] [blame] | 74 | /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */ |
| 75 | || (442 == gdef_len && 42038 == gpos_len && 2874 == gsub_len) |
| 76 | /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */ |
| 77 | || (430 == gdef_len && 40662 == gpos_len && 2874 == gsub_len) |
| 78 | /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */ |
| 79 | || (442 == gdef_len && 39116 == gpos_len && 2874 == gsub_len) |
| 80 | /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */ |
| 81 | || (430 == gdef_len && 39374 == gpos_len && 2874 == gsub_len) |
| 82 | /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */ |
| 83 | || (490 == gdef_len && 41638 == gpos_len && 3046 == gsub_len) |
| 84 | /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */ |
| 85 | || (478 == gdef_len && 41902 == gpos_len && 3046 == gsub_len) |
Behdad Esfahbod | e23cf90 | 2016-02-25 11:11:15 +0900 | [diff] [blame] | 86 | ) |
| 87 | { |
| 88 | /* In certain versions of Times New Roman Italic and Bold Italic, |
| 89 | * ASCII double quotation mark U+0022, mapped to glyph 5, has wrong |
| 90 | * glyph class 3 (mark) in GDEF. Nuke the GDEF to avoid zero-width |
| 91 | * double-quote. See: |
| 92 | * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html |
| 93 | */ |
| 94 | if (3 == layout->gdef->get_glyph_class (5)) |
| 95 | layout->gdef = &OT::Null(OT::GDEF); |
| 96 | } |
jfkthame | f3f6c1c | 2016-06-16 00:10:42 +0100 | [diff] [blame] | 97 | else if (0 |
| 98 | /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */ |
| 99 | || (898 == gdef_len && 46470 == gpos_len && 12554 == gsub_len) |
| 100 | /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */ |
| 101 | || (910 == gdef_len && 47732 == gpos_len && 12566 == gsub_len) |
| 102 | /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */ |
| 103 | || (928 == gdef_len && 59332 == gpos_len && 23298 == gsub_len) |
| 104 | /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */ |
| 105 | || (940 == gdef_len && 60732 == gpos_len && 23310 == gsub_len) |
| 106 | /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */ |
| 107 | || (994 == gdef_len && 60336 == gpos_len && 24474 == gsub_len) |
| 108 | /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */ |
| 109 | || (1006 == gdef_len && 61740 == gpos_len && 24470 == gsub_len) |
| 110 | /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */ |
| 111 | || (832 == gdef_len && 47162 == gpos_len && 7324 == gsub_len) |
| 112 | /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */ |
| 113 | || (844 == gdef_len && 45474 == gpos_len && 7302 == gsub_len) |
| 114 | /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */ |
| 115 | || (192 == gdef_len && 7254 == gpos_len && 12638 == gsub_len) |
| 116 | /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */ |
| 117 | || (192 == gdef_len && 7254 == gpos_len && 12690 == gsub_len) |
| 118 | /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */ |
| 119 | /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */ |
| 120 | || (188 == gdef_len && 3852 == gpos_len && 248 == gsub_len) |
| 121 | /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */ |
| 122 | /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */ |
| 123 | || (188 == gdef_len && 3426 == gpos_len && 264 == gsub_len) |
Dominik Röttsches | 67e9fdf | 2016-09-05 11:27:25 +0300 | [diff] [blame] | 124 | /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */ |
| 125 | || (1046 == gdef_len && 17112 == gpos_len && 71788 == gsub_len) |
| 126 | /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */ |
| 127 | || (1058 == gdef_len && 17514 == gpos_len && 71794 == gsub_len) |
| 128 | /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */ |
| 129 | || (1330 == gdef_len && 57938 == gpos_len && 109904 == gsub_len) |
| 130 | /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */ |
| 131 | || (1330 == gdef_len && 58972 == gpos_len && 109904 == gsub_len) |
jfkthame | f3f6c1c | 2016-06-16 00:10:42 +0100 | [diff] [blame] | 132 | ) |
| 133 | { |
| 134 | /* Many versions of Tahoma have bad GDEF tables that incorrectly classify some spacing marks |
| 135 | * such as certain IPA symbols as glyph class 3. So do older versions of Microsoft Himalaya, |
| 136 | * and the version of Cantarell shipped by Ubuntu 16.04. |
| 137 | * Nuke the GDEF tables of these fonts to avoid unwanted width-zeroing. |
| 138 | * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 |
| 139 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693 |
| 140 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875 |
| 141 | */ |
| 142 | layout->gdef = &OT::Null(OT::GDEF); |
| 143 | } |
Behdad Esfahbod | e23cf90 | 2016-02-25 11:11:15 +0900 | [diff] [blame] | 144 | } |
| 145 | |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 146 | layout->gsub_lookup_count = layout->gsub->get_lookup_count (); |
| 147 | layout->gpos_lookup_count = layout->gpos->get_lookup_count (); |
| 148 | |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 149 | layout->gsub_accels = (hb_ot_layout_lookup_accelerator_t *) calloc (layout->gsub->get_lookup_count (), sizeof (hb_ot_layout_lookup_accelerator_t)); |
| 150 | layout->gpos_accels = (hb_ot_layout_lookup_accelerator_t *) calloc (layout->gpos->get_lookup_count (), sizeof (hb_ot_layout_lookup_accelerator_t)); |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 151 | |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 152 | if (unlikely ((layout->gsub_lookup_count && !layout->gsub_accels) || |
| 153 | (layout->gpos_lookup_count && !layout->gpos_accels))) |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 154 | { |
| 155 | _hb_ot_layout_destroy (layout); |
| 156 | return NULL; |
| 157 | } |
| 158 | |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 159 | for (unsigned int i = 0; i < layout->gsub_lookup_count; i++) |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 160 | layout->gsub_accels[i].init (layout->gsub->get_lookup (i)); |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 161 | for (unsigned int i = 0; i < layout->gpos_lookup_count; i++) |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 162 | layout->gpos_accels[i].init (layout->gpos->get_lookup (i)); |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 163 | |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 164 | return layout; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 167 | void |
Behdad Esfahbod | 266b344 | 2011-05-03 00:35:53 -0400 | [diff] [blame] | 168 | _hb_ot_layout_destroy (hb_ot_layout_t *layout) |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 169 | { |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 170 | for (unsigned int i = 0; i < layout->gsub_lookup_count; i++) |
Behdad Esfahbod | 395b359 | 2014-12-28 16:03:26 -0800 | [diff] [blame] | 171 | layout->gsub_accels[i].fini (); |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 172 | for (unsigned int i = 0; i < layout->gpos_lookup_count; i++) |
Behdad Esfahbod | 395b359 | 2014-12-28 16:03:26 -0800 | [diff] [blame] | 173 | layout->gpos_accels[i].fini (); |
Behdad Esfahbod | 45fd942 | 2013-05-02 18:06:51 -0400 | [diff] [blame] | 174 | |
| 175 | free (layout->gsub_accels); |
| 176 | free (layout->gpos_accels); |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 177 | |
Bradley Grainger | 89312b7 | 2013-06-21 15:02:18 -0700 | [diff] [blame] | 178 | hb_blob_destroy (layout->gdef_blob); |
| 179 | hb_blob_destroy (layout->gsub_blob); |
| 180 | hb_blob_destroy (layout->gpos_blob); |
Behdad Esfahbod | 1f810da | 2017-01-09 23:50:56 -0800 | [diff] [blame] | 181 | |
| 182 | layout->math.fini (); |
Behdad Esfahbod | 55d42fd | 2017-01-19 19:35:48 -0800 | [diff] [blame] | 183 | layout->fvar.fini (); |
| 184 | layout->avar.fini (); |
Frédéric Wang | 5fbcb99 | 2016-08-25 10:47:15 +0200 | [diff] [blame] | 185 | |
Behdad Esfahbod | 9ea7368 | 2010-09-22 17:38:44 -0400 | [diff] [blame] | 186 | free (layout); |
Behdad Esfahbod | 2ebb89d | 2009-07-25 19:09:01 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 189 | static inline const OT::GDEF& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 190 | _get_gdef (hb_face_t *face) |
| 191 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 192 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GDEF); |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 193 | return *hb_ot_layout_from_face (face)->gdef; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 194 | } |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 195 | static inline const OT::GSUB& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 196 | _get_gsub (hb_face_t *face) |
| 197 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 198 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GSUB); |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 199 | return *hb_ot_layout_from_face (face)->gsub; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 200 | } |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 201 | static inline const OT::GPOS& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 202 | _get_gpos (hb_face_t *face) |
| 203 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 204 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GPOS); |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 205 | return *hb_ot_layout_from_face (face)->gpos; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 206 | } |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 207 | |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 208 | /* |
| 209 | * GDEF |
| 210 | */ |
| 211 | |
| 212 | hb_bool_t |
Behdad Esfahbod | 52ea477 | 2009-11-06 17:45:38 -0500 | [diff] [blame] | 213 | hb_ot_layout_has_glyph_classes (hb_face_t *face) |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 214 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 215 | return _get_gdef (face).has_glyph_classes (); |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 216 | } |
| 217 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 218 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 219 | * hb_ot_layout_get_glyph_class: |
| 220 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 221 | * Since: 0.9.7 |
| 222 | **/ |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 223 | hb_ot_layout_glyph_class_t |
| 224 | hb_ot_layout_get_glyph_class (hb_face_t *face, |
| 225 | hb_codepoint_t glyph) |
| 226 | { |
| 227 | return (hb_ot_layout_glyph_class_t) _get_gdef (face).get_glyph_class (glyph); |
| 228 | } |
Behdad Esfahbod | 4a2d844 | 2010-11-03 15:28:56 -0400 | [diff] [blame] | 229 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 230 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 231 | * hb_ot_layout_get_glyphs_in_class: |
| 232 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 233 | * Since: 0.9.7 |
| 234 | **/ |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 235 | void |
| 236 | hb_ot_layout_get_glyphs_in_class (hb_face_t *face, |
| 237 | hb_ot_layout_glyph_class_t klass, |
| 238 | hb_set_t *glyphs /* OUT */) |
| 239 | { |
| 240 | return _get_gdef (face).get_glyphs_in_class (klass, glyphs); |
| 241 | } |
| 242 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 243 | unsigned int |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 244 | hb_ot_layout_get_attach_points (hb_face_t *face, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 245 | hb_codepoint_t glyph, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 246 | unsigned int start_offset, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 247 | unsigned int *point_count /* IN/OUT */, |
| 248 | unsigned int *point_array /* OUT */) |
| 249 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 250 | 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] | 251 | } |
| 252 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 253 | unsigned int |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 254 | hb_ot_layout_get_ligature_carets (hb_font_t *font, |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 255 | hb_direction_t direction, |
| 256 | hb_codepoint_t glyph, |
| 257 | unsigned int start_offset, |
| 258 | unsigned int *caret_count /* IN/OUT */, |
| 259 | int *caret_array /* OUT */) |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 260 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 261 | 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] | 262 | } |
| 263 | |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 264 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 265 | /* |
| 266 | * GSUB/GPOS |
| 267 | */ |
| 268 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 269 | static const OT::GSUBGPOS& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 270 | get_gsubgpos_table (hb_face_t *face, |
| 271 | hb_tag_t table_tag) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 272 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 273 | switch (table_tag) { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 274 | case HB_OT_TAG_GSUB: return _get_gsub (face); |
| 275 | case HB_OT_TAG_GPOS: return _get_gpos (face); |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 276 | default: return OT::Null(OT::GSUBGPOS); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 281 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 282 | hb_ot_layout_table_get_script_tags (hb_face_t *face, |
| 283 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 284 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 285 | unsigned int *script_count /* IN/OUT */, |
| 286 | hb_tag_t *script_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 287 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 288 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 289 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 290 | return g.get_script_tags (start_offset, script_count, script_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 291 | } |
| 292 | |
Behdad Esfahbod | eb45c0a | 2013-01-16 22:07:50 -0600 | [diff] [blame] | 293 | #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
| 294 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 295 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 296 | hb_ot_layout_table_find_script (hb_face_t *face, |
| 297 | hb_tag_t table_tag, |
| 298 | hb_tag_t script_tag, |
| 299 | unsigned int *script_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 300 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 301 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); |
| 302 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 303 | |
| 304 | if (g.find_script_index (script_tag, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 305 | return true; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 306 | |
| 307 | /* try finding 'DFLT' */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 308 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 309 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 310 | |
Behdad Esfahbod | dca8aff | 2010-09-28 16:25:23 -0400 | [diff] [blame] | 311 | /* try with 'dflt'; MS site has had typos and many fonts use it now :(. |
| 312 | * including many versions of DejaVu Sans Mono! */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 313 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 314 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 315 | |
Behdad Esfahbod | eb45c0a | 2013-01-16 22:07:50 -0600 | [diff] [blame] | 316 | /* try with 'latn'; some old fonts put their features there even though |
| 317 | they're really trying to support Thai, for example :( */ |
| 318 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) |
| 319 | return false; |
| 320 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 321 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 322 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 323 | } |
| 324 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 325 | hb_bool_t |
| 326 | hb_ot_layout_table_choose_script (hb_face_t *face, |
| 327 | hb_tag_t table_tag, |
| 328 | const hb_tag_t *script_tags, |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 329 | unsigned int *script_index, |
| 330 | hb_tag_t *chosen_script) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 331 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 332 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); |
| 333 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 334 | |
| 335 | while (*script_tags) |
| 336 | { |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 337 | if (g.find_script_index (*script_tags, script_index)) { |
| 338 | if (chosen_script) |
| 339 | *chosen_script = *script_tags; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 340 | return true; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 341 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 342 | script_tags++; |
| 343 | } |
| 344 | |
| 345 | /* try finding 'DFLT' */ |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 346 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
| 347 | if (chosen_script) |
| 348 | *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 349 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 350 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 351 | |
| 352 | /* 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] | 353 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { |
| 354 | if (chosen_script) |
| 355 | *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 356 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 357 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 358 | |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 359 | /* try with 'latn'; some old fonts put their features there even though |
| 360 | they're really trying to support Thai, for example :( */ |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 361 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { |
| 362 | if (chosen_script) |
| 363 | *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 364 | return false; |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 365 | } |
| 366 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 367 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 368 | if (chosen_script) |
| 369 | *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 370 | return false; |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 371 | } |
| 372 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 373 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 374 | hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
| 375 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 376 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 377 | unsigned int *feature_count /* IN/OUT */, |
| 378 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 379 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 380 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 381 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 382 | return g.get_feature_tags (start_offset, feature_count, feature_tags); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 383 | } |
| 384 | |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 385 | hb_bool_t |
| 386 | hb_ot_layout_table_find_feature (hb_face_t *face, |
| 387 | hb_tag_t table_tag, |
| 388 | hb_tag_t feature_tag, |
| 389 | unsigned int *feature_index) |
| 390 | { |
| 391 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); |
| 392 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 393 | |
| 394 | unsigned int num_features = g.get_feature_count (); |
| 395 | for (unsigned int i = 0; i < num_features; i++) |
| 396 | { |
| 397 | if (feature_tag == g.get_feature_tag (i)) { |
| 398 | if (feature_index) *feature_index = i; |
| 399 | return true; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
| 404 | return false; |
| 405 | } |
| 406 | |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 407 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 408 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 409 | hb_ot_layout_script_get_language_tags (hb_face_t *face, |
| 410 | hb_tag_t table_tag, |
| 411 | unsigned int script_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 412 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 413 | unsigned int *language_count /* IN/OUT */, |
| 414 | hb_tag_t *language_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 415 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 416 | 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] | 417 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 418 | return s.get_lang_sys_tags (start_offset, language_count, language_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 422 | hb_ot_layout_script_find_language (hb_face_t *face, |
| 423 | hb_tag_t table_tag, |
| 424 | unsigned int script_index, |
| 425 | hb_tag_t language_tag, |
| 426 | unsigned int *language_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 427 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 428 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX); |
| 429 | 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] | 430 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 431 | if (s.find_lang_sys_index (language_tag, language_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 432 | return true; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 433 | |
| 434 | /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 435 | 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] | 436 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 437 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 438 | if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 439 | return false; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 440 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 441 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 442 | hb_bool_t |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 443 | hb_ot_layout_language_get_required_feature_index (hb_face_t *face, |
| 444 | hb_tag_t table_tag, |
| 445 | unsigned int script_index, |
| 446 | unsigned int language_index, |
| 447 | unsigned int *feature_index) |
| 448 | { |
| 449 | return hb_ot_layout_language_get_required_feature (face, |
| 450 | table_tag, |
| 451 | script_index, |
| 452 | language_index, |
| 453 | feature_index, |
| 454 | NULL); |
| 455 | } |
| 456 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 457 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 458 | * hb_ot_layout_language_get_required_feature: |
| 459 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 460 | * Since: 0.9.30 |
| 461 | **/ |
Behdad Esfahbod | 911ca38 | 2014-06-24 10:20:36 -0600 | [diff] [blame] | 462 | hb_bool_t |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 463 | hb_ot_layout_language_get_required_feature (hb_face_t *face, |
| 464 | hb_tag_t table_tag, |
| 465 | unsigned int script_index, |
| 466 | unsigned int language_index, |
| 467 | unsigned int *feature_index, |
| 468 | hb_tag_t *feature_tag) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 469 | { |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 470 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 471 | 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] | 472 | |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 473 | unsigned int index = l.get_required_feature_index (); |
| 474 | if (feature_index) *feature_index = index; |
| 475 | if (feature_tag) *feature_tag = g.get_feature_tag (index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 476 | |
| 477 | return l.has_required_feature (); |
| 478 | } |
| 479 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 480 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 481 | hb_ot_layout_language_get_feature_indexes (hb_face_t *face, |
| 482 | hb_tag_t table_tag, |
| 483 | unsigned int script_index, |
| 484 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 485 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 486 | unsigned int *feature_count /* IN/OUT */, |
| 487 | unsigned int *feature_indexes /* OUT */) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 488 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 489 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 490 | 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] | 491 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 492 | return l.get_feature_indexes (start_offset, feature_count, feature_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 495 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 496 | hb_ot_layout_language_get_feature_tags (hb_face_t *face, |
| 497 | hb_tag_t table_tag, |
| 498 | unsigned int script_index, |
| 499 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 500 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 501 | unsigned int *feature_count /* IN/OUT */, |
| 502 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 503 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 504 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 505 | 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] | 506 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 507 | ASSERT_STATIC (sizeof (unsigned int) == sizeof (hb_tag_t)); |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 508 | 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] | 509 | |
Behdad Esfahbod | 9897749 | 2009-08-27 01:32:17 -0400 | [diff] [blame] | 510 | if (feature_tags) { |
| 511 | unsigned int count = *feature_count; |
| 512 | for (unsigned int i = 0; i < count; i++) |
| 513 | feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); |
| 514 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 515 | |
| 516 | return ret; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 517 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 518 | |
| 519 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 520 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 521 | hb_ot_layout_language_find_feature (hb_face_t *face, |
| 522 | hb_tag_t table_tag, |
| 523 | unsigned int script_index, |
| 524 | unsigned int language_index, |
| 525 | hb_tag_t feature_tag, |
| 526 | unsigned int *feature_index) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 527 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 528 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); |
| 529 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 530 | 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] | 531 | |
Behdad Esfahbod | f4c9514 | 2009-05-17 04:59:56 -0400 | [diff] [blame] | 532 | unsigned int num_features = l.get_feature_count (); |
| 533 | for (unsigned int i = 0; i < num_features; i++) { |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 534 | unsigned int f_index = l.get_feature_index (i); |
| 535 | |
| 536 | if (feature_tag == g.get_feature_tag (f_index)) { |
| 537 | if (feature_index) *feature_index = f_index; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 538 | return true; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 543 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 544 | } |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 545 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 546 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 547 | * hb_ot_layout_feature_get_lookups: |
| 548 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 549 | * Since: 0.9.7 |
| 550 | **/ |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 551 | unsigned int |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 552 | hb_ot_layout_feature_get_lookups (hb_face_t *face, |
| 553 | hb_tag_t table_tag, |
| 554 | unsigned int feature_index, |
| 555 | unsigned int start_offset, |
| 556 | unsigned int *lookup_count /* IN/OUT */, |
| 557 | unsigned int *lookup_indexes /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 558 | { |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 559 | return hb_ot_layout_feature_with_variations_get_lookups (face, |
| 560 | table_tag, |
| 561 | feature_index, |
| 562 | HB_OT_LAYOUT_NO_VARIATIONS_INDEX, |
| 563 | start_offset, |
| 564 | lookup_count, |
| 565 | lookup_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 566 | } |
| 567 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 568 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 569 | * hb_ot_layout_table_get_lookup_count: |
| 570 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 571 | * Since: 0.9.22 |
| 572 | **/ |
Behdad Esfahbod | 27674b4 | 2013-10-03 14:54:50 -0400 | [diff] [blame] | 573 | unsigned int |
| 574 | hb_ot_layout_table_get_lookup_count (hb_face_t *face, |
| 575 | hb_tag_t table_tag) |
| 576 | { |
| 577 | switch (table_tag) |
| 578 | { |
| 579 | case HB_OT_TAG_GSUB: |
| 580 | { |
| 581 | return hb_ot_layout_from_face (face)->gsub_lookup_count; |
| 582 | } |
| 583 | case HB_OT_TAG_GPOS: |
| 584 | { |
| 585 | return hb_ot_layout_from_face (face)->gpos_lookup_count; |
| 586 | } |
| 587 | } |
Behdad Esfahbod | 4e6e53d | 2013-10-14 13:06:36 +0200 | [diff] [blame] | 588 | return 0; |
Behdad Esfahbod | 27674b4 | 2013-10-03 14:54:50 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 591 | static void |
| 592 | _hb_ot_layout_collect_lookups_lookups (hb_face_t *face, |
| 593 | hb_tag_t table_tag, |
| 594 | unsigned int feature_index, |
| 595 | hb_set_t *lookup_indexes /* OUT */) |
| 596 | { |
| 597 | unsigned int lookup_indices[32]; |
| 598 | unsigned int offset, len; |
| 599 | |
| 600 | offset = 0; |
| 601 | do { |
| 602 | len = ARRAY_LENGTH (lookup_indices); |
| 603 | hb_ot_layout_feature_get_lookups (face, |
| 604 | table_tag, |
| 605 | feature_index, |
| 606 | offset, &len, |
| 607 | lookup_indices); |
| 608 | |
| 609 | for (unsigned int i = 0; i < len; i++) |
| 610 | lookup_indexes->add (lookup_indices[i]); |
| 611 | |
| 612 | offset += len; |
| 613 | } while (len == ARRAY_LENGTH (lookup_indices)); |
| 614 | } |
| 615 | |
| 616 | static void |
| 617 | _hb_ot_layout_collect_lookups_features (hb_face_t *face, |
| 618 | hb_tag_t table_tag, |
| 619 | unsigned int script_index, |
| 620 | unsigned int language_index, |
| 621 | const hb_tag_t *features, |
| 622 | hb_set_t *lookup_indexes /* OUT */) |
| 623 | { |
| 624 | if (!features) |
| 625 | { |
Behdad Esfahbod | 5f85c80 | 2013-06-26 20:14:18 -0400 | [diff] [blame] | 626 | unsigned int required_feature_index; |
Jonathan Kew | da13293 | 2014-04-27 14:05:24 +0100 | [diff] [blame] | 627 | if (hb_ot_layout_language_get_required_feature (face, |
| 628 | table_tag, |
| 629 | script_index, |
| 630 | language_index, |
| 631 | &required_feature_index, |
| 632 | NULL)) |
Behdad Esfahbod | 5f85c80 | 2013-06-26 20:14:18 -0400 | [diff] [blame] | 633 | _hb_ot_layout_collect_lookups_lookups (face, |
| 634 | table_tag, |
| 635 | required_feature_index, |
| 636 | lookup_indexes); |
| 637 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 638 | /* All features */ |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 639 | unsigned int feature_indices[32]; |
| 640 | unsigned int offset, len; |
| 641 | |
| 642 | offset = 0; |
| 643 | do { |
| 644 | len = ARRAY_LENGTH (feature_indices); |
| 645 | hb_ot_layout_language_get_feature_indexes (face, |
| 646 | table_tag, |
| 647 | script_index, |
| 648 | language_index, |
| 649 | offset, &len, |
| 650 | feature_indices); |
| 651 | |
| 652 | for (unsigned int i = 0; i < len; i++) |
| 653 | _hb_ot_layout_collect_lookups_lookups (face, |
| 654 | table_tag, |
| 655 | feature_indices[i], |
| 656 | lookup_indexes); |
| 657 | |
| 658 | offset += len; |
| 659 | } while (len == ARRAY_LENGTH (feature_indices)); |
| 660 | } |
| 661 | else |
| 662 | { |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 663 | for (; *features; features++) |
| 664 | { |
| 665 | unsigned int feature_index; |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 666 | if (hb_ot_layout_language_find_feature (face, |
| 667 | table_tag, |
| 668 | script_index, |
| 669 | language_index, |
| 670 | *features, |
| 671 | &feature_index)) |
| 672 | _hb_ot_layout_collect_lookups_lookups (face, |
| 673 | table_tag, |
| 674 | feature_index, |
| 675 | lookup_indexes); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | static void |
| 681 | _hb_ot_layout_collect_lookups_languages (hb_face_t *face, |
| 682 | hb_tag_t table_tag, |
| 683 | unsigned int script_index, |
| 684 | const hb_tag_t *languages, |
| 685 | const hb_tag_t *features, |
| 686 | hb_set_t *lookup_indexes /* OUT */) |
| 687 | { |
Behdad Esfahbod | f0c8241 | 2013-01-03 00:07:16 -0600 | [diff] [blame] | 688 | _hb_ot_layout_collect_lookups_features (face, |
| 689 | table_tag, |
| 690 | script_index, |
| 691 | HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX, |
| 692 | features, |
| 693 | lookup_indexes); |
| 694 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 695 | if (!languages) |
| 696 | { |
| 697 | /* All languages */ |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 698 | unsigned int count = hb_ot_layout_script_get_language_tags (face, |
| 699 | table_tag, |
| 700 | script_index, |
| 701 | 0, NULL, NULL); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 702 | for (unsigned int language_index = 0; language_index < count; language_index++) |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 703 | _hb_ot_layout_collect_lookups_features (face, |
| 704 | table_tag, |
| 705 | script_index, |
| 706 | language_index, |
| 707 | features, |
| 708 | lookup_indexes); |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 709 | } |
| 710 | else |
| 711 | { |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 712 | for (; *languages; languages++) |
| 713 | { |
| 714 | unsigned int language_index; |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 715 | if (hb_ot_layout_script_find_language (face, |
| 716 | table_tag, |
| 717 | script_index, |
| 718 | *languages, |
| 719 | &language_index)) |
| 720 | _hb_ot_layout_collect_lookups_features (face, |
| 721 | table_tag, |
| 722 | script_index, |
| 723 | language_index, |
| 724 | features, |
| 725 | lookup_indexes); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 730 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 731 | * hb_ot_layout_collect_lookups: |
| 732 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 733 | * Since: 0.9.8 |
| 734 | **/ |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 735 | void |
| 736 | hb_ot_layout_collect_lookups (hb_face_t *face, |
| 737 | hb_tag_t table_tag, |
| 738 | const hb_tag_t *scripts, |
| 739 | const hb_tag_t *languages, |
| 740 | const hb_tag_t *features, |
| 741 | hb_set_t *lookup_indexes /* OUT */) |
| 742 | { |
| 743 | if (!scripts) |
| 744 | { |
| 745 | /* All scripts */ |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 746 | unsigned int count = hb_ot_layout_table_get_script_tags (face, |
| 747 | table_tag, |
| 748 | 0, NULL, NULL); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 749 | for (unsigned int script_index = 0; script_index < count; script_index++) |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 750 | _hb_ot_layout_collect_lookups_languages (face, |
| 751 | table_tag, |
| 752 | script_index, |
| 753 | languages, |
| 754 | features, |
| 755 | lookup_indexes); |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 759 | for (; *scripts; scripts++) |
| 760 | { |
| 761 | unsigned int script_index; |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 762 | if (hb_ot_layout_table_find_script (face, |
| 763 | table_tag, |
| 764 | *scripts, |
| 765 | &script_index)) |
| 766 | _hb_ot_layout_collect_lookups_languages (face, |
| 767 | table_tag, |
| 768 | script_index, |
| 769 | languages, |
| 770 | features, |
| 771 | lookup_indexes); |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | } |
| 775 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 776 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 777 | * hb_ot_layout_lookup_collect_glyphs: |
| 778 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 779 | * Since: 0.9.7 |
| 780 | **/ |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 781 | void |
| 782 | hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, |
| 783 | hb_tag_t table_tag, |
| 784 | unsigned int lookup_index, |
| 785 | hb_set_t *glyphs_before, /* OUT. May be NULL */ |
| 786 | hb_set_t *glyphs_input, /* OUT. May be NULL */ |
| 787 | hb_set_t *glyphs_after, /* OUT. May be NULL */ |
| 788 | hb_set_t *glyphs_output /* OUT. May be NULL */) |
| 789 | { |
| 790 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; |
| 791 | |
Behdad Esfahbod | 733e8c0 | 2013-01-03 00:00:23 -0600 | [diff] [blame] | 792 | OT::hb_collect_glyphs_context_t c (face, |
| 793 | glyphs_before, |
| 794 | glyphs_input, |
| 795 | glyphs_after, |
| 796 | glyphs_output); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 797 | |
Behdad Esfahbod | 15e9e4e | 2013-01-03 00:04:40 -0600 | [diff] [blame] | 798 | switch (table_tag) |
| 799 | { |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 800 | case HB_OT_TAG_GSUB: |
| 801 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 802 | const OT::SubstLookup& l = hb_ot_layout_from_face (face)->gsub->get_lookup (lookup_index); |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 803 | l.collect_glyphs (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 804 | return; |
| 805 | } |
| 806 | case HB_OT_TAG_GPOS: |
| 807 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 808 | const OT::PosLookup& l = hb_ot_layout_from_face (face)->gpos->get_lookup (lookup_index); |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 809 | l.collect_glyphs (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 810 | return; |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 815 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 816 | /* Variations support */ |
| 817 | |
| 818 | hb_bool_t |
| 819 | hb_ot_layout_table_find_feature_variations (hb_face_t *face, |
| 820 | hb_tag_t table_tag, |
| 821 | const int *coords, |
| 822 | unsigned int num_coords, |
| 823 | unsigned int *variations_index /* out */) |
| 824 | { |
| 825 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 826 | |
| 827 | return g.find_variations_index (coords, num_coords, variations_index); |
| 828 | } |
| 829 | |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 830 | unsigned int |
| 831 | hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, |
| 832 | hb_tag_t table_tag, |
| 833 | unsigned int feature_index, |
| 834 | unsigned int variations_index, |
| 835 | unsigned int start_offset, |
| 836 | unsigned int *lookup_count /* IN/OUT */, |
| 837 | unsigned int *lookup_indexes /* OUT */) |
| 838 | { |
| 839 | ASSERT_STATIC (OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX); |
| 840 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 841 | |
| 842 | const OT::Feature &f = g.get_feature_variation (feature_index, variations_index); |
| 843 | |
| 844 | return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); |
| 845 | } |
| 846 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 847 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 848 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 849 | * OT::GSUB |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 850 | */ |
| 851 | |
| 852 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 853 | hb_ot_layout_has_substitution (hb_face_t *face) |
| 854 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 855 | return &_get_gsub (face) != &OT::Null(OT::GSUB); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 856 | } |
| 857 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 858 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 859 | * hb_ot_layout_lookup_would_substitute: |
| 860 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 861 | * Since: 0.9.7 |
| 862 | **/ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 863 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 864 | hb_ot_layout_lookup_would_substitute (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 865 | unsigned int lookup_index, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 866 | const hb_codepoint_t *glyphs, |
| 867 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 868 | hb_bool_t zero_context) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 869 | { |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 870 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 871 | 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] | 872 | } |
| 873 | |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 874 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 875 | hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 876 | unsigned int lookup_index, |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 877 | const hb_codepoint_t *glyphs, |
| 878 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 879 | hb_bool_t zero_context) |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 880 | { |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 881 | if (unlikely (lookup_index >= hb_ot_layout_from_face (face)->gsub_lookup_count)) return false; |
Behdad Esfahbod | ea512f7 | 2015-11-26 19:22:22 -0500 | [diff] [blame] | 882 | 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] | 883 | |
| 884 | const OT::SubstLookup& l = hb_ot_layout_from_face (face)->gsub->get_lookup (lookup_index); |
| 885 | |
Behdad Esfahbod | 241eac9 | 2015-01-28 20:55:42 -0800 | [diff] [blame] | 886 | return l.would_apply (&c, &hb_ot_layout_from_face (face)->gsub_accels[lookup_index]); |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 887 | } |
| 888 | |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 889 | void |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 890 | hb_ot_layout_substitute_start (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 891 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 892 | OT::GSUB::substitute_start (font, buffer); |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 893 | } |
| 894 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 895 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 896 | * hb_ot_layout_lookup_substitute_closure: |
| 897 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 898 | * Since: 0.9.7 |
| 899 | **/ |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 900 | void |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 901 | hb_ot_layout_lookup_substitute_closure (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 902 | unsigned int lookup_index, |
| 903 | hb_set_t *glyphs) |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 904 | { |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 905 | OT::hb_closure_context_t c (face, glyphs); |
| 906 | |
| 907 | const OT::SubstLookup& l = _get_gsub (face).get_lookup (lookup_index); |
| 908 | |
| 909 | l.closure (&c); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 910 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 911 | |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 912 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 913 | * OT::GPOS |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 914 | */ |
| 915 | |
| 916 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 917 | hb_ot_layout_has_positioning (hb_face_t *face) |
| 918 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 919 | return &_get_gpos (face) != &OT::Null(OT::GPOS); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 920 | } |
| 921 | |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 922 | void |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 923 | 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] | 924 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 925 | OT::GPOS::position_start (font, buffer); |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 926 | } |
| 927 | |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 928 | void |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 929 | 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] | 930 | { |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 931 | OT::GPOS::position_finish_advances (font, buffer); |
| 932 | } |
| 933 | |
| 934 | void |
| 935 | hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) |
| 936 | { |
| 937 | OT::GPOS::position_finish_offsets (font, buffer); |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 938 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 939 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 940 | /** |
Khaled Hosny | d7bf9d0 | 2015-12-29 02:23:24 +0400 | [diff] [blame] | 941 | * hb_ot_layout_get_size_params: |
| 942 | * |
Behdad Esfahbod | b881142 | 2015-09-03 15:53:22 +0430 | [diff] [blame] | 943 | * Since: 0.9.10 |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 944 | **/ |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 945 | hb_bool_t |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 946 | hb_ot_layout_get_size_params (hb_face_t *face, |
| 947 | unsigned int *design_size, /* OUT. May be NULL */ |
| 948 | unsigned int *subfamily_id, /* OUT. May be NULL */ |
| 949 | unsigned int *subfamily_name_id, /* OUT. May be NULL */ |
| 950 | unsigned int *range_start, /* OUT. May be NULL */ |
| 951 | unsigned int *range_end /* OUT. May be NULL */) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 952 | { |
| 953 | const OT::GPOS &gpos = _get_gpos (face); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 954 | const hb_tag_t tag = HB_TAG ('s','i','z','e'); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 955 | |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame] | 956 | unsigned int num_features = gpos.get_feature_count (); |
| 957 | for (unsigned int i = 0; i < num_features; i++) |
| 958 | { |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 959 | if (tag == gpos.get_feature_tag (i)) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 960 | { |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame] | 961 | const OT::Feature &f = gpos.get_feature (i); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 962 | const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 963 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 964 | if (params.designSize) |
Behdad Esfahbod | 85bc44b | 2012-12-12 11:38:49 -0500 | [diff] [blame] | 965 | { |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 966 | #define PARAM(a, A) if (a) *a = params.A |
Behdad Esfahbod | 85bc44b | 2012-12-12 11:38:49 -0500 | [diff] [blame] | 967 | PARAM (design_size, designSize); |
| 968 | PARAM (subfamily_id, subfamilyID); |
| 969 | PARAM (subfamily_name_id, subfamilyNameID); |
| 970 | PARAM (range_start, rangeStart); |
| 971 | PARAM (range_end, rangeEnd); |
Behdad Esfahbod | 85bc44b | 2012-12-12 11:38:49 -0500 | [diff] [blame] | 972 | #undef PARAM |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 973 | |
| 974 | return true; |
| 975 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 979 | #define PARAM(a, A) if (a) *a = 0 |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 980 | PARAM (design_size, designSize); |
| 981 | PARAM (subfamily_id, subfamilyID); |
| 982 | PARAM (subfamily_name_id, subfamilyNameID); |
| 983 | PARAM (range_start, rangeStart); |
| 984 | PARAM (range_end, rangeEnd); |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 985 | #undef PARAM |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 986 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 987 | return false; |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 988 | } |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 989 | |
| 990 | |
| 991 | /* |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 992 | * Parts of different types are implemented here such that they have direct |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 993 | * access to GSUB/GPOS lookups. |
| 994 | */ |
| 995 | |
| 996 | |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 997 | struct GSUBProxy |
| 998 | { |
| 999 | static const unsigned int table_index = 0; |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1000 | static const bool inplace = false; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1001 | typedef OT::SubstLookup Lookup; |
| 1002 | |
| 1003 | GSUBProxy (hb_face_t *face) : |
| 1004 | table (*hb_ot_layout_from_face (face)->gsub), |
| 1005 | accels (hb_ot_layout_from_face (face)->gsub_accels) {} |
| 1006 | |
| 1007 | const OT::GSUB &table; |
| 1008 | const hb_ot_layout_lookup_accelerator_t *accels; |
| 1009 | }; |
| 1010 | |
| 1011 | struct GPOSProxy |
| 1012 | { |
| 1013 | static const unsigned int table_index = 1; |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1014 | static const bool inplace = true; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1015 | typedef OT::PosLookup Lookup; |
| 1016 | |
| 1017 | GPOSProxy (hb_face_t *face) : |
| 1018 | table (*hb_ot_layout_from_face (face)->gpos), |
| 1019 | accels (hb_ot_layout_from_face (face)->gpos_accels) {} |
| 1020 | |
| 1021 | const OT::GPOS &table; |
| 1022 | const hb_ot_layout_lookup_accelerator_t *accels; |
| 1023 | }; |
| 1024 | |
| 1025 | |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1026 | struct hb_get_subtables_context_t : |
| 1027 | OT::hb_dispatch_context_t<hb_get_subtables_context_t, hb_void_t, HB_DEBUG_APPLY> |
| 1028 | { |
| 1029 | template <typename Type> |
| 1030 | static inline bool apply_to (const void *obj, OT::hb_apply_context_t *c) |
| 1031 | { |
| 1032 | const Type *typed_obj = (const Type *) obj; |
| 1033 | return typed_obj->apply (c); |
| 1034 | } |
| 1035 | |
| 1036 | typedef bool (*hb_apply_func_t) (const void *obj, OT::hb_apply_context_t *c); |
| 1037 | |
| 1038 | struct hb_applicable_t |
| 1039 | { |
| 1040 | inline void init (const void *obj_, hb_apply_func_t apply_func_) |
| 1041 | { |
| 1042 | obj = obj_; |
| 1043 | apply_func = apply_func_; |
| 1044 | } |
| 1045 | |
| 1046 | inline bool apply (OT::hb_apply_context_t *c) const { return apply_func (obj, c); } |
| 1047 | |
| 1048 | private: |
| 1049 | const void *obj; |
| 1050 | hb_apply_func_t apply_func; |
| 1051 | }; |
| 1052 | |
| 1053 | typedef hb_auto_array_t<hb_applicable_t> array_t; |
| 1054 | |
| 1055 | /* Dispatch interface. */ |
| 1056 | inline const char *get_name (void) { return "GET_SUBTABLES"; } |
| 1057 | template <typename T> |
| 1058 | inline return_t dispatch (const T &obj) |
| 1059 | { |
| 1060 | hb_applicable_t *entry = array.push(); |
| 1061 | if (likely (entry)) |
| 1062 | entry->init (&obj, apply_to<T>); |
| 1063 | return HB_VOID; |
| 1064 | } |
| 1065 | static return_t default_return_value (void) { return HB_VOID; } |
| 1066 | bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; } |
| 1067 | |
| 1068 | hb_get_subtables_context_t (array_t &array_) : |
| 1069 | array (array_), |
| 1070 | debug_depth (0) {} |
| 1071 | |
| 1072 | array_t &array; |
| 1073 | unsigned int debug_depth; |
| 1074 | }; |
| 1075 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1076 | static inline bool |
| 1077 | apply_forward (OT::hb_apply_context_t *c, |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1078 | const hb_ot_layout_lookup_accelerator_t &accel, |
| 1079 | const hb_get_subtables_context_t::array_t &subtables) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1080 | { |
| 1081 | bool ret = false; |
| 1082 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | abadc17 | 2015-11-18 17:52:08 -0800 | [diff] [blame] | 1083 | while (buffer->idx < buffer->len && !buffer->in_error) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1084 | { |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1085 | bool applied = false; |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1086 | if (accel.may_have (buffer->cur().codepoint) && |
| 1087 | (buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1088 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1089 | { |
| 1090 | for (unsigned int i = 0; i < subtables.len; i++) |
| 1091 | if (subtables[i].apply (c)) |
| 1092 | { |
| 1093 | applied = true; |
| 1094 | break; |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | if (applied) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1099 | ret = true; |
| 1100 | else |
| 1101 | buffer->next_glyph (); |
| 1102 | } |
| 1103 | return ret; |
| 1104 | } |
| 1105 | |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1106 | static inline bool |
| 1107 | apply_backward (OT::hb_apply_context_t *c, |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1108 | const hb_ot_layout_lookup_accelerator_t &accel, |
| 1109 | const hb_get_subtables_context_t::array_t &subtables) |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1110 | { |
| 1111 | bool ret = false; |
| 1112 | hb_buffer_t *buffer = c->buffer; |
| 1113 | do |
| 1114 | { |
| 1115 | if (accel.may_have (buffer->cur().codepoint) && |
| 1116 | (buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1117 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
| 1118 | { |
| 1119 | for (unsigned int i = 0; i < subtables.len; i++) |
| 1120 | if (subtables[i].apply (c)) |
| 1121 | { |
| 1122 | ret = true; |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
Behdad Esfahbod | e2f50f2 | 2015-02-19 17:15:05 +0300 | [diff] [blame] | 1126 | /* The reverse lookup doesn't "advance" cursor (for good reason). */ |
| 1127 | buffer->idx--; |
| 1128 | |
| 1129 | } |
| 1130 | while ((int) buffer->idx >= 0); |
| 1131 | return ret; |
| 1132 | } |
| 1133 | |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1134 | template <typename Proxy> |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1135 | static inline void |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1136 | apply_string (OT::hb_apply_context_t *c, |
| 1137 | const typename Proxy::Lookup &lookup, |
| 1138 | const hb_ot_layout_lookup_accelerator_t &accel) |
| 1139 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1140 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1141 | |
Behdad Esfahbod | 5337db2 | 2015-11-06 16:18:09 -0800 | [diff] [blame] | 1142 | if (unlikely (!buffer->len || !c->lookup_mask)) |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1143 | return; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1144 | |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 1145 | c->set_lookup_props (lookup.get_props ()); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1146 | |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1147 | hb_get_subtables_context_t::array_t subtables; |
| 1148 | hb_get_subtables_context_t c_get_subtables (subtables); |
| 1149 | lookup.dispatch (&c_get_subtables); |
| 1150 | |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1151 | if (likely (!lookup.is_reverse ())) |
| 1152 | { |
| 1153 | /* in/out forward substitution/positioning */ |
| 1154 | if (Proxy::table_index == 0) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1155 | buffer->clear_output (); |
| 1156 | buffer->idx = 0; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1157 | |
Behdad Esfahbod | 640b66c | 2015-02-19 17:30:05 +0300 | [diff] [blame] | 1158 | bool ret; |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1159 | ret = apply_forward (c, accel, subtables); |
Behdad Esfahbod | 640b66c | 2015-02-19 17:30:05 +0300 | [diff] [blame] | 1160 | if (ret) |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1161 | { |
Behdad Esfahbod | 6ffc007 | 2013-10-28 19:26:02 +0100 | [diff] [blame] | 1162 | if (!Proxy::inplace) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1163 | buffer->swap_buffers (); |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1164 | else |
Behdad Esfahbod | 1d4a328 | 2015-02-19 11:33:30 +0300 | [diff] [blame] | 1165 | assert (!buffer->has_separate_output ()); |
Behdad Esfahbod | 9d9e72e | 2013-05-03 18:10:10 -0400 | [diff] [blame] | 1166 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | /* in-place backward substitution/positioning */ |
| 1171 | if (Proxy::table_index == 0) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1172 | buffer->remove_output (); |
| 1173 | buffer->idx = buffer->len - 1; |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1174 | |
Behdad Esfahbod | 3e70452 | 2016-01-11 17:38:41 +0000 | [diff] [blame] | 1175 | apply_backward (c, accel, subtables); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1176 | } |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1179 | template <typename Proxy> |
| 1180 | inline void hb_ot_map_t::apply (const Proxy &proxy, |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1181 | const hb_ot_shape_plan_t *plan, |
| 1182 | hb_font_t *font, |
| 1183 | hb_buffer_t *buffer) const |
| 1184 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1185 | const unsigned int table_index = proxy.table_index; |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1186 | unsigned int i = 0; |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1187 | OT::hb_apply_context_t c (table_index, font, buffer); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1188 | c.set_recurse_func (Proxy::Lookup::apply_recurse_func); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1189 | |
| 1190 | for (unsigned int stage_index = 0; stage_index < stages[table_index].len; stage_index++) { |
| 1191 | const stage_map_t *stage = &stages[table_index][stage_index]; |
| 1192 | for (; i < stage->last_lookup; i++) |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1193 | { |
| 1194 | unsigned int lookup_index = lookups[table_index][i].index; |
Behdad Esfahbod | 0475ef2 | 2015-12-18 18:17:07 +0000 | [diff] [blame] | 1195 | if (!buffer->message (font, "start lookup %d", lookup_index)) continue; |
Behdad Esfahbod | 2c8b3b2 | 2015-08-18 14:36:43 +0100 | [diff] [blame] | 1196 | c.set_lookup_index (lookup_index); |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1197 | c.set_lookup_mask (lookups[table_index][i].mask); |
| 1198 | c.set_auto_zwj (lookups[table_index][i].auto_zwj); |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1199 | apply_string<Proxy> (&c, |
| 1200 | proxy.table.get_lookup (lookup_index), |
| 1201 | proxy.accels[lookup_index]); |
Behdad Esfahbod | 0475ef2 | 2015-12-18 18:17:07 +0000 | [diff] [blame] | 1202 | (void) buffer->message (font, "end lookup %d", lookup_index); |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1203 | } |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1204 | |
| 1205 | if (stage->pause_func) |
| 1206 | { |
| 1207 | buffer->clear_output (); |
| 1208 | stage->pause_func (plan, font, buffer); |
| 1209 | } |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 1214 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1215 | GSUBProxy proxy (font->face); |
| 1216 | apply (proxy, plan, font, buffer); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
| 1220 | { |
Behdad Esfahbod | bac1dd6 | 2013-05-02 18:52:24 -0400 | [diff] [blame] | 1221 | GPOSProxy proxy (font->face); |
| 1222 | apply (proxy, plan, font, buffer); |
| 1223 | } |
| 1224 | |
| 1225 | HB_INTERNAL void |
| 1226 | hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c, |
| 1227 | const OT::SubstLookup &lookup, |
| 1228 | const hb_ot_layout_lookup_accelerator_t &accel) |
| 1229 | { |
Behdad Esfahbod | 45f3d98 | 2013-05-03 17:49:44 -0400 | [diff] [blame] | 1230 | apply_string<GSUBProxy> (c, lookup, accel); |
Behdad Esfahbod | d2c9681 | 2013-05-02 18:18:24 -0400 | [diff] [blame] | 1231 | } |