Implement subset --regain-gids option with CFF1/2 along with api tests & expected results
diff --git a/src/hb-subset-cff-common.cc b/src/hb-subset-cff-common.cc index 3e617d5..d6feb4b 100644 --- a/src/hb-subset-cff-common.cc +++ b/src/hb-subset-cff-common.cc
@@ -43,7 +43,7 @@ **/ bool -hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs, +hb_plan_subset_cff_fdselect (const hb_subset_plan_t *plan, unsigned int fdCount, const FDSelect &src, /* IN */ unsigned int &subset_fd_count /* OUT */, @@ -57,7 +57,7 @@ subset_fdselect_format = 0; unsigned int num_ranges = 0; - unsigned int subset_num_glyphs = glyphs.length; + unsigned int subset_num_glyphs = plan->num_output_glyphs (); if (subset_num_glyphs == 0) return true; @@ -69,7 +69,18 @@ hb_codepoint_t prev_fd = CFF_UNDEF_CODE; for (hb_codepoint_t i = 0; i < subset_num_glyphs; i++) { - hb_codepoint_t fd = src.get_fd (glyphs[i]); + hb_codepoint_t glyph; + hb_codepoint_t fd; + if (!plan->old_gid_for_new_gid (i, &glyph)) + { + /* for a missing glyph, use the same fd as the previous + * as an attempt to minimize the number of ranges */ + fd = (prev_fd == CFF_UNDEF_CODE)? 0: prev_fd; + } + else + { + fd = src.get_fd (glyph); + } set->add (fd); if (fd != prev_fd)