1 | /* |
2 | * Copyright © 1998-2004 David Turner and Werner Lemberg |
3 | * Copyright © 2006 Behdad Esfahbod |
4 | * Copyright © 2007,2008,2009 Red Hat, Inc. |
5 | * Copyright © 2012,2013 Google, Inc. |
6 | * |
7 | * This is part of HarfBuzz, a text shaping library. |
8 | * |
9 | * Permission is hereby granted, without written agreement and without |
10 | * license or royalty fees, to use, copy, modify, and distribute this |
11 | * software and its documentation for any purpose, provided that the |
12 | * above copyright notice and the following two paragraphs appear in |
13 | * all copies of this software. |
14 | * |
15 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
16 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
17 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
18 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
19 | * DAMAGE. |
20 | * |
21 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
22 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
23 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
24 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
25 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
26 | * |
27 | * Red Hat Author(s): Behdad Esfahbod |
28 | * Google Author(s): Behdad Esfahbod |
29 | */ |
30 | |
31 | #include "hb-open-type.hh" |
32 | #include "hb-ot-layout.hh" |
33 | #include "hb-ot-face.hh" |
34 | #include "hb-ot-map.hh" |
35 | #include "hb-map.hh" |
36 | |
37 | #include "hb-ot-layout-gdef-table.hh" |
38 | #include "hb-ot-layout-gsub-table.hh" |
39 | #include "hb-ot-layout-gpos-table.hh" |
40 | |
41 | // Just so we compile them; unused otherwise: |
42 | #include "hb-ot-layout-base-table.hh" |
43 | #include "hb-ot-layout-jstf-table.hh" |
44 | #include "hb-ot-color-colr-table.hh" |
45 | #include "hb-ot-color-cpal-table.hh" |
46 | #include "hb-ot-color-sbix-table.hh" |
47 | #include "hb-ot-color-svg-table.hh" |
48 | #include "hb-ot-name-table.hh" |
49 | |
50 | |
51 | // static inline const OT::BASE& |
52 | // _get_base (hb_face_t *face) |
53 | // { |
54 | // if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::BASE); |
55 | // hb_ot_face_data_t *data = hb_ot_face_data (face); |
56 | // return *(data->base.get ()); |
57 | // } |
58 | |
59 | const OT::GDEF& _get_gdef (hb_face_t *face) |
60 | { |
61 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GDEF); |
62 | return *hb_ot_face_data (face)->GDEF->table; |
63 | } |
64 | static hb_blob_t * _get_gsub_blob (hb_face_t *face) |
65 | { |
66 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); |
67 | return hb_ot_face_data (face)->GSUB->blob; |
68 | } |
69 | static inline const OT::GSUB& _get_gsub (hb_face_t *face) |
70 | { |
71 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GSUB); |
72 | return *hb_ot_face_data (face)->GSUB->table; |
73 | } |
74 | const OT::GSUB& _get_gsub_relaxed (hb_face_t *face) |
75 | { |
76 | return *hb_ot_face_data (face)->GSUB.get_relaxed ()->table; |
77 | } |
78 | static hb_blob_t * _get_gpos_blob (hb_face_t *face) |
79 | { |
80 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return hb_blob_get_empty (); |
81 | return hb_ot_face_data (face)->GPOS->blob; |
82 | } |
83 | static inline const OT::GPOS& _get_gpos (hb_face_t *face) |
84 | { |
85 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GPOS); |
86 | return *hb_ot_face_data (face)->GPOS->table; |
87 | } |
88 | const OT::GPOS& _get_gpos_relaxed (hb_face_t *face) |
89 | { |
90 | return *hb_ot_face_data (face)->GPOS.get_relaxed ()->table; |
91 | } |
92 | |
93 | |
94 | /* |
95 | * GDEF |
96 | */ |
97 | |
98 | static bool |
99 | _hb_ot_blacklist_gdef (unsigned int gdef_len, |
100 | unsigned int gsub_len, |
101 | unsigned int gpos_len) |
102 | { |
103 | /* The ugly business of blacklisting individual fonts' tables happen here! |
104 | * See this thread for why we finally had to bend in and do this: |
105 | * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html |
106 | * |
107 | * In certain versions of Times New Roman Italic and Bold Italic, |
108 | * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark) |
109 | * in GDEF. Many versions of Tahoma have bad GDEF tables that |
110 | * incorrectly classify some spacing marks such as certain IPA |
111 | * symbols as glyph class 3. So do older versions of Microsoft |
112 | * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04. |
113 | * |
114 | * Nuke the GDEF tables of to avoid unwanted width-zeroing. |
115 | * |
116 | * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 |
117 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693 |
118 | * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875 |
119 | */ |
120 | #define ENCODE(x,y,z) ((int64_t) (x) << 32 | (int64_t) (y) << 16 | (z)) |
121 | switch ENCODE(gdef_len, gsub_len, gpos_len) |
122 | { |
123 | /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */ |
124 | case ENCODE (442, 2874, 42038): |
125 | /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */ |
126 | case ENCODE (430, 2874, 40662): |
127 | /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */ |
128 | case ENCODE (442, 2874, 39116): |
129 | /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */ |
130 | case ENCODE (430, 2874, 39374): |
131 | /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */ |
132 | case ENCODE (490, 3046, 41638): |
133 | /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */ |
134 | case ENCODE (478, 3046, 41902): |
135 | /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */ |
136 | case ENCODE (898, 12554, 46470): |
137 | /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc tahomabd.ttf from Windows 8 */ |
138 | case ENCODE (910, 12566, 47732): |
139 | /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e tahoma.ttf from Windows 8.1 */ |
140 | case ENCODE (928, 23298, 59332): |
141 | /* sha1sum:6d400781948517c3c0441ba42acb309584b73033 tahomabd.ttf from Windows 8.1 */ |
142 | case ENCODE (940, 23310, 60732): |
143 | /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
144 | case ENCODE (964, 23836, 60072): |
145 | /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
146 | case ENCODE (976, 23832, 61456): |
147 | /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846 tahoma.ttf from Windows 10 */ |
148 | case ENCODE (994, 24474, 60336): |
149 | /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343 tahomabd.ttf from Windows 10 */ |
150 | case ENCODE (1006, 24470, 61740): |
151 | /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
152 | case ENCODE (1006, 24576, 61346): |
153 | /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */ |
154 | case ENCODE (1018, 24572, 62828): |
155 | /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5 tahoma.ttf from Windows 10 AU */ |
156 | case ENCODE (1006, 24576, 61352): |
157 | /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2 tahomabd.ttf from Windows 10 AU */ |
158 | case ENCODE (1018, 24572, 62834): |
159 | /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7 Tahoma.ttf from Mac OS X 10.9 */ |
160 | case ENCODE (832, 7324, 47162): |
161 | /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba Tahoma Bold.ttf from Mac OS X 10.9 */ |
162 | case ENCODE (844, 7302, 45474): |
163 | /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc himalaya.ttf from Windows 7 */ |
164 | case ENCODE (180, 13054, 7254): |
165 | /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0 himalaya.ttf from Windows 8 */ |
166 | case ENCODE (192, 12638, 7254): |
167 | /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427 himalaya.ttf from Windows 8.1 */ |
168 | case ENCODE (192, 12690, 7254): |
169 | /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44 cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */ |
170 | /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371 cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */ |
171 | case ENCODE (188, 248, 3852): |
172 | /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */ |
173 | /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */ |
174 | case ENCODE (188, 264, 3426): |
175 | /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */ |
176 | case ENCODE (1058, 47032, 11818): |
177 | /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/ |
178 | case ENCODE (1046, 47030, 12600): |
179 | /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */ |
180 | case ENCODE (1058, 71796, 16770): |
181 | /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */ |
182 | case ENCODE (1046, 71790, 17862): |
183 | /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */ |
184 | case ENCODE (1046, 71788, 17112): |
185 | /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */ |
186 | case ENCODE (1058, 71794, 17514): |
187 | /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */ |
188 | case ENCODE (1330, 109904, 57938): |
189 | /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */ |
190 | case ENCODE (1330, 109904, 58972): |
191 | /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85 Padauk.ttf |
192 | * "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */ |
193 | case ENCODE (1004, 59092, 14836): |
194 | return true; |
195 | #undef ENCODE |
196 | } |
197 | return false; |
198 | } |
199 | |
200 | inline void |
201 | OT::GDEF::accelerator_t::init (hb_face_t *face) |
202 | { |
203 | this->blob = hb_sanitize_context_t().reference_table<GDEF> (face); |
204 | |
205 | if (unlikely (_hb_ot_blacklist_gdef (this->blob->length, |
206 | _get_gsub_blob (face)->length, |
207 | _get_gpos_blob (face)->length))) |
208 | { |
209 | hb_blob_destroy (this->blob); |
210 | this->blob = hb_blob_get_empty (); |
211 | } |
212 | |
213 | table = this->blob->as<GDEF> (); |
214 | } |
215 | |
216 | static void |
217 | _hb_ot_layout_set_glyph_props (hb_font_t *font, |
218 | hb_buffer_t *buffer) |
219 | { |
220 | _hb_buffer_assert_gsubgpos_vars (buffer); |
221 | |
222 | const OT::GDEF &gdef = _get_gdef (font->face); |
223 | unsigned int count = buffer->len; |
224 | for (unsigned int i = 0; i < count; i++) |
225 | { |
226 | _hb_glyph_info_set_glyph_props (&buffer->info[i], gdef.get_glyph_props (buffer->info[i].codepoint)); |
227 | _hb_glyph_info_clear_lig_props (&buffer->info[i]); |
228 | buffer->info[i].syllable() = 0; |
229 | } |
230 | } |
231 | |
232 | /* Public API */ |
233 | |
234 | hb_bool_t |
235 | hb_ot_layout_has_glyph_classes (hb_face_t *face) |
236 | { |
237 | return _get_gdef (face).has_glyph_classes (); |
238 | } |
239 | |
240 | /** |
241 | * hb_ot_layout_get_glyph_class: |
242 | * |
243 | * Since: 0.9.7 |
244 | **/ |
245 | hb_ot_layout_glyph_class_t |
246 | hb_ot_layout_get_glyph_class (hb_face_t *face, |
247 | hb_codepoint_t glyph) |
248 | { |
249 | return (hb_ot_layout_glyph_class_t) _get_gdef (face).get_glyph_class (glyph); |
250 | } |
251 | |
252 | /** |
253 | * hb_ot_layout_get_glyphs_in_class: |
254 | * |
255 | * Since: 0.9.7 |
256 | **/ |
257 | void |
258 | hb_ot_layout_get_glyphs_in_class (hb_face_t *face, |
259 | hb_ot_layout_glyph_class_t klass, |
260 | hb_set_t *glyphs /* OUT */) |
261 | { |
262 | return _get_gdef (face).get_glyphs_in_class (klass, glyphs); |
263 | } |
264 | |
265 | unsigned int |
266 | hb_ot_layout_get_attach_points (hb_face_t *face, |
267 | hb_codepoint_t glyph, |
268 | unsigned int start_offset, |
269 | unsigned int *point_count /* IN/OUT */, |
270 | unsigned int *point_array /* OUT */) |
271 | { |
272 | return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, point_array); |
273 | } |
274 | |
275 | unsigned int |
276 | hb_ot_layout_get_ligature_carets (hb_font_t *font, |
277 | hb_direction_t direction, |
278 | hb_codepoint_t glyph, |
279 | unsigned int start_offset, |
280 | unsigned int *caret_count /* IN/OUT */, |
281 | hb_position_t *caret_array /* OUT */) |
282 | { |
283 | return _get_gdef (font->face).get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); |
284 | } |
285 | |
286 | |
287 | /* |
288 | * GSUB/GPOS |
289 | */ |
290 | |
291 | static const OT::GSUBGPOS& |
292 | get_gsubgpos_table (hb_face_t *face, |
293 | hb_tag_t table_tag) |
294 | { |
295 | switch (table_tag) { |
296 | case HB_OT_TAG_GSUB: return _get_gsub (face); |
297 | case HB_OT_TAG_GPOS: return _get_gpos (face); |
298 | default: return Null(OT::GSUBGPOS); |
299 | } |
300 | } |
301 | |
302 | |
303 | unsigned int |
304 | hb_ot_layout_table_get_script_tags (hb_face_t *face, |
305 | hb_tag_t table_tag, |
306 | unsigned int start_offset, |
307 | unsigned int *script_count /* IN/OUT */, |
308 | hb_tag_t *script_tags /* OUT */) |
309 | { |
310 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
311 | |
312 | return g.get_script_tags (start_offset, script_count, script_tags); |
313 | } |
314 | |
315 | #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
316 | |
317 | hb_bool_t |
318 | hb_ot_layout_table_find_script (hb_face_t *face, |
319 | hb_tag_t table_tag, |
320 | hb_tag_t script_tag, |
321 | unsigned int *script_index) |
322 | { |
323 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "" ); |
324 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
325 | |
326 | if (g.find_script_index (script_tag, script_index)) |
327 | return true; |
328 | |
329 | /* try finding 'DFLT' */ |
330 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) |
331 | return false; |
332 | |
333 | /* try with 'dflt'; MS site has had typos and many fonts use it now :(. |
334 | * including many versions of DejaVu Sans Mono! */ |
335 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) |
336 | return false; |
337 | |
338 | /* try with 'latn'; some old fonts put their features there even though |
339 | they're really trying to support Thai, for example :( */ |
340 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) |
341 | return false; |
342 | |
343 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
344 | return false; |
345 | } |
346 | |
347 | hb_bool_t |
348 | hb_ot_layout_table_choose_script (hb_face_t *face, |
349 | hb_tag_t table_tag, |
350 | const hb_tag_t *script_tags, |
351 | unsigned int *script_index, |
352 | hb_tag_t *chosen_script) |
353 | { |
354 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "" ); |
355 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
356 | |
357 | while (*script_tags) |
358 | { |
359 | if (g.find_script_index (*script_tags, script_index)) { |
360 | if (chosen_script) |
361 | *chosen_script = *script_tags; |
362 | return true; |
363 | } |
364 | script_tags++; |
365 | } |
366 | |
367 | /* try finding 'DFLT' */ |
368 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
369 | if (chosen_script) |
370 | *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
371 | return false; |
372 | } |
373 | |
374 | /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
375 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { |
376 | if (chosen_script) |
377 | *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
378 | return false; |
379 | } |
380 | |
381 | /* try with 'latn'; some old fonts put their features there even though |
382 | they're really trying to support Thai, for example :( */ |
383 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { |
384 | if (chosen_script) |
385 | *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
386 | return false; |
387 | } |
388 | |
389 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
390 | if (chosen_script) |
391 | *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
392 | return false; |
393 | } |
394 | |
395 | unsigned int |
396 | hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
397 | hb_tag_t table_tag, |
398 | unsigned int start_offset, |
399 | unsigned int *feature_count /* IN/OUT */, |
400 | hb_tag_t *feature_tags /* OUT */) |
401 | { |
402 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
403 | |
404 | return g.get_feature_tags (start_offset, feature_count, feature_tags); |
405 | } |
406 | |
407 | hb_bool_t |
408 | hb_ot_layout_table_find_feature (hb_face_t *face, |
409 | hb_tag_t table_tag, |
410 | hb_tag_t feature_tag, |
411 | unsigned int *feature_index) |
412 | { |
413 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "" ); |
414 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
415 | |
416 | unsigned int num_features = g.get_feature_count (); |
417 | for (unsigned int i = 0; i < num_features; i++) |
418 | { |
419 | if (feature_tag == g.get_feature_tag (i)) { |
420 | if (feature_index) *feature_index = i; |
421 | return true; |
422 | } |
423 | } |
424 | |
425 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
426 | return false; |
427 | } |
428 | |
429 | |
430 | unsigned int |
431 | hb_ot_layout_script_get_language_tags (hb_face_t *face, |
432 | hb_tag_t table_tag, |
433 | unsigned int script_index, |
434 | unsigned int start_offset, |
435 | unsigned int *language_count /* IN/OUT */, |
436 | hb_tag_t *language_tags /* OUT */) |
437 | { |
438 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
439 | |
440 | return s.get_lang_sys_tags (start_offset, language_count, language_tags); |
441 | } |
442 | |
443 | hb_bool_t |
444 | hb_ot_layout_script_find_language (hb_face_t *face, |
445 | hb_tag_t table_tag, |
446 | unsigned int script_index, |
447 | hb_tag_t language_tag, |
448 | unsigned int *language_index) |
449 | { |
450 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), "" ); |
451 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
452 | |
453 | if (s.find_lang_sys_index (language_tag, language_index)) |
454 | return true; |
455 | |
456 | /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
457 | if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index)) |
458 | return false; |
459 | |
460 | if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
461 | return false; |
462 | } |
463 | |
464 | hb_bool_t |
465 | hb_ot_layout_language_get_required_feature_index (hb_face_t *face, |
466 | hb_tag_t table_tag, |
467 | unsigned int script_index, |
468 | unsigned int language_index, |
469 | unsigned int *feature_index) |
470 | { |
471 | return hb_ot_layout_language_get_required_feature (face, |
472 | table_tag, |
473 | script_index, |
474 | language_index, |
475 | feature_index, |
476 | nullptr); |
477 | } |
478 | |
479 | /** |
480 | * hb_ot_layout_language_get_required_feature: |
481 | * |
482 | * Since: 0.9.30 |
483 | **/ |
484 | hb_bool_t |
485 | hb_ot_layout_language_get_required_feature (hb_face_t *face, |
486 | hb_tag_t table_tag, |
487 | unsigned int script_index, |
488 | unsigned int language_index, |
489 | unsigned int *feature_index, |
490 | hb_tag_t *feature_tag) |
491 | { |
492 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
493 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
494 | |
495 | unsigned int index = l.get_required_feature_index (); |
496 | if (feature_index) *feature_index = index; |
497 | if (feature_tag) *feature_tag = g.get_feature_tag (index); |
498 | |
499 | return l.has_required_feature (); |
500 | } |
501 | |
502 | static void |
503 | _hb_ot_layout_language_add_feature_indexes_to (hb_face_t *face, |
504 | hb_tag_t table_tag, |
505 | unsigned int script_index, |
506 | unsigned int language_index, |
507 | hb_set_t *feature_indexes /* OUT */) |
508 | { |
509 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
510 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
511 | l.add_feature_indexes_to (feature_indexes); |
512 | } |
513 | |
514 | |
515 | unsigned int |
516 | hb_ot_layout_language_get_feature_indexes (hb_face_t *face, |
517 | hb_tag_t table_tag, |
518 | unsigned int script_index, |
519 | unsigned int language_index, |
520 | unsigned int start_offset, |
521 | unsigned int *feature_count /* IN/OUT */, |
522 | unsigned int *feature_indexes /* OUT */) |
523 | { |
524 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
525 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
526 | |
527 | return l.get_feature_indexes (start_offset, feature_count, feature_indexes); |
528 | } |
529 | |
530 | unsigned int |
531 | hb_ot_layout_language_get_feature_tags (hb_face_t *face, |
532 | hb_tag_t table_tag, |
533 | unsigned int script_index, |
534 | unsigned int language_index, |
535 | unsigned int start_offset, |
536 | unsigned int *feature_count /* IN/OUT */, |
537 | hb_tag_t *feature_tags /* OUT */) |
538 | { |
539 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
540 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
541 | |
542 | static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), "" ); |
543 | unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags); |
544 | |
545 | if (feature_tags) { |
546 | unsigned int count = *feature_count; |
547 | for (unsigned int i = 0; i < count; i++) |
548 | feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); |
549 | } |
550 | |
551 | return ret; |
552 | } |
553 | |
554 | |
555 | hb_bool_t |
556 | hb_ot_layout_language_find_feature (hb_face_t *face, |
557 | hb_tag_t table_tag, |
558 | unsigned int script_index, |
559 | unsigned int language_index, |
560 | hb_tag_t feature_tag, |
561 | unsigned int *feature_index) |
562 | { |
563 | static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "" ); |
564 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
565 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
566 | |
567 | unsigned int num_features = l.get_feature_count (); |
568 | for (unsigned int i = 0; i < num_features; i++) { |
569 | unsigned int f_index = l.get_feature_index (i); |
570 | |
571 | if (feature_tag == g.get_feature_tag (f_index)) { |
572 | if (feature_index) *feature_index = f_index; |
573 | return true; |
574 | } |
575 | } |
576 | |
577 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
578 | return false; |
579 | } |
580 | |
581 | /** |
582 | * hb_ot_layout_feature_get_lookups: |
583 | * |
584 | * Since: 0.9.7 |
585 | **/ |
586 | unsigned int |
587 | hb_ot_layout_feature_get_lookups (hb_face_t *face, |
588 | hb_tag_t table_tag, |
589 | unsigned int feature_index, |
590 | unsigned int start_offset, |
591 | unsigned int *lookup_count /* IN/OUT */, |
592 | unsigned int *lookup_indexes /* OUT */) |
593 | { |
594 | return hb_ot_layout_feature_with_variations_get_lookups (face, |
595 | table_tag, |
596 | feature_index, |
597 | HB_OT_LAYOUT_NO_VARIATIONS_INDEX, |
598 | start_offset, |
599 | lookup_count, |
600 | lookup_indexes); |
601 | } |
602 | |
603 | /** |
604 | * hb_ot_layout_table_get_lookup_count: |
605 | * |
606 | * Since: 0.9.22 |
607 | **/ |
608 | unsigned int |
609 | hb_ot_layout_table_get_lookup_count (hb_face_t *face, |
610 | hb_tag_t table_tag) |
611 | { |
612 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return 0; |
613 | switch (table_tag) |
614 | { |
615 | case HB_OT_TAG_GSUB: |
616 | { |
617 | return hb_ot_face_data (face)->GSUB->lookup_count; |
618 | } |
619 | case HB_OT_TAG_GPOS: |
620 | { |
621 | return hb_ot_face_data (face)->GPOS->lookup_count; |
622 | } |
623 | } |
624 | return 0; |
625 | } |
626 | |
627 | static void |
628 | _hb_ot_layout_collect_lookups_lookups (hb_face_t *face, |
629 | hb_tag_t table_tag, |
630 | unsigned int feature_index, |
631 | hb_set_t *lookup_indexes /* OUT */) |
632 | { |
633 | unsigned int lookup_indices[32]; |
634 | unsigned int offset, len; |
635 | |
636 | offset = 0; |
637 | do { |
638 | len = ARRAY_LENGTH (lookup_indices); |
639 | hb_ot_layout_feature_get_lookups (face, |
640 | table_tag, |
641 | feature_index, |
642 | offset, &len, |
643 | lookup_indices); |
644 | |
645 | for (unsigned int i = 0; i < len; i++) |
646 | lookup_indexes->add (lookup_indices[i]); |
647 | |
648 | offset += len; |
649 | } while (len == ARRAY_LENGTH (lookup_indices)); |
650 | } |
651 | |
652 | static void |
653 | _hb_ot_layout_collect_features_features (hb_face_t *face, |
654 | hb_tag_t table_tag, |
655 | unsigned int script_index, |
656 | unsigned int language_index, |
657 | const hb_tag_t *features, |
658 | hb_set_t *feature_indexes /* OUT */) |
659 | { |
660 | if (!features) |
661 | { |
662 | unsigned int required_feature_index; |
663 | if (hb_ot_layout_language_get_required_feature (face, |
664 | table_tag, |
665 | script_index, |
666 | language_index, |
667 | &required_feature_index, |
668 | nullptr)) |
669 | feature_indexes->add (required_feature_index); |
670 | |
671 | /* All features */ |
672 | _hb_ot_layout_language_add_feature_indexes_to (face, |
673 | table_tag, |
674 | script_index, |
675 | language_index, |
676 | feature_indexes); |
677 | } |
678 | else |
679 | { |
680 | for (; *features; features++) |
681 | { |
682 | unsigned int feature_index; |
683 | if (hb_ot_layout_language_find_feature (face, |
684 | table_tag, |
685 | script_index, |
686 | language_index, |
687 | *features, |
688 | &feature_index)) |
689 | feature_indexes->add (feature_index); |
690 | } |
691 | } |
692 | } |
693 | |
694 | static void |
695 | _hb_ot_layout_collect_features_languages (hb_face_t *face, |
696 | hb_tag_t table_tag, |
697 | unsigned int script_index, |
698 | const hb_tag_t *languages, |
699 | const hb_tag_t *features, |
700 | hb_set_t *feature_indexes /* OUT */) |
701 | { |
702 | _hb_ot_layout_collect_features_features (face, |
703 | table_tag, |
704 | script_index, |
705 | HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX, |
706 | features, |
707 | feature_indexes); |
708 | |
709 | if (!languages) |
710 | { |
711 | /* All languages */ |
712 | unsigned int count = hb_ot_layout_script_get_language_tags (face, |
713 | table_tag, |
714 | script_index, |
715 | 0, nullptr, nullptr); |
716 | for (unsigned int language_index = 0; language_index < count; language_index++) |
717 | _hb_ot_layout_collect_features_features (face, |
718 | table_tag, |
719 | script_index, |
720 | language_index, |
721 | features, |
722 | feature_indexes); |
723 | } |
724 | else |
725 | { |
726 | for (; *languages; languages++) |
727 | { |
728 | unsigned int language_index; |
729 | if (hb_ot_layout_script_find_language (face, |
730 | table_tag, |
731 | script_index, |
732 | *languages, |
733 | &language_index)) |
734 | _hb_ot_layout_collect_features_features (face, |
735 | table_tag, |
736 | script_index, |
737 | language_index, |
738 | features, |
739 | feature_indexes); |
740 | } |
741 | } |
742 | } |
743 | |
744 | /** |
745 | * hb_ot_layout_collect_features: |
746 | * |
747 | * Since: 1.8.5 |
748 | **/ |
749 | void |
750 | hb_ot_layout_collect_features (hb_face_t *face, |
751 | hb_tag_t table_tag, |
752 | const hb_tag_t *scripts, |
753 | const hb_tag_t *languages, |
754 | const hb_tag_t *features, |
755 | hb_set_t *feature_indexes /* OUT */) |
756 | { |
757 | if (!scripts) |
758 | { |
759 | /* All scripts */ |
760 | unsigned int count = hb_ot_layout_table_get_script_tags (face, |
761 | table_tag, |
762 | 0, nullptr, nullptr); |
763 | for (unsigned int script_index = 0; script_index < count; script_index++) |
764 | _hb_ot_layout_collect_features_languages (face, |
765 | table_tag, |
766 | script_index, |
767 | languages, |
768 | features, |
769 | feature_indexes); |
770 | } |
771 | else |
772 | { |
773 | for (; *scripts; scripts++) |
774 | { |
775 | unsigned int script_index; |
776 | if (hb_ot_layout_table_find_script (face, |
777 | table_tag, |
778 | *scripts, |
779 | &script_index)) |
780 | _hb_ot_layout_collect_features_languages (face, |
781 | table_tag, |
782 | script_index, |
783 | languages, |
784 | features, |
785 | feature_indexes); |
786 | } |
787 | } |
788 | } |
789 | |
790 | /** |
791 | * hb_ot_layout_collect_lookups: |
792 | * |
793 | * Since: 0.9.8 |
794 | **/ |
795 | void |
796 | hb_ot_layout_collect_lookups (hb_face_t *face, |
797 | hb_tag_t table_tag, |
798 | const hb_tag_t *scripts, |
799 | const hb_tag_t *languages, |
800 | const hb_tag_t *features, |
801 | hb_set_t *lookup_indexes /* OUT */) |
802 | { |
803 | hb_auto_t<hb_set_t> feature_indexes; |
804 | hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes); |
805 | for (hb_codepoint_t feature_index = HB_SET_VALUE_INVALID; hb_set_next (&feature_indexes, &feature_index);) |
806 | _hb_ot_layout_collect_lookups_lookups (face, table_tag, feature_index, lookup_indexes); |
807 | } |
808 | |
809 | /** |
810 | * hb_ot_layout_lookup_collect_glyphs: |
811 | * |
812 | * Since: 0.9.7 |
813 | **/ |
814 | void |
815 | hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, |
816 | hb_tag_t table_tag, |
817 | unsigned int lookup_index, |
818 | hb_set_t *glyphs_before, /* OUT. May be nullptr */ |
819 | hb_set_t *glyphs_input, /* OUT. May be nullptr */ |
820 | hb_set_t *glyphs_after, /* OUT. May be nullptr */ |
821 | hb_set_t *glyphs_output /* OUT. May be nullptr */) |
822 | { |
823 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; |
824 | |
825 | OT::hb_collect_glyphs_context_t c (face, |
826 | glyphs_before, |
827 | glyphs_input, |
828 | glyphs_after, |
829 | glyphs_output); |
830 | |
831 | switch (table_tag) |
832 | { |
833 | case HB_OT_TAG_GSUB: |
834 | { |
835 | const OT::SubstLookup& l = hb_ot_face_data (face)->GSUB->table->get_lookup (lookup_index); |
836 | l.collect_glyphs (&c); |
837 | return; |
838 | } |
839 | case HB_OT_TAG_GPOS: |
840 | { |
841 | const OT::PosLookup& l = hb_ot_face_data (face)->GPOS->table->get_lookup (lookup_index); |
842 | l.collect_glyphs (&c); |
843 | return; |
844 | } |
845 | } |
846 | } |
847 | |
848 | |
849 | /* Variations support */ |
850 | |
851 | hb_bool_t |
852 | hb_ot_layout_table_find_feature_variations (hb_face_t *face, |
853 | hb_tag_t table_tag, |
854 | const int *coords, |
855 | unsigned int num_coords, |
856 | unsigned int *variations_index /* out */) |
857 | { |
858 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
859 | |
860 | return g.find_variations_index (coords, num_coords, variations_index); |
861 | } |
862 | |
863 | unsigned int |
864 | hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, |
865 | hb_tag_t table_tag, |
866 | unsigned int feature_index, |
867 | unsigned int variations_index, |
868 | unsigned int start_offset, |
869 | unsigned int *lookup_count /* IN/OUT */, |
870 | unsigned int *lookup_indexes /* OUT */) |
871 | { |
872 | static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "" ); |
873 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
874 | |
875 | const OT::Feature &f = g.get_feature_variation (feature_index, variations_index); |
876 | |
877 | return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); |
878 | } |
879 | |
880 | |
881 | /* |
882 | * OT::GSUB |
883 | */ |
884 | |
885 | hb_bool_t |
886 | hb_ot_layout_has_substitution (hb_face_t *face) |
887 | { |
888 | return _get_gsub (face).has_data (); |
889 | } |
890 | |
891 | /** |
892 | * hb_ot_layout_lookup_would_substitute: |
893 | * |
894 | * Since: 0.9.7 |
895 | **/ |
896 | hb_bool_t |
897 | hb_ot_layout_lookup_would_substitute (hb_face_t *face, |
898 | unsigned int lookup_index, |
899 | const hb_codepoint_t *glyphs, |
900 | unsigned int glyphs_length, |
901 | hb_bool_t zero_context) |
902 | { |
903 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; |
904 | return hb_ot_layout_lookup_would_substitute_fast (face, lookup_index, glyphs, glyphs_length, zero_context); |
905 | } |
906 | |
907 | hb_bool_t |
908 | hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, |
909 | unsigned int lookup_index, |
910 | const hb_codepoint_t *glyphs, |
911 | unsigned int glyphs_length, |
912 | hb_bool_t zero_context) |
913 | { |
914 | if (unlikely (lookup_index >= hb_ot_face_data (face)->GSUB->lookup_count)) return false; |
915 | OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context); |
916 | |
917 | const OT::SubstLookup& l = hb_ot_face_data (face)->GSUB->table->get_lookup (lookup_index); |
918 | |
919 | return l.would_apply (&c, &hb_ot_face_data (face)->GSUB->accels[lookup_index]); |
920 | } |
921 | |
922 | void |
923 | hb_ot_layout_substitute_start (hb_font_t *font, |
924 | hb_buffer_t *buffer) |
925 | { |
926 | _hb_ot_layout_set_glyph_props (font, buffer); |
927 | } |
928 | |
929 | /** |
930 | * hb_ot_layout_lookup_substitute_closure: |
931 | * |
932 | * Since: 0.9.7 |
933 | **/ |
934 | void |
935 | hb_ot_layout_lookup_substitute_closure (hb_face_t *face, |
936 | unsigned int lookup_index, |
937 | hb_set_t *glyphs) |
938 | { |
939 | hb_auto_t<hb_map_t> done_lookups; |
940 | OT::hb_closure_context_t c (face, glyphs, &done_lookups); |
941 | |
942 | const OT::SubstLookup& l = _get_gsub (face).get_lookup (lookup_index); |
943 | |
944 | l.closure (&c, lookup_index); |
945 | } |
946 | |
947 | /** |
948 | * hb_ot_layout_lookups_substitute_closure: |
949 | * |
950 | * Compute the transitive closure of glyphs needed for all of the |
951 | * provided lookups. |
952 | * |
953 | * Since: 1.8.1 |
954 | **/ |
955 | void |
956 | hb_ot_layout_lookups_substitute_closure (hb_face_t *face, |
957 | const hb_set_t *lookups, |
958 | hb_set_t *glyphs) |
959 | { |
960 | hb_auto_t<hb_map_t> done_lookups; |
961 | OT::hb_closure_context_t c (face, glyphs, &done_lookups); |
962 | const OT::GSUB& gsub = _get_gsub (face); |
963 | |
964 | unsigned int iteration_count = 0; |
965 | unsigned int glyphs_length; |
966 | do |
967 | { |
968 | glyphs_length = glyphs->get_population (); |
969 | if (lookups != nullptr) |
970 | { |
971 | for (hb_codepoint_t lookup_index = HB_SET_VALUE_INVALID; hb_set_next (lookups, &lookup_index);) |
972 | gsub.get_lookup (lookup_index).closure (&c, lookup_index); |
973 | } |
974 | else |
975 | { |
976 | for (unsigned int i = 0; i < gsub.get_lookup_count (); i++) |
977 | gsub.get_lookup (i).closure (&c, i); |
978 | } |
979 | iteration_count++; |
980 | } while (iteration_count <= HB_CLOSURE_MAX_STAGES |
981 | && glyphs_length != glyphs->get_population ()); |
982 | } |
983 | |
984 | /* |
985 | * OT::GPOS |
986 | */ |
987 | |
988 | hb_bool_t |
989 | hb_ot_layout_has_positioning (hb_face_t *face) |
990 | { |
991 | return _get_gpos (face).has_data (); |
992 | } |
993 | |
994 | void |
995 | hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer) |
996 | { |
997 | OT::GPOS::position_start (font, buffer); |
998 | } |
999 | |
1000 | void |
1001 | hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer) |
1002 | { |
1003 | OT::GPOS::position_finish_advances (font, buffer); |
1004 | } |
1005 | |
1006 | void |
1007 | hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer) |
1008 | { |
1009 | OT::GPOS::position_finish_offsets (font, buffer); |
1010 | } |
1011 | |
1012 | /** |
1013 | * hb_ot_layout_get_size_params: |
1014 | * |
1015 | * Since: 0.9.10 |
1016 | **/ |
1017 | hb_bool_t |
1018 | hb_ot_layout_get_size_params (hb_face_t *face, |
1019 | unsigned int *design_size, /* OUT. May be nullptr */ |
1020 | unsigned int *subfamily_id, /* OUT. May be nullptr */ |
1021 | unsigned int *subfamily_name_id, /* OUT. May be nullptr */ |
1022 | unsigned int *range_start, /* OUT. May be nullptr */ |
1023 | unsigned int *range_end /* OUT. May be nullptr */) |
1024 | { |
1025 | const OT::GPOS &gpos = _get_gpos (face); |
1026 | const hb_tag_t tag = HB_TAG ('s','i','z','e'); |
1027 | |
1028 | unsigned int num_features = gpos.get_feature_count (); |
1029 | for (unsigned int i = 0; i < num_features; i++) |
1030 | { |
1031 | if (tag == gpos.get_feature_tag (i)) |
1032 | { |
1033 | const OT::Feature &f = gpos.get_feature (i); |
1034 | const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag); |
1035 | |
1036 | if (params.designSize) |
1037 | { |
1038 | #define PARAM(a, A) if (a) *a = params.A |
1039 | PARAM (design_size, designSize); |
1040 | PARAM (subfamily_id, subfamilyID); |
1041 | PARAM (subfamily_name_id, subfamilyNameID); |
1042 | PARAM (range_start, rangeStart); |
1043 | PARAM (range_end, rangeEnd); |
1044 | #undef PARAM |
1045 | |
1046 | return true; |
1047 | } |
1048 | } |
1049 | } |
1050 | |
1051 | #define PARAM(a, A) if (a) *a = 0 |
1052 | PARAM (design_size, designSize); |
1053 | PARAM (subfamily_id, subfamilyID); |
1054 | PARAM (subfamily_name_id, subfamilyNameID); |
1055 | PARAM (range_start, rangeStart); |
1056 | PARAM (range_end, rangeEnd); |
1057 | #undef PARAM |
1058 | |
1059 | return false; |
1060 | } |
1061 | |
1062 | |
1063 | /* |
1064 | * Parts of different types are implemented here such that they have direct |
1065 | * access to GSUB/GPOS lookups. |
1066 | */ |
1067 | |
1068 | |
1069 | struct GSUBProxy |
1070 | { |
1071 | enum { table_index = 0 }; |
1072 | static const bool inplace = false; |
1073 | typedef OT::SubstLookup Lookup; |
1074 | |
1075 | GSUBProxy (hb_face_t *face) : |
1076 | table (*hb_ot_face_data (face)->GSUB->table), |
1077 | accels (hb_ot_face_data (face)->GSUB->accels) {} |
1078 | |
1079 | const OT::GSUB &table; |
1080 | const hb_ot_layout_lookup_accelerator_t *accels; |
1081 | }; |
1082 | |
1083 | struct GPOSProxy |
1084 | { |
1085 | enum { table_index = 1 }; |
1086 | static const bool inplace = true; |
1087 | typedef OT::PosLookup Lookup; |
1088 | |
1089 | GPOSProxy (hb_face_t *face) : |
1090 | table (*hb_ot_face_data (face)->GPOS->table), |
1091 | accels (hb_ot_face_data (face)->GPOS->accels) {} |
1092 | |
1093 | const OT::GPOS &table; |
1094 | const hb_ot_layout_lookup_accelerator_t *accels; |
1095 | }; |
1096 | |
1097 | |
1098 | struct hb_get_subtables_context_t : |
1099 | hb_dispatch_context_t<hb_get_subtables_context_t, hb_void_t, HB_DEBUG_APPLY> |
1100 | { |
1101 | template <typename Type> |
1102 | static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c) |
1103 | { |
1104 | const Type *typed_obj = (const Type *) obj; |
1105 | return typed_obj->apply (c); |
1106 | } |
1107 | |
1108 | typedef bool (*hb_apply_func_t) (const void *obj, OT::hb_ot_apply_context_t *c); |
1109 | |
1110 | struct hb_applicable_t |
1111 | { |
1112 | inline void init (const void *obj_, hb_apply_func_t apply_func_) |
1113 | { |
1114 | obj = obj_; |
1115 | apply_func = apply_func_; |
1116 | } |
1117 | |
1118 | inline bool apply (OT::hb_ot_apply_context_t *c) const { return apply_func (obj, c); } |
1119 | |
1120 | private: |
1121 | const void *obj; |
1122 | hb_apply_func_t apply_func; |
1123 | }; |
1124 | |
1125 | typedef hb_auto_t<hb_vector_t<hb_applicable_t> > array_t; |
1126 | |
1127 | /* Dispatch interface. */ |
1128 | inline const char *get_name (void) { return "GET_SUBTABLES" ; } |
1129 | template <typename T> |
1130 | inline return_t dispatch (const T &obj) |
1131 | { |
1132 | hb_applicable_t *entry = array.push(); |
1133 | entry->init (&obj, apply_to<T>); |
1134 | return HB_VOID; |
1135 | } |
1136 | static return_t default_return_value (void) { return HB_VOID; } |
1137 | bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; } |
1138 | |
1139 | hb_get_subtables_context_t (array_t &array_) : |
1140 | array (array_), |
1141 | debug_depth (0) {} |
1142 | |
1143 | array_t &array; |
1144 | unsigned int debug_depth; |
1145 | }; |
1146 | |
1147 | static inline bool |
1148 | apply_forward (OT::hb_ot_apply_context_t *c, |
1149 | const hb_ot_layout_lookup_accelerator_t &accel, |
1150 | const hb_get_subtables_context_t::array_t &subtables) |
1151 | { |
1152 | bool ret = false; |
1153 | hb_buffer_t *buffer = c->buffer; |
1154 | while (buffer->idx < buffer->len && buffer->successful) |
1155 | { |
1156 | bool applied = false; |
1157 | if (accel.may_have (buffer->cur().codepoint) && |
1158 | (buffer->cur().mask & c->lookup_mask) && |
1159 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
1160 | { |
1161 | for (unsigned int i = 0; i < subtables.len; i++) |
1162 | if (subtables[i].apply (c)) |
1163 | { |
1164 | applied = true; |
1165 | break; |
1166 | } |
1167 | } |
1168 | |
1169 | if (applied) |
1170 | ret = true; |
1171 | else |
1172 | buffer->next_glyph (); |
1173 | } |
1174 | return ret; |
1175 | } |
1176 | |
1177 | static inline bool |
1178 | apply_backward (OT::hb_ot_apply_context_t *c, |
1179 | const hb_ot_layout_lookup_accelerator_t &accel, |
1180 | const hb_get_subtables_context_t::array_t &subtables) |
1181 | { |
1182 | bool ret = false; |
1183 | hb_buffer_t *buffer = c->buffer; |
1184 | do |
1185 | { |
1186 | if (accel.may_have (buffer->cur().codepoint) && |
1187 | (buffer->cur().mask & c->lookup_mask) && |
1188 | c->check_glyph_property (&buffer->cur(), c->lookup_props)) |
1189 | { |
1190 | for (unsigned int i = 0; i < subtables.len; i++) |
1191 | if (subtables[i].apply (c)) |
1192 | { |
1193 | ret = true; |
1194 | break; |
1195 | } |
1196 | } |
1197 | /* The reverse lookup doesn't "advance" cursor (for good reason). */ |
1198 | buffer->idx--; |
1199 | |
1200 | } |
1201 | while ((int) buffer->idx >= 0); |
1202 | return ret; |
1203 | } |
1204 | |
1205 | template <typename Proxy> |
1206 | static inline void |
1207 | apply_string (OT::hb_ot_apply_context_t *c, |
1208 | const typename Proxy::Lookup &lookup, |
1209 | const hb_ot_layout_lookup_accelerator_t &accel) |
1210 | { |
1211 | hb_buffer_t *buffer = c->buffer; |
1212 | |
1213 | if (unlikely (!buffer->len || !c->lookup_mask)) |
1214 | return; |
1215 | |
1216 | c->set_lookup_props (lookup.get_props ()); |
1217 | |
1218 | hb_get_subtables_context_t::array_t subtables; |
1219 | hb_get_subtables_context_t c_get_subtables (subtables); |
1220 | lookup.dispatch (&c_get_subtables); |
1221 | |
1222 | if (likely (!lookup.is_reverse ())) |
1223 | { |
1224 | /* in/out forward substitution/positioning */ |
1225 | if (Proxy::table_index == 0) |
1226 | buffer->clear_output (); |
1227 | buffer->idx = 0; |
1228 | |
1229 | bool ret; |
1230 | ret = apply_forward (c, accel, subtables); |
1231 | if (ret) |
1232 | { |
1233 | if (!Proxy::inplace) |
1234 | buffer->swap_buffers (); |
1235 | else |
1236 | assert (!buffer->has_separate_output ()); |
1237 | } |
1238 | } |
1239 | else |
1240 | { |
1241 | /* in-place backward substitution/positioning */ |
1242 | if (Proxy::table_index == 0) |
1243 | buffer->remove_output (); |
1244 | buffer->idx = buffer->len - 1; |
1245 | |
1246 | apply_backward (c, accel, subtables); |
1247 | } |
1248 | } |
1249 | |
1250 | template <typename Proxy> |
1251 | inline void hb_ot_map_t::apply (const Proxy &proxy, |
1252 | const hb_ot_shape_plan_t *plan, |
1253 | hb_font_t *font, |
1254 | hb_buffer_t *buffer) const |
1255 | { |
1256 | const unsigned int table_index = proxy.table_index; |
1257 | unsigned int i = 0; |
1258 | OT::hb_ot_apply_context_t c (table_index, font, buffer); |
1259 | c.set_recurse_func (Proxy::Lookup::apply_recurse_func); |
1260 | |
1261 | for (unsigned int stage_index = 0; stage_index < stages[table_index].len; stage_index++) { |
1262 | const stage_map_t *stage = &stages[table_index][stage_index]; |
1263 | for (; i < stage->last_lookup; i++) |
1264 | { |
1265 | unsigned int lookup_index = lookups[table_index][i].index; |
1266 | if (!buffer->message (font, "start lookup %d" , lookup_index)) continue; |
1267 | c.set_lookup_index (lookup_index); |
1268 | c.set_lookup_mask (lookups[table_index][i].mask); |
1269 | c.set_auto_zwj (lookups[table_index][i].auto_zwj); |
1270 | c.set_auto_zwnj (lookups[table_index][i].auto_zwnj); |
1271 | apply_string<Proxy> (&c, |
1272 | proxy.table.get_lookup (lookup_index), |
1273 | proxy.accels[lookup_index]); |
1274 | (void) buffer->message (font, "end lookup %d" , lookup_index); |
1275 | } |
1276 | |
1277 | if (stage->pause_func) |
1278 | { |
1279 | buffer->clear_output (); |
1280 | stage->pause_func (plan, font, buffer); |
1281 | } |
1282 | } |
1283 | } |
1284 | |
1285 | void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
1286 | { |
1287 | GSUBProxy proxy (font->face); |
1288 | apply (proxy, plan, font, buffer); |
1289 | } |
1290 | |
1291 | void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const |
1292 | { |
1293 | GPOSProxy proxy (font->face); |
1294 | apply (proxy, plan, font, buffer); |
1295 | } |
1296 | |
1297 | void |
1298 | hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, |
1299 | const OT::SubstLookup &lookup, |
1300 | const hb_ot_layout_lookup_accelerator_t &accel) |
1301 | { |
1302 | apply_string<GSUBProxy> (c, lookup, accel); |
1303 | } |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | /* |
1309 | * OT::BASE |
1310 | */ |
1311 | |
1312 | // /** |
1313 | // * hb_ot_base_has_data: |
1314 | // * @face: #hb_face_t to test |
1315 | // * |
1316 | // * This function allows to verify the presence of an OpenType BASE table on the |
1317 | // * face. |
1318 | // * |
1319 | // * Return value: true if face has a BASE table, false otherwise |
1320 | // * |
1321 | // * Since: XXX |
1322 | // **/ |
1323 | // hb_bool_t |
1324 | // hb_ot_base_has_data (hb_face_t *face) |
1325 | // { |
1326 | // return _get_base (face).has_data (); |
1327 | // } |
1328 | |