Coverage Report

Created: 2023-06-07 06:14

/src/harfbuzz/src/hb-ot-font.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2011,2014  Google, Inc.
3
 *
4
 *  This is part of HarfBuzz, a text shaping library.
5
 *
6
 * Permission is hereby granted, without written agreement and without
7
 * license or royalty fees, to use, copy, modify, and distribute this
8
 * software and its documentation for any purpose, provided that the
9
 * above copyright notice and the following two paragraphs appear in
10
 * all copies of this software.
11
 *
12
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16
 * DAMAGE.
17
 *
18
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23
 *
24
 * Google Author(s): Behdad Esfahbod, Roozbeh Pournader
25
 */
26
27
#include "hb.hh"
28
29
#ifndef HB_NO_OT_FONT
30
31
#include "hb-ot.h"
32
33
#include "hb-cache.hh"
34
#include "hb-font.hh"
35
#include "hb-machinery.hh"
36
#include "hb-ot-face.hh"
37
#include "hb-outline.hh"
38
39
#include "hb-ot-cmap-table.hh"
40
#include "hb-ot-glyf-table.hh"
41
#include "hb-ot-cff1-table.hh"
42
#include "hb-ot-cff2-table.hh"
43
#include "hb-ot-hmtx-table.hh"
44
#include "hb-ot-post-table.hh"
45
#include "hb-ot-stat-table.hh" // Just so we compile it; unused otherwise.
46
#include "hb-ot-vorg-table.hh"
47
#include "OT/Color/CBDT/CBDT.hh"
48
#include "OT/Color/COLR/COLR.hh"
49
#include "OT/Color/sbix/sbix.hh"
50
#include "OT/Color/svg/svg.hh"
51
52
53
/**
54
 * SECTION:hb-ot-font
55
 * @title: hb-ot-font
56
 * @short_description: OpenType font implementation
57
 * @include: hb-ot.h
58
 *
59
 * Functions for using OpenType fonts with hb_shape().  Note that fonts returned
60
 * by hb_font_create() default to using these functions, so most clients would
61
 * never need to call these functions directly.
62
 **/
63
64
using hb_ot_font_cmap_cache_t    = hb_cache_t<21, 16, 8, true>;
65
using hb_ot_font_advance_cache_t = hb_cache_t<24, 16, 8, true>;
66
67
#ifndef HB_NO_OT_FONT_CMAP_CACHE
68
static hb_user_data_key_t hb_ot_font_cmap_cache_user_data_key;
69
#endif
70
71
struct hb_ot_font_t
72
{
73
  const hb_ot_face_t *ot_face;
74
75
#ifndef HB_NO_OT_FONT_CMAP_CACHE
76
  hb_ot_font_cmap_cache_t *cmap_cache;
77
#endif
78
79
  /* h_advance caching */
80
  mutable hb_atomic_int_t cached_coords_serial;
81
  mutable hb_atomic_ptr_t<hb_ot_font_advance_cache_t> advance_cache;
82
};
83
84
static hb_ot_font_t *
85
_hb_ot_font_create (hb_font_t *font)
86
18
{
87
18
  hb_ot_font_t *ot_font = (hb_ot_font_t *) hb_calloc (1, sizeof (hb_ot_font_t));
88
18
  if (unlikely (!ot_font))
89
0
    return nullptr;
90
91
18
  ot_font->ot_face = &font->face->table;
92
93
18
#ifndef HB_NO_OT_FONT_CMAP_CACHE
94
  // retry:
95
18
  auto *cmap_cache  = (hb_ot_font_cmap_cache_t *) hb_face_get_user_data (font->face,
96
18
                   &hb_ot_font_cmap_cache_user_data_key);
97
18
  if (!cmap_cache)
98
18
  {
99
18
    cmap_cache = (hb_ot_font_cmap_cache_t *) hb_malloc (sizeof (hb_ot_font_cmap_cache_t));
100
18
    if (unlikely (!cmap_cache)) goto out;
101
18
    cmap_cache->init ();
102
18
    if (unlikely (!hb_face_set_user_data (font->face,
103
18
            &hb_ot_font_cmap_cache_user_data_key,
104
18
            cmap_cache,
105
18
            hb_free,
106
18
            false)))
107
0
    {
108
0
      hb_free (cmap_cache);
109
0
      cmap_cache = nullptr;
110
      /* Normally we would retry here, but that would
111
       * infinite-loop if the face is the empty-face.
112
       * Just let it go and this font will be uncached if it
113
       * happened to collide with another thread creating the
114
       * cache at the same time. */
115
      // goto retry;
116
0
    }
117
18
  }
118
18
  out:
119
18
  ot_font->cmap_cache = cmap_cache;
120
18
#endif
121
122
18
  return ot_font;
123
18
}
124
125
static void
126
_hb_ot_font_destroy (void *font_data)
127
18
{
128
18
  hb_ot_font_t *ot_font = (hb_ot_font_t *) font_data;
129
130
18
  auto *cache = ot_font->advance_cache.get_relaxed ();
131
18
  hb_free (cache);
132
133
18
  hb_free (ot_font);
134
18
}
135
136
static hb_bool_t
137
hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED,
138
       void *font_data,
139
       hb_codepoint_t unicode,
140
       hb_codepoint_t *glyph,
141
       void *user_data HB_UNUSED)
142
0
{
143
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
144
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
145
0
  hb_ot_font_cmap_cache_t *cmap_cache = nullptr;
146
0
#ifndef HB_NO_OT_FONT_CMAP_CACHE
147
0
  cmap_cache = ot_font->cmap_cache;
148
0
#endif
149
0
  return ot_face->cmap->get_nominal_glyph (unicode, glyph, cmap_cache);
150
0
}
151
152
static unsigned int
153
hb_ot_get_nominal_glyphs (hb_font_t *font HB_UNUSED,
154
        void *font_data,
155
        unsigned int count,
156
        const hb_codepoint_t *first_unicode,
157
        unsigned int unicode_stride,
158
        hb_codepoint_t *first_glyph,
159
        unsigned int glyph_stride,
160
        void *user_data HB_UNUSED)
161
0
{
162
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
163
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
164
0
  hb_ot_font_cmap_cache_t *cmap_cache = nullptr;
165
0
#ifndef HB_NO_OT_FONT_CMAP_CACHE
166
0
  cmap_cache = ot_font->cmap_cache;
167
0
#endif
168
0
  return ot_face->cmap->get_nominal_glyphs (count,
169
0
              first_unicode, unicode_stride,
170
0
              first_glyph, glyph_stride,
171
0
              cmap_cache);
172
0
}
173
174
static hb_bool_t
175
hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED,
176
         void *font_data,
177
         hb_codepoint_t unicode,
178
         hb_codepoint_t variation_selector,
179
         hb_codepoint_t *glyph,
180
         void *user_data HB_UNUSED)
181
0
{
182
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
183
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
184
0
  hb_ot_font_cmap_cache_t *cmap_cache = nullptr;
185
0
#ifndef HB_NO_OT_FONT_CMAP_CACHE
186
0
  cmap_cache = ot_font->cmap_cache;
187
0
#endif
188
0
  return ot_face->cmap->get_variation_glyph (unicode,
189
0
                                             variation_selector, glyph,
190
0
                                             cmap_cache);
191
0
}
192
193
static void
194
hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
195
          unsigned count,
196
          const hb_codepoint_t *first_glyph,
197
          unsigned glyph_stride,
198
          hb_position_t *first_advance,
199
          unsigned advance_stride,
200
          void *user_data HB_UNUSED)
201
0
{
202
203
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
204
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
205
0
  const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx;
206
207
0
  hb_position_t *orig_first_advance = first_advance;
208
209
0
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
210
0
  const OT::HVAR &HVAR = *hmtx.var_table;
211
0
  const OT::VariationStore &varStore = &HVAR + HVAR.varStore;
212
0
  OT::VariationStore::cache_t *varStore_cache = font->num_coords * count >= 128 ? varStore.create_cache () : nullptr;
213
214
0
  bool use_cache = font->num_coords;
215
#else
216
  OT::VariationStore::cache_t *varStore_cache = nullptr;
217
  bool use_cache = false;
218
#endif
219
220
0
  hb_ot_font_advance_cache_t *cache = nullptr;
221
0
  if (use_cache)
222
0
  {
223
0
  retry:
224
0
    cache = ot_font->advance_cache.get_acquire ();
225
0
    if (unlikely (!cache))
226
0
    {
227
0
      cache = (hb_ot_font_advance_cache_t *) hb_malloc (sizeof (hb_ot_font_advance_cache_t));
228
0
      if (unlikely (!cache))
229
0
      {
230
0
  use_cache = false;
231
0
  goto out;
232
0
      }
233
234
0
      cache->init ();
235
0
      if (unlikely (!ot_font->advance_cache.cmpexch (nullptr, cache)))
236
0
      {
237
0
  hb_free (cache);
238
0
  goto retry;
239
0
      }
240
0
      ot_font->cached_coords_serial.set_release (font->serial_coords);
241
0
    }
242
0
  }
243
0
  out:
244
245
0
  if (!use_cache)
246
0
  {
247
0
    for (unsigned int i = 0; i < count; i++)
248
0
    {
249
0
      *first_advance = font->em_scale_x (hmtx.get_advance_with_var_unscaled (*first_glyph, font, varStore_cache));
250
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
251
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
252
0
    }
253
0
  }
254
0
  else
255
0
  { /* Use cache. */
256
0
    if (ot_font->cached_coords_serial.get_acquire () != (int) font->serial_coords)
257
0
    {
258
0
      ot_font->advance_cache->init ();
259
0
      ot_font->cached_coords_serial.set_release (font->serial_coords);
260
0
    }
261
262
0
    for (unsigned int i = 0; i < count; i++)
263
0
    {
264
0
      hb_position_t v;
265
0
      unsigned cv;
266
0
      if (ot_font->advance_cache->get (*first_glyph, &cv))
267
0
  v = cv;
268
0
      else
269
0
      {
270
0
        v = hmtx.get_advance_with_var_unscaled (*first_glyph, font, varStore_cache);
271
0
  ot_font->advance_cache->set (*first_glyph, v);
272
0
      }
273
0
      *first_advance = font->em_scale_x (v);
274
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
275
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
276
0
    }
277
0
  }
278
279
0
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
280
0
  OT::VariationStore::destroy_cache (varStore_cache);
281
0
#endif
282
283
0
  if (font->x_strength && !font->embolden_in_place)
284
0
  {
285
    /* Emboldening. */
286
0
    hb_position_t x_strength = font->x_scale >= 0 ? font->x_strength : -font->x_strength;
287
0
    first_advance = orig_first_advance;
288
0
    for (unsigned int i = 0; i < count; i++)
289
0
    {
290
0
      *first_advance += *first_advance ? x_strength : 0;
291
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
292
0
    }
293
0
  }
294
0
}
295
296
#ifndef HB_NO_VERTICAL
297
static void
298
hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
299
          unsigned count,
300
          const hb_codepoint_t *first_glyph,
301
          unsigned glyph_stride,
302
          hb_position_t *first_advance,
303
          unsigned advance_stride,
304
          void *user_data HB_UNUSED)
305
0
{
306
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
307
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
308
0
  const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
309
310
0
  hb_position_t *orig_first_advance = first_advance;
311
312
0
  if (vmtx.has_data ())
313
0
  {
314
0
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
315
0
    const OT::VVAR &VVAR = *vmtx.var_table;
316
0
    const OT::VariationStore &varStore = &VVAR + VVAR.varStore;
317
0
    OT::VariationStore::cache_t *varStore_cache = font->num_coords ? varStore.create_cache () : nullptr;
318
#else
319
    OT::VariationStore::cache_t *varStore_cache = nullptr;
320
#endif
321
322
0
    for (unsigned int i = 0; i < count; i++)
323
0
    {
324
0
      *first_advance = font->em_scale_y (-(int) vmtx.get_advance_with_var_unscaled (*first_glyph, font, varStore_cache));
325
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
326
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
327
0
    }
328
329
0
#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
330
0
    OT::VariationStore::destroy_cache (varStore_cache);
331
0
#endif
332
0
  }
333
0
  else
334
0
  {
335
0
    hb_font_extents_t font_extents;
336
0
    font->get_h_extents_with_fallback (&font_extents);
337
0
    hb_position_t advance = -(font_extents.ascender - font_extents.descender);
338
339
0
    for (unsigned int i = 0; i < count; i++)
340
0
    {
341
0
      *first_advance = advance;
342
0
      first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
343
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
344
0
    }
345
0
  }
346
347
0
  if (font->y_strength && !font->embolden_in_place)
348
0
  {
349
    /* Emboldening. */
350
0
    hb_position_t y_strength = font->y_scale >= 0 ? font->y_strength : -font->y_strength;
351
0
    first_advance = orig_first_advance;
352
0
    for (unsigned int i = 0; i < count; i++)
353
0
    {
354
0
      *first_advance += *first_advance ? y_strength : 0;
355
0
      first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
356
0
    }
357
0
  }
358
0
}
359
#endif
360
361
#ifndef HB_NO_VERTICAL
362
static hb_bool_t
363
hb_ot_get_glyph_v_origin (hb_font_t *font,
364
        void *font_data,
365
        hb_codepoint_t glyph,
366
        hb_position_t *x,
367
        hb_position_t *y,
368
        void *user_data HB_UNUSED)
369
0
{
370
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
371
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
372
373
0
  *x = font->get_glyph_h_advance (glyph) / 2;
374
375
0
  const OT::VORG &VORG = *ot_face->VORG;
376
0
  if (VORG.has_data ())
377
0
  {
378
0
    float delta = 0;
379
380
0
#ifndef HB_NO_VAR
381
0
    const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
382
0
    const OT::VVAR &VVAR = *vmtx.var_table;
383
0
    if (font->num_coords)
384
0
      VVAR.get_vorg_delta_unscaled (glyph,
385
0
            font->coords, font->num_coords,
386
0
            &delta);
387
0
#endif
388
389
0
    *y = font->em_scalef_y (VORG.get_y_origin (glyph) + delta);
390
0
    return true;
391
0
  }
392
393
0
  hb_glyph_extents_t extents = {0};
394
0
  if (ot_face->glyf->get_extents (font, glyph, &extents))
395
0
  {
396
0
    const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
397
0
    int tsb = 0;
398
0
    if (vmtx.get_leading_bearing_with_var_unscaled (font, glyph, &tsb))
399
0
    {
400
0
      *y = extents.y_bearing + font->em_scale_y (tsb);
401
0
      return true;
402
0
    }
403
404
0
    hb_font_extents_t font_extents;
405
0
    font->get_h_extents_with_fallback (&font_extents);
406
0
    hb_position_t advance = font_extents.ascender - font_extents.descender;
407
0
    int diff = advance - -extents.height;
408
0
    *y = extents.y_bearing + (diff >> 1);
409
0
    return true;
410
0
  }
411
412
0
  hb_font_extents_t font_extents;
413
0
  font->get_h_extents_with_fallback (&font_extents);
414
0
  *y = font_extents.ascender;
415
416
0
  return true;
417
0
}
418
#endif
419
420
static hb_bool_t
421
hb_ot_get_glyph_extents (hb_font_t *font,
422
       void *font_data,
423
       hb_codepoint_t glyph,
424
       hb_glyph_extents_t *extents,
425
       void *user_data HB_UNUSED)
426
0
{
427
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
428
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
429
430
0
#if !defined(HB_NO_OT_FONT_BITMAP) && !defined(HB_NO_COLOR)
431
0
  if (ot_face->sbix->get_extents (font, glyph, extents)) return true;
432
0
  if (ot_face->CBDT->get_extents (font, glyph, extents)) return true;
433
0
#endif
434
0
#if !defined(HB_NO_COLOR) && !defined(HB_NO_PAINT)
435
0
  if (ot_face->COLR->get_extents (font, glyph, extents)) return true;
436
0
#endif
437
0
  if (ot_face->glyf->get_extents (font, glyph, extents)) return true;
438
0
#ifndef HB_NO_OT_FONT_CFF
439
0
  if (ot_face->cff1->get_extents (font, glyph, extents)) return true;
440
0
  if (ot_face->cff2->get_extents (font, glyph, extents)) return true;
441
0
#endif
442
443
0
  return false;
444
0
}
445
446
#ifndef HB_NO_OT_FONT_GLYPH_NAMES
447
static hb_bool_t
448
hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED,
449
          void *font_data,
450
          hb_codepoint_t glyph,
451
          char *name, unsigned int size,
452
          void *user_data HB_UNUSED)
453
0
{
454
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
455
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
456
457
0
  if (ot_face->post->get_glyph_name (glyph, name, size)) return true;
458
0
#ifndef HB_NO_OT_FONT_CFF
459
0
  if (ot_face->cff1->get_glyph_name (glyph, name, size)) return true;
460
0
#endif
461
0
  return false;
462
0
}
463
static hb_bool_t
464
hb_ot_get_glyph_from_name (hb_font_t *font HB_UNUSED,
465
         void *font_data,
466
         const char *name, int len,
467
         hb_codepoint_t *glyph,
468
         void *user_data HB_UNUSED)
469
0
{
470
0
  const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
471
0
  const hb_ot_face_t *ot_face = ot_font->ot_face;
472
473
0
  if (ot_face->post->get_glyph_from_name (name, len, glyph)) return true;
474
0
#ifndef HB_NO_OT_FONT_CFF
475
0
    if (ot_face->cff1->get_glyph_from_name (name, len, glyph)) return true;
476
0
#endif
477
0
  return false;
478
0
}
479
#endif
480
481
static hb_bool_t
482
hb_ot_get_font_h_extents (hb_font_t *font,
483
        void *font_data HB_UNUSED,
484
        hb_font_extents_t *metrics,
485
        void *user_data HB_UNUSED)
486
0
{
487
0
  bool ret = _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, &metrics->ascender) &&
488
0
       _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER, &metrics->descender) &&
489
0
       _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP, &metrics->line_gap);
490
491
  /* Embolden */
492
0
  int y_shift = font->y_strength;
493
0
  if (font->y_scale < 0) y_shift = -y_shift;
494
0
  metrics->ascender += y_shift;
495
496
0
  return ret;
497
0
}
498
499
#ifndef HB_NO_VERTICAL
500
static hb_bool_t
501
hb_ot_get_font_v_extents (hb_font_t *font,
502
        void *font_data HB_UNUSED,
503
        hb_font_extents_t *metrics,
504
        void *user_data HB_UNUSED)
505
0
{
506
0
  return _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_ASCENDER, &metrics->ascender) &&
507
0
   _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_DESCENDER, &metrics->descender) &&
508
0
   _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_LINE_GAP, &metrics->line_gap);
509
0
}
510
#endif
511
512
#ifndef HB_NO_DRAW
513
static void
514
hb_ot_draw_glyph (hb_font_t *font,
515
      void *font_data HB_UNUSED,
516
      hb_codepoint_t glyph,
517
      hb_draw_funcs_t *draw_funcs, void *draw_data,
518
      void *user_data)
519
0
{
520
0
  bool embolden = font->x_strength || font->y_strength;
521
0
  hb_outline_t outline;
522
523
0
  { // Need draw_session to be destructed before emboldening.
524
0
    hb_draw_session_t draw_session (embolden ? hb_outline_recording_pen_get_funcs () : draw_funcs,
525
0
            embolden ? &outline : draw_data, font->slant_xy);
526
0
    if (!font->face->table.glyf->get_path (font, glyph, draw_session))
527
0
#ifndef HB_NO_CFF
528
0
    if (!font->face->table.cff1->get_path (font, glyph, draw_session))
529
0
    if (!font->face->table.cff2->get_path (font, glyph, draw_session))
530
0
#endif
531
0
    {}
532
0
  }
533
534
0
  if (embolden)
535
0
  {
536
0
    float x_shift = font->embolden_in_place ? 0 : (float) font->x_strength / 2;
537
0
    float y_shift = (float) font->y_strength / 2;
538
0
    if (font->x_scale < 0) x_shift = -x_shift;
539
0
    if (font->y_scale < 0) y_shift = -y_shift;
540
0
    outline.embolden (font->x_strength, font->y_strength,
541
0
          x_shift, y_shift);
542
543
0
    outline.replay (draw_funcs, draw_data);
544
0
  }
545
0
}
546
#endif
547
548
#ifndef HB_NO_PAINT
549
static void
550
hb_ot_paint_glyph (hb_font_t *font,
551
                   void *font_data,
552
                   hb_codepoint_t glyph,
553
                   hb_paint_funcs_t *paint_funcs, void *paint_data,
554
                   unsigned int palette,
555
                   hb_color_t foreground,
556
                   void *user_data)
557
0
{
558
0
#ifndef HB_NO_COLOR
559
0
  if (font->face->table.COLR->paint_glyph (font, glyph, paint_funcs, paint_data, palette, foreground)) return;
560
0
  if (font->face->table.SVG->paint_glyph (font, glyph, paint_funcs, paint_data)) return;
561
0
#ifndef HB_NO_OT_FONT_BITMAP
562
0
  if (font->face->table.CBDT->paint_glyph (font, glyph, paint_funcs, paint_data)) return;
563
0
  if (font->face->table.sbix->paint_glyph (font, glyph, paint_funcs, paint_data)) return;
564
0
#endif
565
0
#endif
566
0
  if (font->face->table.glyf->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return;
567
0
#ifndef HB_NO_CFF
568
0
  if (font->face->table.cff1->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return;
569
0
  if (font->face->table.cff2->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return;
570
0
#endif
571
0
}
572
#endif
573
574
static inline void free_static_ot_funcs ();
575
576
static struct hb_ot_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ot_font_funcs_lazy_loader_t>
577
{
578
  static hb_font_funcs_t *create ()
579
1
  {
580
1
    hb_font_funcs_t *funcs = hb_font_funcs_create ();
581
582
1
    hb_font_funcs_set_nominal_glyph_func (funcs, hb_ot_get_nominal_glyph, nullptr, nullptr);
583
1
    hb_font_funcs_set_nominal_glyphs_func (funcs, hb_ot_get_nominal_glyphs, nullptr, nullptr);
584
1
    hb_font_funcs_set_variation_glyph_func (funcs, hb_ot_get_variation_glyph, nullptr, nullptr);
585
586
1
    hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, nullptr, nullptr);
587
1
    hb_font_funcs_set_glyph_h_advances_func (funcs, hb_ot_get_glyph_h_advances, nullptr, nullptr);
588
    //hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ot_get_glyph_h_origin, nullptr, nullptr);
589
590
1
#ifndef HB_NO_VERTICAL
591
1
    hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, nullptr, nullptr);
592
1
    hb_font_funcs_set_glyph_v_advances_func (funcs, hb_ot_get_glyph_v_advances, nullptr, nullptr);
593
1
    hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, nullptr, nullptr);
594
1
#endif
595
596
1
#ifndef HB_NO_DRAW
597
1
    hb_font_funcs_set_draw_glyph_func (funcs, hb_ot_draw_glyph, nullptr, nullptr);
598
1
#endif
599
600
1
#ifndef HB_NO_PAINT
601
1
    hb_font_funcs_set_paint_glyph_func (funcs, hb_ot_paint_glyph, nullptr, nullptr);
602
1
#endif
603
604
1
    hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, nullptr, nullptr);
605
    //hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour_point, nullptr, nullptr);
606
607
1
#ifndef HB_NO_OT_FONT_GLYPH_NAMES
608
1
    hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, nullptr, nullptr);
609
1
    hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr);
610
1
#endif
611
612
1
    hb_font_funcs_make_immutable (funcs);
613
614
1
    hb_atexit (free_static_ot_funcs);
615
616
1
    return funcs;
617
1
  }
618
} static_ot_funcs;
619
620
static inline
621
void free_static_ot_funcs ()
622
1
{
623
1
  static_ot_funcs.free_instance ();
624
1
}
625
626
static hb_font_funcs_t *
627
_hb_ot_get_font_funcs ()
628
18
{
629
18
  return static_ot_funcs.get_unconst ();
630
18
}
631
632
633
/**
634
 * hb_ot_font_set_funcs:
635
 * @font: #hb_font_t to work upon
636
 *
637
 * Sets the font functions to use when working with @font. 
638
 *
639
 * Since: 0.9.28
640
 **/
641
void
642
hb_ot_font_set_funcs (hb_font_t *font)
643
18
{
644
18
  hb_ot_font_t *ot_font = _hb_ot_font_create (font);
645
18
  if (unlikely (!ot_font))
646
0
    return;
647
648
18
  hb_font_set_funcs (font,
649
18
         _hb_ot_get_font_funcs (),
650
18
         ot_font,
651
18
         _hb_ot_font_destroy);
652
18
}
653
654
#endif