[ot-font] Make everything (cmap/metrics) lazy

This commit is contained in:
Behdad Esfahbod 2018-08-25 23:19:34 -07:00
parent 62fc54725a
commit f36ae6f8a8
2 changed files with 31 additions and 25 deletions

View File

@ -763,6 +763,10 @@ struct hb_lazy_loader_t : hb_data_wrapper_t<Data, WheresData>
} }
return p; return p;
} }
inline Stored * get_stored_relaxed (void) const
{
return this->instance.get_relaxed ();
}
inline void set_stored (Stored *instance_) inline void set_stored (Stored *instance_)
{ {
@ -776,6 +780,7 @@ struct hb_lazy_loader_t : hb_data_wrapper_t<Data, WheresData>
} }
inline const Returned * get (void) const { return Funcs::convert (get_stored ()); } inline const Returned * get (void) const { return Funcs::convert (get_stored ()); }
inline const Returned * get_relaxed (void) const { return Funcs::convert (get_stored_relaxed ()); }
inline Returned * get_unconst (void) const { return const_cast<Returned *> (Funcs::convert (get_stored ())); } inline Returned * get_unconst (void) const { return const_cast<Returned *> (Funcs::convert (get_stored ())); }
/* To be possibly overloaded by subclasses. */ /* To be possibly overloaded by subclasses. */

View File

@ -44,11 +44,10 @@ struct hb_ot_font_t
{ {
inline void init (hb_face_t *face) inline void init (hb_face_t *face)
{ {
cmap.init (face);
h_metrics.init (face);
v_metrics.init (face);
this->face = face; this->face = face;
cmap.init ();
h_metrics.init ();
v_metrics.init ();
glyf.init (); glyf.init ();
cbdt.init (); cbdt.init ();
post.init (); post.init ();
@ -59,22 +58,20 @@ struct hb_ot_font_t
cmap.fini (); cmap.fini ();
h_metrics.fini (); h_metrics.fini ();
v_metrics.fini (); v_metrics.fini ();
glyf.fini (); glyf.fini ();
cbdt.fini (); cbdt.fini ();
post.fini (); post.fini ();
kern.fini (); kern.fini ();
} }
OT::cmap::accelerator_t cmap;
OT::hmtx::accelerator_t h_metrics;
OT::vmtx::accelerator_t v_metrics;
hb_face_t *face; /* MUST be JUST before the lazy loaders. */ hb_face_t *face; /* MUST be JUST before the lazy loaders. */
hb_face_lazy_loader_t<1, OT::glyf::accelerator_t> glyf; hb_face_lazy_loader_t<1, OT::cmap::accelerator_t> cmap;
hb_face_lazy_loader_t<2, OT::CBDT::accelerator_t> cbdt; hb_face_lazy_loader_t<2, OT::hmtx::accelerator_t> h_metrics;
hb_face_lazy_loader_t<3, OT::post::accelerator_t> post; hb_face_lazy_loader_t<3, OT::vmtx::accelerator_t> v_metrics;
hb_face_lazy_loader_t<4, OT::kern::accelerator_t> kern; hb_face_lazy_loader_t<4, OT::glyf::accelerator_t> glyf;
hb_face_lazy_loader_t<5, OT::CBDT::accelerator_t> cbdt;
hb_face_lazy_loader_t<6, OT::post::accelerator_t> post;
hb_face_lazy_loader_t<7, OT::kern::accelerator_t> kern;
}; };
@ -111,7 +108,7 @@ hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED,
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
return ot_font->cmap.get_nominal_glyph (unicode, glyph); return ot_font->cmap.get_relaxed()->get_nominal_glyph (unicode, glyph);
} }
static hb_bool_t static hb_bool_t
@ -123,7 +120,7 @@ hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
return ot_font->cmap.get_variation_glyph (unicode, variation_selector, glyph); return ot_font->cmap.get_relaxed ()->get_variation_glyph (unicode, variation_selector, glyph);
} }
static hb_position_t static hb_position_t
@ -133,7 +130,7 @@ hb_ot_get_glyph_h_advance (hb_font_t *font,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
return font->em_scale_x (ot_font->h_metrics.get_advance (glyph, font)); return font->em_scale_x (ot_font->h_metrics.get_relaxed ()->get_advance (glyph, font));
} }
static hb_position_t static hb_position_t
@ -143,7 +140,7 @@ hb_ot_get_glyph_v_advance (hb_font_t *font,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph, font)); return font->em_scale_y (-(int) ot_font->v_metrics.get_relaxed ()->get_advance (glyph, font));
} }
static hb_position_t static hb_position_t
@ -205,11 +202,11 @@ hb_ot_get_font_h_extents (hb_font_t *font,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
metrics->ascender = font->em_scale_y (ot_font->h_metrics.ascender); metrics->ascender = font->em_scale_y (ot_font->h_metrics.get_relaxed ()->ascender);
metrics->descender = font->em_scale_y (ot_font->h_metrics.descender); metrics->descender = font->em_scale_y (ot_font->h_metrics.get_relaxed ()->descender);
metrics->line_gap = font->em_scale_y (ot_font->h_metrics.line_gap); metrics->line_gap = font->em_scale_y (ot_font->h_metrics.get_relaxed ()->line_gap);
// TODO Hook up variations. // TODO Hook up variations.
return ot_font->h_metrics.has_font_extents; return ot_font->h_metrics.get_relaxed ()->has_font_extents;
} }
static hb_bool_t static hb_bool_t
@ -219,11 +216,11 @@ hb_ot_get_font_v_extents (hb_font_t *font,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
metrics->ascender = font->em_scale_x (ot_font->v_metrics.ascender); metrics->ascender = font->em_scale_x (ot_font->v_metrics.get_relaxed ()->ascender);
metrics->descender = font->em_scale_x (ot_font->v_metrics.descender); metrics->descender = font->em_scale_x (ot_font->v_metrics.get_relaxed ()->descender);
metrics->line_gap = font->em_scale_x (ot_font->v_metrics.line_gap); metrics->line_gap = font->em_scale_x (ot_font->v_metrics.get_relaxed ()->line_gap);
// TODO Hook up variations. // TODO Hook up variations.
return ot_font->v_metrics.has_font_extents; return ot_font->v_metrics.get_relaxed ()->has_font_extents;
} }
#ifdef HB_USE_ATEXIT #ifdef HB_USE_ATEXIT
@ -288,6 +285,10 @@ hb_ot_font_set_funcs (hb_font_t *font)
if (unlikely (!ot_font)) if (unlikely (!ot_font))
return; return;
ot_font->cmap.get ();
ot_font->h_metrics.get ();
ot_font->v_metrics.get ();
hb_font_set_funcs (font, hb_font_set_funcs (font,
_hb_ot_get_font_funcs (), _hb_ot_get_font_funcs (),
ot_font, ot_font,