diff --git a/src/hb-ot-post-table-v2subset.hh b/src/hb-ot-post-table-v2subset.hh index c8ea01126..94450eb53 100644 --- a/src/hb-ot-post-table-v2subset.hh +++ b/src/hb-ot-post-table-v2subset.hh @@ -76,6 +76,9 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const hb_map_t old_new_index_map, old_gid_new_index_map; unsigned i = 0; + post::accelerator_t _post; + _post.init (c->plan->source); + for (hb_codepoint_t new_gid = 0; new_gid < num_glyphs; new_gid++) { hb_codepoint_t old_gid = reverse_glyph_map.get (new_gid); @@ -86,9 +89,24 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const else if (old_new_index_map.has (old_index)) new_index = old_new_index_map.get (old_index); else { - new_index = 258 + i; + hb_bytes_t s = _post.find_glyph_name (old_gid); + int standard_glyph_index = -1; + for (unsigned i = 0; i < format1_names_length; i++) + { + if (s == format1_names (i)) + { + standard_glyph_index = i; + break; + } + } + if (standard_glyph_index == -1) + { + new_index = 258 + i; + i++; + } + else + { new_index = standard_glyph_index; } old_new_index_map.set (old_index, new_index); - i++; } old_gid_new_index_map.set (old_gid, new_index); } @@ -103,8 +121,6 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const }) ; - post::accelerator_t _post; - _post.init (c->plan->source); bool ret = serialize (c->serializer, index_iter, &_post); _post.fini (); return_trace (ret); diff --git a/test/subset/data/Makefile.am b/test/subset/data/Makefile.am index bd70a6356..8490c3732 100644 --- a/test/subset/data/Makefile.am +++ b/test/subset/data/Makefile.am @@ -41,6 +41,7 @@ EXTRA_DIST += \ expected/colr_with_components \ expected/cbdt \ expected/variable \ + expected/glyph_names \ fonts \ profiles \ $(NULL) diff --git a/test/subset/data/Makefile.sources b/test/subset/data/Makefile.sources index 0bbc7cc27..17c9160a7 100644 --- a/test/subset/data/Makefile.sources +++ b/test/subset/data/Makefile.sources @@ -33,6 +33,7 @@ TESTS = \ tests/layout.tests \ tests/sbix.tests \ tests/variable.tests \ + tests/glyph_names.tests \ $(NULL) # TODO: re-enable once colrv1 subsetting is stabilized. diff --git a/test/subset/data/expected/glyph_names/Ubuntu-Regular.glyph-names.0x0,0x8,0x9,0x1d,0x20,0xb7.ttf b/test/subset/data/expected/glyph_names/Ubuntu-Regular.glyph-names.0x0,0x8,0x9,0x1d,0x20,0xb7.ttf new file mode 100644 index 000000000..dd2bf2ce0 Binary files /dev/null and b/test/subset/data/expected/glyph_names/Ubuntu-Regular.glyph-names.0x0,0x8,0x9,0x1d,0x20,0xb7.ttf differ diff --git a/test/subset/data/expected/glyph_names/Ubuntu-Regular.glyph-names.retain-all-codepoint.ttf b/test/subset/data/expected/glyph_names/Ubuntu-Regular.glyph-names.retain-all-codepoint.ttf new file mode 100644 index 000000000..e067ff18b Binary files /dev/null and b/test/subset/data/expected/glyph_names/Ubuntu-Regular.glyph-names.retain-all-codepoint.ttf differ diff --git a/test/subset/data/fonts/Ubuntu-Regular.ttf b/test/subset/data/fonts/Ubuntu-Regular.ttf new file mode 100644 index 000000000..2001d6ec6 Binary files /dev/null and b/test/subset/data/fonts/Ubuntu-Regular.ttf differ diff --git a/test/subset/data/tests/glyph_names.tests b/test/subset/data/tests/glyph_names.tests new file mode 100644 index 000000000..a710a3993 --- /dev/null +++ b/test/subset/data/tests/glyph_names.tests @@ -0,0 +1,9 @@ +FONTS: +Ubuntu-Regular.ttf + +PROFILES: +glyph-names.txt + +SUBSETS: +U+0x0,U+0x8,U+0x9,U+0x1d,U+0x20,U+0xb7 +* diff --git a/test/subset/meson.build b/test/subset/meson.build index 8c1c61cd5..c3ce6b2a4 100644 --- a/test/subset/meson.build +++ b/test/subset/meson.build @@ -36,6 +36,7 @@ tests = [ 'colr_with_components', 'cbdt', 'variable', + 'glyph_names', ] repack_tests = [