[subset] Compute num_glyphs during subset plan construction.
Update maxp to use the correct num glyphs.
This commit is contained in:
parent
ccc59dc612
commit
2da1654aef
@ -105,7 +105,7 @@ struct maxp
|
||||
}
|
||||
maxp *maxp_prime = (maxp *) hb_blob_get_data (maxp_prime_blob, nullptr);
|
||||
|
||||
maxp_prime->set_num_glyphs (plan->glyphs.length);
|
||||
maxp_prime->set_num_glyphs (plan->num_glyphs);
|
||||
if (plan->drop_hints)
|
||||
drop_hint_fields (plan, maxp_prime);
|
||||
|
||||
|
@ -119,13 +119,9 @@ _calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf,
|
||||
hb_vector_t<unsigned int> *instruction_ranges /* OUT */)
|
||||
{
|
||||
unsigned int total = 0;
|
||||
hb_codepoint_t max_new_gid = 0;
|
||||
for (unsigned int i = 0; i < plan->glyphs.length; i++)
|
||||
{
|
||||
hb_codepoint_t next_glyph = plan->glyphs[i];
|
||||
hb_codepoint_t new_gid_for_next_glyph;
|
||||
if (plan->new_gid_for_old_gid (next_glyph, &new_gid_for_next_glyph))
|
||||
max_new_gid = MAX (max_new_gid, new_gid_for_next_glyph);
|
||||
|
||||
unsigned int start_offset, end_offset;
|
||||
if (unlikely (!(glyf.get_offsets (next_glyph, &start_offset, &end_offset) &&
|
||||
@ -156,7 +152,7 @@ _calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf,
|
||||
|
||||
*glyf_size = total;
|
||||
loca_data->is_short = (total <= 131070);
|
||||
loca_data->size = (max_new_gid + 2)
|
||||
loca_data->size = (plan->num_glyphs + 1)
|
||||
* (loca_data->is_short ? sizeof (OT::HBUINT16) : sizeof (OT::HBUINT32));
|
||||
|
||||
DEBUG_MSG(SUBSET, nullptr, "preparing to subset glyf: final size %d, loca size %d, using %s loca",
|
||||
|
@ -158,7 +158,8 @@ _populate_gids_to_retain (hb_face_t *face,
|
||||
static void
|
||||
_create_old_gid_to_new_gid_map (bool retain_gids,
|
||||
const hb_vector_t<hb_codepoint_t> &glyphs,
|
||||
hb_map_t *glyph_map)
|
||||
hb_map_t *glyph_map, /* OUT */
|
||||
unsigned int *num_glyphs /* OUT */)
|
||||
{
|
||||
for (unsigned int i = 0; i < glyphs.length; i++) {
|
||||
if (!retain_gids)
|
||||
@ -166,6 +167,14 @@ _create_old_gid_to_new_gid_map (bool retain_gids,
|
||||
else
|
||||
glyph_map->set (glyphs[i], glyphs[i]);
|
||||
}
|
||||
if (!retain_gids || glyphs.length == 0)
|
||||
{
|
||||
*num_glyphs = glyphs.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
*num_glyphs = glyphs[glyphs.length - 1] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +211,8 @@ hb_subset_plan_create (hb_face_t *face,
|
||||
|
||||
_create_old_gid_to_new_gid_map (input->retain_gids,
|
||||
plan->glyphs,
|
||||
plan->glyph_map);
|
||||
plan->glyph_map,
|
||||
&plan->num_glyphs);
|
||||
|
||||
return plan;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ struct hb_subset_plan_t
|
||||
|
||||
hb_map_t *codepoint_to_glyph;
|
||||
hb_map_t *glyph_map;
|
||||
unsigned int num_glyphs;
|
||||
|
||||
// Plan is only good for a specific source/dest so keep them with it
|
||||
hb_face_t *source;
|
||||
|
Loading…
Reference in New Issue
Block a user