Coverage Report

Created: 2023-12-14 14:04

/src/harfbuzz/src/hb-font.cc
Line
Count
Source (jump to first uncovered line)
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
42
/**
43
 * SECTION:hb-font
44
 * @title: hb-font
45
 * @short_description: Font objects
46
 * @include: hb.h
47
 *
48
 * Functions for working with font objects.
49
 *
50
 * A font object represents a font face at a specific size and with
51
 * certain other parameters (pixels-per-em, points-per-em, variation
52
 * settings) specified. Font objects are created from font face
53
 * objects, and are used as input to hb_shape(), among other things.
54
 *
55
 * Client programs can optionally pass in their own functions that
56
 * implement the basic, lower-level queries of font objects. This set
57
 * of font functions is defined by the virtual methods in
58
 * #hb_font_funcs_t.
59
 *
60
 * HarfBuzz provides a built-in set of lightweight default
61
 * functions for each method in #hb_font_funcs_t.
62
 **/
63
64
65
/*
66
 * hb_font_funcs_t
67
 */
68
69
static hb_bool_t
70
hb_font_get_font_h_extents_nil (hb_font_t         *font HB_UNUSED,
71
        void              *font_data HB_UNUSED,
72
        hb_font_extents_t *extents,
73
        void              *user_data HB_UNUSED)
74
0
{
75
0
  hb_memset (extents, 0, sizeof (*extents));
76
0
  return false;
77
0
}
78
79
static hb_bool_t
80
hb_font_get_font_h_extents_default (hb_font_t         *font,
81
            void              *font_data HB_UNUSED,
82
            hb_font_extents_t *extents,
83
            void              *user_data HB_UNUSED)
84
0
{
85
0
  hb_bool_t ret = font->parent->get_font_h_extents (extents);
86
0
  if (ret) {
87
0
    extents->ascender = font->parent_scale_y_distance (extents->ascender);
88
0
    extents->descender = font->parent_scale_y_distance (extents->descender);
89
0
    extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
90
0
  }
91
0
  return ret;
92
0
}
93
94
static hb_bool_t
95
hb_font_get_font_v_extents_nil (hb_font_t         *font HB_UNUSED,
96
        void              *font_data HB_UNUSED,
97
        hb_font_extents_t *extents,
98
        void              *user_data HB_UNUSED)
99
0
{
100
0
  hb_memset (extents, 0, sizeof (*extents));
101
0
  return false;
102
0
}
103
104
static hb_bool_t
105
hb_font_get_font_v_extents_default (hb_font_t         *font,
106
            void              *font_data HB_UNUSED,
107
            hb_font_extents_t *extents,
108
            void              *user_data HB_UNUSED)
109
0
{
110
0
  hb_bool_t ret = font->parent->get_font_v_extents (extents);
111
0
  if (ret) {
112
0
    extents->ascender = font->parent_scale_x_distance (extents->ascender);
113
0
    extents->descender = font->parent_scale_x_distance (extents->descender);
114
0
    extents->line_gap = font->parent_scale_x_distance (extents->line_gap);
115
0
  }
116
0
  return ret;
117
0
}
118
119
static hb_bool_t
120
hb_font_get_nominal_glyph_nil (hb_font_t      *font HB_UNUSED,
121
             void           *font_data HB_UNUSED,
122
             hb_codepoint_t  unicode HB_UNUSED,
123
             hb_codepoint_t *glyph,
124
             void           *user_data HB_UNUSED)
125
506k
{
126
506k
  *glyph = 0;
127
506k
  return false;
128
506k
}
129
130
static hb_bool_t
131
hb_font_get_nominal_glyph_default (hb_font_t      *font,
132
           void           *font_data HB_UNUSED,
133
           hb_codepoint_t  unicode,
134
           hb_codepoint_t *glyph,
135
           void           *user_data HB_UNUSED)
136
403k
{
137
403k
  if (font->has_nominal_glyphs_func_set ())
138
0
  {
139
0
    return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
140
0
  }
141
403k
  return font->parent->get_nominal_glyph (unicode, glyph);
142
403k
}
143
144
#define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default
145
146
static unsigned int
147
hb_font_get_nominal_glyphs_default (hb_font_t            *font,
148
            void                 *font_data HB_UNUSED,
149
            unsigned int          count,
150
            const hb_codepoint_t *first_unicode,
151
            unsigned int          unicode_stride,
152
            hb_codepoint_t       *first_glyph,
153
            unsigned int          glyph_stride,
154
            void                 *user_data HB_UNUSED)
155
206k
{
156
206k
  if (font->has_nominal_glyph_func_set ())
157
103k
  {
158
103k
    for (unsigned int i = 0; i < count; i++)
159
102k
    {
160
102k
      if (!font->get_nominal_glyph (*first_unicode, first_glyph))
161
102k
  return i;
162
163
0
      first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
164
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
165
0
    }
166
614
    return count;
167
103k
  }
168
169
103k
  return font->parent->get_nominal_glyphs (count,
170
103k
             first_unicode, unicode_stride,
171
103k
             first_glyph, glyph_stride);
172
206k
}
173
174
static hb_bool_t
175
hb_font_get_variation_glyph_nil (hb_font_t      *font HB_UNUSED,
176
         void           *font_data HB_UNUSED,
177
         hb_codepoint_t  unicode HB_UNUSED,
178
         hb_codepoint_t  variation_selector HB_UNUSED,
179
         hb_codepoint_t *glyph,
180
         void           *user_data HB_UNUSED)
181
6.58k
{
182
6.58k
  *glyph = 0;
183
6.58k
  return false;
184
6.58k
}
185
186
static hb_bool_t
187
hb_font_get_variation_glyph_default (hb_font_t      *font,
188
             void           *font_data HB_UNUSED,
189
             hb_codepoint_t  unicode,
190
             hb_codepoint_t  variation_selector,
191
             hb_codepoint_t *glyph,
192
             void           *user_data HB_UNUSED)
193
5.98k
{
194
5.98k
  return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
195
5.98k
}
196
197
198
static hb_position_t
199
hb_font_get_glyph_h_advance_nil (hb_font_t      *font,
200
         void           *font_data HB_UNUSED,
201
         hb_codepoint_t  glyph HB_UNUSED,
202
         void           *user_data HB_UNUSED)
203
5.73M
{
204
5.73M
  return font->x_scale;
205
5.73M
}
206
207
static hb_position_t
208
hb_font_get_glyph_h_advance_default (hb_font_t      *font,
209
             void           *font_data HB_UNUSED,
210
             hb_codepoint_t  glyph,
211
             void           *user_data HB_UNUSED)
212
1.62M
{
213
1.62M
  if (font->has_glyph_h_advances_func_set ())
214
1.61M
  {
215
1.61M
    hb_position_t ret;
216
1.61M
    font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);
217
1.61M
    return ret;
218
1.61M
  }
219
11.7k
  return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
220
1.62M
}
221
222
static hb_position_t
223
hb_font_get_glyph_v_advance_nil (hb_font_t      *font,
224
         void           *font_data HB_UNUSED,
225
         hb_codepoint_t  glyph HB_UNUSED,
226
         void           *user_data HB_UNUSED)
227
6.45k
{
228
  /* TODO use font_extents.ascender+descender */
229
6.45k
  return font->y_scale;
230
6.45k
}
231
232
static hb_position_t
233
hb_font_get_glyph_v_advance_default (hb_font_t      *font,
234
             void           *font_data HB_UNUSED,
235
             hb_codepoint_t  glyph,
236
             void           *user_data HB_UNUSED)
237
419k
{
238
419k
  if (font->has_glyph_v_advances_func_set ())
239
413k
  {
240
413k
    hb_position_t ret;
241
413k
    font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);
242
413k
    return ret;
243
413k
  }
244
5.85k
  return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
245
419k
}
246
247
#define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
248
249
static void
250
hb_font_get_glyph_h_advances_default (hb_font_t*            font,
251
              void*                 font_data HB_UNUSED,
252
              unsigned int          count,
253
              const hb_codepoint_t *first_glyph,
254
              unsigned int          glyph_stride,
255
              hb_position_t        *first_advance,
256
              unsigned int          advance_stride,
257
              void                 *user_data HB_UNUSED)
258
202k
{
259
202k
  if (font->has_glyph_h_advance_func_set ())
260
101k
  {
261
5.82M
    for (unsigned int i = 0; i < count; i++)
262
5.72M
    {
263
5.72M
      *first_advance = font->get_glyph_h_advance (*first_glyph);
264
5.72M
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
265
5.72M
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
266
5.72M
    }
267
101k
    return;
268
101k
  }
269
270
101k
  font->parent->get_glyph_h_advances (count,
271
101k
              first_glyph, glyph_stride,
272
101k
              first_advance, advance_stride);
273
5.82M
  for (unsigned int i = 0; i < count; i++)
274
5.72M
  {
275
5.72M
    *first_advance = font->parent_scale_x_distance (*first_advance);
276
5.72M
    first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
277
5.72M
  }
278
101k
}
279
280
#define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default
281
static void
282
hb_font_get_glyph_v_advances_default (hb_font_t*            font,
283
              void*                 font_data HB_UNUSED,
284
              unsigned int          count,
285
              const hb_codepoint_t *first_glyph,
286
              unsigned int          glyph_stride,
287
              hb_position_t        *first_advance,
288
              unsigned int          advance_stride,
289
              void                 *user_data HB_UNUSED)
290
0
{
291
0
  if (font->has_glyph_v_advance_func_set ())
292
0
  {
293
0
    for (unsigned int i = 0; i < count; i++)
294
0
    {
295
0
      *first_advance = font->get_glyph_v_advance (*first_glyph);
296
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
297
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
298
0
    }
299
0
    return;
300
0
  }
301
302
0
  font->parent->get_glyph_v_advances (count,
303
0
              first_glyph, glyph_stride,
304
0
              first_advance, advance_stride);
305
0
  for (unsigned int i = 0; i < count; i++)
306
0
  {
307
0
    *first_advance = font->parent_scale_y_distance (*first_advance);
308
0
    first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
309
0
  }
310
0
}
311
312
static hb_bool_t
313
hb_font_get_glyph_h_origin_nil (hb_font_t      *font HB_UNUSED,
314
        void           *font_data HB_UNUSED,
315
        hb_codepoint_t  glyph HB_UNUSED,
316
        hb_position_t  *x,
317
        hb_position_t  *y,
318
        void           *user_data HB_UNUSED)
319
419k
{
320
419k
  *x = *y = 0;
321
419k
  return true;
322
419k
}
323
324
static hb_bool_t
325
hb_font_get_glyph_h_origin_default (hb_font_t      *font,
326
            void           *font_data HB_UNUSED,
327
            hb_codepoint_t  glyph,
328
            hb_position_t  *x,
329
            hb_position_t  *y,
330
            void           *user_data HB_UNUSED)
331
419k
{
332
419k
  hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
333
419k
  if (ret)
334
419k
    font->parent_scale_position (x, y);
335
419k
  return ret;
336
419k
}
337
338
static hb_bool_t
339
hb_font_get_glyph_v_origin_nil (hb_font_t      *font HB_UNUSED,
340
        void           *font_data HB_UNUSED,
341
        hb_codepoint_t  glyph HB_UNUSED,
342
        hb_position_t  *x,
343
        hb_position_t  *y,
344
        void           *user_data HB_UNUSED)
345
6.45k
{
346
6.45k
  *x = *y = 0;
347
6.45k
  return false;
348
6.45k
}
349
350
static hb_bool_t
351
hb_font_get_glyph_v_origin_default (hb_font_t      *font,
352
            void           *font_data HB_UNUSED,
353
            hb_codepoint_t  glyph,
354
            hb_position_t  *x,
355
            hb_position_t  *y,
356
            void           *user_data HB_UNUSED)
357
5.85k
{
358
5.85k
  hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
359
5.85k
  if (ret)
360
0
    font->parent_scale_position (x, y);
361
5.85k
  return ret;
362
5.85k
}
363
364
static hb_position_t
365
hb_font_get_glyph_h_kerning_nil (hb_font_t      *font HB_UNUSED,
366
         void           *font_data HB_UNUSED,
367
         hb_codepoint_t  left_glyph HB_UNUSED,
368
         hb_codepoint_t  right_glyph HB_UNUSED,
369
         void           *user_data HB_UNUSED)
370
0
{
371
0
  return 0;
372
0
}
373
374
static hb_position_t
375
hb_font_get_glyph_h_kerning_default (hb_font_t      *font,
376
             void           *font_data HB_UNUSED,
377
             hb_codepoint_t  left_glyph,
378
             hb_codepoint_t  right_glyph,
379
             void           *user_data HB_UNUSED)
380
0
{
381
0
  return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
382
0
}
383
384
#ifndef HB_DISABLE_DEPRECATED
385
static hb_position_t
386
hb_font_get_glyph_v_kerning_nil (hb_font_t      *font HB_UNUSED,
387
         void           *font_data HB_UNUSED,
388
         hb_codepoint_t  top_glyph HB_UNUSED,
389
         hb_codepoint_t  bottom_glyph HB_UNUSED,
390
         void           *user_data HB_UNUSED)
391
0
{
392
0
  return 0;
393
0
}
394
395
static hb_position_t
396
hb_font_get_glyph_v_kerning_default (hb_font_t      *font,
397
             void           *font_data HB_UNUSED,
398
             hb_codepoint_t  top_glyph,
399
             hb_codepoint_t  bottom_glyph,
400
             void           *user_data HB_UNUSED)
401
0
{
402
0
  return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
403
0
}
404
#endif
405
406
static hb_bool_t
407
hb_font_get_glyph_extents_nil (hb_font_t          *font HB_UNUSED,
408
             void               *font_data HB_UNUSED,
409
             hb_codepoint_t      glyph HB_UNUSED,
410
             hb_glyph_extents_t *extents,
411
             void               *user_data HB_UNUSED)
412
8.45k
{
413
8.45k
  hb_memset (extents, 0, sizeof (*extents));
414
8.45k
  return false;
415
8.45k
}
416
417
static hb_bool_t
418
hb_font_get_glyph_extents_default (hb_font_t          *font,
419
           void               *font_data HB_UNUSED,
420
           hb_codepoint_t      glyph,
421
           hb_glyph_extents_t *extents,
422
           void               *user_data HB_UNUSED)
423
7.86k
{
424
7.86k
  hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
425
7.86k
  if (ret) {
426
0
    font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
427
0
    font->parent_scale_distance (&extents->width, &extents->height);
428
0
  }
429
7.86k
  return ret;
430
7.86k
}
431
432
static hb_bool_t
433
hb_font_get_glyph_contour_point_nil (hb_font_t      *font HB_UNUSED,
434
             void           *font_data HB_UNUSED,
435
             hb_codepoint_t  glyph HB_UNUSED,
436
             unsigned int    point_index HB_UNUSED,
437
             hb_position_t  *x,
438
             hb_position_t  *y,
439
             void           *user_data HB_UNUSED)
440
816k
{
441
816k
  *x = *y = 0;
442
816k
  return false;
443
816k
}
444
445
static hb_bool_t
446
hb_font_get_glyph_contour_point_default (hb_font_t      *font,
447
           void           *font_data HB_UNUSED,
448
           hb_codepoint_t  glyph,
449
           unsigned int    point_index,
450
           hb_position_t  *x,
451
           hb_position_t  *y,
452
           void           *user_data HB_UNUSED)
453
815k
{
454
815k
  hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
455
815k
  if (ret)
456
0
    font->parent_scale_position (x, y);
457
815k
  return ret;
458
815k
}
459
460
static hb_bool_t
461
hb_font_get_glyph_name_nil (hb_font_t      *font HB_UNUSED,
462
          void           *font_data HB_UNUSED,
463
          hb_codepoint_t  glyph HB_UNUSED,
464
          char           *name,
465
          unsigned int    size,
466
          void           *user_data HB_UNUSED)
467
6.45k
{
468
6.45k
  if (size) *name = '\0';
469
6.45k
  return false;
470
6.45k
}
471
472
static hb_bool_t
473
hb_font_get_glyph_name_default (hb_font_t      *font,
474
        void           *font_data HB_UNUSED,
475
        hb_codepoint_t  glyph,
476
        char           *name,
477
        unsigned int    size,
478
        void           *user_data HB_UNUSED)
479
5.85k
{
480
5.85k
  return font->parent->get_glyph_name (glyph, name, size);
481
5.85k
}
482
483
static hb_bool_t
484
hb_font_get_glyph_from_name_nil (hb_font_t      *font HB_UNUSED,
485
         void           *font_data HB_UNUSED,
486
         const char     *name HB_UNUSED,
487
         int             len HB_UNUSED, /* -1 means nul-terminated */
488
         hb_codepoint_t *glyph,
489
         void           *user_data HB_UNUSED)
490
6.45k
{
491
6.45k
  *glyph = 0;
492
6.45k
  return false;
493
6.45k
}
494
495
static hb_bool_t
496
hb_font_get_glyph_from_name_default (hb_font_t      *font,
497
             void           *font_data HB_UNUSED,
498
             const char     *name,
499
             int             len, /* -1 means nul-terminated */
500
             hb_codepoint_t *glyph,
501
             void           *user_data HB_UNUSED)
502
5.85k
{
503
5.85k
  return font->parent->get_glyph_from_name (name, len, glyph);
504
5.85k
}
505
506
static void
507
hb_font_draw_glyph_nil (hb_font_t       *font HB_UNUSED,
508
      void            *font_data HB_UNUSED,
509
      hb_codepoint_t   glyph,
510
      hb_draw_funcs_t *draw_funcs,
511
      void            *draw_data,
512
      void            *user_data HB_UNUSED)
513
6.45k
{
514
6.45k
}
515
516
static void
517
hb_font_paint_glyph_nil (hb_font_t *font HB_UNUSED,
518
                         void *font_data HB_UNUSED,
519
                         hb_codepoint_t glyph HB_UNUSED,
520
                         hb_paint_funcs_t *paint_funcs HB_UNUSED,
521
                         void *paint_data HB_UNUSED,
522
                         unsigned int palette HB_UNUSED,
523
                         hb_color_t foreground HB_UNUSED,
524
                         void *user_data HB_UNUSED)
525
0
{
526
0
}
527
528
typedef struct hb_font_draw_glyph_default_adaptor_t {
529
  hb_draw_funcs_t *draw_funcs;
530
  void      *draw_data;
531
  float      x_scale;
532
  float      y_scale;
533
  float      slant;
534
} hb_font_draw_glyph_default_adaptor_t;
535
536
static void
537
hb_draw_move_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED,
538
       void *draw_data,
539
       hb_draw_state_t *st,
540
       float to_x, float to_y,
541
       void *user_data HB_UNUSED)
542
0
{
543
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
544
0
  float x_scale = adaptor->x_scale;
545
0
  float y_scale = adaptor->y_scale;
546
0
  float slant   = adaptor->slant;
547
548
0
  adaptor->draw_funcs->emit_move_to (adaptor->draw_data, *st,
549
0
             x_scale * to_x + slant * to_y, y_scale * to_y);
550
0
}
551
552
static void
553
hb_draw_line_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
554
       hb_draw_state_t *st,
555
       float to_x, float to_y,
556
       void *user_data HB_UNUSED)
557
0
{
558
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
559
0
  float x_scale = adaptor->x_scale;
560
0
  float y_scale = adaptor->y_scale;
561
0
  float slant   = adaptor->slant;
562
563
0
  st->current_x = st->current_x * x_scale + st->current_y * slant;
564
0
  st->current_y = st->current_y * y_scale;
565
566
0
  adaptor->draw_funcs->emit_line_to (adaptor->draw_data, *st,
567
0
             x_scale * to_x + slant * to_y, y_scale * to_y);
568
0
}
569
570
static void
571
hb_draw_quadratic_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
572
            hb_draw_state_t *st,
573
            float control_x, float control_y,
574
            float to_x, float to_y,
575
            void *user_data HB_UNUSED)
576
0
{
577
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
578
0
  float x_scale = adaptor->x_scale;
579
0
  float y_scale = adaptor->y_scale;
580
0
  float slant   = adaptor->slant;
581
582
0
  st->current_x = st->current_x * x_scale + st->current_y * slant;
583
0
  st->current_y = st->current_y * y_scale;
584
585
0
  adaptor->draw_funcs->emit_quadratic_to (adaptor->draw_data, *st,
586
0
            x_scale * control_x + slant * control_y, y_scale * control_y,
587
0
            x_scale * to_x + slant * to_y, y_scale * to_y);
588
0
}
589
590
static void
591
hb_draw_cubic_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
592
        hb_draw_state_t *st,
593
        float control1_x, float control1_y,
594
        float control2_x, float control2_y,
595
        float to_x, float to_y,
596
        void *user_data HB_UNUSED)
597
0
{
598
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
599
0
  float x_scale = adaptor->x_scale;
600
0
  float y_scale = adaptor->y_scale;
601
0
  float slant   = adaptor->slant;
602
603
0
  st->current_x = st->current_x * x_scale + st->current_y * slant;
604
0
  st->current_y = st->current_y * y_scale;
605
606
0
  adaptor->draw_funcs->emit_cubic_to (adaptor->draw_data, *st,
607
0
              x_scale * control1_x + slant * control1_y, y_scale * control1_y,
608
0
              x_scale * control2_x + slant * control2_y, y_scale * control2_y,
609
0
              x_scale * to_x + slant * to_y, y_scale * to_y);
610
0
}
611
612
static void
613
hb_draw_close_path_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
614
          hb_draw_state_t *st,
615
          void *user_data HB_UNUSED)
616
0
{
617
0
  hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
618
619
0
  adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st);
620
0
}
621
622
static const hb_draw_funcs_t _hb_draw_funcs_default = {
623
  HB_OBJECT_HEADER_STATIC,
624
625
  {
626
#define HB_DRAW_FUNC_IMPLEMENT(name) hb_draw_##name##_default,
627
    HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS
628
#undef HB_DRAW_FUNC_IMPLEMENT
629
  }
630
};
631
632
static void
633
hb_font_draw_glyph_default (hb_font_t       *font,
634
         void            *font_data HB_UNUSED,
635
         hb_codepoint_t   glyph,
636
         hb_draw_funcs_t *draw_funcs,
637
         void            *draw_data,
638
         void            *user_data HB_UNUSED)
639
5.85k
{
640
5.85k
  hb_font_draw_glyph_default_adaptor_t adaptor = {
641
5.85k
    draw_funcs,
642
5.85k
    draw_data,
643
5.85k
    font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0.f,
644
5.85k
    font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f,
645
5.85k
    font->parent->y_scale ? (font->slant - font->parent->slant) *
646
5.85k
          (float) font->x_scale / (float) font->parent->y_scale : 0.f
647
5.85k
  };
648
649
5.85k
  font->parent->draw_glyph (glyph,
650
5.85k
         const_cast<hb_draw_funcs_t *> (&_hb_draw_funcs_default),
651
5.85k
         &adaptor);
652
5.85k
}
653
654
static void
655
hb_font_paint_glyph_default (hb_font_t *font,
656
                             void *font_data,
657
                             hb_codepoint_t glyph,
658
                             hb_paint_funcs_t *paint_funcs,
659
                             void *paint_data,
660
                             unsigned int palette,
661
                             hb_color_t foreground,
662
                             void *user_data)
663
0
{
664
0
  paint_funcs->push_transform (paint_data,
665
0
    font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0.f,
666
0
    font->parent->y_scale ? (font->slant - font->parent->slant) *
667
0
          (float) font->x_scale / (float) font->parent->y_scale : 0.f,
668
0
    0.f,
669
0
    font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f,
670
0
    0.f, 0.f);
671
672
0
  font->parent->paint_glyph (glyph, paint_funcs, paint_data, palette, foreground);
673
674
0
  paint_funcs->pop_transform (paint_data);
675
0
}
676
677
DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
678
{
679
  HB_OBJECT_HEADER_STATIC,
680
681
  nullptr,
682
  nullptr,
683
  {
684
    {
685
#define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_nil,
686
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
687
#undef HB_FONT_FUNC_IMPLEMENT
688
    }
689
  }
690
};
691
692
static const hb_font_funcs_t _hb_font_funcs_default = {
693
  HB_OBJECT_HEADER_STATIC,
694
695
  nullptr,
696
  nullptr,
697
  {
698
    {
699
#define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_default,
700
      HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
701
#undef HB_FONT_FUNC_IMPLEMENT
702
    }
703
  }
704
};
705
706
707
/**
708
 * hb_font_funcs_create:
709
 *
710
 * Creates a new #hb_font_funcs_t structure of font functions.
711
 *
712
 * Return value: (transfer full): The font-functions structure
713
 *
714
 * Since: 0.9.2
715
 **/
716
hb_font_funcs_t *
717
hb_font_funcs_create ()
718
1.85k
{
719
1.85k
  hb_font_funcs_t *ffuncs;
720
721
1.85k
  if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
722
13
    return hb_font_funcs_get_empty ();
723
724
1.83k
  ffuncs->get = _hb_font_funcs_default.get;
725
726
1.83k
  return ffuncs;
727
1.85k
}
728
729
/**
730
 * hb_font_funcs_get_empty:
731
 *
732
 * Fetches an empty font-functions structure.
733
 *
734
 * Return value: (transfer full): The font-functions structure
735
 *
736
 * Since: 0.9.2
737
 **/
738
hb_font_funcs_t *
739
hb_font_funcs_get_empty ()
740
419k
{
741
419k
  return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
742
419k
}
743
744
/**
745
 * hb_font_funcs_reference: (skip)
746
 * @ffuncs: The font-functions structure
747
 *
748
 * Increases the reference count on a font-functions structure.
749
 *
750
 * Return value: The font-functions structure
751
 *
752
 * Since: 0.9.2
753
 **/
754
hb_font_funcs_t *
755
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
756
1.24M
{
757
1.24M
  return hb_object_reference (ffuncs);
758
1.24M
}
759
760
/**
761
 * hb_font_funcs_destroy: (skip)
762
 * @ffuncs: The font-functions structure
763
 *
764
 * Decreases the reference count on a font-functions structure. When
765
 * the reference count reaches zero, the font-functions structure is
766
 * destroyed, freeing all memory.
767
 *
768
 * Since: 0.9.2
769
 **/
770
void
771
hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
772
1.66M
{
773
1.66M
  if (!hb_object_destroy (ffuncs)) return;
774
775
0
  if (ffuncs->destroy)
776
0
  {
777
0
#define HB_FONT_FUNC_IMPLEMENT(get_,name) if (ffuncs->destroy->name) \
778
0
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name);
779
0
    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
780
0
#undef HB_FONT_FUNC_IMPLEMENT
781
0
  }
782
783
0
  hb_free (ffuncs->destroy);
784
0
  hb_free (ffuncs->user_data);
785
786
0
  hb_free (ffuncs);
787
0
}
788
789
/**
790
 * hb_font_funcs_set_user_data: (skip)
791
 * @ffuncs: The font-functions structure
792
 * @key: The user-data key to set
793
 * @data: A pointer to the user data set
794
 * @destroy: (nullable): A callback to call when @data is not needed anymore
795
 * @replace: Whether to replace an existing data with the same key
796
 *
797
 * Attaches a user-data key/data pair to the specified font-functions structure.
798
 *
799
 * Return value: `true` if success, `false` otherwise
800
 *
801
 * Since: 0.9.2
802
 **/
803
hb_bool_t
804
hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
805
           hb_user_data_key_t *key,
806
           void *              data,
807
           hb_destroy_func_t   destroy /* May be NULL. */,
808
           hb_bool_t           replace)
809
0
{
810
0
  return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
811
0
}
812
813
/**
814
 * hb_font_funcs_get_user_data: (skip)
815
 * @ffuncs: The font-functions structure
816
 * @key: The user-data key to query
817
 *
818
 * Fetches the user data associated with the specified key,
819
 * attached to the specified font-functions structure.
820
 *
821
 * Return value: (transfer none): A pointer to the user data
822
 *
823
 * Since: 0.9.2
824
 **/
825
void *
826
hb_font_funcs_get_user_data (const hb_font_funcs_t *ffuncs,
827
           hb_user_data_key_t    *key)
828
0
{
829
0
  return hb_object_get_user_data (ffuncs, key);
830
0
}
831
832
833
/**
834
 * hb_font_funcs_make_immutable:
835
 * @ffuncs: The font-functions structure
836
 *
837
 * Makes a font-functions structure immutable.
838
 *
839
 * Since: 0.9.2
840
 **/
841
void
842
hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
843
1.85k
{
844
1.85k
  if (hb_object_is_immutable (ffuncs))
845
13
    return;
846
847
1.83k
  hb_object_make_immutable (ffuncs);
848
1.83k
}
849
850
/**
851
 * hb_font_funcs_is_immutable:
852
 * @ffuncs: The font-functions structure
853
 *
854
 * Tests whether a font-functions structure is immutable.
855
 *
856
 * Return value: `true` if @ffuncs is immutable, `false` otherwise
857
 *
858
 * Since: 0.9.2
859
 **/
860
hb_bool_t
861
hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
862
0
{
863
0
  return hb_object_is_immutable (ffuncs);
864
0
}
865
866
867
static bool
868
_hb_font_funcs_set_preamble (hb_font_funcs_t    *ffuncs,
869
           bool                func_is_null,
870
           void              **user_data,
871
           hb_destroy_func_t  *destroy)
872
24.0k
{
873
24.0k
  if (hb_object_is_immutable (ffuncs))
874
169
  {
875
169
    if (*destroy)
876
0
      (*destroy) (*user_data);
877
169
    return false;
878
169
  }
879
880
23.8k
  if (func_is_null)
881
0
  {
882
0
    if (*destroy)
883
0
      (*destroy) (*user_data);
884
0
    *destroy = nullptr;
885
0
    *user_data = nullptr;
886
0
  }
887
888
23.8k
  return true;
889
24.0k
}
890
891
static bool
892
_hb_font_funcs_set_middle (hb_font_funcs_t   *ffuncs,
893
         void              *user_data,
894
         hb_destroy_func_t  destroy)
895
23.8k
{
896
23.8k
  if (user_data && !ffuncs->user_data)
897
0
  {
898
0
    ffuncs->user_data = (decltype (ffuncs->user_data)) hb_calloc (1, sizeof (*ffuncs->user_data));
899
0
    if (unlikely (!ffuncs->user_data))
900
0
      goto fail;
901
0
  }
902
23.8k
  if (destroy && !ffuncs->destroy)
903
0
  {
904
0
    ffuncs->destroy = (decltype (ffuncs->destroy)) hb_calloc (1, sizeof (*ffuncs->destroy));
905
0
    if (unlikely (!ffuncs->destroy))
906
0
      goto fail;
907
0
  }
908
909
23.8k
  return true;
910
911
0
fail:
912
0
  if (destroy)
913
0
    (destroy) (user_data);
914
0
  return false;
915
23.8k
}
916
917
#define HB_FONT_FUNC_IMPLEMENT(get_,name) \
918
                   \
919
void                                                                     \
920
hb_font_funcs_set_##name##_func (hb_font_funcs_t             *ffuncs,    \
921
         hb_font_##get_##name##_func_t func,     \
922
         void                        *user_data, \
923
24.0k
         hb_destroy_func_t            destroy)   \
924
24.0k
{                                                                        \
925
24.0k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
24.0k
      return;                                                            \
927
24.0k
                   \
928
24.0k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
23.8k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
23.8k
                                                                         \
931
23.8k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
23.8k
      return;                                                            \
933
23.8k
                   \
934
23.8k
  if (func)                                                              \
935
23.8k
    ffuncs->get.f.name = func;                                           \
936
23.8k
  else                                                                   \
937
23.8k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
23.8k
                   \
939
23.8k
  if (ffuncs->user_data)                                                 \
940
23.8k
    ffuncs->user_data->name = user_data;                                 \
941
23.8k
  if (ffuncs->destroy)                                                   \
942
23.8k
    ffuncs->destroy->name = destroy;                                     \
943
23.8k
}
hb_font_funcs_set_font_h_extents_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_font_v_extents_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_nominal_glyph_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_nominal_glyphs_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_variation_glyph_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
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
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_glyph_v_advances_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
Unexecuted instantiation: hb_font_funcs_set_glyph_h_origin_func
hb_font_funcs_set_glyph_v_origin_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
Unexecuted instantiation: hb_font_funcs_set_glyph_h_kerning_func
hb_font_funcs_set_glyph_extents_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
Unexecuted instantiation: hb_font_funcs_set_glyph_contour_point_func
hb_font_funcs_set_glyph_name_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_glyph_from_name_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_draw_glyph_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
hb_font_funcs_set_paint_glyph_func
Line
Count
Source
923
1.85k
         hb_destroy_func_t            destroy)   \
924
1.85k
{                                                                        \
925
1.85k
  if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\
926
1.85k
      return;                                                            \
927
1.85k
                   \
928
1.85k
  if (ffuncs->destroy && ffuncs->destroy->name)                          \
929
1.83k
    ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \
930
1.83k
                                                                         \
931
1.83k
  if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy))           \
932
1.83k
      return;                                                            \
933
1.83k
                   \
934
1.83k
  if (func)                                                              \
935
1.83k
    ffuncs->get.f.name = func;                                           \
936
1.83k
  else                                                                   \
937
1.83k
    ffuncs->get.f.name = hb_font_##get_##name##_default;                   \
938
1.83k
                   \
939
1.83k
  if (ffuncs->user_data)                                                 \
940
1.83k
    ffuncs->user_data->name = user_data;                                 \
941
1.83k
  if (ffuncs->destroy)                                                   \
942
1.83k
    ffuncs->destroy->name = destroy;                                     \
943
1.83k
}
944
945
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
946
#undef HB_FONT_FUNC_IMPLEMENT
947
948
bool
949
hb_font_t::has_func_set (unsigned int i)
950
29.8M
{
951
29.8M
  return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
952
29.8M
}
953
954
bool
955
hb_font_t::has_func (unsigned int i)
956
26.9M
{
957
26.9M
  return has_func_set (i) ||
958
26.9M
   (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
959
26.9M
}
960
961
/* Public getters */
962
963
/**
964
 * hb_font_get_h_extents:
965
 * @font: #hb_font_t to work upon
966
 * @extents: (out): The font extents retrieved
967
 *
968
 * Fetches the extents for a specified font, for horizontal
969
 * text segments.
970
 *
971
 * Return value: `true` if data found, `false` otherwise
972
 *
973
 * Since: 1.1.3
974
 **/
975
hb_bool_t
976
hb_font_get_h_extents (hb_font_t         *font,
977
           hb_font_extents_t *extents)
978
0
{
979
0
  return font->get_font_h_extents (extents);
980
0
}
981
982
/**
983
 * hb_font_get_v_extents:
984
 * @font: #hb_font_t to work upon
985
 * @extents: (out): The font extents retrieved
986
 *
987
 * Fetches the extents for a specified font, for vertical
988
 * text segments.
989
 *
990
 * Return value: `true` if data found, `false` otherwise
991
 *
992
 * Since: 1.1.3
993
 **/
994
hb_bool_t
995
hb_font_get_v_extents (hb_font_t         *font,
996
           hb_font_extents_t *extents)
997
0
{
998
0
  return font->get_font_v_extents (extents);
999
0
}
1000
1001
/**
1002
 * hb_font_get_glyph:
1003
 * @font: #hb_font_t to work upon
1004
 * @unicode: The Unicode code point to query
1005
 * @variation_selector: A variation-selector code point
1006
 * @glyph: (out): The glyph ID retrieved
1007
 *
1008
 * Fetches the glyph ID for a Unicode code point in the specified
1009
 * font, with an optional variation selector.
1010
 *
1011
 * If @variation_selector is 0, calls hb_font_get_nominal_glyph();
1012
 * otherwise calls hb_font_get_variation_glyph().
1013
 *
1014
 * Return value: `true` if data found, `false` otherwise
1015
 *
1016
 * Since: 0.9.2
1017
 **/
1018
hb_bool_t
1019
hb_font_get_glyph (hb_font_t      *font,
1020
       hb_codepoint_t  unicode,
1021
       hb_codepoint_t  variation_selector,
1022
       hb_codepoint_t *glyph)
1023
8.09M
{
1024
8.09M
  if (unlikely (variation_selector))
1025
0
    return font->get_variation_glyph (unicode, variation_selector, glyph);
1026
8.09M
  return font->get_nominal_glyph (unicode, glyph);
1027
8.09M
}
1028
1029
/**
1030
 * hb_font_get_nominal_glyph:
1031
 * @font: #hb_font_t to work upon
1032
 * @unicode: The Unicode code point to query
1033
 * @glyph: (out): The glyph ID retrieved
1034
 *
1035
 * Fetches the nominal glyph ID for a Unicode code point in the
1036
 * specified font.
1037
 *
1038
 * This version of the function should not be used to fetch glyph IDs
1039
 * for code points modified by variation selectors. For variation-selector
1040
 * support, user hb_font_get_variation_glyph() or use hb_font_get_glyph().
1041
 *
1042
 * Return value: `true` if data found, `false` otherwise
1043
 *
1044
 * Since: 1.2.3
1045
 **/
1046
hb_bool_t
1047
hb_font_get_nominal_glyph (hb_font_t      *font,
1048
         hb_codepoint_t  unicode,
1049
         hb_codepoint_t *glyph)
1050
696k
{
1051
696k
  return font->get_nominal_glyph (unicode, glyph);
1052
696k
}
1053
1054
/**
1055
 * hb_font_get_nominal_glyphs:
1056
 * @font: #hb_font_t to work upon
1057
 * @count: number of code points to query
1058
 * @first_unicode: The first Unicode code point to query
1059
 * @unicode_stride: The stride between successive code points
1060
 * @first_glyph: (out): The first glyph ID retrieved
1061
 * @glyph_stride: The stride between successive glyph IDs
1062
 *
1063
 * Fetches the nominal glyph IDs for a sequence of Unicode code points. Glyph
1064
 * IDs must be returned in a #hb_codepoint_t output parameter.
1065
 *
1066
 * Return value: the number of code points processed
1067
 *
1068
 * Since: 2.6.3
1069
 **/
1070
unsigned int
1071
hb_font_get_nominal_glyphs (hb_font_t *font,
1072
          unsigned int count,
1073
          const hb_codepoint_t *first_unicode,
1074
          unsigned int unicode_stride,
1075
          hb_codepoint_t *first_glyph,
1076
          unsigned int glyph_stride)
1077
0
{
1078
0
  return font->get_nominal_glyphs (count,
1079
0
           first_unicode, unicode_stride,
1080
0
           first_glyph, glyph_stride);
1081
0
}
1082
1083
/**
1084
 * hb_font_get_variation_glyph:
1085
 * @font: #hb_font_t to work upon
1086
 * @unicode: The Unicode code point to query
1087
 * @variation_selector: The  variation-selector code point to query
1088
 * @glyph: (out): The glyph ID retrieved
1089
 *
1090
 * Fetches the glyph ID for a Unicode code point when followed by
1091
 * by the specified variation-selector code point, in the specified
1092
 * font.
1093
 *
1094
 * Return value: `true` if data found, `false` otherwise
1095
 *
1096
 * Since: 1.2.3
1097
 **/
1098
hb_bool_t
1099
hb_font_get_variation_glyph (hb_font_t      *font,
1100
           hb_codepoint_t  unicode,
1101
           hb_codepoint_t  variation_selector,
1102
           hb_codepoint_t *glyph)
1103
419k
{
1104
419k
  return font->get_variation_glyph (unicode, variation_selector, glyph);
1105
419k
}
1106
1107
/**
1108
 * hb_font_get_glyph_h_advance:
1109
 * @font: #hb_font_t to work upon
1110
 * @glyph: The glyph ID to query
1111
 *
1112
 * Fetches the advance for a glyph ID in the specified font,
1113
 * for horizontal text segments.
1114
 *
1115
 * Return value: The advance of @glyph within @font
1116
 *
1117
 * Since: 0.9.2
1118
 **/
1119
hb_position_t
1120
hb_font_get_glyph_h_advance (hb_font_t      *font,
1121
           hb_codepoint_t  glyph)
1122
419k
{
1123
419k
  return font->get_glyph_h_advance (glyph);
1124
419k
}
1125
1126
/**
1127
 * hb_font_get_glyph_v_advance:
1128
 * @font: #hb_font_t to work upon
1129
 * @glyph: The glyph ID to query
1130
 *
1131
 * Fetches the advance for a glyph ID in the specified font,
1132
 * for vertical text segments.
1133
 *
1134
 * Return value: The advance of @glyph within @font
1135
 *
1136
 * Since: 0.9.2
1137
 **/
1138
hb_position_t
1139
hb_font_get_glyph_v_advance (hb_font_t      *font,
1140
           hb_codepoint_t  glyph)
1141
419k
{
1142
419k
  return font->get_glyph_v_advance (glyph);
1143
419k
}
1144
1145
/**
1146
 * hb_font_get_glyph_h_advances:
1147
 * @font: #hb_font_t to work upon
1148
 * @count: The number of glyph IDs in the sequence queried
1149
 * @first_glyph: The first glyph ID to query
1150
 * @glyph_stride: The stride between successive glyph IDs
1151
 * @first_advance: (out): The first advance retrieved
1152
 * @advance_stride: The stride between successive advances
1153
 *
1154
 * Fetches the advances for a sequence of glyph IDs in the specified
1155
 * font, for horizontal text segments.
1156
 *
1157
 * Since: 1.8.6
1158
 **/
1159
void
1160
hb_font_get_glyph_h_advances (hb_font_t*            font,
1161
            unsigned int          count,
1162
            const hb_codepoint_t *first_glyph,
1163
            unsigned              glyph_stride,
1164
            hb_position_t        *first_advance,
1165
            unsigned              advance_stride)
1166
0
{
1167
0
  font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
1168
0
}
1169
/**
1170
 * hb_font_get_glyph_v_advances:
1171
 * @font: #hb_font_t to work upon
1172
 * @count: The number of glyph IDs in the sequence queried
1173
 * @first_glyph: The first glyph ID to query
1174
 * @glyph_stride: The stride between successive glyph IDs
1175
 * @first_advance: (out): The first advance retrieved
1176
 * @advance_stride: (out): The stride between successive advances
1177
 *
1178
 * Fetches the advances for a sequence of glyph IDs in the specified
1179
 * font, for vertical text segments.
1180
 *
1181
 * Since: 1.8.6
1182
 **/
1183
void
1184
hb_font_get_glyph_v_advances (hb_font_t*            font,
1185
            unsigned int          count,
1186
            const hb_codepoint_t *first_glyph,
1187
            unsigned              glyph_stride,
1188
            hb_position_t        *first_advance,
1189
            unsigned              advance_stride)
1190
0
{
1191
0
  font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
1192
0
}
1193
1194
/**
1195
 * hb_font_get_glyph_h_origin:
1196
 * @font: #hb_font_t to work upon
1197
 * @glyph: The glyph ID to query
1198
 * @x: (out): The X coordinate of the origin
1199
 * @y: (out): The Y coordinate of the origin
1200
 *
1201
 * Fetches the (X,Y) coordinates of the origin for a glyph ID
1202
 * in the specified font, for horizontal text segments.
1203
 *
1204
 * Return value: `true` if data found, `false` otherwise
1205
 *
1206
 * Since: 0.9.2
1207
 **/
1208
hb_bool_t
1209
hb_font_get_glyph_h_origin (hb_font_t      *font,
1210
          hb_codepoint_t  glyph,
1211
          hb_position_t  *x,
1212
          hb_position_t  *y)
1213
419k
{
1214
419k
  return font->get_glyph_h_origin (glyph, x, y);
1215
419k
}
1216
1217
/**
1218
 * hb_font_get_glyph_v_origin:
1219
 * @font: #hb_font_t to work upon
1220
 * @glyph: The glyph ID to query
1221
 * @x: (out): The X coordinate of the origin
1222
 * @y: (out): The Y coordinate of the origin
1223
 *
1224
 * Fetches the (X,Y) coordinates of the origin for a glyph ID
1225
 * in the specified font, for vertical text segments.
1226
 *
1227
 * Return value: `true` if data found, `false` otherwise
1228
 *
1229
 * Since: 0.9.2
1230
 **/
1231
hb_bool_t
1232
hb_font_get_glyph_v_origin (hb_font_t      *font,
1233
          hb_codepoint_t  glyph,
1234
          hb_position_t  *x,
1235
          hb_position_t  *y)
1236
419k
{
1237
419k
  return font->get_glyph_v_origin (glyph, x, y);
1238
419k
}
1239
1240
/**
1241
 * hb_font_get_glyph_h_kerning:
1242
 * @font: #hb_font_t to work upon
1243
 * @left_glyph: The glyph ID of the left glyph in the glyph pair
1244
 * @right_glyph: The glyph ID of the right glyph in the glyph pair
1245
 *
1246
 * Fetches the kerning-adjustment value for a glyph-pair in
1247
 * the specified font, for horizontal text segments.
1248
 *
1249
 * <note>It handles legacy kerning only (as returned by the corresponding
1250
 * #hb_font_funcs_t function).</note>
1251
 *
1252
 * Return value: The kerning adjustment value
1253
 *
1254
 * Since: 0.9.2
1255
 **/
1256
hb_position_t
1257
hb_font_get_glyph_h_kerning (hb_font_t      *font,
1258
           hb_codepoint_t  left_glyph,
1259
           hb_codepoint_t  right_glyph)
1260
0
{
1261
0
  return font->get_glyph_h_kerning (left_glyph, right_glyph);
1262
0
}
1263
1264
#ifndef HB_DISABLE_DEPRECATED
1265
/**
1266
 * hb_font_get_glyph_v_kerning:
1267
 * @font: #hb_font_t to work upon
1268
 * @top_glyph: The glyph ID of the top glyph in the glyph pair
1269
 * @bottom_glyph: The glyph ID of the bottom glyph in the glyph pair
1270
 *
1271
 * Fetches the kerning-adjustment value for a glyph-pair in
1272
 * the specified font, for vertical text segments.
1273
 *
1274
 * <note>It handles legacy kerning only (as returned by the corresponding
1275
 * #hb_font_funcs_t function).</note>
1276
 *
1277
 * Return value: The kerning adjustment value
1278
 *
1279
 * Since: 0.9.2
1280
 * Deprecated: 2.0.0
1281
 **/
1282
hb_position_t
1283
hb_font_get_glyph_v_kerning (hb_font_t      *font,
1284
           hb_codepoint_t  top_glyph,
1285
           hb_codepoint_t  bottom_glyph)
1286
0
{
1287
0
  return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
1288
0
}
1289
#endif
1290
1291
/**
1292
 * hb_font_get_glyph_extents:
1293
 * @font: #hb_font_t to work upon
1294
 * @glyph: The glyph ID to query
1295
 * @extents: (out): The #hb_glyph_extents_t retrieved
1296
 *
1297
 * Fetches the #hb_glyph_extents_t data for a glyph ID
1298
 * in the specified font.
1299
 *
1300
 * Return value: `true` if data found, `false` otherwise
1301
 *
1302
 * Since: 0.9.2
1303
 **/
1304
hb_bool_t
1305
hb_font_get_glyph_extents (hb_font_t          *font,
1306
         hb_codepoint_t      glyph,
1307
         hb_glyph_extents_t *extents)
1308
419k
{
1309
419k
  return font->get_glyph_extents (glyph, extents);
1310
419k
}
1311
1312
/**
1313
 * hb_font_get_glyph_contour_point:
1314
 * @font: #hb_font_t to work upon
1315
 * @glyph: The glyph ID to query
1316
 * @point_index: The contour-point index to query
1317
 * @x: (out): The X value retrieved for the contour point
1318
 * @y: (out): The Y value retrieved for the contour point
1319
 *
1320
 * Fetches the (x,y) coordinates of a specified contour-point index
1321
 * in the specified glyph, within the specified font.
1322
 *
1323
 * Return value: `true` if data found, `false` otherwise
1324
 *
1325
 * Since: 0.9.2
1326
 **/
1327
hb_bool_t
1328
hb_font_get_glyph_contour_point (hb_font_t      *font,
1329
         hb_codepoint_t  glyph,
1330
         unsigned int    point_index,
1331
         hb_position_t  *x,
1332
         hb_position_t  *y)
1333
419k
{
1334
419k
  return font->get_glyph_contour_point (glyph, point_index, x, y);
1335
419k
}
1336
1337
/**
1338
 * hb_font_get_glyph_name:
1339
 * @font: #hb_font_t to work upon
1340
 * @glyph: The glyph ID to query
1341
 * @name: (out) (array length=size): Name string retrieved for the glyph ID
1342
 * @size: Length of the glyph-name string retrieved
1343
 *
1344
 * Fetches the glyph-name string for a glyph ID in the specified @font.
1345
 *
1346
 * According to the OpenType specification, glyph names are limited to 63
1347
 * characters and can only contain (a subset of) ASCII.
1348
 *
1349
 * Return value: `true` if data found, `false` otherwise
1350
 *
1351
 * Since: 0.9.2
1352
 **/
1353
hb_bool_t
1354
hb_font_get_glyph_name (hb_font_t      *font,
1355
      hb_codepoint_t  glyph,
1356
      char           *name,
1357
      unsigned int    size)
1358
419k
{
1359
419k
  return font->get_glyph_name (glyph, name, size);
1360
419k
}
1361
1362
/**
1363
 * hb_font_get_glyph_from_name:
1364
 * @font: #hb_font_t to work upon
1365
 * @name: (array length=len): The name string to query
1366
 * @len: The length of the name queried
1367
 * @glyph: (out): The glyph ID retrieved
1368
 *
1369
 * Fetches the glyph ID that corresponds to a name string in the specified @font.
1370
 *
1371
 * <note>Note: @len == -1 means the name string is null-terminated.</note>
1372
 *
1373
 * Return value: `true` if data found, `false` otherwise
1374
 *
1375
 * Since: 0.9.2
1376
 **/
1377
hb_bool_t
1378
hb_font_get_glyph_from_name (hb_font_t      *font,
1379
           const char     *name,
1380
           int             len, /* -1 means nul-terminated */
1381
           hb_codepoint_t *glyph)
1382
419k
{
1383
419k
  return font->get_glyph_from_name (name, len, glyph);
1384
419k
}
1385
1386
/**
1387
 * hb_font_get_glyph_shape:
1388
 * @font: #hb_font_t to work upon
1389
 * @glyph: : The glyph ID
1390
 * @dfuncs: #hb_draw_funcs_t to draw to
1391
 * @draw_data: User data to pass to draw callbacks
1392
 *
1393
 * Fetches the glyph shape that corresponds to a glyph in the specified @font.
1394
 * The shape is returned by way of calls to the callbacks of the @dfuncs
1395
 * objects, with @draw_data passed to them.
1396
 *
1397
 * Since: 4.0.0
1398
 */
1399
void
1400
hb_font_get_glyph_shape (hb_font_t *font,
1401
             hb_codepoint_t glyph,
1402
             hb_draw_funcs_t *dfuncs, void *draw_data)
1403
419k
{
1404
419k
  hb_font_draw_glyph (font, glyph, dfuncs, draw_data);
1405
419k
}
1406
1407
/**
1408
 * hb_font_draw_glyph:
1409
 * @font: #hb_font_t to work upon
1410
 * @glyph: : The glyph ID
1411
 * @dfuncs: #hb_draw_funcs_t to draw to
1412
 * @draw_data: User data to pass to draw callbacks
1413
 *
1414
 * Draws the outline that corresponds to a glyph in the specified @font.
1415
 *
1416
 * The outline is returned by way of calls to the callbacks of the @dfuncs
1417
 * objects, with @draw_data passed to them.
1418
 *
1419
 * Since: REPLACEME
1420
 **/
1421
void
1422
hb_font_draw_glyph (hb_font_t *font,
1423
       hb_codepoint_t glyph,
1424
       hb_draw_funcs_t *dfuncs, void *draw_data)
1425
2.15M
{
1426
2.15M
  font->draw_glyph (glyph, dfuncs, draw_data);
1427
2.15M
}
1428
1429
/**
1430
 * hb_font_paint_glyph:
1431
 * @font: #hb_font_t to work upon
1432
 * @glyph: The glyph ID
1433
 * @pfuncs: #hb_paint_funcs_t to paint with
1434
 * @paint_data: User data to pass to paint callbacks
1435
 * @palette_index: The index of the font's color palette to use
1436
 * @foreground: The foreground color, unpremultipled
1437
 *
1438
 * Paints the glyph.
1439
 *
1440
 * The painting instructions are returned by way of calls to
1441
 * the callbacks of the @funcs object, with @paint_data passed
1442
 * to them.
1443
 *
1444
 * If the font has color palettes (see hb_ot_color_has_palettes()),
1445
 * then @palette_index selects the palette to use. If the font only
1446
 * has one palette, this will be 0.
1447
 *
1448
 * Since: REPLACEME
1449
 */
1450
void
1451
hb_font_paint_glyph (hb_font_t *font,
1452
                     hb_codepoint_t glyph,
1453
                     hb_paint_funcs_t *pfuncs, void *paint_data,
1454
                     unsigned int palette_index,
1455
                     hb_color_t foreground)
1456
0
{
1457
0
  font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground);
1458
0
}
1459
1460
/* A bit higher-level, and with fallback */
1461
1462
/**
1463
 * hb_font_get_extents_for_direction:
1464
 * @font: #hb_font_t to work upon
1465
 * @direction: The direction of the text segment
1466
 * @extents: (out): The #hb_font_extents_t retrieved
1467
 *
1468
 * Fetches the extents for a font in a text segment of the
1469
 * specified direction.
1470
 *
1471
 * Calls the appropriate direction-specific variant (horizontal
1472
 * or vertical) depending on the value of @direction.
1473
 *
1474
 * Since: 1.1.3
1475
 **/
1476
void
1477
hb_font_get_extents_for_direction (hb_font_t         *font,
1478
           hb_direction_t     direction,
1479
           hb_font_extents_t *extents)
1480
0
{
1481
0
  font->get_extents_for_direction (direction, extents);
1482
0
}
1483
/**
1484
 * hb_font_get_glyph_advance_for_direction:
1485
 * @font: #hb_font_t to work upon
1486
 * @glyph: The glyph ID to query
1487
 * @direction: The direction of the text segment
1488
 * @x: (out): The horizontal advance retrieved
1489
 * @y: (out):  The vertical advance retrieved
1490
 *
1491
 * Fetches the advance for a glyph ID from the specified font,
1492
 * in a text segment of the specified direction.
1493
 *
1494
 * Calls the appropriate direction-specific variant (horizontal
1495
 * or vertical) depending on the value of @direction.
1496
 *
1497
 * Since: 0.9.2
1498
 **/
1499
void
1500
hb_font_get_glyph_advance_for_direction (hb_font_t      *font,
1501
           hb_codepoint_t  glyph,
1502
           hb_direction_t  direction,
1503
           hb_position_t  *x,
1504
           hb_position_t  *y)
1505
0
{
1506
0
  font->get_glyph_advance_for_direction (glyph, direction, x, y);
1507
0
}
1508
/**
1509
 * hb_font_get_glyph_advances_for_direction:
1510
 * @font: #hb_font_t to work upon
1511
 * @direction: The direction of the text segment
1512
 * @count: The number of glyph IDs in the sequence queried
1513
 * @first_glyph: The first glyph ID to query
1514
 * @glyph_stride: The stride between successive glyph IDs
1515
 * @first_advance: (out): The first advance retrieved
1516
 * @advance_stride: (out): The stride between successive advances
1517
 *
1518
 * Fetches the advances for a sequence of glyph IDs in the specified
1519
 * font, in a text segment of the specified direction.
1520
 *
1521
 * Calls the appropriate direction-specific variant (horizontal
1522
 * or vertical) depending on the value of @direction.
1523
 *
1524
 * Since: 1.8.6
1525
 **/
1526
HB_EXTERN void
1527
hb_font_get_glyph_advances_for_direction (hb_font_t*            font,
1528
            hb_direction_t        direction,
1529
            unsigned int          count,
1530
            const hb_codepoint_t *first_glyph,
1531
            unsigned              glyph_stride,
1532
            hb_position_t        *first_advance,
1533
            unsigned              advance_stride)
1534
0
{
1535
0
  font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);
1536
0
}
1537
1538
/**
1539
 * hb_font_get_glyph_origin_for_direction:
1540
 * @font: #hb_font_t to work upon
1541
 * @glyph: The glyph ID to query
1542
 * @direction: The direction of the text segment
1543
 * @x: (out): The X coordinate retrieved for the origin
1544
 * @y: (out): The Y coordinate retrieved for the origin
1545
 *
1546
 * Fetches the (X,Y) coordinates of the origin for a glyph in
1547
 * the specified font.
1548
 *
1549
 * Calls the appropriate direction-specific variant (horizontal
1550
 * or vertical) depending on the value of @direction.
1551
 *
1552
 * Since: 0.9.2
1553
 **/
1554
void
1555
hb_font_get_glyph_origin_for_direction (hb_font_t      *font,
1556
          hb_codepoint_t  glyph,
1557
          hb_direction_t  direction,
1558
          hb_position_t  *x,
1559
          hb_position_t  *y)
1560
0
{
1561
0
  return font->get_glyph_origin_for_direction (glyph, direction, x, y);
1562
0
}
1563
1564
/**
1565
 * hb_font_add_glyph_origin_for_direction:
1566
 * @font: #hb_font_t to work upon
1567
 * @glyph: The glyph ID to query
1568
 * @direction: The direction of the text segment
1569
 * @x: (inout): Input = The original X coordinate
1570
 *     Output = The X coordinate plus the X-coordinate of the origin
1571
 * @y: (inout): Input = The original Y coordinate
1572
 *     Output = The Y coordinate plus the Y-coordinate of the origin
1573
 *
1574
 * Adds the origin coordinates to an (X,Y) point coordinate, in
1575
 * the specified glyph ID in the specified font.
1576
 *
1577
 * Calls the appropriate direction-specific variant (horizontal
1578
 * or vertical) depending on the value of @direction.
1579
 *
1580
 * Since: 0.9.2
1581
 **/
1582
void
1583
hb_font_add_glyph_origin_for_direction (hb_font_t      *font,
1584
          hb_codepoint_t  glyph,
1585
          hb_direction_t  direction,
1586
          hb_position_t  *x,
1587
          hb_position_t  *y)
1588
0
{
1589
0
  return font->add_glyph_origin_for_direction (glyph, direction, x, y);
1590
0
}
1591
1592
/**
1593
 * hb_font_subtract_glyph_origin_for_direction:
1594
 * @font: #hb_font_t to work upon
1595
 * @glyph: The glyph ID to query
1596
 * @direction: The direction of the text segment
1597
 * @x: (inout): Input = The original X coordinate
1598
 *     Output = The X coordinate minus the X-coordinate of the origin
1599
 * @y: (inout): Input = The original Y coordinate
1600
 *     Output = The Y coordinate minus the Y-coordinate of the origin
1601
 *
1602
 * Subtracts the origin coordinates from an (X,Y) point coordinate,
1603
 * in the specified glyph ID in the specified font.
1604
 *
1605
 * Calls the appropriate direction-specific variant (horizontal
1606
 * or vertical) depending on the value of @direction.
1607
 *
1608
 * Since: 0.9.2
1609
 **/
1610
void
1611
hb_font_subtract_glyph_origin_for_direction (hb_font_t      *font,
1612
               hb_codepoint_t  glyph,
1613
               hb_direction_t  direction,
1614
               hb_position_t  *x,
1615
               hb_position_t  *y)
1616
0
{
1617
0
  return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
1618
0
}
1619
1620
/**
1621
 * hb_font_get_glyph_kerning_for_direction:
1622
 * @font: #hb_font_t to work upon
1623
 * @first_glyph: The glyph ID of the first glyph in the glyph pair to query
1624
 * @second_glyph: The glyph ID of the second glyph in the glyph pair to query
1625
 * @direction: The direction of the text segment
1626
 * @x: (out): The horizontal kerning-adjustment value retrieved
1627
 * @y: (out): The vertical kerning-adjustment value retrieved
1628
 *
1629
 * Fetches the kerning-adjustment value for a glyph-pair in the specified font.
1630
 *
1631
 * Calls the appropriate direction-specific variant (horizontal
1632
 * or vertical) depending on the value of @direction.
1633
 *
1634
 * Since: 0.9.2
1635
 **/
1636
void
1637
hb_font_get_glyph_kerning_for_direction (hb_font_t      *font,
1638
           hb_codepoint_t  first_glyph,
1639
           hb_codepoint_t  second_glyph,
1640
           hb_direction_t  direction,
1641
           hb_position_t  *x,
1642
           hb_position_t  *y)
1643
0
{
1644
0
  return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1645
0
}
1646
1647
/**
1648
 * hb_font_get_glyph_extents_for_origin:
1649
 * @font: #hb_font_t to work upon
1650
 * @glyph: The glyph ID to query
1651
 * @direction: The direction of the text segment
1652
 * @extents: (out): The #hb_glyph_extents_t retrieved
1653
 *
1654
 * Fetches the #hb_glyph_extents_t data for a glyph ID
1655
 * in the specified font, with respect to the origin in
1656
 * a text segment in the specified direction.
1657
 *
1658
 * Calls the appropriate direction-specific variant (horizontal
1659
 * or vertical) depending on the value of @direction.
1660
 *
1661
 * Return value: `true` if data found, `false` otherwise
1662
 *
1663
 * Since: 0.9.2
1664
 **/
1665
hb_bool_t
1666
hb_font_get_glyph_extents_for_origin (hb_font_t          *font,
1667
              hb_codepoint_t      glyph,
1668
              hb_direction_t      direction,
1669
              hb_glyph_extents_t *extents)
1670
0
{
1671
0
  return font->get_glyph_extents_for_origin (glyph, direction, extents);
1672
0
}
1673
1674
/**
1675
 * hb_font_get_glyph_contour_point_for_origin:
1676
 * @font: #hb_font_t to work upon
1677
 * @glyph: The glyph ID to query
1678
 * @point_index: The contour-point index to query
1679
 * @direction: The direction of the text segment
1680
 * @x: (out): The X value retrieved for the contour point
1681
 * @y: (out): The Y value retrieved for the contour point
1682
 *
1683
 * Fetches the (X,Y) coordinates of a specified contour-point index
1684
 * in the specified glyph ID in the specified font, with respect
1685
 * to the origin in a text segment in the specified direction.
1686
 *
1687
 * Calls the appropriate direction-specific variant (horizontal
1688
 * or vertical) depending on the value of @direction.
1689
 *
1690
 * Return value: `true` if data found, `false` otherwise
1691
 *
1692
 * Since: 0.9.2
1693
 **/
1694
hb_bool_t
1695
hb_font_get_glyph_contour_point_for_origin (hb_font_t      *font,
1696
              hb_codepoint_t  glyph,
1697
              unsigned int    point_index,
1698
              hb_direction_t  direction,
1699
              hb_position_t  *x,
1700
              hb_position_t  *y)
1701
0
{
1702
0
  return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1703
0
}
1704
1705
/**
1706
 * hb_font_glyph_to_string:
1707
 * @font: #hb_font_t to work upon
1708
 * @glyph: The glyph ID to query
1709
 * @s: (out) (array length=size): The string containing the glyph name
1710
 * @size: Length of string @s
1711
 *
1712
 * Fetches the name of the specified glyph ID in @font and returns
1713
 * it in string @s.
1714
 *
1715
 * If the glyph ID has no name in @font, a string of the form `gidDDD` is
1716
 * generated, with `DDD` being the glyph ID.
1717
 *
1718
 * According to the OpenType specification, glyph names are limited to 63
1719
 * characters and can only contain (a subset of) ASCII.
1720
 *
1721
 * Since: 0.9.2
1722
 **/
1723
void
1724
hb_font_glyph_to_string (hb_font_t      *font,
1725
       hb_codepoint_t  glyph,
1726
       char           *s,
1727
       unsigned int    size)
1728
0
{
1729
0
  font->glyph_to_string (glyph, s, size);
1730
0
}
1731
1732
/**
1733
 * hb_font_glyph_from_string:
1734
 * @font: #hb_font_t to work upon
1735
 * @s: (array length=len) (element-type uint8_t): string to query
1736
 * @len: The length of the string @s
1737
 * @glyph: (out): The glyph ID corresponding to the string requested
1738
 *
1739
 * Fetches the glyph ID from @font that matches the specified string.
1740
 * Strings of the format `gidDDD` or `uniUUUU` are parsed automatically.
1741
 *
1742
 * <note>Note: @len == -1 means the string is null-terminated.</note>
1743
 *
1744
 * Return value: `true` if data found, `false` otherwise
1745
 *
1746
 * Since: 0.9.2
1747
 **/
1748
hb_bool_t
1749
hb_font_glyph_from_string (hb_font_t      *font,
1750
         const char     *s,
1751
         int             len,
1752
         hb_codepoint_t *glyph)
1753
0
{
1754
0
  return font->glyph_from_string (s, len, glyph);
1755
0
}
1756
1757
1758
/*
1759
 * hb_font_t
1760
 */
1761
1762
DEFINE_NULL_INSTANCE (hb_font_t) =
1763
{
1764
  HB_OBJECT_HEADER_STATIC,
1765
1766
  0, /* serial */
1767
  0, /* serial_coords */
1768
1769
  nullptr, /* parent */
1770
  const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
1771
1772
  1000, /* x_scale */
1773
  1000, /* y_scale */
1774
  0., /* slant */
1775
  0., /* slant_xy; */
1776
  1.f, /* x_multf */
1777
  1.f, /* y_multf */
1778
  1<<16, /* x_mult */
1779
  1<<16, /* y_mult */
1780
1781
  0, /* x_ppem */
1782
  0, /* y_ppem */
1783
  0, /* ptem */
1784
1785
  HB_FONT_NO_VAR_NAMED_INSTANCE, /* instance_index */
1786
  0, /* num_coords */
1787
  nullptr, /* coords */
1788
  nullptr, /* design_coords */
1789
1790
  const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),
1791
1792
  /* Zero for the rest is fine. */
1793
};
1794
1795
1796
static hb_font_t *
1797
_hb_font_create (hb_face_t *face)
1798
419k
{
1799
419k
  hb_font_t *font;
1800
1801
419k
  if (unlikely (!face))
1802
0
    face = hb_face_get_empty ();
1803
1804
419k
  if (!(font = hb_object_create<hb_font_t> ()))
1805
597
    return hb_font_get_empty ();
1806
1807
419k
  hb_face_make_immutable (face);
1808
419k
  font->parent = hb_font_get_empty ();
1809
419k
  font->face = hb_face_reference (face);
1810
419k
  font->klass = hb_font_funcs_get_empty ();
1811
419k
  font->data.init0 (font);
1812
419k
  font->x_scale = font->y_scale = face->get_upem ();
1813
419k
  font->x_multf = font->y_multf = 1.f;
1814
419k
  font->x_mult = font->y_mult = 1 << 16;
1815
419k
  font->instance_index = HB_FONT_NO_VAR_NAMED_INSTANCE;
1816
1817
419k
  return font;
1818
419k
}
1819
1820
/**
1821
 * hb_font_create:
1822
 * @face: a face.
1823
 *
1824
 * Constructs a new font object from the specified face.
1825
 *
1826
 * <note>Note: If @face's index value (as passed to hb_face_create()
1827
 * has non-zero top 16-bits, those bits minus one are passed to
1828
 * hb_font_set_var_named_instance(), effectively loading a named-instance
1829
 * of a variable font, instead of the default-instance.  This allows
1830
 * specifying which named-instance to load by default when creating the
1831
 * face.</note>
1832
 *
1833
 * Return value: (transfer full): The new font object
1834
 *
1835
 * Since: 0.9.2
1836
 **/
1837
hb_font_t *
1838
hb_font_create (hb_face_t *face)
1839
419k
{
1840
419k
  hb_font_t *font = _hb_font_create (face);
1841
1842
419k
#ifndef HB_NO_OT_FONT
1843
  /* Install our in-house, very lightweight, funcs. */
1844
419k
  hb_ot_font_set_funcs (font);
1845
419k
#endif
1846
1847
419k
#ifndef HB_NO_VAR
1848
419k
  if (face && face->index >> 16)
1849
0
    hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
1850
419k
#endif
1851
1852
419k
  return font;
1853
419k
}
1854
1855
static void
1856
_hb_font_adopt_var_coords (hb_font_t *font,
1857
         int *coords, /* 2.14 normalized */
1858
         float *design_coords,
1859
         unsigned int coords_length)
1860
418k
{
1861
418k
  hb_free (font->coords);
1862
418k
  hb_free (font->design_coords);
1863
1864
418k
  font->coords = coords;
1865
418k
  font->design_coords = design_coords;
1866
418k
  font->num_coords = coords_length;
1867
1868
418k
  font->mults_changed (); // Easiest to call this to drop cached data
1869
418k
}
1870
1871
/**
1872
 * hb_font_create_sub_font:
1873
 * @parent: The parent font object
1874
 *
1875
 * Constructs a sub-font font object from the specified @parent font,
1876
 * replicating the parent's properties.
1877
 *
1878
 * Return value: (transfer full): The new sub-font font object
1879
 *
1880
 * Since: 0.9.2
1881
 **/
1882
hb_font_t *
1883
hb_font_create_sub_font (hb_font_t *parent)
1884
0
{
1885
0
  if (unlikely (!parent))
1886
0
    parent = hb_font_get_empty ();
1887
1888
0
  hb_font_t *font = _hb_font_create (parent->face);
1889
1890
0
  if (unlikely (hb_object_is_immutable (font)))
1891
0
    return font;
1892
1893
0
  font->parent = hb_font_reference (parent);
1894
1895
0
  font->x_scale = parent->x_scale;
1896
0
  font->y_scale = parent->y_scale;
1897
0
  font->slant = parent->slant;
1898
0
  font->x_ppem = parent->x_ppem;
1899
0
  font->y_ppem = parent->y_ppem;
1900
0
  font->ptem = parent->ptem;
1901
1902
0
  unsigned int num_coords = parent->num_coords;
1903
0
  if (num_coords)
1904
0
  {
1905
0
    int *coords = (int *) hb_calloc (num_coords, sizeof (parent->coords[0]));
1906
0
    float *design_coords = (float *) hb_calloc (num_coords, sizeof (parent->design_coords[0]));
1907
0
    if (likely (coords && design_coords))
1908
0
    {
1909
0
      hb_memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0]));
1910
0
      hb_memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0]));
1911
0
      _hb_font_adopt_var_coords (font, coords, design_coords, num_coords);
1912
0
    }
1913
0
    else
1914
0
    {
1915
0
      hb_free (coords);
1916
0
      hb_free (design_coords);
1917
0
    }
1918
0
  }
1919
1920
0
  font->mults_changed ();
1921
1922
0
  return font;
1923
0
}
1924
1925
/**
1926
 * hb_font_get_empty:
1927
 *
1928
 * Fetches the empty font object.
1929
 *
1930
 * Return value: (transfer full): The empty font object
1931
 *
1932
 * Since: 0.9.2
1933
 **/
1934
hb_font_t *
1935
hb_font_get_empty ()
1936
419k
{
1937
419k
  return const_cast<hb_font_t *> (&Null (hb_font_t));
1938
419k
}
1939
1940
/**
1941
 * hb_font_reference: (skip)
1942
 * @font: #hb_font_t to work upon
1943
 *
1944
 * Increases the reference count on the given font object.
1945
 *
1946
 * Return value: (transfer full): The @font object
1947
 *
1948
 * Since: 0.9.2
1949
 **/
1950
hb_font_t *
1951
hb_font_reference (hb_font_t *font)
1952
0
{
1953
0
  return hb_object_reference (font);
1954
0
}
1955
1956
/**
1957
 * hb_font_destroy: (skip)
1958
 * @font: #hb_font_t to work upon
1959
 *
1960
 * Decreases the reference count on the given font object. When the
1961
 * reference count reaches zero, the font is destroyed,
1962
 * freeing all memory.
1963
 *
1964
 * Since: 0.9.2
1965
 **/
1966
void
1967
hb_font_destroy (hb_font_t *font)
1968
838k
{
1969
838k
  if (!hb_object_destroy (font)) return;
1970
1971
419k
  font->data.fini ();
1972
1973
419k
  if (font->destroy)
1974
418k
    font->destroy (font->user_data);
1975
1976
419k
  hb_font_destroy (font->parent);
1977
419k
  hb_face_destroy (font->face);
1978
419k
  hb_font_funcs_destroy (font->klass);
1979
1980
419k
  hb_free (font->coords);
1981
419k
  hb_free (font->design_coords);
1982
1983
419k
  hb_free (font);
1984
419k
}
1985
1986
/**
1987
 * hb_font_set_user_data: (skip)
1988
 * @font: #hb_font_t to work upon
1989
 * @key: The user-data key
1990
 * @data: A pointer to the user data
1991
 * @destroy: (nullable): A callback to call when @data is not needed anymore
1992
 * @replace: Whether to replace an existing data with the same key
1993
 *
1994
 * Attaches a user-data key/data pair to the specified font object.
1995
 *
1996
 * Return value: `true` if success, `false` otherwise
1997
 *
1998
 * Since: 0.9.2
1999
 **/
2000
hb_bool_t
2001
hb_font_set_user_data (hb_font_t          *font,
2002
           hb_user_data_key_t *key,
2003
           void *              data,
2004
           hb_destroy_func_t   destroy /* May be NULL. */,
2005
           hb_bool_t           replace)
2006
0
{
2007
0
  if (!hb_object_is_immutable (font))
2008
0
    font->serial++;
2009
2010
0
  return hb_object_set_user_data (font, key, data, destroy, replace);
2011
0
}
2012
2013
/**
2014
 * hb_font_get_user_data: (skip)
2015
 * @font: #hb_font_t to work upon
2016
 * @key: The user-data key to query
2017
 *
2018
 * Fetches the user-data object associated with the specified key,
2019
 * attached to the specified font object.
2020
 *
2021
 * Return value: (transfer none): Pointer to the user data
2022
 *
2023
 * Since: 0.9.2
2024
 **/
2025
void *
2026
hb_font_get_user_data (const hb_font_t    *font,
2027
           hb_user_data_key_t *key)
2028
0
{
2029
0
  return hb_object_get_user_data (font, key);
2030
0
}
2031
2032
/**
2033
 * hb_font_make_immutable:
2034
 * @font: #hb_font_t to work upon
2035
 *
2036
 * Makes @font immutable.
2037
 *
2038
 * Since: 0.9.2
2039
 **/
2040
void
2041
hb_font_make_immutable (hb_font_t *font)
2042
0
{
2043
0
  if (hb_object_is_immutable (font))
2044
0
    return;
2045
2046
0
  if (font->parent)
2047
0
    hb_font_make_immutable (font->parent);
2048
2049
0
  hb_object_make_immutable (font);
2050
0
}
2051
2052
/**
2053
 * hb_font_is_immutable:
2054
 * @font: #hb_font_t to work upon
2055
 *
2056
 * Tests whether a font object is immutable.
2057
 *
2058
 * Return value: `true` if @font is immutable, `false` otherwise
2059
 *
2060
 * Since: 0.9.2
2061
 **/
2062
hb_bool_t
2063
hb_font_is_immutable (hb_font_t *font)
2064
0
{
2065
0
  return hb_object_is_immutable (font);
2066
0
}
2067
2068
/**
2069
 * hb_font_get_serial:
2070
 * @font: #hb_font_t to work upon
2071
 *
2072
 * Returns the internal serial number of the font. The serial
2073
 * number is increased every time a setting on the font is
2074
 * changed, using a setter function.
2075
 *
2076
 * Return value: serial number
2077
 *
2078
 * Since: 4.4.0
2079
 **/
2080
unsigned int
2081
hb_font_get_serial (hb_font_t *font)
2082
0
{
2083
0
  return font->serial;
2084
0
}
2085
2086
/**
2087
 * hb_font_changed:
2088
 * @font: #hb_font_t to work upon
2089
 *
2090
 * Notifies the @font that underlying font data has changed.
2091
 * This has the effect of increasing the serial as returned
2092
 * by hb_font_get_serial(), which invalidates internal caches.
2093
 *
2094
 * Since: 4.4.0
2095
 **/
2096
void
2097
hb_font_changed (hb_font_t *font)
2098
0
{
2099
0
  if (hb_object_is_immutable (font))
2100
0
    return;
2101
2102
0
  font->serial++;
2103
2104
0
  font->mults_changed ();
2105
0
}
2106
2107
/**
2108
 * hb_font_set_parent:
2109
 * @font: #hb_font_t to work upon
2110
 * @parent: The parent font object to assign
2111
 *
2112
 * Sets the parent font of @font.
2113
 *
2114
 * Since: 1.0.5
2115
 **/
2116
void
2117
hb_font_set_parent (hb_font_t *font,
2118
        hb_font_t *parent)
2119
0
{
2120
0
  if (hb_object_is_immutable (font))
2121
0
    return;
2122
2123
0
  if (parent == font->parent)
2124
0
    return;
2125
2126
0
  font->serial++;
2127
2128
0
  if (!parent)
2129
0
    parent = hb_font_get_empty ();
2130
2131
0
  hb_font_t *old = font->parent;
2132
2133
0
  font->parent = hb_font_reference (parent);
2134
2135
0
  hb_font_destroy (old);
2136
0
}
2137
2138
/**
2139
 * hb_font_get_parent:
2140
 * @font: #hb_font_t to work upon
2141
 *
2142
 * Fetches the parent font of @font.
2143
 *
2144
 * Return value: (transfer none): The parent font object
2145
 *
2146
 * Since: 0.9.2
2147
 **/
2148
hb_font_t *
2149
hb_font_get_parent (hb_font_t *font)
2150
0
{
2151
0
  return font->parent;
2152
0
}
2153
2154
/**
2155
 * hb_font_set_face:
2156
 * @font: #hb_font_t to work upon
2157
 * @face: The #hb_face_t to assign
2158
 *
2159
 * Sets @face as the font-face value of @font.
2160
 *
2161
 * Since: 1.4.3
2162
 **/
2163
void
2164
hb_font_set_face (hb_font_t *font,
2165
      hb_face_t *face)
2166
0
{
2167
0
  if (hb_object_is_immutable (font))
2168
0
    return;
2169
2170
0
  if (face == font->face)
2171
0
    return;
2172
2173
0
  font->serial++;
2174
2175
0
  if (unlikely (!face))
2176
0
    face = hb_face_get_empty ();
2177
2178
0
  hb_face_t *old = font->face;
2179
2180
0
  hb_face_make_immutable (face);
2181
0
  font->face = hb_face_reference (face);
2182
0
  font->mults_changed ();
2183
2184
0
  hb_face_destroy (old);
2185
0
}
2186
2187
/**
2188
 * hb_font_get_face:
2189
 * @font: #hb_font_t to work upon
2190
 *
2191
 * Fetches the face associated with the specified font object.
2192
 *
2193
 * Return value: (transfer none): The #hb_face_t value
2194
 *
2195
 * Since: 0.9.2
2196
 **/
2197
hb_face_t *
2198
hb_font_get_face (hb_font_t *font)
2199
1.22M
{
2200
1.22M
  return font->face;
2201
1.22M
}
2202
2203
2204
/**
2205
 * hb_font_set_funcs:
2206
 * @font: #hb_font_t to work upon
2207
 * @klass: (closure font_data) (destroy destroy) (scope notified): The font-functions structure.
2208
 * @font_data: Data to attach to @font
2209
 * @destroy: (nullable): The function to call when @font_data is not needed anymore
2210
 *
2211
 * Replaces the font-functions structure attached to a font, updating
2212
 * the font's user-data with @font-data and the @destroy callback.
2213
 *
2214
 * Since: 0.9.2
2215
 **/
2216
void
2217
hb_font_set_funcs (hb_font_t         *font,
2218
       hb_font_funcs_t   *klass,
2219
       void              *font_data,
2220
       hb_destroy_func_t  destroy /* May be NULL. */)
2221
1.24M
{
2222
1.24M
  if (hb_object_is_immutable (font))
2223
1.62k
  {
2224
1.62k
    if (destroy)
2225
1.62k
      destroy (font_data);
2226
1.62k
    return;
2227
1.62k
  }
2228
2229
1.24M
  font->serial++;
2230
2231
1.24M
  if (font->destroy)
2232
824k
    font->destroy (font->user_data);
2233
2234
1.24M
  if (!klass)
2235
0
    klass = hb_font_funcs_get_empty ();
2236
2237
1.24M
  hb_font_funcs_reference (klass);
2238
1.24M
  hb_font_funcs_destroy (font->klass);
2239
1.24M
  font->klass = klass;
2240
1.24M
  font->user_data = font_data;
2241
1.24M
  font->destroy = destroy;
2242
1.24M
}
2243
2244
/**
2245
 * hb_font_set_funcs_data:
2246
 * @font: #hb_font_t to work upon
2247
 * @font_data: (destroy destroy) (scope notified): Data to attach to @font
2248
 * @destroy: (nullable): The function to call when @font_data is not needed anymore
2249
 *
2250
 * Replaces the user data attached to a font, updating the font's
2251
 * @destroy callback.
2252
 *
2253
 * Since: 0.9.2
2254
 **/
2255
void
2256
hb_font_set_funcs_data (hb_font_t         *font,
2257
            void              *font_data,
2258
            hb_destroy_func_t  destroy /* May be NULL. */)
2259
0
{
2260
  /* Destroy user_data? */
2261
0
  if (hb_object_is_immutable (font))
2262
0
  {
2263
0
    if (destroy)
2264
0
      destroy (font_data);
2265
0
    return;
2266
0
  }
2267
2268
0
  font->serial++;
2269
2270
0
  if (font->destroy)
2271
0
    font->destroy (font->user_data);
2272
2273
0
  font->user_data = font_data;
2274
0
  font->destroy = destroy;
2275
0
}
2276
2277
2278
/**
2279
 * hb_font_set_scale:
2280
 * @font: #hb_font_t to work upon
2281
 * @x_scale: Horizontal scale value to assign
2282
 * @y_scale: Vertical scale value to assign
2283
 *
2284
 * Sets the horizontal and vertical scale of a font.
2285
 *
2286
 * The font scale is a number related to, but not the same as,
2287
 * font size. Typically the client establishes a scale factor
2288
 * to be used between the two. For example, 64, or 256, which
2289
 * would be the fractional-precision part of the font scale.
2290
 * This is necessary because #hb_position_t values are integer
2291
 * types and you need to leave room for fractional values
2292
 * in there.
2293
 *
2294
 * For example, to set the font size to 20, with 64
2295
 * levels of fractional precision you would call
2296
 * `hb_font_set_scale(font, 20 * 64, 20 * 64)`.
2297
 *
2298
 * In the example above, even what font size 20 means is up to
2299
 * you. It might be 20 pixels, or 20 points, or 20 millimeters.
2300
 * HarfBuzz does not care about that.  You can set the point
2301
 * size of the font using hb_font_set_ptem(), and the pixel
2302
 * size using hb_font_set_ppem().
2303
 *
2304
 * The choice of scale is yours but needs to be consistent between
2305
 * what you set here, and what you expect out of #hb_position_t
2306
 * as well has draw / paint API output values.
2307
 *
2308
 * Fonts default to a scale equal to the UPEM value of their face.
2309
 * A font with this setting is sometimes called an "unscaled" font.
2310
 *
2311
 * Since: 0.9.2
2312
 **/
2313
void
2314
hb_font_set_scale (hb_font_t *font,
2315
       int        x_scale,
2316
       int        y_scale)
2317
419k
{
2318
419k
  if (hb_object_is_immutable (font))
2319
597
    return;
2320
2321
419k
  if (font->x_scale == x_scale && font->y_scale == y_scale)
2322
0
    return;
2323
2324
419k
  font->serial++;
2325
2326
419k
  font->x_scale = x_scale;
2327
419k
  font->y_scale = y_scale;
2328
419k
  font->mults_changed ();
2329
419k
}
2330
2331
/**
2332
 * hb_font_get_scale:
2333
 * @font: #hb_font_t to work upon
2334
 * @x_scale: (out): Horizontal scale value
2335
 * @y_scale: (out): Vertical scale value
2336
 *
2337
 * Fetches the horizontal and vertical scale of a font.
2338
 *
2339
 * Since: 0.9.2
2340
 **/
2341
void
2342
hb_font_get_scale (hb_font_t *font,
2343
       int       *x_scale,
2344
       int       *y_scale)
2345
0
{
2346
0
  if (x_scale) *x_scale = font->x_scale;
2347
0
  if (y_scale) *y_scale = font->y_scale;
2348
0
}
2349
2350
/**
2351
 * hb_font_set_ppem:
2352
 * @font: #hb_font_t to work upon
2353
 * @x_ppem: Horizontal ppem value to assign
2354
 * @y_ppem: Vertical ppem value to assign
2355
 *
2356
 * Sets the horizontal and vertical pixels-per-em (PPEM) of a font.
2357
 *
2358
 * These values are used for pixel-size-specific adjustment to
2359
 * shaping and draw results, though for the most part they are
2360
 * unused and can be left unset.
2361
 *
2362
 * Since: 0.9.2
2363
 **/
2364
void
2365
hb_font_set_ppem (hb_font_t    *font,
2366
      unsigned int  x_ppem,
2367
      unsigned int  y_ppem)
2368
0
{
2369
0
  if (hb_object_is_immutable (font))
2370
0
    return;
2371
2372
0
  if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
2373
0
    return;
2374
2375
0
  font->serial++;
2376
2377
0
  font->x_ppem = x_ppem;
2378
0
  font->y_ppem = y_ppem;
2379
0
}
2380
2381
/**
2382
 * hb_font_get_ppem:
2383
 * @font: #hb_font_t to work upon
2384
 * @x_ppem: (out): Horizontal ppem value
2385
 * @y_ppem: (out): Vertical ppem value
2386
 *
2387
 * Fetches the horizontal and vertical points-per-em (ppem) of a font.
2388
 *
2389
 * Since: 0.9.2
2390
 **/
2391
void
2392
hb_font_get_ppem (hb_font_t    *font,
2393
      unsigned int *x_ppem,
2394
      unsigned int *y_ppem)
2395
0
{
2396
0
  if (x_ppem) *x_ppem = font->x_ppem;
2397
0
  if (y_ppem) *y_ppem = font->y_ppem;
2398
0
}
2399
2400
/**
2401
 * hb_font_set_ptem:
2402
 * @font: #hb_font_t to work upon
2403
 * @ptem: font size in points.
2404
 *
2405
 * Sets the "point size" of a font. Set to zero to unset.
2406
 * Used in CoreText to implement optical sizing.
2407
 *
2408
 * <note>Note: There are 72 points in an inch.</note>
2409
 *
2410
 * Since: 1.6.0
2411
 **/
2412
void
2413
hb_font_set_ptem (hb_font_t *font,
2414
      float      ptem)
2415
0
{
2416
0
  if (hb_object_is_immutable (font))
2417
0
    return;
2418
2419
0
  if (font->ptem == ptem)
2420
0
    return;
2421
2422
0
  font->serial++;
2423
2424
0
  font->ptem = ptem;
2425
0
}
2426
2427
/**
2428
 * hb_font_get_ptem:
2429
 * @font: #hb_font_t to work upon
2430
 *
2431
 * Fetches the "point size" of a font. Used in CoreText to
2432
 * implement optical sizing.
2433
 *
2434
 * Return value: Point size.  A value of zero means "not set."
2435
 *
2436
 * Since: 1.6.0
2437
 **/
2438
float
2439
hb_font_get_ptem (hb_font_t *font)
2440
0
{
2441
0
  return font->ptem;
2442
0
}
2443
2444
/**
2445
 * hb_font_set_synthetic_slant:
2446
 * @font: #hb_font_t to work upon
2447
 * @slant: synthetic slant value.
2448
 *
2449
 * Sets the "synthetic slant" of a font.  By default is zero.
2450
 * Synthetic slant is the graphical skew applied to the font
2451
 * at rendering time.
2452
 *
2453
 * HarfBuzz needs to know this value to adjust shaping results,
2454
 * metrics, and style values to match the slanted rendering.
2455
 *
2456
 * <note>Note: The glyph shape fetched via the hb_font_draw_glyph()
2457
 * function is slanted to reflect this value as well.</note>
2458
 *
2459
 * <note>Note: The slant value is a ratio.  For example, a
2460
 * 20% slant would be represented as a 0.2 value.</note>
2461
 *
2462
 * Since: 3.3.0
2463
 **/
2464
HB_EXTERN void
2465
hb_font_set_synthetic_slant (hb_font_t *font, float slant)
2466
0
{
2467
0
  if (hb_object_is_immutable (font))
2468
0
    return;
2469
2470
0
  if (font->slant == slant)
2471
0
    return;
2472
2473
0
  font->serial++;
2474
2475
0
  font->slant = slant;
2476
0
  font->mults_changed ();
2477
0
}
2478
2479
/**
2480
 * hb_font_get_synthetic_slant:
2481
 * @font: #hb_font_t to work upon
2482
 *
2483
 * Fetches the "synthetic slant" of a font.
2484
 *
2485
 * Return value: Synthetic slant.  By default is zero.
2486
 *
2487
 * Since: 3.3.0
2488
 **/
2489
HB_EXTERN float
2490
hb_font_get_synthetic_slant (hb_font_t *font)
2491
0
{
2492
0
  return font->slant;
2493
0
}
2494
2495
#ifndef HB_NO_VAR
2496
/*
2497
 * Variations
2498
 */
2499
2500
/**
2501
 * hb_font_set_variations:
2502
 * @font: #hb_font_t to work upon
2503
 * @variations: (array length=variations_length): Array of variation settings to apply
2504
 * @variations_length: Number of variations to apply
2505
 *
2506
 * Applies a list of font-variation settings to a font.
2507
 *
2508
 * Note that this overrides all existing variations set on @font.
2509
 * Axes not included in @variations will be effectively set to their
2510
 * default values.
2511
 *
2512
 * Since: 1.4.2
2513
 */
2514
void
2515
hb_font_set_variations (hb_font_t            *font,
2516
      const hb_variation_t *variations,
2517
      unsigned int          variations_length)
2518
0
{
2519
0
  if (hb_object_is_immutable (font))
2520
0
    return;
2521
2522
0
  font->serial_coords = ++font->serial;
2523
2524
0
  if (!variations_length && font->instance_index == HB_FONT_NO_VAR_NAMED_INSTANCE)
2525
0
  {
2526
0
    hb_font_set_var_coords_normalized (font, nullptr, 0);
2527
0
    return;
2528
0
  }
2529
2530
0
  const OT::fvar &fvar = *font->face->table.fvar;
2531
0
  auto axes = fvar.get_axes ();
2532
0
  const unsigned coords_length = axes.length;
2533
2534
0
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
2535
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
2536
2537
0
  if (unlikely (coords_length && !(normalized && design_coords)))
2538
0
  {
2539
0
    hb_free (normalized);
2540
0
    hb_free (design_coords);
2541
0
    return;
2542
0
  }
2543
2544
  /* Initialize design coords. */
2545
0
  for (unsigned int i = 0; i < coords_length; i++)
2546
0
    design_coords[i] = axes[i].get_default ();
2547
0
  if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE)
2548
0
  {
2549
0
    unsigned count = coords_length;
2550
    /* This may fail if index is out-of-range;
2551
     * That's why we initialize design_coords from fvar above
2552
     * unconditionally. */
2553
0
    hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index,
2554
0
            &count, design_coords);
2555
0
  }
2556
2557
0
  for (unsigned int i = 0; i < variations_length; i++)
2558
0
  {
2559
0
    const auto tag = variations[i].tag;
2560
0
    const auto v = variations[i].value;
2561
0
    for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
2562
0
      if (axes[axis_index].axisTag == tag)
2563
0
  design_coords[axis_index] = v;
2564
0
  }
2565
0
  font->face->table.avar->map_coords (normalized, coords_length);
2566
2567
0
  hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized);
2568
0
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
2569
0
}
2570
2571
/**
2572
 * hb_font_set_var_coords_design:
2573
 * @font: #hb_font_t to work upon
2574
 * @coords: (array length=coords_length): Array of variation coordinates to apply
2575
 * @coords_length: Number of coordinates to apply
2576
 *
2577
 * Applies a list of variation coordinates (in design-space units)
2578
 * to a font.
2579
 *
2580
 * Note that this overrides all existing variations set on @font.
2581
 * Axes not included in @coords will be effectively set to their
2582
 * default values.
2583
 *
2584
 * Since: 1.4.2
2585
 */
2586
void
2587
hb_font_set_var_coords_design (hb_font_t    *font,
2588
             const float  *coords,
2589
             unsigned int  coords_length)
2590
0
{
2591
0
  if (hb_object_is_immutable (font))
2592
0
    return;
2593
2594
0
  font->serial_coords = ++font->serial;
2595
2596
0
  int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
2597
0
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
2598
2599
0
  if (unlikely (coords_length && !(normalized && design_coords)))
2600
0
  {
2601
0
    hb_free (normalized);
2602
0
    hb_free (design_coords);
2603
0
    return;
2604
0
  }
2605
2606
0
  if (coords_length)
2607
0
    hb_memcpy (design_coords, coords, coords_length * sizeof (font->design_coords[0]));
2608
2609
0
  hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
2610
0
  _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
2611
0
}
2612
2613
/**
2614
 * hb_font_set_var_named_instance:
2615
 * @font: a font.
2616
 * @instance_index: named instance index.
2617
 *
2618
 * Sets design coords of a font from a named-instance index.
2619
 *
2620
 * Since: 2.6.0
2621
 */
2622
void
2623
hb_font_set_var_named_instance (hb_font_t *font,
2624
        unsigned int instance_index)
2625
0
{
2626
0
  if (hb_object_is_immutable (font))
2627
0
    return;
2628
2629
0
  if (font->instance_index == instance_index)
2630
0
    return;
2631
2632
0
  font->serial_coords = ++font->serial;
2633
2634
0
  font->instance_index = instance_index;
2635
0
  hb_font_set_variations (font, nullptr, 0);
2636
0
}
2637
2638
/**
2639
 * hb_font_get_var_named_instance:
2640
 * @font: a font.
2641
 *
2642
 * Returns the currently-set named-instance index of the font.
2643
 *
2644
 * Return value: Named-instance index or %HB_FONT_NO_VAR_NAMED_INSTANCE.
2645
 *
2646
 * Since: REPLACEME
2647
 **/
2648
unsigned int
2649
hb_font_get_var_named_instance (hb_font_t *font)
2650
0
{
2651
0
  return font->instance_index;
2652
0
}
2653
2654
/**
2655
 * hb_font_set_var_coords_normalized:
2656
 * @font: #hb_font_t to work upon
2657
 * @coords: (array length=coords_length): Array of variation coordinates to apply
2658
 * @coords_length: Number of coordinates to apply
2659
 *
2660
 * Applies a list of variation coordinates (in normalized units)
2661
 * to a font.
2662
 *
2663
 * Note that this overrides all existing variations set on @font.
2664
 * Axes not included in @coords will be effectively set to their
2665
 * default values.
2666
 *
2667
 * <note>Note: Coordinates should be normalized to 2.14.</note>
2668
 *
2669
 * Since: 1.4.2
2670
 */
2671
void
2672
hb_font_set_var_coords_normalized (hb_font_t    *font,
2673
           const int    *coords, /* 2.14 normalized */
2674
           unsigned int  coords_length)
2675
419k
{
2676
419k
  if (hb_object_is_immutable (font))
2677
597
    return;
2678
2679
419k
  font->serial_coords = ++font->serial;
2680
2681
419k
  int *copy = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
2682
419k
  int *unmapped = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
2683
419k
  float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (design_coords[0])) : nullptr;
2684
2685
419k
  if (unlikely (coords_length && !(copy && unmapped && design_coords)))
2686
435
  {
2687
435
    hb_free (copy);
2688
435
    hb_free (unmapped);
2689
435
    hb_free (design_coords);
2690
435
    return;
2691
435
  }
2692
2693
418k
  if (coords_length)
2694
21.3k
  {
2695
21.3k
    hb_memcpy (copy, coords, coords_length * sizeof (coords[0]));
2696
21.3k
    hb_memcpy (unmapped, coords, coords_length * sizeof (coords[0]));
2697
21.3k
  }
2698
2699
  /* Best effort design coords simulation */
2700
418k
  font->face->table.avar->unmap_coords (unmapped, coords_length);
2701
461k
  for (unsigned int i = 0; i < coords_length; ++i)
2702
43.1k
    design_coords[i] = font->face->table.fvar->unnormalize_axis_value (i, unmapped[i]);
2703
418k
  hb_free (unmapped);
2704
2705
418k
  _hb_font_adopt_var_coords (font, copy, design_coords, coords_length);
2706
418k
}
2707
2708
/**
2709
 * hb_font_get_var_coords_normalized:
2710
 * @font: #hb_font_t to work upon
2711
 * @length: (out): Number of coordinates retrieved
2712
 *
2713
 * Fetches the list of normalized variation coordinates currently
2714
 * set on a font.
2715
 *
2716
 * Note that this returned array may only contain values for some
2717
 * (or none) of the axes; omitted axes effectively have zero values.
2718
 *
2719
 * Return value is valid as long as variation coordinates of the font
2720
 * are not modified.
2721
 *
2722
 * Return value: coordinates array
2723
 *
2724
 * Since: 1.4.2
2725
 */
2726
const int *
2727
hb_font_get_var_coords_normalized (hb_font_t    *font,
2728
           unsigned int *length)
2729
0
{
2730
0
  if (length)
2731
0
    *length = font->num_coords;
2732
2733
0
  return font->coords;
2734
0
}
2735
2736
/**
2737
 * hb_font_get_var_coords_design:
2738
 * @font: #hb_font_t to work upon
2739
 * @length: (out): Number of coordinates retrieved
2740
 *
2741
 * Fetches the list of variation coordinates (in design-space units) currently
2742
 * set on a font.
2743
 *
2744
 * Note that this returned array may only contain values for some
2745
 * (or none) of the axes; omitted axes effectively have their default
2746
 * values.
2747
 *
2748
 * Return value is valid as long as variation coordinates of the font
2749
 * are not modified.
2750
 *
2751
 * Return value: coordinates array
2752
 *
2753
 * Since: 3.3.0
2754
 */
2755
const float *
2756
hb_font_get_var_coords_design (hb_font_t *font,
2757
             unsigned int *length)
2758
0
{
2759
0
  if (length)
2760
0
    *length = font->num_coords;
2761
2762
0
  return font->design_coords;
2763
0
}
2764
#endif
2765
2766
#ifndef HB_DISABLE_DEPRECATED
2767
/*
2768
 * Deprecated get_glyph_func():
2769
 */
2770
2771
struct hb_trampoline_closure_t
2772
{
2773
  void *user_data;
2774
  hb_destroy_func_t destroy;
2775
  unsigned int ref_count;
2776
};
2777
2778
template <typename FuncType>
2779
struct hb_trampoline_t
2780
{
2781
  hb_trampoline_closure_t closure; /* Must be first. */
2782
  FuncType func;
2783
};
2784
2785
template <typename FuncType>
2786
static hb_trampoline_t<FuncType> *
2787
trampoline_create (FuncType           func,
2788
       void              *user_data,
2789
       hb_destroy_func_t  destroy)
2790
0
{
2791
0
  typedef hb_trampoline_t<FuncType> trampoline_t;
2792
2793
0
  trampoline_t *trampoline = (trampoline_t *) hb_calloc (1, sizeof (trampoline_t));
2794
2795
0
  if (unlikely (!trampoline))
2796
0
    return nullptr;
2797
2798
0
  trampoline->closure.user_data = user_data;
2799
0
  trampoline->closure.destroy = destroy;
2800
0
  trampoline->closure.ref_count = 1;
2801
0
  trampoline->func = func;
2802
2803
0
  return trampoline;
2804
0
}
2805
2806
static void
2807
trampoline_reference (hb_trampoline_closure_t *closure)
2808
0
{
2809
0
  closure->ref_count++;
2810
0
}
2811
2812
static void
2813
trampoline_destroy (void *user_data)
2814
0
{
2815
0
  hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
2816
2817
0
  if (--closure->ref_count)
2818
0
    return;
2819
2820
0
  if (closure->destroy)
2821
0
    closure->destroy (closure->user_data);
2822
0
  hb_free (closure);
2823
0
}
2824
2825
typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
2826
2827
static hb_bool_t
2828
hb_font_get_nominal_glyph_trampoline (hb_font_t      *font,
2829
              void           *font_data,
2830
              hb_codepoint_t  unicode,
2831
              hb_codepoint_t *glyph,
2832
              void           *user_data)
2833
0
{
2834
0
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2835
0
  return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
2836
0
}
2837
2838
static hb_bool_t
2839
hb_font_get_variation_glyph_trampoline (hb_font_t      *font,
2840
          void           *font_data,
2841
          hb_codepoint_t  unicode,
2842
          hb_codepoint_t  variation_selector,
2843
          hb_codepoint_t *glyph,
2844
          void           *user_data)
2845
0
{
2846
0
  hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2847
0
  return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
2848
0
}
2849
2850
/**
2851
 * hb_font_funcs_set_glyph_func:
2852
 * @ffuncs: The font-functions structure
2853
 * @func: (closure user_data) (destroy destroy) (scope notified): callback function
2854
 * @user_data: data to pass to @func
2855
 * @destroy: (nullable): function to call when @user_data is not needed anymore
2856
 *
2857
 * Deprecated.  Use hb_font_funcs_set_nominal_glyph_func() and
2858
 * hb_font_funcs_set_variation_glyph_func() instead.
2859
 *
2860
 * Since: 0.9.2
2861
 * Deprecated: 1.2.3
2862
 **/
2863
void
2864
hb_font_funcs_set_glyph_func (hb_font_funcs_t          *ffuncs,
2865
            hb_font_get_glyph_func_t  func,
2866
            void                     *user_data,
2867
            hb_destroy_func_t         destroy /* May be NULL. */)
2868
0
{
2869
0
  if (hb_object_is_immutable (ffuncs))
2870
0
  {
2871
0
    if (destroy)
2872
0
      destroy (user_data);
2873
0
    return;
2874
0
  }
2875
2876
0
  hb_font_get_glyph_trampoline_t *trampoline;
2877
2878
0
  trampoline = trampoline_create (func, user_data, destroy);
2879
0
  if (unlikely (!trampoline))
2880
0
  {
2881
0
    if (destroy)
2882
0
      destroy (user_data);
2883
0
    return;
2884
0
  }
2885
2886
  /* Since we pass it to two destroying functions. */
2887
0
  trampoline_reference (&trampoline->closure);
2888
2889
0
  hb_font_funcs_set_nominal_glyph_func (ffuncs,
2890
0
          hb_font_get_nominal_glyph_trampoline,
2891
0
          trampoline,
2892
0
          trampoline_destroy);
2893
2894
0
  hb_font_funcs_set_variation_glyph_func (ffuncs,
2895
0
            hb_font_get_variation_glyph_trampoline,
2896
0
            trampoline,
2897
0
            trampoline_destroy);
2898
0
}
2899
#endif
2900
2901
2902
void
2903
hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t               *ffuncs,
2904
                                   hb_font_get_glyph_shape_func_t  func,
2905
                                   void                           *user_data,
2906
                                   hb_destroy_func_t               destroy /* May be NULL. */)
2907
0
{
2908
0
  hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
2909
0
}