[glyf] Move instanciation to serialize()
This commit is contained in:
parent
d8d881f22d
commit
299ec902eb
|
@ -21,10 +21,18 @@ struct SubsetGlyph
|
|||
|
||||
bool serialize (hb_serialize_context_t *c,
|
||||
bool use_short_loca,
|
||||
const hb_subset_plan_t *plan) const
|
||||
const hb_subset_plan_t *plan,
|
||||
hb_font_t *font)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
|
||||
if (font)
|
||||
{
|
||||
const OT::glyf_accelerator_t &glyf = *font->face->table.glyf;
|
||||
if (!this->compile_bytes_with_deltas (plan, font, glyf))
|
||||
return_trace (false);
|
||||
}
|
||||
|
||||
hb_bytes_t dest_glyph = dest_start.copy (c);
|
||||
dest_glyph = hb_bytes_t (&dest_glyph, dest_glyph.length + dest_end.copy (c).length);
|
||||
unsigned int pad_length = use_short_loca ? padding () : 0;
|
||||
|
|
|
@ -42,11 +42,15 @@ struct glyf
|
|||
bool serialize (hb_serialize_context_t *c,
|
||||
Iterator it,
|
||||
bool use_short_loca,
|
||||
const hb_subset_plan_t *plan)
|
||||
const hb_subset_plan_t *plan,
|
||||
hb_font_t *font)
|
||||
{
|
||||
TRACE_SERIALIZE (this);
|
||||
|
||||
unsigned init_len = c->length ();
|
||||
for (const auto &_ : it) _.serialize (c, use_short_loca, plan);
|
||||
for (auto &_ : it)
|
||||
if (unlikely (!_.serialize (c, use_short_loca, plan, font)))
|
||||
return false;
|
||||
|
||||
/* As a special case when all glyph in the font are empty, add a zero byte
|
||||
* to the table, so that OTS doesn’t reject it, and to make the table work
|
||||
|
@ -74,10 +78,11 @@ struct glyf
|
|||
hb_vector_t<glyf_impl::SubsetGlyph> glyphs;
|
||||
_populate_subset_glyphs (c->plan, glyphs);
|
||||
|
||||
hb_font_t *font = nullptr;
|
||||
if (!c->plan->pinned_at_default)
|
||||
{
|
||||
if (!_compile_subset_glyphs_with_deltas (c->plan, &glyphs))
|
||||
return_trace (false);
|
||||
font = _create_font_for_instancing (c->plan);
|
||||
if (unlikely (!font)) return false;
|
||||
}
|
||||
|
||||
auto padded_offsets =
|
||||
|
@ -89,7 +94,7 @@ struct glyf
|
|||
bool use_short_loca = max_offset < 0x1FFFF;
|
||||
|
||||
|
||||
glyf_prime->serialize (c->serializer, hb_iter (glyphs), use_short_loca, c->plan);
|
||||
glyf_prime->serialize (c->serializer, glyphs.writer (), use_short_loca, c->plan, font);
|
||||
if (!use_short_loca) {
|
||||
padded_offsets =
|
||||
+ hb_iter (glyphs)
|
||||
|
@ -97,13 +102,15 @@ struct glyf
|
|||
;
|
||||
}
|
||||
|
||||
|
||||
if (!c->plan->pinned_at_default)
|
||||
if (font)
|
||||
_free_compiled_subset_glyphs (&glyphs);
|
||||
|
||||
if (unlikely (c->serializer->in_error ())) return_trace (false);
|
||||
return_trace (c->serializer->check_success (glyf_impl::_add_loca_and_head (c->plan,
|
||||
padded_offsets,
|
||||
use_short_loca)));
|
||||
|
||||
hb_font_destroy (font);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -113,10 +120,6 @@ struct glyf
|
|||
hb_font_t *
|
||||
_create_font_for_instancing (const hb_subset_plan_t *plan) const;
|
||||
|
||||
bool
|
||||
_compile_subset_glyphs_with_deltas (const hb_subset_plan_t *plan,
|
||||
hb_vector_t<glyf_impl::SubsetGlyph> *glyphs /* OUT */) const;
|
||||
|
||||
void _free_compiled_subset_glyphs (hb_vector_t<glyf_impl::SubsetGlyph> *glyphs) const
|
||||
{
|
||||
for (auto _ : *glyphs)
|
||||
|
@ -432,27 +435,6 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const
|
|||
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;
|
||||
|
||||
const OT::glyf_accelerator_t &glyf = *plan->source->table.glyf;
|
||||
for (auto& subset_glyph : *glyphs)
|
||||
{
|
||||
if (!const_cast<glyf_impl::SubsetGlyph &> (subset_glyph).compile_bytes_with_deltas (plan, font, glyf))
|
||||
{
|
||||
hb_font_destroy (font);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
hb_font_destroy (font);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace OT */
|
||||
|
||||
|
|
Loading…
Reference in New Issue