[ft] Port ft font funcs to allocated object
This commit is contained in:
parent
da29b43794
commit
7918c261ef
43
src/hb-ft.cc
43
src/hb-ft.cc
@ -380,23 +380,50 @@ hb_ft_get_glyph_from_name (hb_font_t *font HB_UNUSED,
|
||||
}
|
||||
|
||||
|
||||
static hb_font_funcs_t *static_ft_funcs = NULL;
|
||||
|
||||
#ifdef HB_USE_ATEXIT
|
||||
static
|
||||
void free_static_ft_funcs (void)
|
||||
{
|
||||
hb_font_funcs_destroy (static_ft_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref)
|
||||
{
|
||||
static const hb_font_funcs_t ft_ffuncs = {
|
||||
HB_OBJECT_HEADER_STATIC,
|
||||
retry:
|
||||
hb_font_funcs_t *funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ft_funcs);
|
||||
|
||||
true, /* immutable */
|
||||
if (unlikely (!funcs))
|
||||
{
|
||||
funcs = hb_font_funcs_create ();
|
||||
|
||||
{
|
||||
#define HB_FONT_FUNC_IMPLEMENT(name) hb_ft_get_##name,
|
||||
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
|
||||
#undef HB_FONT_FUNC_IMPLEMENT
|
||||
hb_font_funcs_set_glyph_func (funcs, hb_ft_get_glyph, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ft_get_glyph_h_advance, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ft_get_glyph_v_advance, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ft_get_glyph_h_origin, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ft_get_glyph_v_origin, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ft_get_glyph_h_kerning, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ft_get_glyph_v_kerning, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_extents_func (funcs, hb_ft_get_glyph_extents, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ft_get_glyph_contour_point, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_name_func (funcs, hb_ft_get_glyph_name, NULL, NULL);
|
||||
hb_font_funcs_set_glyph_from_name_func (funcs, hb_ft_get_glyph_from_name, NULL, NULL);
|
||||
|
||||
if (!hb_atomic_ptr_cmpexch (&static_ft_funcs, NULL, funcs)) {
|
||||
hb_font_funcs_destroy (funcs);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
#ifdef HB_USE_ATEXIT
|
||||
atexit (free_static_ft_funcs); /* First person registers atexit() callback. */
|
||||
#endif
|
||||
};
|
||||
|
||||
hb_font_set_funcs (font,
|
||||
const_cast<hb_font_funcs_t *> (&ft_ffuncs),
|
||||
funcs,
|
||||
_hb_ft_font_create (ft_face, unref),
|
||||
(hb_destroy_func_t) _hb_ft_font_destroy);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user