[subset] Compute num_glyphs during subset plan construction.
authorGarret Rieger <grieger@google.com>
Sat, 19 Jan 2019 01:49:35 +0000 (17:49 -0800)
committerGarret Rieger <grieger@google.com>
Tue, 29 Jan 2019 21:19:21 +0000 (13:19 -0800)
Update maxp to use the correct num glyphs.

src/hb-ot-maxp-table.hh
src/hb-subset-glyf.cc
src/hb-subset-plan.cc
src/hb-subset-plan.hh

index e4b67ab..e0e6bd7 100644 (file)
@@ -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);
 
index 51608c9..712b7cd 100644 (file)
@@ -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",
index 7060dc9..63498b7 100644 (file)
@@ -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<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;
 }
index a710a4d..b8b2c5d 100644 (file)
@@ -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;