diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 8a8b3f272..49fe7df21 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -547,13 +547,10 @@ HB_EXTERN void hb_subset_input_set_old_to_new_glyph_mapping (hb_subset_input_t *input, const hb_map_t* mapping) { - hb_set_t new_gids; - for (auto gid : mapping->values()) - { + hb_set_t new_gids(mapping->values()); + if (new_gids.get_population() != mapping->get_population()) // Mapping cannot map multiple old gids to the same new gid. - if (new_gids.has(gid)) return; - new_gids.add(gid); - } + return; input->glyph_map = *mapping; } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index f018814e7..1e152d3e0 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -782,10 +782,16 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, if (*requested_glyph_map) { - hb_codepoint_t max_glyph = HB_SET_VALUE_INVALID; + + hb_codepoint_t max_glyph = 0; hb_set_t remaining; for (auto old_gid : all_gids_to_retain->iter ()) { + if (old_gid == 0) { + reverse_glyph_map->set(0, 0); + continue; + } + hb_codepoint_t* new_gid; if (!requested_glyph_map->has (old_gid, &new_gid)) { @@ -793,7 +799,7 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, continue; } - if (*new_gid > max_glyph || max_glyph == HB_SET_VALUE_INVALID) + if (*new_gid > max_glyph) max_glyph = *new_gid; reverse_glyph_map->set (*new_gid, old_gid); } diff --git a/test/subset/data/expected/glyph_map/Roboto-Regular.glyph_map_roboto.41,43,61,66,69.ttf b/test/subset/data/expected/glyph_map/Roboto-Regular.glyph_map_roboto.41,43,61,66,69.ttf new file mode 100644 index 000000000..a4c82662f Binary files /dev/null and b/test/subset/data/expected/glyph_map/Roboto-Regular.glyph_map_roboto.41,43,61,66,69.ttf differ diff --git a/test/subset/data/expected/glyph_map/Roboto-Regular.glyph_map_roboto_retain_gids.41,43,61,66,69.ttf b/test/subset/data/expected/glyph_map/Roboto-Regular.glyph_map_roboto_retain_gids.41,43,61,66,69.ttf new file mode 100644 index 000000000..f63599984 Binary files /dev/null and b/test/subset/data/expected/glyph_map/Roboto-Regular.glyph_map_roboto_retain_gids.41,43,61,66,69.ttf differ diff --git a/test/subset/data/profiles/glyph_map_roboto.txt b/test/subset/data/profiles/glyph_map_roboto.txt new file mode 100644 index 000000000..2ee33b3cf --- /dev/null +++ b/test/subset/data/profiles/glyph_map_roboto.txt @@ -0,0 +1,2 @@ +--gid-map=37:1,39:2,69:3,74:4,77:5 +--layout-features+=c2sc diff --git a/test/subset/data/profiles/glyph_map_roboto_retain_gids.txt b/test/subset/data/profiles/glyph_map_roboto_retain_gids.txt new file mode 100644 index 000000000..77a513cbb --- /dev/null +++ b/test/subset/data/profiles/glyph_map_roboto_retain_gids.txt @@ -0,0 +1,4 @@ +--gid-map=37:37,39:39,69:69,74:74,77:77,444:444,446:446,561:561,563:563 +--gids=444,446,561,563 +--layout-features+=c2sc +--retain-gids diff --git a/test/subset/data/tests/glyph_map.tests b/test/subset/data/tests/glyph_map.tests new file mode 100644 index 000000000..d222aceee --- /dev/null +++ b/test/subset/data/tests/glyph_map.tests @@ -0,0 +1,9 @@ +FONTS: +Roboto-Regular.ttf + +PROFILES: +glyph_map_roboto.txt +glyph_map_roboto_retain_gids.txt + +SUBSETS: +ACafi diff --git a/test/subset/generate-expected-outputs.py b/test/subset/generate-expected-outputs.py index 201fe4a78..5f21f80c4 100755 --- a/test/subset/generate-expected-outputs.py +++ b/test/subset/generate-expected-outputs.py @@ -51,7 +51,9 @@ def generate_expected_output(input_file, unicodes, profile_flags, instance_flags if unicodes != "": args.extend(["--unicodes=%s" % unicodes,]) - args.extend(profile_flags) + # --gid-map is unsupported in fonttools so don't send it. Tests using + # it are crafted to work without fonttools knowing about the flag. + args.extend([f for f in profile_flags if not f.startswith("--gid-map")]) if not no_fonttools: check_call(args)