Coverage Report

Created: 2025-07-11 06:34

/src/harfbuzz/src/hb-ot-layout.cc
Line
Count
Source (jump to first uncovered line)
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.hh"
32
33
#ifndef HB_NO_OT_LAYOUT
34
35
#ifdef HB_NO_OT_TAG
36
#error "Cannot compile hb-ot-layout.cc with HB_NO_OT_TAG."
37
#endif
38
39
#include "hb-open-type.hh"
40
#include "hb-ot-layout.hh"
41
#include "hb-ot-face.hh"
42
#include "hb-ot-map.hh"
43
#include "hb-map.hh"
44
45
#include "hb-ot-kern-table.hh"
46
#include "hb-ot-layout-gdef-table.hh"
47
#include "hb-ot-layout-gsub-table.hh"
48
#include "hb-ot-layout-gpos-table.hh"
49
#include "hb-ot-layout-base-table.hh"
50
#include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise.
51
#include "hb-ot-name-table.hh"
52
#include "hb-ot-os2-table.hh"
53
54
#include "hb-aat-layout-morx-table.hh"
55
#include "hb-aat-layout-opbd-table.hh" // Just so we compile it; unused otherwise.
56
57
using OT::Layout::GSUB;
58
using OT::Layout::GPOS;
59
60
/**
61
 * SECTION:hb-ot-layout
62
 * @title: hb-ot-layout
63
 * @short_description: OpenType Layout
64
 * @include: hb-ot.h
65
 *
66
 * Functions for querying OpenType Layout features in the font face.
67
 * See the [OpenType specification](http://www.microsoft.com/typography/otspec/)
68
 * for details.
69
 **/
70
71
72
/*
73
 * kern
74
 */
75
76
#ifndef HB_NO_OT_KERN
77
/**
78
 * hb_ot_layout_has_kerning:
79
 * @face: The #hb_face_t to work on
80
 *
81
 * Tests whether a face includes any kerning data in the 'kern' table.
82
 * Does NOT test for kerning lookups in the GPOS table.
83
 *
84
 * Return value: `true` if data found, `false` otherwise
85
 *
86
 **/
87
bool
88
hb_ot_layout_has_kerning (hb_face_t *face)
89
2.69k
{
90
2.69k
  return face->table.kern->table->has_data ();
91
2.69k
}
92
93
/**
94
 * hb_ot_layout_has_machine_kerning:
95
 * @face: The #hb_face_t to work on
96
 *
97
 * Tests whether a face includes any state-machine kerning in the 'kern' table.
98
 * Does NOT examine the GPOS table.
99
 *
100
 * Return value: `true` if data found, `false` otherwise
101
 *
102
 **/
103
bool
104
hb_ot_layout_has_machine_kerning (hb_face_t *face)
105
46
{
106
46
  return face->table.kern->table->has_state_machine ();
107
46
}
108
109
/**
110
 * hb_ot_layout_has_cross_kerning:
111
 * @face: The #hb_face_t to work on
112
 *
113
 * Tests whether a face has any cross-stream kerning (i.e., kerns
114
 * that make adjustments perpendicular to the direction of the text
115
 * flow: Y adjustments in horizontal text or X adjustments in
116
 * vertical text) in the 'kern' table.
117
 *
118
 * Does NOT examine the GPOS table.
119
 *
120
 * Return value: `true` is data found, `false` otherwise
121
 *
122
 **/
123
bool
124
hb_ot_layout_has_cross_kerning (hb_face_t *face)
125
0
{
126
0
  return face->table.kern->table->has_cross_stream ();
127
0
}
128
129
void
130
hb_ot_layout_kern (const hb_ot_shape_plan_t *plan,
131
       hb_font_t *font,
132
       hb_buffer_t  *buffer)
133
2.26k
{
134
2.26k
  auto &accel = *font->face->table.kern;
135
2.26k
  hb_blob_t *blob = accel.get_blob ();
136
137
2.26k
  AAT::hb_aat_apply_context_t c (plan, font, buffer, blob);
138
139
2.26k
  if (!buffer->message (font, "start table kern")) return;
140
2.26k
  c.buffer_glyph_set = accel.scratch.create_buffer_glyph_set ();
141
2.26k
  accel.apply (&c);
142
2.26k
  accel.scratch.destroy_buffer_glyph_set (c.buffer_glyph_set);
143
2.26k
  (void) buffer->message (font, "end table kern");
144
2.26k
}
145
#endif
146
147
148
/*
149
 * GDEF
150
 */
151
152
bool
153
OT::GDEF::is_blocklisted (hb_blob_t *blob,
154
        hb_face_t *face) const
155
2.30k
{
156
#ifdef HB_NO_OT_LAYOUT_BLOCKLIST
157
  return false;
158
#endif
159
  /* The ugly business of blocklisting individual fonts' tables happen here!
160
   * See this thread for why we finally had to bend in and do this:
161
   * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html
162
   *
163
   * In certain versions of Times New Roman Italic and Bold Italic,
164
   * ASCII double quotation mark U+0022 has wrong glyph class 3 (mark)
165
   * in GDEF.  Many versions of Tahoma have bad GDEF tables that
166
   * incorrectly classify some spacing marks such as certain IPA
167
   * symbols as glyph class 3. So do older versions of Microsoft
168
   * Himalaya, and the version of Cantarell shipped by Ubuntu 16.04.
169
   *
170
   * Nuke the GDEF tables of to avoid unwanted width-zeroing.
171
   *
172
   * See https://bugzilla.mozilla.org/show_bug.cgi?id=1279925
173
   *     https://bugzilla.mozilla.org/show_bug.cgi?id=1279693
174
   *     https://bugzilla.mozilla.org/show_bug.cgi?id=1279875
175
   */
176
2.30k
  switch HB_CODEPOINT_ENCODE3(blob->length,
177
2.30k
            face->table.GSUB->table.get_length (),
178
2.30k
            face->table.GPOS->table.get_length ())
179
2.30k
  {
180
    /* sha1sum:c5ee92f0bca4bfb7d06c4d03e8cf9f9cf75d2e8a Windows 7? timesi.ttf */
181
0
    case HB_CODEPOINT_ENCODE3 (442, 2874, 42038):
182
    /* sha1sum:37fc8c16a0894ab7b749e35579856c73c840867b Windows 7? timesbi.ttf */
183
0
    case HB_CODEPOINT_ENCODE3 (430, 2874, 40662):
184
    /* sha1sum:19fc45110ea6cd3cdd0a5faca256a3797a069a80 Windows 7 timesi.ttf */
185
0
    case HB_CODEPOINT_ENCODE3 (442, 2874, 39116):
186
    /* sha1sum:6d2d3c9ed5b7de87bc84eae0df95ee5232ecde26 Windows 7 timesbi.ttf */
187
0
    case HB_CODEPOINT_ENCODE3 (430, 2874, 39374):
188
    /* sha1sum:8583225a8b49667c077b3525333f84af08c6bcd8 OS X 10.11.3 Times New Roman Italic.ttf */
189
0
    case HB_CODEPOINT_ENCODE3 (490, 3046, 41638):
190
    /* sha1sum:ec0f5a8751845355b7c3271d11f9918a966cb8c9 OS X 10.11.3 Times New Roman Bold Italic.ttf */
191
0
    case HB_CODEPOINT_ENCODE3 (478, 3046, 41902):
192
    /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c  tahoma.ttf from Windows 8 */
193
0
    case HB_CODEPOINT_ENCODE3 (898, 12554, 46470):
194
    /* sha1sum:20928dc06014e0cd120b6fc942d0c3b1a46ac2bc  tahomabd.ttf from Windows 8 */
195
0
    case HB_CODEPOINT_ENCODE3 (910, 12566, 47732):
196
    /* sha1sum:4f95b7e4878f60fa3a39ca269618dfde9721a79e  tahoma.ttf from Windows 8.1 */
197
0
    case HB_CODEPOINT_ENCODE3 (928, 23298, 59332):
198
    /* sha1sum:6d400781948517c3c0441ba42acb309584b73033  tahomabd.ttf from Windows 8.1 */
199
0
    case HB_CODEPOINT_ENCODE3 (940, 23310, 60732):
200
    /* tahoma.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
201
0
    case HB_CODEPOINT_ENCODE3 (964, 23836, 60072):
202
    /* tahomabd.ttf v6.04 from Windows 8.1 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
203
0
    case HB_CODEPOINT_ENCODE3 (976, 23832, 61456):
204
    /* sha1sum:e55fa2dfe957a9f7ec26be516a0e30b0c925f846  tahoma.ttf from Windows 10 */
205
0
    case HB_CODEPOINT_ENCODE3 (994, 24474, 60336):
206
    /* sha1sum:7199385abb4c2cc81c83a151a7599b6368e92343  tahomabd.ttf from Windows 10 */
207
0
    case HB_CODEPOINT_ENCODE3 (1006, 24470, 61740):
208
    /* tahoma.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
209
0
    case HB_CODEPOINT_ENCODE3 (1006, 24576, 61346):
210
    /* tahomabd.ttf v6.91 from Windows 10 x64, see https://bugzilla.mozilla.org/show_bug.cgi?id=1279925 */
211
0
    case HB_CODEPOINT_ENCODE3 (1018, 24572, 62828):
212
    /* sha1sum:b9c84d820c49850d3d27ec498be93955b82772b5  tahoma.ttf from Windows 10 AU */
213
0
    case HB_CODEPOINT_ENCODE3 (1006, 24576, 61352):
214
    /* sha1sum:2bdfaab28174bdadd2f3d4200a30a7ae31db79d2  tahomabd.ttf from Windows 10 AU */
215
0
    case HB_CODEPOINT_ENCODE3 (1018, 24572, 62834):
216
    /* sha1sum:b0d36cf5a2fbe746a3dd277bffc6756a820807a7  Tahoma.ttf from Mac OS X 10.9 */
217
0
    case HB_CODEPOINT_ENCODE3 (832, 7324, 47162):
218
    /* sha1sum:12fc4538e84d461771b30c18b5eb6bd434e30fba  Tahoma Bold.ttf from Mac OS X 10.9 */
219
0
    case HB_CODEPOINT_ENCODE3 (844, 7302, 45474):
220
    /* sha1sum:eb8afadd28e9cf963e886b23a30b44ab4fd83acc  himalaya.ttf from Windows 7 */
221
0
    case HB_CODEPOINT_ENCODE3 (180, 13054, 7254):
222
    /* sha1sum:73da7f025b238a3f737aa1fde22577a6370f77b0  himalaya.ttf from Windows 8 */
223
0
    case HB_CODEPOINT_ENCODE3 (192, 12638, 7254):
224
    /* sha1sum:6e80fd1c0b059bbee49272401583160dc1e6a427  himalaya.ttf from Windows 8.1 */
225
0
    case HB_CODEPOINT_ENCODE3 (192, 12690, 7254):
226
    /* 8d9267aea9cd2c852ecfb9f12a6e834bfaeafe44  cantarell-fonts-0.0.21/otf/Cantarell-Regular.otf */
227
    /* 983988ff7b47439ab79aeaf9a45bd4a2c5b9d371  cantarell-fonts-0.0.21/otf/Cantarell-Oblique.otf */
228
0
    case HB_CODEPOINT_ENCODE3 (188, 248, 3852):
229
    /* 2c0c90c6f6087ffbfea76589c93113a9cbb0e75f  cantarell-fonts-0.0.21/otf/Cantarell-Bold.otf */
230
    /* 55461f5b853c6da88069ffcdf7f4dd3f8d7e3e6b  cantarell-fonts-0.0.21/otf/Cantarell-Bold-Oblique.otf */
231
0
    case HB_CODEPOINT_ENCODE3 (188, 264, 3426):
232
    /* d125afa82a77a6475ac0e74e7c207914af84b37a padauk-2.80/Padauk.ttf RHEL 7.2 */
233
0
    case HB_CODEPOINT_ENCODE3 (1058, 47032, 11818):
234
    /* 0f7b80437227b90a577cc078c0216160ae61b031 padauk-2.80/Padauk-Bold.ttf RHEL 7.2*/
235
0
    case HB_CODEPOINT_ENCODE3 (1046, 47030, 12600):
236
    /* d3dde9aa0a6b7f8f6a89ef1002e9aaa11b882290 padauk-2.80/Padauk.ttf Ubuntu 16.04 */
237
0
    case HB_CODEPOINT_ENCODE3 (1058, 71796, 16770):
238
    /* 5f3c98ccccae8a953be2d122c1b3a77fd805093f padauk-2.80/Padauk-Bold.ttf Ubuntu 16.04 */
239
0
    case HB_CODEPOINT_ENCODE3 (1046, 71790, 17862):
240
    /* 6c93b63b64e8b2c93f5e824e78caca555dc887c7 padauk-2.80/Padauk-book.ttf */
241
0
    case HB_CODEPOINT_ENCODE3 (1046, 71788, 17112):
242
    /* d89b1664058359b8ec82e35d3531931125991fb9 padauk-2.80/Padauk-bookbold.ttf */
243
0
    case HB_CODEPOINT_ENCODE3 (1058, 71794, 17514):
244
    /* 824cfd193aaf6234b2b4dc0cf3c6ef576c0d00ef padauk-3.0/Padauk-book.ttf */
245
0
    case HB_CODEPOINT_ENCODE3 (1330, 109904, 57938):
246
    /* 91fcc10cf15e012d27571e075b3b4dfe31754a8a padauk-3.0/Padauk-bookbold.ttf */
247
0
    case HB_CODEPOINT_ENCODE3 (1330, 109904, 58972):
248
    /* sha1sum: c26e41d567ed821bed997e937bc0c41435689e85  Padauk.ttf
249
     *  "Padauk Regular" "Version 2.5", see https://crbug.com/681813 */
250
0
    case HB_CODEPOINT_ENCODE3 (1004, 59092, 14836):
251
    /* 88d2006ca084f04af2df1954ed714a8c71e8400f  Courier New.ttf from macOS 15 */
252
0
    case HB_CODEPOINT_ENCODE3 (588, 5078, 14418):
253
    /* 608e3ebb6dd1aee521cff08eb07d500a2c59df68  Courier New Bold.ttf from macOS 15 */
254
0
    case HB_CODEPOINT_ENCODE3 (588, 5078, 14238):
255
    /* d13221044ff054efd78f1cd8631b853c3ce85676  cour.ttf from Windows 10 */
256
0
    case HB_CODEPOINT_ENCODE3 (894, 17162, 33960):
257
    /* 68ed4a22d8067fcf1622ac6f6e2f4d3a2e3ec394  courbd.ttf from Windows 10 */
258
0
    case HB_CODEPOINT_ENCODE3 (894, 17154, 34472):
259
    /* 4cdb0259c96b7fd7c103821bb8f08f7cc6b211d7  cour.ttf from Windows 8.1 */
260
0
    case HB_CODEPOINT_ENCODE3 (816, 7868, 17052):
261
    /* 920483d8a8ed37f7f0afdabbe7f679aece7c75d8  courbd.ttf from Windows 8.1 */
262
0
    case HB_CODEPOINT_ENCODE3 (816, 7868, 17138):
263
0
      return true;
264
2.30k
  }
265
2.30k
  return false;
266
2.30k
}
267
268
static void
269
_hb_ot_layout_set_glyph_props (hb_font_t *font,
270
             hb_buffer_t *buffer)
271
201k
{
272
201k
  _hb_buffer_assert_gsubgpos_vars (buffer);
273
274
201k
  const auto &gdef = *font->face->table.GDEF;
275
201k
  unsigned int count = buffer->len;
276
201k
  hb_glyph_info_t *info = buffer->info;
277
2.20M
  for (unsigned int i = 0; i < count; i++)
278
2.00M
  {
279
2.00M
    _hb_glyph_info_set_glyph_props (&info[i], gdef.get_glyph_props (info[i].codepoint));
280
2.00M
    _hb_glyph_info_clear_lig_props (&info[i]);
281
2.00M
  }
282
201k
}
283
284
/* Public API */
285
286
/**
287
 * hb_ot_layout_has_glyph_classes:
288
 * @face: #hb_face_t to work upon
289
 *
290
 * Tests whether a face has any glyph classes defined in its GDEF table.
291
 *
292
 * Return value: `true` if data found, `false` otherwise
293
 *
294
 **/
295
hb_bool_t
296
hb_ot_layout_has_glyph_classes (hb_face_t *face)
297
2.69k
{
298
2.69k
  return face->table.GDEF->table->has_glyph_classes ();
299
2.69k
}
300
301
/**
302
 * hb_ot_layout_get_glyph_class:
303
 * @face: The #hb_face_t to work on
304
 * @glyph: The #hb_codepoint_t code point to query
305
 *
306
 * Fetches the GDEF class of the requested glyph in the specified face.
307
 *
308
 * Return value: The #hb_ot_layout_glyph_class_t glyph class of the given code
309
 * point in the GDEF table of the face.
310
 *
311
 * Since: 0.9.7
312
 **/
313
hb_ot_layout_glyph_class_t
314
hb_ot_layout_get_glyph_class (hb_face_t      *face,
315
            hb_codepoint_t  glyph)
316
0
{
317
0
  return (hb_ot_layout_glyph_class_t) face->table.GDEF->table->get_glyph_class (glyph);
318
0
}
319
320
/**
321
 * hb_ot_layout_get_glyphs_in_class:
322
 * @face: The #hb_face_t to work on
323
 * @klass: The #hb_ot_layout_glyph_class_t GDEF class to retrieve
324
 * @glyphs: (out): The #hb_set_t set of all glyphs belonging to the requested
325
 *          class.
326
 *
327
 * Retrieves the set of all glyphs from the face that belong to the requested
328
 * glyph class in the face's GDEF table.
329
 *
330
 * Since: 0.9.7
331
 **/
332
void
333
hb_ot_layout_get_glyphs_in_class (hb_face_t                  *face,
334
          hb_ot_layout_glyph_class_t  klass,
335
          hb_set_t                   *glyphs /* OUT */)
336
0
{
337
0
  return face->table.GDEF->table->get_glyphs_in_class (klass, glyphs);
338
0
}
339
340
#ifndef HB_NO_LAYOUT_UNUSED
341
/**
342
 * hb_ot_layout_get_attach_points:
343
 * @face: The #hb_face_t to work on
344
 * @glyph: The #hb_codepoint_t code point to query
345
 * @start_offset: offset of the first attachment point to retrieve
346
 * @point_count: (inout) (nullable): Input = the maximum number of attachment points to return;
347
 *               Output = the actual number of attachment points returned (may be zero)
348
 * @point_array: (out) (array length=point_count): The array of attachment points found for the query
349
 *
350
 * Fetches a list of all attachment points for the specified glyph in the GDEF
351
 * table of the face. The list returned will begin at the offset provided.
352
 *
353
 * Useful if the client program wishes to cache the list.
354
 *
355
 * Return value: Total number of attachment points for @glyph.
356
 *
357
 **/
358
unsigned int
359
hb_ot_layout_get_attach_points (hb_face_t      *face,
360
        hb_codepoint_t  glyph,
361
        unsigned int    start_offset,
362
        unsigned int   *point_count /* IN/OUT */,
363
        unsigned int   *point_array /* OUT */)
364
0
{
365
0
  return face->table.GDEF->table->get_attach_points (glyph,
366
0
                 start_offset,
367
0
                 point_count,
368
0
                 point_array);
369
0
}
370
/**
371
 * hb_ot_layout_get_ligature_carets:
372
 * @font: The #hb_font_t to work on
373
 * @direction: The #hb_direction_t text direction to use
374
 * @glyph: The #hb_codepoint_t code point to query
375
 * @start_offset: offset of the first caret position to retrieve
376
 * @caret_count: (inout) (nullable): Input = the maximum number of caret positions to return;
377
 *               Output = the actual number of caret positions returned (may be zero)
378
 * @caret_array: (out) (array length=caret_count): The array of caret positions found for the query
379
 *
380
 * Fetches a list of the caret positions defined for a ligature glyph in the GDEF
381
 * table of the font. The list returned will begin at the offset provided.
382
 *
383
 * Note that a ligature that is formed from n characters will have n-1
384
 * caret positions. The first character is not represented in the array,
385
 * since its caret position is the glyph position.
386
 *
387
 * The positions returned by this function are 'unshaped', and will have to
388
 * be fixed up for kerning that may be applied to the ligature glyph.
389
 *
390
 * Return value: Total number of ligature caret positions for @glyph.
391
 *
392
 **/
393
unsigned int
394
hb_ot_layout_get_ligature_carets (hb_font_t      *font,
395
          hb_direction_t  direction,
396
          hb_codepoint_t  glyph,
397
          unsigned int    start_offset,
398
          unsigned int   *caret_count /* IN/OUT */,
399
          hb_position_t  *caret_array /* OUT */)
400
0
{
401
0
  return font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array);
402
0
}
403
#endif
404
405
406
/*
407
 * GSUB/GPOS
408
 */
409
410
bool
411
GSUB::is_blocklisted (hb_blob_t *blob HB_UNUSED,
412
        hb_face_t *face) const
413
2.30k
{
414
#ifdef HB_NO_OT_LAYOUT_BLOCKLIST
415
  return false;
416
#endif
417
2.30k
  return false;
418
2.30k
}
419
420
bool
421
GPOS::is_blocklisted (hb_blob_t *blob HB_UNUSED,
422
        hb_face_t *face HB_UNUSED) const
423
2.30k
{
424
#ifdef HB_NO_OT_LAYOUT_BLOCKLIST
425
  return false;
426
#endif
427
2.30k
  return false;
428
2.30k
}
429
430
static const OT::GSUBGPOS&
431
get_gsubgpos_table (hb_face_t *face,
432
        hb_tag_t   table_tag)
433
430k
{
434
430k
  switch (table_tag) {
435
215k
    case HB_OT_TAG_GSUB: return *face->table.GSUB->table;
436
215k
    case HB_OT_TAG_GPOS: return *face->table.GPOS->table;
437
0
    default:             return Null (OT::GSUBGPOS);
438
430k
  }
439
430k
}
440
441
442
/**
443
 * hb_ot_layout_table_get_script_tags:
444
 * @face: #hb_face_t to work upon
445
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
446
 * @start_offset: offset of the first script tag to retrieve
447
 * @script_count: (inout) (nullable): Input = the maximum number of script tags to return;
448
 *                Output = the actual number of script tags returned (may be zero)
449
 * @script_tags: (out) (array length=script_count): The array of #hb_tag_t script tags found for the query
450
 *
451
 * Fetches a list of all scripts enumerated in the specified face's GSUB table
452
 * or GPOS table. The list returned will begin at the offset provided.
453
 *
454
 * Return value: Total number of script tags.
455
 *
456
 **/
457
unsigned int
458
hb_ot_layout_table_get_script_tags (hb_face_t    *face,
459
            hb_tag_t      table_tag,
460
            unsigned int  start_offset,
461
            unsigned int *script_count /* IN/OUT */,
462
            hb_tag_t     *script_tags  /* OUT */)
463
0
{
464
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
465
466
0
  return g.get_script_tags (start_offset, script_count, script_tags);
467
0
}
468
469
5.30k
#define HB_OT_TAG_LATIN_SCRIPT    HB_TAG ('l', 'a', 't', 'n')
470
471
/**
472
 * hb_ot_layout_table_find_script:
473
 * @face: #hb_face_t to work upon
474
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
475
 * @script_tag: #hb_tag_t of the script tag requested
476
 * @script_index: (out): The index of the requested script tag
477
 *
478
 * Fetches the index if a given script tag in the specified face's GSUB table
479
 * or GPOS table.
480
 *
481
 * Return value: `true` if the script is found, `false` otherwise
482
 *
483
 **/
484
hb_bool_t
485
hb_ot_layout_table_find_script (hb_face_t    *face,
486
        hb_tag_t      table_tag,
487
        hb_tag_t      script_tag,
488
        unsigned int *script_index /* OUT */)
489
0
{
490
0
  static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
491
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
492
493
0
  if (g.find_script_index (script_tag, script_index))
494
0
    return true;
495
496
  /* try finding 'DFLT' */
497
0
  if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
498
0
    return false;
499
500
  /* try with 'dflt'; MS site has had typos and many fonts use it now :(.
501
   * including many versions of DejaVu Sans Mono! */
502
0
  if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
503
0
    return false;
504
505
  /* try with 'latn'; some old fonts put their features there even though
506
     they're really trying to support Thai, for example :( */
507
0
  if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index))
508
0
    return false;
509
510
0
  if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
511
0
  return false;
512
0
}
513
514
#ifndef HB_DISABLE_DEPRECATED
515
/**
516
 * hb_ot_layout_table_choose_script:
517
 * @face: #hb_face_t to work upon
518
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
519
 * @script_tags: Array of #hb_tag_t script tags
520
 * @script_index: (out): The index of the chosen script
521
 * @chosen_script: (out): #hb_tag_t of the chosen script
522
 *
523
 * Deprecated since 2.0.0
524
 **/
525
hb_bool_t
526
hb_ot_layout_table_choose_script (hb_face_t      *face,
527
          hb_tag_t        table_tag,
528
          const hb_tag_t *script_tags,
529
          unsigned int   *script_index  /* OUT */,
530
          hb_tag_t       *chosen_script /* OUT */)
531
0
{
532
0
  const hb_tag_t *t;
533
0
  for (t = script_tags; *t; t++);
534
0
  return hb_ot_layout_table_select_script (face, table_tag, t - script_tags, script_tags, script_index, chosen_script);
535
0
}
536
#endif
537
538
/**
539
 * hb_ot_layout_table_select_script:
540
 * @face: #hb_face_t to work upon
541
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
542
 * @script_count: Number of script tags in the array
543
 * @script_tags: Array of #hb_tag_t script tags
544
 * @script_index: (out) (nullable): The index of the requested script
545
 * @chosen_script: (out) (nullable): #hb_tag_t of the requested script
546
 *
547
 * Selects an OpenType script for @table_tag from the @script_tags array.
548
 *
549
 * If the table does not have any of the requested scripts, then `DFLT`,
550
 * `dflt`, and `latn` tags are tried in that order. If the table still does not
551
 * have any of these scripts, @script_index is set to
552
 * #HB_OT_LAYOUT_NO_SCRIPT_INDEX and @chosen_script is set to #HB_TAG_NONE.
553
 *
554
 * Return value:
555
 * `true` if one of the requested scripts is selected, `false` if a fallback
556
 * script is selected or if no scripts are selected.
557
 *
558
 * Since: 2.0.0
559
 **/
560
hb_bool_t
561
hb_ot_layout_table_select_script (hb_face_t      *face,
562
          hb_tag_t        table_tag,
563
          unsigned int    script_count,
564
          const hb_tag_t *script_tags,
565
          unsigned int   *script_index  /* OUT */,
566
          hb_tag_t       *chosen_script /* OUT */)
567
5.39k
{
568
5.39k
  static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX), "");
569
5.39k
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
570
5.39k
  unsigned int i;
571
572
10.7k
  for (i = 0; i < script_count; i++)
573
5.39k
  {
574
5.39k
    if (g.find_script_index (script_tags[i], script_index))
575
74
    {
576
74
      if (chosen_script)
577
74
  *chosen_script = script_tags[i];
578
74
      return true;
579
74
    }
580
5.39k
  }
581
582
  /* try finding 'DFLT' */
583
5.32k
  if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) {
584
18
    if (chosen_script)
585
18
      *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT;
586
18
    return false;
587
18
  }
588
589
  /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
590
5.30k
  if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) {
591
0
    if (chosen_script)
592
0
      *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE;
593
0
    return false;
594
0
  }
595
596
  /* try with 'latn'; some old fonts put their features there even though
597
     they're really trying to support Thai, for example :( */
598
5.30k
  if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) {
599
0
    if (chosen_script)
600
0
      *chosen_script = HB_OT_TAG_LATIN_SCRIPT;
601
0
    return false;
602
0
  }
603
604
5.30k
  if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
605
5.30k
  if (chosen_script)
606
5.30k
    *chosen_script = HB_TAG_NONE;
607
5.30k
  return false;
608
5.30k
}
609
610
611
/**
612
 * hb_ot_layout_table_get_feature_tags:
613
 * @face: #hb_face_t to work upon
614
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
615
 * @start_offset: offset of the first feature tag to retrieve
616
 * @feature_count: (inout) (nullable): Input = the maximum number of feature tags to return;
617
 *                 Output = the actual number of feature tags returned (may be zero)
618
 * @feature_tags: (out) (array length=feature_count): Array of feature tags found in the table
619
 *
620
 * Fetches a list of all feature tags in the given face's GSUB or GPOS table.
621
 * Note that there might be duplicate feature tags, belonging to different
622
 * script/language-system pairs of the table.
623
 *
624
 * Return value: Total number of feature tags.
625
 *
626
 * Since: 0.6.0
627
 *
628
 **/
629
unsigned int
630
hb_ot_layout_table_get_feature_tags (hb_face_t    *face,
631
             hb_tag_t      table_tag,
632
             unsigned int  start_offset,
633
             unsigned int *feature_count /* IN/OUT */,
634
             hb_tag_t     *feature_tags  /* OUT */)
635
0
{
636
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
637
638
0
  return g.get_feature_tags (start_offset, feature_count, feature_tags);
639
0
}
640
641
642
/**
643
 * hb_ot_layout_table_find_feature:
644
 * @face: #hb_face_t to work upon
645
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
646
 * @feature_tag: The #hb_tag_t of the requested feature tag
647
 * @feature_index: (out): The index of the requested feature
648
 *
649
 * Fetches the index for a given feature tag in the specified face's GSUB table
650
 * or GPOS table.
651
 *
652
 * Return value: `true` if the feature is found, `false` otherwise
653
 *
654
 * Since: 0.6.0
655
 *
656
 **/
657
bool
658
hb_ot_layout_table_find_feature (hb_face_t    *face,
659
         hb_tag_t      table_tag,
660
         hb_tag_t      feature_tag,
661
         unsigned int *feature_index /* OUT */)
662
0
{
663
0
  static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
664
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
665
666
0
  unsigned int num_features = g.get_feature_count ();
667
0
  for (unsigned int i = 0; i < num_features; i++)
668
0
  {
669
0
    if (feature_tag == g.get_feature_tag (i)) {
670
0
      if (feature_index) *feature_index = i;
671
0
      return true;
672
0
    }
673
0
  }
674
675
0
  if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
676
0
  return false;
677
0
}
678
679
680
/**
681
 * hb_ot_layout_script_get_language_tags:
682
 * @face: #hb_face_t to work upon
683
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
684
 * @script_index: The index of the requested script tag
685
 * @start_offset: offset of the first language tag to retrieve
686
 * @language_count: (inout) (nullable): Input = the maximum number of language tags to return;
687
 *                  Output = the actual number of language tags returned (may be zero)
688
 * @language_tags: (out) (array length=language_count): Array of language tags found in the table
689
 *
690
 * Fetches a list of language tags in the given face's GSUB or GPOS table, underneath
691
 * the specified script index. The list returned will begin at the offset provided.
692
 *
693
 * Return value: Total number of language tags.
694
 *
695
 * Since: 0.6.0
696
 *
697
 **/
698
unsigned int
699
hb_ot_layout_script_get_language_tags (hb_face_t    *face,
700
               hb_tag_t      table_tag,
701
               unsigned int  script_index,
702
               unsigned int  start_offset,
703
               unsigned int *language_count /* IN/OUT */,
704
               hb_tag_t     *language_tags  /* OUT */)
705
0
{
706
0
  const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
707
708
0
  return s.get_lang_sys_tags (start_offset, language_count, language_tags);
709
0
}
710
711
712
#ifndef HB_DISABLE_DEPRECATED
713
/**
714
 * hb_ot_layout_script_find_language:
715
 * @face: #hb_face_t to work upon
716
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
717
 * @script_index: The index of the requested script tag
718
 * @language_tag: The #hb_tag_t of the requested language
719
 * @language_index: The index of the requested language
720
 *
721
 * Fetches the index of a given language tag in the specified face's GSUB table
722
 * or GPOS table, underneath the specified script tag.
723
 *
724
 * Return value: `true` if the language tag is found, `false` otherwise
725
 *
726
 * Since: 0.6.0
727
 * Deprecated: 2.0.0
728
 **/
729
hb_bool_t
730
hb_ot_layout_script_find_language (hb_face_t    *face,
731
           hb_tag_t      table_tag,
732
           unsigned int  script_index,
733
           hb_tag_t      language_tag,
734
           unsigned int *language_index)
735
0
{
736
0
  return hb_ot_layout_script_select_language (face,
737
0
                table_tag,
738
0
                script_index,
739
0
                1,
740
0
                &language_tag,
741
0
                language_index);
742
0
}
743
#endif
744
745
746
/**
747
 * hb_ot_layout_script_select_language2:
748
 * @face: #hb_face_t to work upon
749
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
750
 * @script_index: The index of the requested script tag
751
 * @language_count: The number of languages in the specified script
752
 * @language_tags: The array of language tags
753
 * @language_index: (out): The index of the chosen language
754
 * @chosen_language: (out): #hb_tag_t of the chosen language
755
 *
756
 * Fetches the index of the first language tag fom @language_tags that is present
757
 * in the specified face's GSUB or GPOS table, underneath the specified script
758
 * index.
759
 *
760
 * If none of the given language tags is found, `false` is returned and
761
 * @language_index is set to #HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX and
762
 * @chosen_language is set to #HB_TAG_NONE.
763
 *
764
 * Return value: `true` if one of the given language tags is found, `false` otherwise
765
 *
766
 * Since: 7.0.0
767
 **/
768
hb_bool_t
769
hb_ot_layout_script_select_language2 (hb_face_t      *face,
770
             hb_tag_t        table_tag,
771
             unsigned int    script_index,
772
             unsigned int    language_count,
773
             const hb_tag_t *language_tags,
774
             unsigned int   *language_index /* OUT */,
775
             hb_tag_t       *chosen_language /* OUT */)
776
5.39k
{
777
5.39k
  static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX), "");
778
5.39k
  const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
779
5.39k
  unsigned int i;
780
781
8.87k
  for (i = 0; i < language_count; i++)
782
3.48k
  {
783
3.48k
    if (s.find_lang_sys_index (language_tags[i], language_index))
784
0
    {
785
0
      if (chosen_language)
786
0
        *chosen_language = language_tags[i];
787
0
      return true;
788
0
    }
789
3.48k
  }
790
791
  /* try finding 'dflt' */
792
5.39k
  if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
793
0
  {
794
0
    if (chosen_language)
795
0
      *chosen_language = HB_OT_TAG_DEFAULT_LANGUAGE;
796
0
    return false;
797
0
  }
798
799
5.39k
  if (language_index)
800
5.39k
    *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
801
5.39k
  if (chosen_language)
802
0
    *chosen_language = HB_TAG_NONE;
803
5.39k
  return false;
804
5.39k
}
805
806
/**
807
 * hb_ot_layout_script_select_language:
808
 * @face: #hb_face_t to work upon
809
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
810
 * @script_index: The index of the requested script tag
811
 * @language_count: The number of languages in the specified script
812
 * @language_tags: The array of language tags
813
 * @language_index: (out): The index of the requested language
814
 *
815
 * Fetches the index of the first language tag fom @language_tags that is present
816
 * in the specified face's GSUB or GPOS table, underneath the specified script
817
 * index.
818
 *
819
 * If none of the given language tags is found, `false` is returned and
820
 * @language_index is set to the default language index.
821
 *
822
 * Return value: `true` if one of the given language tags is found, `false` otherwise
823
 *
824
 * Since: 2.0.0
825
 **/
826
hb_bool_t
827
hb_ot_layout_script_select_language (hb_face_t      *face,
828
             hb_tag_t        table_tag,
829
             unsigned int    script_index,
830
             unsigned int    language_count,
831
             const hb_tag_t *language_tags,
832
             unsigned int   *language_index /* OUT */)
833
5.39k
{
834
5.39k
  return hb_ot_layout_script_select_language2 (face, table_tag,
835
5.39k
                 script_index,
836
5.39k
                 language_count, language_tags,
837
5.39k
                 language_index, nullptr);
838
5.39k
}
839
840
/**
841
 * hb_ot_layout_language_get_required_feature_index:
842
 * @face: #hb_face_t to work upon
843
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
844
 * @script_index: The index of the requested script tag
845
 * @language_index: The index of the requested language tag
846
 * @feature_index: (out): The index of the requested feature
847
 *
848
 * Fetches the index of a requested feature in the given face's GSUB or GPOS table,
849
 * underneath the specified script and language.
850
 *
851
 * Return value: `true` if the feature is found, `false` otherwise
852
 *
853
 * Since: 0.6.0
854
 *
855
 **/
856
hb_bool_t
857
hb_ot_layout_language_get_required_feature_index (hb_face_t    *face,
858
              hb_tag_t      table_tag,
859
              unsigned int  script_index,
860
              unsigned int  language_index,
861
              unsigned int *feature_index /* OUT */)
862
0
{
863
0
  return hb_ot_layout_language_get_required_feature (face,
864
0
                 table_tag,
865
0
                 script_index,
866
0
                 language_index,
867
0
                 feature_index,
868
0
                 nullptr);
869
0
}
870
871
872
/**
873
 * hb_ot_layout_language_get_required_feature:
874
 * @face: #hb_face_t to work upon
875
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
876
 * @script_index: The index of the requested script tag
877
 * @language_index: The index of the requested language tag
878
 * @feature_index: (out): The index of the requested feature
879
 * @feature_tag: (out): The #hb_tag_t of the requested feature
880
 *
881
 * Fetches the tag of a requested feature index in the given face's GSUB or GPOS table,
882
 * underneath the specified script and language.
883
 *
884
 * Return value: `true` if the feature is found, `false` otherwise
885
 *
886
 * Since: 0.9.30
887
 **/
888
hb_bool_t
889
hb_ot_layout_language_get_required_feature (hb_face_t    *face,
890
              hb_tag_t      table_tag,
891
              unsigned int  script_index,
892
              unsigned int  language_index,
893
              unsigned int *feature_index /* OUT */,
894
              hb_tag_t     *feature_tag   /* OUT */)
895
5.39k
{
896
5.39k
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
897
5.39k
  const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
898
899
5.39k
  unsigned int index = l.get_required_feature_index ();
900
5.39k
  if (feature_index) *feature_index = index;
901
5.39k
  if (feature_tag) *feature_tag = g.get_feature_tag (index);
902
903
5.39k
  return l.has_required_feature ();
904
5.39k
}
905
906
907
/**
908
 * hb_ot_layout_language_get_feature_indexes:
909
 * @face: #hb_face_t to work upon
910
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
911
 * @script_index: The index of the requested script tag
912
 * @language_index: The index of the requested language tag
913
 * @start_offset: offset of the first feature tag to retrieve
914
 * @feature_count: (inout) (nullable): Input = the maximum number of feature tags to return;
915
 *                 Output: the actual number of feature tags returned (may be zero)
916
 * @feature_indexes: (out) (array length=feature_count): The array of feature indexes found for the query
917
 *
918
 * Fetches a list of all features in the specified face's GSUB table
919
 * or GPOS table, underneath the specified script and language. The list
920
 * returned will begin at the offset provided.
921
 *
922
 * Return value: Total number of features.
923
 *
924
 * Since: 0.6.0
925
 *
926
 **/
927
unsigned int
928
hb_ot_layout_language_get_feature_indexes (hb_face_t    *face,
929
             hb_tag_t      table_tag,
930
             unsigned int  script_index,
931
             unsigned int  language_index,
932
             unsigned int  start_offset,
933
             unsigned int *feature_count   /* IN/OUT */,
934
             unsigned int *feature_indexes /* OUT */)
935
0
{
936
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
937
0
  const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
938
939
0
  return l.get_feature_indexes (start_offset, feature_count, feature_indexes);
940
0
}
941
942
943
/**
944
 * hb_ot_layout_language_get_feature_tags:
945
 * @face: #hb_face_t to work upon
946
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
947
 * @script_index: The index of the requested script tag
948
 * @language_index: The index of the requested language tag
949
 * @start_offset: offset of the first feature tag to retrieve
950
 * @feature_count: (inout) (nullable): Input = the maximum number of feature tags to return;
951
 *                 Output = the actual number of feature tags returned (may be zero)
952
 * @feature_tags: (out) (array length=feature_count): The array of #hb_tag_t feature tags found for the query
953
 *
954
 * Fetches a list of all features in the specified face's GSUB table
955
 * or GPOS table, underneath the specified script and language. The list
956
 * returned will begin at the offset provided.
957
 *
958
 * Return value: Total number of feature tags.
959
 *
960
 * Since: 0.6.0
961
 *
962
 **/
963
unsigned int
964
hb_ot_layout_language_get_feature_tags (hb_face_t    *face,
965
          hb_tag_t      table_tag,
966
          unsigned int  script_index,
967
          unsigned int  language_index,
968
          unsigned int  start_offset,
969
          unsigned int *feature_count /* IN/OUT */,
970
          hb_tag_t     *feature_tags  /* OUT */)
971
0
{
972
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
973
0
  const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
974
975
0
  static_assert ((sizeof (unsigned int) == sizeof (hb_tag_t)), "");
976
0
  unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
977
978
0
  if (feature_tags) {
979
0
    unsigned int count = *feature_count;
980
0
    for (unsigned int i = 0; i < count; i++)
981
0
      feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]);
982
0
  }
983
984
0
  return ret;
985
0
}
986
987
988
/**
989
 * hb_ot_layout_language_find_feature:
990
 * @face: #hb_face_t to work upon
991
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
992
 * @script_index: The index of the requested script tag
993
 * @language_index: The index of the requested language tag
994
 * @feature_tag: #hb_tag_t of the feature tag requested
995
 * @feature_index: (out): The index of the requested feature
996
 *
997
 * Fetches the index of a given feature tag in the specified face's GSUB table
998
 * or GPOS table, underneath the specified script and language.
999
 *
1000
 * Return value: `true` if the feature is found, `false` otherwise
1001
 *
1002
 * Since: 0.6.0
1003
 *
1004
 **/
1005
hb_bool_t
1006
hb_ot_layout_language_find_feature (hb_face_t    *face,
1007
            hb_tag_t      table_tag,
1008
            unsigned int  script_index,
1009
            unsigned int  language_index,
1010
            hb_tag_t      feature_tag,
1011
            unsigned int *feature_index /* OUT */)
1012
12
{
1013
12
  static_assert ((OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX), "");
1014
12
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1015
12
  const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
1016
1017
12
  unsigned int num_features = l.get_feature_count ();
1018
39
  for (unsigned int i = 0; i < num_features; i++) {
1019
27
    unsigned int f_index = l.get_feature_index (i);
1020
1021
27
    if (feature_tag == g.get_feature_tag (f_index)) {
1022
0
      if (feature_index) *feature_index = f_index;
1023
0
      return true;
1024
0
    }
1025
27
  }
1026
1027
12
  if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
1028
12
  return false;
1029
12
}
1030
1031
1032
/**
1033
 * hb_ot_layout_feature_get_lookups:
1034
 * @face: #hb_face_t to work upon
1035
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1036
 * @feature_index: The index of the requested feature
1037
 * @start_offset: offset of the first lookup to retrieve
1038
 * @lookup_count: (inout) (nullable): Input = the maximum number of lookups to return;
1039
 *                Output = the actual number of lookups returned (may be zero)
1040
 * @lookup_indexes: (out) (array length=lookup_count): The array of lookup indexes found for the query
1041
 *
1042
 * Fetches a list of all lookups enumerated for the specified feature, in
1043
 * the specified face's GSUB table or GPOS table. The list returned will
1044
 * begin at the offset provided.
1045
 *
1046
 * Return value: Total number of lookups.
1047
 *
1048
 * Since: 0.9.7
1049
 **/
1050
unsigned int
1051
hb_ot_layout_feature_get_lookups (hb_face_t    *face,
1052
          hb_tag_t      table_tag,
1053
          unsigned int  feature_index,
1054
          unsigned int  start_offset,
1055
          unsigned int *lookup_count   /* IN/OUT */,
1056
          unsigned int *lookup_indexes /* OUT */)
1057
0
{
1058
0
  return hb_ot_layout_feature_with_variations_get_lookups (face,
1059
0
                 table_tag,
1060
0
                 feature_index,
1061
0
                 HB_OT_LAYOUT_NO_VARIATIONS_INDEX,
1062
0
                 start_offset,
1063
0
                 lookup_count,
1064
0
                 lookup_indexes);
1065
0
}
1066
1067
1068
/**
1069
 * hb_ot_layout_table_get_lookup_count:
1070
 * @face: #hb_face_t to work upon
1071
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1072
 *
1073
 * Fetches the total number of lookups enumerated in the specified
1074
 * face's GSUB table or GPOS table.
1075
 *
1076
 * Return value: Total number of lookups.
1077
 *
1078
 * Since: 0.9.22
1079
 **/
1080
unsigned int
1081
hb_ot_layout_table_get_lookup_count (hb_face_t    *face,
1082
             hb_tag_t      table_tag)
1083
348
{
1084
348
  return get_gsubgpos_table (face, table_tag).get_lookup_count ();
1085
348
}
1086
1087
1088
struct hb_collect_features_context_t
1089
{
1090
  hb_collect_features_context_t (hb_face_t *face,
1091
         hb_tag_t   table_tag,
1092
         hb_set_t  *feature_indices_,
1093
         const hb_tag_t *features)
1094
1095
0
    : g (get_gsubgpos_table (face, table_tag)),
1096
0
      feature_indices (feature_indices_),
1097
0
      has_feature_filter (false),
1098
0
      script_count (0),langsys_count (0), feature_index_count (0)
1099
0
  {
1100
0
    compute_feature_filter (features);
1101
0
  }
1102
1103
  void compute_feature_filter (const hb_tag_t *features)
1104
0
  {
1105
0
    if (features == nullptr)
1106
0
    {
1107
0
      has_feature_filter = false;
1108
0
      return;
1109
0
    }
1110
1111
0
    has_feature_filter = true;
1112
0
    hb_set_t features_set;
1113
0
    for (; *features; features++)
1114
0
      features_set.add (*features);
1115
1116
0
    for (unsigned i = 0; i < g.get_feature_count (); i++)
1117
0
    {
1118
0
      hb_tag_t tag = g.get_feature_tag (i);
1119
0
      if (features_set.has (tag))
1120
0
  feature_indices_filter.add(i);
1121
0
    }
1122
0
  }
1123
1124
  bool visited (const OT::Script &s)
1125
0
  {
1126
    /* We might have Null() object here.  Don't want to involve
1127
     * that in the memoize.  So, detect empty objects and return. */
1128
0
    if (unlikely (!s.has_default_lang_sys () &&
1129
0
      !s.get_lang_sys_count ()))
1130
0
      return true;
1131
1132
0
    if (script_count++ > HB_MAX_SCRIPTS)
1133
0
      return true;
1134
1135
0
    return visited (s, visited_script);
1136
0
  }
1137
  bool visited (const OT::LangSys &l)
1138
0
  {
1139
    /* We might have Null() object here.  Don't want to involve
1140
     * that in the memoize.  So, detect empty objects and return. */
1141
0
    if (unlikely (!l.has_required_feature () &&
1142
0
      !l.get_feature_count ()))
1143
0
      return true;
1144
1145
0
    if (langsys_count++ > HB_MAX_LANGSYS)
1146
0
      return true;
1147
1148
0
    return visited (l, visited_langsys);
1149
0
  }
1150
1151
  bool visited_feature_indices (unsigned count)
1152
0
  {
1153
0
    feature_index_count += count;
1154
0
    return feature_index_count > HB_MAX_FEATURE_INDICES;
1155
0
  }
1156
1157
  private:
1158
  template <typename T>
1159
  bool visited (const T &p, hb_set_t &visited_set)
1160
0
  {
1161
0
    hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) &p - (uintptr_t) &g);
1162
0
     if (visited_set.has (delta))
1163
0
      return true;
1164
1165
0
    visited_set.add (delta);
1166
0
    return false;
1167
0
  }
Unexecuted instantiation: bool hb_collect_features_context_t::visited<OT::Script>(OT::Script const&, hb_set_t&)
Unexecuted instantiation: bool hb_collect_features_context_t::visited<OT::LangSys>(OT::LangSys const&, hb_set_t&)
1168
1169
  public:
1170
  const OT::GSUBGPOS &g;
1171
  hb_set_t *feature_indices;
1172
  hb_set_t  feature_indices_filter;
1173
  bool has_feature_filter;
1174
1175
  private:
1176
  hb_set_t visited_script;
1177
  hb_set_t visited_langsys;
1178
  unsigned int script_count;
1179
  unsigned int langsys_count;
1180
  unsigned int feature_index_count;
1181
};
1182
1183
static void
1184
langsys_collect_features (hb_collect_features_context_t *c,
1185
        const OT::LangSys  &l)
1186
0
{
1187
0
  if (c->visited (l)) return;
1188
1189
0
  if (!c->has_feature_filter)
1190
0
  {
1191
    /* All features. */
1192
0
    if (l.has_required_feature () && !c->visited_feature_indices (1))
1193
0
      c->feature_indices->add (l.get_required_feature_index ());
1194
1195
    // TODO(garretrieger): filter out indices >= feature count?
1196
0
    if (!c->visited_feature_indices (l.featureIndex.len))
1197
0
      l.add_feature_indexes_to (c->feature_indices);
1198
0
  }
1199
0
  else
1200
0
  {
1201
0
    if (c->feature_indices_filter.is_empty()) return;
1202
0
    unsigned int num_features = l.get_feature_count ();
1203
0
    for (unsigned int i = 0; i < num_features; i++)
1204
0
    {
1205
0
      unsigned int feature_index = l.get_feature_index (i);
1206
0
      if (!c->feature_indices_filter.has (feature_index)) continue;
1207
1208
0
      c->feature_indices->add (feature_index);
1209
0
      c->feature_indices_filter.del (feature_index);
1210
0
    }
1211
0
  }
1212
0
}
1213
1214
static void
1215
script_collect_features (hb_collect_features_context_t *c,
1216
       const OT::Script   &s,
1217
       const hb_tag_t *languages)
1218
0
{
1219
0
  if (c->visited (s)) return;
1220
1221
0
  if (!languages)
1222
0
  {
1223
    /* All languages. */
1224
0
    if (s.has_default_lang_sys ())
1225
0
      langsys_collect_features (c,
1226
0
        s.get_default_lang_sys ());
1227
1228
1229
0
    unsigned int count = s.get_lang_sys_count ();
1230
0
    for (unsigned int language_index = 0; language_index < count; language_index++)
1231
0
      langsys_collect_features (c,
1232
0
        s.get_lang_sys (language_index));
1233
0
  }
1234
0
  else
1235
0
  {
1236
0
    for (; *languages; languages++)
1237
0
    {
1238
0
      unsigned int language_index;
1239
0
      if (s.find_lang_sys_index (*languages, &language_index))
1240
0
  langsys_collect_features (c,
1241
0
          s.get_lang_sys (language_index));
1242
1243
0
    }
1244
0
  }
1245
0
}
1246
1247
1248
/**
1249
 * hb_ot_layout_collect_features:
1250
 * @face: #hb_face_t to work upon
1251
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1252
 * @scripts: (nullable) (array zero-terminated=1): The array of scripts to collect features for,
1253
 *   terminated by %HB_TAG_NONE
1254
 * @languages: (nullable) (array zero-terminated=1): The array of languages to collect features for,
1255
 *   terminated by %HB_TAG_NONE
1256
 * @features: (nullable) (array zero-terminated=1): The array of features to collect,
1257
 *   terminated by %HB_TAG_NONE
1258
 * @feature_indexes: (out): The set of feature indexes found for the query
1259
 *
1260
 * Fetches a list of all feature indexes in the specified face's GSUB table
1261
 * or GPOS table, underneath the specified scripts, languages, and features.
1262
 * If no list of scripts is provided, all scripts will be queried. If no list
1263
 * of languages is provided, all languages will be queried. If no list of
1264
 * features is provided, all features will be queried.
1265
 *
1266
 * Since: 1.8.5
1267
 **/
1268
void
1269
hb_ot_layout_collect_features (hb_face_t      *face,
1270
             hb_tag_t        table_tag,
1271
             const hb_tag_t *scripts,
1272
             const hb_tag_t *languages,
1273
             const hb_tag_t *features,
1274
             hb_set_t       *feature_indexes /* OUT */)
1275
0
{
1276
0
  hb_collect_features_context_t c (face, table_tag, feature_indexes, features);
1277
0
  if (!scripts)
1278
0
  {
1279
    /* All scripts. */
1280
0
    unsigned int count = c.g.get_script_count ();
1281
0
    for (unsigned int script_index = 0; script_index < count; script_index++)
1282
0
      script_collect_features (&c,
1283
0
             c.g.get_script (script_index),
1284
0
             languages);
1285
0
  }
1286
0
  else
1287
0
  {
1288
0
    for (; *scripts; scripts++)
1289
0
    {
1290
0
      unsigned int script_index;
1291
0
      if (c.g.find_script_index (*scripts, &script_index))
1292
0
  script_collect_features (&c,
1293
0
         c.g.get_script (script_index),
1294
0
         languages);
1295
0
    }
1296
0
  }
1297
0
}
1298
1299
/**
1300
 * hb_ot_layout_collect_features_map:
1301
 * @face: #hb_face_t to work upon
1302
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1303
 * @script_index: The index of the requested script tag
1304
 * @language_index: The index of the requested language tag
1305
 * @feature_map: (out): The map of feature tag to feature index.
1306
 *
1307
 * Fetches the mapping from feature tags to feature indexes for
1308
 * the specified script and language.
1309
 *
1310
 * Since: 8.1.0
1311
 **/
1312
void
1313
hb_ot_layout_collect_features_map (hb_face_t      *face,
1314
           hb_tag_t        table_tag,
1315
           unsigned        script_index,
1316
           unsigned        language_index,
1317
           hb_map_t       *feature_map /* OUT */)
1318
5.39k
{
1319
5.39k
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1320
5.39k
  const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
1321
1322
5.39k
  unsigned int count = l.get_feature_indexes (0, nullptr, nullptr);
1323
5.39k
  feature_map->alloc (count);
1324
1325
  /* Loop in reverse, such that earlier entries win. That emulates
1326
   * a linear search, which seems to be what other implementations do.
1327
   * We found that with arialuni_t.ttf, the "ur" language system has
1328
   * duplicate features, and the earlier ones work but not later ones.
1329
   */
1330
5.70k
  for (unsigned int i = count; i; i--)
1331
306
  {
1332
306
    unsigned feature_index = 0;
1333
306
    unsigned feature_count = 1;
1334
306
    l.get_feature_indexes (i - 1, &feature_count, &feature_index);
1335
306
    if (!feature_count)
1336
0
      break;
1337
306
    hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1338
306
    feature_map->set (feature_tag, feature_index);
1339
306
  }
1340
5.39k
}
1341
1342
1343
/**
1344
 * hb_ot_layout_collect_lookups:
1345
 * @face: #hb_face_t to work upon
1346
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1347
 * @scripts: (nullable) (array zero-terminated=1): The array of scripts to collect lookups for,
1348
 *   terminated by %HB_TAG_NONE
1349
 * @languages: (nullable) (array zero-terminated=1): The array of languages to collect lookups for,
1350
 *   terminated by %HB_TAG_NONE
1351
 * @features: (nullable) (array zero-terminated=1): The array of features to collect lookups for,
1352
 *   terminated by %HB_TAG_NONE
1353
 * @lookup_indexes: (out): The array of lookup indexes found for the query
1354
 *
1355
 * Fetches a list of all feature-lookup indexes in the specified face's GSUB
1356
 * table or GPOS table, underneath the specified scripts, languages, and
1357
 * features. If no list of scripts is provided, all scripts will be queried.
1358
 * If no list of languages is provided, all languages will be queried. If no
1359
 * list of features is provided, all features will be queried.
1360
 *
1361
 * Since: 0.9.8
1362
 **/
1363
void
1364
hb_ot_layout_collect_lookups (hb_face_t      *face,
1365
            hb_tag_t        table_tag,
1366
            const hb_tag_t *scripts,
1367
            const hb_tag_t *languages,
1368
            const hb_tag_t *features,
1369
            hb_set_t       *lookup_indexes /* OUT */)
1370
0
{
1371
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1372
1373
0
  hb_set_t feature_indexes;
1374
0
  hb_ot_layout_collect_features (face, table_tag, scripts, languages, features, &feature_indexes);
1375
1376
0
  for (auto feature_index : feature_indexes)
1377
0
    g.get_feature (feature_index).add_lookup_indexes_to (lookup_indexes);
1378
1379
0
  g.feature_variation_collect_lookups (&feature_indexes, nullptr, lookup_indexes);
1380
0
}
1381
1382
1383
#ifndef HB_NO_LAYOUT_COLLECT_GLYPHS
1384
/**
1385
 * hb_ot_layout_lookup_collect_glyphs:
1386
 * @face: #hb_face_t to work upon
1387
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1388
 * @lookup_index: The index of the feature lookup to query
1389
 * @glyphs_before: (out) (nullable): Array of glyphs preceding the substitution range
1390
 * @glyphs_input: (out) (nullable): Array of input glyphs that would be substituted by the lookup
1391
 * @glyphs_after: (out) (nullable): Array of glyphs following the substitution range
1392
 * @glyphs_output: (out) (nullable): Array of glyphs that would be the substituted output of the lookup
1393
 *
1394
 * Fetches a list of all glyphs affected by the specified lookup in the
1395
 * specified face's GSUB table or GPOS table.
1396
 *
1397
 * Since: 0.9.7
1398
 **/
1399
void
1400
hb_ot_layout_lookup_collect_glyphs (hb_face_t    *face,
1401
            hb_tag_t      table_tag,
1402
            unsigned int  lookup_index,
1403
            hb_set_t     *glyphs_before, /* OUT.  May be NULL */
1404
            hb_set_t     *glyphs_input,  /* OUT.  May be NULL */
1405
            hb_set_t     *glyphs_after,  /* OUT.  May be NULL */
1406
            hb_set_t     *glyphs_output  /* OUT.  May be NULL */)
1407
0
{
1408
0
  OT::hb_collect_glyphs_context_t c (face,
1409
0
             glyphs_before,
1410
0
             glyphs_input,
1411
0
             glyphs_after,
1412
0
             glyphs_output);
1413
1414
0
  switch (table_tag)
1415
0
  {
1416
0
    case HB_OT_TAG_GSUB:
1417
0
    {
1418
0
      const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1419
0
      l.collect_glyphs (&c);
1420
0
      return;
1421
0
    }
1422
0
    case HB_OT_TAG_GPOS:
1423
0
    {
1424
0
      const OT::PosLookup& l = face->table.GPOS->table->get_lookup (lookup_index);
1425
0
      l.collect_glyphs (&c);
1426
0
      return;
1427
0
    }
1428
0
  }
1429
0
}
1430
#endif
1431
1432
1433
/* Variations support */
1434
1435
1436
/**
1437
 * hb_ot_layout_table_find_feature_variations:
1438
 * @face: #hb_face_t to work upon
1439
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1440
 * @coords: The variation coordinates to query
1441
 * @num_coords: The number of variation coordinates
1442
 * @variations_index: (out): The array of feature variations found for the query
1443
 *
1444
 * Fetches a list of feature variations in the specified face's GSUB table
1445
 * or GPOS table, at the specified variation coordinates.
1446
 *
1447
 * Return value: `true` if feature variations were found, `false` otherwise.
1448
 *
1449
 * Since: 1.4.0
1450
 *
1451
 **/
1452
hb_bool_t
1453
hb_ot_layout_table_find_feature_variations (hb_face_t    *face,
1454
              hb_tag_t      table_tag,
1455
              const int    *coords,
1456
              unsigned int  num_coords,
1457
              unsigned int *variations_index /* out */)
1458
407k
{
1459
407k
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1460
407k
  const OT::GDEF &gdef = *face->table.GDEF->table;
1461
1462
407k
  auto instancer = OT::ItemVarStoreInstancer(&gdef.get_var_store(), nullptr,
1463
407k
               hb_array (coords, num_coords));
1464
1465
407k
  return g.find_variations_index (coords, num_coords, variations_index, &instancer);
1466
407k
}
1467
1468
1469
/**
1470
 * hb_ot_layout_feature_with_variations_get_lookups:
1471
 * @face: #hb_face_t to work upon
1472
 * @table_tag: #HB_OT_TAG_GSUB or #HB_OT_TAG_GPOS
1473
 * @feature_index: The index of the feature to query
1474
 * @variations_index: The index of the feature variation to query
1475
 * @start_offset: offset of the first lookup to retrieve
1476
 * @lookup_count: (inout) (nullable): Input = the maximum number of lookups to return;
1477
 *                Output = the actual number of lookups returned (may be zero)
1478
 * @lookup_indexes: (out) (array length=lookup_count): The array of lookups found for the query
1479
 *
1480
 * Fetches a list of all lookups enumerated for the specified feature, in
1481
 * the specified face's GSUB table or GPOS table, enabled at the specified
1482
 * variations index. The list returned will begin at the offset provided.
1483
 *
1484
 * Return value: Total number of lookups.
1485
 *
1486
 * Since: 1.4.0
1487
 *
1488
 **/
1489
unsigned int
1490
hb_ot_layout_feature_with_variations_get_lookups (hb_face_t    *face,
1491
              hb_tag_t      table_tag,
1492
              unsigned int  feature_index,
1493
              unsigned int  variations_index,
1494
              unsigned int  start_offset,
1495
              unsigned int *lookup_count /* IN/OUT */,
1496
              unsigned int *lookup_indexes /* OUT */)
1497
348
{
1498
348
  static_assert ((OT::FeatureVariations::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_VARIATIONS_INDEX), "");
1499
348
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1500
1501
348
  const OT::Feature &f = g.get_feature_variation (feature_index, variations_index);
1502
1503
348
  return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
1504
348
}
1505
1506
1507
/*
1508
 * OT::GSUB
1509
 */
1510
1511
1512
/**
1513
 * hb_ot_layout_has_substitution:
1514
 * @face: #hb_face_t to work upon
1515
 *
1516
 * Tests whether the specified face includes any GSUB substitutions.
1517
 *
1518
 * Return value: `true` if data found, `false` otherwise
1519
 *
1520
 * Since: 0.6.0
1521
 *
1522
 **/
1523
hb_bool_t
1524
hb_ot_layout_has_substitution (hb_face_t *face)
1525
2.69k
{
1526
2.69k
  return face->table.GSUB->table->has_data ();
1527
2.69k
}
1528
1529
1530
/**
1531
 * hb_ot_layout_lookup_would_substitute:
1532
 * @face: #hb_face_t to work upon
1533
 * @lookup_index: The index of the lookup to query
1534
 * @glyphs: The sequence of glyphs to query for substitution
1535
 * @glyphs_length: The length of the glyph sequence
1536
 * @zero_context: #hb_bool_t indicating whether pre-/post-context are disallowed
1537
 * in substitutions
1538
 *
1539
 * Tests whether a specified lookup in the specified face would
1540
 * trigger a substitution on the given glyph sequence.
1541
 *
1542
 * Return value: `true` if a substitution would be triggered, `false` otherwise
1543
 *
1544
 * Since: 0.9.7
1545
 **/
1546
hb_bool_t
1547
hb_ot_layout_lookup_would_substitute (hb_face_t            *face,
1548
              unsigned int          lookup_index,
1549
              const hb_codepoint_t *glyphs,
1550
              unsigned int          glyphs_length,
1551
              hb_bool_t             zero_context)
1552
0
{
1553
0
  auto &gsub = face->table.GSUB;
1554
0
  if (unlikely (lookup_index >= gsub->lookup_count)) return false;
1555
0
  OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context);
1556
1557
0
  const OT::SubstLookup& l = gsub->table->get_lookup (lookup_index);
1558
0
  auto *accel = gsub->get_accel (lookup_index);
1559
0
  return accel && l.would_apply (&c, accel);
1560
0
}
1561
1562
1563
/**
1564
 * hb_ot_layout_substitute_start:
1565
 * @font: #hb_font_t to use
1566
 * @buffer: #hb_buffer_t buffer to work upon
1567
 *
1568
 * Called before substitution lookups are performed, to ensure that glyph
1569
 * class and other properties are set on the glyphs in the buffer.
1570
 *
1571
 **/
1572
void
1573
hb_ot_layout_substitute_start (hb_font_t    *font,
1574
             hb_buffer_t  *buffer)
1575
201k
{
1576
201k
  _hb_ot_layout_set_glyph_props (font, buffer);
1577
201k
}
1578
1579
/**
1580
 * hb_ot_layout_lookup_substitute_closure:
1581
 * @face: #hb_face_t to work upon
1582
 * @lookup_index: index of the feature lookup to query
1583
 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookup
1584
 *
1585
 * Compute the transitive closure of glyphs needed for a
1586
 * specified lookup.
1587
 *
1588
 * Since: 0.9.7
1589
 **/
1590
void
1591
hb_ot_layout_lookup_substitute_closure (hb_face_t    *face,
1592
          unsigned int  lookup_index,
1593
          hb_set_t     *glyphs /* OUT */)
1594
0
{
1595
0
  hb_map_t done_lookups_glyph_count;
1596
0
  hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> done_lookups_glyph_set;
1597
0
  OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
1598
1599
0
  const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
1600
1601
0
  l.closure (&c, lookup_index);
1602
0
}
1603
1604
/**
1605
 * hb_ot_layout_lookups_substitute_closure:
1606
 * @face: #hb_face_t to work upon
1607
 * @lookups: The set of lookups to query
1608
 * @glyphs: (out): Array of glyphs comprising the transitive closure of the lookups
1609
 *
1610
 * Compute the transitive closure of glyphs needed for all of the
1611
 * provided lookups.
1612
 *
1613
 * Since: 1.8.1
1614
 **/
1615
void
1616
hb_ot_layout_lookups_substitute_closure (hb_face_t      *face,
1617
           const hb_set_t *lookups,
1618
           hb_set_t       *glyphs /* OUT */)
1619
0
{
1620
0
  hb_map_t done_lookups_glyph_count;
1621
0
  hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> done_lookups_glyph_set;
1622
0
  OT::hb_closure_context_t c (face, glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
1623
0
  const GSUB& gsub = *face->table.GSUB->table;
1624
1625
0
  unsigned int iteration_count = 0;
1626
0
  unsigned int glyphs_length;
1627
0
  do
1628
0
  {
1629
0
    c.reset_lookup_visit_count ();
1630
0
    glyphs_length = glyphs->get_population ();
1631
0
    if (lookups)
1632
0
    {
1633
0
      for (auto lookup_index : *lookups)
1634
0
  gsub.get_lookup (lookup_index).closure (&c, lookup_index);
1635
0
    }
1636
0
    else
1637
0
    {
1638
0
      for (unsigned int i = 0; i < gsub.get_lookup_count (); i++)
1639
0
  gsub.get_lookup (i).closure (&c, i);
1640
0
    }
1641
0
  } while (iteration_count++ <= HB_CLOSURE_MAX_STAGES &&
1642
0
     glyphs_length != glyphs->get_population ());
1643
0
}
1644
1645
/*
1646
 * GPOS
1647
 */
1648
1649
1650
/**
1651
 * hb_ot_layout_has_positioning:
1652
 * @face: #hb_face_t to work upon
1653
 *
1654
 * Tests whether the specified face includes any GPOS positioning.
1655
 *
1656
 * Return value: `true` if the face has GPOS data, `false` otherwise
1657
 *
1658
 **/
1659
hb_bool_t
1660
hb_ot_layout_has_positioning (hb_face_t *face)
1661
2.69k
{
1662
2.69k
  return face->table.GPOS->table->has_data ();
1663
2.69k
}
1664
1665
/**
1666
 * hb_ot_layout_position_start:
1667
 * @font: #hb_font_t to use
1668
 * @buffer: #hb_buffer_t buffer to work upon
1669
 *
1670
 * Called before positioning lookups are performed, to ensure that glyph
1671
 * attachment types and glyph-attachment chains are set for the glyphs in the buffer.
1672
 *
1673
 **/
1674
void
1675
hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer)
1676
201k
{
1677
201k
  GPOS::position_start (font, buffer);
1678
201k
}
1679
1680
1681
/**
1682
 * hb_ot_layout_position_finish_advances:
1683
 * @font: #hb_font_t to use
1684
 * @buffer: #hb_buffer_t buffer to work upon
1685
 *
1686
 * Called after positioning lookups are performed, to finish glyph advances.
1687
 *
1688
 **/
1689
void
1690
hb_ot_layout_position_finish_advances (hb_font_t *font, hb_buffer_t *buffer)
1691
201k
{
1692
201k
  GPOS::position_finish_advances (font, buffer);
1693
201k
}
1694
1695
/**
1696
 * hb_ot_layout_position_finish_offsets:
1697
 * @font: #hb_font_t to use
1698
 * @buffer: #hb_buffer_t buffer to work upon
1699
 *
1700
 * Called after positioning lookups are performed, to finish glyph offsets.
1701
 *
1702
 **/
1703
void
1704
hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
1705
201k
{
1706
201k
  GPOS::position_finish_offsets (font, buffer);
1707
201k
}
1708
1709
1710
#ifndef HB_NO_LAYOUT_FEATURE_PARAMS
1711
/**
1712
 * hb_ot_layout_get_size_params:
1713
 * @face: #hb_face_t to work upon
1714
 * @design_size: (out): The design size of the face
1715
 * @subfamily_id: (out): The identifier of the face within the font subfamily
1716
 * @subfamily_name_id: (out): The ‘name’ table name ID of the face within the font subfamily
1717
 * @range_start: (out): The minimum size of the recommended size range for the face
1718
 * @range_end: (out): The maximum size of the recommended size range for the face
1719
 *
1720
 * Fetches optical-size feature data (i.e., the `size` feature from GPOS). Note that
1721
 * the subfamily_id and the subfamily name string (accessible via the subfamily_name_id)
1722
 * as used here are defined as pertaining only to fonts within a font family that differ
1723
 * specifically in their respective size ranges; other ways to differentiate fonts within
1724
 * a subfamily are not covered by the `size` feature.
1725
 *
1726
 * For more information on this distinction, see the [`size` feature documentation](
1727
 * https://docs.microsoft.com/en-us/typography/opentype/spec/features_pt#tag-size).
1728
 *
1729
 * Return value: `true` if data found, `false` otherwise
1730
 *
1731
 * Since: 0.9.10
1732
 **/
1733
hb_bool_t
1734
hb_ot_layout_get_size_params (hb_face_t       *face,
1735
            unsigned int    *design_size,       /* OUT.  May be NULL */
1736
            unsigned int    *subfamily_id,      /* OUT.  May be NULL */
1737
            hb_ot_name_id_t *subfamily_name_id, /* OUT.  May be NULL */
1738
            unsigned int    *range_start,       /* OUT.  May be NULL */
1739
            unsigned int    *range_end          /* OUT.  May be NULL */)
1740
0
{
1741
0
  const GPOS &gpos = *face->table.GPOS->table;
1742
0
  const hb_tag_t tag = HB_TAG ('s','i','z','e');
1743
1744
0
  unsigned int num_features = gpos.get_feature_count ();
1745
0
  for (unsigned int i = 0; i < num_features; i++)
1746
0
  {
1747
0
    if (tag == gpos.get_feature_tag (i))
1748
0
    {
1749
0
      const OT::Feature &f = gpos.get_feature (i);
1750
0
      const OT::FeatureParamsSize &params = f.get_feature_params ().get_size_params (tag);
1751
1752
0
      if (params.designSize)
1753
0
      {
1754
0
  if (design_size) *design_size = params.designSize;
1755
0
  if (subfamily_id) *subfamily_id = params.subfamilyID;
1756
0
  if (subfamily_name_id) *subfamily_name_id = params.subfamilyNameID;
1757
0
  if (range_start) *range_start = params.rangeStart;
1758
0
  if (range_end) *range_end = params.rangeEnd;
1759
1760
0
  return true;
1761
0
      }
1762
0
    }
1763
0
  }
1764
1765
0
  if (design_size) *design_size = 0;
1766
0
  if (subfamily_id) *subfamily_id = 0;
1767
0
  if (subfamily_name_id) *subfamily_name_id = HB_OT_NAME_ID_INVALID;
1768
0
  if (range_start) *range_start = 0;
1769
0
  if (range_end) *range_end = 0;
1770
1771
0
  return false;
1772
0
}
1773
1774
1775
/**
1776
 * hb_ot_layout_feature_get_name_ids:
1777
 * @face: #hb_face_t to work upon
1778
 * @table_tag: table tag to query, "GSUB" or "GPOS".
1779
 * @feature_index: index of feature to query.
1780
 * @label_id: (out) (nullable): The ‘name’ table name ID that specifies a string
1781
 *            for a user-interface label for this feature.
1782
 * @tooltip_id: (out) (nullable): The ‘name’ table name ID that specifies a string
1783
 *              that an application can use for tooltip text for this
1784
 *              feature.
1785
 * @sample_id: (out) (nullable): The ‘name’ table name ID that specifies sample text
1786
 *             that illustrates the effect of this feature.
1787
 * @num_named_parameters: (out) (nullable):  Number of named parameters.
1788
 * @first_param_id: (out) (nullable): The first ‘name’ table name ID used to specify
1789
 *                  strings for user-interface labels for the feature
1790
 *                  parameters. (Must be zero if numParameters is zero.)
1791
 *
1792
 * Fetches name indices from feature parameters for "Stylistic Set" ('ssXX') or
1793
 * "Character Variant" ('cvXX') features.
1794
 *
1795
 * Return value: `true` if data found, `false` otherwise
1796
 *
1797
 * Since: 2.0.0
1798
 **/
1799
hb_bool_t
1800
hb_ot_layout_feature_get_name_ids (hb_face_t       *face,
1801
           hb_tag_t         table_tag,
1802
           unsigned int     feature_index,
1803
           hb_ot_name_id_t *label_id,             /* OUT.  May be NULL */
1804
           hb_ot_name_id_t *tooltip_id,           /* OUT.  May be NULL */
1805
           hb_ot_name_id_t *sample_id,            /* OUT.  May be NULL */
1806
           unsigned int    *num_named_parameters, /* OUT.  May be NULL */
1807
           hb_ot_name_id_t *first_param_id        /* OUT.  May be NULL */)
1808
0
{
1809
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1810
1811
0
  hb_tag_t feature_tag = g.get_feature_tag (feature_index);
1812
0
  const OT::Feature &f = g.get_feature (feature_index);
1813
1814
0
  const OT::FeatureParams &feature_params = f.get_feature_params ();
1815
0
  if (&feature_params != &Null (OT::FeatureParams))
1816
0
  {
1817
0
    const OT::FeatureParamsStylisticSet& ss_params =
1818
0
      feature_params.get_stylistic_set_params (feature_tag);
1819
0
    if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */
1820
0
    {
1821
0
      if (label_id) *label_id = ss_params.uiNameID;
1822
      // ssXX features don't have the rest
1823
0
      if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1824
0
      if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1825
0
      if (num_named_parameters) *num_named_parameters = 0;
1826
0
      if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1827
0
      return true;
1828
0
    }
1829
0
    const OT::FeatureParamsCharacterVariants& cv_params =
1830
0
      feature_params.get_character_variants_params (feature_tag);
1831
0
    if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */
1832
0
    {
1833
0
      if (label_id) *label_id = cv_params.featUILableNameID;
1834
0
      if (tooltip_id) *tooltip_id = cv_params.featUITooltipTextNameID;
1835
0
      if (sample_id) *sample_id = cv_params.sampleTextNameID;
1836
0
      if (num_named_parameters) *num_named_parameters = cv_params.numNamedParameters;
1837
0
      if (first_param_id) *first_param_id = cv_params.firstParamUILabelNameID;
1838
0
      return true;
1839
0
    }
1840
0
  }
1841
1842
0
  if (label_id) *label_id = HB_OT_NAME_ID_INVALID;
1843
0
  if (tooltip_id) *tooltip_id = HB_OT_NAME_ID_INVALID;
1844
0
  if (sample_id) *sample_id = HB_OT_NAME_ID_INVALID;
1845
0
  if (num_named_parameters) *num_named_parameters = 0;
1846
0
  if (first_param_id) *first_param_id = HB_OT_NAME_ID_INVALID;
1847
0
  return false;
1848
0
}
1849
/**
1850
 * hb_ot_layout_feature_get_characters:
1851
 * @face: #hb_face_t to work upon
1852
 * @table_tag: table tag to query, "GSUB" or "GPOS".
1853
 * @feature_index: index of feature to query.
1854
 * @start_offset: offset of the first character to retrieve
1855
 * @char_count: (inout) (nullable): Input = the maximum number of characters to return;
1856
 *              Output = the actual number of characters returned (may be zero)
1857
 * @characters: (out caller-allocates) (array length=char_count): A buffer pointer.
1858
 *              The Unicode codepoints of the characters for which this feature provides
1859
 *               glyph variants.
1860
 *
1861
 * Fetches a list of the characters defined as having a variant under the specified
1862
 * "Character Variant" ("cvXX") feature tag.
1863
 *
1864
 * Return value: Number of total sample characters in the cvXX feature.
1865
 *
1866
 * Since: 2.0.0
1867
 **/
1868
unsigned int
1869
hb_ot_layout_feature_get_characters (hb_face_t      *face,
1870
             hb_tag_t        table_tag,
1871
             unsigned int    feature_index,
1872
             unsigned int    start_offset,
1873
             unsigned int   *char_count, /* IN/OUT.  May be NULL */
1874
             hb_codepoint_t *characters  /* OUT.     May be NULL */)
1875
0
{
1876
0
  const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
1877
0
  return g.get_feature (feature_index)
1878
0
    .get_feature_params ()
1879
0
    .get_character_variants_params(g.get_feature_tag (feature_index))
1880
0
    .get_characters (start_offset, char_count, characters);
1881
0
}
1882
#endif
1883
1884
1885
/*
1886
 * Parts of different types are implemented here such that they have direct
1887
 * access to GSUB/GPOS lookups.
1888
 */
1889
1890
1891
struct GSUBProxy
1892
{
1893
  static constexpr unsigned table_index = 0u;
1894
  static constexpr bool always_inplace = false;
1895
  typedef OT::SubstLookup Lookup;
1896
1897
  GSUBProxy (hb_face_t *face) :
1898
201k
    accel (*face->table.GSUB) {}
1899
1900
  const GSUB::accelerator_t &accel;
1901
};
1902
1903
struct GPOSProxy
1904
{
1905
  static constexpr unsigned table_index = 1u;
1906
  static constexpr bool always_inplace = true;
1907
  typedef OT::PosLookup Lookup;
1908
1909
  GPOSProxy (hb_face_t *face) :
1910
201k
    accel (*face->table.GPOS) {}
1911
1912
  const GPOS::accelerator_t &accel;
1913
};
1914
1915
1916
static inline bool
1917
apply_forward (OT::hb_ot_apply_context_t *c,
1918
         const OT::hb_ot_layout_lookup_accelerator_t &accel,
1919
         unsigned subtable_count)
1920
315
{
1921
315
  bool use_cache = accel.cache_enter (c);
1922
1923
315
  bool ret = false;
1924
315
  hb_buffer_t *buffer = c->buffer;
1925
630
  while (buffer->idx < buffer->len && buffer->successful)
1926
315
  {
1927
315
    bool applied = false;
1928
315
    auto &cur = buffer->cur();
1929
315
    if (accel.digest.may_have (cur.codepoint) &&
1930
315
  (cur.mask & c->lookup_mask) &&
1931
315
  c->check_glyph_property (&cur, c->lookup_props))
1932
57
     {
1933
57
       applied = accel.apply (c, subtable_count, use_cache);
1934
57
     }
1935
1936
315
    if (applied)
1937
0
      ret = true;
1938
315
    else
1939
315
      (void) buffer->next_glyph ();
1940
315
  }
1941
1942
315
  if (use_cache)
1943
0
    accel.cache_leave (c);
1944
1945
315
  return ret;
1946
315
}
1947
1948
static inline bool
1949
apply_backward (OT::hb_ot_apply_context_t *c,
1950
         const OT::hb_ot_layout_lookup_accelerator_t &accel,
1951
         unsigned subtable_count)
1952
0
{
1953
0
  bool ret = false;
1954
0
  hb_buffer_t *buffer = c->buffer;
1955
0
  do
1956
0
  {
1957
0
    auto &cur = buffer->cur();
1958
0
    if (accel.digest.may_have (cur.codepoint) &&
1959
0
  (cur.mask & c->lookup_mask) &&
1960
0
  c->check_glyph_property (&cur, c->lookup_props))
1961
0
      ret |= accel.apply (c, subtable_count, false);
1962
1963
    /* The reverse lookup doesn't "advance" cursor (for good reason). */
1964
0
    buffer->idx--;
1965
1966
0
  }
1967
0
  while ((int) buffer->idx >= 0);
1968
0
  return ret;
1969
0
}
1970
1971
template <typename Proxy>
1972
static inline bool
1973
apply_string (OT::hb_ot_apply_context_t *c,
1974
        const typename Proxy::Lookup &lookup,
1975
        const OT::hb_ot_layout_lookup_accelerator_t &accel)
1976
315
{
1977
315
  hb_buffer_t *buffer = c->buffer;
1978
315
  unsigned subtable_count = lookup.get_subtable_count ();
1979
1980
315
  if (unlikely (!buffer->len || !c->lookup_mask))
1981
0
    return false;
1982
1983
315
  bool ret = false;
1984
1985
315
  c->set_lookup_props (lookup.get_props ());
1986
1987
315
  if (likely (!lookup.is_reverse ()))
1988
315
  {
1989
    /* in/out forward substitution/positioning */
1990
315
    if (!Proxy::always_inplace)
1991
258
      buffer->clear_output ();
1992
1993
315
    buffer->idx = 0;
1994
315
    ret = apply_forward (c, accel, subtable_count);
1995
1996
315
    if (!Proxy::always_inplace)
1997
258
      buffer->sync ();
1998
315
  }
1999
0
  else
2000
0
  {
2001
    /* in-place backward substitution/positioning */
2002
0
    assert (!buffer->have_output);
2003
0
    buffer->idx = buffer->len - 1;
2004
0
    ret = apply_backward (c, accel, subtable_count);
2005
0
  }
2006
2007
315
  return ret;
2008
315
}
hb-ot-layout.cc:bool apply_string<GPOSProxy>(OT::hb_ot_apply_context_t*, GPOSProxy::Lookup const&, OT::hb_ot_layout_lookup_accelerator_t const&)
Line
Count
Source
1976
57
{
1977
57
  hb_buffer_t *buffer = c->buffer;
1978
57
  unsigned subtable_count = lookup.get_subtable_count ();
1979
1980
57
  if (unlikely (!buffer->len || !c->lookup_mask))
1981
0
    return false;
1982
1983
57
  bool ret = false;
1984
1985
57
  c->set_lookup_props (lookup.get_props ());
1986
1987
57
  if (likely (!lookup.is_reverse ()))
1988
57
  {
1989
    /* in/out forward substitution/positioning */
1990
57
    if (!Proxy::always_inplace)
1991
0
      buffer->clear_output ();
1992
1993
57
    buffer->idx = 0;
1994
57
    ret = apply_forward (c, accel, subtable_count);
1995
1996
57
    if (!Proxy::always_inplace)
1997
0
      buffer->sync ();
1998
57
  }
1999
0
  else
2000
0
  {
2001
    /* in-place backward substitution/positioning */
2002
0
    assert (!buffer->have_output);
2003
0
    buffer->idx = buffer->len - 1;
2004
0
    ret = apply_backward (c, accel, subtable_count);
2005
0
  }
2006
2007
57
  return ret;
2008
57
}
hb-ot-layout.cc:bool apply_string<GSUBProxy>(OT::hb_ot_apply_context_t*, GSUBProxy::Lookup const&, OT::hb_ot_layout_lookup_accelerator_t const&)
Line
Count
Source
1976
258
{
1977
258
  hb_buffer_t *buffer = c->buffer;
1978
258
  unsigned subtable_count = lookup.get_subtable_count ();
1979
1980
258
  if (unlikely (!buffer->len || !c->lookup_mask))
1981
0
    return false;
1982
1983
258
  bool ret = false;
1984
1985
258
  c->set_lookup_props (lookup.get_props ());
1986
1987
258
  if (likely (!lookup.is_reverse ()))
1988
258
  {
1989
    /* in/out forward substitution/positioning */
1990
258
    if (!Proxy::always_inplace)
1991
258
      buffer->clear_output ();
1992
1993
258
    buffer->idx = 0;
1994
258
    ret = apply_forward (c, accel, subtable_count);
1995
1996
258
    if (!Proxy::always_inplace)
1997
258
      buffer->sync ();
1998
258
  }
1999
0
  else
2000
0
  {
2001
    /* in-place backward substitution/positioning */
2002
0
    assert (!buffer->have_output);
2003
0
    buffer->idx = buffer->len - 1;
2004
0
    ret = apply_backward (c, accel, subtable_count);
2005
0
  }
2006
2007
258
  return ret;
2008
258
}
2009
2010
template <typename Proxy>
2011
inline void hb_ot_map_t::apply (const Proxy &proxy,
2012
        const hb_ot_shape_plan_t *plan,
2013
        hb_font_t *font,
2014
        hb_buffer_t *buffer) const
2015
402k
{
2016
402k
  const unsigned int table_index = proxy.table_index;
2017
402k
  unsigned int i = 0;
2018
2019
402k
  auto *font_data = font->data.ot.get ();
2020
402k
  auto *var_store_cache = (OT::hb_scalar_cache_t *) font_data;
2021
2022
402k
  OT::hb_ot_apply_context_t c (table_index, font, buffer, proxy.accel.get_blob (), var_store_cache);
2023
402k
  c.set_recurse_func (Proxy::Lookup::template dispatch_recurse_func<OT::hb_ot_apply_context_t>);
2024
2025
1.00M
  for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++)
2026
604k
  {
2027
604k
    const stage_map_t *stage = &stages[table_index][stage_index];
2028
616k
    for (; i < stage->last_lookup; i++)
2029
11.7k
    {
2030
11.7k
      auto &lookup = lookups[table_index][i];
2031
2032
11.7k
      unsigned int lookup_index = lookup.index;
2033
2034
11.7k
      auto *accel = proxy.accel.get_accel (lookup_index);
2035
11.7k
      if (unlikely (!accel)) continue;
2036
2037
11.7k
      if (buffer->messaging () &&
2038
11.7k
    !buffer->message (font, "start lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag))) continue;
2039
2040
      /* c.digest is a digest of all the current glyphs in the buffer
2041
       * (plus some past glyphs).
2042
       *
2043
       * Only try applying the lookup if there is any overlap. */
2044
11.7k
      if (accel->digest.may_intersect (c.digest))
2045
315
      {
2046
315
  c.set_lookup_index (lookup_index);
2047
315
  c.set_lookup_mask (lookup.mask, false);
2048
315
  c.set_auto_zwj (lookup.auto_zwj, false);
2049
315
  c.set_auto_zwnj (lookup.auto_zwnj, false);
2050
315
  c.set_random (lookup.random);
2051
315
  c.set_per_syllable (lookup.per_syllable, false);
2052
  /* apply_string's set_lookup_props initializes the iterators. */
2053
2054
315
  apply_string<Proxy> (&c,
2055
315
           proxy.accel.table->get_lookup (lookup_index),
2056
315
           *accel);
2057
315
      }
2058
11.4k
      else if (buffer->messaging ())
2059
0
  (void) buffer->message (font, "skipped lookup %u feature '%c%c%c%c' because no glyph matches", lookup_index, HB_UNTAG (lookup.feature_tag));
2060
2061
11.7k
      if (buffer->messaging ())
2062
0
  (void) buffer->message (font, "end lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag));
2063
11.7k
    }
2064
2065
604k
    if (stage->pause_func)
2066
288
    {
2067
288
      if (stage->pause_func (plan, font, buffer))
2068
6
      {
2069
  /* Refresh working buffer digest since buffer changed. */
2070
6
  buffer->collect_codepoints (c.digest);
2071
6
      }
2072
288
    }
2073
604k
  }
2074
402k
}
void hb_ot_map_t::apply<GSUBProxy>(GSUBProxy const&, hb_ot_shape_plan_t const*, hb_font_t*, hb_buffer_t*) const
Line
Count
Source
2015
201k
{
2016
201k
  const unsigned int table_index = proxy.table_index;
2017
201k
  unsigned int i = 0;
2018
2019
201k
  auto *font_data = font->data.ot.get ();
2020
201k
  auto *var_store_cache = (OT::hb_scalar_cache_t *) font_data;
2021
2022
201k
  OT::hb_ot_apply_context_t c (table_index, font, buffer, proxy.accel.get_blob (), var_store_cache);
2023
201k
  c.set_recurse_func (Proxy::Lookup::template dispatch_recurse_func<OT::hb_ot_apply_context_t>);
2024
2025
604k
  for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++)
2026
403k
  {
2027
403k
    const stage_map_t *stage = &stages[table_index][stage_index];
2028
408k
    for (; i < stage->last_lookup; i++)
2029
4.92k
    {
2030
4.92k
      auto &lookup = lookups[table_index][i];
2031
2032
4.92k
      unsigned int lookup_index = lookup.index;
2033
2034
4.92k
      auto *accel = proxy.accel.get_accel (lookup_index);
2035
4.92k
      if (unlikely (!accel)) continue;
2036
2037
4.92k
      if (buffer->messaging () &&
2038
4.92k
    !buffer->message (font, "start lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag))) continue;
2039
2040
      /* c.digest is a digest of all the current glyphs in the buffer
2041
       * (plus some past glyphs).
2042
       *
2043
       * Only try applying the lookup if there is any overlap. */
2044
4.92k
      if (accel->digest.may_intersect (c.digest))
2045
258
      {
2046
258
  c.set_lookup_index (lookup_index);
2047
258
  c.set_lookup_mask (lookup.mask, false);
2048
258
  c.set_auto_zwj (lookup.auto_zwj, false);
2049
258
  c.set_auto_zwnj (lookup.auto_zwnj, false);
2050
258
  c.set_random (lookup.random);
2051
258
  c.set_per_syllable (lookup.per_syllable, false);
2052
  /* apply_string's set_lookup_props initializes the iterators. */
2053
2054
258
  apply_string<Proxy> (&c,
2055
258
           proxy.accel.table->get_lookup (lookup_index),
2056
258
           *accel);
2057
258
      }
2058
4.66k
      else if (buffer->messaging ())
2059
0
  (void) buffer->message (font, "skipped lookup %u feature '%c%c%c%c' because no glyph matches", lookup_index, HB_UNTAG (lookup.feature_tag));
2060
2061
4.92k
      if (buffer->messaging ())
2062
0
  (void) buffer->message (font, "end lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag));
2063
4.92k
    }
2064
2065
403k
    if (stage->pause_func)
2066
288
    {
2067
288
      if (stage->pause_func (plan, font, buffer))
2068
6
      {
2069
  /* Refresh working buffer digest since buffer changed. */
2070
6
  buffer->collect_codepoints (c.digest);
2071
6
      }
2072
288
    }
2073
403k
  }
2074
201k
}
void hb_ot_map_t::apply<GPOSProxy>(GPOSProxy const&, hb_ot_shape_plan_t const*, hb_font_t*, hb_buffer_t*) const
Line
Count
Source
2015
201k
{
2016
201k
  const unsigned int table_index = proxy.table_index;
2017
201k
  unsigned int i = 0;
2018
2019
201k
  auto *font_data = font->data.ot.get ();
2020
201k
  auto *var_store_cache = (OT::hb_scalar_cache_t *) font_data;
2021
2022
201k
  OT::hb_ot_apply_context_t c (table_index, font, buffer, proxy.accel.get_blob (), var_store_cache);
2023
201k
  c.set_recurse_func (Proxy::Lookup::template dispatch_recurse_func<OT::hb_ot_apply_context_t>);
2024
2025
402k
  for (unsigned int stage_index = 0; stage_index < stages[table_index].length; stage_index++)
2026
201k
  {
2027
201k
    const stage_map_t *stage = &stages[table_index][stage_index];
2028
208k
    for (; i < stage->last_lookup; i++)
2029
6.87k
    {
2030
6.87k
      auto &lookup = lookups[table_index][i];
2031
2032
6.87k
      unsigned int lookup_index = lookup.index;
2033
2034
6.87k
      auto *accel = proxy.accel.get_accel (lookup_index);
2035
6.87k
      if (unlikely (!accel)) continue;
2036
2037
6.87k
      if (buffer->messaging () &&
2038
6.87k
    !buffer->message (font, "start lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag))) continue;
2039
2040
      /* c.digest is a digest of all the current glyphs in the buffer
2041
       * (plus some past glyphs).
2042
       *
2043
       * Only try applying the lookup if there is any overlap. */
2044
6.87k
      if (accel->digest.may_intersect (c.digest))
2045
57
      {
2046
57
  c.set_lookup_index (lookup_index);
2047
57
  c.set_lookup_mask (lookup.mask, false);
2048
57
  c.set_auto_zwj (lookup.auto_zwj, false);
2049
57
  c.set_auto_zwnj (lookup.auto_zwnj, false);
2050
57
  c.set_random (lookup.random);
2051
57
  c.set_per_syllable (lookup.per_syllable, false);
2052
  /* apply_string's set_lookup_props initializes the iterators. */
2053
2054
57
  apply_string<Proxy> (&c,
2055
57
           proxy.accel.table->get_lookup (lookup_index),
2056
57
           *accel);
2057
57
      }
2058
6.81k
      else if (buffer->messaging ())
2059
0
  (void) buffer->message (font, "skipped lookup %u feature '%c%c%c%c' because no glyph matches", lookup_index, HB_UNTAG (lookup.feature_tag));
2060
2061
6.87k
      if (buffer->messaging ())
2062
0
  (void) buffer->message (font, "end lookup %u feature '%c%c%c%c'", lookup_index, HB_UNTAG (lookup.feature_tag));
2063
6.87k
    }
2064
2065
201k
    if (stage->pause_func)
2066
0
    {
2067
0
      if (stage->pause_func (plan, font, buffer))
2068
0
      {
2069
  /* Refresh working buffer digest since buffer changed. */
2070
0
  buffer->collect_codepoints (c.digest);
2071
0
      }
2072
0
    }
2073
201k
  }
2074
201k
}
2075
2076
void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
2077
201k
{
2078
201k
  GSUBProxy proxy (font->face);
2079
201k
  if (buffer->messaging () &&
2080
201k
      !buffer->message (font, "start table GSUB script tag '%c%c%c%c'", HB_UNTAG (chosen_script[0]))) return;
2081
201k
  apply (proxy, plan, font, buffer);
2082
201k
  if (buffer->messaging ())
2083
0
    (void) buffer->message (font, "end table GSUB script tag '%c%c%c%c'", HB_UNTAG (chosen_script[0]));
2084
201k
}
2085
2086
void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
2087
201k
{
2088
201k
  GPOSProxy proxy (font->face);
2089
201k
  if (buffer->messaging () &&
2090
201k
      !buffer->message (font, "start table GPOS script tag '%c%c%c%c'", HB_UNTAG (chosen_script[1]))) return;
2091
201k
  apply (proxy, plan, font, buffer);
2092
201k
  if (buffer->messaging ())
2093
0
    (void) buffer->message (font, "end table GPOS script tag '%c%c%c%c'", HB_UNTAG (chosen_script[1]));
2094
201k
}
2095
2096
void
2097
hb_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c,
2098
        const OT::SubstLookup &lookup,
2099
        const OT::hb_ot_layout_lookup_accelerator_t &accel)
2100
0
{
2101
0
  apply_string<GSUBProxy> (c, lookup, accel);
2102
0
}
2103
2104
#ifndef HB_NO_BASE
2105
2106
static void
2107
choose_base_tags (hb_script_t    script,
2108
      hb_language_t  language,
2109
      hb_tag_t      *script_tag,
2110
      hb_tag_t      *language_tag)
2111
0
{
2112
0
  hb_tag_t script_tags[HB_OT_MAX_TAGS_PER_SCRIPT];
2113
0
  unsigned script_count = ARRAY_LENGTH (script_tags);
2114
2115
0
  hb_tag_t language_tags[HB_OT_MAX_TAGS_PER_LANGUAGE];
2116
0
  unsigned language_count = ARRAY_LENGTH (language_tags);
2117
2118
0
  hb_ot_tags_from_script_and_language (script, language,
2119
0
               &script_count, script_tags,
2120
0
               &language_count, language_tags);
2121
2122
0
  *script_tag = script_count ? script_tags[script_count - 1] : HB_OT_TAG_DEFAULT_SCRIPT;
2123
0
  *language_tag = language_count ? language_tags[language_count - 1] : HB_OT_TAG_DEFAULT_LANGUAGE;
2124
0
}
2125
2126
/**
2127
 * hb_ot_layout_get_font_extents:
2128
 * @font: a font
2129
 * @direction: text direction.
2130
 * @script_tag:  script tag.
2131
 * @language_tag: language tag.
2132
 * @extents: (out) (nullable): font extents if found.
2133
 *
2134
 * Fetches script/language-specific font extents.  These values are
2135
 * looked up in the `BASE` table's `MinMax` records.
2136
 *
2137
 * If no such extents are found, the default extents for the font are
2138
 * fetched. As such, the return value of this function can for the
2139
 * most part be ignored.  Note that the per-script/language extents
2140
 * do not have a line-gap value, and the line-gap is set to zero in
2141
 * that case.
2142
 *
2143
 * Return value: `true` if found script/language-specific font extents.
2144
 *
2145
 * Since: 8.0.0
2146
 **/
2147
hb_bool_t
2148
hb_ot_layout_get_font_extents (hb_font_t         *font,
2149
             hb_direction_t     direction,
2150
             hb_tag_t           script_tag,
2151
             hb_tag_t           language_tag,
2152
             hb_font_extents_t *extents)
2153
0
{
2154
0
  hb_position_t min = 0, max = 0;
2155
0
  if (font->face->table.BASE->get_min_max (font, direction, script_tag, language_tag, HB_TAG_NONE,
2156
0
             &min, &max))
2157
0
  {
2158
0
    if (extents)
2159
0
    {
2160
0
      extents->ascender  = max;
2161
0
      extents->descender = min;
2162
0
      extents->line_gap  = 0;
2163
0
    }
2164
0
    return true;
2165
0
  }
2166
2167
0
  hb_font_get_extents_for_direction (font, direction, extents);
2168
0
  return false;
2169
0
}
2170
2171
/**
2172
 * hb_ot_layout_get_font_extents2:
2173
 * @font: a font
2174
 * @direction: text direction.
2175
 * @script:  script.
2176
 * @language: (nullable): language.
2177
 * @extents: (out) (nullable): font extents if found.
2178
 *
2179
 * Fetches script/language-specific font extents.  These values are
2180
 * looked up in the `BASE` table's `MinMax` records.
2181
 *
2182
 * If no such extents are found, the default extents for the font are
2183
 * fetched. As such, the return value of this function can for the
2184
 * most part be ignored.  Note that the per-script/language extents
2185
 * do not have a line-gap value, and the line-gap is set to zero in
2186
 * that case.
2187
 *
2188
 * This function is like hb_ot_layout_get_font_extents() but takes
2189
 * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t.
2190
 *
2191
 * Return value: `true` if found script/language-specific font extents.
2192
 *
2193
 * Since: 8.0.0
2194
 **/
2195
hb_bool_t
2196
hb_ot_layout_get_font_extents2 (hb_font_t         *font,
2197
        hb_direction_t     direction,
2198
        hb_script_t        script,
2199
        hb_language_t      language,
2200
        hb_font_extents_t *extents)
2201
0
{
2202
0
  hb_tag_t script_tag, language_tag;
2203
0
  choose_base_tags (script, language, &script_tag, &language_tag);
2204
0
  return hb_ot_layout_get_font_extents (font,
2205
0
          direction,
2206
0
          script_tag,
2207
0
          language_tag,
2208
0
          extents);
2209
0
}
2210
2211
/**
2212
 * hb_ot_layout_get_horizontal_baseline_tag_for_script:
2213
 * @script: a script tag.
2214
 *
2215
 * Fetches the dominant horizontal baseline tag used by @script.
2216
 *
2217
 * Return value: dominant baseline tag for the @script.
2218
 *
2219
 * Since: 4.0.0
2220
 **/
2221
hb_ot_layout_baseline_tag_t
2222
hb_ot_layout_get_horizontal_baseline_tag_for_script (hb_script_t script)
2223
0
{
2224
  /* Keep in sync with hb_ot_layout_get_baseline_with_fallback */
2225
0
  switch ((int) script)
2226
0
  {
2227
    /* Unicode-1.1 additions */
2228
0
    case HB_SCRIPT_BENGALI:
2229
0
    case HB_SCRIPT_DEVANAGARI:
2230
0
    case HB_SCRIPT_GUJARATI:
2231
0
    case HB_SCRIPT_GURMUKHI:
2232
    /* Unicode-2.0 additions */
2233
0
    case HB_SCRIPT_TIBETAN:
2234
    /* Unicode-4.0 additions */
2235
0
    case HB_SCRIPT_LIMBU:
2236
    /* Unicode-4.1 additions */
2237
0
    case HB_SCRIPT_SYLOTI_NAGRI:
2238
    /* Unicode-5.0 additions */
2239
0
    case HB_SCRIPT_PHAGS_PA:
2240
    /* Unicode-5.2 additions */
2241
0
    case HB_SCRIPT_MEETEI_MAYEK:
2242
    /* Unicode-6.1 additions */
2243
0
    case HB_SCRIPT_SHARADA:
2244
0
    case HB_SCRIPT_TAKRI:
2245
    /* Unicode-7.0 additions */
2246
0
    case HB_SCRIPT_MODI:
2247
0
    case HB_SCRIPT_SIDDHAM:
2248
0
    case HB_SCRIPT_TIRHUTA:
2249
    /* Unicode-9.0 additions */
2250
0
    case HB_SCRIPT_MARCHEN:
2251
0
    case HB_SCRIPT_NEWA:
2252
    /* Unicode-10.0 additions */
2253
0
    case HB_SCRIPT_SOYOMBO:
2254
0
    case HB_SCRIPT_ZANABAZAR_SQUARE:
2255
    /* Unicode-11.0 additions */
2256
0
    case HB_SCRIPT_DOGRA:
2257
0
    case HB_SCRIPT_GUNJALA_GONDI:
2258
    /* Unicode-12.0 additions */
2259
0
    case HB_SCRIPT_NANDINAGARI:
2260
0
      return HB_OT_LAYOUT_BASELINE_TAG_HANGING;
2261
2262
    /* Unicode-1.1 additions */
2263
0
    case HB_SCRIPT_HANGUL:
2264
0
    case HB_SCRIPT_HAN:
2265
0
    case HB_SCRIPT_HIRAGANA:
2266
0
    case HB_SCRIPT_KATAKANA:
2267
    /* Unicode-3.0 additions */
2268
0
    case HB_SCRIPT_BOPOMOFO:
2269
    /* Unicode-9.0 additions */
2270
0
    case HB_SCRIPT_TANGUT:
2271
    /* Unicode-10.0 additions */
2272
0
    case HB_SCRIPT_NUSHU:
2273
    /* Unicode-13.0 additions */
2274
0
    case HB_SCRIPT_KHITAN_SMALL_SCRIPT:
2275
0
      return HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT;
2276
2277
0
    default:
2278
0
      return HB_OT_LAYOUT_BASELINE_TAG_ROMAN;
2279
0
  }
2280
0
}
2281
2282
/**
2283
 * hb_ot_layout_get_baseline:
2284
 * @font: a font
2285
 * @baseline_tag: a baseline tag
2286
 * @direction: text direction.
2287
 * @script_tag:  script tag.
2288
 * @language_tag: language tag, currently unused.
2289
 * @coord: (out) (nullable): baseline value if found.
2290
 *
2291
 * Fetches a baseline value from the face.
2292
 *
2293
 * Return value: `true` if found baseline value in the font.
2294
 *
2295
 * Since: 2.6.0
2296
 **/
2297
hb_bool_t
2298
hb_ot_layout_get_baseline (hb_font_t                   *font,
2299
         hb_ot_layout_baseline_tag_t  baseline_tag,
2300
         hb_direction_t               direction,
2301
         hb_tag_t                     script_tag,
2302
         hb_tag_t                     language_tag,
2303
         hb_position_t               *coord        /* OUT.  May be NULL. */)
2304
0
{
2305
0
  return font->face->table.BASE->get_baseline (font, baseline_tag, direction, script_tag, language_tag, coord);
2306
0
}
2307
2308
/**
2309
 * hb_ot_layout_get_baseline2:
2310
 * @font: a font
2311
 * @baseline_tag: a baseline tag
2312
 * @direction: text direction.
2313
 * @script:  script.
2314
 * @language: (nullable): language, currently unused.
2315
 * @coord: (out) (nullable): baseline value if found.
2316
 *
2317
 * Fetches a baseline value from the face.
2318
 *
2319
 * This function is like hb_ot_layout_get_baseline() but takes
2320
 * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t.
2321
 *
2322
 * Return value: `true` if found baseline value in the font.
2323
 *
2324
 * Since: 8.0.0
2325
 **/
2326
hb_bool_t
2327
hb_ot_layout_get_baseline2 (hb_font_t                   *font,
2328
          hb_ot_layout_baseline_tag_t  baseline_tag,
2329
          hb_direction_t               direction,
2330
          hb_script_t                  script,
2331
          hb_language_t                language,
2332
          hb_position_t               *coord        /* OUT.  May be NULL. */)
2333
0
{
2334
0
  hb_tag_t script_tag, language_tag;
2335
0
  choose_base_tags (script, language, &script_tag, &language_tag);
2336
0
  return hb_ot_layout_get_baseline (font,
2337
0
            baseline_tag,
2338
0
            direction,
2339
0
            script_tag,
2340
0
            language_tag,
2341
0
            coord);
2342
0
}
2343
2344
/**
2345
 * hb_ot_layout_get_baseline_with_fallback:
2346
 * @font: a font
2347
 * @baseline_tag: a baseline tag
2348
 * @direction: text direction.
2349
 * @script_tag:  script tag.
2350
 * @language_tag: language tag, currently unused.
2351
 * @coord: (out): baseline value if found.
2352
 *
2353
 * Fetches a baseline value from the face, and synthesizes
2354
 * it if the font does not have it.
2355
 *
2356
 * Since: 4.0.0
2357
 **/
2358
void
2359
hb_ot_layout_get_baseline_with_fallback (hb_font_t                   *font,
2360
           hb_ot_layout_baseline_tag_t  baseline_tag,
2361
           hb_direction_t               direction,
2362
           hb_tag_t                     script_tag,
2363
           hb_tag_t                     language_tag,
2364
           hb_position_t               *coord /* OUT */)
2365
0
{
2366
0
  if (hb_ot_layout_get_baseline (font,
2367
0
         baseline_tag,
2368
0
         direction,
2369
0
         script_tag,
2370
0
         language_tag,
2371
0
         coord))
2372
0
    return;
2373
2374
  /* Synthesize missing baselines.
2375
   * See https://www.w3.org/TR/css-inline-3/#baseline-synthesis-fonts
2376
   */
2377
0
  switch (baseline_tag)
2378
0
  {
2379
0
  case HB_OT_LAYOUT_BASELINE_TAG_ROMAN:
2380
0
    *coord = 0; // FIXME origin ?
2381
0
    break;
2382
2383
0
  case HB_OT_LAYOUT_BASELINE_TAG_MATH:
2384
0
    {
2385
0
      hb_codepoint_t glyph;
2386
0
      hb_glyph_extents_t extents;
2387
0
      if (HB_DIRECTION_IS_HORIZONTAL (direction) &&
2388
0
    (hb_font_get_nominal_glyph (font, 0x2212u, &glyph) ||
2389
0
     hb_font_get_nominal_glyph (font, '-', &glyph)) &&
2390
0
    hb_font_get_glyph_extents (font, glyph, &extents))
2391
0
      {
2392
0
  *coord = extents.y_bearing + extents.height / 2;
2393
0
      }
2394
0
      else
2395
0
      {
2396
0
  hb_position_t x_height = font->y_scale / 2;
2397
0
#ifndef HB_NO_METRICS
2398
0
  hb_ot_metrics_get_position_with_fallback (font, HB_OT_METRICS_TAG_X_HEIGHT, &x_height);
2399
0
#endif
2400
0
  *coord = x_height / 2;
2401
0
      }
2402
0
    }
2403
0
    break;
2404
2405
0
  case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT:
2406
0
  case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT:
2407
0
    {
2408
0
      hb_position_t embox_top, embox_bottom;
2409
2410
0
      hb_ot_layout_get_baseline_with_fallback (font,
2411
0
                 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT,
2412
0
                 direction,
2413
0
                 script_tag,
2414
0
                 language_tag,
2415
0
                 &embox_top);
2416
0
      hb_ot_layout_get_baseline_with_fallback (font,
2417
0
                 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT,
2418
0
                 direction,
2419
0
                 script_tag,
2420
0
                 language_tag,
2421
0
                 &embox_bottom);
2422
2423
0
      if (baseline_tag == HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT)
2424
0
  *coord = embox_top + (embox_bottom - embox_top) / 10;
2425
0
      else
2426
0
  *coord = embox_bottom + (embox_top - embox_bottom) / 10;
2427
0
    }
2428
0
    break;
2429
2430
0
  case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT:
2431
0
    if (hb_ot_layout_get_baseline (font,
2432
0
           HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT,
2433
0
           direction,
2434
0
           script_tag,
2435
0
           language_tag,
2436
0
           coord))
2437
0
      *coord += HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale;
2438
0
    else
2439
0
    {
2440
0
      hb_font_extents_t font_extents;
2441
0
      hb_font_get_extents_for_direction (font, direction, &font_extents);
2442
0
      *coord = font_extents.ascender;
2443
0
    }
2444
0
    break;
2445
2446
0
  case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT:
2447
0
    if (hb_ot_layout_get_baseline (font,
2448
0
           HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT,
2449
0
           direction,
2450
0
           script_tag,
2451
0
           language_tag,
2452
0
           coord))
2453
0
      *coord -= HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale;
2454
0
    else
2455
0
    {
2456
0
      hb_font_extents_t font_extents;
2457
0
      hb_font_get_extents_for_direction (font, direction, &font_extents);
2458
0
      *coord = font_extents.descender;
2459
0
    }
2460
0
    break;
2461
2462
0
  case HB_OT_LAYOUT_BASELINE_TAG_HANGING:
2463
0
    if (HB_DIRECTION_IS_HORIZONTAL (direction))
2464
0
    {
2465
0
      hb_codepoint_t ch;
2466
0
      hb_codepoint_t glyph;
2467
0
      hb_glyph_extents_t extents;
2468
2469
      /* Keep in sync with hb_ot_layout_get_horizontal_baseline_for_script */
2470
0
      switch ((int) script_tag)
2471
0
      {
2472
      /* Unicode-1.1 additions */
2473
0
      case HB_SCRIPT_BENGALI:          ch = 0x0995u; break;
2474
0
      case HB_SCRIPT_DEVANAGARI:       ch = 0x0915u; break;
2475
0
      case HB_SCRIPT_GUJARATI:         ch = 0x0a95u; break;
2476
0
      case HB_SCRIPT_GURMUKHI:         ch = 0x0a15u; break;
2477
      /* Unicode-2.0 additions */
2478
0
      case HB_SCRIPT_TIBETAN:          ch = 0x0f40u; break;
2479
      /* Unicode-4.0 additions */
2480
0
      case HB_SCRIPT_LIMBU:            ch = 0x1901u; break;
2481
      /* Unicode-4.1 additions */
2482
0
      case HB_SCRIPT_SYLOTI_NAGRI:     ch = 0xa807u; break;
2483
      /* Unicode-5.0 additions */
2484
0
      case HB_SCRIPT_PHAGS_PA:         ch = 0xa840u; break;
2485
      /* Unicode-5.2 additions */
2486
0
      case HB_SCRIPT_MEETEI_MAYEK:     ch = 0xabc0u; break;
2487
      /* Unicode-6.1 additions */
2488
0
      case HB_SCRIPT_SHARADA:          ch = 0x11191u; break;
2489
0
      case HB_SCRIPT_TAKRI:            ch = 0x1168cu; break;
2490
      /* Unicode-7.0 additions */
2491
0
      case HB_SCRIPT_MODI:             ch = 0x1160eu;break;
2492
0
      case HB_SCRIPT_SIDDHAM:          ch = 0x11590u; break;
2493
0
      case HB_SCRIPT_TIRHUTA:          ch = 0x1148fu; break;
2494
      /* Unicode-9.0 additions */
2495
0
      case HB_SCRIPT_MARCHEN:          ch = 0x11c72u; break;
2496
0
      case HB_SCRIPT_NEWA:             ch = 0x1140eu; break;
2497
      /* Unicode-10.0 additions */
2498
0
      case HB_SCRIPT_SOYOMBO:          ch = 0x11a5cu; break;
2499
0
      case HB_SCRIPT_ZANABAZAR_SQUARE: ch = 0x11a0bu; break;
2500
      /* Unicode-11.0 additions */
2501
0
      case HB_SCRIPT_DOGRA:            ch = 0x1180au; break;
2502
0
      case HB_SCRIPT_GUNJALA_GONDI:    ch = 0x11d6cu; break;
2503
      /* Unicode-12.0 additions */
2504
0
      case HB_SCRIPT_NANDINAGARI:      ch = 0x119b0u; break;
2505
0
      default:                         ch = 0;        break;
2506
0
      }
2507
2508
0
      if (ch &&
2509
0
    hb_font_get_nominal_glyph (font, ch, &glyph) &&
2510
0
    hb_font_get_glyph_extents (font, glyph, &extents))
2511
0
  *coord = extents.y_bearing;
2512
0
      else
2513
0
  *coord = font->y_scale * 6 / 10; // FIXME makes assumptions about origin
2514
0
    }
2515
0
    else
2516
0
      *coord = font->x_scale * 6 / 10; // FIXME makes assumptions about origin
2517
0
    break;
2518
2519
0
  case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL:
2520
0
    {
2521
0
      hb_position_t top, bottom;
2522
0
      hb_ot_layout_get_baseline_with_fallback (font,
2523
0
                 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_TOP_OR_RIGHT,
2524
0
                 direction,
2525
0
                 script_tag,
2526
0
                 language_tag,
2527
0
                 &top);
2528
0
      hb_ot_layout_get_baseline_with_fallback (font,
2529
0
                 HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT,
2530
0
                 direction,
2531
0
                 script_tag,
2532
0
                 language_tag,
2533
0
                 &bottom);
2534
0
      *coord = (top + bottom) / 2;
2535
2536
0
    }
2537
0
    break;
2538
2539
0
  case HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_CENTRAL:
2540
0
    {
2541
0
      hb_position_t top, bottom;
2542
0
      hb_ot_layout_get_baseline_with_fallback (font,
2543
0
                 HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT,
2544
0
                 direction,
2545
0
                 script_tag,
2546
0
                 language_tag,
2547
0
                 &top);
2548
0
      hb_ot_layout_get_baseline_with_fallback (font,
2549
0
                 HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_BOTTOM_OR_LEFT,
2550
0
                 direction,
2551
0
                 script_tag,
2552
0
                 language_tag,
2553
0
                 &bottom);
2554
0
      *coord = (top + bottom) / 2;
2555
2556
0
    }
2557
0
    break;
2558
2559
0
  case _HB_OT_LAYOUT_BASELINE_TAG_MAX_VALUE:
2560
0
  default:
2561
0
    *coord = 0;
2562
0
    break;
2563
0
  }
2564
0
}
2565
2566
/**
2567
 * hb_ot_layout_get_baseline_with_fallback2:
2568
 * @font: a font
2569
 * @baseline_tag: a baseline tag
2570
 * @direction: text direction.
2571
 * @script:  script.
2572
 * @language: (nullable): language, currently unused.
2573
 * @coord: (out): baseline value if found.
2574
 *
2575
 * Fetches a baseline value from the face, and synthesizes
2576
 * it if the font does not have it.
2577
 *
2578
 * This function is like hb_ot_layout_get_baseline_with_fallback() but takes
2579
 * #hb_script_t and #hb_language_t instead of OpenType #hb_tag_t.
2580
 *
2581
 * Since: 8.0.0
2582
 **/
2583
void
2584
hb_ot_layout_get_baseline_with_fallback2 (hb_font_t                   *font,
2585
            hb_ot_layout_baseline_tag_t  baseline_tag,
2586
            hb_direction_t               direction,
2587
            hb_script_t                  script,
2588
            hb_language_t                language,
2589
            hb_position_t               *coord        /* OUT */)
2590
0
{
2591
0
  hb_tag_t script_tag, language_tag;
2592
0
  choose_base_tags (script, language, &script_tag, &language_tag);
2593
0
  hb_ot_layout_get_baseline_with_fallback (font,
2594
0
             baseline_tag,
2595
0
             direction,
2596
0
             script_tag,
2597
0
             language_tag,
2598
0
             coord);
2599
0
}
2600
2601
#endif
2602
2603
2604
struct hb_get_glyph_alternates_dispatch_t :
2605
       hb_dispatch_context_t<hb_get_glyph_alternates_dispatch_t, unsigned>
2606
{
2607
0
  static return_t default_return_value () { return 0; }
2608
0
  bool stop_sublookup_iteration (return_t r) const { return r; }
2609
2610
  private:
2611
  template <typename T, typename ...Ts> auto
2612
  _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN
2613
  ( obj.get_glyph_alternates (std::forward<Ts> (ds)...) )
2614
  template <typename T, typename ...Ts> auto
2615
  _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN
2616
  ( default_return_value () )
2617
  public:
2618
  template <typename T, typename ...Ts> auto
2619
  dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
2620
  ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) )
2621
};
2622
2623
#ifndef HB_NO_LAYOUT_RARELY_USED
2624
/**
2625
 * hb_ot_layout_lookup_get_glyph_alternates:
2626
 * @face: a face.
2627
 * @lookup_index: index of the feature lookup to query.
2628
 * @glyph: a glyph id.
2629
 * @start_offset: starting offset.
2630
 * @alternate_count: (inout) (nullable): Input = the maximum number of alternate glyphs to return;
2631
 *                   Output = the actual number of alternate glyphs returned (may be zero).
2632
 * @alternate_glyphs: (out caller-allocates) (array length=alternate_count): A glyphs buffer.
2633
 *                    Alternate glyphs associated with the glyph id.
2634
 *
2635
 * Fetches alternates of a glyph from a given GSUB lookup index. Note that for one-to-one GSUB
2636
 * glyph substitutions, this function fetches the substituted glyph.
2637
 *
2638
 * Return value: Total number of alternates found in the specific lookup index for the given glyph id.
2639
 *
2640
 * Since: 2.6.8
2641
 **/
2642
HB_EXTERN unsigned
2643
hb_ot_layout_lookup_get_glyph_alternates (hb_face_t      *face,
2644
            unsigned        lookup_index,
2645
            hb_codepoint_t  glyph,
2646
            unsigned        start_offset,
2647
            unsigned       *alternate_count  /* IN/OUT.  May be NULL. */,
2648
            hb_codepoint_t *alternate_glyphs /* OUT.     May be NULL. */)
2649
0
{
2650
0
  hb_get_glyph_alternates_dispatch_t c;
2651
0
  const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index);
2652
0
  auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs);
2653
0
  if (!ret && alternate_count) *alternate_count = 0;
2654
0
  return ret;
2655
0
}
2656
2657
2658
struct hb_position_single_dispatch_t :
2659
       hb_dispatch_context_t<hb_position_single_dispatch_t, bool>
2660
{
2661
0
  static return_t default_return_value () { return false; }
2662
0
  bool stop_sublookup_iteration (return_t r) const { return r; }
2663
2664
  private:
2665
  template <typename T, typename ...Ts> auto
2666
  _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN
2667
  ( obj.position_single (std::forward<Ts> (ds)...) )
2668
  template <typename T, typename ...Ts> auto
2669
  _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN
2670
  ( default_return_value () )
2671
  public:
2672
  template <typename T, typename ...Ts> auto
2673
  dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN
2674
  ( _dispatch (obj, hb_prioritize, std::forward<Ts> (ds)...) )
2675
};
2676
2677
/**
2678
 * hb_ot_layout_lookup_get_optical_bound:
2679
 * @font: a font.
2680
 * @lookup_index: index of the feature lookup to query.
2681
 * @direction: edge of the glyph to query.
2682
 * @glyph: a glyph id.
2683
 *
2684
 * Fetches the optical bound of a glyph positioned at the margin of text.
2685
 * The direction identifies which edge of the glyph to query.
2686
 *
2687
 * Return value: Adjustment value. Negative values mean the glyph will stick out of the margin.
2688
 *
2689
 * Since: 5.3.0
2690
 **/
2691
hb_position_t
2692
hb_ot_layout_lookup_get_optical_bound (hb_font_t      *font,
2693
               unsigned        lookup_index,
2694
               hb_direction_t  direction,
2695
               hb_codepoint_t  glyph)
2696
0
{
2697
0
  const OT::PosLookup &lookup = font->face->table.GPOS->table->get_lookup (lookup_index);
2698
0
  hb_blob_t *blob = font->face->table.GPOS->get_blob ();
2699
0
  hb_glyph_position_t pos = {0};
2700
0
  hb_position_single_dispatch_t c;
2701
0
  lookup.dispatch (&c, font, blob, direction, glyph, pos);
2702
0
  hb_position_t ret = 0;
2703
0
  switch (direction)
2704
0
  {
2705
0
    case HB_DIRECTION_LTR:
2706
0
      ret = pos.x_offset;
2707
0
      break;
2708
0
    case HB_DIRECTION_RTL:
2709
0
      ret = pos.x_advance - pos.x_offset;
2710
0
      break;
2711
0
    case HB_DIRECTION_TTB:
2712
0
      ret = pos.y_offset;
2713
0
      break;
2714
0
    case HB_DIRECTION_BTT:
2715
0
      ret = pos.y_advance - pos.y_offset;
2716
0
      break;
2717
0
    case HB_DIRECTION_INVALID:
2718
0
    default:
2719
0
      break;
2720
0
  }
2721
0
  return ret;
2722
0
}
2723
#endif
2724
2725
2726
#endif