[subset] make glyph-names option match fonttools behavior

Don't encode psNames that are contained in standard glyph names set
This commit is contained in:
Qunxin Liu 2021-08-18 20:46:06 -07:00 committed by Behdad Esfahbod
parent 829b0f3353
commit 34e0b28fae
8 changed files with 32 additions and 4 deletions

View File

@ -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; hb_map_t old_new_index_map, old_gid_new_index_map;
unsigned i = 0; 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++) for (hb_codepoint_t new_gid = 0; new_gid < num_glyphs; new_gid++)
{ {
hb_codepoint_t old_gid = reverse_glyph_map.get (new_gid); hb_codepoint_t old_gid = reverse_glyph_map.get (new_gid);
@ -85,11 +88,26 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const
if (old_index <= 257) new_index = old_index; if (old_index <= 257) new_index = old_index;
else if (old_new_index_map.has (old_index)) new_index = old_new_index_map.get (old_index); else if (old_new_index_map.has (old_index)) new_index = old_new_index_map.get (old_index);
else else
{
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; new_index = 258 + i;
old_new_index_map.set (old_index, new_index);
i++; i++;
} }
else
{ new_index = standard_glyph_index; }
old_new_index_map.set (old_index, new_index);
}
old_gid_new_index_map.set (old_gid, new_index); 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); bool ret = serialize (c->serializer, index_iter, &_post);
_post.fini (); _post.fini ();
return_trace (ret); return_trace (ret);

View File

@ -41,6 +41,7 @@ EXTRA_DIST += \
expected/colr_with_components \ expected/colr_with_components \
expected/cbdt \ expected/cbdt \
expected/variable \ expected/variable \
expected/glyph_names \
fonts \ fonts \
profiles \ profiles \
$(NULL) $(NULL)

View File

@ -33,6 +33,7 @@ TESTS = \
tests/layout.tests \ tests/layout.tests \
tests/sbix.tests \ tests/sbix.tests \
tests/variable.tests \ tests/variable.tests \
tests/glyph_names.tests \
$(NULL) $(NULL)
# TODO: re-enable once colrv1 subsetting is stabilized. # TODO: re-enable once colrv1 subsetting is stabilized.

Binary file not shown.

View File

@ -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
*

View File

@ -36,6 +36,7 @@ tests = [
'colr_with_components', 'colr_with_components',
'cbdt', 'cbdt',
'variable', 'variable',
'glyph_names',
] ]
repack_tests = [ repack_tests = [