jdk
654 строки · 21.9 Кб
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-cff2-table.hh"
42#include "hb-ot-cff1-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
64using hb_ot_font_cmap_cache_t = hb_cache_t<21, 16, 8, true>;
65using hb_ot_font_advance_cache_t = hb_cache_t<24, 16, 8, true>;
66
67#ifndef HB_NO_OT_FONT_CMAP_CACHE
68static hb_user_data_key_t hb_ot_font_cmap_cache_user_data_key;
69#endif
70
71struct hb_ot_font_t
72{
73const hb_ot_face_t *ot_face;
74
75#ifndef HB_NO_OT_FONT_CMAP_CACHE
76hb_ot_font_cmap_cache_t *cmap_cache;
77#endif
78
79/* h_advance caching */
80mutable hb_atomic_int_t cached_coords_serial;
81mutable hb_atomic_ptr_t<hb_ot_font_advance_cache_t> advance_cache;
82};
83
84static hb_ot_font_t *
85_hb_ot_font_create (hb_font_t *font)
86{
87hb_ot_font_t *ot_font = (hb_ot_font_t *) hb_calloc (1, sizeof (hb_ot_font_t));
88if (unlikely (!ot_font))
89return nullptr;
90
91ot_font->ot_face = &font->face->table;
92
93#ifndef HB_NO_OT_FONT_CMAP_CACHE
94// retry:
95auto *cmap_cache = (hb_ot_font_cmap_cache_t *) hb_face_get_user_data (font->face,
96&hb_ot_font_cmap_cache_user_data_key);
97if (!cmap_cache)
98{
99cmap_cache = (hb_ot_font_cmap_cache_t *) hb_malloc (sizeof (hb_ot_font_cmap_cache_t));
100if (unlikely (!cmap_cache)) goto out;
101new (cmap_cache) hb_ot_font_cmap_cache_t ();
102if (unlikely (!hb_face_set_user_data (font->face,
103&hb_ot_font_cmap_cache_user_data_key,
104cmap_cache,
105hb_free,
106false)))
107{
108hb_free (cmap_cache);
109cmap_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}
117}
118out:
119ot_font->cmap_cache = cmap_cache;
120#endif
121
122return ot_font;
123}
124
125static void
126_hb_ot_font_destroy (void *font_data)
127{
128hb_ot_font_t *ot_font = (hb_ot_font_t *) font_data;
129
130auto *cache = ot_font->advance_cache.get_relaxed ();
131hb_free (cache);
132
133hb_free (ot_font);
134}
135
136static hb_bool_t
137hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED,
138void *font_data,
139hb_codepoint_t unicode,
140hb_codepoint_t *glyph,
141void *user_data HB_UNUSED)
142{
143const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
144const hb_ot_face_t *ot_face = ot_font->ot_face;
145hb_ot_font_cmap_cache_t *cmap_cache = nullptr;
146#ifndef HB_NO_OT_FONT_CMAP_CACHE
147cmap_cache = ot_font->cmap_cache;
148#endif
149return ot_face->cmap->get_nominal_glyph (unicode, glyph, cmap_cache);
150}
151
152static unsigned int
153hb_ot_get_nominal_glyphs (hb_font_t *font HB_UNUSED,
154void *font_data,
155unsigned int count,
156const hb_codepoint_t *first_unicode,
157unsigned int unicode_stride,
158hb_codepoint_t *first_glyph,
159unsigned int glyph_stride,
160void *user_data HB_UNUSED)
161{
162const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
163const hb_ot_face_t *ot_face = ot_font->ot_face;
164hb_ot_font_cmap_cache_t *cmap_cache = nullptr;
165#ifndef HB_NO_OT_FONT_CMAP_CACHE
166cmap_cache = ot_font->cmap_cache;
167#endif
168return ot_face->cmap->get_nominal_glyphs (count,
169first_unicode, unicode_stride,
170first_glyph, glyph_stride,
171cmap_cache);
172}
173
174static hb_bool_t
175hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED,
176void *font_data,
177hb_codepoint_t unicode,
178hb_codepoint_t variation_selector,
179hb_codepoint_t *glyph,
180void *user_data HB_UNUSED)
181{
182const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
183const hb_ot_face_t *ot_face = ot_font->ot_face;
184hb_ot_font_cmap_cache_t *cmap_cache = nullptr;
185#ifndef HB_NO_OT_FONT_CMAP_CACHE
186cmap_cache = ot_font->cmap_cache;
187#endif
188return ot_face->cmap->get_variation_glyph (unicode,
189variation_selector, glyph,
190cmap_cache);
191}
192
193static void
194hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
195unsigned count,
196const hb_codepoint_t *first_glyph,
197unsigned glyph_stride,
198hb_position_t *first_advance,
199unsigned advance_stride,
200void *user_data HB_UNUSED)
201{
202
203const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
204const hb_ot_face_t *ot_face = ot_font->ot_face;
205const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx;
206
207hb_position_t *orig_first_advance = first_advance;
208
209#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
210const OT::HVAR &HVAR = *hmtx.var_table;
211const OT::VariationStore &varStore = &HVAR + HVAR.varStore;
212OT::VariationStore::cache_t *varStore_cache = font->num_coords * count >= 128 ? varStore.create_cache () : nullptr;
213
214bool use_cache = font->num_coords;
215#else
216OT::VariationStore::cache_t *varStore_cache = nullptr;
217bool use_cache = false;
218#endif
219
220hb_ot_font_advance_cache_t *cache = nullptr;
221if (use_cache)
222{
223retry:
224cache = ot_font->advance_cache.get_acquire ();
225if (unlikely (!cache))
226{
227cache = (hb_ot_font_advance_cache_t *) hb_malloc (sizeof (hb_ot_font_advance_cache_t));
228if (unlikely (!cache))
229{
230use_cache = false;
231goto out;
232}
233new (cache) hb_ot_font_advance_cache_t;
234
235if (unlikely (!ot_font->advance_cache.cmpexch (nullptr, cache)))
236{
237hb_free (cache);
238goto retry;
239}
240ot_font->cached_coords_serial.set_release (font->serial_coords);
241}
242}
243out:
244
245if (!use_cache)
246{
247for (unsigned int i = 0; i < count; i++)
248{
249*first_advance = font->em_scale_x (hmtx.get_advance_with_var_unscaled (*first_glyph, font, varStore_cache));
250first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
251first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
252}
253}
254else
255{ /* Use cache. */
256if (ot_font->cached_coords_serial.get_acquire () != (int) font->serial_coords)
257{
258ot_font->advance_cache->clear ();
259ot_font->cached_coords_serial.set_release (font->serial_coords);
260}
261
262for (unsigned int i = 0; i < count; i++)
263{
264hb_position_t v;
265unsigned cv;
266if (ot_font->advance_cache->get (*first_glyph, &cv))
267v = cv;
268else
269{
270v = hmtx.get_advance_with_var_unscaled (*first_glyph, font, varStore_cache);
271ot_font->advance_cache->set (*first_glyph, v);
272}
273*first_advance = font->em_scale_x (v);
274first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
275first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
276}
277}
278
279#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
280OT::VariationStore::destroy_cache (varStore_cache);
281#endif
282
283if (font->x_strength && !font->embolden_in_place)
284{
285/* Emboldening. */
286hb_position_t x_strength = font->x_scale >= 0 ? font->x_strength : -font->x_strength;
287first_advance = orig_first_advance;
288for (unsigned int i = 0; i < count; i++)
289{
290*first_advance += *first_advance ? x_strength : 0;
291first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
292}
293}
294}
295
296#ifndef HB_NO_VERTICAL
297static void
298hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
299unsigned count,
300const hb_codepoint_t *first_glyph,
301unsigned glyph_stride,
302hb_position_t *first_advance,
303unsigned advance_stride,
304void *user_data HB_UNUSED)
305{
306const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
307const hb_ot_face_t *ot_face = ot_font->ot_face;
308const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
309
310hb_position_t *orig_first_advance = first_advance;
311
312if (vmtx.has_data ())
313{
314#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
315const OT::VVAR &VVAR = *vmtx.var_table;
316const OT::VariationStore &varStore = &VVAR + VVAR.varStore;
317OT::VariationStore::cache_t *varStore_cache = font->num_coords ? varStore.create_cache () : nullptr;
318#else
319OT::VariationStore::cache_t *varStore_cache = nullptr;
320#endif
321
322for (unsigned int i = 0; i < count; i++)
323{
324*first_advance = font->em_scale_y (-(int) vmtx.get_advance_with_var_unscaled (*first_glyph, font, varStore_cache));
325first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
326first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
327}
328
329#if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_ADVANCE_CACHE)
330OT::VariationStore::destroy_cache (varStore_cache);
331#endif
332}
333else
334{
335hb_font_extents_t font_extents;
336font->get_h_extents_with_fallback (&font_extents);
337hb_position_t advance = -(font_extents.ascender - font_extents.descender);
338
339for (unsigned int i = 0; i < count; i++)
340{
341*first_advance = advance;
342first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
343first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
344}
345}
346
347if (font->y_strength && !font->embolden_in_place)
348{
349/* Emboldening. */
350hb_position_t y_strength = font->y_scale >= 0 ? font->y_strength : -font->y_strength;
351first_advance = orig_first_advance;
352for (unsigned int i = 0; i < count; i++)
353{
354*first_advance += *first_advance ? y_strength : 0;
355first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
356}
357}
358}
359#endif
360
361#ifndef HB_NO_VERTICAL
362static hb_bool_t
363hb_ot_get_glyph_v_origin (hb_font_t *font,
364void *font_data,
365hb_codepoint_t glyph,
366hb_position_t *x,
367hb_position_t *y,
368void *user_data HB_UNUSED)
369{
370const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
371const hb_ot_face_t *ot_face = ot_font->ot_face;
372
373*x = font->get_glyph_h_advance (glyph) / 2;
374
375const OT::VORG &VORG = *ot_face->VORG;
376if (VORG.has_data ())
377{
378float delta = 0;
379
380#ifndef HB_NO_VAR
381const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
382const OT::VVAR &VVAR = *vmtx.var_table;
383if (font->num_coords)
384VVAR.get_vorg_delta_unscaled (glyph,
385font->coords, font->num_coords,
386&delta);
387#endif
388
389*y = font->em_scalef_y (VORG.get_y_origin (glyph) + delta);
390return true;
391}
392
393hb_glyph_extents_t extents = {0};
394if (ot_face->glyf->get_extents (font, glyph, &extents))
395{
396const OT::vmtx_accelerator_t &vmtx = *ot_face->vmtx;
397int tsb = 0;
398if (vmtx.get_leading_bearing_with_var_unscaled (font, glyph, &tsb))
399{
400*y = extents.y_bearing + font->em_scale_y (tsb);
401return true;
402}
403
404hb_font_extents_t font_extents;
405font->get_h_extents_with_fallback (&font_extents);
406hb_position_t advance = font_extents.ascender - font_extents.descender;
407int diff = advance - -extents.height;
408*y = extents.y_bearing + (diff >> 1);
409return true;
410}
411
412hb_font_extents_t font_extents;
413font->get_h_extents_with_fallback (&font_extents);
414*y = font_extents.ascender;
415
416return true;
417}
418#endif
419
420static hb_bool_t
421hb_ot_get_glyph_extents (hb_font_t *font,
422void *font_data,
423hb_codepoint_t glyph,
424hb_glyph_extents_t *extents,
425void *user_data HB_UNUSED)
426{
427const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
428const hb_ot_face_t *ot_face = ot_font->ot_face;
429
430#if !defined(HB_NO_OT_FONT_BITMAP) && !defined(HB_NO_COLOR)
431if (ot_face->sbix->get_extents (font, glyph, extents)) return true;
432if (ot_face->CBDT->get_extents (font, glyph, extents)) return true;
433#endif
434#if !defined(HB_NO_COLOR) && !defined(HB_NO_PAINT)
435if (ot_face->COLR->get_extents (font, glyph, extents)) return true;
436#endif
437if (ot_face->glyf->get_extents (font, glyph, extents)) return true;
438#ifndef HB_NO_OT_FONT_CFF
439if (ot_face->cff2->get_extents (font, glyph, extents)) return true;
440if (ot_face->cff1->get_extents (font, glyph, extents)) return true;
441#endif
442
443return false;
444}
445
446#ifndef HB_NO_OT_FONT_GLYPH_NAMES
447static hb_bool_t
448hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED,
449void *font_data,
450hb_codepoint_t glyph,
451char *name, unsigned int size,
452void *user_data HB_UNUSED)
453{
454const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
455const hb_ot_face_t *ot_face = ot_font->ot_face;
456
457if (ot_face->post->get_glyph_name (glyph, name, size)) return true;
458#ifndef HB_NO_OT_FONT_CFF
459if (ot_face->cff1->get_glyph_name (glyph, name, size)) return true;
460#endif
461return false;
462}
463static hb_bool_t
464hb_ot_get_glyph_from_name (hb_font_t *font HB_UNUSED,
465void *font_data,
466const char *name, int len,
467hb_codepoint_t *glyph,
468void *user_data HB_UNUSED)
469{
470const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
471const hb_ot_face_t *ot_face = ot_font->ot_face;
472
473if (ot_face->post->get_glyph_from_name (name, len, glyph)) return true;
474#ifndef HB_NO_OT_FONT_CFF
475if (ot_face->cff1->get_glyph_from_name (name, len, glyph)) return true;
476#endif
477return false;
478}
479#endif
480
481static hb_bool_t
482hb_ot_get_font_h_extents (hb_font_t *font,
483void *font_data HB_UNUSED,
484hb_font_extents_t *metrics,
485void *user_data HB_UNUSED)
486{
487bool ret = _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER, &metrics->ascender) &&
488_hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER, &metrics->descender) &&
489_hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP, &metrics->line_gap);
490
491/* Embolden */
492int y_shift = font->y_strength;
493if (font->y_scale < 0) y_shift = -y_shift;
494metrics->ascender += y_shift;
495
496return ret;
497}
498
499#ifndef HB_NO_VERTICAL
500static hb_bool_t
501hb_ot_get_font_v_extents (hb_font_t *font,
502void *font_data HB_UNUSED,
503hb_font_extents_t *metrics,
504void *user_data HB_UNUSED)
505{
506return _hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_ASCENDER, &metrics->ascender) &&
507_hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_DESCENDER, &metrics->descender) &&
508_hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_LINE_GAP, &metrics->line_gap);
509}
510#endif
511
512#ifndef HB_NO_DRAW
513static void
514hb_ot_draw_glyph (hb_font_t *font,
515void *font_data HB_UNUSED,
516hb_codepoint_t glyph,
517hb_draw_funcs_t *draw_funcs, void *draw_data,
518void *user_data)
519{
520bool embolden = font->x_strength || font->y_strength;
521hb_outline_t outline;
522
523{ // Need draw_session to be destructed before emboldening.
524hb_draw_session_t draw_session (embolden ? hb_outline_recording_pen_get_funcs () : draw_funcs,
525embolden ? &outline : draw_data, font->slant_xy);
526if (!font->face->table.glyf->get_path (font, glyph, draw_session))
527#ifndef HB_NO_CFF
528if (!font->face->table.cff2->get_path (font, glyph, draw_session))
529if (!font->face->table.cff1->get_path (font, glyph, draw_session))
530#endif
531{}
532}
533
534if (embolden)
535{
536float x_shift = font->embolden_in_place ? 0 : (float) font->x_strength / 2;
537float y_shift = (float) font->y_strength / 2;
538if (font->x_scale < 0) x_shift = -x_shift;
539if (font->y_scale < 0) y_shift = -y_shift;
540outline.embolden (font->x_strength, font->y_strength,
541x_shift, y_shift);
542
543outline.replay (draw_funcs, draw_data);
544}
545}
546#endif
547
548#ifndef HB_NO_PAINT
549static void
550hb_ot_paint_glyph (hb_font_t *font,
551void *font_data,
552hb_codepoint_t glyph,
553hb_paint_funcs_t *paint_funcs, void *paint_data,
554unsigned int palette,
555hb_color_t foreground,
556void *user_data)
557{
558#ifndef HB_NO_COLOR
559if (font->face->table.COLR->paint_glyph (font, glyph, paint_funcs, paint_data, palette, foreground)) return;
560if (font->face->table.SVG->paint_glyph (font, glyph, paint_funcs, paint_data)) return;
561#ifndef HB_NO_OT_FONT_BITMAP
562if (font->face->table.CBDT->paint_glyph (font, glyph, paint_funcs, paint_data)) return;
563if (font->face->table.sbix->paint_glyph (font, glyph, paint_funcs, paint_data)) return;
564#endif
565#endif
566if (font->face->table.glyf->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return;
567#ifndef HB_NO_CFF
568if (font->face->table.cff2->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return;
569if (font->face->table.cff1->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return;
570#endif
571}
572#endif
573
574static inline void free_static_ot_funcs ();
575
576static struct hb_ot_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ot_font_funcs_lazy_loader_t>
577{
578static hb_font_funcs_t *create ()
579{
580hb_font_funcs_t *funcs = hb_font_funcs_create ();
581
582hb_font_funcs_set_nominal_glyph_func (funcs, hb_ot_get_nominal_glyph, nullptr, nullptr);
583hb_font_funcs_set_nominal_glyphs_func (funcs, hb_ot_get_nominal_glyphs, nullptr, nullptr);
584hb_font_funcs_set_variation_glyph_func (funcs, hb_ot_get_variation_glyph, nullptr, nullptr);
585
586hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, nullptr, nullptr);
587hb_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#ifndef HB_NO_VERTICAL
591hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, nullptr, nullptr);
592hb_font_funcs_set_glyph_v_advances_func (funcs, hb_ot_get_glyph_v_advances, nullptr, nullptr);
593hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, nullptr, nullptr);
594#endif
595
596#ifndef HB_NO_DRAW
597hb_font_funcs_set_draw_glyph_func (funcs, hb_ot_draw_glyph, nullptr, nullptr);
598#endif
599
600#ifndef HB_NO_PAINT
601hb_font_funcs_set_paint_glyph_func (funcs, hb_ot_paint_glyph, nullptr, nullptr);
602#endif
603
604hb_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#ifndef HB_NO_OT_FONT_GLYPH_NAMES
608hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, nullptr, nullptr);
609hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr);
610#endif
611
612hb_font_funcs_make_immutable (funcs);
613
614hb_atexit (free_static_ot_funcs);
615
616return funcs;
617}
618} static_ot_funcs;
619
620static inline
621void free_static_ot_funcs ()
622{
623static_ot_funcs.free_instance ();
624}
625
626static hb_font_funcs_t *
627_hb_ot_get_font_funcs ()
628{
629return static_ot_funcs.get_unconst ();
630}
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**/
641void
642hb_ot_font_set_funcs (hb_font_t *font)
643{
644hb_ot_font_t *ot_font = _hb_ot_font_create (font);
645if (unlikely (!ot_font))
646return;
647
648hb_font_set_funcs (font,
649_hb_ot_get_font_funcs (),
650ot_font,
651_hb_ot_font_destroy);
652}
653
654#endif
655