blob: 4cd65b4a92fc7404d4dcb9643f4cd39aa4be9792 [file] [log] [blame]
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -05001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2006 Behdad Esfahbod
4 * Copyright © 2007,2008,2009 Red Hat, Inc.
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04005 * Copyright © 2012,2013 Google, Inc.
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -05006 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04007 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -05008 *
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 Esfahbodf8603662012-07-30 02:38:39 -040028 * Google Author(s): Behdad Esfahbod
Behdad Esfahbodfd92a3d2008-01-24 03:11:09 -050029 */
30
Behdad Esfahbodbb4bbe62019-06-26 13:29:58 -070031#include "hb.hh"
32
33#ifndef HB_NO_OT_LAYOUT
34
Behdad Esfahbod8fe15482019-06-26 13:49:42 -070035#ifdef HB_NO_OT_TAG
36#error "Cannot compile hb-ot-layout.cc with HB_NO_OT_TAG."
37#endif
38
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070039#include "hb-open-type.hh"
40#include "hb-ot-layout.hh"
Behdad Esfahbodb9291002018-08-26 01:15:47 -070041#include "hb-ot-face.hh"
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070042#include "hb-ot-map.hh"
43#include "hb-map.hh"
Ebrahim Byagowi5b9c2342018-02-27 22:56:17 +033044
Behdad Esfahbod574d8882018-11-25 16:51:22 -050045#include "hb-ot-kern-table.hh"
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020046#include "hb-ot-layout-gdef-table.hh"
47#include "hb-ot-layout-gsub-table.hh"
48#include "hb-ot-layout-gpos-table.hh"
Ebrahim Byagowi8f80e532018-12-05 13:51:14 +033049#include "hb-ot-layout-base-table.hh" // Just so we compile it; unused otherwise.
50#include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise.
Behdad Esfahbod203dc442018-05-03 21:03:27 -040051#include "hb-ot-name-table.hh"
Behdad Esfahbod574d8882018-11-25 16:51:22 -050052#include "hb-ot-os2-table.hh"
Behdad Esfahbodd2c96812013-05-02 18:18:24 -040053
Ebrahim Byagowib986fea2018-11-05 12:31:58 +033054#include "hb-aat-layout-lcar-table.hh"
Behdad Esfahbod574d8882018-11-25 16:51:22 -050055#include "hb-aat-layout-morx-table.hh"
Ebrahim Byagowib986fea2018-11-05 12:31:58 +033056
Behdad Esfahbodaff831e2008-01-24 06:03:45 -050057
Behdad Esfahbod80d9a422018-10-27 04:58:32 -070058/**
59 * SECTION:hb-ot-layout
60 * @title: hb-ot-layout
61 * @short_description: OpenType Layout
62 * @include: hb-ot.h
63 *
64 * Functions for querying OpenType Layout features in the font face.
65 **/
66
67
Behdad Esfahbod590d55c2008-01-24 19:13:50 -050068/*
Behdad Esfahboda5195882018-10-08 23:57:45 -040069 * kern
70 */
71
Behdad Esfahbod588697a2019-06-19 16:24:51 -070072#ifndef HB_NO_OT_KERN
Nathan Willis930f6fc2019-03-16 15:10:21 +000073/**
74 * hb_ot_layout_has_kerning:
75 * @face: The #hb_face_t to work on
76 *
Nathan Willisd3178aa2019-03-17 14:27:27 +000077 * Tests whether a face includes any kerning data in the 'kern' table.
78 * Does NOT test for kerning lookups in the GPOS table.
Nathan Willis930f6fc2019-03-16 15:10:21 +000079 *
80 * Return value: true if data found, false otherwise
81 *
82 **/
Behdad Esfahbod385f78b2018-11-07 17:19:21 -050083bool
Behdad Esfahboda5195882018-10-08 23:57:45 -040084hb_ot_layout_has_kerning (hb_face_t *face)
85{
Behdad Esfahboda35c92c2018-11-05 22:58:43 -050086 return face->table.kern->has_data ();
Behdad Esfahboda5195882018-10-08 23:57:45 -040087}
88
Nathan Willis930f6fc2019-03-16 15:10:21 +000089/**
90 * hb_ot_layout_has_machine_kerning:
91 * @face: The #hb_face_t to work on
92 *
Nathan Willisd3178aa2019-03-17 14:27:27 +000093 * Tests whether a face includes any state-machine kerning in the 'kern' table.
94 * Does NOT examine the GPOS table.
Nathan Willis930f6fc2019-03-16 15:10:21 +000095 *
96 * Return value: true if data found, false otherwise
97 *
98 **/
Behdad Esfahbod385f78b2018-11-07 17:19:21 -050099bool
Behdad Esfahbod74896222018-11-23 11:10:17 -0500100hb_ot_layout_has_machine_kerning (hb_face_t *face)
101{
102 return face->table.kern->has_state_machine ();
103}
104
Nathan Willis930f6fc2019-03-16 15:10:21 +0000105/**
106 * hb_ot_layout_has_cross_kerning:
107 * @face: The #hb_face_t to work on
108 *
109 * Tests whether a face has any cross-stream kerning (i.e., kerns
110 * that make adjustments perpendicular to the direction of the text
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +0430111 * flow: Y adjustments in horizontal text or X adjustments in
Nathan Willisd3178aa2019-03-17 14:27:27 +0000112 * vertical text) in the 'kern' table.
113 *
114 * Does NOT examine the GPOS table.
Nathan Willis930f6fc2019-03-16 15:10:21 +0000115 *
116 * Return value: true is data found, false otherwise
117 *
118 **/
Behdad Esfahbod74896222018-11-23 11:10:17 -0500119bool
Behdad Esfahbodca235672018-11-07 16:19:51 -0500120hb_ot_layout_has_cross_kerning (hb_face_t *face)
121{
122 return face->table.kern->has_cross_stream ();
123}
124
Behdad Esfahboda5195882018-10-08 23:57:45 -0400125void
Behdad Esfahbodc221dc02018-11-14 14:49:34 -0500126hb_ot_layout_kern (const hb_ot_shape_plan_t *plan,
Behdad Esfahbod095f5ad2018-11-02 13:23:54 -0400127 hb_font_t *font,
128 hb_buffer_t *buffer)
Behdad Esfahboda5195882018-10-08 23:57:45 -0400129{
Behdad Esfahboda35c92c2018-11-05 22:58:43 -0500130 hb_blob_t *blob = font->face->table.kern.get_blob ();
Behdad Esfahbodfa3ebf82018-11-05 23:34:07 -0500131 const AAT::kern& kern = *blob->as<AAT::kern> ();
Behdad Esfahbod095f5ad2018-11-02 13:23:54 -0400132
133 AAT::hb_aat_apply_context_t c (plan, font, buffer, blob);
134
135 kern.apply (&c);
Behdad Esfahboda5195882018-10-08 23:57:45 -0400136}
Behdad Esfahbod588697a2019-06-19 16:24:51 -0700137#endif
Behdad Esfahboda5195882018-10-08 23:57:45 -0400138
139
140/*
Behdad Esfahbod590d55c2008-01-24 19:13:50 -0500141 * GDEF
142 */
143
Behdad Esfahbod4f217032018-11-25 15:59:18 -0500144bool
145OT::GDEF::is_blacklisted (hb_blob_t *blob,
146 hb_face_t *face) const
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700147{
Behdad Esfahbod227d85e2019-05-10 23:15:58 -0700148#ifdef HB_NO_OT_LAYOUT_BLACKLIST
Behdad Esfahbod9ddbfa02019-04-12 09:33:25 -0400149 return false;
150#endif
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700151 /* The ugly business of blacklisting individual fonts' tables happen here!
152 * See this thread for why we finally had to bend in and do this:
153 * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html
154 *
155 * In certain versions of Times New Roman Italic and Bold Italic,
156 * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark)
157 * in GDEF. Many versions of Tahoma have bad GDEF tables that
158 * incorrectly classify some spacing marks such as certain IPA
159 * symbols as glyph class 3. So do older versions of Microsoft
160 * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04.
161 *
162 * Nuke the GDEF tables of to avoid unwanted width-zeroing.
163 *
164 * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925
165 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693
166 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875
167 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400168 switch HB_CODEPOINT_ENCODE3(blob->length,
169 face->table.GSUB->table.get_length (),
170 face->table.GPOS->table.get_length ())
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700171 {
172 /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400173 case HB_CODEPOINT_ENCODE3 (442, 2874, 42038):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700174 /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400175 case HB_CODEPOINT_ENCODE3 (430, 2874, 40662):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700176 /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400177 case HB_CODEPOINT_ENCODE3 (442, 2874, 39116):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700178 /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400179 case HB_CODEPOINT_ENCODE3 (430, 2874, 39374):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700180 /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400181 case HB_CODEPOINT_ENCODE3 (490, 3046, 41638):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700182 /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400183 case HB_CODEPOINT_ENCODE3 (478, 3046, 41902):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700184 /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400185 case HB_CODEPOINT_ENCODE3 (898, 12554, 46470):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700186 /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400187 case HB_CODEPOINT_ENCODE3 (910, 12566, 47732):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700188 /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400189 case HB_CODEPOINT_ENCODE3 (928, 23298, 59332):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700190 /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400191 case HB_CODEPOINT_ENCODE3 (940, 23310, 60732):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700192 /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400193 case HB_CODEPOINT_ENCODE3 (964, 23836, 60072):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700194 /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400195 case HB_CODEPOINT_ENCODE3 (976, 23832, 61456):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700196 /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400197 case HB_CODEPOINT_ENCODE3 (994, 24474, 60336):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700198 /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400199 case HB_CODEPOINT_ENCODE3 (1006, 24470, 61740):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700200 /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400201 case HB_CODEPOINT_ENCODE3 (1006, 24576, 61346):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700202 /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400203 case HB_CODEPOINT_ENCODE3 (1018, 24572, 62828):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700204 /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5 tahoma.ttf from Windows 10 AU */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400205 case HB_CODEPOINT_ENCODE3 (1006, 24576, 61352):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700206 /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2 tahomabd.ttf from Windows 10 AU */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400207 case HB_CODEPOINT_ENCODE3 (1018, 24572, 62834):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700208 /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400209 case HB_CODEPOINT_ENCODE3 (832, 7324, 47162):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700210 /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400211 case HB_CODEPOINT_ENCODE3 (844, 7302, 45474):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700212 /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc himalaya.ttf from Windows 7 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400213 case HB_CODEPOINT_ENCODE3 (180, 13054, 7254):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700214 /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400215 case HB_CODEPOINT_ENCODE3 (192, 12638, 7254):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700216 /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400217 case HB_CODEPOINT_ENCODE3 (192, 12690, 7254):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700218 /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */
219 /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400220 case HB_CODEPOINT_ENCODE3 (188, 248, 3852):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700221 /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */
222 /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400223 case HB_CODEPOINT_ENCODE3 (188, 264, 3426):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700224 /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400225 case HB_CODEPOINT_ENCODE3 (1058, 47032, 11818):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700226 /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400227 case HB_CODEPOINT_ENCODE3 (1046, 47030, 12600):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700228 /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400229 case HB_CODEPOINT_ENCODE3 (1058, 71796, 16770):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700230 /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400231 case HB_CODEPOINT_ENCODE3 (1046, 71790, 17862):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700232 /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400233 case HB_CODEPOINT_ENCODE3 (1046, 71788, 17112):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700234 /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400235 case HB_CODEPOINT_ENCODE3 (1058, 71794, 17514):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700236 /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400237 case HB_CODEPOINT_ENCODE3 (1330, 109904, 57938):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700238 /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400239 case HB_CODEPOINT_ENCODE3 (1330, 109904, 58972):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700240 /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85 Padauk.ttf
241 * "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */
Behdad Esfahbod65392b72019-05-22 16:21:21 -0400242 case HB_CODEPOINT_ENCODE3 (1004, 59092, 14836):
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700243 return true;
Behdad Esfahbodd8c57e82018-08-26 09:03:31 -0700244 }
245 return false;
246}
247
Behdad Esfahbodc624e182018-08-26 09:19:20 -0700248static void
249_hb_ot_layout_set_glyph_props (hb_font_t *font,
250 hb_buffer_t *buffer)
251{
252 _hb_buffer_assert_gsubgpos_vars (buffer);
253
Behdad Esfahbod5e68cec2018-11-05 23:23:57 -0500254 const OT::GDEF &gdef = *font->face->table.GDEF->table;
Behdad Esfahbodc624e182018-08-26 09:19:20 -0700255 unsigned int count = buffer->len;
256 for (unsigned int i = 0; i < count; i++)
257 {
258 _hb_glyph_info_set_glyph_props (&buffer->info[i], gdef.get_glyph_props (buffer->info[i].codepoint));
259 _hb_glyph_info_clear_lig_props (&buffer->info[i]);
260 buffer->info[i].syllable() = 0;
261 }
262}
263
264/* Public API */
265
Nathan Willis930f6fc2019-03-16 15:10:21 +0000266/**
267 * hb_ot_layout_has_glyph_classes:
268 * @face: #hb_face_t to work upon
269 *
270 * Tests whether a face has any glyph classes defined in its GDEF table.
271 *
272 * Return value: true if data found, false otherwise
273 *
274 **/
Behdad Esfahbod590d55c2008-01-24 19:13:50 -0500275hb_bool_t
Behdad Esfahbod52ea4772009-11-06 17:45:38 -0500276hb_ot_layout_has_glyph_classes (hb_face_t *face)
Behdad Esfahbod590d55c2008-01-24 19:13:50 -0500277{
Behdad Esfahbod5e68cec2018-11-05 23:23:57 -0500278 return face->table.GDEF->table->has_glyph_classes ();
Behdad Esfahbod590d55c2008-01-24 19:13:50 -0500279}
280
Sascha Brawer01c3a882015-06-01 13:22:01 +0200281/**
Behdad Esfahbod35d18582015-11-26 19:30:37 -0500282 * hb_ot_layout_get_glyph_class:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000283 * @face: The #hb_face_t to work on
284 * @glyph: The #hb_codepoint_t code point to query
285 *
286 * Fetches the GDEF class of the requested glyph in the specified face.
287 *
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +0430288 * Return value: The #hb_ot_layout_glyph_class_t glyph class of the given code
Nathan Willisc08ddbd2019-03-24 15:07:07 +0000289 * point in the GDEF table of the face.
Behdad Esfahbod35d18582015-11-26 19:30:37 -0500290 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200291 * Since: 0.9.7
292 **/
Behdad Esfahbod5a08ecf2012-11-16 13:34:29 -0800293hb_ot_layout_glyph_class_t
294hb_ot_layout_get_glyph_class (hb_face_t *face,
295 hb_codepoint_t glyph)
296{
Behdad Esfahbod5e68cec2018-11-05 23:23:57 -0500297 return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph);
Behdad Esfahbod5a08ecf2012-11-16 13:34:29 -0800298}
Behdad Esfahbod4a2d8442010-11-03 15:28:56 -0400299
Sascha Brawer01c3a882015-06-01 13:22:01 +0200300/**
Behdad Esfahbod35d18582015-11-26 19:30:37 -0500301 * hb_ot_layout_get_glyphs_in_class:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000302 * @face: The #hb_face_t to work on
303 * @klass: The #hb_ot_layout_glyph_class_t GDEF class to retrieve
304 * @glyphs: (out): The #hb_set_t set of all glyphs belonging to the requested
305 * class.
306 *
307 * Retrieves the set of all glyphs from the face that belong to the requested
308 * glyph class in the face's GDEF table.
Behdad Esfahbod35d18582015-11-26 19:30:37 -0500309 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200310 * Since: 0.9.7
311 **/
Behdad Esfahbod89ca8ee2012-11-16 13:53:40 -0800312void
313hb_ot_layout_get_glyphs_in_class (hb_face_t *face,
314 hb_ot_layout_glyph_class_t klass,
315 hb_set_t *glyphs /* OUT */)
316{
Behdad Esfahbod5e68cec2018-11-05 23:23:57 -0500317 return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs);
Behdad Esfahbod89ca8ee2012-11-16 13:53:40 -0800318}
319
Nathan Willis930f6fc2019-03-16 15:10:21 +0000320
Behdad Esfahbodbf9424a2019-06-18 13:31:35 -0700321#ifndef HB_NO_LAYOUT_UNUSED
Nathan Willis930f6fc2019-03-16 15:10:21 +0000322/**
323 * hb_ot_layout_get_attach_points:
324 * @face: The #hb_face_t to work on
325 * @glyph: The #hb_codepoint_t code point to query
Nathan Willis3db22722019-04-02 18:49:40 +0100326 * @start_offset: offset of the first attachment point to retrieve
327 * @point_count: (inout) (allow-none): Input = the maximum number of attachment points to return;
328 * Output = the actual number of attachment points returned (may be zero)
329 * @point_array: (out) (array length=point_count): The array of attachment points found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +0000330 *
331 * Fetches a list of all attachment points for the specified glyph in the GDEF
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +0430332 * table of the face. The list returned will begin at the offset provided.
Nathan Willis930f6fc2019-03-16 15:10:21 +0000333 *
334 * Useful if the client program wishes to cache the list.
335 *
336 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500337unsigned int
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400338hb_ot_layout_get_attach_points (hb_face_t *face,
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400339 hb_codepoint_t glyph,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500340 unsigned int start_offset,
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400341 unsigned int *point_count /* IN/OUT */,
342 unsigned int *point_array /* OUT */)
343{
Behdad Esfahbod5e68cec2018-11-05 23:23:57 -0500344 return face->table.GDEF->table->get_attach_points (glyph,
345 start_offset,
346 point_count,
347 point_array);
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400348}
Nathan Willis930f6fc2019-03-16 15:10:21 +0000349/**
350 * hb_ot_layout_get_ligature_carets:
351 * @font: The #hb_font_t to work on
352 * @direction: The #hb_direction_t text direction to use
353 * @glyph: The #hb_codepoint_t code point to query
Nathan Willis3db22722019-04-02 18:49:40 +0100354 * @start_offset: offset of the first caret position to retrieve
355 * @caret_count: (inout) (allow-none): Input = the maximum number of caret positions to return;
356 * Output = the actual number of caret positions returned (may be zero)
357 * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +0000358 *
359 * Fetches a list of the caret positions defined for a ligature glyph in the GDEF
360 * table of the font. The list returned will begin at the offset provided.
361 *
362 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500363unsigned int
Behdad Esfahbode2046742010-10-27 12:32:02 -0400364hb_ot_layout_get_ligature_carets (hb_font_t *font,
Behdad Esfahbode2046742010-10-27 12:32:02 -0400365 hb_direction_t direction,
366 hb_codepoint_t glyph,
367 unsigned int start_offset,
368 unsigned int *caret_count /* IN/OUT */,
Ebrahim Byagowi3b0e47c2017-06-19 14:47:09 +0430369 hb_position_t *caret_array /* OUT */)
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400370{
Ebrahim Byagowib986fea2018-11-05 12:31:58 +0330371 unsigned int result_caret_count = 0;
372 unsigned int result = font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, &result_caret_count, caret_array);
373 if (result)
374 {
375 if (caret_count) *caret_count = result_caret_count;
376 }
Behdad Esfahbod631da9d2019-06-19 15:36:14 -0700377#ifndef HB_NO_AAT
Ebrahim Byagowib986fea2018-11-05 12:31:58 +0330378 else
379 result = font->face->table.lcar->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array);
Behdad Esfahbod631da9d2019-06-19 15:36:14 -0700380#endif
Ebrahim Byagowib986fea2018-11-05 12:31:58 +0330381 return result;
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400382}
Behdad Esfahbodbf9424a2019-06-18 13:31:35 -0700383#endif
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400384
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -0400385
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500386/*
387 * GSUB/GPOS
388 */
389
Behdad Esfahbod574d8882018-11-25 16:51:22 -0500390bool
391OT::GSUB::is_blacklisted (hb_blob_t *blob HB_UNUSED,
392 hb_face_t *face) const
393{
Behdad Esfahbod227d85e2019-05-10 23:15:58 -0700394#ifdef HB_NO_OT_LAYOUT_BLACKLIST
Behdad Esfahbod9ddbfa02019-04-12 09:33:25 -0400395 return false;
396#endif
Behdad Esfahbodf08066c2019-06-18 14:29:27 -0700397
Behdad Esfahbod12092a42019-06-26 13:31:01 -0700398#ifndef HB_NO_AAT_SHAPE
Behdad Esfahbod574d8882018-11-25 16:51:22 -0500399 /* Mac OS X prefers morx over GSUB. It also ships with various Indic fonts,
400 * all by 'MUTF' foundry (Tamil MN, Tamil Sangam MN, etc.), that have broken
401 * GSUB/GPOS tables. Some have GSUB with zero scripts, those are ignored by
402 * our morx/GSUB preference code. But if GSUB has non-zero scripts, we tend
403 * to prefer it over morx because we want to be consistent with other OpenType
404 * shapers.
405 *
406 * To work around broken Indic Mac system fonts, we ignore GSUB table if
407 * OS/2 VendorId is 'MUTF' and font has morx table as well.
408 *
409 * https://github.com/harfbuzz/harfbuzz/issues/1410
410 * https://github.com/harfbuzz/harfbuzz/issues/1348
411 * https://github.com/harfbuzz/harfbuzz/issues/1391
412 */
413 if (unlikely (face->table.OS2->achVendID == HB_TAG ('M','U','T','F') &&
414 face->table.morx->has_data ()))
415 return true;
Behdad Esfahbodf08066c2019-06-18 14:29:27 -0700416#endif
Behdad Esfahbod574d8882018-11-25 16:51:22 -0500417
418 return false;
419}
420
421bool
422OT::GPOS::is_blacklisted (hb_blob_t *blob HB_UNUSED,
423 hb_face_t *face HB_UNUSED) const
424{
Behdad Esfahbod227d85e2019-05-10 23:15:58 -0700425#ifdef HB_NO_OT_LAYOUT_BLACKLIST
Behdad Esfahbod9ddbfa02019-04-12 09:33:25 -0400426 return false;
427#endif
Behdad Esfahbod574d8882018-11-25 16:51:22 -0500428 return false;
429}
430
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400431static const OT::GSUBGPOS&
Behdad Esfahbod23c86aa2009-08-03 21:40:20 -0400432get_gsubgpos_table (hb_face_t *face,
433 hb_tag_t table_tag)
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500434{
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400435 switch (table_tag) {
Behdad Esfahbod737efbe2018-11-05 23:26:29 -0500436 case HB_OT_TAG_GSUB: return *face->table.GSUB->table;
437 case HB_OT_TAG_GPOS: return *face->table.GPOS->table;
Behdad Esfahbodabc12f72018-05-08 02:23:36 -0700438 default: return Null(OT::GSUBGPOS);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500439 }
440}
441
442
Nathan Willis930f6fc2019-03-16 15:10:21 +0000443/**
444 * hb_ot_layout_table_get_script_tags:
445 * @face: #hb_face_t to work upon
446 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
Nathan Willis3db22722019-04-02 18:49:40 +0100447 * @start_offset: offset of the first script tag to retrieve
448 * @script_count: (inout) (allow-none): Input = the maximum number of script tags to return;
449 * Output = the actual number of script tags returned (may be zero)
450 * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +0000451 *
452 * Fetches a list of all scripts enumerated in the specified face's GSUB table
453 * or GPOS table. The list returned will begin at the offset provided.
454 *
455 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500456unsigned int
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400457hb_ot_layout_table_get_script_tags (hb_face_t *face,
458 hb_tag_t table_tag,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500459 unsigned int start_offset,
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400460 unsigned int *script_count /* IN/OUT */,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330461 hb_tag_t *script_tags /* OUT */)
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500462{
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400463 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500464
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500465 return g.get_script_tags (start_offset, script_count, script_tags);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500466}
467
Behdad Esfahbodeb45c0a2013-01-16 22:07:50 -0600468#define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n')
469
Nathan Willis930f6fc2019-03-16 15:10:21 +0000470/**
471 * hb_ot_layout_table_find_script:
472 * @face: #hb_face_t to work upon
473 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
474 * @script_tag: #hb_tag_t of the script tag requested
Nathan Willis51228052019-03-17 14:43:06 +0000475 * @script_index: (out): The index of the requested script tag
Nathan Willis930f6fc2019-03-16 15:10:21 +0000476 *
477 * Fetches the index if a given script tag in the specified face's GSUB table
478 * or GPOS table.
479 *
480 * Return value: true if the script is found, false otherwise
481 *
482 **/
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500483hb_bool_t
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400484hb_ot_layout_table_find_script (hb_face_t *face,
485 hb_tag_t table_tag,
486 hb_tag_t script_tag,
Nathan Willis930f6fc2019-03-16 15:10:21 +0000487 unsigned int *script_index /* OUT */)
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500488{
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200489 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400490 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500491
492 if (g.find_script_index (script_tag, script_index))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400493 return true;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500494
495 /* try finding 'DFLT' */
Behdad Esfahbod8a3511a2009-11-04 19:45:39 -0500496 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400497 return false;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500498
Behdad Esfahboddca8aff2010-09-28 16:25:23 -0400499 /* try with 'dflt'; MS site has had typos and many fonts use it now :(.
500 * including many versions of DejaVu Sans Mono! */
Behdad Esfahbod8a3511a2009-11-04 19:45:39 -0500501 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400502 return false;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500503
Behdad Esfahbodeb45c0a2013-01-16 22:07:50 -0600504 /* try with 'latn'; some old fonts put their features there even though
505 they're really trying to support Thai, for example :( */
506 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index))
507 return false;
508
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500509 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400510 return false;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500511}
512
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700513#ifndef HB_DISABLE_DEPRECATED
Nathan Willis930f6fc2019-03-16 15:10:21 +0000514/**
515 * hb_ot_layout_table_choose_script:
516 * @face: #hb_face_t to work upon
517 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
518 * @script_tags: Array of #hb_tag_t script tags
Nathan Willis6c0a1e82019-03-17 14:50:47 +0000519 * @script_index: (out): The index of the requested script tag
520 * @chosen_script: (out): #hb_tag_t of the script tag requested
Nathan Willis930f6fc2019-03-16 15:10:21 +0000521 *
Nathan Willisc08ddbd2019-03-24 15:07:07 +0000522 * Deprecated since 2.0.0
Nathan Willis930f6fc2019-03-16 15:10:21 +0000523 **/
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100524hb_bool_t
525hb_ot_layout_table_choose_script (hb_face_t *face,
526 hb_tag_t table_tag,
527 const hb_tag_t *script_tags,
Nathan Willis6c0a1e82019-03-17 14:50:47 +0000528 unsigned int *script_index /* OUT */,
529 hb_tag_t *chosen_script /* OUT */)
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100530{
David Corbett91067712017-12-08 11:21:14 -0500531 const hb_tag_t *t;
532 for (t = script_tags; *t; t++);
533 return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script);
534}
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700535#endif
David Corbett91067712017-12-08 11:21:14 -0500536
Behdad Esfahbod80616642018-10-11 14:16:55 -0400537/**
538 * hb_ot_layout_table_select_script:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000539 * @face: #hb_face_t to work upon
540 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
541 * @script_count: Number of script tags in the array
542 * @script_tags: Array of #hb_tag_t script tags
Nathan Willis51228052019-03-17 14:43:06 +0000543 * @script_index: (out): The index of the requested script
544 * @chosen_script: (out): #hb_tag_t of the requested script
Behdad Esfahbod80616642018-10-11 14:16:55 -0400545 *
Behdad Esfahbod3d9a0302018-10-18 05:58:17 -0700546 * Since: 2.0.0
Behdad Esfahbod80616642018-10-11 14:16:55 -0400547 **/
David Corbett91067712017-12-08 11:21:14 -0500548hb_bool_t
549hb_ot_layout_table_select_script (hb_face_t *face,
550 hb_tag_t table_tag,
551 unsigned int script_count,
552 const hb_tag_t *script_tags,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330553 unsigned int *script_index /* OUT */,
David Corbett91067712017-12-08 11:21:14 -0500554 hb_tag_t *chosen_script /* OUT */)
555{
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200556 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400557 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
David Corbett91067712017-12-08 11:21:14 -0500558 unsigned int i;
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100559
David Corbett91067712017-12-08 11:21:14 -0500560 for (i = 0; i < script_count; i++)
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100561 {
David Corbett91067712017-12-08 11:21:14 -0500562 if (g.find_script_index (script_tags[i], script_index))
563 {
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400564 if (chosen_script)
David Corbett91067712017-12-08 11:21:14 -0500565 *chosen_script = script_tags[i];
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400566 return true;
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400567 }
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100568 }
569
570 /* try finding 'DFLT' */
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400571 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) {
572 if (chosen_script)
573 *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400574 return false;
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400575 }
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100576
577 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400578 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) {
579 if (chosen_script)
580 *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400581 return false;
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400582 }
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100583
Behdad Esfahbod71632c92012-01-22 15:31:44 -0500584 /* try with 'latn'; some old fonts put their features there even though
585 they're really trying to support Thai, for example :( */
Behdad Esfahbod71632c92012-01-22 15:31:44 -0500586 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) {
587 if (chosen_script)
588 *chosen_script = HB_OT_TAG_LATIN_SCRIPT;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400589 return false;
Behdad Esfahbod71632c92012-01-22 15:31:44 -0500590 }
591
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100592 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
Behdad Esfahbodc47a31f2011-07-30 20:57:01 -0400593 if (chosen_script)
594 *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400595 return false;
Behdad Esfahbod2014b8d2009-12-20 20:58:26 +0100596}
597
Nathan Willis930f6fc2019-03-16 15:10:21 +0000598
599/**
600 * hb_ot_layout_table_get_feature_tags:
601 * @face: #hb_face_t to work upon
602 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
Nathan Willis3db22722019-04-02 18:49:40 +0100603 * @start_offset: offset of the first feature tag to retrieve
604 * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return;
605 * Output = the actual number of feature tags returned (may be zero)
606 * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table
Nathan Willis930f6fc2019-03-16 15:10:21 +0000607 *
608 * Fetches a list of all feature tags in the given face's GSUB or GPOS table.
609 *
610 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500611unsigned int
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400612hb_ot_layout_table_get_feature_tags (hb_face_t *face,
613 hb_tag_t table_tag,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500614 unsigned int start_offset,
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400615 unsigned int *feature_count /* IN/OUT */,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330616 hb_tag_t *feature_tags /* OUT */)
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500617{
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400618 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500619
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500620 return g.get_feature_tags (start_offset, feature_count, feature_tags);
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500621}
622
Nathan Willis930f6fc2019-03-16 15:10:21 +0000623
624/**
625 * hb_ot_layout_table_find_feature:
626 * @face: #hb_face_t to work upon
627 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
628 * @feature_tag: The #hb_tag_t og the requested feature tag
Nathan Willis51228052019-03-17 14:43:06 +0000629 * @feature_index: (out): The index of the requested feature
Nathan Willis930f6fc2019-03-16 15:10:21 +0000630 *
631 * Fetches the index for a given feature tag in the specified face's GSUB table
632 * or GPOS table.
633 *
634 * Return value: true if the feature is found, false otherwise
635 **/
Behdad Esfahbod385f78b2018-11-07 17:19:21 -0500636bool
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +0100637hb_ot_layout_table_find_feature (hb_face_t *face,
638 hb_tag_t table_tag,
639 hb_tag_t feature_tag,
Nathan Willis930f6fc2019-03-16 15:10:21 +0000640 unsigned int *feature_index /* OUT */)
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +0100641{
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200642 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
Behdad Esfahbod0f98fe82015-07-23 11:52:11 +0100643 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
644
645 unsigned int num_features = g.get_feature_count ();
646 for (unsigned int i = 0; i < num_features; i++)
647 {
648 if (feature_tag == g.get_feature_tag (i)) {
649 if (feature_index) *feature_index = i;
650 return true;
651 }
652 }
653
654 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
655 return false;
656}
657
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500658
Nathan Willis930f6fc2019-03-16 15:10:21 +0000659/**
660 * hb_ot_layout_script_get_language_tags:
661 * @face: #hb_face_t to work upon
662 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
663 * @script_index: The index of the requested script tag
Nathan Willis3db22722019-04-02 18:49:40 +0100664 * @start_offset: offset of the first language tag to retrieve
665 * @language_count: (inout) (allow-none): Input = the maximum number of language tags to return;
666 * Output = the actual number of language tags returned (may be zero)
667 * @language_tags: (out) (array length=language_count): Array of language tags found in the table
Nathan Willis930f6fc2019-03-16 15:10:21 +0000668 *
669 * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath
670 * the specified script index. The list returned will begin at the offset provided.
671 *
672 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500673unsigned int
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400674hb_ot_layout_script_get_language_tags (hb_face_t *face,
675 hb_tag_t table_tag,
676 unsigned int script_index,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500677 unsigned int start_offset,
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400678 unsigned int *language_count /* IN/OUT */,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330679 hb_tag_t *language_tags /* OUT */)
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500680{
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400681 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500682
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500683 return s.get_lang_sys_tags (start_offset, language_count, language_tags);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500684}
685
Nathan Willis930f6fc2019-03-16 15:10:21 +0000686
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700687#ifndef HB_DISABLE_DEPRECATED
Nathan Willis930f6fc2019-03-16 15:10:21 +0000688/**
689 * hb_ot_layout_script_find_language:
690 * @face: #hb_face_t to work upon
691 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
692 * @script_index: The index of the requested script tag
693 * @language_tag: The #hb_tag_t of the requested language
694 * @language_index: The index of the requested language
695 *
696 * Fetches the index of a given language tag in the specified face's GSUB table
697 * or GPOS table, underneath the specified script tag.
698 *
699 * Return value: true if the language tag is found, false otherwise
700 *
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700701 * Since: ??
702 * Deprecated: ??
Nathan Willis930f6fc2019-03-16 15:10:21 +0000703 **/
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500704hb_bool_t
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400705hb_ot_layout_script_find_language (hb_face_t *face,
706 hb_tag_t table_tag,
707 unsigned int script_index,
708 hb_tag_t language_tag,
709 unsigned int *language_index)
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500710{
Behdad Esfahbod737efbe2018-11-05 23:26:29 -0500711 return hb_ot_layout_script_select_language (face,
712 table_tag,
713 script_index,
714 1,
715 &language_tag,
716 language_index);
David Corbett91067712017-12-08 11:21:14 -0500717}
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700718#endif
David Corbett91067712017-12-08 11:21:14 -0500719
Nathan Willis930f6fc2019-03-16 15:10:21 +0000720
Behdad Esfahbod80616642018-10-11 14:16:55 -0400721/**
722 * hb_ot_layout_script_select_language:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000723 * @face: #hb_face_t to work upon
724 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
725 * @script_index: The index of the requested script tag
726 * @language_count: The number of languages in the specified script
727 * @language_tags: The array of language tags
Nathan Willis51228052019-03-17 14:43:06 +0000728 * @language_index: (out): The index of the requested language
Nathan Willis930f6fc2019-03-16 15:10:21 +0000729 *
730 * Fetches the index of a given language tag in the specified face's GSUB table
731 * or GPOS table, underneath the specified script index.
732 *
733 * Return value: true if the language tag is found, false otherwise
734 *
Behdad Esfahbod3d9a0302018-10-18 05:58:17 -0700735 * Since: 2.0.0
Behdad Esfahbod80616642018-10-11 14:16:55 -0400736 **/
David Corbett91067712017-12-08 11:21:14 -0500737hb_bool_t
Behdad Esfahbodcf975ac2018-10-11 14:07:44 -0400738hb_ot_layout_script_select_language (hb_face_t *face,
739 hb_tag_t table_tag,
740 unsigned int script_index,
741 unsigned int language_count,
742 const hb_tag_t *language_tags,
743 unsigned int *language_index /* OUT */)
David Corbett91067712017-12-08 11:21:14 -0500744{
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200745 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), "");
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400746 const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
David Corbett91067712017-12-08 11:21:14 -0500747 unsigned int i;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500748
David Corbett91067712017-12-08 11:21:14 -0500749 for (i = 0; i < language_count; i++)
750 {
751 if (s.find_lang_sys_index (language_tags[i], language_index))
752 return true;
753 }
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500754
David Corbett91067712017-12-08 11:21:14 -0500755 /* try finding 'dflt' */
Behdad Esfahbod8a3511a2009-11-04 19:45:39 -0500756 if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400757 return false;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500758
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500759 if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400760 return false;
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500761}
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500762
Nathan Willis930f6fc2019-03-16 15:10:21 +0000763
764/**
765 * hb_ot_layout_language_get_required_feature_index:
766 * @face: #hb_face_t to work upon
767 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
768 * @script_index: The index of the requested script tag
769 * @language_index: The index of the requested language tag
Nathan Willis51228052019-03-17 14:43:06 +0000770 * @feature_index: (out): The index of the requested feature
Nathan Willis930f6fc2019-03-16 15:10:21 +0000771 *
772 * Fetches the index of a requested feature in the given face's GSUB or GPOS table,
773 * underneath the specified script and language.
774 *
775 * Return value: true if the feature is found, false otherwise
776 *
777 **/
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500778hb_bool_t
Behdad Esfahbod911ca382014-06-24 10:20:36 -0600779hb_ot_layout_language_get_required_feature_index (hb_face_t *face,
780 hb_tag_t table_tag,
781 unsigned int script_index,
782 unsigned int language_index,
783 unsigned int *feature_index)
784{
785 return hb_ot_layout_language_get_required_feature (face,
786 table_tag,
787 script_index,
788 language_index,
789 feature_index,
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200790 nullptr);
Behdad Esfahbod911ca382014-06-24 10:20:36 -0600791}
792
Nathan Willis930f6fc2019-03-16 15:10:21 +0000793
Sascha Brawer01c3a882015-06-01 13:22:01 +0200794/**
Behdad Esfahbod35d18582015-11-26 19:30:37 -0500795 * hb_ot_layout_language_get_required_feature:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000796 * @face: #hb_face_t to work upon
797 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
798 * @script_index: The index of the requested script tag
799 * @language_index: The index of the requested language tag
800 * @feature_index: The index of the requested feature
Nathan Willis51228052019-03-17 14:43:06 +0000801 * @feature_tag: (out): The #hb_tag_t of the requested feature
Nathan Willis930f6fc2019-03-16 15:10:21 +0000802 *
803 * Fetches the tag of a requested feature index in the given face's GSUB or GPOS table,
804 * underneath the specified script and language.
805 *
806 * Return value: true if the feature is found, false otherwise
Behdad Esfahbod35d18582015-11-26 19:30:37 -0500807 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200808 * Since: 0.9.30
809 **/
Behdad Esfahbod911ca382014-06-24 10:20:36 -0600810hb_bool_t
Jonathan Kewda132932014-04-27 14:05:24 +0100811hb_ot_layout_language_get_required_feature (hb_face_t *face,
812 hb_tag_t table_tag,
813 unsigned int script_index,
814 unsigned int language_index,
815 unsigned int *feature_index,
816 hb_tag_t *feature_tag)
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500817{
Jonathan Kewda132932014-04-27 14:05:24 +0100818 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
819 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500820
Jonathan Kewda132932014-04-27 14:05:24 +0100821 unsigned int index = l.get_required_feature_index ();
822 if (feature_index) *feature_index = index;
823 if (feature_tag) *feature_tag = g.get_feature_tag (index);
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500824
825 return l.has_required_feature ();
826}
827
Nathan Willis930f6fc2019-03-16 15:10:21 +0000828
829/**
830 * hb_ot_layout_language_get_feature_indexes:
831 * @face: #hb_face_t to work upon
832 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
833 * @script_index: The index of the requested script tag
834 * @language_index: The index of the requested language tag
Nathan Willis3db22722019-04-02 18:49:40 +0100835 * @start_offset: offset of the first feature tag to retrieve
836 * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return;
837 * Output: the actual number of feature tags returned (may be zero)
838 * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +0000839 *
840 * Fetches a list of all features in the specified face's GSUB table
841 * or GPOS table, underneath the specified script and language. The list
842 * returned will begin at the offset provided.
843 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500844unsigned int
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400845hb_ot_layout_language_get_feature_indexes (hb_face_t *face,
846 hb_tag_t table_tag,
847 unsigned int script_index,
848 unsigned int language_index,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500849 unsigned int start_offset,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330850 unsigned int *feature_count /* IN/OUT */,
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400851 unsigned int *feature_indexes /* OUT */)
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500852{
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400853 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
854 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500855
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500856 return l.get_feature_indexes (start_offset, feature_count, feature_indexes);
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500857}
858
Nathan Willis930f6fc2019-03-16 15:10:21 +0000859
860/**
861 * hb_ot_layout_language_get_feature_tags:
862 * @face: #hb_face_t to work upon
863 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
864 * @script_index: The index of the requested script tag
865 * @language_index: The index of the requested language tag
Nathan Willis3db22722019-04-02 18:49:40 +0100866 * @start_offset: offset of the first feature tag to retrieve
867 * @feature_count: (inout) (allow-none): Input = the maximum number of feature tags to return;
868 * Output = the actual number of feature tags returned (may be zero)
869 * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +0000870 *
871 * Fetches a list of all features in the specified face's GSUB table
872 * or GPOS table, underneath the specified script and language. The list
873 * returned will begin at the offset provided.
874 *
875 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500876unsigned int
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400877hb_ot_layout_language_get_feature_tags (hb_face_t *face,
878 hb_tag_t table_tag,
879 unsigned int script_index,
880 unsigned int language_index,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500881 unsigned int start_offset,
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400882 unsigned int *feature_count /* IN/OUT */,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330883 hb_tag_t *feature_tags /* OUT */)
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500884{
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400885 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
886 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500887
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200888 static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), "");
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500889 unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400890
Behdad Esfahbod98977492009-08-27 01:32:17 -0400891 if (feature_tags) {
892 unsigned int count = *feature_count;
893 for (unsigned int i = 0; i < count; i++)
894 feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]);
895 }
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -0400896
897 return ret;
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500898}
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500899
900
Nathan Willis930f6fc2019-03-16 15:10:21 +0000901/**
902 * hb_ot_layout_language_find_feature:
903 * @face: #hb_face_t to work upon
904 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
905 * @script_index: The index of the requested script tag
906 * @language_index: The index of the requested language tag
907 * @feature_tag: #hb_tag_t of the feature tag requested
Nathan Willis51228052019-03-17 14:43:06 +0000908 * @feature_index: (out): The index of the requested feature
Nathan Willis930f6fc2019-03-16 15:10:21 +0000909 *
910 * Fetches the index of a given feature tag in the specified face's GSUB table
911 * or GPOS table, underneath the specified script and language.
912 *
913 * Return value: true if the feature is found, false otherwise
914 *
915 **/
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500916hb_bool_t
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400917hb_ot_layout_language_find_feature (hb_face_t *face,
918 hb_tag_t table_tag,
919 unsigned int script_index,
920 unsigned int language_index,
921 hb_tag_t feature_tag,
Nathan Willis930f6fc2019-03-16 15:10:21 +0000922 unsigned int *feature_index /* OUT */)
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500923{
Behdad Esfahbod606bf572018-09-16 19:33:48 +0200924 static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -0400925 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
926 const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500927
Behdad Esfahbodf4c95142009-05-17 04:59:56 -0400928 unsigned int num_features = l.get_feature_count ();
929 for (unsigned int i = 0; i < num_features; i++) {
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500930 unsigned int f_index = l.get_feature_index (i);
931
932 if (feature_tag == g.get_feature_tag (f_index)) {
933 if (feature_index) *feature_index = f_index;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400934 return true;
Behdad Esfahbod4a26ea42008-01-28 07:40:10 -0500935 }
936 }
937
938 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400939 return false;
Behdad Esfahbod706ab252008-01-28 05:58:50 -0500940}
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500941
Nathan Willis930f6fc2019-03-16 15:10:21 +0000942
Sascha Brawer01c3a882015-06-01 13:22:01 +0200943/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +0400944 * hb_ot_layout_feature_get_lookups:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000945 * @face: #hb_face_t to work upon
946 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
947 * @feature_index: The index of the requested feature
Nathan Willis3db22722019-04-02 18:49:40 +0100948 * @start_offset: offset of the first lookup to retrieve
949 * @lookup_count: (inout) (allow-none): Input = the maximum number of lookups to return;
950 * Output = the actual number of lookups returned (may be zero)
951 * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +0000952 *
953 * Fetches a list of all lookups enumerated for the specified feature, in
954 * the specified face's GSUB table or GPOS table. The list returned will
955 * begin at the offset provided.
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +0400956 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200957 * Since: 0.9.7
958 **/
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500959unsigned int
Behdad Esfahbodf3064102012-11-15 18:39:46 -0800960hb_ot_layout_feature_get_lookups (hb_face_t *face,
961 hb_tag_t table_tag,
962 unsigned int feature_index,
963 unsigned int start_offset,
Ebrahim Byagowi63109432018-10-13 14:00:05 +0330964 unsigned int *lookup_count /* IN/OUT */,
Behdad Esfahbodf3064102012-11-15 18:39:46 -0800965 unsigned int *lookup_indexes /* OUT */)
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500966{
Behdad Esfahbodec87ba92016-09-10 03:53:11 -0700967 return hb_ot_layout_feature_with_variations_get_lookups (face,
968 table_tag,
969 feature_index,
970 HB_OT_LAYOUT_NO_VARIATIONS_INDEX,
971 start_offset,
972 lookup_count,
973 lookup_indexes);
Behdad Esfahbodc4473352008-02-18 21:14:23 -0500974}
975
Nathan Willis930f6fc2019-03-16 15:10:21 +0000976
Sascha Brawer01c3a882015-06-01 13:22:01 +0200977/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +0400978 * hb_ot_layout_table_get_lookup_count:
Nathan Willis930f6fc2019-03-16 15:10:21 +0000979 * @face: #hb_face_t to work upon
980 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
981 *
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +0430982 * Fetches the total number of lookups enumerated in the specified
Nathan Willis930f6fc2019-03-16 15:10:21 +0000983 * face's GSUB table or GPOS table.
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +0400984 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200985 * Since: 0.9.22
986 **/
Behdad Esfahbod27674b42013-10-03 14:54:50 -0400987unsigned int
988hb_ot_layout_table_get_lookup_count (hb_face_t *face,
989 hb_tag_t table_tag)
990{
Behdad Esfahbod96828b92018-10-25 20:34:29 -0700991 return get_gsubgpos_table (face, table_tag).get_lookup_count ();
Behdad Esfahbod27674b42013-10-03 14:54:50 -0400992}
993
Behdad Esfahbod941600a2018-10-25 21:26:08 -0700994
995struct hb_collect_features_context_t
996{
997 hb_collect_features_context_t (hb_face_t *face,
998 hb_tag_t table_tag,
999 hb_set_t *feature_indexes_)
1000 : g (get_gsubgpos_table (face, table_tag)),
Garret Rieger0e1ad5a2018-10-30 11:29:58 -07001001 feature_indexes (feature_indexes_),
Behdad Esfahbodbfd549d2018-10-30 14:47:27 -07001002 script_count(0),langsys_count(0) {}
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001003
Ebrahim Byagowid0a706c2018-12-22 19:47:48 +03301004 bool visited (const OT::Script &s)
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001005 {
1006 /* We might have Null() object here. Don't want to involve
1007 * that in the memoize. So, detect empty objects and return. */
1008 if (unlikely (!s.has_default_lang_sys () &&
1009 !s.get_lang_sys_count ()))
1010 return true;
1011
Garret Rieger0e1ad5a2018-10-30 11:29:58 -07001012 if (script_count++ > HB_MAX_SCRIPTS)
1013 return true;
1014
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001015 return visited (s, visited_script);
1016 }
Ebrahim Byagowid0a706c2018-12-22 19:47:48 +03301017 bool visited (const OT::LangSys &l)
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001018 {
1019 /* We might have Null() object here. Don't want to involve
1020 * that in the memoize. So, detect empty objects and return. */
1021 if (unlikely (!l.has_required_feature () &&
1022 !l.get_feature_count ()))
1023 return true;
1024
Garret Rieger0e1ad5a2018-10-30 11:29:58 -07001025 if (langsys_count++ > HB_MAX_LANGSYS)
1026 return true;
1027
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001028 return visited (l, visited_langsys);
1029 }
1030
1031 private:
1032 template <typename T>
Ebrahim Byagowid0a706c2018-12-22 19:47:48 +03301033 bool visited (const T &p, hb_set_t &visited_set)
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001034 {
1035 hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g);
1036 if (visited_set.has (delta))
1037 return true;
1038
1039 visited_set.add (delta);
1040 return false;
1041 }
1042
1043 public:
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001044 const OT::GSUBGPOS &g;
1045 hb_set_t *feature_indexes;
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001046
1047 private:
Behdad Esfahbod3a4e5dd2018-10-29 18:05:25 -07001048 hb_set_t visited_script;
1049 hb_set_t visited_langsys;
Garret Rieger0e1ad5a2018-10-30 11:29:58 -07001050 unsigned int script_count;
1051 unsigned int langsys_count;
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001052};
1053
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001054static void
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001055langsys_collect_features (hb_collect_features_context_t *c,
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001056 const OT::LangSys &l,
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001057 const hb_tag_t *features)
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001058{
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001059 if (c->visited (l)) return;
1060
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001061 if (!features)
1062 {
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001063 /* All features. */
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001064 if (l.has_required_feature ())
1065 c->feature_indexes->add (l.get_required_feature_index ());
Behdad Esfahbod5f85c802013-06-26 20:14:18 -04001066
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001067 l.add_feature_indexes_to (c->feature_indexes);
Behdad Esfahbod15e9e4e2013-01-03 00:04:40 -06001068 }
1069 else
1070 {
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001071 /* Ugh. Any faster way? */
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001072 for (; *features; features++)
1073 {
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001074 hb_tag_t feature_tag = *features;
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001075 unsigned int num_features = l.get_feature_count ();
1076 for (unsigned int i = 0; i < num_features; i++)
1077 {
1078 unsigned int feature_index = l.get_feature_index (i);
1079
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001080 if (feature_tag == c->g.get_feature_tag (feature_index))
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001081 {
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001082 c->feature_indexes->add (feature_index);
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001083 break;
1084 }
1085 }
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001086 }
1087 }
1088}
1089
1090static void
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001091script_collect_features (hb_collect_features_context_t *c,
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001092 const OT::Script &s,
1093 const hb_tag_t *languages,
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001094 const hb_tag_t *features)
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001095{
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001096 if (c->visited (s)) return;
1097
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001098 if (!languages)
1099 {
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001100 /* All languages. */
Behdad Esfahbodeb44bfc2018-10-25 21:42:19 -07001101 if (s.has_default_lang_sys ())
1102 langsys_collect_features (c,
1103 s.get_default_lang_sys (),
1104 features);
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001105
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001106 unsigned int count = s.get_lang_sys_count ();
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001107 for (unsigned int language_index = 0; language_index < count; language_index++)
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001108 langsys_collect_features (c,
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001109 s.get_lang_sys (language_index),
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001110 features);
Behdad Esfahbod15e9e4e2013-01-03 00:04:40 -06001111 }
1112 else
1113 {
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001114 for (; *languages; languages++)
1115 {
1116 unsigned int language_index;
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001117 if (s.find_lang_sys_index (*languages, &language_index))
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001118 langsys_collect_features (c,
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001119 s.get_lang_sys (language_index),
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001120 features);
Garret Rieger7d92bef2018-07-30 17:17:43 -07001121 }
1122 }
1123}
1124
Nathan Willis930f6fc2019-03-16 15:10:21 +00001125
Garret Rieger7d92bef2018-07-30 17:17:43 -07001126/**
Garret Rieger89733752018-07-30 18:10:43 -07001127 * hb_ot_layout_collect_features:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001128 * @face: #hb_face_t to work upon
1129 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1130 * @scripts: The array of scripts to collect features for
1131 * @languages: The array of languages to collect features for
1132 * @features: The array of features to collect
Nathan Willis51228052019-03-17 14:43:06 +00001133 * @feature_indexes: (out): The array of feature indexes found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +00001134 *
1135 * Fetches a list of all feature indexes in the specified face's GSUB table
1136 * or GPOS table, underneath the specified scripts, languages, and features.
1137 * If no list of scripts is provided, all scripts will be queried. If no list
1138 * of languages is provided, all languages will be queried. If no list of
1139 * features is provided, all features will be queried.
Garret Rieger7d92bef2018-07-30 17:17:43 -07001140 *
Behdad Esfahbod44d1fb32018-08-01 14:51:51 -07001141 * Since: 1.8.5
Garret Rieger7d92bef2018-07-30 17:17:43 -07001142 **/
1143void
1144hb_ot_layout_collect_features (hb_face_t *face,
1145 hb_tag_t table_tag,
1146 const hb_tag_t *scripts,
1147 const hb_tag_t *languages,
1148 const hb_tag_t *features,
1149 hb_set_t *feature_indexes /* OUT */)
1150{
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001151 hb_collect_features_context_t c (face, table_tag, feature_indexes);
Garret Rieger7d92bef2018-07-30 17:17:43 -07001152 if (!scripts)
1153 {
Behdad Esfahbode8e67502018-10-25 20:48:20 -07001154 /* All scripts. */
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001155 unsigned int count = c.g.get_script_count ();
Garret Rieger7d92bef2018-07-30 17:17:43 -07001156 for (unsigned int script_index = 0; script_index < count; script_index++)
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001157 script_collect_features (&c,
1158 c.g.get_script (script_index),
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001159 languages,
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001160 features);
Garret Rieger7d92bef2018-07-30 17:17:43 -07001161 }
1162 else
1163 {
1164 for (; *scripts; scripts++)
1165 {
1166 unsigned int script_index;
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001167 if (c.g.find_script_index (*scripts, &script_index))
1168 script_collect_features (&c,
1169 c.g.get_script (script_index),
Behdad Esfahbodfe5520d2018-10-25 20:58:34 -07001170 languages,
Behdad Esfahbod941600a2018-10-25 21:26:08 -07001171 features);
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001172 }
1173 }
1174}
1175
Nathan Willis930f6fc2019-03-16 15:10:21 +00001176
Sascha Brawer01c3a882015-06-01 13:22:01 +02001177/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001178 * hb_ot_layout_collect_lookups:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001179 * @face: #hb_face_t to work upon
1180 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1181 * @scripts: The array of scripts to collect lookups for
1182 * @languages: The array of languages to collect lookups for
1183 * @features: The array of features to collect lookups for
Nathan Willis51228052019-03-17 14:43:06 +00001184 * @lookup_indexes: (out): The array of lookup indexes found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +00001185 *
1186 * Fetches a list of all feature-lookup indexes in the specified face's GSUB
1187 * table or GPOS table, underneath the specified scripts, languages, and
1188 * features. If no list of scripts is provided, all scripts will be queried.
1189 * If no list of languages is provided, all languages will be queried. If no
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +04301190 * list of features is provided, all features will be queried.
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001191 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001192 * Since: 0.9.8
1193 **/
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001194void
1195hb_ot_layout_collect_lookups (hb_face_t *face,
1196 hb_tag_t table_tag,
1197 const hb_tag_t *scripts,
1198 const hb_tag_t *languages,
1199 const hb_tag_t *features,
1200 hb_set_t *lookup_indexes /* OUT */)
1201{
Behdad Esfahbode98af6d2018-10-25 22:25:29 -07001202 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1203
Behdad Esfahbod3a4e5dd2018-10-29 18:05:25 -07001204 hb_set_t feature_indexes;
Garret Rieger7d92bef2018-07-30 17:17:43 -07001205 hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes);
Behdad Esfahbode98af6d2018-10-25 22:25:29 -07001206
Behdad Esfahbodc237cdf2018-10-25 21:17:30 -07001207 for (hb_codepoint_t feature_index = HB_SET_VALUE_INVALID;
1208 hb_set_next (&feature_indexes, &feature_index);)
Behdad Esfahbode98af6d2018-10-25 22:25:29 -07001209 g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes);
Behdad Esfahboda88e7162012-11-24 02:31:02 -05001210}
1211
Nathan Willis930f6fc2019-03-16 15:10:21 +00001212
Behdad Esfahbodfce3bf82019-06-19 20:34:29 -07001213#ifndef HB_NO_LAYOUT_COLLECT_GLYPHS
Sascha Brawer01c3a882015-06-01 13:22:01 +02001214/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001215 * hb_ot_layout_lookup_collect_glyphs:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001216 * @face: #hb_face_t to work upon
1217 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1218 * @lookup_index: The index of the feature lookup to query
Nathan Willis51228052019-03-17 14:43:06 +00001219 * @glyphs_before: (out): Array of glyphs preceding the substitution range
1220 * @glyphs_input: (out): Array of input glyphs that would be substituted by the lookup
1221 * @glyphs_after: (out): Array of glyphs following the substition range
1222 * @glyphs_output: (out): Array of glyphs that would be the substitued output of the lookup
Nathan Willis930f6fc2019-03-16 15:10:21 +00001223 *
1224 * Fetches a list of all glyphs affected by the specified lookup in the
1225 * specified face's GSUB table of GPOS table.
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001226 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001227 * Since: 0.9.7
1228 **/
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001229void
1230hb_ot_layout_lookup_collect_glyphs (hb_face_t *face,
1231 hb_tag_t table_tag,
1232 unsigned int lookup_index,
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301233 hb_set_t *glyphs_before, /* OUT. May be NULL */
1234 hb_set_t *glyphs_input, /* OUT. May be NULL */
1235 hb_set_t *glyphs_after, /* OUT. May be NULL */
1236 hb_set_t *glyphs_output /* OUT. May be NULL */)
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001237{
Behdad Esfahbod733e8c02013-01-03 00:00:23 -06001238 OT::hb_collect_glyphs_context_t c (face,
1239 glyphs_before,
1240 glyphs_input,
1241 glyphs_after,
1242 glyphs_output);
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001243
Behdad Esfahbod15e9e4e2013-01-03 00:04:40 -06001244 switch (table_tag)
1245 {
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001246 case HB_OT_TAG_GSUB:
1247 {
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001248 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
Behdad Esfahbod780cd932013-05-03 17:33:16 -04001249 l.collect_glyphs (&c);
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001250 return;
1251 }
1252 case HB_OT_TAG_GPOS:
1253 {
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001254 const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index);
Behdad Esfahbod780cd932013-05-03 17:33:16 -04001255 l.collect_glyphs (&c);
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001256 return;
1257 }
1258 }
1259}
Behdad Esfahbodfce3bf82019-06-19 20:34:29 -07001260#endif
Behdad Esfahbode8cfdd72012-11-16 19:07:06 -08001261
Behdad Esfahbod2d15e722009-04-15 19:50:16 -04001262
Behdad Esfahbod30c42b62016-09-10 03:32:39 -07001263/* Variations support */
1264
Nathan Willis930f6fc2019-03-16 15:10:21 +00001265
1266/**
1267 * hb_ot_layout_table_find_feature_variations:
1268 * @face: #hb_face_t to work upon
1269 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1270 * @coords: The variation coordinates to query
1271 * @num_coords: The number of variation coorinates
Nathan Willis3db22722019-04-02 18:49:40 +01001272 * @variations_index: (out): The array of feature variations found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +00001273 *
1274 * Fetches a list of feature variations in the specified face's GSUB table
1275 * or GPOS table, at the specified variation coordinates.
1276 *
1277 **/
Behdad Esfahbod30c42b62016-09-10 03:32:39 -07001278hb_bool_t
1279hb_ot_layout_table_find_feature_variations (hb_face_t *face,
1280 hb_tag_t table_tag,
1281 const int *coords,
1282 unsigned int num_coords,
1283 unsigned int *variations_index /* out */)
1284{
1285 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1286
1287 return g.find_variations_index (coords, num_coords, variations_index);
1288}
1289
Nathan Willis930f6fc2019-03-16 15:10:21 +00001290
1291/**
1292 * hb_ot_layout_feature_with_variations_get_lookups:
1293 * @face: #hb_face_t to work upon
1294 * @table_tag: HB_OT_TAG_GSUB or HB_OT_TAG_GPOS
1295 * @feature_index: The index of the feature to query
1296 * @variations_index: The index of the feature variation to query
Nathan Willis3db22722019-04-02 18:49:40 +01001297 * @start_offset: offset of the first lookup to retrieve
1298 * @lookup_count: (inout) (allow-none): Input = the maximum number of lookups to return;
1299 * Output = the actual number of lookups returned (may be zero)
1300 * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query
Nathan Willis930f6fc2019-03-16 15:10:21 +00001301 *
1302 * Fetches a list of all lookups enumerated for the specified feature, in
1303 * the specified face's GSUB table or GPOS table, enabled at the specified
1304 * variations index. The list returned will begin at the offset provided.
1305 *
1306 **/
Behdad Esfahbodec87ba92016-09-10 03:53:11 -07001307unsigned int
1308hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face,
1309 hb_tag_t table_tag,
1310 unsigned int feature_index,
1311 unsigned int variations_index,
1312 unsigned int start_offset,
1313 unsigned int *lookup_count /* IN/OUT */,
1314 unsigned int *lookup_indexes /* OUT */)
1315{
Behdad Esfahbod606bf572018-09-16 19:33:48 +02001316 static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "");
Behdad Esfahbodec87ba92016-09-10 03:53:11 -07001317 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1318
1319 const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
1320
1321 return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
1322}
1323
Behdad Esfahbod30c42b62016-09-10 03:32:39 -07001324
Behdad Esfahbod2d15e722009-04-15 19:50:16 -04001325/*
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -04001326 * OT::GSUB
Behdad Esfahbod2d15e722009-04-15 19:50:16 -04001327 */
1328
Nathan Willis930f6fc2019-03-16 15:10:21 +00001329
1330/**
1331 * hb_ot_layout_has_substitution:
1332 * @face: #hb_face_t to work upon
1333 *
1334 * Tests whether the specified face includes any GSUB substitutions.
1335 *
1336 * Return value: true if data found, false otherwise
1337 *
1338 **/
Behdad Esfahbod2d15e722009-04-15 19:50:16 -04001339hb_bool_t
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001340hb_ot_layout_has_substitution (hb_face_t *face)
1341{
Behdad Esfahbod737efbe2018-11-05 23:26:29 -05001342 return face->table.GSUB->table->has_data ();
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001343}
1344
Nathan Willis930f6fc2019-03-16 15:10:21 +00001345
Sascha Brawer01c3a882015-06-01 13:22:01 +02001346/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001347 * hb_ot_layout_lookup_would_substitute:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001348 * @face: #hb_face_t to work upon
1349 * @lookup_index: The index of the lookup to query
1350 * @glyphs: The sequence of glyphs to query for substitution
1351 * @glyphs_length: The length of the glyph sequence
1352 * @zero_context: #hb_bool_t indicating whether substitutions should be context-free
1353 *
1354 * Tests whether a specified lookup in the specified face would
1355 * trigger a substitution on the given glyph sequence.
1356 *
1357 * Return value: true if a substitution would be triggered, false otherwise
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001358 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001359 * Since: 0.9.7
1360 **/
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001361hb_bool_t
Behdad Esfahbod362a9902012-11-15 14:57:31 -08001362hb_ot_layout_lookup_would_substitute (hb_face_t *face,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -04001363 unsigned int lookup_index,
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001364 const hb_codepoint_t *glyphs,
1365 unsigned int glyphs_length,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -04001366 hb_bool_t zero_context)
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001367{
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001368 if (unlikely (lookup_index >= face->table.GSUB->lookup_count)) return false;
Behdad Esfahbodea512f72015-11-26 19:22:22 -05001369 OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context);
Behdad Esfahbod2bd9fe32012-09-04 15:15:19 -04001370
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001371 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
Behdad Esfahbod2bd9fe32012-09-04 15:15:19 -04001372
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001373 return l.would_apply (&c, &face->table.GSUB->accels[lookup_index]);
Behdad Esfahbodf8603662012-07-30 02:38:39 -04001374}
1375
Nathan Willis930f6fc2019-03-16 15:10:21 +00001376
1377/**
1378 * hb_ot_layout_substitute_start:
1379 * @font: #hb_font_t to use
1380 * @buffer: #hb_buffer_t buffer to work upon
1381 *
Nathan Willis3db22722019-04-02 18:49:40 +01001382 * Called before substitution lookups are performed, to ensure that glyph
1383 * class and other properties are set on the glyphs in the buffer.
Nathan Willis930f6fc2019-03-16 15:10:21 +00001384 *
1385 **/
Behdad Esfahbod46d6a212011-05-11 22:33:13 -04001386void
Behdad Esfahbodc624e182018-08-26 09:19:20 -07001387hb_ot_layout_substitute_start (hb_font_t *font,
1388 hb_buffer_t *buffer)
Behdad Esfahbod46d6a212011-05-11 22:33:13 -04001389{
Behdad Esfahbodc624e182018-08-26 09:19:20 -07001390_hb_ot_layout_set_glyph_props (font, buffer);
Behdad Esfahbod46d6a212011-05-11 22:33:13 -04001391}
1392
Behdad Esfahbod385f78b2018-11-07 17:19:21 -05001393void
1394hb_ot_layout_delete_glyphs_inplace (hb_buffer_t *buffer,
1395 bool (*filter) (const hb_glyph_info_t *info))
1396{
1397 /* Merge clusters and delete filtered glyphs.
1398 * NOTE! We can't use out-buffer as we have positioning data. */
1399 unsigned int j = 0;
1400 unsigned int count = buffer->len;
1401 hb_glyph_info_t *info = buffer->info;
1402 hb_glyph_position_t *pos = buffer->pos;
1403 for (unsigned int i = 0; i < count; i++)
1404 {
1405 if (filter (&info[i]))
1406 {
1407 /* Merge clusters.
1408 * Same logic as buffer->delete_glyph(), but for in-place removal. */
1409
1410 unsigned int cluster = info[i].cluster;
1411 if (i + 1 < count && cluster == info[i + 1].cluster)
1412 continue; /* Cluster survives; do nothing. */
1413
1414 if (j)
1415 {
1416 /* Merge cluster backward. */
1417 if (cluster < info[j - 1].cluster)
1418 {
1419 unsigned int mask = info[i].mask;
1420 unsigned int old_cluster = info[j - 1].cluster;
1421 for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--)
1422 buffer->set_cluster (info[k - 1], cluster, mask);
1423 }
1424 continue;
1425 }
1426
1427 if (i + 1 < count)
1428 buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */
1429
1430 continue;
1431 }
1432
1433 if (j != i)
1434 {
1435 info[j] = info[i];
1436 pos[j] = pos[i];
1437 }
1438 j++;
1439 }
1440 buffer->len = j;
1441}
1442
Sascha Brawer01c3a882015-06-01 13:22:01 +02001443/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001444 * hb_ot_layout_lookup_substitute_closure:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001445 * @face: #hb_face_t to work upon
1446 * @lookup_index: index of the feature lookup to query
Nathan Willis51228052019-03-17 14:43:06 +00001447 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup
Nathan Willis930f6fc2019-03-16 15:10:21 +00001448 *
1449 * Compute the transitive closure of glyphs needed for a
1450 * specified lookup.
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001451 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001452 * Since: 0.9.7
1453 **/
Behdad Esfahbod5caece62012-04-23 23:03:12 -04001454void
Behdad Esfahbod362a9902012-11-15 14:57:31 -08001455hb_ot_layout_lookup_substitute_closure (hb_face_t *face,
Behdad Esfahbodd9b204d2012-08-23 16:22:28 -04001456 unsigned int lookup_index,
Nathan Willis930f6fc2019-03-16 15:10:21 +00001457 hb_set_t *glyphs /* OUT */)
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001458{
Behdad Esfahbod3a4e5dd2018-10-29 18:05:25 -07001459 hb_map_t done_lookups;
Garret Rieger45186b92018-06-05 17:14:42 -07001460 OT::hb_closure_context_t c (face, glyphs, &done_lookups);
Behdad Esfahbod9b346772012-11-23 17:55:40 -05001461
Behdad Esfahbod737efbe2018-11-05 23:26:29 -05001462 const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
Behdad Esfahbod9b346772012-11-23 17:55:40 -05001463
Garret Rieger45186b92018-06-05 17:14:42 -07001464 l.closure (&c, lookup_index);
Behdad Esfahbodf94b0aa2012-04-23 13:04:38 -04001465}
Behdad Esfahbodbff3c0f2009-08-07 19:46:30 -04001466
Garret Rieger57badad2018-06-06 16:02:51 -07001467/**
1468 * hb_ot_layout_lookups_substitute_closure:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001469 * @face: #hb_face_t to work upon
1470 * @lookups: The set of lookups to query
Nathan Willis51228052019-03-17 14:43:06 +00001471 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups
Garret Rieger57badad2018-06-06 16:02:51 -07001472 *
1473 * Compute the transitive closure of glyphs needed for all of the
1474 * provided lookups.
1475 *
1476 * Since: 1.8.1
1477 **/
1478void
1479hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
1480 const hb_set_t *lookups,
Nathan Willis930f6fc2019-03-16 15:10:21 +00001481 hb_set_t *glyphs /* OUT */)
Garret Rieger57badad2018-06-06 16:02:51 -07001482{
Behdad Esfahbod3a4e5dd2018-10-29 18:05:25 -07001483 hb_map_t done_lookups;
Garret Rieger57badad2018-06-06 16:02:51 -07001484 OT::hb_closure_context_t c (face, glyphs, &done_lookups);
Behdad Esfahbod737efbe2018-11-05 23:26:29 -05001485 const OT::GSUB& gsub = *face->table.GSUB->table;
Garret Rieger57badad2018-06-06 16:02:51 -07001486
Garret Rieger85646fd2018-07-23 15:37:18 -07001487 unsigned int iteration_count = 0;
Garret Rieger57badad2018-06-06 16:02:51 -07001488 unsigned int glyphs_length;
1489 do
1490 {
1491 glyphs_length = glyphs->get_population ();
Garret Riegerfeb23892018-06-07 14:32:34 -07001492 if (lookups != nullptr)
1493 {
1494 for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);)
1495 gsub.get_lookup (lookup_index).closure (&c, lookup_index);
Behdad Esfahbodf56cd9d2018-06-11 22:02:38 -04001496 }
1497 else
1498 {
Garret Riegerfeb23892018-06-07 14:32:34 -07001499 for (unsigned int i = 0; i < gsub.get_lookup_count (); i++)
1500 gsub.get_lookup (i).closure (&c, i);
1501 }
Behdad Esfahbode44046e2018-11-10 22:41:35 -05001502 } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES &&
1503 glyphs_length != glyphs->get_population ());
Garret Rieger57badad2018-06-06 16:02:51 -07001504}
1505
Behdad Esfahbod9c42f052009-05-18 17:43:49 -04001506/*
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -04001507 * OT::GPOS
Behdad Esfahbod9c42f052009-05-18 17:43:49 -04001508 */
1509
Nathan Willis930f6fc2019-03-16 15:10:21 +00001510
1511/**
1512 * hb_ot_layout_has_positioning:
1513 * @face: #hb_face_t to work upon
1514 *
1515 * Return value: true if the face has GPOS data, false otherwise
1516 *
1517 **/
Behdad Esfahbod9c42f052009-05-18 17:43:49 -04001518hb_bool_t
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001519hb_ot_layout_has_positioning (hb_face_t *face)
1520{
Behdad Esfahbod737efbe2018-11-05 23:26:29 -05001521 return face->table.GPOS->table->has_data ();
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001522}
1523
Nathan Willis930f6fc2019-03-16 15:10:21 +00001524/**
1525 * hb_ot_layout_position_start:
1526 * @font: #hb_font_t to use
1527 * @buffer: #hb_buffer_t buffer to work upon
1528 *
Nathan Willis3db22722019-04-02 18:49:40 +01001529 * Called before positioning lookups are performed, to ensure that glyph
1530 * attachment types and glyph-attachment chains are set for the glyphs in the buffer.
1531 *
Nathan Willis930f6fc2019-03-16 15:10:21 +00001532 **/
Behdad Esfahbod8f0d7e02011-04-15 18:59:56 -04001533void
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -04001534hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer)
Behdad Esfahbod8f0d7e02011-04-15 18:59:56 -04001535{
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -04001536 OT::GPOS::position_start (font, buffer);
Behdad Esfahbod8f0d7e02011-04-15 18:59:56 -04001537}
1538
Nathan Willis930f6fc2019-03-16 15:10:21 +00001539
1540/**
1541 * hb_ot_layout_position_finish_advances:
1542 * @font: #hb_font_t to use
1543 * @buffer: #hb_buffer_t buffer to work upon
1544 *
Nathan Willis3db22722019-04-02 18:49:40 +01001545 * Called after positioning lookups are performed, to finish glyph advances.
1546 *
Nathan Willis930f6fc2019-03-16 15:10:21 +00001547 **/
Behdad Esfahbod9db8ad72009-11-06 16:47:31 -05001548void
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +07001549hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer)
Behdad Esfahbod9db8ad72009-11-06 16:47:31 -05001550{
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +07001551 OT::GPOS::position_finish_advances (font, buffer);
1552}
1553
Nathan Willis3db22722019-04-02 18:49:40 +01001554/**
1555 * hb_ot_layout_position_finish_offsets:
1556 * @font: #hb_font_t to use
1557 * @buffer: #hb_buffer_t buffer to work upon
1558 *
1559 * Called after positioning lookups are performed, to finish glyph offsets.
1560 *
1561 **/
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +07001562void
1563hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
1564{
1565 OT::GPOS::position_finish_offsets (font, buffer);
Behdad Esfahbod9db8ad72009-11-06 16:47:31 -05001566}
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001567
Nathan Willis930f6fc2019-03-16 15:10:21 +00001568
Behdad Esfahbod6c725c72019-06-19 20:12:25 -07001569#ifndef HB_NO_LAYOUT_FEATURE_PARAMS
Sascha Brawer01c3a882015-06-01 13:22:01 +02001570/**
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001571 * hb_ot_layout_get_size_params:
Nathan Willis930f6fc2019-03-16 15:10:21 +00001572 * @face: #hb_face_t to work upon
Nathan Willis51228052019-03-17 14:43:06 +00001573 * @design_size: (out): The design size of the face
1574 * @subfamily_id: (out): The identifier of the face within the font subfamily
Nathan Willisc08ddbd2019-03-24 15:07:07 +00001575 * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily
Nathan Willis3db22722019-04-02 18:49:40 +01001576 * @range_start: (out): The minimum size of the recommended size range for the face
1577 * @range_end: (out): The maximum size of the recommended size range for the face
Nathan Willis930f6fc2019-03-16 15:10:21 +00001578 *
Nathan Willisc08ddbd2019-03-24 15:07:07 +00001579 * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that
1580 * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id)
1581 * as used here are defined as pertaining only to fonts within a font family that differ
1582 * specifically in their respective size ranges; other ways to differentiate fonts within
1583 * a subfamily are not covered by the `size` feature.
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +04301584 *
Nathan Willisc08ddbd2019-03-24 15:07:07 +00001585 * For more information on this distinction, see the `size` documentation at
1586 * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-39size39
Nathan Willis930f6fc2019-03-16 15:10:21 +00001587 *
1588 * Return value: true if data found, false otherwise
Khaled Hosnyd7bf9d02015-12-29 02:23:24 +04001589 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +04301590 * Since: 0.9.10
Sascha Brawer01c3a882015-06-01 13:22:01 +02001591 **/
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001592hb_bool_t
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001593hb_ot_layout_get_size_params (hb_face_t *face,
1594 unsigned int *design_size, /* OUT. May be NULL */
1595 unsigned int *subfamily_id, /* OUT. May be NULL */
1596 hb_ot_name_id_t *subfamily_name_id, /* OUT. May be NULL */
1597 unsigned int *range_start, /* OUT. May be NULL */
1598 unsigned int *range_end /* OUT. May be NULL */)
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001599{
Behdad Esfahbod737efbe2018-11-05 23:26:29 -05001600 const OT::GPOS &gpos = *face->table.GPOS->table;
Behdad Esfahbodefe252e2012-12-17 23:21:05 -05001601 const hb_tag_t tag = HB_TAG ('s','i','z','e');
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001602
Behdad Esfahbod0dff11f2012-11-30 08:14:20 +02001603 unsigned int num_features = gpos.get_feature_count ();
1604 for (unsigned int i = 0; i < num_features; i++)
1605 {
Behdad Esfahbodefe252e2012-12-17 23:21:05 -05001606 if (tag == gpos.get_feature_tag (i))
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001607 {
Behdad Esfahbod0dff11f2012-11-30 08:14:20 +02001608 const OT::Feature &f = gpos.get_feature (i);
Behdad Esfahbodefe252e2012-12-17 23:21:05 -05001609 const OT::FeatureParamsSize &params = f.get_feature_params ().get_size_params (tag);
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001610
Behdad Esfahbodefe252e2012-12-17 23:21:05 -05001611 if (params.designSize)
Behdad Esfahbod85bc44b2012-12-12 11:38:49 -05001612 {
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301613 if (design_size) *design_size = params.designSize;
1614 if (subfamily_id) *subfamily_id = params.subfamilyID;
Behdad Esfahbod6ce49a92018-10-28 08:26:30 -07001615 if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID;
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301616 if (range_start) *range_start = params.rangeStart;
1617 if (range_end) *range_end = params.rangeEnd;
Behdad Esfahbodefe252e2012-12-17 23:21:05 -05001618
1619 return true;
1620 }
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001621 }
1622 }
1623
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301624 if (design_size) *design_size = 0;
1625 if (subfamily_id) *subfamily_id = 0;
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001626 if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID;
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301627 if (range_start) *range_start = 0;
1628 if (range_end) *range_end = 0;
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001629
Behdad Esfahbodefe252e2012-12-17 23:21:05 -05001630 return false;
Behdad Esfahbodf54cce32012-11-26 14:02:31 +02001631}
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301632/**
1633 * hb_ot_layout_feature_get_name_ids:
1634 * @face: #hb_face_t to work upon
Behdad Esfahboda5ad8c62018-10-20 16:52:55 -07001635 * @table_tag: table tag to query, "GSUB" or "GPOS".
1636 * @feature_index: index of feature to query.
Nathan Willisaf5230b2019-03-18 14:03:16 +00001637 * @label_id: (out) (allow-none): The ‘name’ table name ID that specifies a string
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301638 * for a user-interface label for this feature. (May be NULL.)
Nathan Willisaf5230b2019-03-18 14:03:16 +00001639 * @tooltip_id: (out) (allow-none): The ‘name’ table name ID that specifies a string
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301640 * that an application can use for tooltip text for this
1641 * feature. (May be NULL.)
Nathan Willisaf5230b2019-03-18 14:03:16 +00001642 * @sample_id: (out) (allow-none): The ‘name’ table name ID that specifies sample text
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301643 * that illustrates the effect of this feature. (May be NULL.)
Nathan Willisaf5230b2019-03-18 14:03:16 +00001644 * @num_named_parameters: (out) (allow-none): Number of named parameters. (May be zero.)
1645 * @first_param_id: (out) (allow-none): The first ‘name’ table name ID used to specify
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301646 * strings for user-interface labels for the feature
1647 * parameters. (Must be zero if numParameters is zero.)
1648 *
Behdad Esfahbodc0a68142018-10-12 16:05:56 -04001649 * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or
1650 * "Character Variant" ('cvXX') features.
1651 *
1652 * Return value: true if data found, false otherwise
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301653 *
Behdad Esfahbod3d9a0302018-10-18 05:58:17 -07001654 * Since: 2.0.0
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301655 **/
1656hb_bool_t
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001657hb_ot_layout_feature_get_name_ids (hb_face_t *face,
1658 hb_tag_t table_tag,
1659 unsigned int feature_index,
1660 hb_ot_name_id_t *label_id, /* OUT. May be NULL */
1661 hb_ot_name_id_t *tooltip_id, /* OUT. May be NULL */
1662 hb_ot_name_id_t *sample_id, /* OUT. May be NULL */
1663 unsigned int *num_named_parameters, /* OUT. May be NULL */
1664 hb_ot_name_id_t *first_param_id /* OUT. May be NULL */)
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301665{
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301666 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1667
Behdad Esfahbodc0a68142018-10-12 16:05:56 -04001668 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301669 const OT::Feature &f = g.get_feature (feature_index);
1670
1671 const OT::FeatureParams &feature_params = f.get_feature_params ();
1672 if (&feature_params != &Null (OT::FeatureParams))
1673 {
1674 const OT::FeatureParamsStylisticSet& ss_params =
1675 feature_params.get_stylistic_set_params (feature_tag);
1676 if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */
1677 {
Behdad Esfahbod6ce49a92018-10-28 08:26:30 -07001678 if (label_id) *label_id = ss_params.uiNameID;
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301679 // ssXX features don't have the rest
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001680 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1681 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301682 if (num_named_parameters) *num_named_parameters = 0;
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001683 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301684 return true;
1685 }
1686 const OT::FeatureParamsCharacterVariants& cv_params =
1687 feature_params.get_character_variants_params (feature_tag);
1688 if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */
1689 {
Behdad Esfahbod6ce49a92018-10-28 08:26:30 -07001690 if (label_id) *label_id = cv_params.featUILableNameID;
1691 if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID;
1692 if (sample_id) *sample_id = cv_params.sampleTextNameID;
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301693 if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters;
Behdad Esfahbod6ce49a92018-10-28 08:26:30 -07001694 if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID;
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301695 return true;
1696 }
1697 }
1698
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001699 if (label_id) *label_id = HB_OT_NAME_ID_INVALID;
1700 if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1701 if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301702 if (num_named_parameters) *num_named_parameters = 0;
Behdad Esfahboda7aba992018-10-30 14:04:09 -07001703 if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301704 return false;
1705}
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301706/**
Behdad Esfahboda5ad8c62018-10-20 16:52:55 -07001707 * hb_ot_layout_feature_get_characters:
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301708 * @face: #hb_face_t to work upon
Behdad Esfahboda5ad8c62018-10-20 16:52:55 -07001709 * @table_tag: table tag to query, "GSUB" or "GPOS".
1710 * @feature_index: index of feature to query.
Nathan Willis3db22722019-04-02 18:49:40 +01001711 * @start_offset: offset of the first character to retrieve
1712 * @char_count: (inout) (allow-none): Input = the maximum number of characters to return;
1713 * Output = the actual number of characters returned (may be zero)
1714 * @characters: (out caller-allocates) (array length=char_count): A buffer pointer.
1715 * The Unicode codepoints of the characters for which this feature provides
1716 * glyph variants.
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301717 *
Nathan Willis3db22722019-04-02 18:49:40 +01001718 * Fetches a list of the characters defined as having a variant under the specified
1719 * "Character Variant" ("cvXX") feature tag.
Behdad Esfahbodc0a68142018-10-12 16:05:56 -04001720 *
Nathan Willis3db22722019-04-02 18:49:40 +01001721 * <note>Note: If the char_count output value is equal to its input value, then there
1722 * is a chance there were more characters defined under the feature tag than were
1723 * returned. This function can be called with incrementally larger start_offset
1724 * until the char_count output value is lower than its input value, or the size
1725 * of the characters array can be increased.</note>
Ebrahim Byagowi41ab56e2019-07-22 18:46:52 +04301726 *
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301727 * Return value: Number of total sample characters in the cvXX feature.
1728 *
Behdad Esfahbod3d9a0302018-10-18 05:58:17 -07001729 * Since: 2.0.0
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301730 **/
1731unsigned int
1732hb_ot_layout_feature_get_characters (hb_face_t *face,
1733 hb_tag_t table_tag,
1734 unsigned int feature_index,
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301735 unsigned int start_offset,
1736 unsigned int *char_count, /* IN/OUT. May be NULL */
1737 hb_codepoint_t *characters /* OUT. May be NULL */)
1738{
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301739 const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1740
Behdad Esfahbodc0a68142018-10-12 16:05:56 -04001741 hb_tag_t feature_tag = g.get_feature_tag (feature_index);
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301742 const OT::Feature &f = g.get_feature (feature_index);
1743
1744 const OT::FeatureParams &feature_params = f.get_feature_params ();
1745
1746 const OT::FeatureParamsCharacterVariants& cv_params =
1747 feature_params.get_character_variants_params(feature_tag);
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301748
1749 unsigned int len = 0;
1750 if (char_count && characters && start_offset < cv_params.characters.len)
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301751 {
Behdad Esfahbod41248cc2019-05-07 20:54:31 -07001752 len = hb_min (cv_params.characters.len - start_offset, *char_count);
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301753 for (unsigned int i = 0; i < len; ++i)
1754 characters[i] = cv_params.characters[start_offset + i];
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301755 }
Ebrahim Byagowi63109432018-10-13 14:00:05 +03301756 if (char_count) *char_count = len;
1757 return cv_params.characters.len;
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301758}
Behdad Esfahbod6c725c72019-06-19 20:12:25 -07001759#endif
Ebrahim Byagowidc49bd82018-10-12 03:00:59 +03301760
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001761
1762/*
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001763 * Parts of different types are implemented here such that they have direct
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001764 * access to GSUB/GPOS lookups.
1765 */
1766
1767
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001768struct GSUBProxy
1769{
Behdad Esfahbod5d4b0372019-01-22 12:11:24 +01001770 static constexpr unsigned table_index = 0u;
Behdad Esfahbod39e1b6d2019-01-22 12:07:43 +01001771 static constexpr bool inplace = false;
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001772 typedef OT::SubstLookup Lookup;
1773
1774 GSUBProxy (hb_face_t *face) :
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001775 table (*face->table.GSUB->table),
1776 accels (face->table.GSUB->accels) {}
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001777
1778 const OT::GSUB &table;
Behdad Esfahbod97e59132018-10-10 11:41:05 -04001779 const OT::hb_ot_layout_lookup_accelerator_t *accels;
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001780};
1781
1782struct GPOSProxy
1783{
Behdad Esfahbod5d4b0372019-01-22 12:11:24 +01001784 static constexpr unsigned table_index = 1u;
Behdad Esfahbod39e1b6d2019-01-22 12:07:43 +01001785 static constexpr bool inplace = true;
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001786 typedef OT::PosLookup Lookup;
1787
1788 GPOSProxy (hb_face_t *face) :
Behdad Esfahbod0fe7a742018-11-05 23:08:33 -05001789 table (*face->table.GPOS->table),
1790 accels (face->table.GPOS->accels) {}
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001791
1792 const OT::GPOS &table;
Behdad Esfahbod97e59132018-10-10 11:41:05 -04001793 const OT::hb_ot_layout_lookup_accelerator_t *accels;
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001794};
1795
1796
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001797static inline bool
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001798apply_forward (OT::hb_ot_apply_context_t *c,
Behdad Esfahbod78c09bf2018-10-10 11:50:46 -04001799 const OT::hb_ot_layout_lookup_accelerator_t &accel)
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001800{
1801 bool ret = false;
1802 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbod7185b272018-05-31 20:03:00 -07001803 while (buffer->idx < buffer->len && buffer->successful)
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001804 {
Behdad Esfahbod3e704522016-01-11 17:38:41 +00001805 bool applied = false;
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001806 if (accel.may_have (buffer->cur().codepoint) &&
1807 (buffer->cur().mask & c->lookup_mask) &&
Behdad Esfahbod3e704522016-01-11 17:38:41 +00001808 c->check_glyph_property (&buffer->cur(), c->lookup_props))
1809 {
Behdad Esfahbode78549e2018-10-10 11:54:48 -04001810 applied = accel.apply (c);
Behdad Esfahbod3e704522016-01-11 17:38:41 +00001811 }
1812
1813 if (applied)
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001814 ret = true;
1815 else
1816 buffer->next_glyph ();
1817 }
1818 return ret;
1819}
1820
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001821static inline bool
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001822apply_backward (OT::hb_ot_apply_context_t *c,
Behdad Esfahbod78c09bf2018-10-10 11:50:46 -04001823 const OT::hb_ot_layout_lookup_accelerator_t &accel)
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001824{
1825 bool ret = false;
1826 hb_buffer_t *buffer = c->buffer;
1827 do
1828 {
1829 if (accel.may_have (buffer->cur().codepoint) &&
1830 (buffer->cur().mask & c->lookup_mask) &&
Behdad Esfahbod3e704522016-01-11 17:38:41 +00001831 c->check_glyph_property (&buffer->cur(), c->lookup_props))
Behdad Esfahbod9af983a2018-11-07 16:03:09 -05001832 ret |= accel.apply (c);
1833
Behdad Esfahbode2f50f22015-02-19 17:15:05 +03001834 /* The reverse lookup doesn't "advance" cursor (for good reason). */
1835 buffer->idx--;
1836
1837 }
1838 while ((int) buffer->idx >= 0);
1839 return ret;
1840}
1841
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001842template <typename Proxy>
Behdad Esfahbod1d4a3282015-02-19 11:33:30 +03001843static inline void
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001844apply_string (OT::hb_ot_apply_context_t *c,
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001845 const typename Proxy::Lookup &lookup,
Behdad Esfahbod97e59132018-10-10 11:41:05 -04001846 const OT::hb_ot_layout_lookup_accelerator_t &accel)
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001847{
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001848 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001849
Behdad Esfahbod5337db22015-11-06 16:18:09 -08001850 if (unlikely (!buffer->len || !c->lookup_mask))
Behdad Esfahbod1d4a3282015-02-19 11:33:30 +03001851 return;
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001852
Behdad Esfahbod2c8b3b22015-08-18 14:36:43 +01001853 c->set_lookup_props (lookup.get_props ());
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001854
1855 if (likely (!lookup.is_reverse ()))
1856 {
1857 /* in/out forward substitution/positioning */
Behdad Esfahbod271cb7c2019-01-22 12:05:35 +01001858 if (Proxy::table_index == 0u)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001859 buffer->clear_output ();
1860 buffer->idx = 0;
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001861
Behdad Esfahbod640b66c2015-02-19 17:30:05 +03001862 bool ret;
Behdad Esfahbod78c09bf2018-10-10 11:50:46 -04001863 ret = apply_forward (c, accel);
Behdad Esfahbod640b66c2015-02-19 17:30:05 +03001864 if (ret)
Behdad Esfahbod9d9e72e2013-05-03 18:10:10 -04001865 {
Behdad Esfahbod6ffc0072013-10-28 19:26:02 +01001866 if (!Proxy::inplace)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001867 buffer->swap_buffers ();
Behdad Esfahbod9d9e72e2013-05-03 18:10:10 -04001868 else
Behdad Esfahbod1d4a3282015-02-19 11:33:30 +03001869 assert (!buffer->has_separate_output ());
Behdad Esfahbod9d9e72e2013-05-03 18:10:10 -04001870 }
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001871 }
1872 else
1873 {
1874 /* in-place backward substitution/positioning */
Behdad Esfahbod271cb7c2019-01-22 12:05:35 +01001875 if (Proxy::table_index == 0u)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001876 buffer->remove_output ();
1877 buffer->idx = buffer->len - 1;
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001878
Behdad Esfahbod78c09bf2018-10-10 11:50:46 -04001879 apply_backward (c, accel);
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001880 }
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001881}
1882
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001883template <typename Proxy>
1884inline void hb_ot_map_t::apply (const Proxy &proxy,
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001885 const hb_ot_shape_plan_t *plan,
1886 hb_font_t *font,
1887 hb_buffer_t *buffer) const
1888{
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001889 const unsigned int table_index = proxy.table_index;
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001890 unsigned int i = 0;
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001891 OT::hb_ot_apply_context_t c (table_index, font, buffer);
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001892 c.set_recurse_func (Proxy::Lookup::apply_recurse_func);
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001893
Behdad Esfahbod474a1202018-12-21 18:46:51 -05001894 for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++) {
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001895 const stage_map_t *stage = &stages[table_index][stage_index];
1896 for (; i < stage->last_lookup; i++)
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001897 {
1898 unsigned int lookup_index = lookups[table_index][i].index;
Behdad Esfahbod0475ef22015-12-18 18:17:07 +00001899 if (!buffer->message (font, "start lookup %d", lookup_index)) continue;
Behdad Esfahbod2c8b3b22015-08-18 14:36:43 +01001900 c.set_lookup_index (lookup_index);
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001901 c.set_lookup_mask (lookups[table_index][i].mask);
1902 c.set_auto_zwj (lookups[table_index][i].auto_zwj);
Behdad Esfahbodcdf1fd02017-07-14 12:43:34 +01001903 c.set_auto_zwnj (lookups[table_index][i].auto_zwnj);
David Corbettc2a75e02018-01-25 14:22:03 -05001904 if (lookups[table_index][i].random)
1905 {
David Corbettb545e272018-02-23 12:22:32 -05001906 c.set_random (true);
David Corbettc2a75e02018-01-25 14:22:03 -05001907 buffer->unsafe_to_break_all ();
1908 }
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001909 apply_string<Proxy> (&c,
1910 proxy.table.get_lookup (lookup_index),
1911 proxy.accels[lookup_index]);
Behdad Esfahbod0475ef22015-12-18 18:17:07 +00001912 (void) buffer->message (font, "end lookup %d", lookup_index);
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001913 }
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001914
1915 if (stage->pause_func)
1916 {
1917 buffer->clear_output ();
1918 stage->pause_func (plan, font, buffer);
1919 }
1920 }
1921}
1922
1923void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
1924{
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001925 GSUBProxy proxy (font->face);
1926 apply (proxy, plan, font, buffer);
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001927}
1928
1929void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
1930{
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001931 GPOSProxy proxy (font->face);
1932 apply (proxy, plan, font, buffer);
1933}
1934
Behdad Esfahbodcdab20d2018-02-10 15:45:17 -06001935void
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001936hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001937 const OT::SubstLookup &lookup,
Behdad Esfahbod97e59132018-10-10 11:41:05 -04001938 const OT::hb_ot_layout_lookup_accelerator_t &accel)
Behdad Esfahbodbac1dd62013-05-02 18:52:24 -04001939{
Behdad Esfahbod45f3d982013-05-03 17:49:44 -04001940 apply_string<GSUBProxy> (c, lookup, accel);
Behdad Esfahbodd2c96812013-05-02 18:18:24 -04001941}
Ebrahim Byagowib8a78ce2018-11-03 22:28:30 +03301942
1943#if 0
Ebrahim Byagowib8a78ce2018-11-03 22:28:30 +03301944hb_bool_t
1945hb_ot_layout_get_baseline (hb_font_t *font,
1946 hb_ot_layout_baseline_t baseline,
1947 hb_direction_t direction,
1948 hb_tag_t script_tag,
1949 hb_tag_t language_tag,
1950 hb_position_t *coord /* OUT. May be NULL. */)
1951{
Behdad Esfahbodf0b0fd42019-06-18 14:40:24 -07001952 bool result = font->face->table.BASE->get_baseline (font, baseline, direction, script_tag,
1953 language_tag, coord);
Ebrahim Byagowib8a78ce2018-11-03 22:28:30 +03301954
1955 /* TODO: Simulate https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags#ideographic-em-box */
1956 if (!result && coord) *coord = 0;
1957
1958 if (coord) *coord = font->em_scale_dir (*coord, direction);
1959
1960 return result;
1961}
1962
1963/* To be moved to public header */
1964/*
1965 * BASE
1966 */
1967
1968/**
1969 * hb_ot_layout_baseline_t:
1970 *
1971 * https://docs.microsoft.com/en-us/typography/opentype/spec/baselinetags
1972 *
1973 * Since: DONTREPLACEME
1974 */
1975typedef enum {
1976 HB_OT_LAYOUT_BASELINE_HANG = HB_TAG('h','a','n','g'),
1977 HB_OT_LAYOUT_BASELINE_ICFB = HB_TAG('i','c','f','b'),
1978 HB_OT_LAYOUT_BASELINE_ICFT = HB_TAG('i','c','f','t'),
1979 HB_OT_LAYOUT_BASELINE_IDEO = HB_TAG('i','d','e','o'),
1980 HB_OT_LAYOUT_BASELINE_IDTB = HB_TAG('i','d','t','b'),
1981 HB_OT_LAYOUT_BASELINE_MATH = HB_TAG('m','a','t','h'),
Ebrahim Byagowi737eb852019-07-25 14:26:30 +04301982 HB_OT_LAYOUT_BASELINE_ROMN = HB_TAG('r','o','m','n'),
1983
Ebrahim Byagowi069872c2019-07-25 14:27:43 +04301984 _HB_OT_LAYOUT_BASELINE_MAX_VALUE = HB_TAG_MAX_SIGNED /*< skip >*/
Ebrahim Byagowib8a78ce2018-11-03 22:28:30 +03301985} hb_ot_layout_baseline_t;
1986
Nathan Willis930f6fc2019-03-16 15:10:21 +00001987
1988/**
1989 * hb_ot_layout_get_baseline:
1990 * @font: The #hb_font_t to work upon
1991 * @baseline: The #hb_ot_layout_baseline_t to query
Nathan Willisc08ddbd2019-03-24 15:07:07 +00001992 * @direction: The #hb_direction_t text direction to use (horizontal or vertical)
Nathan Willis930f6fc2019-03-16 15:10:21 +00001993 * @script_tag: #hb_tag_t of the script to use
1994 * @language_tag: #hb_tag_t of the language to use
Nathan Willis51228052019-03-17 14:43:06 +00001995 * @coord: (out): The position of the requested baseline
Nathan Willis930f6fc2019-03-16 15:10:21 +00001996 *
1997 * Fetches the coordinates of the specified baseline in the face, underneath
1998 * the specified script and language and in the specified text direction.
1999 *
2000 * Return value: true if the baseline is found for the settings queried, false otherwise
2001 *
2002 **/
Ebrahim Byagowib8a78ce2018-11-03 22:28:30 +03302003HB_EXTERN hb_bool_t
2004hb_ot_layout_get_baseline (hb_font_t *font,
2005 hb_ot_layout_baseline_t baseline,
2006 hb_direction_t direction,
2007 hb_tag_t script_tag,
2008 hb_tag_t language_tag,
2009 hb_position_t *coord /* OUT. May be NULL. */);
2010
2011#endif
Behdad Esfahbodbb4bbe62019-06-26 13:29:58 -07002012
2013
2014#endif