[instancer] always recalculate bounds when --instance option enabled

But don't recompile glyph bytes if pinned at default
This commit is contained in:
Qunxin Liu 2023-01-18 09:52:00 -08:00
parent 1f948e7fd5
commit 2ecb1c31e9
2 changed files with 29 additions and 24 deletions

View File

@ -116,7 +116,7 @@ struct Glyph
hb_bytes_t &dest_bytes /* OUT */) const hb_bytes_t &dest_bytes /* OUT */) const
{ {
GlyphHeader *glyph_header = nullptr; GlyphHeader *glyph_header = nullptr;
if (type != EMPTY && all_points.length > 4) if (!plan->pinned_at_default && type != EMPTY && all_points.length > 4)
{ {
glyph_header = (GlyphHeader *) hb_calloc (1, GlyphHeader::static_size); glyph_header = (GlyphHeader *) hb_calloc (1, GlyphHeader::static_size);
if (unlikely (!glyph_header)) return false; if (unlikely (!glyph_header)) return false;
@ -155,8 +155,9 @@ struct Glyph
plan->head_maxp_info.yMax = hb_max (plan->head_maxp_info.yMax, rounded_yMax); plan->head_maxp_info.yMax = hb_max (plan->head_maxp_info.yMax, rounded_yMax);
} }
/*for empty glyphs: all_points only include phantom points. /* when pinned at default, no need to compile glyph header
*just update metrics and then return */ * and for empty glyphs: all_points only include phantom points.
* just update metrics and then return */
if (!glyph_header) if (!glyph_header)
return true; return true;
@ -188,6 +189,8 @@ struct Glyph
!(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE)) !(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))
type = EMPTY; type = EMPTY;
//dont compile bytes when pinned at default, just recalculate bounds
if (!plan->pinned_at_default) {
switch (type) { switch (type) {
case COMPOSITE: case COMPOSITE:
if (!CompositeGlyph (*header, bytes).compile_bytes_with_deltas (dest_start, if (!CompositeGlyph (*header, bytes).compile_bytes_with_deltas (dest_start,
@ -208,6 +211,7 @@ struct Glyph
dest_end = hb_bytes_t (); dest_end = hb_bytes_t ();
break; break;
} }
}
if (!compile_header_bytes (plan, all_points, dest_start)) if (!compile_header_bytes (plan, all_points, dest_start))
{ {

View File

@ -80,7 +80,7 @@ struct glyf
_populate_subset_glyphs (c->plan, glyphs); _populate_subset_glyphs (c->plan, glyphs);
hb_font_t *font = nullptr; hb_font_t *font = nullptr;
if (!c->plan->pinned_at_default) if (c->plan->normalized_coords)
{ {
font = _create_font_for_instancing (c->plan); font = _create_font_for_instancing (c->plan);
if (unlikely (!font)) return false; if (unlikely (!font)) return false;
@ -108,6 +108,7 @@ struct glyf
if (font) if (font)
{ {
if (!c->plan->pinned_at_default)
_free_compiled_subset_glyphs (&glyphs); _free_compiled_subset_glyphs (&glyphs);
hb_font_destroy (font); hb_font_destroy (font);
} }