Merge pull request #3672 from googlefonts/cmap14

[subset] consider variation selectors subsetting cmap14
This commit is contained in:
Behdad Esfahbod 2024-11-11 13:45:36 -07:00 committed by GitHub
commit f1d3e116d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 1185 additions and 1 deletions

View File

@ -2873,7 +2873,9 @@ def closure_glyphs(self, s):
# Close glyphs # Close glyphs
for table in tables: for table in tables:
if table.format == 14: if table.format == 14:
for cmap in table.uvsDict.values(): for varSelector, cmap in table.uvsDict.items():
if varSelector not in s.unicodes_requested:
continue
glyphs = {g for u, g in cmap if u in s.unicodes_requested} glyphs = {g for u, g in cmap if u in s.unicodes_requested}
if None in glyphs: if None in glyphs:
glyphs.remove(None) glyphs.remove(None)
@ -2928,6 +2930,7 @@ def subset_glyphs(self, s):
if g in s.glyphs_requested or u in s.unicodes_requested if g in s.glyphs_requested or u in s.unicodes_requested
] ]
for v, l in t.uvsDict.items() for v, l in t.uvsDict.items()
if v in s.unicodes_requested
} }
t.uvsDict = {v: l for v, l in t.uvsDict.items() if l} t.uvsDict = {v: l for v, l in t.uvsDict.items() if l}
elif t.isUnicode(): elif t.isUnicode():
@ -3797,6 +3800,8 @@ def main(args=None):
for t in font["cmap"].tables: for t in font["cmap"].tables:
if t.isUnicode(): if t.isUnicode():
unicodes.extend(t.cmap.keys()) unicodes.extend(t.cmap.keys())
if t.format == 14:
unicodes.extend(t.uvsDict.keys())
assert "" not in glyphs assert "" not in glyphs
log.info("Text: '%s'" % text) log.info("Text: '%s'" % text)

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x4e05" name="g15"/><!-- CJK UNIFIED IDEOGRAPH-4E05 -->
</cmap_format_4>
</cmap>
</ttFont>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x4e10" name="g20"/><!-- CJK UNIFIED IDEOGRAPH-4E10 -->
</cmap_format_4>
</cmap>
</ttFont>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<cmap>
<tableVersion version="0"/>
<cmap_format_14 platformID="0" platEncID="5">
<map uv="0x4e05" uvs="0xe0100"/>
</cmap_format_14>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x4e05" name="g15"/><!-- CJK UNIFIED IDEOGRAPH-4E05 -->
</cmap_format_4>
</cmap>
</ttFont>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<cmap>
<tableVersion version="0"/>
<cmap_format_14 platformID="0" platEncID="5">
<map uv="0x4e10" uvs="0xe0100" name="g25"/>
</cmap_format_14>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x4e10" name="g20"/><!-- CJK UNIFIED IDEOGRAPH-4E10 -->
</cmap_format_4>
</cmap>
</ttFont>

View File

@ -938,6 +938,34 @@ class SubsetTest:
subsetfont = TTFont(subsetpath) subsetfont = TTFont(subsetpath)
self.expect_ttx(subsetfont, self.getpath("CmapSubsetTest.subset.ttx"), ["cmap"]) self.expect_ttx(subsetfont, self.getpath("CmapSubsetTest.subset.ttx"), ["cmap"])
def test_cmap_format14(self):
fontpath = self.compile_font(self.getpath("cmap14_font1.ttx"), ".otf")
subsetpath = self.temp_path(".otf")
subset.main([fontpath, "--unicodes=4e05", "--output-file=%s" % subsetpath])
subsetfont = TTFont(subsetpath)
self.expect_ttx(subsetfont, self.getpath("cmap14_font1.no_uvs.ttx"), ["cmap"])
subset.main(
[fontpath, "--unicodes=4e05,e0100", "--output-file=%s" % subsetpath]
)
subsetfont = TTFont(subsetpath)
self.expect_ttx(subsetfont, self.getpath("cmap14_font1.uvs.ttx"), ["cmap"])
subset.main([fontpath, "--unicodes=4e10", "--output-file=%s" % subsetpath])
subsetfont = TTFont(subsetpath)
self.expect_ttx(
subsetfont, self.getpath("cmap14_font1.no_uvs_non_default.ttx"), ["cmap"]
)
subset.main(
[fontpath, "--unicodes=4e10,e0100", "--output-file=%s" % subsetpath]
)
subsetfont = TTFont(subsetpath)
self.expect_ttx(
subsetfont, self.getpath("cmap14_font1.uvs_non_default.ttx"), ["cmap"]
)
@pytest.mark.parametrize("text, n", [("!", 1), ("#", 2)]) @pytest.mark.parametrize("text, n", [("!", 1), ("#", 2)])
def test_GPOS_PairPos_Format2_useClass0(self, text, n): def test_GPOS_PairPos_Format2_useClass0(self, text, n):
# Check two things related to class 0 ('every other glyph'): # Check two things related to class 0 ('every other glyph'):