[paint-extents] Lazy-load draw-funcs

This commit is contained in:
Behdad Esfahbod 2022-12-24 11:37:59 -07:00
parent 11036ed71e
commit 2c0ab34d03
2 changed files with 46 additions and 9 deletions

View File

@ -321,6 +321,22 @@ struct hb_unicode_funcs_lazy_loader_t : hb_lazy_loader_t<hb_unicode_funcs_t, Sub
static const hb_unicode_funcs_t *get_null ()
{ return hb_unicode_funcs_get_empty (); }
};
template <typename Subclass>
struct hb_draw_funcs_lazy_loader_t : hb_lazy_loader_t<hb_draw_funcs_t, Subclass>
{
static void destroy (hb_draw_funcs_t *p)
{ hb_draw_funcs_destroy (p); }
static const hb_draw_funcs_t *get_null ()
{ return hb_draw_funcs_get_empty (); }
};
template <typename Subclass>
struct hb_paint_funcs_lazy_loader_t : hb_lazy_loader_t<hb_paint_funcs_t, Subclass>
{
static void destroy (hb_paint_funcs_t *p)
{ hb_paint_funcs_destroy (p); }
static const hb_paint_funcs_t *get_null ()
{ return hb_paint_funcs_get_empty (); }
};
#endif /* HB_MACHINERY_HH */

View File

@ -25,6 +25,7 @@
#include "hb.hh"
#include "hb-paint-extents.hh"
#include "hb-draw.h"
#include "hb-machinery.hh"
/*
* This file implements bounds-extraction as well as boundedness
@ -114,14 +115,35 @@ hb_draw_extents_cubic_to (hb_draw_funcs_t *dfuncs,
add_point (extents, to_x, to_y);
}
static hb_draw_funcs_t *
hb_draw_extent_get_funcs ()
static inline void free_static_draw_extents_funcs ();
static struct hb_draw_extents_funcs_lazy_loader_t : hb_draw_funcs_lazy_loader_t<hb_draw_extents_funcs_lazy_loader_t>
{
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);
return funcs;
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);
hb_draw_funcs_make_immutable (funcs);
hb_atexit (free_static_draw_extents_funcs);
return funcs;
}
} static_draw_extents_funcs;
static inline
void free_static_draw_extents_funcs ()
{
static_draw_extents_funcs.free_instance ();
}
static hb_draw_funcs_t *
hb_draw_extents_get_funcs ()
{
return static_draw_extents_funcs.get_unconst ();
}
static void
@ -134,9 +156,8 @@ hb_paint_extents_push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
hb_paint_extents_context_t *c = (hb_paint_extents_context_t *) paint_data;
hb_extents_t extents;
hb_draw_funcs_t *draw_extent_funcs = hb_draw_extent_get_funcs ();
hb_draw_funcs_t *draw_extent_funcs = hb_draw_extents_get_funcs ();
hb_font_draw_glyph (font, glyph, draw_extent_funcs, &extents);
hb_draw_funcs_destroy (draw_extent_funcs);
c->push_clip (extents);
}