Coverage Report

Created: 2026-10-16 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-font.cc
Line
Count
Source
1
/*
2
 * Copyright © 2009  Red Hat, Inc.
3
 * Copyright © 2012  Google, Inc.
4
 *
5
 *  This is part of HarfBuzz, a text shaping library.
6
 *
7
 * Permission is hereby granted, without written agreement and without
8
 * license or royalty fees, to use, copy, modify, and distribute this
9
 * software and its documentation for any purpose, provided that the
10
 * above copyright notice and the following two paragraphs appear in
11
 * all copies of this software.
12
 *
13
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17
 * DAMAGE.
18
 *
19
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24
 *
25
 * Red Hat Author(s): Behdad Esfahbod
26
 * Google Author(s): Behdad Esfahbod
27
 */
28
29
#include "hb.hh"
30
31
#include "hb-font.hh"
32
#include "hb-draw.hh"
33
#include "hb-paint.hh"
34
#include "hb-machinery.hh"
35
36
#include "hb-ot.h"
37
38
#include "hb-ot-var-avar-table.hh"
39
#include "hb-ot-var-fvar-table.hh"
40
41
#ifndef HB_NO_OT_FONT
42
#include "hb-ot.h"
43
#endif
44
#ifdef HAVE_FREETYPE
45
#include "hb-ft.h"
46
#endif
47
#ifdef HAVE_FONTATIONS
48
#include "hb-fontations.h"
49
#endif
50
#ifdef HAVE_CORETEXT
51
#include "hb-coretext.h"
52
#endif
53
#ifdef HAVE_DIRECTWRITE
54
#include "hb-directwrite.h"
55
#endif
56
57
58
/**
59
 * SECTION:hb-font
60
 * @title: hb-font
61
 * @short_description: Font objects
62
 * @include: hb.h
63
 *
64
 * Functions for working with font objects.
65
 *
66
 * A font object represents a font face at a specific size and with
67
 * certain other parameters (pixels-per-em, points-per-em, variation
68
 * settings) specified. Font objects are created from font face
69
 * objects, and are used as input to hb_shape(), among other things.
70
 *
71
 * Client programs can optionally pass in their own functions that
72
 * implement the basic, lower-level queries of font objects. This set
73
 * of font functions is defined by the virtual methods in
74
 * #hb_font_funcs_t.
75
 *
76
 * HarfBuzz provides a built-in set of lightweight default
77
 * functions for each method in #hb_font_funcs_t.
78
 *
79
 * The default font functions are implemented in terms of the
80
 * #hb_font_funcs_t methods of the parent font object.  This allows
81
 * client programs to override only the methods they need to, and
82
 * otherwise inherit the parent font's implementation, if any.
83
 **/
84
85
86
/*
87
 * hb_font_funcs_t
88
 */
89
90
static hb_bool_t
91
hb_font_get_font_h_extents_nil (hb_font_t         *font HB_UNUSED,
92
        void              *font_data HB_UNUSED,
93
        hb_font_extents_t *extents,
94
        void              *user_data HB_UNUSED)
95
0
{
96
0
  hb_memset (extents, 0, sizeof (*extents));
97
0
  return false;
98
0
}
99
100
static hb_bool_t
101
hb_font_get_font_h_extents_default (hb_font_t         *font,
102
            void              *font_data HB_UNUSED,
103
            hb_font_extents_t *extents,
104
            void              *user_data HB_UNUSED)
105
0
{
106
0
  hb_bool_t ret = font->parent->get_font_h_extents (extents, false);
107
0
  if (ret) {
108
0
    extents->ascender = font->parent_scale_y_distance (extents->ascender);
109
0
    extents->descender = font->parent_scale_y_distance (extents->descender);
110
0
    extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
111
0
  }
112
0
  return ret;
113
0
}
114
115
static hb_bool_t
116
hb_font_get_font_v_extents_nil (hb_font_t         *font HB_UNUSED,
117
        void              *font_data HB_UNUSED,
118
        hb_font_extents_t *extents,
119
        void              *user_data HB_UNUSED)
120
0
{
121
0
  hb_memset (extents, 0, sizeof (*extents));
122
0
  return false;
123
0
}
124
125
static hb_bool_t
126
hb_font_get_font_v_extents_default (hb_font_t         *font,
127
            void              *font_data HB_UNUSED,
128
            hb_font_extents_t *extents,
129
            void              *user_data HB_UNUSED)
130
0
{
131
0
  hb_bool_t ret = font->parent->get_font_v_extents (extents, false);
132
0
  if (ret) {
133
0
    extents->ascender = font->parent_scale_x_distance (extents->ascender);
134
0
    extents->descender = font->parent_scale_x_distance (extents->descender);
135
0
    extents->line_gap = font->parent_scale_x_distance (extents->line_gap);
136
0
  }
137
0
  return ret;
138
0
}
139
140
static hb_bool_t
141
hb_font_get_nominal_glyph_nil (hb_font_t      *font HB_UNUSED,
142
             void           *font_data HB_UNUSED,
143
             hb_codepoint_t  unicode HB_UNUSED,
144
             hb_codepoint_t *glyph,
145
             void           *user_data HB_UNUSED)
146
6.60k
{
147
6.60k
  *glyph = 0;
148
6.60k
  return false;
149
6.60k
}
150
151
static hb_bool_t
152
hb_font_get_nominal_glyph_default (hb_font_t      *font,
153
           void           *font_data HB_UNUSED,
154
           hb_codepoint_t  unicode,
155
           hb_codepoint_t *glyph,
156
           void           *user_data HB_UNUSED)
157
6.00k
{
158
6.00k
  if (font->has_nominal_glyphs_func_set ())
159
0
  {
160
0
    return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
161
0
  }
162
6.00k
  return font->parent->get_nominal_glyph (unicode, glyph);
163
6.00k
}
164
165
#define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default
166
167
static unsigned int
168
hb_font_get_nominal_glyphs_default (hb_font_t            *font,
169
            void                 *font_data HB_UNUSED,
170
            unsigned int          count,
171
            const hb_codepoint_t *first_unicode,
172
            unsigned int          unicode_stride,
173
            hb_codepoint_t       *first_glyph,
174
            unsigned int          glyph_stride,
175
            void                 *user_data HB_UNUSED)
176
1.11k
{
177
1.11k
  if (font->has_nominal_glyph_func_set ())
178
555
  {
179
555
    for (unsigned int i = 0; i < count; i++)
180
520
    {
181
520
      if (!font->get_nominal_glyph (*first_unicode, first_glyph))
182
520
  return i;
183
184
0
      first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
185
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
186
0
    }
187
35
    return count;
188
555
  }
189
190
555
  return font->parent->get_nominal_glyphs (count,
191
555
             first_unicode, unicode_stride,
192
555
             first_glyph, glyph_stride);
193
1.11k
}
194
195
static hb_bool_t
196
hb_font_get_variation_glyph_nil (hb_font_t      *font HB_UNUSED,
197
         void           *font_data HB_UNUSED,
198
         hb_codepoint_t  unicode HB_UNUSED,
199
         hb_codepoint_t  variation_selector HB_UNUSED,
200
         hb_codepoint_t *glyph,
201
         void           *user_data HB_UNUSED)
202
200
{
203
200
  *glyph = 0;
204
200
  return false;
205
200
}
206
207
static hb_bool_t
208
hb_font_get_variation_glyph_default (hb_font_t      *font,
209
             void           *font_data HB_UNUSED,
210
             hb_codepoint_t  unicode,
211
             hb_codepoint_t  variation_selector,
212
             hb_codepoint_t *glyph,
213
             void           *user_data HB_UNUSED)
214
122
{
215
122
  return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
216
122
}
217
218
219
static hb_position_t
220
hb_font_get_glyph_h_advance_nil (hb_font_t      *font,
221
         void           *font_data HB_UNUSED,
222
         hb_codepoint_t  glyph HB_UNUSED,
223
         void           *user_data HB_UNUSED)
224
13.4k
{
225
13.4k
  return font->x_scale;
226
13.4k
}
227
228
static hb_position_t
229
hb_font_get_glyph_h_advance_default (hb_font_t      *font,
230
             void           *font_data HB_UNUSED,
231
             hb_codepoint_t  glyph,
232
             void           *user_data HB_UNUSED)
233
169k
{
234
169k
  if (font->has_glyph_h_advances_func_set ())
235
168k
  {
236
168k
    hb_position_t ret;
237
168k
    font->get_glyph_h_advances (1, &glyph, 0, &ret, 0, false);
238
168k
    return ret;
239
168k
  }
240
1.33k
  return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph, false));
241
169k
}
242
243
static hb_position_t
244
hb_font_get_glyph_v_advance_nil (hb_font_t      *font,
245
         void           *font_data HB_UNUSED,
246
         hb_codepoint_t  glyph HB_UNUSED,
247
         void           *user_data HB_UNUSED)
248
182
{
249
182
  return -font->y_scale;
250
182
}
251
252
static hb_position_t
253
hb_font_get_glyph_v_advance_default (hb_font_t      *font,
254
             void           *font_data HB_UNUSED,
255
             hb_codepoint_t  glyph,
256
             void           *user_data HB_UNUSED)
257
43.4k
{
258
43.4k
  if (font->has_glyph_v_advances_func_set ())
259
43.3k
  {
260
43.3k
    hb_position_t ret;
261
43.3k
    font->get_glyph_v_advances (1, &glyph, 0, &ret, 0, false);
262
43.3k
    return ret;
263
43.3k
  }
264
104
  return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph, false));
265
43.4k
}
266
267
#define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
268
269
static void
270
hb_font_get_glyph_h_advances_default (hb_font_t*            font,
271
              void*                 font_data HB_UNUSED,
272
              unsigned int          count,
273
              const hb_codepoint_t *first_glyph,
274
              unsigned int          glyph_stride,
275
              hb_position_t        *first_advance,
276
              unsigned int          advance_stride,
277
              void                 *user_data HB_UNUSED)
278
984
{
279
984
  if (font->has_glyph_h_advance_func_set ())
280
492
  {
281
12.4k
    for (unsigned int i = 0; i < count; i++)
282
11.9k
    {
283
11.9k
      *first_advance = font->get_glyph_h_advance (*first_glyph, false);
284
11.9k
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
285
11.9k
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
286
11.9k
    }
287
492
    return;
288
492
  }
289
290
492
  font->parent->get_glyph_h_advances (count,
291
492
              first_glyph, glyph_stride,
292
492
              first_advance, advance_stride,
293
492
              false);
294
12.4k
  for (unsigned int i = 0; i < count; i++)
295
11.9k
  {
296
11.9k
    *first_advance = font->parent_scale_x_distance (*first_advance);
297
11.9k
    first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
298
11.9k
  }
299
492
}
300
301
#define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default
302
static void
303
hb_font_get_glyph_v_advances_default (hb_font_t*            font,
304
              void*                 font_data HB_UNUSED,
305
              unsigned int          count,
306
              const hb_codepoint_t *first_glyph,
307
              unsigned int          glyph_stride,
308
              hb_position_t        *first_advance,
309
              unsigned int          advance_stride,
310
              void                 *user_data HB_UNUSED)
311
0
{
312
0
  if (font->has_glyph_v_advance_func_set ())
313
0
  {
314
0
    for (unsigned int i = 0; i < count; i++)
315
0
    {
316
0
      *first_advance = font->get_glyph_v_advance (*first_glyph, false);
317
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
318
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
319
0
    }
320
0
    return;
321
0
  }
322
323
0
  font->parent->get_glyph_v_advances (count,
324
0
              first_glyph, glyph_stride,
325
0
              first_advance, advance_stride,
326
0
              false);
327
0
  for (unsigned int i = 0; i < count; i++)
328
0
  {
329
0
    *first_advance = font->parent_scale_y_distance (*first_advance);
330
0
    first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
331
0
  }
332
0
}
333
334
static hb_bool_t
335
hb_font_get_glyph_h_origin_nil (hb_font_t      *font HB_UNUSED,
336
        void           *font_data HB_UNUSED,
337
        hb_codepoint_t  glyph HB_UNUSED,
338
        hb_position_t  *x,
339
        hb_position_t  *y,
340
        void           *user_data HB_UNUSED)
341
43.5k
{
342
43.5k
  *x = *y = 0;
343
43.5k
  return true;
344
43.5k
}
345
346
static hb_bool_t
347
hb_font_get_glyph_h_origin_default (hb_font_t      *font,
348
            void           *font_data HB_UNUSED,
349
            hb_codepoint_t  glyph,
350
            hb_position_t  *x,
351
            hb_position_t  *y,
352
            void           *user_data HB_UNUSED)
353
43.4k
{
354
43.4k
  if (font->has_glyph_h_origins_func_set ())
355
0
  {
356
0
    return font->get_glyph_h_origins (1, &glyph, 0, x, 0, y, 0, false);
357
0
  }
358
43.4k
  hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
359
43.4k
  if (ret)
360
43.4k
    font->parent_scale_position (x, y);
361
43.4k
  return ret;
362
43.4k
}
363
364
static hb_bool_t
365
hb_font_get_glyph_v_origin_nil (hb_font_t      *font HB_UNUSED,
366
        void           *font_data HB_UNUSED,
367
        hb_codepoint_t  glyph HB_UNUSED,
368
        hb_position_t  *x,
369
        hb_position_t  *y,
370
        void           *user_data HB_UNUSED)
371
182
{
372
182
  return false;
373
182
}
374
375
static hb_bool_t
376
hb_font_get_glyph_v_origin_default (hb_font_t      *font,
377
            void           *font_data HB_UNUSED,
378
            hb_codepoint_t  glyph,
379
            hb_position_t  *x,
380
            hb_position_t  *y,
381
            void           *user_data HB_UNUSED)
382
43.4k
{
383
43.4k
  if (font->has_glyph_v_origins_func_set ())
384
43.3k
  {
385
43.3k
    return font->get_glyph_v_origins (1, &glyph, 0, x, 0, y, 0, false);
386
43.3k
  }
387
104
  hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
388
104
  if (ret)
389
0
    font->parent_scale_position (x, y);
390
104
  return ret;
391
43.4k
}
392
393
#define hb_font_get_glyph_h_origins_nil hb_font_get_glyph_h_origins_default
394
395
static hb_bool_t
396
hb_font_get_glyph_h_origins_default (hb_font_t *font HB_UNUSED,
397
             void *font_data HB_UNUSED,
398
             unsigned int count,
399
             const hb_codepoint_t *first_glyph HB_UNUSED,
400
             unsigned glyph_stride HB_UNUSED,
401
             hb_position_t *first_x,
402
             unsigned x_stride,
403
             hb_position_t *first_y,
404
             unsigned y_stride,
405
             void *user_data HB_UNUSED)
406
0
{
407
0
  if (font->has_glyph_h_origin_func_set ())
408
0
  {
409
0
    hb_bool_t ret = true;
410
0
    for (unsigned int i = 0; i < count; i++)
411
0
    {
412
0
      ret &= font->get_glyph_h_origin (*first_glyph, first_x, first_y, false);
413
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
414
0
      first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride);
415
0
      first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride);
416
0
    }
417
0
    return ret;
418
0
  }
419
420
0
  hb_bool_t ret = font->parent->get_glyph_h_origins (count,
421
0
                 first_glyph, glyph_stride,
422
0
                 first_x, x_stride,
423
0
                 first_y, y_stride);
424
0
  if (ret)
425
0
  {
426
0
    for (unsigned i = 0; i < count; i++)
427
0
    {
428
0
      font->parent_scale_position (first_x, first_y);
429
0
      first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride);
430
0
      first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride);
431
0
    }
432
0
  }
433
0
  return ret;
434
0
}
435
436
#define hb_font_get_glyph_v_origins_nil hb_font_get_glyph_v_origins_default
437
438
static hb_bool_t
439
hb_font_get_glyph_v_origins_default (hb_font_t *font HB_UNUSED,
440
             void *font_data HB_UNUSED,
441
             unsigned int count,
442
             const hb_codepoint_t *first_glyph HB_UNUSED,
443
             unsigned glyph_stride HB_UNUSED,
444
             hb_position_t *first_x,
445
             unsigned x_stride,
446
             hb_position_t *first_y,
447
             unsigned y_stride,
448
             void *user_data HB_UNUSED)
449
0
{
450
0
  if (font->has_glyph_v_origin_func_set ())
451
0
  {
452
0
    hb_bool_t ret = true;
453
0
    for (unsigned int i = 0; i < count; i++)
454
0
    {
455
0
      ret &= font->get_glyph_v_origin (*first_glyph, first_x, first_y, false);
456
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
457
0
      first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride);
458
0
      first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride);
459
0
    }
460
0
    return ret;
461
0
  }
462
463
0
  hb_bool_t ret = font->parent->get_glyph_v_origins (count,
464
0
                 first_glyph, glyph_stride,
465
0
                 first_x, x_stride,
466
0
                 first_y, y_stride);
467
0
  if (ret)
468
0
  {
469
0
    for (unsigned i = 0; i < count; i++)
470
0
    {
471
0
      font->parent_scale_position (first_x, first_y);
472
0
      first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride);
473
0
      first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride);
474
0
    }
475
0
  }
476
0
  return ret;
477
0
}
478
479
static hb_position_t
480
hb_font_get_glyph_h_kerning_nil (hb_font_t      *font HB_UNUSED,
481
         void           *font_data HB_UNUSED,
482
         hb_codepoint_t  left_glyph HB_UNUSED,
483
         hb_codepoint_t  right_glyph HB_UNUSED,
484
         void           *user_data HB_UNUSED)
485
0
{
486
0
  return 0;
487
0
}
488
489
static hb_position_t
490
hb_font_get_glyph_h_kerning_default (hb_font_t      *font,
491
             void           *font_data HB_UNUSED,
492
             hb_codepoint_t  left_glyph,
493
             hb_codepoint_t  right_glyph,
494
             void           *user_data HB_UNUSED)
495
0
{
496
0
  return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
497
0
}
498
499
#ifndef HB_DISABLE_DEPRECATED
500
static hb_position_t
501
hb_font_get_glyph_v_kerning_nil (hb_font_t      *font HB_UNUSED,
502
         void           *font_data HB_UNUSED,
503
         hb_codepoint_t  top_glyph HB_UNUSED,
504
         hb_codepoint_t  bottom_glyph HB_UNUSED,
505
         void           *user_data HB_UNUSED)
506
0
{
507
0
  return 0;
508
0
}
509
510
static hb_position_t
511
hb_font_get_glyph_v_kerning_default (hb_font_t      *font,
512
             void           *font_data HB_UNUSED,
513
             hb_codepoint_t  top_glyph,
514
             hb_codepoint_t  bottom_glyph,
515
             void           *user_data HB_UNUSED)
516
0
{
517
0
  return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
518
0
}
519
#endif
520
521
static hb_bool_t
522
hb_font_get_glyph_extents_nil (hb_font_t          *font HB_UNUSED,
523
             void               *font_data HB_UNUSED,
524
             hb_codepoint_t      glyph HB_UNUSED,
525
             hb_glyph_extents_t *extents,
526
             void               *user_data HB_UNUSED)
527
1.34k
{
528
1.34k
  hb_memset (extents, 0, sizeof (*extents));
529
1.34k
  return false;
530
1.34k
}
531
532
static hb_bool_t
533
hb_font_get_glyph_extents_default (hb_font_t          *font,
534
           void               *font_data HB_UNUSED,
535
           hb_codepoint_t      glyph,
536
           hb_glyph_extents_t *extents,
537
           void               *user_data HB_UNUSED)
538
1.18k
{
539
1.18k
  hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents, false);
540
1.18k
  if (ret) {
541
0
    font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
542
0
    font->parent_scale_distance (&extents->width, &extents->height);
543
0
  }
544
1.18k
  return ret;
545
1.18k
}
546
547
static hb_bool_t
548
hb_font_get_glyph_contour_point_nil (hb_font_t      *font HB_UNUSED,
549
             void           *font_data HB_UNUSED,
550
             hb_codepoint_t  glyph HB_UNUSED,
551
             unsigned int    point_index HB_UNUSED,
552
             hb_position_t  *x,
553
             hb_position_t  *y,
554
             void           *user_data HB_UNUSED)
555
396k
{
556
396k
  *x = *y = 0;
557
396k
  return false;
558
396k
}
559
560
static hb_bool_t
561
hb_font_get_glyph_contour_point_default (hb_font_t      *font,
562
           void           *font_data HB_UNUSED,
563
           hb_codepoint_t  glyph,
564
           unsigned int    point_index,
565
           hb_position_t  *x,
566
           hb_position_t  *y,
567
           void           *user_data HB_UNUSED)
568
396k
{
569
396k
  hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y, false);
570
396k
  if (ret)
571
0
    font->parent_scale_position (x, y);
572
396k
  return ret;
573
396k
}
574
575
static hb_bool_t
576
hb_font_get_glyph_name_nil (hb_font_t      *font HB_UNUSED,
577
          void           *font_data HB_UNUSED,
578
          hb_codepoint_t  glyph HB_UNUSED,
579
          char           *name,
580
          unsigned int    size,
581
          void           *user_data HB_UNUSED)
582
182
{
583
182
  if (size) *name = '\0';
584
182
  return false;
585
182
}
586
587
static hb_bool_t
588
hb_font_get_glyph_name_default (hb_font_t      *font,
589
        void           *font_data HB_UNUSED,
590
        hb_codepoint_t  glyph,
591
        char           *name,
592
        unsigned int    size,
593
        void           *user_data HB_UNUSED)
594
104
{
595
104
  return font->parent->get_glyph_name (glyph, name, size);
596
104
}
597
598
static hb_bool_t
599
hb_font_get_glyph_from_name_nil (hb_font_t      *font HB_UNUSED,
600
         void           *font_data HB_UNUSED,
601
         const char     *name HB_UNUSED,
602
         int             len HB_UNUSED, /* -1 means nul-terminated */
603
         hb_codepoint_t *glyph,
604
         void           *user_data HB_UNUSED)
605
182
{
606
182
  *glyph = 0;
607
182
  return false;
608
182
}
609
610
static hb_bool_t
611
hb_font_get_glyph_from_name_default (hb_font_t      *font,
612
             void           *font_data HB_UNUSED,
613
             const char     *name,
614
             int             len, /* -1 means nul-terminated */
615
             hb_codepoint_t *glyph,
616
             void           *user_data HB_UNUSED)
617
104
{
618
104
  return font->parent->get_glyph_from_name (name, len, glyph);
619
104
}
620
621
static hb_bool_t
622
hb_font_draw_glyph_or_fail_nil (hb_font_t       *font HB_UNUSED,
623
        void            *font_data HB_UNUSED,
624
        hb_codepoint_t   glyph,
625
        hb_draw_funcs_t *draw_funcs,
626
        void            *draw_data,
627
        void            *user_data HB_UNUSED)
628
854
{
629
854
  return false;
630
854
}
631
632
static hb_bool_t
633
hb_font_paint_glyph_or_fail_nil (hb_font_t *font HB_UNUSED,
634
         void *font_data HB_UNUSED,
635
         hb_codepoint_t glyph HB_UNUSED,
636
         hb_paint_funcs_t *paint_funcs HB_UNUSED,
637
         void *paint_data HB_UNUSED,
638
         unsigned int palette HB_UNUSED,
639
         hb_color_t foreground HB_UNUSED,
640
         void *user_data HB_UNUSED)
641
672
{
642
672
  return false;
643
672
}
644
645
typedef struct hb_font_draw_glyph_default_adaptor_t {
646
  hb_draw_funcs_t *draw_funcs;
647
  void      *draw_data;
648
  float      x_scale;
649
  float      y_scale;
650
} hb_font_draw_glyph_default_adaptor_t;
651
652
static void
653
hb_draw_move_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED,
654
       void *draw_data,
655
       hb_draw_state_t *st,
656
       float to_x, float to_y,
657
       void *user_data HB_UNUSED)
658
0
{
659
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
660
0
  float x_scale = adaptor->x_scale;
661
0
  float y_scale = adaptor->y_scale;
662
663
0
  adaptor->draw_funcs->emit_move_to (adaptor->draw_data, *st,
664
0
             x_scale * to_x, y_scale * to_y);
665
0
}
666
667
static void
668
hb_draw_line_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
669
       hb_draw_state_t *st,
670
       float to_x, float to_y,
671
       void *user_data HB_UNUSED)
672
0
{
673
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
674
0
  float x_scale = adaptor->x_scale;
675
0
  float y_scale = adaptor->y_scale;
676
677
0
  st->current_x = st->current_x * x_scale;
678
0
  st->current_y = st->current_y * y_scale;
679
680
0
  adaptor->draw_funcs->emit_line_to (adaptor->draw_data, *st,
681
0
             x_scale * to_x, y_scale * to_y);
682
0
}
683
684
static void
685
hb_draw_quadratic_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
686
            hb_draw_state_t *st,
687
            float control_x, float control_y,
688
            float to_x, float to_y,
689
            void *user_data HB_UNUSED)
690
0
{
691
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
692
0
  float x_scale = adaptor->x_scale;
693
0
  float y_scale = adaptor->y_scale;
694
695
0
  st->current_x = st->current_x * x_scale;
696
0
  st->current_y = st->current_y * y_scale;
697
698
0
  adaptor->draw_funcs->emit_quadratic_to (adaptor->draw_data, *st,
699
0
            x_scale * control_x, y_scale * control_y,
700
0
            x_scale * to_x, y_scale * to_y);
701
0
}
702
703
static void
704
hb_draw_cubic_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
705
        hb_draw_state_t *st,
706
        float control1_x, float control1_y,
707
        float control2_x, float control2_y,
708
        float to_x, float to_y,
709
        void *user_data HB_UNUSED)
710
0
{
711
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
712
0
  float x_scale = adaptor->x_scale;
713
0
  float y_scale = adaptor->y_scale;
714
715
0
  st->current_x = st->current_x * x_scale;
716
0
  st->current_y = st->current_y * y_scale;
717
718
0
  adaptor->draw_funcs->emit_cubic_to (adaptor->draw_data, *st,
719
0
              x_scale * control1_x, y_scale * control1_y,
720
0
              x_scale * control2_x, y_scale * control2_y,
721
0
              x_scale * to_x, y_scale * to_y);
722
0
}
723
724
static void
725
hb_draw_close_path_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
726
          hb_draw_state_t *st,
727
          void *user_data HB_UNUSED)
728
0
{
729
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
730
731
0
  adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st);
732
0
}
733
734
static hb_bool_t
735
hb_draw_set_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
736
          int64_t budget,
737
          void *user_data HB_UNUSED)
738
0
{
739
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
740
0
  return adaptor->draw_funcs->set_budget (adaptor->draw_data, budget);
741
0
}
742
743
static int64_t
744
hb_draw_get_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
745
          void *user_data HB_UNUSED)
746
0
{
747
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
748
0
  return adaptor->draw_funcs->get_budget (adaptor->draw_data);
749
0
}
750
751
static int64_t *
752
hb_draw_get_budget_remaining_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
753
              void *user_data HB_UNUSED)
754
0
{
755
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
756
0
  return adaptor->draw_funcs->get_budget_remaining_ptr (adaptor->draw_data);
757
0
}
758
759
static const hb_draw_funcs_t _hb_draw_funcs_default = {
760
  HB_OBJECT_HEADER_STATIC,
761
762
  {
763
#define HB_DRAW_FUNC_IMPLEMENT(name) hb_draw_##name##_default,
764
    HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS
765
#undef HB_DRAW_FUNC_IMPLEMENT
766
  }
767
};
768
769
static hb_bool_t
770
hb_font_draw_glyph_or_fail_default (hb_font_t       *font,
771
            void            *font_data HB_UNUSED,
772
            hb_codepoint_t   glyph,
773
            hb_draw_funcs_t *draw_funcs,
774
            void            *draw_data,
775
            void            *user_data HB_UNUSED)
776
698
{
777
698
  hb_font_draw_glyph_default_adaptor_t adaptor = {
778
698
    draw_funcs,
779
698
    draw_data,
780
698
    font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0.f,
781
698
    font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f
782
698
  };
783
784
698
  return font->parent->draw_glyph_or_fail (glyph,
785
698
             const_cast<hb_draw_funcs_t *> (&_hb_draw_funcs_default),
786
698
             &adaptor,
787
698
             false);
788
698
}
789
790
static hb_bool_t
791
hb_font_paint_glyph_or_fail_default (hb_font_t *font,
792
             void *font_data,
793
             hb_codepoint_t glyph,
794
             hb_paint_funcs_t *paint_funcs,
795
             void *paint_data,
796
             unsigned int palette,
797
             hb_color_t foreground,
798
             void *user_data)
799
594
{
800
594
  paint_funcs->push_transform (paint_data,
801
594
    font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0, 0,
802
594
    0, font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0,
803
594
    0, 0);
804
805
594
  bool ret = font->parent->paint_glyph_or_fail (glyph, paint_funcs, paint_data, palette, foreground);
806
807
594
  paint_funcs->pop_transform (paint_data);
808
809
594
  return ret;
810
594
}
811
812
DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
813
{
814
  HB_OBJECT_HEADER_STATIC,
815
816
  nullptr,
817
  nullptr,
818
  {
819
    {
820
#define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_nil,
821
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
822
#undef HB_FONT_FUNC_IMPLEMENT
823
    }
824
  }
825
};
826
827
static const hb_font_funcs_t _hb_font_funcs_default = {
828
  HB_OBJECT_HEADER_STATIC,
829
830
  nullptr,
831
  nullptr,
832
  {
833
    {
834
#define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_default,
835
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
836
#undef HB_FONT_FUNC_IMPLEMENT
837
    }
838
  }
839
};
840
841
842
/**
843
 * hb_font_funcs_create:
844
 *
845
 * Creates a new #hb_font_funcs_t structure of font functions.
846
 *
847
 * Return value: (transfer full): The font-functions structure
848
 *
849
 * Since: 0.9.2
850
 **/
851
hb_font_funcs_t *
852
hb_font_funcs_create ()
853
1
{
854
1
  hb_font_funcs_t *ffuncs;
855
856
1
  if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
857
0
    return hb_font_funcs_get_empty ();
858
859
1
  ffuncs->get = _hb_font_funcs_default.get;
860
861
1
  return ffuncs;
862
1
}
863
864
/**
865
 * hb_font_funcs_get_empty:
866
 *
867
 * Fetches an empty font-functions structure.
868
 *
869
 * Return value: (transfer full): The font-functions structure
870
 *
871
 * Since: 0.9.2
872
 **/
873
hb_font_funcs_t *
874
hb_font_funcs_get_empty ()
875
88.0k
{
876
88.0k
  return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
877
88.0k
}
878
879
/**
880
 * hb_font_funcs_reference: (skip)
881
 * @ffuncs: The font-functions structure
882
 *
883
 * Increases the reference count on a font-functions structure.
884
 *
885
 * Return value: The font-functions structure
886
 *
887
 * Since: 0.9.2
888
 **/
889
hb_font_funcs_t *
890
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
891
43.6k
{
892
43.6k
  return hb_object_reference (ffuncs);
893
43.6k
}
894
895
/**
896
 * hb_font_funcs_destroy: (skip)
897
 * @ffuncs: The font-functions structure
898
 *
899
 * Decreases the reference count on a font-functions structure. When
900
 * the reference count reaches zero, the font-functions structure is
901
 * destroyed, freeing all memory.
902
 *
903
 * Since: 0.9.2
904
 **/
905
void
906
hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
907
87.3k
{
908
87.3k
  if (!hb_object_destroy (ffuncs)) return;
909
910
1
  if (ffuncs->destroy)
911
0
  {
912
0
#define HB_FONT_FUNC_IMPLEMENT(get_,name) if (ffuncs->destroy->name) \
913
0
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name);
914
0
    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
915
0
#undef HB_FONT_FUNC_IMPLEMENT
916
0
  }
917
918
1
  hb_free (ffuncs->destroy);
919
1
  hb_free (ffuncs->user_data);
920
921
1
  hb_free (ffuncs);
922
1
}
923
924
/**
925
 * hb_font_funcs_set_user_data: (skip)
926
 * @ffuncs: The font-functions structure
927
 * @key: The user-data key to set
928
 * @data: A pointer to the user data set
929
 * @destroy: (nullable): A callback to call when @data is not needed anymore
930
 * @replace: Whether to replace an existing data with the same key
931
 *
932
 * Attaches a user-data key/data pair to the specified font-functions structure.
933
 *
934
 * Return value: `true` if success, `false` otherwise
935
 *
936
 * Since: 0.9.2
937
 **/
938
hb_bool_t
939
hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
940
           hb_user_data_key_t *key,
941
           void *              data,
942
           hb_destroy_func_t   destroy /* May be NULL. */,
943
           hb_bool_t           replace)
944
0
{
945
0
  return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
946
0
}
947
948
/**
949
 * hb_font_funcs_get_user_data: (skip)
950
 * @ffuncs: The font-functions structure
951
 * @key: The user-data key to query
952
 *
953
 * Fetches the user data associated with the specified key,
954
 * attached to the specified font-functions structure.
955
 *
956
 * Return value: (transfer none): A pointer to the user data
957
 *
958
 * Since: 0.9.2
959
 **/
960
void *
961
hb_font_funcs_get_user_data (const hb_font_funcs_t *ffuncs,
962
           hb_user_data_key_t    *key)
963
0
{
964
0
  return hb_object_get_user_data (ffuncs, key);
965
0
}
966
967
968
/**
969
 * hb_font_funcs_make_immutable:
970
 * @ffuncs: The font-functions structure
971
 *
972
 * Makes a font-functions structure immutable.
973
 *
974
 * Since: 0.9.2
975
 **/
976
void
977
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
978
1
{
979
1
  if (hb_object_is_immutable (ffuncs))
980
0
    return;
981
982
1
  hb_object_make_immutable (ffuncs);
983
1
}
984
985
/**
986
 * hb_font_funcs_is_immutable:
987
 * @ffuncs: The font-functions structure
988
 *
989
 * Tests whether a font-functions structure is immutable.
990
 *
991
 * Return value: `true` if @ffuncs is immutable, `false` otherwise
992
 *
993
 * Since: 0.9.2
994
 **/
995
hb_bool_t
996
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
997
0
{
998
0
  return hb_object_is_immutable (ffuncs);
999
0
}
1000
1001
1002
static bool
1003
_hb_font_funcs_set_preamble (hb_font_funcs_t    *ffuncs,
1004
           bool                func_is_null,
1005
           void              **user_data,
1006
           hb_destroy_func_t  *destroy)
1007
13
{
1008
13
  if (hb_object_is_immutable (ffuncs))
1009
0
  {
1010
0
    if (*destroy)
1011
0
      (*destroy) (*user_data);
1012
0
    return false;
1013
0
  }
1014
1015
13
  if (func_is_null)
1016
0
  {
1017
0
    if (*destroy)
1018
0
      (*destroy) (*user_data);
1019
0
    *destroy = nullptr;
1020
0
    *user_data = nullptr;
1021
0
  }
1022
1023
13
  return true;
1024
13
}
1025
1026
static bool
1027
_hb_font_funcs_set_middle (hb_font_funcs_t   *ffuncs,
1028
         void              *user_data,
1029
         hb_destroy_func_t  destroy)
1030
13
{
1031
13
  auto destroy_guard = hb_make_scope_guard ([&]() {
1032
0
    if (destroy) destroy (user_data);
1033
0
  });
1034
1035
13
  if (user_data && !ffuncs->user_data)
1036
0
  {
1037
0
    ffuncs->user_data = (decltype (ffuncs->user_data)) hb_calloc (1, sizeof (*ffuncs->user_data));
1038
0
    if (unlikely (!ffuncs->user_data))
1039
0
      return false;
1040
0
  }
1041
13
  if (destroy && !ffuncs->destroy)
1042
0
  {
1043
0
    ffuncs->destroy = (decltype (ffuncs->destroy)) hb_calloc (1, sizeof (*ffuncs->destroy));
1044
0
    if (unlikely (!ffuncs->destroy))
1045
0
      return false;
1046
0
  }
1047
1048
13
  destroy_guard.release ();
1049
13
  return true;
1050
13
}
1051
1052
#define HB_FONT_FUNC_IMPLEMENT(get_,name) \
1053
                   \
1054
void                                                                     \
1055
hb_font_funcs_set_##name##_func (hb_font_funcs_t             *ffuncs,    \
1056
         hb_font_##get_##name##_func_t func,     \
1057
         void                        *user_data, \
1058
13
         hb_destroy_func_t            destroy)   \
1059
13
{                                                                        \
1060
13
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
13
      return;                                                            \
1062
13
                   \
1063
13
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
13
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
13
                                                                         \
1066
13
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
13
      return;                                                            \
1068
13
                   \
1069
13
  if (func)                                                              \
1070
13
    ffuncs->get.f.name = func;                                           \
1071
13
  else                                                                   \
1072
13
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
13
                   \
1074
13
  if (ffuncs->user_data)                                                 \
1075
13
    ffuncs->user_data->name = user_data;                                 \
1076
13
  if (ffuncs->destroy)                                                   \
1077
13
    ffuncs->destroy->name = destroy;                                     \
1078
13
}
hb_font_funcs_set_font_h_extents_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_font_v_extents_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_nominal_glyph_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_nominal_glyphs_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_variation_glyph_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
Unexecuted instantiation: hb_font_funcs_set_glyph_h_advance_func
Unexecuted instantiation: hb_font_funcs_set_glyph_v_advance_func
hb_font_funcs_set_glyph_h_advances_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_glyph_v_advances_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
Unexecuted instantiation: hb_font_funcs_set_glyph_h_origin_func
Unexecuted instantiation: hb_font_funcs_set_glyph_v_origin_func
Unexecuted instantiation: hb_font_funcs_set_glyph_h_origins_func
hb_font_funcs_set_glyph_v_origins_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
Unexecuted instantiation: hb_font_funcs_set_glyph_h_kerning_func
hb_font_funcs_set_glyph_extents_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
Unexecuted instantiation: hb_font_funcs_set_glyph_contour_point_func
hb_font_funcs_set_glyph_name_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_glyph_from_name_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_draw_glyph_or_fail_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
hb_font_funcs_set_paint_glyph_or_fail_func
Line
Count
Source
1058
1
         hb_destroy_func_t            destroy)   \
1059
1
{                                                                        \
1060
1
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
1
      return;                                                            \
1062
1
                   \
1063
1
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
1
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
1
                                                                         \
1066
1
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
1
      return;                                                            \
1068
1
                   \
1069
1
  if (func)                                                              \
1070
1
    ffuncs->get.f.name = func;                                           \
1071
1
  else                                                                   \
1072
1
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
1
                   \
1074
1
  if (ffuncs->user_data)                                                 \
1075
1
    ffuncs->user_data->name = user_data;                                 \
1076
1
  if (ffuncs->destroy)                                                   \
1077
1
    ffuncs->destroy->name = destroy;                                     \
1078
1
}
1079
1080
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
1081
#undef HB_FONT_FUNC_IMPLEMENT
1082
1083
bool
1084
hb_font_t::has_func_set (unsigned int i)
1085
5.43M
{
1086
5.43M
  return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
1087
5.43M
}
1088
1089
bool
1090
hb_font_t::has_func (unsigned int i)
1091
5.12M
{
1092
5.12M
  return has_func_set (i) ||
1093
5.08M
   (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
1094
5.12M
}
1095
1096
/* Public getters */
1097
1098
/**
1099
 * hb_font_get_h_extents:
1100
 * @font: #hb_font_t to work upon
1101
 * @extents: (out): The font extents retrieved
1102
 *
1103
 * Fetches the extents for a specified font, for horizontal
1104
 * text segments.
1105
 *
1106
 * Return value: `true` if data found, `false` otherwise
1107
 *
1108
 * Since: 1.1.3
1109
 **/
1110
hb_bool_t
1111
hb_font_get_h_extents (hb_font_t         *font,
1112
           hb_font_extents_t *extents)
1113
0
{
1114
0
  return font->get_font_h_extents (extents);
1115
0
}
1116
1117
/**
1118
 * hb_font_get_v_extents:
1119
 * @font: #hb_font_t to work upon
1120
 * @extents: (out): The font extents retrieved
1121
 *
1122
 * Fetches the extents for a specified font, for vertical
1123
 * text segments.
1124
 *
1125
 * Return value: `true` if data found, `false` otherwise
1126
 *
1127
 * Since: 1.1.3
1128
 **/
1129
hb_bool_t
1130
hb_font_get_v_extents (hb_font_t         *font,
1131
           hb_font_extents_t *extents)
1132
0
{
1133
0
  return font->get_font_v_extents (extents);
1134
0
}
1135
1136
/**
1137
 * hb_font_get_glyph:
1138
 * @font: #hb_font_t to work upon
1139
 * @unicode: The Unicode code point to query
1140
 * @variation_selector: A variation-selector code point
1141
 * @glyph: (out): The glyph ID retrieved
1142
 *
1143
 * Fetches the glyph ID for a Unicode code point in the specified
1144
 * font, with an optional variation selector.
1145
 *
1146
 * If @variation_selector is 0, calls hb_font_get_nominal_glyph();
1147
 * otherwise calls hb_font_get_variation_glyph().
1148
 *
1149
 * Return value: `true` if data found, `false` otherwise
1150
 *
1151
 * Since: 0.9.2
1152
 **/
1153
hb_bool_t
1154
hb_font_get_glyph (hb_font_t      *font,
1155
       hb_codepoint_t  unicode,
1156
       hb_codepoint_t  variation_selector,
1157
       hb_codepoint_t *glyph)
1158
678k
{
1159
678k
  if (unlikely (variation_selector))
1160
0
    return font->get_variation_glyph (unicode, variation_selector, glyph);
1161
678k
  return font->get_nominal_glyph (unicode, glyph);
1162
678k
}
1163
1164
/**
1165
 * hb_font_get_nominal_glyph:
1166
 * @font: #hb_font_t to work upon
1167
 * @unicode: The Unicode code point to query
1168
 * @glyph: (out): The glyph ID retrieved
1169
 *
1170
 * Fetches the nominal glyph ID for a Unicode code point in the
1171
 * specified font.
1172
 *
1173
 * This version of the function should not be used to fetch glyph IDs
1174
 * for code points modified by variation selectors. For variation-selector
1175
 * support, user hb_font_get_variation_glyph() or use hb_font_get_glyph().
1176
 *
1177
 * Return value: `true` if data found, `false` otherwise
1178
 *
1179
 * Since: 1.2.3
1180
 **/
1181
hb_bool_t
1182
hb_font_get_nominal_glyph (hb_font_t      *font,
1183
         hb_codepoint_t  unicode,
1184
         hb_codepoint_t *glyph)
1185
74.7k
{
1186
74.7k
  return font->get_nominal_glyph (unicode, glyph);
1187
74.7k
}
1188
1189
/**
1190
 * hb_font_get_nominal_glyphs:
1191
 * @font: #hb_font_t to work upon
1192
 * @count: number of code points to query
1193
 * @first_unicode: The first Unicode code point to query
1194
 * @unicode_stride: The stride between successive code points
1195
 * @first_glyph: (out): The first glyph ID retrieved
1196
 * @glyph_stride: The stride between successive glyph IDs
1197
 *
1198
 * Fetches the nominal glyph IDs for a sequence of Unicode code points. Glyph
1199
 * IDs must be returned in a #hb_codepoint_t output parameter. Stops at the
1200
 * first unsupported glyph ID.
1201
 *
1202
 * Return value: the number of code points processed
1203
 *
1204
 * Since: 2.6.3
1205
 **/
1206
unsigned int
1207
hb_font_get_nominal_glyphs (hb_font_t *font,
1208
          unsigned int count,
1209
          const hb_codepoint_t *first_unicode,
1210
          unsigned int unicode_stride,
1211
          hb_codepoint_t *first_glyph,
1212
          unsigned int glyph_stride)
1213
0
{
1214
0
  return font->get_nominal_glyphs (count,
1215
0
           first_unicode, unicode_stride,
1216
0
           first_glyph, glyph_stride);
1217
0
}
1218
1219
/**
1220
 * hb_font_get_variation_glyph:
1221
 * @font: #hb_font_t to work upon
1222
 * @unicode: The Unicode code point to query
1223
 * @variation_selector: The  variation-selector code point to query
1224
 * @glyph: (out): The glyph ID retrieved
1225
 *
1226
 * Fetches the glyph ID for a Unicode code point when followed by
1227
 * by the specified variation-selector code point, in the specified
1228
 * font.
1229
 *
1230
 * Return value: `true` if data found, `false` otherwise
1231
 *
1232
 * Since: 1.2.3
1233
 **/
1234
hb_bool_t
1235
hb_font_get_variation_glyph (hb_font_t      *font,
1236
           hb_codepoint_t  unicode,
1237
           hb_codepoint_t  variation_selector,
1238
           hb_codepoint_t *glyph)
1239
43.5k
{
1240
43.5k
  return font->get_variation_glyph (unicode, variation_selector, glyph);
1241
43.5k
}
1242
1243
/**
1244
 * hb_font_get_glyph_h_advance:
1245
 * @font: #hb_font_t to work upon
1246
 * @glyph: The glyph ID to query
1247
 *
1248
 * Fetches the advance for a glyph ID in the specified font,
1249
 * for horizontal text segments.
1250
 *
1251
 * Return value: The advance of @glyph within @font
1252
 *
1253
 * Since: 0.9.2
1254
 **/
1255
hb_position_t
1256
hb_font_get_glyph_h_advance (hb_font_t      *font,
1257
           hb_codepoint_t  glyph)
1258
43.7k
{
1259
43.7k
  return font->get_glyph_h_advance (glyph);
1260
43.7k
}
1261
1262
/**
1263
 * hb_font_get_glyph_v_advance:
1264
 * @font: #hb_font_t to work upon
1265
 * @glyph: The glyph ID to query
1266
 *
1267
 * Fetches the advance for a glyph ID in the specified font,
1268
 * for vertical text segments.
1269
 *
1270
 * Return value: The advance of @glyph within @font
1271
 *
1272
 * Since: 0.9.2
1273
 **/
1274
hb_position_t
1275
hb_font_get_glyph_v_advance (hb_font_t      *font,
1276
           hb_codepoint_t  glyph)
1277
43.5k
{
1278
43.5k
  return font->get_glyph_v_advance (glyph);
1279
43.5k
}
1280
1281
/**
1282
 * hb_font_get_glyph_h_advances:
1283
 * @font: #hb_font_t to work upon
1284
 * @count: The number of glyph IDs in the sequence queried
1285
 * @first_glyph: The first glyph ID to query
1286
 * @glyph_stride: The stride between successive glyph IDs
1287
 * @first_advance: (out): The first advance retrieved
1288
 * @advance_stride: The stride between successive advances
1289
 *
1290
 * Fetches the advances for a sequence of glyph IDs in the specified
1291
 * font, for horizontal text segments.
1292
 *
1293
 * Since: 1.8.6
1294
 **/
1295
void
1296
hb_font_get_glyph_h_advances (hb_font_t*            font,
1297
            unsigned int          count,
1298
            const hb_codepoint_t *first_glyph,
1299
            unsigned              glyph_stride,
1300
            hb_position_t        *first_advance,
1301
            unsigned              advance_stride)
1302
0
{
1303
0
  font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
1304
0
}
1305
/**
1306
 * hb_font_get_glyph_v_advances:
1307
 * @font: #hb_font_t to work upon
1308
 * @count: The number of glyph IDs in the sequence queried
1309
 * @first_glyph: The first glyph ID to query
1310
 * @glyph_stride: The stride between successive glyph IDs
1311
 * @first_advance: (out): The first advance retrieved
1312
 * @advance_stride: (out): The stride between successive advances
1313
 *
1314
 * Fetches the advances for a sequence of glyph IDs in the specified
1315
 * font, for vertical text segments.
1316
 *
1317
 * Since: 1.8.6
1318
 **/
1319
void
1320
hb_font_get_glyph_v_advances (hb_font_t*            font,
1321
            unsigned int          count,
1322
            const hb_codepoint_t *first_glyph,
1323
            unsigned              glyph_stride,
1324
            hb_position_t        *first_advance,
1325
            unsigned              advance_stride)
1326
0
{
1327
0
  font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
1328
0
}
1329
1330
/**
1331
 * hb_font_get_glyph_h_origin:
1332
 * @font: #hb_font_t to work upon
1333
 * @glyph: The glyph ID to query
1334
 * @x: (out): The X coordinate of the origin
1335
 * @y: (out): The Y coordinate of the origin
1336
 *
1337
 * Fetches the (X,Y) coordinates of the origin for a glyph ID
1338
 * in the specified font, for horizontal text segments.
1339
 *
1340
 * Return value: `true` if data found, `false` otherwise
1341
 *
1342
 * Since: 0.9.2
1343
 **/
1344
hb_bool_t
1345
hb_font_get_glyph_h_origin (hb_font_t      *font,
1346
          hb_codepoint_t  glyph,
1347
          hb_position_t  *x,
1348
          hb_position_t  *y)
1349
43.5k
{
1350
43.5k
  return font->get_glyph_h_origin (glyph, x, y);
1351
43.5k
}
1352
1353
/**
1354
 * hb_font_get_glyph_v_origin:
1355
 * @font: #hb_font_t to work upon
1356
 * @glyph: The glyph ID to query
1357
 * @x: (out): The X coordinate of the origin
1358
 * @y: (out): The Y coordinate of the origin
1359
 *
1360
 * Fetches the (X,Y) coordinates of the origin for a glyph ID
1361
 * in the specified font, for vertical text segments.
1362
 *
1363
 * Return value: `true` if data found, `false` otherwise
1364
 *
1365
 * Since: 0.9.2
1366
 **/
1367
hb_bool_t
1368
hb_font_get_glyph_v_origin (hb_font_t      *font,
1369
          hb_codepoint_t  glyph,
1370
          hb_position_t  *x,
1371
          hb_position_t  *y)
1372
43.5k
{
1373
43.5k
  return font->get_glyph_v_origin (glyph, x, y);
1374
43.5k
}
1375
1376
/**
1377
 * hb_font_get_glyph_h_origins:
1378
 * @font: #hb_font_t to work upon
1379
 * @count: The number of glyph IDs in the sequence queried
1380
 * @first_glyph: The first glyph ID to query
1381
 * @glyph_stride: The stride between successive glyph IDs
1382
 * @first_x: (out): The first X coordinate of the origin retrieved
1383
 * @x_stride: The stride between successive X coordinates
1384
 * @first_y: (out): The first Y coordinate of the origin retrieved
1385
 * @y_stride: The stride between successive Y coordinates
1386
 *
1387
 * Fetches the (X,Y) coordinates of the origin for requested glyph IDs
1388
 * in the specified font, for horizontal text segments.
1389
 *
1390
 * Return value: `true` if data found, `false` otherwise
1391
 *
1392
 * Since: 11.3.0
1393
 **/
1394
hb_bool_t
1395
hb_font_get_glyph_h_origins (hb_font_t      *font,
1396
           unsigned int    count,
1397
           const hb_codepoint_t *first_glyph,
1398
           unsigned int    glyph_stride,
1399
           hb_position_t  *first_x,
1400
           unsigned int    x_stride,
1401
           hb_position_t  *first_y,
1402
           unsigned int    y_stride)
1403
1404
0
{
1405
0
  return font->get_glyph_h_origins (count,
1406
0
            first_glyph, glyph_stride,
1407
0
            first_x, x_stride,
1408
0
            first_y, y_stride);
1409
0
}
1410
1411
/**
1412
 * hb_font_get_glyph_v_origins:
1413
 * @font: #hb_font_t to work upon
1414
 * @count: The number of glyph IDs in the sequence queried
1415
 * @first_glyph: The first glyph ID to query
1416
 * @glyph_stride: The stride between successive glyph IDs
1417
 * @first_x: (out): The first X coordinate of the origin retrieved
1418
 * @x_stride: The stride between successive X coordinates
1419
 * @first_y: (out): The first Y coordinate of the origin retrieved
1420
 * @y_stride: The stride between successive Y coordinates
1421
 *
1422
 * Fetches the (X,Y) coordinates of the origin for requested glyph IDs
1423
 * in the specified font, for vertical text segments.
1424
 *
1425
 * Return value: `true` if data found, `false` otherwise
1426
 *
1427
 * Since: 11.3.0
1428
 **/
1429
hb_bool_t
1430
hb_font_get_glyph_v_origins (hb_font_t      *font,
1431
           unsigned int    count,
1432
           const hb_codepoint_t *first_glyph,
1433
           unsigned int    glyph_stride,
1434
           hb_position_t  *first_x,
1435
           unsigned int    x_stride,
1436
           hb_position_t  *first_y,
1437
           unsigned int    y_stride)
1438
1439
0
{
1440
0
  return font->get_glyph_v_origins (count,
1441
0
            first_glyph, glyph_stride,
1442
0
            first_x, x_stride,
1443
0
            first_y, y_stride);
1444
0
}
1445
1446
1447
/**
1448
 * hb_font_get_glyph_h_kerning:
1449
 * @font: #hb_font_t to work upon
1450
 * @left_glyph: The glyph ID of the left glyph in the glyph pair
1451
 * @right_glyph: The glyph ID of the right glyph in the glyph pair
1452
 *
1453
 * Fetches the kerning-adjustment value for a glyph-pair in
1454
 * the specified font, for horizontal text segments.
1455
 *
1456
 * <note>It handles legacy kerning only (as returned by the corresponding
1457
 * #hb_font_funcs_t function).</note>
1458
 *
1459
 * Return value: The kerning adjustment value
1460
 *
1461
 * Since: 0.9.2
1462
 **/
1463
hb_position_t
1464
hb_font_get_glyph_h_kerning (hb_font_t      *font,
1465
           hb_codepoint_t  left_glyph,
1466
           hb_codepoint_t  right_glyph)
1467
0
{
1468
0
  return font->get_glyph_h_kerning (left_glyph, right_glyph);
1469
0
}
1470
1471
#ifndef HB_DISABLE_DEPRECATED
1472
/**
1473
 * hb_font_get_glyph_v_kerning:
1474
 * @font: #hb_font_t to work upon
1475
 * @top_glyph: The glyph ID of the top glyph in the glyph pair
1476
 * @bottom_glyph: The glyph ID of the bottom glyph in the glyph pair
1477
 *
1478
 * Fetches the kerning-adjustment value for a glyph-pair in
1479
 * the specified font, for vertical text segments.
1480
 *
1481
 * <note>It handles legacy kerning only (as returned by the corresponding
1482
 * #hb_font_funcs_t function).</note>
1483
 *
1484
 * Return value: The kerning adjustment value
1485
 *
1486
 * Since: 0.9.2
1487
 * Deprecated: 2.0.0
1488
 **/
1489
hb_position_t
1490
hb_font_get_glyph_v_kerning (hb_font_t      *font,
1491
           hb_codepoint_t  top_glyph,
1492
           hb_codepoint_t  bottom_glyph)
1493
0
{
1494
0
  return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
1495
0
}
1496
#endif
1497
1498
/**
1499
 * hb_font_get_glyph_extents:
1500
 * @font: #hb_font_t to work upon
1501
 * @glyph: The glyph ID to query
1502
 * @extents: (out): The #hb_glyph_extents_t retrieved
1503
 *
1504
 * Fetches the #hb_glyph_extents_t data for a glyph ID
1505
 * in the specified font.
1506
 *
1507
 * Return value: `true` if data found, `false` otherwise
1508
 *
1509
 * Since: 0.9.2
1510
 **/
1511
hb_bool_t
1512
hb_font_get_glyph_extents (hb_font_t          *font,
1513
         hb_codepoint_t      glyph,
1514
         hb_glyph_extents_t *extents)
1515
43.5k
{
1516
43.5k
  return font->get_glyph_extents (glyph, extents);
1517
43.5k
}
1518
1519
/**
1520
 * hb_font_get_glyph_contour_point:
1521
 * @font: #hb_font_t to work upon
1522
 * @glyph: The glyph ID to query
1523
 * @point_index: The contour-point index to query
1524
 * @x: (out): The X value retrieved for the contour point
1525
 * @y: (out): The Y value retrieved for the contour point
1526
 *
1527
 * Fetches the (x,y) coordinates of a specified contour-point index
1528
 * in the specified glyph, within the specified font.
1529
 *
1530
 * Return value: `true` if data found, `false` otherwise
1531
 *
1532
 * Since: 0.9.2
1533
 **/
1534
hb_bool_t
1535
hb_font_get_glyph_contour_point (hb_font_t      *font,
1536
         hb_codepoint_t  glyph,
1537
         unsigned int    point_index,
1538
         hb_position_t  *x,
1539
         hb_position_t  *y)
1540
43.5k
{
1541
43.5k
  return font->get_glyph_contour_point (glyph, point_index, x, y);
1542
43.5k
}
1543
1544
/**
1545
 * hb_font_get_glyph_name:
1546
 * @font: #hb_font_t to work upon
1547
 * @glyph: The glyph ID to query
1548
 * @name: (out) (array length=size): Name string retrieved for the glyph ID
1549
 * @size: Length of the glyph-name string retrieved
1550
 *
1551
 * Fetches the glyph-name string for a glyph ID in the specified @font.
1552
 *
1553
 * According to the OpenType specification, glyph names are limited to 63
1554
 * characters and can only contain (a subset of) ASCII.
1555
 *
1556
 * Return value: `true` if data found, `false` otherwise
1557
 *
1558
 * Since: 0.9.2
1559
 **/
1560
hb_bool_t
1561
hb_font_get_glyph_name (hb_font_t      *font,
1562
      hb_codepoint_t  glyph,
1563
      char           *name,
1564
      unsigned int    size)
1565
43.5k
{
1566
43.5k
  return font->get_glyph_name (glyph, name, size);
1567
43.5k
}
1568
1569
/**
1570
 * hb_font_get_glyph_from_name:
1571
 * @font: #hb_font_t to work upon
1572
 * @name: (array length=len): The name string to query
1573
 * @len: The length of the name queried
1574
 * @glyph: (out): The glyph ID retrieved
1575
 *
1576
 * Fetches the glyph ID that corresponds to a name string in the specified @font.
1577
 *
1578
 * <note>Note: @len == -1 means the name string is null-terminated.</note>
1579
 *
1580
 * Return value: `true` if data found, `false` otherwise
1581
 *
1582
 * Since: 0.9.2
1583
 **/
1584
hb_bool_t
1585
hb_font_get_glyph_from_name (hb_font_t      *font,
1586
           const char     *name,
1587
           int             len, /* -1 means nul-terminated */
1588
           hb_codepoint_t *glyph)
1589
43.5k
{
1590
43.5k
  return font->get_glyph_from_name (name, len, glyph);
1591
43.5k
}
1592
1593
#ifndef HB_DISABLE_DEPRECATED
1594
/**
1595
 * hb_font_get_glyph_shape:
1596
 * @font: #hb_font_t to work upon
1597
 * @glyph: The glyph ID
1598
 * @dfuncs: #hb_draw_funcs_t to draw to
1599
 * @draw_data: User data to pass to draw callbacks
1600
 *
1601
 * Fetches the glyph shape that corresponds to a glyph in the specified @font.
1602
 * The shape is returned by way of calls to the callbacks of the @dfuncs
1603
 * objects, with @draw_data passed to them.
1604
 *
1605
 * Since: 4.0.0
1606
 * Deprecated: 7.0.0: Use hb_font_draw_glyph() instead
1607
 */
1608
void
1609
hb_font_get_glyph_shape (hb_font_t *font,
1610
             hb_codepoint_t glyph,
1611
             hb_draw_funcs_t *dfuncs, void *draw_data)
1612
0
{
1613
0
  hb_font_draw_glyph (font, glyph, dfuncs, draw_data);
1614
0
}
1615
#endif
1616
1617
/**
1618
 * hb_font_draw_glyph_or_fail:
1619
 * @font: #hb_font_t to work upon
1620
 * @glyph: The glyph ID
1621
 * @dfuncs: #hb_draw_funcs_t to draw to
1622
 * @draw_data: User data to pass to draw callbacks
1623
 *
1624
 * Draws the outline that corresponds to a glyph in the specified @font.
1625
 *
1626
 * This is a newer name for hb_font_draw_glyph(), that returns `false`
1627
 * if the font has no outlines for the glyph.
1628
 *
1629
 * The outline is returned by way of calls to the callbacks of the @dfuncs
1630
 * objects, with @draw_data passed to them.
1631
 *
1632
 * Return value: `true` if glyph was drawn, `false` otherwise
1633
 *
1634
 * Since: 11.2.0
1635
 **/
1636
hb_bool_t
1637
hb_font_draw_glyph_or_fail (hb_font_t *font,
1638
          hb_codepoint_t glyph,
1639
          hb_draw_funcs_t *dfuncs, void *draw_data)
1640
1.18M
{
1641
1.18M
  return font->draw_glyph_or_fail (glyph, dfuncs, draw_data);
1642
1.18M
}
1643
1644
/**
1645
 * hb_font_paint_glyph_or_fail:
1646
 * @font: #hb_font_t to work upon
1647
 * @glyph: The glyph ID
1648
 * @pfuncs: #hb_paint_funcs_t to paint with
1649
 * @paint_data: User data to pass to paint callbacks
1650
 * @palette_index: The index of the font's color palette to use
1651
 * @foreground: The foreground color, unpremultipled
1652
 *
1653
 * Paints a color glyph.
1654
 *
1655
 * Succeeds if @glyph has color paint layers (COLRv0),
1656
 * a color paint graph (COLRv1), or a bitmap image that the
1657
 * font's callbacks render successfully.  Returns `false` if
1658
 * the font has no color data for @glyph; the client can then
1659
 * fall back to hb_font_draw_glyph_or_fail() for the monochrome
1660
 * outline.
1661
 *
1662
 * The painting instructions are returned by way of calls to
1663
 * the callbacks of the @funcs object, with @paint_data passed
1664
 * to them.
1665
 *
1666
 * If the font has color palettes (see hb_ot_color_has_palettes()),
1667
 * then @palette_index selects the palette to use. If the font only
1668
 * has one palette, this will be 0.
1669
 *
1670
 * Return value: `true` if glyph was painted, `false` otherwise
1671
 *
1672
 * Since: 11.2.0
1673
 */
1674
hb_bool_t
1675
hb_font_paint_glyph_or_fail (hb_font_t *font,
1676
           hb_codepoint_t glyph,
1677
           hb_paint_funcs_t *pfuncs, void *paint_data,
1678
           unsigned int palette_index,
1679
           hb_color_t foreground)
1680
0
{
1681
0
  return font->paint_glyph_or_fail (glyph, pfuncs, paint_data, palette_index, foreground);
1682
0
}
1683
1684
/* A bit higher-level, and with fallback */
1685
1686
void
1687
hb_font_t::paint_glyph (hb_codepoint_t glyph,
1688
      hb_paint_funcs_t *paint_funcs, void *paint_data,
1689
      unsigned int palette,
1690
      hb_color_t foreground)
1691
0
{
1692
0
  if (paint_glyph_or_fail (glyph,
1693
0
         paint_funcs, paint_data,
1694
0
         palette, foreground))
1695
0
    return;
1696
1697
  /* Fallback for outline glyph. */
1698
0
  paint_funcs->fill_glyph (paint_data, glyph, this, true, foreground);
1699
0
}
1700
1701
1702
/**
1703
 * hb_font_draw_glyph:
1704
 * @font: #hb_font_t to work upon
1705
 * @glyph: The glyph ID
1706
 * @dfuncs: #hb_draw_funcs_t to draw to
1707
 * @draw_data: User data to pass to draw callbacks
1708
 *
1709
 * Draws the outline that corresponds to a glyph in the specified @font.
1710
 *
1711
 * This is an older name for hb_font_draw_glyph_or_fail(), with no
1712
 * return value.
1713
 *
1714
 * The outline is returned by way of calls to the callbacks of the @dfuncs
1715
 * objects, with @draw_data passed to them.
1716
 *
1717
 * Since: 7.0.0
1718
 **/
1719
void
1720
hb_font_draw_glyph (hb_font_t *font,
1721
        hb_codepoint_t glyph,
1722
        hb_draw_funcs_t *dfuncs, void *draw_data)
1723
1.18M
{
1724
1.18M
  (void) hb_font_draw_glyph_or_fail (font, glyph, dfuncs, draw_data);
1725
1.18M
}
1726
1727
/**
1728
 * hb_font_paint_glyph:
1729
 * @font: #hb_font_t to work upon
1730
 * @glyph: The glyph ID
1731
 * @pfuncs: #hb_paint_funcs_t to paint with
1732
 * @paint_data: User data to pass to paint callbacks
1733
 * @palette_index: The index of the font's color palette to use
1734
 * @foreground: The foreground color, unpremultipled
1735
 *
1736
 * Paints the glyph. This function is similar to
1737
 * hb_font_paint_glyph_or_fail(), but if painting a color glyph
1738
 * failed, it will fall back to painting an outline monochrome
1739
 * glyph.
1740
 *
1741
 * The painting instructions are returned by way of calls to
1742
 * the callbacks of the @funcs object, with @paint_data passed
1743
 * to them.
1744
 *
1745
 * If the font has color palettes (see hb_ot_color_has_palettes()),
1746
 * then @palette_index selects the palette to use. If the font only
1747
 * has one palette, this will be 0.
1748
 *
1749
 * Since: 7.0.0
1750
 */
1751
void
1752
hb_font_paint_glyph (hb_font_t *font,
1753
                     hb_codepoint_t glyph,
1754
                     hb_paint_funcs_t *pfuncs, void *paint_data,
1755
                     unsigned int palette_index,
1756
                     hb_color_t foreground)
1757
0
{
1758
0
  font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground);
1759
0
}
1760
1761
/**
1762
 * hb_font_get_extents_for_direction:
1763
 * @font: #hb_font_t to work upon
1764
 * @direction: The direction of the text segment
1765
 * @extents: (out): The #hb_font_extents_t retrieved
1766
 *
1767
 * Fetches the extents for a font in a text segment of the
1768
 * specified direction.
1769
 *
1770
 * Calls the appropriate direction-specific variant (horizontal
1771
 * or vertical) depending on the value of @direction.
1772
 *
1773
 * Since: 1.1.3
1774
 **/
1775
void
1776
hb_font_get_extents_for_direction (hb_font_t         *font,
1777
           hb_direction_t     direction,
1778
           hb_font_extents_t *extents)
1779
0
{
1780
0
  font->get_extents_for_direction (direction, extents);
1781
0
}
1782
/**
1783
 * hb_font_get_glyph_advance_for_direction:
1784
 * @font: #hb_font_t to work upon
1785
 * @glyph: The glyph ID to query
1786
 * @direction: The direction of the text segment
1787
 * @x: (out): The horizontal advance retrieved
1788
 * @y: (out):  The vertical advance retrieved
1789
 *
1790
 * Fetches the advance for a glyph ID from the specified font,
1791
 * in a text segment of the specified direction.
1792
 *
1793
 * Calls the appropriate direction-specific variant (horizontal
1794
 * or vertical) depending on the value of @direction.
1795
 *
1796
 * Since: 0.9.2
1797
 **/
1798
void
1799
hb_font_get_glyph_advance_for_direction (hb_font_t      *font,
1800
           hb_codepoint_t  glyph,
1801
           hb_direction_t  direction,
1802
           hb_position_t  *x,
1803
           hb_position_t  *y)
1804
0
{
1805
0
  font->get_glyph_advance_for_direction (glyph, direction, x, y);
1806
0
}
1807
/**
1808
 * hb_font_get_glyph_advances_for_direction:
1809
 * @font: #hb_font_t to work upon
1810
 * @direction: The direction of the text segment
1811
 * @count: The number of glyph IDs in the sequence queried
1812
 * @first_glyph: The first glyph ID to query
1813
 * @glyph_stride: The stride between successive glyph IDs
1814
 * @first_advance: (out): The first advance retrieved
1815
 * @advance_stride: (out): The stride between successive advances
1816
 *
1817
 * Fetches the advances for a sequence of glyph IDs in the specified
1818
 * font, in a text segment of the specified direction.
1819
 *
1820
 * Calls the appropriate direction-specific variant (horizontal
1821
 * or vertical) depending on the value of @direction.
1822
 *
1823
 * Since: 1.8.6
1824
 **/
1825
HB_EXTERN void
1826
hb_font_get_glyph_advances_for_direction (hb_font_t*            font,
1827
            hb_direction_t        direction,
1828
            unsigned int          count,
1829
            const hb_codepoint_t *first_glyph,
1830
            unsigned              glyph_stride,
1831
            hb_position_t        *first_advance,
1832
            unsigned              advance_stride)
1833
0
{
1834
0
  font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);
1835
0
}
1836
1837
/**
1838
 * hb_font_get_glyph_origin_for_direction:
1839
 * @font: #hb_font_t to work upon
1840
 * @glyph: The glyph ID to query
1841
 * @direction: The direction of the text segment
1842
 * @x: (out): The X coordinate retrieved for the origin
1843
 * @y: (out): The Y coordinate retrieved for the origin
1844
 *
1845
 * Fetches the (X,Y) coordinates of the origin for a glyph in
1846
 * the specified font.
1847
 *
1848
 * Calls the appropriate direction-specific variant (horizontal
1849
 * or vertical) depending on the value of @direction.
1850
 *
1851
 * Since: 0.9.2
1852
 **/
1853
void
1854
hb_font_get_glyph_origin_for_direction (hb_font_t      *font,
1855
          hb_codepoint_t  glyph,
1856
          hb_direction_t  direction,
1857
          hb_position_t  *x,
1858
          hb_position_t  *y)
1859
0
{
1860
0
  return font->get_glyph_origin_for_direction (glyph, direction, x, y);
1861
0
}
1862
1863
/**
1864
 * hb_font_add_glyph_origin_for_direction:
1865
 * @font: #hb_font_t to work upon
1866
 * @glyph: The glyph ID to query
1867
 * @direction: The direction of the text segment
1868
 * @x: (inout): Input = The original X coordinate
1869
 *     Output = The X coordinate plus the X-coordinate of the origin
1870
 * @y: (inout): Input = The original Y coordinate
1871
 *     Output = The Y coordinate plus the Y-coordinate of the origin
1872
 *
1873
 * Adds the origin coordinates to an (X,Y) point coordinate, in
1874
 * the specified glyph ID in the specified font.
1875
 *
1876
 * Calls the appropriate direction-specific variant (horizontal
1877
 * or vertical) depending on the value of @direction.
1878
 *
1879
 * Since: 0.9.2
1880
 **/
1881
void
1882
hb_font_add_glyph_origin_for_direction (hb_font_t      *font,
1883
          hb_codepoint_t  glyph,
1884
          hb_direction_t  direction,
1885
          hb_position_t  *x,
1886
          hb_position_t  *y)
1887
0
{
1888
0
  return font->add_glyph_origin_for_direction (glyph, direction, x, y);
1889
0
}
1890
1891
/**
1892
 * hb_font_subtract_glyph_origin_for_direction:
1893
 * @font: #hb_font_t to work upon
1894
 * @glyph: The glyph ID to query
1895
 * @direction: The direction of the text segment
1896
 * @x: (inout): Input = The original X coordinate
1897
 *     Output = The X coordinate minus the X-coordinate of the origin
1898
 * @y: (inout): Input = The original Y coordinate
1899
 *     Output = The Y coordinate minus the Y-coordinate of the origin
1900
 *
1901
 * Subtracts the origin coordinates from an (X,Y) point coordinate,
1902
 * in the specified glyph ID in the specified font.
1903
 *
1904
 * Calls the appropriate direction-specific variant (horizontal
1905
 * or vertical) depending on the value of @direction.
1906
 *
1907
 * Since: 0.9.2
1908
 **/
1909
void
1910
hb_font_subtract_glyph_origin_for_direction (hb_font_t      *font,
1911
               hb_codepoint_t  glyph,
1912
               hb_direction_t  direction,
1913
               hb_position_t  *x,
1914
               hb_position_t  *y)
1915
0
{
1916
0
  return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
1917
0
}
1918
1919
/**
1920
 * hb_font_get_glyph_kerning_for_direction:
1921
 * @font: #hb_font_t to work upon
1922
 * @first_glyph: The glyph ID of the first glyph in the glyph pair to query
1923
 * @second_glyph: The glyph ID of the second glyph in the glyph pair to query
1924
 * @direction: The direction of the text segment
1925
 * @x: (out): The horizontal kerning-adjustment value retrieved
1926
 * @y: (out): The vertical kerning-adjustment value retrieved
1927
 *
1928
 * Fetches the kerning-adjustment value for a glyph-pair in the specified font.
1929
 *
1930
 * Calls the appropriate direction-specific variant (horizontal
1931
 * or vertical) depending on the value of @direction.
1932
 *
1933
 * Since: 0.9.2
1934
 **/
1935
void
1936
hb_font_get_glyph_kerning_for_direction (hb_font_t      *font,
1937
           hb_codepoint_t  first_glyph,
1938
           hb_codepoint_t  second_glyph,
1939
           hb_direction_t  direction,
1940
           hb_position_t  *x,
1941
           hb_position_t  *y)
1942
0
{
1943
0
  return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1944
0
}
1945
1946
/**
1947
 * hb_font_get_glyph_extents_for_origin:
1948
 * @font: #hb_font_t to work upon
1949
 * @glyph: The glyph ID to query
1950
 * @direction: The direction of the text segment
1951
 * @extents: (out): The #hb_glyph_extents_t retrieved
1952
 *
1953
 * Fetches the #hb_glyph_extents_t data for a glyph ID
1954
 * in the specified font, with respect to the origin in
1955
 * a text segment in the specified direction.
1956
 *
1957
 * Calls the appropriate direction-specific variant (horizontal
1958
 * or vertical) depending on the value of @direction.
1959
 *
1960
 * Return value: `true` if data found, `false` otherwise
1961
 *
1962
 * Since: 0.9.2
1963
 **/
1964
hb_bool_t
1965
hb_font_get_glyph_extents_for_origin (hb_font_t          *font,
1966
              hb_codepoint_t      glyph,
1967
              hb_direction_t      direction,
1968
              hb_glyph_extents_t *extents)
1969
0
{
1970
0
  return font->get_glyph_extents_for_origin (glyph, direction, extents);
1971
0
}
1972
1973
/**
1974
 * hb_font_get_glyph_contour_point_for_origin:
1975
 * @font: #hb_font_t to work upon
1976
 * @glyph: The glyph ID to query
1977
 * @point_index: The contour-point index to query
1978
 * @direction: The direction of the text segment
1979
 * @x: (out): The X value retrieved for the contour point
1980
 * @y: (out): The Y value retrieved for the contour point
1981
 *
1982
 * Fetches the (X,Y) coordinates of a specified contour-point index
1983
 * in the specified glyph ID in the specified font, with respect
1984
 * to the origin in a text segment in the specified direction.
1985
 *
1986
 * Calls the appropriate direction-specific variant (horizontal
1987
 * or vertical) depending on the value of @direction.
1988
 *
1989
 * Return value: `true` if data found, `false` otherwise
1990
 *
1991
 * Since: 0.9.2
1992
 **/
1993
hb_bool_t
1994
hb_font_get_glyph_contour_point_for_origin (hb_font_t      *font,
1995
              hb_codepoint_t  glyph,
1996
              unsigned int    point_index,
1997
              hb_direction_t  direction,
1998
              hb_position_t  *x,
1999
              hb_position_t  *y)
2000
0
{
2001
0
  return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
2002
0
}
2003
2004
/**
2005
 * hb_font_glyph_to_string:
2006
 * @font: #hb_font_t to work upon
2007
 * @glyph: The glyph ID to query
2008
 * @s: (out) (array length=size): The string containing the glyph name
2009
 * @size: Length of string @s
2010
 *
2011
 * Fetches the name of the specified glyph ID in @font and returns
2012
 * it in string @s.
2013
 *
2014
 * If the glyph ID has no name in @font, a string of the form `gidDDD` is
2015
 * generated, with `DDD` being the glyph ID.
2016
 *
2017
 * According to the OpenType specification, glyph names are limited to 63
2018
 * characters and can only contain (a subset of) ASCII.
2019
 *
2020
 * Since: 0.9.2
2021
 **/
2022
void
2023
hb_font_glyph_to_string (hb_font_t      *font,
2024
       hb_codepoint_t  glyph,
2025
       char           *s,
2026
       unsigned int    size)
2027
0
{
2028
0
  font->glyph_to_string (glyph, s, size);
2029
0
}
2030
2031
/**
2032
 * hb_font_glyph_from_string:
2033
 * @font: #hb_font_t to work upon
2034
 * @s: (array length=len) (element-type uint8_t): string to query
2035
 * @len: The length of the string @s
2036
 * @glyph: (out): The glyph ID corresponding to the string requested
2037
 *
2038
 * Fetches the glyph ID from @font that matches the specified string.
2039
 * Strings of the format `gidDDD` or `uniUUUU` are parsed automatically.
2040
 *
2041
 * <note>Note: @len == -1 means the string is null-terminated.</note>
2042
 *
2043
 * Return value: `true` if data found, `false` otherwise
2044
 *
2045
 * Since: 0.9.2
2046
 **/
2047
hb_bool_t
2048
hb_font_glyph_from_string (hb_font_t      *font,
2049
         const char     *s,
2050
         int             len,
2051
         hb_codepoint_t *glyph)
2052
0
{
2053
0
  return font->glyph_from_string (s, len, glyph);
2054
0
}
2055
2056
2057
/*
2058
 * hb_font_t
2059
 */
2060
2061
DEFINE_NULL_INSTANCE (hb_font_t) =
2062
{
2063
  HB_OBJECT_HEADER_STATIC,
2064
2065
  0, /* serial */
2066
  0, /* serial_coords */
2067
2068
  nullptr, /* parent */
2069
  const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
2070
2071
  1000, /* x_scale */
2072
  1000, /* y_scale */
2073
  false, /* is_synthetic */
2074
  0.f, /* x_embolden */
2075
  0.f, /* y_embolden */
2076
  true, /* embolden_in_place */
2077
  0, /* x_strength */
2078
  0, /* y_strength */
2079
  0.f, /* slant */
2080
  0.f, /* slant_xy; */
2081
  1.f, /* x_multf */
2082
  1.f, /* y_multf */
2083
  1<<16, /* x_mult */
2084
  1<<16, /* y_mult */
2085
2086
  0, /* x_ppem */
2087
  0, /* y_ppem */
2088
  0, /* ptem */
2089
2090
  HB_FONT_NO_VAR_NAMED_INSTANCE, /* instance_index */
2091
  false, /* has_nonzero_coords */
2092
  0, /* num_coords */
2093
  nullptr, /* coords */
2094
  nullptr, /* design_coords */
2095
2096
  const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),
2097
2098
  /* Zero for the rest is fine. */
2099
};
2100
2101
2102
static hb_font_t *
2103
_hb_font_create (hb_face_t *face)
2104
43.8k
{
2105
43.8k
  hb_font_t *font;
2106
2107
43.8k
  if (unlikely (!face))
2108
0
    face = hb_face_get_empty ();
2109
2110
43.8k
  if (!(font = hb_object_create<hb_font_t> ()))
2111
78
    return hb_font_get_empty ();
2112
2113
43.7k
  hb_face_make_immutable (face);
2114
43.7k
  font->parent = hb_font_get_empty ();
2115
43.7k
  font->face = hb_face_reference (face);
2116
43.7k
  font->klass = hb_font_funcs_get_empty ();
2117
43.7k
  font->data.init0 (font);
2118
43.7k
  font->x_scale = font->y_scale = face->get_upem ();
2119
43.7k
  font->embolden_in_place = true;
2120
43.7k
  font->x_multf = font->y_multf = 1.f;
2121
43.7k
  font->x_mult = font->y_mult = 1 << 16;
2122
43.7k
  font->instance_index = HB_FONT_NO_VAR_NAMED_INSTANCE;
2123
2124
43.7k
  return font;
2125
43.8k
}
2126
2127
/**
2128
 * hb_font_create:
2129
 * @face: a face.
2130
 *
2131
 * Constructs a new font object from the specified face.
2132
 *
2133
 * <note>Note: If @face's index value (as passed to hb_face_create()
2134
 * has non-zero top 16-bits, those bits minus one are passed to
2135
 * hb_font_set_var_named_instance(), effectively loading a named-instance
2136
 * of a variable font, instead of the default-instance.  This allows
2137
 * specifying which named-instance to load by default when creating the
2138
 * face.</note>
2139
 *
2140
 * Return value: (transfer full): The new font object
2141
 *
2142
 * Since: 0.9.2
2143
 **/
2144
hb_font_t *
2145
hb_font_create (hb_face_t *face)
2146
43.8k
{
2147
43.8k
  hb_font_t *font = _hb_font_create (face);
2148
2149
43.8k
  hb_font_set_funcs_using (font, nullptr);
2150
2151
43.8k
#ifndef HB_NO_VAR
2152
  // Initialize variations.
2153
43.8k
  if (likely (face))
2154
43.8k
  {
2155
43.8k
    if (face->index >> 16)
2156
0
      hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
2157
43.8k
    else
2158
43.8k
      hb_font_set_variations (font, nullptr, 0);
2159
43.8k
  }
2160
43.8k
#endif
2161
2162
43.8k
  return font;
2163
43.8k
}
2164
2165
static void
2166
_hb_font_adopt_var_coords (hb_font_t *font,
2167
         int *coords, /* 2.14 normalized */
2168
         float *design_coords,
2169
         unsigned int coords_length)
2170
87.1k
{
2171
87.1k
  hb_free (font->coords);
2172
87.1k
  hb_free (font->design_coords);
2173
2174
87.1k
  font->coords = coords;
2175
87.1k
  font->design_coords = design_coords;
2176
87.1k
  font->num_coords = coords_length;
2177
87.1k
  font->has_nonzero_coords = hb_any (hb_array (coords, coords_length));
2178
2179
87.1k
  font->changed ();
2180
87.1k
  font->serial_coords = font->serial;
2181
87.1k
}
2182
2183
/**
2184
 * hb_font_create_sub_font:
2185
 * @parent: The parent font object
2186
 *
2187
 * Constructs a sub-font font object from the specified @parent font,
2188
 * replicating the parent's properties.
2189
 *
2190
 * Return value: (transfer full): The new sub-font font object
2191
 *
2192
 * Since: 0.9.2
2193
 **/
2194
hb_font_t *
2195
hb_font_create_sub_font (hb_font_t *parent)
2196
0
{
2197
0
  if (unlikely (!parent))
2198
0
    parent = hb_font_get_empty ();
2199
2200
0
  hb_font_t *font = _hb_font_create (parent->face);
2201
2202
0
  if (unlikely (hb_object_is_immutable (font)))
2203
0
    return font;
2204
2205
0
  font->parent = hb_font_reference (parent);
2206
2207
0
  font->x_scale = parent->x_scale;
2208
0
  font->y_scale = parent->y_scale;
2209
0
  font->x_embolden = parent->x_embolden;
2210
0
  font->y_embolden = parent->y_embolden;
2211
0
  font->embolden_in_place = parent->embolden_in_place;
2212
0
  font->slant = parent->slant;
2213
0
  font->x_ppem = parent->x_ppem;
2214
0
  font->y_ppem = parent->y_ppem;
2215
0
  font->ptem = parent->ptem;
2216
2217
0
  unsigned int num_coords = parent->num_coords;
2218
0
  if (num_coords)
2219
0
  {
2220
0
    int *coords = (int *) hb_calloc (num_coords, sizeof (parent->coords[0]));
2221
0
    float *design_coords = (float *) hb_calloc (num_coords, sizeof (parent->design_coords[0]));
2222
0
    if (likely (coords && design_coords))
2223
0
    {
2224
0
      hb_memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0]));
2225
0
      hb_memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0]));
2226
0
      _hb_font_adopt_var_coords (font, coords, design_coords, num_coords);
2227
0
    }
2228
0
    else
2229
0
    {
2230
0
      hb_free (coords);
2231
0
      hb_free (design_coords);
2232
0
    }
2233
0
  }
2234
2235
0
  font->changed ();
2236
0
  font->serial_coords = font->serial;
2237
2238
0
  return font;
2239
0
}
2240
2241
/**
2242
 * hb_font_get_empty:
2243
 *
2244
 * Fetches the empty font object.
2245
 *
2246
 * Return value: (transfer full): The empty font object
2247
 *
2248
 * Since: 0.9.2
2249
 **/
2250
hb_font_t *
2251
hb_font_get_empty ()
2252
43.8k
{
2253
43.8k
  return const_cast<hb_font_t *> (&Null (hb_font_t));
2254
43.8k
}
2255
2256
/**
2257
 * hb_font_reference: (skip)
2258
 * @font: #hb_font_t to work upon
2259
 *
2260
 * Increases the reference count on the given font object.
2261
 *
2262
 * Return value: (transfer full): The @font object
2263
 *
2264
 * Since: 0.9.2
2265
 **/
2266
hb_font_t *
2267
hb_font_reference (hb_font_t *font)
2268
23.0k
{
2269
23.0k
  return hb_object_reference (font);
2270
23.0k
}
2271
2272
/**
2273
 * hb_font_destroy: (skip)
2274
 * @font: #hb_font_t to work upon
2275
 *
2276
 * Decreases the reference count on the given font object. When the
2277
 * reference count reaches zero, the font is destroyed,
2278
 * freeing all memory.
2279
 *
2280
 * Since: 0.9.2
2281
 **/
2282
void
2283
hb_font_destroy (hb_font_t *font)
2284
110k
{
2285
110k
  if (!hb_object_destroy (font)) return;
2286
2287
43.7k
  font->data.fini ();
2288
2289
43.7k
  if (font->destroy)
2290
43.6k
    font->destroy (font->user_data);
2291
2292
43.7k
  hb_font_destroy (font->parent);
2293
43.7k
  hb_face_destroy (font->face);
2294
43.7k
  hb_font_funcs_destroy (font->klass);
2295
2296
43.7k
  hb_free (font->coords);
2297
43.7k
  hb_free (font->design_coords);
2298
2299
43.7k
  hb_free (font);
2300
43.7k
}
2301
2302
/**
2303
 * hb_font_set_user_data: (skip)
2304
 * @font: #hb_font_t to work upon
2305
 * @key: The user-data key
2306
 * @data: A pointer to the user data
2307
 * @destroy: (nullable): A callback to call when @data is not needed anymore
2308
 * @replace: Whether to replace an existing data with the same key
2309
 *
2310
 * Attaches a user-data key/data pair to the specified font object.
2311
 *
2312
 * Return value: `true` if success, `false` otherwise
2313
 *
2314
 * Since: 0.9.2
2315
 **/
2316
hb_bool_t
2317
hb_font_set_user_data (hb_font_t          *font,
2318
           hb_user_data_key_t *key,
2319
           void *              data,
2320
           hb_destroy_func_t   destroy /* May be NULL. */,
2321
           hb_bool_t           replace)
2322
0
{
2323
0
  if (!hb_object_is_immutable (font))
2324
0
    font->changed ();
2325
2326
0
  return hb_object_set_user_data (font, key, data, destroy, replace);
2327
0
}
2328
2329
/**
2330
 * hb_font_get_user_data: (skip)
2331
 * @font: #hb_font_t to work upon
2332
 * @key: The user-data key to query
2333
 *
2334
 * Fetches the user-data object associated with the specified key,
2335
 * attached to the specified font object.
2336
 *
2337
 * Return value: (transfer none): Pointer to the user data
2338
 *
2339
 * Since: 0.9.2
2340
 **/
2341
void *
2342
hb_font_get_user_data (const hb_font_t    *font,
2343
           hb_user_data_key_t *key)
2344
0
{
2345
0
  return hb_object_get_user_data (font, key);
2346
0
}
2347
2348
/**
2349
 * hb_font_make_immutable:
2350
 * @font: #hb_font_t to work upon
2351
 *
2352
 * Makes @font immutable.
2353
 *
2354
 * Since: 0.9.2
2355
 **/
2356
void
2357
hb_font_make_immutable (hb_font_t *font)
2358
0
{
2359
0
  if (hb_object_is_immutable (font))
2360
0
    return;
2361
2362
0
  if (font->parent)
2363
0
    hb_font_make_immutable (font->parent);
2364
2365
0
  hb_object_make_immutable (font);
2366
0
}
2367
2368
/**
2369
 * hb_font_is_immutable:
2370
 * @font: #hb_font_t to work upon
2371
 *
2372
 * Tests whether a font object is immutable.
2373
 *
2374
 * Return value: `true` if @font is immutable, `false` otherwise
2375
 *
2376
 * Since: 0.9.2
2377
 **/
2378
hb_bool_t
2379
hb_font_is_immutable (hb_font_t *font)
2380
0
{
2381
0
  return hb_object_is_immutable (font);
2382
0
}
2383
2384
/**
2385
 * hb_font_get_serial:
2386
 * @font: #hb_font_t to work upon
2387
 *
2388
 * Returns the internal serial number of the font. The serial
2389
 * number is increased every time a setting on the font is
2390
 * changed, using a setter function.
2391
 *
2392
 * Return value: serial number
2393
 *
2394
 * Since: 4.4.0
2395
 **/
2396
unsigned int
2397
hb_font_get_serial (hb_font_t *font)
2398
0
{
2399
0
  return font->serial.get_acquire ();
2400
0
}
2401
2402
/**
2403
 * hb_font_changed:
2404
 * @font: #hb_font_t to work upon
2405
 *
2406
 * Notifies the @font that underlying font data has changed.
2407
 * This has the effect of increasing the serial as returned
2408
 * by hb_font_get_serial(), which invalidates internal caches.
2409
 *
2410
 * Since: 4.4.0
2411
 **/
2412
void
2413
hb_font_changed (hb_font_t *font)
2414
0
{
2415
0
  if (hb_object_is_immutable (font))
2416
0
    return;
2417
2418
0
  font->changed ();
2419
0
}
2420
2421
/**
2422
 * hb_font_set_parent:
2423
 * @font: #hb_font_t to work upon
2424
 * @parent: The parent font object to assign
2425
 *
2426
 * Sets the parent font of @font.
2427
 *
2428
 * Since: 1.0.5
2429
 **/
2430
void
2431
hb_font_set_parent (hb_font_t *font,
2432
        hb_font_t *parent)
2433
0
{
2434
0
  if (hb_object_is_immutable (font))
2435
0
    return;
2436
2437
0
  if (parent == font->parent)
2438
0
    return;
2439
2440
0
  if (!parent)
2441
0
    parent = hb_font_get_empty ();
2442
2443
0
  for (hb_font_t *p = parent; p && p != hb_font_get_empty(); p = p->parent)
2444
0
    if (p == font)
2445
0
      return; /* Would create a cycle - reject */
2446
2447
0
  hb_font_t *old = font->parent;
2448
2449
0
  font->parent = hb_font_reference (parent);
2450
2451
0
  hb_font_destroy (old);
2452
2453
0
  font->changed ();
2454
0
}
2455
2456
/**
2457
 * hb_font_get_parent:
2458
 * @font: #hb_font_t to work upon
2459
 *
2460
 * Fetches the parent font of @font.
2461
 *
2462
 * Return value: (transfer none): The parent font object
2463
 *
2464
 * Since: 0.9.2
2465
 **/
2466
hb_font_t *
2467
hb_font_get_parent (hb_font_t *font)
2468
0
{
2469
0
  return font->parent;
2470
0
}
2471
2472
#ifndef HB_DISABLE_DEPRECATED
2473
/**
2474
 * hb_font_set_face:
2475
 * @font: #hb_font_t to work upon
2476
 * @face: The #hb_face_t to assign
2477
 *
2478
 * Sets @face as the font-face value of @font.
2479
 *
2480
 * Font functions and their data may hold pointers into the old face,
2481
 * so the font functions of @font are released and replaced with the
2482
 * default ones for @face, as hb_font_create() would set up.  Other
2483
 * font properties, such as scale and variations, are kept.
2484
 *
2485
 * Since: 1.4.3
2486
 * XDeprecated: REPLACEME: Use hb_font_create() instead.
2487
 **/
2488
void
2489
hb_font_set_face (hb_font_t *font,
2490
      hb_face_t *face)
2491
0
{
2492
0
  if (hb_object_is_immutable (font))
2493
0
    return;
2494
2495
0
  if (face == font->face)
2496
0
    return;
2497
2498
0
  if (unlikely (!face))
2499
0
    face = hb_face_get_empty ();
2500
2501
0
  hb_face_t *old = font->face;
2502
2503
0
  hb_face_make_immutable (face);
2504
0
  font->face = hb_face_reference (face);
2505
0
  font->changed ();
2506
2507
  /* Release the old font funcs while the old face is still alive. */
2508
0
  hb_font_set_funcs (font, nullptr, nullptr, nullptr);
2509
0
  hb_font_set_funcs_using (font, nullptr);
2510
2511
0
  hb_face_destroy (old);
2512
2513
0
  font->changed ();
2514
0
  font->serial_coords = font->serial;
2515
0
}
2516
#endif
2517
2518
/**
2519
 * hb_font_get_face:
2520
 * @font: #hb_font_t to work upon
2521
 *
2522
 * Fetches the face associated with the specified font object.
2523
 *
2524
 * Return value: (transfer none): The #hb_face_t value
2525
 *
2526
 * Since: 0.9.2
2527
 **/
2528
hb_face_t *
2529
hb_font_get_face (hb_font_t *font)
2530
43.5k
{
2531
43.5k
  return font->face;
2532
43.5k
}
2533
2534
2535
/**
2536
 * hb_font_set_funcs:
2537
 * @font: #hb_font_t to work upon
2538
 * @klass: The font-functions structure.
2539
 * @font_data: Data to attach to @font
2540
 * @destroy: (nullable) (scope async) (closure font_data): The function to call when @font_data is not needed anymore
2541
 *
2542
 * Replaces the font-functions structure attached to a font, updating
2543
 * the font's user-data with @font-data and the @destroy callback.
2544
 *
2545
 * Since: 0.9.2
2546
 **/
2547
void
2548
hb_font_set_funcs (hb_font_t         *font,
2549
       hb_font_funcs_t   *klass,
2550
       void              *font_data,
2551
       hb_destroy_func_t  destroy /* May be NULL. */)
2552
43.6k
{
2553
43.6k
  if (hb_object_is_immutable (font))
2554
0
  {
2555
0
    if (destroy)
2556
0
      destroy (font_data);
2557
0
    return;
2558
0
  }
2559
2560
43.6k
  if (font->destroy)
2561
0
    font->destroy (font->user_data);
2562
2563
43.6k
  if (!klass)
2564
0
    klass = hb_font_funcs_get_empty ();
2565
2566
43.6k
  hb_font_funcs_reference (klass);
2567
43.6k
  hb_font_funcs_destroy (font->klass);
2568
43.6k
  font->klass = klass;
2569
43.6k
  font->user_data = font_data;
2570
43.6k
  font->destroy = destroy;
2571
2572
43.6k
  font->changed ();
2573
43.6k
}
2574
2575
/**
2576
 * hb_font_set_funcs_data:
2577
 * @font: #hb_font_t to work upon
2578
 * @font_data: Data to attach to @font
2579
 * @destroy: (nullable) (scope async) (closure font_data): The function to call when @font_data is not needed anymore
2580
 *
2581
 * Replaces the user data attached to a font, updating the font's
2582
 * @destroy callback.
2583
 *
2584
 * Since: 0.9.2
2585
 **/
2586
void
2587
hb_font_set_funcs_data (hb_font_t         *font,
2588
            void              *font_data,
2589
            hb_destroy_func_t  destroy /* May be NULL. */)
2590
0
{
2591
  /* Destroy user_data? */
2592
0
  if (hb_object_is_immutable (font))
2593
0
  {
2594
0
    if (destroy)
2595
0
      destroy (font_data);
2596
0
    return;
2597
0
  }
2598
2599
0
  if (font->destroy)
2600
0
    font->destroy (font->user_data);
2601
2602
0
  font->user_data = font_data;
2603
0
  font->destroy = destroy;
2604
2605
0
  font->changed ();
2606
0
}
2607
2608
static const struct supported_font_funcs_t {
2609
  char name[16];
2610
  void (*func) (hb_font_t *);
2611
} supported_font_funcs[] =
2612
{
2613
#ifndef HB_NO_OT_FONT
2614
  {"ot",  hb_ot_font_set_funcs},
2615
#endif
2616
#ifdef HAVE_FREETYPE
2617
  {"ft",  hb_ft_font_set_funcs},
2618
#endif
2619
#ifdef HAVE_FONTATIONS
2620
  {"fontations",hb_fontations_font_set_funcs},
2621
#endif
2622
#ifdef HAVE_CORETEXT
2623
  {"coretext",  hb_coretext_font_set_funcs},
2624
#endif
2625
#ifdef HAVE_DIRECTWRITE
2626
  {"directwrite",hb_directwrite_font_set_funcs},
2627
#endif
2628
};
2629
2630
static const char *get_default_funcs_name ()
2631
43.7k
{
2632
43.7k
  static hb_atomic_t<const char *> static_funcs_name;
2633
43.7k
  const char *name = static_funcs_name.get_acquire ();
2634
43.7k
  if (!name)
2635
1
  {
2636
1
    name = getenv ("HB_FONT_FUNCS");
2637
1
    if (!name)
2638
1
      name = "";
2639
1
    if (!static_funcs_name.cmpexch (nullptr, name))
2640
0
      name = static_funcs_name.get_acquire ();
2641
1
  }
2642
43.7k
  return name;
2643
43.7k
}
2644
2645
/**
2646
 * hb_font_set_funcs_using:
2647
 * @font: #hb_font_t to work upon
2648
 * @name: The name of the font-functions structure to use, or `NULL`
2649
 *
2650
 * Sets the font-functions structure to use for a font, based on the
2651
 * specified name.
2652
 *
2653
 * If @name is `NULL` or the empty string, the default (first) functioning font-functions
2654
 * are used.  This default can be changed by setting the `HB_FONT_FUNCS` environment
2655
 * variable to the name of the desired font-functions.
2656
 *
2657
 * Return value: `true` if the font-functions was found and set, `false` otherwise
2658
 *
2659
 * Since: 11.0.0
2660
 **/
2661
hb_bool_t
2662
hb_font_set_funcs_using (hb_font_t  *font,
2663
       const char *name)
2664
43.8k
{
2665
43.8k
  if (unlikely (hb_object_is_immutable (font)))
2666
78
    return false;
2667
2668
43.7k
  bool retry = false;
2669
2670
43.7k
  if (!name || !*name)
2671
43.7k
  {
2672
43.7k
    name = get_default_funcs_name ();
2673
43.7k
    retry = true;
2674
43.7k
  }
2675
43.7k
  if (name && !*name) name = nullptr;
2676
2677
44.3k
retry:
2678
45.0k
  for (unsigned i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
2679
44.3k
    if (!name || strcmp (supported_font_funcs[i].name, name) == 0)
2680
44.3k
    {
2681
44.3k
      supported_font_funcs[i].func (font);
2682
44.3k
      if (name || font->klass != hb_font_funcs_get_empty ())
2683
43.6k
  return true;
2684
44.3k
    }
2685
2686
693
  if (retry)
2687
589
  {
2688
589
    retry = false;
2689
589
    name = nullptr;
2690
589
    goto retry;
2691
589
  }
2692
2693
104
  return false;
2694
693
}
2695
2696
static inline void free_static_font_funcs_list ();
2697
2698
static const char * const nil_font_funcs_list[] = {nullptr};
2699
2700
static struct hb_font_funcs_list_lazy_loader_t : hb_lazy_loader_t<const char *,
2701
                  hb_font_funcs_list_lazy_loader_t>
2702
{
2703
  static const char ** create ()
2704
0
  {
2705
0
    const char **font_funcs_list = (const char **) hb_calloc (1 + ARRAY_LENGTH (supported_font_funcs), sizeof (const char *));
2706
0
    if (unlikely (!font_funcs_list))
2707
0
      return nullptr;
2708
2709
0
    unsigned i;
2710
0
    for (i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
2711
0
      font_funcs_list[i] = supported_font_funcs[i].name;
2712
0
    font_funcs_list[i] = nullptr;
2713
2714
0
    hb_atexit (free_static_font_funcs_list);
2715
2716
0
    return font_funcs_list;
2717
0
  }
2718
  static void destroy (const char **l)
2719
0
  { hb_free (l); }
2720
  static const char * const * get_null ()
2721
0
  { return nil_font_funcs_list; }
2722
} static_font_funcs_list;
2723
2724
static inline
2725
void free_static_font_funcs_list ()
2726
0
{
2727
0
  static_font_funcs_list.free_instance ();
2728
0
}
2729
2730
/**
2731
 * hb_font_list_funcs:
2732
 *
2733
 * Retrieves the list of font functions supported by HarfBuzz.
2734
 *
2735
 * Return value: (transfer none) (array zero-terminated=1): a
2736
 *    `NULL`-terminated array of supported font functions
2737
 *    constant strings. The returned array is owned by HarfBuzz
2738
 *    and should not be modified or freed.
2739
 *
2740
 * Since: 11.0.0
2741
 **/
2742
const char **
2743
hb_font_list_funcs ()
2744
0
{
2745
0
  return static_font_funcs_list.get_unconst ();
2746
0
}
2747
2748
/**
2749
 * hb_font_set_scale:
2750
 * @font: #hb_font_t to work upon
2751
 * @x_scale: Horizontal scale value to assign
2752
 * @y_scale: Vertical scale value to assign
2753
 *
2754
 * Sets the horizontal and vertical scale of a font.
2755
 *
2756
 * The font scale is a number related to, but not the same as,
2757
 * font size. Typically the client establishes a scale factor
2758
 * to be used between the two. For example, 64, or 256, which
2759
 * would be the fractional-precision part of the font scale.
2760
 * This is necessary because #hb_position_t values are integer
2761
 * types and you need to leave room for fractional values
2762
 * in there.
2763
 *
2764
 * For example, to set the font size to 20, with 64
2765
 * levels of fractional precision you would call
2766
 * `hb_font_set_scale(font, 20 * 64, 20 * 64)`.
2767
 *
2768
 * In the example above, even what font size 20 means is up to
2769
 * you. It might be 20 pixels, or 20 points, or 20 millimeters.
2770
 * HarfBuzz does not care about that.  You can set the point
2771
 * size of the font using hb_font_set_ptem(), and the pixel
2772
 * size using hb_font_set_ppem().
2773
 *
2774
 * The choice of scale is yours but needs to be consistent between
2775
 * what you set here, and what you expect out of #hb_position_t
2776
 * as well has draw / paint API output values.
2777
 *
2778
 * Fonts default to a scale equal to the UPEM value of their face.
2779
 * A font with this setting is sometimes called an "unscaled" font.
2780
 *
2781
 * Since: 0.9.2
2782
 **/
2783
void
2784
hb_font_set_scale (hb_font_t *font,
2785
       int        x_scale,
2786
       int        y_scale)
2787
43.8k
{
2788
43.8k
  if (hb_object_is_immutable (font))
2789
78
    return;
2790
2791
43.7k
  if (font->x_scale == x_scale && font->y_scale == y_scale)
2792
0
    return;
2793
2794
43.7k
  font->x_scale = x_scale;
2795
43.7k
  font->y_scale = y_scale;
2796
2797
43.7k
  font->changed ();
2798
43.7k
}
2799
2800
/**
2801
 * hb_font_get_scale:
2802
 * @font: #hb_font_t to work upon
2803
 * @x_scale: (out): Horizontal scale value
2804
 * @y_scale: (out): Vertical scale value
2805
 *
2806
 * Fetches the horizontal and vertical scale of a font.
2807
 *
2808
 * Since: 0.9.2
2809
 **/
2810
void
2811
hb_font_get_scale (hb_font_t *font,
2812
       int       *x_scale,
2813
       int       *y_scale)
2814
0
{
2815
0
  if (x_scale) *x_scale = font->x_scale;
2816
0
  if (y_scale) *y_scale = font->y_scale;
2817
0
}
2818
2819
/**
2820
 * hb_font_set_ppem:
2821
 * @font: #hb_font_t to work upon
2822
 * @x_ppem: Horizontal ppem value to assign
2823
 * @y_ppem: Vertical ppem value to assign
2824
 *
2825
 * Sets the horizontal and vertical pixels-per-em (PPEM) of a font.
2826
 *
2827
 * These values are used for pixel-size-specific adjustment to
2828
 * shaping and draw results, though for the most part they are
2829
 * unused and can be left unset.
2830
 *
2831
 * Since: 0.9.2
2832
 **/
2833
void
2834
hb_font_set_ppem (hb_font_t    *font,
2835
      unsigned int  x_ppem,
2836
      unsigned int  y_ppem)
2837
0
{
2838
0
  if (hb_object_is_immutable (font))
2839
0
    return;
2840
2841
0
  if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
2842
0
    return;
2843
2844
0
  font->x_ppem = x_ppem;
2845
0
  font->y_ppem = y_ppem;
2846
2847
0
  font->changed ();
2848
0
}
2849
2850
/**
2851
 * hb_font_get_ppem:
2852
 * @font: #hb_font_t to work upon
2853
 * @x_ppem: (out): Horizontal ppem value
2854
 * @y_ppem: (out): Vertical ppem value
2855
 *
2856
 * Fetches the horizontal and vertical points-per-em (ppem) of a font.
2857
 *
2858
 * Since: 0.9.2
2859
 **/
2860
void
2861
hb_font_get_ppem (hb_font_t    *font,
2862
      unsigned int *x_ppem,
2863
      unsigned int *y_ppem)
2864
0
{
2865
0
  if (x_ppem) *x_ppem = font->x_ppem;
2866
0
  if (y_ppem) *y_ppem = font->y_ppem;
2867
0
}
2868
2869
/**
2870
 * hb_font_set_ptem:
2871
 * @font: #hb_font_t to work upon
2872
 * @ptem: font size in points.
2873
 *
2874
 * Sets the "point size" of a font. Set to zero to unset.
2875
 * Used in CoreText to implement optical sizing.
2876
 *
2877
 * <note>Note: There are 72 points in an inch.</note>
2878
 *
2879
 * Since: 1.6.0
2880
 **/
2881
void
2882
hb_font_set_ptem (hb_font_t *font,
2883
      float      ptem)
2884
0
{
2885
0
  if (hb_object_is_immutable (font))
2886
0
    return;
2887
2888
0
  if (font->ptem == ptem)
2889
0
    return;
2890
2891
0
  font->ptem = ptem;
2892
2893
0
  font->changed ();
2894
0
}
2895
2896
/**
2897
 * hb_font_get_ptem:
2898
 * @font: #hb_font_t to work upon
2899
 *
2900
 * Fetches the "point size" of a font. Used in CoreText to
2901
 * implement optical sizing.
2902
 *
2903
 * Return value: Point size.  A value of zero means "not set."
2904
 *
2905
 * Since: 1.6.0
2906
 **/
2907
float
2908
hb_font_get_ptem (hb_font_t *font)
2909
0
{
2910
0
  return font->ptem;
2911
0
}
2912
2913
/**
2914
 * hb_font_is_synthetic:
2915
 * @font: #hb_font_t to work upon
2916
 *
2917
 * Tests whether a font is synthetic. A synthetic font is one
2918
 * that has either synthetic slant or synthetic bold set on it.
2919
 *
2920
 * Return value: `true` if the font is synthetic, `false` otherwise.
2921
 *
2922
 * Since: 11.2.0
2923
 */
2924
hb_bool_t
2925
hb_font_is_synthetic (hb_font_t *font)
2926
0
{
2927
0
  return font->is_synthetic;
2928
0
}
2929
2930
/**
2931
 * hb_font_set_synthetic_bold:
2932
 * @font: #hb_font_t to work upon
2933
 * @x_embolden: the amount to embolden horizontally
2934
 * @y_embolden: the amount to embolden vertically
2935
 * @in_place: whether to embolden glyphs in-place
2936
 *
2937
 * Sets the "synthetic boldness" of a font.
2938
 *
2939
 * Positive values for @x_embolden / @y_embolden make a font
2940
 * bolder, negative values thinner. Typical values are in the
2941
 * 0.01 to 0.05 range. The default value is zero.
2942
 *
2943
 * Synthetic boldness is applied by offsetting the contour
2944
 * points of the glyph shape.
2945
 *
2946
 * Synthetic boldness is applied when rendering a glyph via
2947
 * hb_font_draw_glyph_or_fail().
2948
 *
2949
 * If @in_place is `false`, then glyph advance-widths are also
2950
 * adjusted, otherwise they are not.  The in-place mode is
2951
 * useful for simulating [font grading](https://fonts.google.com/knowledge/glossary/grade).
2952
 *
2953
 *
2954
 * Since: 7.0.0
2955
 **/
2956
void
2957
hb_font_set_synthetic_bold (hb_font_t *font,
2958
          float x_embolden,
2959
          float y_embolden,
2960
          hb_bool_t in_place)
2961
0
{
2962
0
  if (hb_object_is_immutable (font))
2963
0
    return;
2964
2965
0
  if (font->x_embolden == x_embolden &&
2966
0
      font->y_embolden == y_embolden &&
2967
0
      font->embolden_in_place == (bool) in_place)
2968
0
    return;
2969
2970
0
  font->x_embolden = x_embolden;
2971
0
  font->y_embolden = y_embolden;
2972
0
  font->embolden_in_place = in_place;
2973
2974
0
  font->changed ();
2975
0
}
2976
2977
/**
2978
 * hb_font_get_synthetic_bold:
2979
 * @font: #hb_font_t to work upon
2980
 * @x_embolden: (out): return location for horizontal value
2981
 * @y_embolden: (out): return location for vertical value
2982
 * @in_place: (out): return location for in-place value
2983
 *
2984
 * Fetches the "synthetic boldness" parameters of a font.
2985
 *
2986
 * Since: 7.0.0
2987
 **/
2988
void
2989
hb_font_get_synthetic_bold (hb_font_t *font,
2990
          float *x_embolden,
2991
          float *y_embolden,
2992
          hb_bool_t *in_place)
2993
0
{
2994
0
  if (x_embolden) *x_embolden = font->x_embolden;
2995
0
  if (y_embolden) *y_embolden = font->y_embolden;
2996
0
  if (in_place) *in_place = font->embolden_in_place;
2997
0
}
2998
2999
/**
3000
 * hb_font_set_synthetic_slant:
3001
 * @font: #hb_font_t to work upon
3002
 * @slant: synthetic slant value.
3003
 *
3004
 * Sets the "synthetic slant" of a font.  By default is zero.
3005
 * Synthetic slant is the graphical skew applied to the font
3006
 * at rendering time.
3007
 *
3008
 * HarfBuzz needs to know this value to adjust shaping results,
3009
 * metrics, and style values to match the slanted rendering.
3010
 *
3011
 * <note>Note: The glyph shape fetched via the hb_font_draw_glyph_or_fail()
3012
 * function is slanted to reflect this value as well.</note>
3013
 *
3014
 * <note>Note: The slant value is a ratio.  For example, a
3015
 * 20% slant would be represented as a 0.2 value.</note>
3016
 *
3017
 * Since: 3.3.0
3018
 **/
3019
HB_EXTERN void
3020
hb_font_set_synthetic_slant (hb_font_t *font, float slant)
3021
0
{
3022
0
  if (hb_object_is_immutable (font))
3023
0
    return;
3024
3025
0
  if (font->slant == slant)
3026
0
    return;
3027
3028
0
  font->slant = slant;
3029
3030
0
  font->changed ();
3031
0
}
3032
3033
/**
3034
 * hb_font_get_synthetic_slant:
3035
 * @font: #hb_font_t to work upon
3036
 *
3037
 * Fetches the "synthetic slant" of a font.
3038
 *
3039
 * Return value: Synthetic slant.  By default is zero.
3040
 *
3041
 * Since: 3.3.0
3042
 **/
3043
HB_EXTERN float
3044
hb_font_get_synthetic_slant (hb_font_t *font)
3045
0
{
3046
0
  return font->slant;
3047
0
}
3048
3049
#ifndef HB_NO_VAR
3050
/*
3051
 * Variations
3052
 */
3053
3054
/**
3055
 * hb_font_set_variations:
3056
 * @font: #hb_font_t to work upon
3057
 * @variations: (array length=variations_length): Array of variation settings to apply
3058
 * @variations_length: Number of variations to apply
3059
 *
3060
 * Applies a list of font-variation settings to a font.
3061
 *
3062
 * Note that this overrides all existing variations set on @font.
3063
 * Axes not included in @variations will be effectively set to their
3064
 * default values.
3065
 *
3066
 * Since: 1.4.2
3067
 */
3068
void
3069
hb_font_set_variations (hb_font_t            *font,
3070
      const hb_variation_t *variations,
3071
      unsigned int          variations_length)
3072
43.9k
{
3073
43.9k
  if (hb_object_is_immutable (font))
3074
78
    return;
3075
3076
43.9k
  const OT::fvar &fvar = *font->face->table.fvar;
3077
43.9k
  auto axes = fvar.get_axes ();
3078
43.9k
  const unsigned coords_length = axes.length;
3079
3080
43.9k
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
3081
43.9k
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
3082
3083
43.9k
  if (unlikely (coords_length && !(normalized && design_coords)))
3084
50
  {
3085
50
    hb_free (normalized);
3086
50
    hb_free (design_coords);
3087
50
    return;
3088
50
  }
3089
3090
  /* Initialize design coords. */
3091
73.6k
  for (unsigned int i = 0; i < coords_length; i++)
3092
29.8k
    design_coords[i] = axes[i].get_default ();
3093
43.8k
  if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE)
3094
0
  {
3095
0
    unsigned count = coords_length;
3096
    /* This may fail if index is out-of-range;
3097
     * That's why we initialize design_coords from fvar above
3098
     * unconditionally. */
3099
0
    hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index,
3100
0
            &count, design_coords);
3101
0
  }
3102
3103
43.9k
  for (unsigned int i = 0; i < variations_length; i++)
3104
59
  {
3105
59
    const auto tag = variations[i].tag;
3106
59
    const auto v = variations[i].value;
3107
2.24k
    for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
3108
2.19k
      if (axes[axis_index].axisTag == tag)
3109
1.06k
  design_coords[axis_index] = v;
3110
59
  }
3111
3112
43.8k
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
3113
43.8k
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
3114
43.8k
}
3115
3116
/**
3117
 * hb_font_set_variation:
3118
 * @font: #hb_font_t to work upon
3119
 * @tag: The #hb_tag_t tag of the variation-axis name
3120
 * @value: The value of the variation axis
3121
 *
3122
 * Change the value of one variation axis on the font.
3123
 *
3124
 * Note: This function is expensive to be called repeatedly.
3125
 *   If you want to set multiple variation axes at the same time,
3126
 *   use hb_font_set_variations() instead.
3127
 *
3128
 * Since: 7.1.0
3129
 */
3130
void
3131
hb_font_set_variation (hb_font_t *font,
3132
           hb_tag_t tag,
3133
           float    value)
3134
0
{
3135
0
  if (hb_object_is_immutable (font))
3136
0
    return;
3137
3138
  // TODO Share some of this code with set_variations()
3139
3140
0
  const OT::fvar &fvar = *font->face->table.fvar;
3141
0
  auto axes = fvar.get_axes ();
3142
0
  const unsigned coords_length = axes.length;
3143
3144
0
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
3145
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
3146
3147
0
  if (unlikely (coords_length && !(normalized && design_coords)))
3148
0
  {
3149
0
    hb_free (normalized);
3150
0
    hb_free (design_coords);
3151
0
    return;
3152
0
  }
3153
3154
  /* Initialize design coords. */
3155
0
  if (font->design_coords)
3156
0
  {
3157
0
    assert (coords_length == font->num_coords);
3158
0
    for (unsigned int i = 0; i < coords_length; i++)
3159
0
      design_coords[i] = font->design_coords[i];
3160
0
  }
3161
0
  else
3162
0
  {
3163
0
    for (unsigned int i = 0; i < coords_length; i++)
3164
0
      design_coords[i] = axes[i].get_default ();
3165
0
    if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE)
3166
0
    {
3167
0
      unsigned count = coords_length;
3168
      /* This may fail if index is out-of-range;
3169
       * That's why we initialize design_coords from fvar above
3170
       * unconditionally. */
3171
0
      hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index,
3172
0
              &count, design_coords);
3173
0
    }
3174
0
  }
3175
3176
0
  for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
3177
0
    if (axes[axis_index].axisTag == tag)
3178
0
      design_coords[axis_index] = value;
3179
3180
0
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
3181
0
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
3182
0
}
3183
3184
/**
3185
 * hb_font_set_var_coords_design:
3186
 * @font: #hb_font_t to work upon
3187
 * @coords: (array length=coords_length): Array of variation coordinates to apply
3188
 * @coords_length: Number of coordinates to apply
3189
 *
3190
 * Applies a list of variation coordinates (in design-space units)
3191
 * to a font.
3192
 *
3193
 * Note that this overrides all existing variations set on @font.
3194
 * Axes not included in @coords will be effectively set to their
3195
 * default values.
3196
 *
3197
 * Since: 1.4.2
3198
 */
3199
void
3200
hb_font_set_var_coords_design (hb_font_t    *font,
3201
             const float  *coords,
3202
             unsigned int  input_coords_length)
3203
0
{
3204
0
  if (hb_object_is_immutable (font))
3205
0
    return;
3206
3207
0
  const OT::fvar &fvar = *font->face->table.fvar;
3208
0
  auto axes = fvar.get_axes ();
3209
0
  const unsigned coords_length = axes.length;
3210
3211
0
  input_coords_length = hb_min (input_coords_length, coords_length);
3212
0
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
3213
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
3214
3215
0
  if (unlikely (coords_length && !(normalized && design_coords)))
3216
0
  {
3217
0
    hb_free (normalized);
3218
0
    hb_free (design_coords);
3219
0
    return;
3220
0
  }
3221
3222
0
  if (input_coords_length)
3223
0
    hb_memcpy (design_coords, coords, input_coords_length * sizeof (font->design_coords[0]));
3224
  // Fill in the rest with default values
3225
0
  for (unsigned int i = input_coords_length; i < coords_length; i++)
3226
0
    design_coords[i] = axes[i].get_default ();
3227
3228
0
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
3229
0
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
3230
0
}
3231
3232
/**
3233
 * hb_font_set_var_named_instance:
3234
 * @font: a font.
3235
 * @instance_index: named instance index.
3236
 *
3237
 * Sets design coords of a font from a named-instance index.
3238
 *
3239
 * Since: 2.6.0
3240
 */
3241
void
3242
hb_font_set_var_named_instance (hb_font_t *font,
3243
        unsigned int instance_index)
3244
0
{
3245
0
  if (hb_object_is_immutable (font))
3246
0
    return;
3247
3248
0
  if (font->instance_index == instance_index)
3249
0
    return;
3250
3251
0
  font->instance_index = instance_index;
3252
0
  hb_font_set_variations (font, nullptr, 0);
3253
0
}
3254
3255
/**
3256
 * hb_font_get_var_named_instance:
3257
 * @font: a font.
3258
 *
3259
 * Returns the currently-set named-instance index of the font.
3260
 *
3261
 * Return value: Named-instance index or %HB_FONT_NO_VAR_NAMED_INSTANCE.
3262
 *
3263
 * Since: 7.0.0
3264
 **/
3265
unsigned int
3266
hb_font_get_var_named_instance (hb_font_t *font)
3267
0
{
3268
0
  return font->instance_index;
3269
0
}
3270
3271
/**
3272
 * hb_font_set_var_coords_normalized:
3273
 * @font: #hb_font_t to work upon
3274
 * @coords: (array length=coords_length): Array of variation coordinates to apply
3275
 * @coords_length: Number of coordinates to apply
3276
 *
3277
 * Applies a list of variation coordinates (in normalized units)
3278
 * to a font.
3279
 *
3280
 * Note that this overrides all existing variations set on @font.
3281
 * Axes not included in @coords will be effectively set to their
3282
 * default values.
3283
 *
3284
 * <note>Note: Coordinates should be normalized to 2.14.</note>
3285
 *
3286
 * Since: 1.4.2
3287
 */
3288
void
3289
hb_font_set_var_coords_normalized (hb_font_t    *font,
3290
           const int    *coords, /* 2.14 normalized */
3291
           unsigned int  input_coords_length)
3292
43.3k
{
3293
43.3k
  if (hb_object_is_immutable (font))
3294
78
    return;
3295
3296
43.3k
  const OT::fvar &fvar = *font->face->table.fvar;
3297
43.3k
  auto axes = fvar.get_axes ();
3298
43.3k
  unsigned coords_length = axes.length;
3299
3300
43.3k
  input_coords_length = hb_min (input_coords_length, coords_length);
3301
43.3k
  int *copy = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
3302
43.3k
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (design_coords[0])) : nullptr;
3303
3304
43.3k
  if (unlikely (coords_length && !(copy && design_coords)))
3305
24
  {
3306
24
    hb_free (copy);
3307
24
    hb_free (design_coords);
3308
24
    return;
3309
24
  }
3310
3311
43.2k
  if (input_coords_length)
3312
2.82k
    hb_memcpy (copy, coords, input_coords_length * sizeof (coords[0]));
3313
3314
59.0k
  for (unsigned int i = 0; i < coords_length; ++i)
3315
15.8k
    design_coords[i] = NAN;
3316
3317
43.2k
  _hb_font_adopt_var_coords (font, copy, design_coords, coords_length);
3318
43.2k
}
3319
3320
/**
3321
 * hb_font_get_var_coords_normalized:
3322
 * @font: #hb_font_t to work upon
3323
 * @length: (out): Number of coordinates retrieved
3324
 *
3325
 * Fetches the list of normalized variation coordinates currently
3326
 * set on a font.
3327
 *
3328
 * <note>Note that if no variation coordinates are set, this function may
3329
 * return %NULL.</note>
3330
 *
3331
 * Return value is valid as long as variation coordinates of the font
3332
 * are not modified.
3333
 *
3334
 * Return value: coordinates array
3335
 *
3336
 * Since: 1.4.2
3337
 */
3338
const int *
3339
hb_font_get_var_coords_normalized (hb_font_t    *font,
3340
           unsigned int *length)
3341
0
{
3342
0
  if (length)
3343
0
    *length = font->num_coords;
3344
3345
0
  return font->coords;
3346
0
}
3347
3348
/**
3349
 * hb_font_get_var_coords_design:
3350
 * @font: #hb_font_t to work upon
3351
 * @length: (out): Number of coordinates retrieved
3352
 *
3353
 * Fetches the list of variation coordinates (in design-space units) currently
3354
 * set on a font.
3355
 *
3356
 * <note>Note that if no variation coordinates are set, this function may
3357
 * return %NULL.</note>
3358
 *
3359
 * <note>If variations have been set on the font using normalized coordinates
3360
 * (i.e. via hb_font_set_var_coords_normalized()), the design coordinates will
3361
 * have NaN (Not a Number) values.</note>
3362
 *
3363
 * Return value is valid as long as variation coordinates of the font
3364
 * are not modified.
3365
 *
3366
 * Return value: coordinates array
3367
 *
3368
 * Since: 3.3.0
3369
 */
3370
const float *
3371
hb_font_get_var_coords_design (hb_font_t *font,
3372
             unsigned int *length)
3373
0
{
3374
0
  if (length)
3375
0
    *length = font->num_coords;
3376
3377
0
  return font->design_coords;
3378
0
}
3379
#endif
3380
3381
#ifndef HB_DISABLE_DEPRECATED
3382
/*
3383
 * Deprecated get_glyph_func():
3384
 */
3385
3386
struct hb_trampoline_closure_t
3387
{
3388
  void *user_data;
3389
  hb_destroy_func_t destroy;
3390
  unsigned int ref_count;
3391
};
3392
3393
template <typename FuncType>
3394
struct hb_trampoline_t
3395
{
3396
  hb_trampoline_closure_t closure; /* Must be first. */
3397
  FuncType func;
3398
};
3399
3400
template <typename FuncType>
3401
static hb_trampoline_t<FuncType> *
3402
trampoline_create (FuncType           func,
3403
       void              *user_data,
3404
       hb_destroy_func_t  destroy)
3405
0
{
3406
0
  typedef hb_trampoline_t<FuncType> trampoline_t;
3407
3408
0
  trampoline_t *trampoline = (trampoline_t *) hb_calloc (1, sizeof (trampoline_t));
3409
3410
0
  if (unlikely (!trampoline))
3411
0
    return nullptr;
3412
3413
0
  trampoline->closure.user_data = user_data;
3414
0
  trampoline->closure.destroy = destroy;
3415
0
  trampoline->closure.ref_count = 1;
3416
0
  trampoline->func = func;
3417
3418
0
  return trampoline;
3419
0
}
3420
3421
static void
3422
trampoline_reference (hb_trampoline_closure_t *closure)
3423
0
{
3424
0
  closure->ref_count++;
3425
0
}
3426
3427
static void
3428
trampoline_destroy (void *user_data)
3429
0
{
3430
0
  hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
3431
3432
0
  if (--closure->ref_count)
3433
0
    return;
3434
3435
0
  if (closure->destroy)
3436
0
    closure->destroy (closure->user_data);
3437
0
  hb_free (closure);
3438
0
}
3439
3440
typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
3441
3442
static hb_bool_t
3443
hb_font_get_nominal_glyph_trampoline (hb_font_t      *font,
3444
              void           *font_data,
3445
              hb_codepoint_t  unicode,
3446
              hb_codepoint_t *glyph,
3447
              void           *user_data)
3448
0
{
3449
0
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
3450
0
  return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
3451
0
}
3452
3453
static hb_bool_t
3454
hb_font_get_variation_glyph_trampoline (hb_font_t      *font,
3455
          void           *font_data,
3456
          hb_codepoint_t  unicode,
3457
          hb_codepoint_t  variation_selector,
3458
          hb_codepoint_t *glyph,
3459
          void           *user_data)
3460
0
{
3461
0
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
3462
0
  return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
3463
0
}
3464
3465
/**
3466
 * hb_font_funcs_set_glyph_func:
3467
 * @ffuncs: The font-functions structure
3468
 * @func: (closure user_data) (destroy destroy) (scope notified): callback function
3469
 * @user_data: data to pass to @func
3470
 * @destroy: (nullable): function to call when @user_data is not needed anymore
3471
 *
3472
 * Deprecated.  Use hb_font_funcs_set_nominal_glyph_func() and
3473
 * hb_font_funcs_set_variation_glyph_func() instead.
3474
 *
3475
 * Since: 0.9.2
3476
 * Deprecated: 1.2.3
3477
 **/
3478
void
3479
hb_font_funcs_set_glyph_func (hb_font_funcs_t          *ffuncs,
3480
            hb_font_get_glyph_func_t  func,
3481
            void                     *user_data,
3482
            hb_destroy_func_t         destroy /* May be NULL. */)
3483
0
{
3484
0
  if (hb_object_is_immutable (ffuncs))
3485
0
  {
3486
0
    if (destroy)
3487
0
      destroy (user_data);
3488
0
    return;
3489
0
  }
3490
3491
0
  hb_font_get_glyph_trampoline_t *trampoline;
3492
3493
0
  trampoline = trampoline_create (func, user_data, destroy);
3494
0
  if (unlikely (!trampoline))
3495
0
  {
3496
0
    if (destroy)
3497
0
      destroy (user_data);
3498
0
    return;
3499
0
  }
3500
3501
  /* Since we pass it to two destroying functions. */
3502
0
  trampoline_reference (&trampoline->closure);
3503
3504
0
  hb_font_funcs_set_nominal_glyph_func (ffuncs,
3505
0
          hb_font_get_nominal_glyph_trampoline,
3506
0
          trampoline,
3507
0
          trampoline_destroy);
3508
3509
0
  hb_font_funcs_set_variation_glyph_func (ffuncs,
3510
0
            hb_font_get_variation_glyph_trampoline,
3511
0
            trampoline,
3512
0
            trampoline_destroy);
3513
0
}
3514
#endif
3515
3516
3517
#ifndef HB_DISABLE_DEPRECATED
3518
3519
struct hb_draw_glyph_closure_t
3520
{
3521
  hb_font_draw_glyph_func_t func;
3522
  void *user_data;
3523
  hb_destroy_func_t destroy;
3524
};
3525
static hb_bool_t
3526
hb_font_draw_glyph_trampoline (hb_font_t       *font,
3527
             void            *font_data,
3528
             hb_codepoint_t   glyph,
3529
             hb_draw_funcs_t *draw_funcs,
3530
             void            *draw_data,
3531
             void            *user_data)
3532
0
{
3533
0
  hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data;
3534
0
  closure->func (font, font_data, glyph, draw_funcs, draw_data, closure->user_data);
3535
0
  return true;
3536
0
}
3537
static void
3538
hb_font_draw_glyph_closure_destroy (void *user_data)
3539
0
{
3540
0
  hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data;
3541
3542
0
  if (closure->destroy)
3543
0
    closure->destroy (closure->user_data);
3544
0
  hb_free (closure);
3545
0
}
3546
static void
3547
_hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t           *ffuncs,
3548
            hb_font_draw_glyph_func_t  func,
3549
            void                      *user_data,
3550
            hb_destroy_func_t          destroy /* May be NULL. */)
3551
0
{
3552
0
  if (hb_object_is_immutable (ffuncs))
3553
0
  {
3554
0
    if (destroy)
3555
0
      destroy (user_data);
3556
0
    return;
3557
0
  }
3558
0
  hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) hb_calloc (1, sizeof (hb_draw_glyph_closure_t));
3559
0
  if (unlikely (!closure))
3560
0
  {
3561
0
    if (destroy)
3562
0
      destroy (user_data);
3563
0
    return;
3564
0
  }
3565
0
  closure->func = func;
3566
0
  closure->user_data = user_data;
3567
0
  closure->destroy = destroy;
3568
3569
0
  hb_font_funcs_set_draw_glyph_or_fail_func (ffuncs,
3570
0
               hb_font_draw_glyph_trampoline,
3571
0
               closure,
3572
0
               hb_font_draw_glyph_closure_destroy);
3573
0
}
3574
void
3575
hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t           *ffuncs,
3576
                                   hb_font_draw_glyph_func_t  func,
3577
                                   void                      *user_data,
3578
                                   hb_destroy_func_t          destroy /* May be NULL. */)
3579
0
{
3580
0
  _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
3581
0
}
3582
void
3583
hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t               *ffuncs,
3584
                                   hb_font_get_glyph_shape_func_t  func,
3585
                                   void                           *user_data,
3586
                                   hb_destroy_func_t               destroy /* May be NULL. */)
3587
0
{
3588
0
  _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
3589
0
}
3590
3591
struct hb_paint_glyph_closure_t
3592
{
3593
  hb_font_paint_glyph_func_t func;
3594
  void *user_data;
3595
  hb_destroy_func_t destroy;
3596
};
3597
static hb_bool_t
3598
hb_font_paint_glyph_trampoline (hb_font_t        *font,
3599
        void *font_data,
3600
        hb_codepoint_t glyph,
3601
        hb_paint_funcs_t *paint_funcs,
3602
        void *paint_data,
3603
        unsigned int palette,
3604
        hb_color_t foreground,
3605
        void *user_data)
3606
0
{
3607
0
  hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data;
3608
0
  closure->func (font, font_data, glyph, paint_funcs, paint_data, palette, foreground, closure->user_data);
3609
0
  return true;
3610
0
}
3611
static void
3612
hb_font_paint_glyph_closure_destroy (void *user_data)
3613
0
{
3614
0
  hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data;
3615
3616
0
  if (closure->destroy)
3617
0
    closure->destroy (closure->user_data);
3618
0
  hb_free (closure);
3619
0
}
3620
void
3621
hb_font_funcs_set_paint_glyph_func (hb_font_funcs_t           *ffuncs,
3622
            hb_font_paint_glyph_func_t  func,
3623
            void                      *user_data,
3624
            hb_destroy_func_t          destroy /* May be NULL. */)
3625
0
{
3626
0
  if (hb_object_is_immutable (ffuncs))
3627
0
  {
3628
0
    if (destroy)
3629
0
      destroy (user_data);
3630
0
    return;
3631
0
  }
3632
0
  hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) hb_calloc (1, sizeof (hb_paint_glyph_closure_t));
3633
0
  if (unlikely (!closure))
3634
0
  {
3635
0
    if (destroy)
3636
0
      destroy (user_data);
3637
0
    return;
3638
0
  }
3639
0
  closure->func = func;
3640
0
  closure->user_data = user_data;
3641
0
  closure->destroy = destroy;
3642
3643
0
  hb_font_funcs_set_paint_glyph_or_fail_func (ffuncs,
3644
0
                hb_font_paint_glyph_trampoline,
3645
0
                closure,
3646
0
                hb_font_paint_glyph_closure_destroy);
3647
0
}
3648
#endif