[glyf] Add _create_font_for_instancing

This commit is contained in:
Behdad Esfahbod 2022-11-22 15:22:25 -07:00
parent 40634ceeb0
commit 7560930070
1 changed files with 18 additions and 6 deletions

View File

@ -110,6 +110,9 @@ struct glyf
_populate_subset_glyphs (const hb_subset_plan_t *plan, _populate_subset_glyphs (const hb_subset_plan_t *plan,
hb_vector_t<glyf_impl::SubsetGlyph> &glyphs /* OUT */) const; hb_vector_t<glyf_impl::SubsetGlyph> &glyphs /* OUT */) const;
hb_font_t *
_create_font_for_instancing (const hb_subset_plan_t *plan) const;
bool bool
_compile_subset_glyphs_with_deltas (const hb_subset_plan_t *plan, _compile_subset_glyphs_with_deltas (const hb_subset_plan_t *plan,
hb_vector_t<glyf_impl::SubsetGlyph> *glyphs /* OUT */) const; hb_vector_t<glyf_impl::SubsetGlyph> *glyphs /* OUT */) const;
@ -407,17 +410,15 @@ glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan,
} }
} }
inline bool inline hb_font_t *
glyf::_compile_subset_glyphs_with_deltas (const hb_subset_plan_t *plan, glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const
hb_vector_t<glyf_impl::SubsetGlyph> *glyphs /* OUT */) const
{ {
OT::glyf_accelerator_t glyf (plan->source);
hb_font_t *font = hb_font_create (plan->source); hb_font_t *font = hb_font_create (plan->source);
if (unlikely (font == hb_font_get_empty ())) return false; if (unlikely (font == hb_font_get_empty ())) return nullptr;
hb_vector_t<hb_variation_t> vars; hb_vector_t<hb_variation_t> vars;
if (unlikely (!vars.alloc (plan->user_axes_location->get_population ()))) if (unlikely (!vars.alloc (plan->user_axes_location->get_population ())))
return false; return nullptr;
for (auto _ : *plan->user_axes_location) for (auto _ : *plan->user_axes_location)
{ {
@ -428,6 +429,17 @@ glyf::_compile_subset_glyphs_with_deltas (const hb_subset_plan_t *plan,
} }
hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location->get_population ()); hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location->get_population ());
return font;
}
inline bool
glyf::_compile_subset_glyphs_with_deltas (const hb_subset_plan_t *plan,
hb_vector_t<glyf_impl::SubsetGlyph> *glyphs /* OUT */) const
{
hb_font_t *font = _create_font_for_instancing (plan);
if (unlikely (!font)) return false;
OT::glyf_accelerator_t glyf (plan->source);
for (auto& subset_glyph : *glyphs) for (auto& subset_glyph : *glyphs)
{ {
if (!const_cast<glyf_impl::SubsetGlyph &> (subset_glyph).compile_bytes_with_deltas (plan, font, glyf)) if (!const_cast<glyf_impl::SubsetGlyph &> (subset_glyph).compile_bytes_with_deltas (plan, font, glyf))