From 2da1654aefbe4f8e5f1320f1c061adbf90963951 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 18 Jan 2019 17:49:35 -0800 Subject: [PATCH] [subset] Compute num_glyphs during subset plan construction. Update maxp to use the correct num glyphs. --- src/hb-ot-maxp-table.hh | 2 +- src/hb-subset-glyf.cc | 6 +----- src/hb-subset-plan.cc | 16 +++++++++++++--- src/hb-subset-plan.hh | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index e4b67ab..e0e6bd7 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -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); diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc index 51608c9..712b7cd 100644 --- a/src/hb-subset-glyf.cc +++ b/src/hb-subset-glyf.cc @@ -119,13 +119,9 @@ _calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf, hb_vector_t *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", diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 7060dc9..63498b7 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -156,9 +156,10 @@ _populate_gids_to_retain (hb_face_t *face, } static void -_create_old_gid_to_new_gid_map (bool retain_gids, +_create_old_gid_to_new_gid_map (bool retain_gids, const hb_vector_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; } diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index a710a4d..b8b2c5d 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -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; -- 2.7.4