[subset] Correct calculation of max offset; fixes bug where loca would erroneously be short

This commit is contained in:
rsheeter 2019-05-31 15:14:44 -07:00 committed by Behdad Esfahbod
parent 2ad4ba7bc0
commit 49879adbfc
1 changed files with 4 additions and 1 deletions

View File

@ -85,7 +85,7 @@ struct glyf
static bool static bool
_add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets) _add_loca_and_head (hb_subset_plan_t * plan, Iterator padded_offsets)
{ {
unsigned int max_offset = + padded_offsets | hb_reduce (hb_max, 0); unsigned max_offset = + padded_offsets | hb_reduce(hb_add, 0);
unsigned num_offsets = padded_offsets.len () + 1; unsigned num_offsets = padded_offsets.len () + 1;
bool use_short_loca = max_offset < 0x1FFFF; bool use_short_loca = max_offset < 0x1FFFF;
unsigned entry_size = use_short_loca ? 2 : 4; unsigned entry_size = use_short_loca ? 2 : 4;
@ -93,6 +93,8 @@ struct glyf
if (unlikely (!loca_prime_data)) return false; if (unlikely (!loca_prime_data)) return false;
DEBUG_MSG(SUBSET, nullptr, "loca entry_size %d num_offsets %d max_offset %d size %d", entry_size, num_offsets, max_offset, entry_size * num_offsets);
if (use_short_loca) if (use_short_loca)
_write_loca (padded_offsets, 1, hb_array ((HBUINT16*) loca_prime_data, num_offsets)); _write_loca (padded_offsets, 1, hb_array ((HBUINT16*) loca_prime_data, num_offsets));
else else
@ -164,6 +166,7 @@ struct glyf
| hb_map (&SubsetGlyph::padded_size) | hb_map (&SubsetGlyph::padded_size)
; ;
if (c->serializer->in_error ()) return_trace (false);
return_trace (c->serializer->check_success (_add_loca_and_head (c->plan, padded_offsets))); return_trace (c->serializer->check_success (_add_loca_and_head (c->plan, padded_offsets)));
} }