Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/workdir/UnpackedTarball/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
229k
{
106
229k
  hb_bool_t ret = font->parent->get_font_h_extents (extents, false);
107
229k
  if (ret) {
108
229k
    extents->ascender = font->parent_scale_y_distance (extents->ascender);
109
229k
    extents->descender = font->parent_scale_y_distance (extents->descender);
110
229k
    extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
111
229k
  }
112
229k
  return ret;
113
229k
}
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
0
{
147
0
  *glyph = 0;
148
0
  return false;
149
0
}
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
0
{
158
0
  if (font->has_nominal_glyphs_func_set ())
159
0
  {
160
0
    return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
161
0
  }
162
0
  return font->parent->get_nominal_glyph (unicode, glyph);
163
0
}
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
0
{
177
0
  if (font->has_nominal_glyph_func_set ())
178
0
  {
179
0
    for (unsigned int i = 0; i < count; i++)
180
0
    {
181
0
      if (!font->get_nominal_glyph (*first_unicode, first_glyph))
182
0
  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
0
    return count;
188
0
  }
189
190
0
  return font->parent->get_nominal_glyphs (count,
191
0
             first_unicode, unicode_stride,
192
0
             first_glyph, glyph_stride);
193
0
}
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
0
{
203
0
  *glyph = 0;
204
0
  return false;
205
0
}
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
0
{
215
0
  return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
216
0
}
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
0
{
225
0
  return font->x_scale;
226
0
}
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
25.8M
{
234
25.8M
  if (font->has_glyph_h_advances_func_set ())
235
12.9M
  {
236
12.9M
    hb_position_t ret;
237
12.9M
    font->get_glyph_h_advances (1, &glyph, 0, &ret, 0, false);
238
12.9M
    return ret;
239
12.9M
  }
240
12.9M
  return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph, false));
241
25.8M
}
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
0
{
249
0
  return -font->y_scale;
250
0
}
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
0
{
258
0
  if (font->has_glyph_v_advances_func_set ())
259
0
  {
260
0
    hb_position_t ret;
261
0
    font->get_glyph_v_advances (1, &glyph, 0, &ret, 0, false);
262
0
    return ret;
263
0
  }
264
0
  return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph, false));
265
0
}
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
13.8M
{
279
13.8M
  if (font->has_glyph_h_advance_func_set ())
280
0
  {
281
0
    for (unsigned int i = 0; i < count; i++)
282
0
    {
283
0
      *first_advance = font->get_glyph_h_advance (*first_glyph, false);
284
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
285
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
286
0
    }
287
0
    return;
288
0
  }
289
290
13.8M
  font->parent->get_glyph_h_advances (count,
291
13.8M
              first_glyph, glyph_stride,
292
13.8M
              first_advance, advance_stride,
293
13.8M
              false);
294
236M
  for (unsigned int i = 0; i < count; i++)
295
223M
  {
296
223M
    *first_advance = font->parent_scale_x_distance (*first_advance);
297
223M
    first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
298
223M
  }
299
13.8M
}
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
163k
{
312
163k
  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
163k
  font->parent->get_glyph_v_advances (count,
324
163k
              first_glyph, glyph_stride,
325
163k
              first_advance, advance_stride,
326
163k
              false);
327
810k
  for (unsigned int i = 0; i < count; i++)
328
646k
  {
329
646k
    *first_advance = font->parent_scale_y_distance (*first_advance);
330
646k
    first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
331
646k
  }
332
163k
}
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
0
{
342
0
  *x = *y = 0;
343
0
  return true;
344
0
}
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
0
{
354
0
  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
0
  hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
359
0
  if (ret)
360
0
    font->parent_scale_position (x, y);
361
0
  return ret;
362
0
}
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
0
{
372
0
  return false;
373
0
}
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
0
{
383
0
  if (font->has_glyph_v_origins_func_set ())
384
0
  {
385
0
    return font->get_glyph_v_origins (1, &glyph, 0, x, 0, y, 0, false);
386
0
  }
387
0
  hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
388
0
  if (ret)
389
0
    font->parent_scale_position (x, y);
390
0
  return ret;
391
0
}
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
166k
{
450
166k
  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
166k
  hb_bool_t ret = font->parent->get_glyph_v_origins (count,
464
166k
                 first_glyph, glyph_stride,
465
166k
                 first_x, x_stride,
466
166k
                 first_y, y_stride);
467
166k
  if (ret)
468
166k
  {
469
813k
    for (unsigned i = 0; i < count; i++)
470
646k
    {
471
646k
      font->parent_scale_position (first_x, first_y);
472
646k
      first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride);
473
646k
      first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride);
474
646k
    }
475
166k
  }
476
166k
  return ret;
477
166k
}
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
0
{
528
0
  hb_memset (extents, 0, sizeof (*extents));
529
0
  return false;
530
0
}
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
498k
{
539
498k
  hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents, false);
540
498k
  if (ret) {
541
498k
    font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
542
498k
    font->parent_scale_distance (&extents->width, &extents->height);
543
498k
  }
544
498k
  return ret;
545
498k
}
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
0
{
556
0
  *x = *y = 0;
557
0
  return false;
558
0
}
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
0
{
569
0
  hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y, false);
570
0
  if (ret)
571
0
    font->parent_scale_position (x, y);
572
0
  return ret;
573
0
}
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
0
{
583
0
  if (size) *name = '\0';
584
0
  return false;
585
0
}
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
0
{
595
0
  return font->parent->get_glyph_name (glyph, name, size);
596
0
}
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
0
{
606
0
  *glyph = 0;
607
0
  return false;
608
0
}
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
0
{
618
0
  return font->parent->get_glyph_from_name (name, len, glyph);
619
0
}
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
0
{
629
0
  return false;
630
0
}
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
0
{
642
0
  return false;
643
0
}
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
299
{
659
299
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
660
299
  float x_scale = adaptor->x_scale;
661
299
  float y_scale = adaptor->y_scale;
662
663
299
  adaptor->draw_funcs->emit_move_to (adaptor->draw_data, *st,
664
299
             x_scale * to_x, y_scale * to_y);
665
299
}
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
1.27k
{
673
1.27k
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
674
1.27k
  float x_scale = adaptor->x_scale;
675
1.27k
  float y_scale = adaptor->y_scale;
676
677
1.27k
  st->current_x = st->current_x * x_scale;
678
1.27k
  st->current_y = st->current_y * y_scale;
679
680
1.27k
  adaptor->draw_funcs->emit_line_to (adaptor->draw_data, *st,
681
1.27k
             x_scale * to_x, y_scale * to_y);
682
1.27k
}
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
317
{
691
317
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
692
317
  float x_scale = adaptor->x_scale;
693
317
  float y_scale = adaptor->y_scale;
694
695
317
  st->current_x = st->current_x * x_scale;
696
317
  st->current_y = st->current_y * y_scale;
697
698
317
  adaptor->draw_funcs->emit_quadratic_to (adaptor->draw_data, *st,
699
317
            x_scale * control_x, y_scale * control_y,
700
317
            x_scale * to_x, y_scale * to_y);
701
317
}
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
299
{
729
299
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
730
731
299
  adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st);
732
299
}
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
332
{
755
332
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
756
332
  return adaptor->draw_funcs->get_budget_remaining_ptr (adaptor->draw_data);
757
332
}
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
332
{
777
332
  hb_font_draw_glyph_default_adaptor_t adaptor = {
778
332
    draw_funcs,
779
332
    draw_data,
780
332
    font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0.f,
781
332
    font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f
782
332
  };
783
784
332
  return font->parent->draw_glyph_or_fail (glyph,
785
332
             const_cast<hb_draw_funcs_t *> (&_hb_draw_funcs_default),
786
332
             &adaptor,
787
332
             false);
788
332
}
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
0
{
800
0
  paint_funcs->push_transform (paint_data,
801
0
    font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0, 0,
802
0
    0, font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0,
803
0
    0, 0);
804
805
0
  bool ret = font->parent->paint_glyph_or_fail (glyph, paint_funcs, paint_data, palette, foreground);
806
807
0
  paint_funcs->pop_transform (paint_data);
808
809
0
  return ret;
810
0
}
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
46
{
854
46
  hb_font_funcs_t *ffuncs;
855
856
46
  if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
857
0
    return hb_font_funcs_get_empty ();
858
859
46
  ffuncs->get = _hb_font_funcs_default.get;
860
861
46
  return ffuncs;
862
46
}
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
481k
{
876
481k
  return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
877
481k
}
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
465k
{
892
465k
  return hb_object_reference (ffuncs);
893
465k
}
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
779k
{
908
779k
  if (!hb_object_destroy (ffuncs)) return;
909
910
0
  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
0
  hb_free (ffuncs->destroy);
919
0
  hb_free (ffuncs->user_data);
920
921
0
  hb_free (ffuncs);
922
0
}
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
23
{
979
23
  if (hb_object_is_immutable (ffuncs))
980
0
    return;
981
982
23
  hb_object_make_immutable (ffuncs);
983
23
}
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
368
{
1008
368
  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
368
  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
368
  return true;
1024
368
}
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
368
{
1031
368
  auto destroy_guard = hb_make_scope_guard ([&]() {
1032
0
    if (destroy) destroy (user_data);
1033
0
  });
1034
1035
368
  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
368
  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
368
  destroy_guard.release ();
1049
368
  return true;
1050
368
}
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
368
         hb_destroy_func_t            destroy)   \
1059
368
{                                                                        \
1060
368
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
368
      return;                                                            \
1062
368
                   \
1063
368
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
368
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
368
                                                                         \
1066
368
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
368
      return;                                                            \
1068
368
                   \
1069
368
  if (func)                                                              \
1070
368
    ffuncs->get.f.name = func;                                           \
1071
368
  else                                                                   \
1072
368
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
368
                   \
1074
368
  if (ffuncs->user_data)                                                 \
1075
368
    ffuncs->user_data->name = user_data;                                 \
1076
368
  if (ffuncs->destroy)                                                   \
1077
368
    ffuncs->destroy->name = destroy;                                     \
1078
368
}
hb_font_funcs_set_font_h_extents_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
hb_font_funcs_set_font_v_extents_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
hb_font_funcs_set_nominal_glyph_func
Line
Count
Source
1058
46
         hb_destroy_func_t            destroy)   \
1059
46
{                                                                        \
1060
46
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
46
      return;                                                            \
1062
46
                   \
1063
46
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
46
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
46
                                                                         \
1066
46
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
46
      return;                                                            \
1068
46
                   \
1069
46
  if (func)                                                              \
1070
46
    ffuncs->get.f.name = func;                                           \
1071
46
  else                                                                   \
1072
46
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
46
                   \
1074
46
  if (ffuncs->user_data)                                                 \
1075
46
    ffuncs->user_data->name = user_data;                                 \
1076
46
  if (ffuncs->destroy)                                                   \
1077
46
    ffuncs->destroy->name = destroy;                                     \
1078
46
}
hb_font_funcs_set_nominal_glyphs_func
Line
Count
Source
1058
46
         hb_destroy_func_t            destroy)   \
1059
46
{                                                                        \
1060
46
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
46
      return;                                                            \
1062
46
                   \
1063
46
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
46
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
46
                                                                         \
1066
46
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
46
      return;                                                            \
1068
46
                   \
1069
46
  if (func)                                                              \
1070
46
    ffuncs->get.f.name = func;                                           \
1071
46
  else                                                                   \
1072
46
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
46
                   \
1074
46
  if (ffuncs->user_data)                                                 \
1075
46
    ffuncs->user_data->name = user_data;                                 \
1076
46
  if (ffuncs->destroy)                                                   \
1077
46
    ffuncs->destroy->name = destroy;                                     \
1078
46
}
hb_font_funcs_set_variation_glyph_func
Line
Count
Source
1058
46
         hb_destroy_func_t            destroy)   \
1059
46
{                                                                        \
1060
46
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
46
      return;                                                            \
1062
46
                   \
1063
46
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
46
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
46
                                                                         \
1066
46
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
46
      return;                                                            \
1068
46
                   \
1069
46
  if (func)                                                              \
1070
46
    ffuncs->get.f.name = func;                                           \
1071
46
  else                                                                   \
1072
46
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
46
                   \
1074
46
  if (ffuncs->user_data)                                                 \
1075
46
    ffuncs->user_data->name = user_data;                                 \
1076
46
  if (ffuncs->destroy)                                                   \
1077
46
    ffuncs->destroy->name = destroy;                                     \
1078
46
}
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
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
hb_font_funcs_set_glyph_v_advances_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
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
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
Unexecuted instantiation: hb_font_funcs_set_glyph_h_kerning_func
hb_font_funcs_set_glyph_extents_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
Unexecuted instantiation: hb_font_funcs_set_glyph_contour_point_func
hb_font_funcs_set_glyph_name_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
hb_font_funcs_set_glyph_from_name_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
hb_font_funcs_set_draw_glyph_or_fail_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
hb_font_funcs_set_paint_glyph_or_fail_func
Line
Count
Source
1058
23
         hb_destroy_func_t            destroy)   \
1059
23
{                                                                        \
1060
23
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
1061
23
      return;                                                            \
1062
23
                   \
1063
23
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
1064
23
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
1065
23
                                                                         \
1066
23
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
1067
23
      return;                                                            \
1068
23
                   \
1069
23
  if (func)                                                              \
1070
23
    ffuncs->get.f.name = func;                                           \
1071
23
  else                                                                   \
1072
23
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
1073
23
                   \
1074
23
  if (ffuncs->user_data)                                                 \
1075
23
    ffuncs->user_data->name = user_data;                                 \
1076
23
  if (ffuncs->destroy)                                                   \
1077
23
    ffuncs->destroy->name = destroy;                                     \
1078
23
}
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
207M
{
1086
207M
  return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
1087
207M
}
1088
1089
bool
1090
hb_font_t::has_func (unsigned int i)
1091
167M
{
1092
167M
  return has_func_set (i) ||
1093
167M
   (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
1094
167M
}
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
229k
{
1114
229k
  return font->get_font_h_extents (extents);
1115
229k
}
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
343k
{
1159
343k
  if (unlikely (variation_selector))
1160
42
    return font->get_variation_glyph (unicode, variation_selector, glyph);
1161
343k
  return font->get_nominal_glyph (unicode, glyph);
1162
343k
}
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
45.2M
{
1186
45.2M
  return font->get_nominal_glyph (unicode, glyph);
1187
45.2M
}
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
14.1M
{
1214
14.1M
  return font->get_nominal_glyphs (count,
1215
14.1M
           first_unicode, unicode_stride,
1216
14.1M
           first_glyph, glyph_stride);
1217
14.1M
}
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
22.3k
{
1240
22.3k
  return font->get_variation_glyph (unicode, variation_selector, glyph);
1241
22.3k
}
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
12.9M
{
1259
12.9M
  return font->get_glyph_h_advance (glyph);
1260
12.9M
}
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
0
{
1278
0
  return font->get_glyph_v_advance (glyph);
1279
0
}
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
0
{
1350
0
  return font->get_glyph_h_origin (glyph, x, y);
1351
0
}
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
0
{
1373
0
  return font->get_glyph_v_origin (glyph, x, y);
1374
0
}
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
498k
{
1516
498k
  return font->get_glyph_extents (glyph, extents);
1517
498k
}
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
0
{
1541
0
  return font->get_glyph_contour_point (glyph, point_index, x, y);
1542
0
}
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
0
{
1566
0
  return font->get_glyph_name (glyph, name, size);
1567
0
}
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
0
{
1590
0
  return font->get_glyph_from_name (name, len, glyph);
1591
0
}
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
332
{
1641
332
  return font->draw_glyph_or_fail (glyph, dfuncs, draw_data);
1642
332
}
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
0
{
1724
0
  (void) hb_font_draw_glyph_or_fail (font, glyph, dfuncs, draw_data);
1725
0
}
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
315k
{
2105
315k
  hb_font_t *font;
2106
2107
315k
  if (unlikely (!face))
2108
0
    face = hb_face_get_empty ();
2109
2110
315k
  if (!(font = hb_object_create<hb_font_t> ()))
2111
0
    return hb_font_get_empty ();
2112
2113
315k
  hb_face_make_immutable (face);
2114
315k
  font->parent = hb_font_get_empty ();
2115
315k
  font->face = hb_face_reference (face);
2116
315k
  font->klass = hb_font_funcs_get_empty ();
2117
315k
  font->data.init0 (font);
2118
315k
  font->x_scale = font->y_scale = face->get_upem ();
2119
315k
  font->embolden_in_place = true;
2120
315k
  font->x_multf = font->y_multf = 1.f;
2121
315k
  font->x_mult = font->y_mult = 1 << 16;
2122
315k
  font->instance_index = HB_FONT_NO_VAR_NAMED_INSTANCE;
2123
2124
315k
  return font;
2125
315k
}
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
165k
{
2147
165k
  hb_font_t *font = _hb_font_create (face);
2148
2149
165k
  hb_font_set_funcs_using (font, nullptr);
2150
2151
165k
#ifndef HB_NO_VAR
2152
  // Initialize variations.
2153
165k
  if (likely (face))
2154
165k
  {
2155
165k
    if (face->index >> 16)
2156
0
      hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
2157
165k
    else
2158
165k
      hb_font_set_variations (font, nullptr, 0);
2159
165k
  }
2160
165k
#endif
2161
2162
165k
  return font;
2163
165k
}
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
204k
{
2171
204k
  hb_free (font->coords);
2172
204k
  hb_free (font->design_coords);
2173
2174
204k
  font->coords = coords;
2175
204k
  font->design_coords = design_coords;
2176
204k
  font->num_coords = coords_length;
2177
204k
  font->has_nonzero_coords = hb_any (hb_array (coords, coords_length));
2178
2179
204k
  font->changed ();
2180
204k
  font->serial_coords = font->serial;
2181
204k
}
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
150k
{
2197
150k
  if (unlikely (!parent))
2198
0
    parent = hb_font_get_empty ();
2199
2200
150k
  hb_font_t *font = _hb_font_create (parent->face);
2201
2202
150k
  if (unlikely (hb_object_is_immutable (font)))
2203
0
    return font;
2204
2205
150k
  font->parent = hb_font_reference (parent);
2206
2207
150k
  font->x_scale = parent->x_scale;
2208
150k
  font->y_scale = parent->y_scale;
2209
150k
  font->x_embolden = parent->x_embolden;
2210
150k
  font->y_embolden = parent->y_embolden;
2211
150k
  font->embolden_in_place = parent->embolden_in_place;
2212
150k
  font->slant = parent->slant;
2213
150k
  font->x_ppem = parent->x_ppem;
2214
150k
  font->y_ppem = parent->y_ppem;
2215
150k
  font->ptem = parent->ptem;
2216
2217
150k
  unsigned int num_coords = parent->num_coords;
2218
150k
  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
150k
  font->changed ();
2236
150k
  font->serial_coords = font->serial;
2237
2238
150k
  return font;
2239
150k
}
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
315k
{
2253
315k
  return const_cast<hb_font_t *> (&Null (hb_font_t));
2254
315k
}
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
150k
{
2269
150k
  return hb_object_reference (font);
2270
150k
}
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
629k
{
2285
629k
  if (!hb_object_destroy (font)) return;
2286
2287
314k
  font->data.fini ();
2288
2289
314k
  if (font->destroy)
2290
164k
    font->destroy (font->user_data);
2291
2292
314k
  hb_font_destroy (font->parent);
2293
314k
  hb_face_destroy (font->face);
2294
314k
  hb_font_funcs_destroy (font->klass);
2295
2296
314k
  hb_free (font->coords);
2297
314k
  hb_free (font->design_coords);
2298
2299
314k
  hb_free (font);
2300
314k
}
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
150k
{
2469
150k
  return font->parent;
2470
150k
}
2471
2472
/**
2473
 * hb_font_set_face:
2474
 * @font: #hb_font_t to work upon
2475
 * @face: The #hb_face_t to assign
2476
 *
2477
 * Sets @face as the font-face value of @font.
2478
 *
2479
 * Since: 1.4.3
2480
 **/
2481
void
2482
hb_font_set_face (hb_font_t *font,
2483
      hb_face_t *face)
2484
0
{
2485
0
  if (hb_object_is_immutable (font))
2486
0
    return;
2487
2488
0
  if (face == font->face)
2489
0
    return;
2490
2491
0
  if (unlikely (!face))
2492
0
    face = hb_face_get_empty ();
2493
2494
0
  hb_face_t *old = font->face;
2495
2496
0
  hb_face_make_immutable (face);
2497
0
  font->face = hb_face_reference (face);
2498
0
  font->changed ();
2499
2500
0
  hb_face_destroy (old);
2501
2502
0
  font->changed ();
2503
0
  font->serial_coords = font->serial;
2504
0
}
2505
2506
/**
2507
 * hb_font_get_face:
2508
 * @font: #hb_font_t to work upon
2509
 *
2510
 * Fetches the face associated with the specified font object.
2511
 *
2512
 * Return value: (transfer none): The #hb_face_t value
2513
 *
2514
 * Since: 0.9.2
2515
 **/
2516
hb_face_t *
2517
hb_font_get_face (hb_font_t *font)
2518
5.91M
{
2519
5.91M
  return font->face;
2520
5.91M
}
2521
2522
2523
/**
2524
 * hb_font_set_funcs:
2525
 * @font: #hb_font_t to work upon
2526
 * @klass: The font-functions structure.
2527
 * @font_data: Data to attach to @font
2528
 * @destroy: (nullable) (scope async) (closure font_data): The function to call when @font_data is not needed anymore
2529
 *
2530
 * Replaces the font-functions structure attached to a font, updating
2531
 * the font's user-data with @font-data and the @destroy callback.
2532
 *
2533
 * Since: 0.9.2
2534
 **/
2535
void
2536
hb_font_set_funcs (hb_font_t         *font,
2537
       hb_font_funcs_t   *klass,
2538
       void              *font_data,
2539
       hb_destroy_func_t  destroy /* May be NULL. */)
2540
465k
{
2541
465k
  if (hb_object_is_immutable (font))
2542
0
  {
2543
0
    if (destroy)
2544
0
      destroy (font_data);
2545
0
    return;
2546
0
  }
2547
2548
465k
  if (font->destroy)
2549
150k
    font->destroy (font->user_data);
2550
2551
465k
  if (!klass)
2552
0
    klass = hb_font_funcs_get_empty ();
2553
2554
465k
  hb_font_funcs_reference (klass);
2555
465k
  hb_font_funcs_destroy (font->klass);
2556
465k
  font->klass = klass;
2557
465k
  font->user_data = font_data;
2558
465k
  font->destroy = destroy;
2559
2560
465k
  font->changed ();
2561
465k
}
2562
2563
/**
2564
 * hb_font_set_funcs_data:
2565
 * @font: #hb_font_t to work upon
2566
 * @font_data: Data to attach to @font
2567
 * @destroy: (nullable) (scope async) (closure font_data): The function to call when @font_data is not needed anymore
2568
 *
2569
 * Replaces the user data attached to a font, updating the font's
2570
 * @destroy callback.
2571
 *
2572
 * Since: 0.9.2
2573
 **/
2574
void
2575
hb_font_set_funcs_data (hb_font_t         *font,
2576
            void              *font_data,
2577
            hb_destroy_func_t  destroy /* May be NULL. */)
2578
0
{
2579
  /* Destroy user_data? */
2580
0
  if (hb_object_is_immutable (font))
2581
0
  {
2582
0
    if (destroy)
2583
0
      destroy (font_data);
2584
0
    return;
2585
0
  }
2586
2587
0
  if (font->destroy)
2588
0
    font->destroy (font->user_data);
2589
2590
0
  font->user_data = font_data;
2591
0
  font->destroy = destroy;
2592
2593
0
  font->changed ();
2594
0
}
2595
2596
static const struct supported_font_funcs_t {
2597
  char name[16];
2598
  void (*func) (hb_font_t *);
2599
} supported_font_funcs[] =
2600
{
2601
#ifndef HB_NO_OT_FONT
2602
  {"ot",  hb_ot_font_set_funcs},
2603
#endif
2604
#ifdef HAVE_FREETYPE
2605
  {"ft",  hb_ft_font_set_funcs},
2606
#endif
2607
#ifdef HAVE_FONTATIONS
2608
  {"fontations",hb_fontations_font_set_funcs},
2609
#endif
2610
#ifdef HAVE_CORETEXT
2611
  {"coretext",  hb_coretext_font_set_funcs},
2612
#endif
2613
#ifdef HAVE_DIRECTWRITE
2614
  {"directwrite",hb_directwrite_font_set_funcs},
2615
#endif
2616
};
2617
2618
static const char *get_default_funcs_name ()
2619
165k
{
2620
165k
  static hb_atomic_t<const char *> static_funcs_name;
2621
165k
  const char *name = static_funcs_name.get_acquire ();
2622
165k
  if (!name)
2623
23
  {
2624
23
    name = getenv ("HB_FONT_FUNCS");
2625
23
    if (!name)
2626
23
      name = "";
2627
23
    if (!static_funcs_name.cmpexch (nullptr, name))
2628
0
      name = static_funcs_name.get_acquire ();
2629
23
  }
2630
165k
  return name;
2631
165k
}
2632
2633
/**
2634
 * hb_font_set_funcs_using:
2635
 * @font: #hb_font_t to work upon
2636
 * @name: The name of the font-functions structure to use, or `NULL`
2637
 *
2638
 * Sets the font-functions structure to use for a font, based on the
2639
 * specified name.
2640
 *
2641
 * If @name is `NULL` or the empty string, the default (first) functioning font-functions
2642
 * are used.  This default can be changed by setting the `HB_FONT_FUNCS` environment
2643
 * variable to the name of the desired font-functions.
2644
 *
2645
 * Return value: `true` if the font-functions was found and set, `false` otherwise
2646
 *
2647
 * Since: 11.0.0
2648
 **/
2649
hb_bool_t
2650
hb_font_set_funcs_using (hb_font_t  *font,
2651
       const char *name)
2652
165k
{
2653
165k
  if (unlikely (hb_object_is_immutable (font)))
2654
0
    return false;
2655
2656
165k
  bool retry = false;
2657
2658
165k
  if (!name || !*name)
2659
165k
  {
2660
165k
    name = get_default_funcs_name ();
2661
165k
    retry = true;
2662
165k
  }
2663
165k
  if (name && !*name) name = nullptr;
2664
2665
165k
retry:
2666
165k
  for (unsigned i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
2667
165k
    if (!name || strcmp (supported_font_funcs[i].name, name) == 0)
2668
165k
    {
2669
165k
      supported_font_funcs[i].func (font);
2670
165k
      if (name || font->klass != hb_font_funcs_get_empty ())
2671
165k
  return true;
2672
165k
    }
2673
2674
0
  if (retry)
2675
0
  {
2676
0
    retry = false;
2677
0
    name = nullptr;
2678
0
    goto retry;
2679
0
  }
2680
2681
0
  return false;
2682
0
}
2683
2684
static inline void free_static_font_funcs_list ();
2685
2686
static const char * const nil_font_funcs_list[] = {nullptr};
2687
2688
static struct hb_font_funcs_list_lazy_loader_t : hb_lazy_loader_t<const char *,
2689
                  hb_font_funcs_list_lazy_loader_t>
2690
{
2691
  static const char ** create ()
2692
0
  {
2693
0
    const char **font_funcs_list = (const char **) hb_calloc (1 + ARRAY_LENGTH (supported_font_funcs), sizeof (const char *));
2694
0
    if (unlikely (!font_funcs_list))
2695
0
      return nullptr;
2696
2697
0
    unsigned i;
2698
0
    for (i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
2699
0
      font_funcs_list[i] = supported_font_funcs[i].name;
2700
0
    font_funcs_list[i] = nullptr;
2701
2702
0
    hb_atexit (free_static_font_funcs_list);
2703
2704
0
    return font_funcs_list;
2705
0
  }
2706
  static void destroy (const char **l)
2707
0
  { hb_free (l); }
2708
  static const char * const * get_null ()
2709
0
  { return nil_font_funcs_list; }
2710
} static_font_funcs_list;
2711
2712
static inline
2713
void free_static_font_funcs_list ()
2714
0
{
2715
0
  static_font_funcs_list.free_instance ();
2716
0
}
2717
2718
/**
2719
 * hb_font_list_funcs:
2720
 *
2721
 * Retrieves the list of font functions supported by HarfBuzz.
2722
 *
2723
 * Return value: (transfer none) (array zero-terminated=1): a
2724
 *    `NULL`-terminated array of supported font functions
2725
 *    constant strings. The returned array is owned by HarfBuzz
2726
 *    and should not be modified or freed.
2727
 *
2728
 * Since: 11.0.0
2729
 **/
2730
const char **
2731
hb_font_list_funcs ()
2732
0
{
2733
0
  return static_font_funcs_list.get_unconst ();
2734
0
}
2735
2736
/**
2737
 * hb_font_set_scale:
2738
 * @font: #hb_font_t to work upon
2739
 * @x_scale: Horizontal scale value to assign
2740
 * @y_scale: Vertical scale value to assign
2741
 *
2742
 * Sets the horizontal and vertical scale of a font.
2743
 *
2744
 * The font scale is a number related to, but not the same as,
2745
 * font size. Typically the client establishes a scale factor
2746
 * to be used between the two. For example, 64, or 256, which
2747
 * would be the fractional-precision part of the font scale.
2748
 * This is necessary because #hb_position_t values are integer
2749
 * types and you need to leave room for fractional values
2750
 * in there.
2751
 *
2752
 * For example, to set the font size to 20, with 64
2753
 * levels of fractional precision you would call
2754
 * `hb_font_set_scale(font, 20 * 64, 20 * 64)`.
2755
 *
2756
 * In the example above, even what font size 20 means is up to
2757
 * you. It might be 20 pixels, or 20 points, or 20 millimeters.
2758
 * HarfBuzz does not care about that.  You can set the point
2759
 * size of the font using hb_font_set_ptem(), and the pixel
2760
 * size using hb_font_set_ppem().
2761
 *
2762
 * The choice of scale is yours but needs to be consistent between
2763
 * what you set here, and what you expect out of #hb_position_t
2764
 * as well has draw / paint API output values.
2765
 *
2766
 * Fonts default to a scale equal to the UPEM value of their face.
2767
 * A font with this setting is sometimes called an "unscaled" font.
2768
 *
2769
 * Since: 0.9.2
2770
 **/
2771
void
2772
hb_font_set_scale (hb_font_t *font,
2773
       int        x_scale,
2774
       int        y_scale)
2775
150k
{
2776
150k
  if (hb_object_is_immutable (font))
2777
0
    return;
2778
2779
150k
  if (font->x_scale == x_scale && font->y_scale == y_scale)
2780
150k
    return;
2781
2782
0
  font->x_scale = x_scale;
2783
0
  font->y_scale = y_scale;
2784
2785
0
  font->changed ();
2786
0
}
2787
2788
/**
2789
 * hb_font_get_scale:
2790
 * @font: #hb_font_t to work upon
2791
 * @x_scale: (out): Horizontal scale value
2792
 * @y_scale: (out): Vertical scale value
2793
 *
2794
 * Fetches the horizontal and vertical scale of a font.
2795
 *
2796
 * Since: 0.9.2
2797
 **/
2798
void
2799
hb_font_get_scale (hb_font_t *font,
2800
       int       *x_scale,
2801
       int       *y_scale)
2802
0
{
2803
0
  if (x_scale) *x_scale = font->x_scale;
2804
0
  if (y_scale) *y_scale = font->y_scale;
2805
0
}
2806
2807
/**
2808
 * hb_font_set_ppem:
2809
 * @font: #hb_font_t to work upon
2810
 * @x_ppem: Horizontal ppem value to assign
2811
 * @y_ppem: Vertical ppem value to assign
2812
 *
2813
 * Sets the horizontal and vertical pixels-per-em (PPEM) of a font.
2814
 *
2815
 * These values are used for pixel-size-specific adjustment to
2816
 * shaping and draw results, though for the most part they are
2817
 * unused and can be left unset.
2818
 *
2819
 * Since: 0.9.2
2820
 **/
2821
void
2822
hb_font_set_ppem (hb_font_t    *font,
2823
      unsigned int  x_ppem,
2824
      unsigned int  y_ppem)
2825
0
{
2826
0
  if (hb_object_is_immutable (font))
2827
0
    return;
2828
2829
0
  if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
2830
0
    return;
2831
2832
0
  font->x_ppem = x_ppem;
2833
0
  font->y_ppem = y_ppem;
2834
2835
0
  font->changed ();
2836
0
}
2837
2838
/**
2839
 * hb_font_get_ppem:
2840
 * @font: #hb_font_t to work upon
2841
 * @x_ppem: (out): Horizontal ppem value
2842
 * @y_ppem: (out): Vertical ppem value
2843
 *
2844
 * Fetches the horizontal and vertical points-per-em (ppem) of a font.
2845
 *
2846
 * Since: 0.9.2
2847
 **/
2848
void
2849
hb_font_get_ppem (hb_font_t    *font,
2850
      unsigned int *x_ppem,
2851
      unsigned int *y_ppem)
2852
0
{
2853
0
  if (x_ppem) *x_ppem = font->x_ppem;
2854
0
  if (y_ppem) *y_ppem = font->y_ppem;
2855
0
}
2856
2857
/**
2858
 * hb_font_set_ptem:
2859
 * @font: #hb_font_t to work upon
2860
 * @ptem: font size in points.
2861
 *
2862
 * Sets the "point size" of a font. Set to zero to unset.
2863
 * Used in CoreText to implement optical sizing.
2864
 *
2865
 * <note>Note: There are 72 points in an inch.</note>
2866
 *
2867
 * Since: 1.6.0
2868
 **/
2869
void
2870
hb_font_set_ptem (hb_font_t *font,
2871
      float      ptem)
2872
0
{
2873
0
  if (hb_object_is_immutable (font))
2874
0
    return;
2875
2876
0
  if (font->ptem == ptem)
2877
0
    return;
2878
2879
0
  font->ptem = ptem;
2880
2881
0
  font->changed ();
2882
0
}
2883
2884
/**
2885
 * hb_font_get_ptem:
2886
 * @font: #hb_font_t to work upon
2887
 *
2888
 * Fetches the "point size" of a font. Used in CoreText to
2889
 * implement optical sizing.
2890
 *
2891
 * Return value: Point size.  A value of zero means "not set."
2892
 *
2893
 * Since: 1.6.0
2894
 **/
2895
float
2896
hb_font_get_ptem (hb_font_t *font)
2897
0
{
2898
0
  return font->ptem;
2899
0
}
2900
2901
/**
2902
 * hb_font_is_synthetic:
2903
 * @font: #hb_font_t to work upon
2904
 *
2905
 * Tests whether a font is synthetic. A synthetic font is one
2906
 * that has either synthetic slant or synthetic bold set on it.
2907
 *
2908
 * Return value: `true` if the font is synthetic, `false` otherwise.
2909
 *
2910
 * Since: 11.2.0
2911
 */
2912
hb_bool_t
2913
hb_font_is_synthetic (hb_font_t *font)
2914
0
{
2915
0
  return font->is_synthetic;
2916
0
}
2917
2918
/**
2919
 * hb_font_set_synthetic_bold:
2920
 * @font: #hb_font_t to work upon
2921
 * @x_embolden: the amount to embolden horizontally
2922
 * @y_embolden: the amount to embolden vertically
2923
 * @in_place: whether to embolden glyphs in-place
2924
 *
2925
 * Sets the "synthetic boldness" of a font.
2926
 *
2927
 * Positive values for @x_embolden / @y_embolden make a font
2928
 * bolder, negative values thinner. Typical values are in the
2929
 * 0.01 to 0.05 range. The default value is zero.
2930
 *
2931
 * Synthetic boldness is applied by offsetting the contour
2932
 * points of the glyph shape.
2933
 *
2934
 * Synthetic boldness is applied when rendering a glyph via
2935
 * hb_font_draw_glyph_or_fail().
2936
 *
2937
 * If @in_place is `false`, then glyph advance-widths are also
2938
 * adjusted, otherwise they are not.  The in-place mode is
2939
 * useful for simulating [font grading](https://fonts.google.com/knowledge/glossary/grade).
2940
 *
2941
 *
2942
 * Since: 7.0.0
2943
 **/
2944
void
2945
hb_font_set_synthetic_bold (hb_font_t *font,
2946
          float x_embolden,
2947
          float y_embolden,
2948
          hb_bool_t in_place)
2949
0
{
2950
0
  if (hb_object_is_immutable (font))
2951
0
    return;
2952
2953
0
  if (font->x_embolden == x_embolden &&
2954
0
      font->y_embolden == y_embolden &&
2955
0
      font->embolden_in_place == (bool) in_place)
2956
0
    return;
2957
2958
0
  font->x_embolden = x_embolden;
2959
0
  font->y_embolden = y_embolden;
2960
0
  font->embolden_in_place = in_place;
2961
2962
0
  font->changed ();
2963
0
}
2964
2965
/**
2966
 * hb_font_get_synthetic_bold:
2967
 * @font: #hb_font_t to work upon
2968
 * @x_embolden: (out): return location for horizontal value
2969
 * @y_embolden: (out): return location for vertical value
2970
 * @in_place: (out): return location for in-place value
2971
 *
2972
 * Fetches the "synthetic boldness" parameters of a font.
2973
 *
2974
 * Since: 7.0.0
2975
 **/
2976
void
2977
hb_font_get_synthetic_bold (hb_font_t *font,
2978
          float *x_embolden,
2979
          float *y_embolden,
2980
          hb_bool_t *in_place)
2981
0
{
2982
0
  if (x_embolden) *x_embolden = font->x_embolden;
2983
0
  if (y_embolden) *y_embolden = font->y_embolden;
2984
0
  if (in_place) *in_place = font->embolden_in_place;
2985
0
}
2986
2987
/**
2988
 * hb_font_set_synthetic_slant:
2989
 * @font: #hb_font_t to work upon
2990
 * @slant: synthetic slant value.
2991
 *
2992
 * Sets the "synthetic slant" of a font.  By default is zero.
2993
 * Synthetic slant is the graphical skew applied to the font
2994
 * at rendering time.
2995
 *
2996
 * HarfBuzz needs to know this value to adjust shaping results,
2997
 * metrics, and style values to match the slanted rendering.
2998
 *
2999
 * <note>Note: The glyph shape fetched via the hb_font_draw_glyph_or_fail()
3000
 * function is slanted to reflect this value as well.</note>
3001
 *
3002
 * <note>Note: The slant value is a ratio.  For example, a
3003
 * 20% slant would be represented as a 0.2 value.</note>
3004
 *
3005
 * Since: 3.3.0
3006
 **/
3007
HB_EXTERN void
3008
hb_font_set_synthetic_slant (hb_font_t *font, float slant)
3009
0
{
3010
0
  if (hb_object_is_immutable (font))
3011
0
    return;
3012
3013
0
  if (font->slant == slant)
3014
0
    return;
3015
3016
0
  font->slant = slant;
3017
3018
0
  font->changed ();
3019
0
}
3020
3021
/**
3022
 * hb_font_get_synthetic_slant:
3023
 * @font: #hb_font_t to work upon
3024
 *
3025
 * Fetches the "synthetic slant" of a font.
3026
 *
3027
 * Return value: Synthetic slant.  By default is zero.
3028
 *
3029
 * Since: 3.3.0
3030
 **/
3031
HB_EXTERN float
3032
hb_font_get_synthetic_slant (hb_font_t *font)
3033
0
{
3034
0
  return font->slant;
3035
0
}
3036
3037
#ifndef HB_NO_VAR
3038
/*
3039
 * Variations
3040
 */
3041
3042
/**
3043
 * hb_font_set_variations:
3044
 * @font: #hb_font_t to work upon
3045
 * @variations: (array length=variations_length): Array of variation settings to apply
3046
 * @variations_length: Number of variations to apply
3047
 *
3048
 * Applies a list of font-variation settings to a font.
3049
 *
3050
 * Note that this overrides all existing variations set on @font.
3051
 * Axes not included in @variations will be effectively set to their
3052
 * default values.
3053
 *
3054
 * Since: 1.4.2
3055
 */
3056
void
3057
hb_font_set_variations (hb_font_t            *font,
3058
      const hb_variation_t *variations,
3059
      unsigned int          variations_length)
3060
204k
{
3061
204k
  if (hb_object_is_immutable (font))
3062
0
    return;
3063
3064
204k
  const OT::fvar &fvar = *font->face->table.fvar;
3065
204k
  auto axes = fvar.get_axes ();
3066
204k
  const unsigned coords_length = axes.length;
3067
3068
204k
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
3069
204k
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
3070
3071
204k
  if (unlikely (coords_length && !(normalized && design_coords)))
3072
0
  {
3073
0
    hb_free (normalized);
3074
0
    hb_free (design_coords);
3075
0
    return;
3076
0
  }
3077
3078
  /* Initialize design coords. */
3079
204k
  for (unsigned int i = 0; i < coords_length; i++)
3080
0
    design_coords[i] = axes[i].get_default ();
3081
204k
  if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE)
3082
0
  {
3083
0
    unsigned count = coords_length;
3084
    /* This may fail if index is out-of-range;
3085
     * That's why we initialize design_coords from fvar above
3086
     * unconditionally. */
3087
0
    hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index,
3088
0
            &count, design_coords);
3089
0
  }
3090
3091
243k
  for (unsigned int i = 0; i < variations_length; i++)
3092
38.9k
  {
3093
38.9k
    const auto tag = variations[i].tag;
3094
38.9k
    const auto v = variations[i].value;
3095
38.9k
    for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
3096
0
      if (axes[axis_index].axisTag == tag)
3097
0
  design_coords[axis_index] = v;
3098
38.9k
  }
3099
3100
204k
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
3101
204k
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
3102
204k
}
3103
3104
/**
3105
 * hb_font_set_variation:
3106
 * @font: #hb_font_t to work upon
3107
 * @tag: The #hb_tag_t tag of the variation-axis name
3108
 * @value: The value of the variation axis
3109
 *
3110
 * Change the value of one variation axis on the font.
3111
 *
3112
 * Note: This function is expensive to be called repeatedly.
3113
 *   If you want to set multiple variation axes at the same time,
3114
 *   use hb_font_set_variations() instead.
3115
 *
3116
 * Since: 7.1.0
3117
 */
3118
void
3119
hb_font_set_variation (hb_font_t *font,
3120
           hb_tag_t tag,
3121
           float    value)
3122
0
{
3123
0
  if (hb_object_is_immutable (font))
3124
0
    return;
3125
3126
  // TODO Share some of this code with set_variations()
3127
3128
0
  const OT::fvar &fvar = *font->face->table.fvar;
3129
0
  auto axes = fvar.get_axes ();
3130
0
  const unsigned coords_length = axes.length;
3131
3132
0
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
3133
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
3134
3135
0
  if (unlikely (coords_length && !(normalized && design_coords)))
3136
0
  {
3137
0
    hb_free (normalized);
3138
0
    hb_free (design_coords);
3139
0
    return;
3140
0
  }
3141
3142
  /* Initialize design coords. */
3143
0
  if (font->design_coords)
3144
0
  {
3145
0
    assert (coords_length == font->num_coords);
3146
0
    for (unsigned int i = 0; i < coords_length; i++)
3147
0
      design_coords[i] = font->design_coords[i];
3148
0
  }
3149
0
  else
3150
0
  {
3151
0
    for (unsigned int i = 0; i < coords_length; i++)
3152
0
      design_coords[i] = axes[i].get_default ();
3153
0
    if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE)
3154
0
    {
3155
0
      unsigned count = coords_length;
3156
      /* This may fail if index is out-of-range;
3157
       * That's why we initialize design_coords from fvar above
3158
       * unconditionally. */
3159
0
      hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index,
3160
0
              &count, design_coords);
3161
0
    }
3162
0
  }
3163
3164
0
  for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
3165
0
    if (axes[axis_index].axisTag == tag)
3166
0
      design_coords[axis_index] = value;
3167
3168
0
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
3169
0
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
3170
0
}
3171
3172
/**
3173
 * hb_font_set_var_coords_design:
3174
 * @font: #hb_font_t to work upon
3175
 * @coords: (array length=coords_length): Array of variation coordinates to apply
3176
 * @coords_length: Number of coordinates to apply
3177
 *
3178
 * Applies a list of variation coordinates (in design-space units)
3179
 * to a font.
3180
 *
3181
 * Note that this overrides all existing variations set on @font.
3182
 * Axes not included in @coords will be effectively set to their
3183
 * default values.
3184
 *
3185
 * Since: 1.4.2
3186
 */
3187
void
3188
hb_font_set_var_coords_design (hb_font_t    *font,
3189
             const float  *coords,
3190
             unsigned int  input_coords_length)
3191
0
{
3192
0
  if (hb_object_is_immutable (font))
3193
0
    return;
3194
3195
0
  const OT::fvar &fvar = *font->face->table.fvar;
3196
0
  auto axes = fvar.get_axes ();
3197
0
  const unsigned coords_length = axes.length;
3198
3199
0
  input_coords_length = hb_min (input_coords_length, coords_length);
3200
0
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
3201
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
3202
3203
0
  if (unlikely (coords_length && !(normalized && design_coords)))
3204
0
  {
3205
0
    hb_free (normalized);
3206
0
    hb_free (design_coords);
3207
0
    return;
3208
0
  }
3209
3210
0
  if (input_coords_length)
3211
0
    hb_memcpy (design_coords, coords, input_coords_length * sizeof (font->design_coords[0]));
3212
  // Fill in the rest with default values
3213
0
  for (unsigned int i = input_coords_length; i < coords_length; i++)
3214
0
    design_coords[i] = axes[i].get_default ();
3215
3216
0
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
3217
0
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
3218
0
}
3219
3220
/**
3221
 * hb_font_set_var_named_instance:
3222
 * @font: a font.
3223
 * @instance_index: named instance index.
3224
 *
3225
 * Sets design coords of a font from a named-instance index.
3226
 *
3227
 * Since: 2.6.0
3228
 */
3229
void
3230
hb_font_set_var_named_instance (hb_font_t *font,
3231
        unsigned int instance_index)
3232
0
{
3233
0
  if (hb_object_is_immutable (font))
3234
0
    return;
3235
3236
0
  if (font->instance_index == instance_index)
3237
0
    return;
3238
3239
0
  font->instance_index = instance_index;
3240
0
  hb_font_set_variations (font, nullptr, 0);
3241
0
}
3242
3243
/**
3244
 * hb_font_get_var_named_instance:
3245
 * @font: a font.
3246
 *
3247
 * Returns the currently-set named-instance index of the font.
3248
 *
3249
 * Return value: Named-instance index or %HB_FONT_NO_VAR_NAMED_INSTANCE.
3250
 *
3251
 * Since: 7.0.0
3252
 **/
3253
unsigned int
3254
hb_font_get_var_named_instance (hb_font_t *font)
3255
0
{
3256
0
  return font->instance_index;
3257
0
}
3258
3259
/**
3260
 * hb_font_set_var_coords_normalized:
3261
 * @font: #hb_font_t to work upon
3262
 * @coords: (array length=coords_length): Array of variation coordinates to apply
3263
 * @coords_length: Number of coordinates to apply
3264
 *
3265
 * Applies a list of variation coordinates (in normalized units)
3266
 * to a font.
3267
 *
3268
 * Note that this overrides all existing variations set on @font.
3269
 * Axes not included in @coords will be effectively set to their
3270
 * default values.
3271
 *
3272
 * <note>Note: Coordinates should be normalized to 2.14.</note>
3273
 *
3274
 * Since: 1.4.2
3275
 */
3276
void
3277
hb_font_set_var_coords_normalized (hb_font_t    *font,
3278
           const int    *coords, /* 2.14 normalized */
3279
           unsigned int  input_coords_length)
3280
0
{
3281
0
  if (hb_object_is_immutable (font))
3282
0
    return;
3283
3284
0
  const OT::fvar &fvar = *font->face->table.fvar;
3285
0
  auto axes = fvar.get_axes ();
3286
0
  unsigned coords_length = axes.length;
3287
3288
0
  input_coords_length = hb_min (input_coords_length, coords_length);
3289
0
  int *copy = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
3290
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (design_coords[0])) : nullptr;
3291
3292
0
  if (unlikely (coords_length && !(copy && design_coords)))
3293
0
  {
3294
0
    hb_free (copy);
3295
0
    hb_free (design_coords);
3296
0
    return;
3297
0
  }
3298
3299
0
  if (input_coords_length)
3300
0
    hb_memcpy (copy, coords, input_coords_length * sizeof (coords[0]));
3301
3302
0
  for (unsigned int i = 0; i < coords_length; ++i)
3303
0
    design_coords[i] = NAN;
3304
3305
0
  _hb_font_adopt_var_coords (font, copy, design_coords, coords_length);
3306
0
}
3307
3308
/**
3309
 * hb_font_get_var_coords_normalized:
3310
 * @font: #hb_font_t to work upon
3311
 * @length: (out): Number of coordinates retrieved
3312
 *
3313
 * Fetches the list of normalized variation coordinates currently
3314
 * set on a font.
3315
 *
3316
 * <note>Note that if no variation coordinates are set, this function may
3317
 * return %NULL.</note>
3318
 *
3319
 * Return value is valid as long as variation coordinates of the font
3320
 * are not modified.
3321
 *
3322
 * Return value: coordinates array
3323
 *
3324
 * Since: 1.4.2
3325
 */
3326
const int *
3327
hb_font_get_var_coords_normalized (hb_font_t    *font,
3328
           unsigned int *length)
3329
0
{
3330
0
  if (length)
3331
0
    *length = font->num_coords;
3332
3333
0
  return font->coords;
3334
0
}
3335
3336
/**
3337
 * hb_font_get_var_coords_design:
3338
 * @font: #hb_font_t to work upon
3339
 * @length: (out): Number of coordinates retrieved
3340
 *
3341
 * Fetches the list of variation coordinates (in design-space units) currently
3342
 * set on a font.
3343
 *
3344
 * <note>Note that if no variation coordinates are set, this function may
3345
 * return %NULL.</note>
3346
 *
3347
 * <note>If variations have been set on the font using normalized coordinates
3348
 * (i.e. via hb_font_set_var_coords_normalized()), the design coordinates will
3349
 * have NaN (Not a Number) values.</note>
3350
 *
3351
 * Return value is valid as long as variation coordinates of the font
3352
 * are not modified.
3353
 *
3354
 * Return value: coordinates array
3355
 *
3356
 * Since: 3.3.0
3357
 */
3358
const float *
3359
hb_font_get_var_coords_design (hb_font_t *font,
3360
             unsigned int *length)
3361
0
{
3362
0
  if (length)
3363
0
    *length = font->num_coords;
3364
3365
0
  return font->design_coords;
3366
0
}
3367
#endif
3368
3369
#ifndef HB_DISABLE_DEPRECATED
3370
/*
3371
 * Deprecated get_glyph_func():
3372
 */
3373
3374
struct hb_trampoline_closure_t
3375
{
3376
  void *user_data;
3377
  hb_destroy_func_t destroy;
3378
  unsigned int ref_count;
3379
};
3380
3381
template <typename FuncType>
3382
struct hb_trampoline_t
3383
{
3384
  hb_trampoline_closure_t closure; /* Must be first. */
3385
  FuncType func;
3386
};
3387
3388
template <typename FuncType>
3389
static hb_trampoline_t<FuncType> *
3390
trampoline_create (FuncType           func,
3391
       void              *user_data,
3392
       hb_destroy_func_t  destroy)
3393
0
{
3394
0
  typedef hb_trampoline_t<FuncType> trampoline_t;
3395
3396
0
  trampoline_t *trampoline = (trampoline_t *) hb_calloc (1, sizeof (trampoline_t));
3397
3398
0
  if (unlikely (!trampoline))
3399
0
    return nullptr;
3400
3401
0
  trampoline->closure.user_data = user_data;
3402
0
  trampoline->closure.destroy = destroy;
3403
0
  trampoline->closure.ref_count = 1;
3404
0
  trampoline->func = func;
3405
3406
0
  return trampoline;
3407
0
}
3408
3409
static void
3410
trampoline_reference (hb_trampoline_closure_t *closure)
3411
0
{
3412
0
  closure->ref_count++;
3413
0
}
3414
3415
static void
3416
trampoline_destroy (void *user_data)
3417
0
{
3418
0
  hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
3419
3420
0
  if (--closure->ref_count)
3421
0
    return;
3422
3423
0
  if (closure->destroy)
3424
0
    closure->destroy (closure->user_data);
3425
0
  hb_free (closure);
3426
0
}
3427
3428
typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
3429
3430
static hb_bool_t
3431
hb_font_get_nominal_glyph_trampoline (hb_font_t      *font,
3432
              void           *font_data,
3433
              hb_codepoint_t  unicode,
3434
              hb_codepoint_t *glyph,
3435
              void           *user_data)
3436
0
{
3437
0
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
3438
0
  return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
3439
0
}
3440
3441
static hb_bool_t
3442
hb_font_get_variation_glyph_trampoline (hb_font_t      *font,
3443
          void           *font_data,
3444
          hb_codepoint_t  unicode,
3445
          hb_codepoint_t  variation_selector,
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, variation_selector, glyph, trampoline->closure.user_data);
3451
0
}
3452
3453
/**
3454
 * hb_font_funcs_set_glyph_func:
3455
 * @ffuncs: The font-functions structure
3456
 * @func: (closure user_data) (destroy destroy) (scope notified): callback function
3457
 * @user_data: data to pass to @func
3458
 * @destroy: (nullable): function to call when @user_data is not needed anymore
3459
 *
3460
 * Deprecated.  Use hb_font_funcs_set_nominal_glyph_func() and
3461
 * hb_font_funcs_set_variation_glyph_func() instead.
3462
 *
3463
 * Since: 0.9.2
3464
 * Deprecated: 1.2.3
3465
 **/
3466
void
3467
hb_font_funcs_set_glyph_func (hb_font_funcs_t          *ffuncs,
3468
            hb_font_get_glyph_func_t  func,
3469
            void                     *user_data,
3470
            hb_destroy_func_t         destroy /* May be NULL. */)
3471
0
{
3472
0
  if (hb_object_is_immutable (ffuncs))
3473
0
  {
3474
0
    if (destroy)
3475
0
      destroy (user_data);
3476
0
    return;
3477
0
  }
3478
3479
0
  hb_font_get_glyph_trampoline_t *trampoline;
3480
3481
0
  trampoline = trampoline_create (func, user_data, destroy);
3482
0
  if (unlikely (!trampoline))
3483
0
  {
3484
0
    if (destroy)
3485
0
      destroy (user_data);
3486
0
    return;
3487
0
  }
3488
3489
  /* Since we pass it to two destroying functions. */
3490
0
  trampoline_reference (&trampoline->closure);
3491
3492
0
  hb_font_funcs_set_nominal_glyph_func (ffuncs,
3493
0
          hb_font_get_nominal_glyph_trampoline,
3494
0
          trampoline,
3495
0
          trampoline_destroy);
3496
3497
0
  hb_font_funcs_set_variation_glyph_func (ffuncs,
3498
0
            hb_font_get_variation_glyph_trampoline,
3499
0
            trampoline,
3500
0
            trampoline_destroy);
3501
0
}
3502
#endif
3503
3504
3505
#ifndef HB_DISABLE_DEPRECATED
3506
3507
struct hb_draw_glyph_closure_t
3508
{
3509
  hb_font_draw_glyph_func_t func;
3510
  void *user_data;
3511
  hb_destroy_func_t destroy;
3512
};
3513
static hb_bool_t
3514
hb_font_draw_glyph_trampoline (hb_font_t       *font,
3515
             void            *font_data,
3516
             hb_codepoint_t   glyph,
3517
             hb_draw_funcs_t *draw_funcs,
3518
             void            *draw_data,
3519
             void            *user_data)
3520
0
{
3521
0
  hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data;
3522
0
  closure->func (font, font_data, glyph, draw_funcs, draw_data, closure->user_data);
3523
0
  return true;
3524
0
}
3525
static void
3526
hb_font_draw_glyph_closure_destroy (void *user_data)
3527
0
{
3528
0
  hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data;
3529
3530
0
  if (closure->destroy)
3531
0
    closure->destroy (closure->user_data);
3532
0
  hb_free (closure);
3533
0
}
3534
static void
3535
_hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t           *ffuncs,
3536
            hb_font_draw_glyph_func_t  func,
3537
            void                      *user_data,
3538
            hb_destroy_func_t          destroy /* May be NULL. */)
3539
0
{
3540
0
  if (hb_object_is_immutable (ffuncs))
3541
0
  {
3542
0
    if (destroy)
3543
0
      destroy (user_data);
3544
0
    return;
3545
0
  }
3546
0
  hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) hb_calloc (1, sizeof (hb_draw_glyph_closure_t));
3547
0
  if (unlikely (!closure))
3548
0
  {
3549
0
    if (destroy)
3550
0
      destroy (user_data);
3551
0
    return;
3552
0
  }
3553
0
  closure->func = func;
3554
0
  closure->user_data = user_data;
3555
0
  closure->destroy = destroy;
3556
3557
0
  hb_font_funcs_set_draw_glyph_or_fail_func (ffuncs,
3558
0
               hb_font_draw_glyph_trampoline,
3559
0
               closure,
3560
0
               hb_font_draw_glyph_closure_destroy);
3561
0
}
3562
void
3563
hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t           *ffuncs,
3564
                                   hb_font_draw_glyph_func_t  func,
3565
                                   void                      *user_data,
3566
                                   hb_destroy_func_t          destroy /* May be NULL. */)
3567
0
{
3568
0
  _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
3569
0
}
3570
void
3571
hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t               *ffuncs,
3572
                                   hb_font_get_glyph_shape_func_t  func,
3573
                                   void                           *user_data,
3574
                                   hb_destroy_func_t               destroy /* May be NULL. */)
3575
0
{
3576
0
  _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
3577
0
}
3578
3579
struct hb_paint_glyph_closure_t
3580
{
3581
  hb_font_paint_glyph_func_t func;
3582
  void *user_data;
3583
  hb_destroy_func_t destroy;
3584
};
3585
static hb_bool_t
3586
hb_font_paint_glyph_trampoline (hb_font_t        *font,
3587
        void *font_data,
3588
        hb_codepoint_t glyph,
3589
        hb_paint_funcs_t *paint_funcs,
3590
        void *paint_data,
3591
        unsigned int palette,
3592
        hb_color_t foreground,
3593
        void *user_data)
3594
0
{
3595
0
  hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data;
3596
0
  closure->func (font, font_data, glyph, paint_funcs, paint_data, palette, foreground, closure->user_data);
3597
0
  return true;
3598
0
}
3599
static void
3600
hb_font_paint_glyph_closure_destroy (void *user_data)
3601
0
{
3602
0
  hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data;
3603
3604
0
  if (closure->destroy)
3605
0
    closure->destroy (closure->user_data);
3606
0
  hb_free (closure);
3607
0
}
3608
void
3609
hb_font_funcs_set_paint_glyph_func (hb_font_funcs_t           *ffuncs,
3610
            hb_font_paint_glyph_func_t  func,
3611
            void                      *user_data,
3612
            hb_destroy_func_t          destroy /* May be NULL. */)
3613
0
{
3614
0
  if (hb_object_is_immutable (ffuncs))
3615
0
  {
3616
0
    if (destroy)
3617
0
      destroy (user_data);
3618
0
    return;
3619
0
  }
3620
0
  hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) hb_calloc (1, sizeof (hb_paint_glyph_closure_t));
3621
0
  if (unlikely (!closure))
3622
0
  {
3623
0
    if (destroy)
3624
0
      destroy (user_data);
3625
0
    return;
3626
0
  }
3627
0
  closure->func = func;
3628
0
  closure->user_data = user_data;
3629
0
  closure->destroy = destroy;
3630
3631
0
  hb_font_funcs_set_paint_glyph_or_fail_func (ffuncs,
3632
0
                hb_font_paint_glyph_trampoline,
3633
0
                closure,
3634
0
                hb_font_paint_glyph_closure_destroy);
3635
0
}
3636
#endif