diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 3fb40e109..617aaa7fa 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -479,8 +479,6 @@ hb_ft_paint_glyph_colr (hb_font_t *font, extents.ymin, extents.xmax, extents.ymax); - - hb_paint_funcs_destroy (extents_funcs); } paint_funcs->push_root_transform (paint_data, font); diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index c14033233..96e9430e9 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -2008,8 +2008,6 @@ struct COLR extents->width = e.xmax - e.xmin; extents->height = e.ymin - e.ymax; - hb_paint_funcs_destroy (extents_funcs); - return true; } @@ -2067,8 +2065,6 @@ struct COLR extents.xmax, extents.ymax); - hb_paint_funcs_destroy (extents_funcs); - c.funcs->push_root_transform (c.data, font); pop_clip_first = false; diff --git a/src/hb-paint-extents.cc b/src/hb-paint-extents.cc index a14f756e3..01151ecf1 100644 --- a/src/hb-paint-extents.cc +++ b/src/hb-paint-extents.cc @@ -122,6 +122,7 @@ static struct hb_draw_extents_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t< static hb_draw_funcs_t *create () { hb_draw_funcs_t *funcs = hb_draw_funcs_create (); + hb_draw_funcs_set_move_to_func (funcs, hb_draw_extents_move_to, nullptr, nullptr); hb_draw_funcs_set_line_to_func (funcs, hb_draw_extents_line_to, nullptr, nullptr); hb_draw_funcs_set_cubic_to_func (funcs, hb_draw_extents_cubic_to, nullptr, nullptr); @@ -281,23 +282,43 @@ hb_paint_extents_paint_sweep_gradient (hb_paint_funcs_t *funcs HB_UNUSED, c->paint (); } +static inline void free_static_paint_extents_funcs (); + +static struct hb_paint_extents_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t +{ + static hb_paint_funcs_t *create () + { + hb_paint_funcs_t *funcs = hb_paint_funcs_create (); + + hb_paint_funcs_set_push_transform_func (funcs, hb_paint_extents_push_transform, nullptr, nullptr); + hb_paint_funcs_set_pop_transform_func (funcs, hb_paint_extents_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_paint_extents_push_clip_glyph, nullptr, nullptr); + hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_paint_extents_push_clip_rectangle, nullptr, nullptr); + hb_paint_funcs_set_pop_clip_func (funcs, hb_paint_extents_pop_clip, nullptr, nullptr); + hb_paint_funcs_set_push_group_func (funcs, hb_paint_extents_push_group, nullptr, nullptr); + hb_paint_funcs_set_pop_group_func (funcs, hb_paint_extents_pop_group, nullptr, nullptr); + hb_paint_funcs_set_color_func (funcs, hb_paint_extents_paint_color, nullptr, nullptr); + hb_paint_funcs_set_image_func (funcs, hb_paint_extents_paint_image, nullptr, nullptr); + hb_paint_funcs_set_linear_gradient_func (funcs, hb_paint_extents_paint_linear_gradient, nullptr, nullptr); + hb_paint_funcs_set_radial_gradient_func (funcs, hb_paint_extents_paint_radial_gradient, nullptr, nullptr); + hb_paint_funcs_set_sweep_gradient_func (funcs, hb_paint_extents_paint_sweep_gradient, nullptr, nullptr); + + hb_paint_funcs_make_immutable (funcs); + + hb_atexit (free_static_paint_extents_funcs); + + return funcs; + } +} static_paint_extents_funcs; + +static inline +void free_static_paint_extents_funcs () +{ + static_paint_extents_funcs.free_instance (); +} + hb_paint_funcs_t * hb_paint_extents_get_funcs () { - hb_paint_funcs_t *funcs = hb_paint_funcs_create (); - - hb_paint_funcs_set_push_transform_func (funcs, hb_paint_extents_push_transform, nullptr, nullptr); - hb_paint_funcs_set_pop_transform_func (funcs, hb_paint_extents_pop_transform, nullptr, nullptr); - hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_paint_extents_push_clip_glyph, nullptr, nullptr); - hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_paint_extents_push_clip_rectangle, nullptr, nullptr); - hb_paint_funcs_set_pop_clip_func (funcs, hb_paint_extents_pop_clip, nullptr, nullptr); - hb_paint_funcs_set_push_group_func (funcs, hb_paint_extents_push_group, nullptr, nullptr); - hb_paint_funcs_set_pop_group_func (funcs, hb_paint_extents_pop_group, nullptr, nullptr); - hb_paint_funcs_set_color_func (funcs, hb_paint_extents_paint_color, nullptr, nullptr); - hb_paint_funcs_set_image_func (funcs, hb_paint_extents_paint_image, nullptr, nullptr); - hb_paint_funcs_set_linear_gradient_func (funcs, hb_paint_extents_paint_linear_gradient, nullptr, nullptr); - hb_paint_funcs_set_radial_gradient_func (funcs, hb_paint_extents_paint_radial_gradient, nullptr, nullptr); - hb_paint_funcs_set_sweep_gradient_func (funcs, hb_paint_extents_paint_sweep_gradient, nullptr, nullptr); - - return funcs; + return static_paint_extents_funcs.get_unconst (); }