diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index fad75d0b3..2e7b71b8e 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -183,9 +183,11 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, | hb_sink (reverse_glyph_map) ; - // TODO(grieger): Should we discard glyphs past the max glyph to keep? - // *num_glyphs = + hb_iter (all_gids_to_retain) | hb_reduce (hb_max, 0); - *num_glyphs = face->get_num_glyphs (); + unsigned max_glyph = + + hb_iter (all_gids_to_retain) + | hb_reduce (hb_max, 0) + ; + *num_glyphs = max_glyph + 1; } + reverse_glyph_map->iter () diff --git a/test/api/fonts/Roboto-Regular.a.retaingids.ttf b/test/api/fonts/Roboto-Regular.a.retaingids.ttf new file mode 100644 index 000000000..183b148ca Binary files /dev/null and b/test/api/fonts/Roboto-Regular.a.retaingids.ttf differ diff --git a/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf b/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf index 906bdbefd..fa2a0e446 100644 Binary files a/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf and b/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf differ diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index 4671156f9..dd9833c58 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -305,6 +305,30 @@ test_subset_glyf_retain_gids (void) hb_face_destroy (face_ac); } +static void +test_subset_glyf_retain_gids_truncates (void) +{ + hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf"); + hb_face_t *face_a = hb_test_open_font_file ("fonts/Roboto-Regular.a.retaingids.ttf"); + + hb_set_t *codepoints = hb_set_create(); + hb_face_t *face_abc_subset; + hb_set_add (codepoints, 97); + + hb_subset_input_t *input = hb_subset_test_create_input (codepoints); + hb_subset_input_set_retain_gids (input, true); + face_abc_subset = hb_subset_test_create_subset (face_abc, input); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_a, face_abc_subset, HB_TAG ('g','l','y','f')); + hb_subset_test_check (face_a, face_abc_subset, HB_TAG ('l','o','c', 'a')); + check_maxp_num_glyphs(face_abc_subset, 2, true); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_a); +} + // TODO(grieger): test for long loca generation. int @@ -322,6 +346,7 @@ main (int argc, char **argv) hb_test_add (test_subset_glyf_with_gsub); hb_test_add (test_subset_glyf_without_gsub); hb_test_add (test_subset_glyf_retain_gids); + hb_test_add (test_subset_glyf_retain_gids_truncates); return hb_test_run(); } diff --git a/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.61.ttf b/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.61.ttf index 1a0d5bdd0..128eae016 100644 Binary files a/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.61.ttf and b/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.61.ttf differ diff --git a/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.62.ttf b/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.62.ttf index 257184b92..2d2b65b0d 100644 Binary files a/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.62.ttf and b/test/subset/data/expected/basics/Roboto-Regular.abc.drop-hints-retain-gids.62.ttf differ diff --git a/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.61.ttf b/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.61.ttf index d3a67eafa..a699eea0b 100644 Binary files a/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.61.ttf and b/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.61.ttf differ diff --git a/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.62.ttf b/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.62.ttf index 4ff6e338c..eb84f9c9f 100644 Binary files a/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.62.ttf and b/test/subset/data/expected/basics/Roboto-Regular.abc.retain-gids.62.ttf differ