Merge pull request #3672 from googlefonts/cmap14
[subset] consider variation selectors subsetting cmap14
This commit is contained in:
commit
f1d3e116d5
@ -2873,7 +2873,9 @@ def closure_glyphs(self, s):
|
||||
# Close glyphs
|
||||
for table in tables:
|
||||
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}
|
||||
if None in glyphs:
|
||||
glyphs.remove(None)
|
||||
@ -2928,6 +2930,7 @@ def subset_glyphs(self, s):
|
||||
if g in s.glyphs_requested or u in s.unicodes_requested
|
||||
]
|
||||
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}
|
||||
elif t.isUnicode():
|
||||
@ -3797,6 +3800,8 @@ def main(args=None):
|
||||
for t in font["cmap"].tables:
|
||||
if t.isUnicode():
|
||||
unicodes.extend(t.cmap.keys())
|
||||
if t.format == 14:
|
||||
unicodes.extend(t.uvsDict.keys())
|
||||
assert "" not in glyphs
|
||||
|
||||
log.info("Text: '%s'" % text)
|
||||
|
11
Tests/subset/data/cmap14_font1.no_uvs.ttx
Normal file
11
Tests/subset/data/cmap14_font1.no_uvs.ttx
Normal 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>
|
11
Tests/subset/data/cmap14_font1.no_uvs_non_default.ttx
Normal file
11
Tests/subset/data/cmap14_font1.no_uvs_non_default.ttx
Normal 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>
|
1101
Tests/subset/data/cmap14_font1.ttx
Normal file
1101
Tests/subset/data/cmap14_font1.ttx
Normal file
File diff suppressed because it is too large
Load Diff
14
Tests/subset/data/cmap14_font1.uvs.ttx
Normal file
14
Tests/subset/data/cmap14_font1.uvs.ttx
Normal 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>
|
14
Tests/subset/data/cmap14_font1.uvs_non_default.ttx
Normal file
14
Tests/subset/data/cmap14_font1.uvs_non_default.ttx
Normal 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>
|
@ -938,6 +938,34 @@ class SubsetTest:
|
||||
subsetfont = TTFont(subsetpath)
|
||||
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)])
|
||||
def test_GPOS_PairPos_Format2_useClass0(self, text, n):
|
||||
# Check two things related to class 0 ('every other glyph'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user