Add Google-style color font test and make _dict_subset more forgiving.
This commit is contained in:
parent
812609e90c
commit
905eb831b9
@ -332,7 +332,7 @@ def _set_update(s, *others):
|
|||||||
s.update(other)
|
s.update(other)
|
||||||
|
|
||||||
def _dict_subset(d, glyphs):
|
def _dict_subset(d, glyphs):
|
||||||
return {g:d[g] for g in glyphs}
|
return {g:d[g] for g in glyphs if g in d}
|
||||||
|
|
||||||
|
|
||||||
@_add_method(otTables.Coverage)
|
@_add_method(otTables.Coverage)
|
||||||
|
@ -110,6 +110,23 @@ class SubsetTest(unittest.TestCase):
|
|||||||
self.assertTrue('Xyz-' in opt2.layout_features)
|
self.assertTrue('Xyz-' in opt2.layout_features)
|
||||||
self.assertTrue('Xyz-' not in opt1.layout_features)
|
self.assertTrue('Xyz-' not in opt1.layout_features)
|
||||||
|
|
||||||
|
def test_google_color(self):
|
||||||
|
_, fontpath = self.compile_font(self.getpath("google_color.ttx"), ".ttf")
|
||||||
|
subsetpath = self.temp_path(".ttf")
|
||||||
|
subset.main([fontpath, "--gids=0,1", "--output-file=%s" % subsetpath])
|
||||||
|
subsetfont = TTFont(subsetpath)
|
||||||
|
self.assertTrue("CBDT" in subsetfont)
|
||||||
|
self.assertTrue("CBLC" in subsetfont)
|
||||||
|
self.assertTrue("x" in subsetfont['CBDT'].strikeData[0])
|
||||||
|
self.assertFalse("y" in subsetfont['CBDT'].strikeData[0])
|
||||||
|
|
||||||
|
def test_google_color_all(self):
|
||||||
|
_, fontpath = self.compile_font(self.getpath("google_color.ttx"), ".ttf")
|
||||||
|
subsetpath = self.temp_path(".ttf")
|
||||||
|
subset.main([fontpath, "--unicodes=*", "--output-file=%s" % subsetpath])
|
||||||
|
subsetfont = TTFont(subsetpath)
|
||||||
|
self.assertTrue("x" in subsetfont['CBDT'].strikeData[0])
|
||||||
|
self.assertTrue("y" in subsetfont['CBDT'].strikeData[0])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
250
Lib/fontTools/subset/testdata/google_color.ttx
vendored
Normal file
250
Lib/fontTools/subset/testdata/google_color.ttx
vendored
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.0">
|
||||||
|
|
||||||
|
<GlyphOrder>
|
||||||
|
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
|
||||||
|
<GlyphID id="0" name=".notdef"/>
|
||||||
|
<GlyphID id="1" name="x"/>
|
||||||
|
<GlyphID id="2" name="y"/>
|
||||||
|
</GlyphOrder>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<!-- Most of this table will be recalculated by the compiler -->
|
||||||
|
<tableVersion value="1.0"/>
|
||||||
|
<fontRevision value="1.0"/>
|
||||||
|
<checkSumAdjustment value="0x75dc550a"/>
|
||||||
|
<magicNumber value="0x5f0f3cf5"/>
|
||||||
|
<flags value="00000000 00001011"/>
|
||||||
|
<unitsPerEm value="2048"/>
|
||||||
|
<created value="Wed May 22 20:07:39 2013"/>
|
||||||
|
<modified value="Wed Dec 9 20:01:21 2015"/>
|
||||||
|
<xMin value="0"/>
|
||||||
|
<yMin value="-512"/>
|
||||||
|
<xMax value="2048"/>
|
||||||
|
<yMax value="1536"/>
|
||||||
|
<macStyle value="00000000 00000000"/>
|
||||||
|
<lowestRecPPEM value="8"/>
|
||||||
|
<fontDirectionHint value="2"/>
|
||||||
|
<indexToLocFormat value="0"/>
|
||||||
|
<glyphDataFormat value="0"/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<hhea>
|
||||||
|
<tableVersion value="1.0"/>
|
||||||
|
<ascent value="1536"/>
|
||||||
|
<descent value="-512"/>
|
||||||
|
<lineGap value="256"/>
|
||||||
|
<advanceWidthMax value="2048"/>
|
||||||
|
<minLeftSideBearing value="0"/>
|
||||||
|
<minRightSideBearing value="0"/>
|
||||||
|
<xMaxExtent value="1491"/>
|
||||||
|
<caretSlopeRise value="1"/>
|
||||||
|
<caretSlopeRun value="0"/>
|
||||||
|
<caretOffset value="0"/>
|
||||||
|
<reserved0 value="0"/>
|
||||||
|
<reserved1 value="0"/>
|
||||||
|
<reserved2 value="0"/>
|
||||||
|
<reserved3 value="0"/>
|
||||||
|
<metricDataFormat value="0"/>
|
||||||
|
<numberOfHMetrics value="96"/>
|
||||||
|
</hhea>
|
||||||
|
|
||||||
|
<maxp>
|
||||||
|
<!-- Most of this table will be recalculated by the compiler -->
|
||||||
|
<tableVersion value="0x10000"/>
|
||||||
|
<numGlyphs value="96"/>
|
||||||
|
<maxPoints value="8"/>
|
||||||
|
<maxContours value="2"/>
|
||||||
|
<maxCompositePoints value="0"/>
|
||||||
|
<maxCompositeContours value="0"/>
|
||||||
|
<maxZones value="2"/>
|
||||||
|
<maxTwilightPoints value="0"/>
|
||||||
|
<maxStorage value="1"/>
|
||||||
|
<maxFunctionDefs value="1"/>
|
||||||
|
<maxInstructionDefs value="0"/>
|
||||||
|
<maxStackElements value="64"/>
|
||||||
|
<maxSizeOfInstructions value="46"/>
|
||||||
|
<maxComponentElements value="0"/>
|
||||||
|
<maxComponentDepth value="0"/>
|
||||||
|
</maxp>
|
||||||
|
|
||||||
|
<OS_2>
|
||||||
|
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
|
||||||
|
will be recalculated by the compiler -->
|
||||||
|
<version value="4"/>
|
||||||
|
<xAvgCharWidth value="2048"/>
|
||||||
|
<usWeightClass value="500"/>
|
||||||
|
<usWidthClass value="5"/>
|
||||||
|
<fsType value="00000000 00000000"/>
|
||||||
|
<ySubscriptXSize value="1331"/>
|
||||||
|
<ySubscriptYSize value="1433"/>
|
||||||
|
<ySubscriptXOffset value="0"/>
|
||||||
|
<ySubscriptYOffset value="286"/>
|
||||||
|
<ySuperscriptXSize value="1331"/>
|
||||||
|
<ySuperscriptYSize value="1433"/>
|
||||||
|
<ySuperscriptXOffset value="0"/>
|
||||||
|
<ySuperscriptYOffset value="983"/>
|
||||||
|
<yStrikeoutSize value="102"/>
|
||||||
|
<yStrikeoutPosition value="530"/>
|
||||||
|
<sFamilyClass value="0"/>
|
||||||
|
<panose>
|
||||||
|
<bFamilyType value="2"/>
|
||||||
|
<bSerifStyle value="0"/>
|
||||||
|
<bWeight value="6"/>
|
||||||
|
<bProportion value="9"/>
|
||||||
|
<bContrast value="0"/>
|
||||||
|
<bStrokeVariation value="0"/>
|
||||||
|
<bArmStyle value="0"/>
|
||||||
|
<bLetterForm value="0"/>
|
||||||
|
<bMidline value="0"/>
|
||||||
|
<bXHeight value="0"/>
|
||||||
|
</panose>
|
||||||
|
<ulUnicodeRange1 value="00000000 00000000 00000000 00000001"/>
|
||||||
|
<ulUnicodeRange2 value="00000000 00000000 00000000 00000000"/>
|
||||||
|
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
|
||||||
|
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
|
||||||
|
<achVendID value="GOOG"/>
|
||||||
|
<fsSelection value="00000000 11000000"/>
|
||||||
|
<usFirstCharIndex value="0"/>
|
||||||
|
<usLastCharIndex value="126"/>
|
||||||
|
<sTypoAscender value="1536"/>
|
||||||
|
<sTypoDescender value="-512"/>
|
||||||
|
<sTypoLineGap value="184"/>
|
||||||
|
<usWinAscent value="1536"/>
|
||||||
|
<usWinDescent value="512"/>
|
||||||
|
<ulCodePageRange1 value="00000000 00000000 00000000 00000001"/>
|
||||||
|
<ulCodePageRange2 value="00000000 00000000 00000000 00000000"/>
|
||||||
|
<sxHeight value="0"/>
|
||||||
|
<sCapHeight value="1322"/>
|
||||||
|
<usDefaultChar value="0"/>
|
||||||
|
<usBreakChar value="32"/>
|
||||||
|
<usMaxContext value="1"/>
|
||||||
|
</OS_2>
|
||||||
|
|
||||||
|
<hmtx>
|
||||||
|
<mtx name=".notdef" width="2048" lsb="0"/>
|
||||||
|
<mtx name="x" width="1600" lsb="0"/>
|
||||||
|
<mtx name="y" width="1584" lsb="0"/>
|
||||||
|
</hmtx>
|
||||||
|
|
||||||
|
<cmap>
|
||||||
|
<tableVersion version="0"/>
|
||||||
|
<cmap_format_4 platformID="3" platEncID="1" language="0">
|
||||||
|
<map code="0x0" name=".notdef"/>
|
||||||
|
<map code="0x78" name="x"/>
|
||||||
|
<map code="0x79" name="y"/>
|
||||||
|
</cmap_format_4>
|
||||||
|
</cmap>
|
||||||
|
|
||||||
|
<name>
|
||||||
|
<namerecord nameID="1" platformID="1" platEncID="0" langID="0x0" unicode="True">
|
||||||
|
Meh
|
||||||
|
</namerecord>
|
||||||
|
<namerecord nameID="2" platformID="1" platEncID="0" langID="0x0" unicode="True">
|
||||||
|
ZOMG
|
||||||
|
</namerecord>
|
||||||
|
</name>
|
||||||
|
|
||||||
|
<post>
|
||||||
|
<formatType value="2.0"/>
|
||||||
|
<italicAngle value="0.0"/>
|
||||||
|
<underlinePosition value="-1244"/>
|
||||||
|
<underlineThickness value="131"/>
|
||||||
|
<isFixedPitch value="1"/>
|
||||||
|
<minMemType42 value="0"/>
|
||||||
|
<maxMemType42 value="0"/>
|
||||||
|
<minMemType1 value="0"/>
|
||||||
|
<maxMemType1 value="0"/>
|
||||||
|
<psNames>
|
||||||
|
<!-- This file uses unique glyph names based on the information
|
||||||
|
found in the 'post' table. Since these names might not be unique,
|
||||||
|
we have to invent artificial names in case of clashes. In order to
|
||||||
|
be able to retain the original information, we need a name to
|
||||||
|
ps name mapping for those cases where they differ. That's what
|
||||||
|
you see below.
|
||||||
|
-->
|
||||||
|
</psNames>
|
||||||
|
<extraNames>
|
||||||
|
</extraNames>
|
||||||
|
</post>
|
||||||
|
|
||||||
|
<CBDT>
|
||||||
|
<header version="2.0"/>
|
||||||
|
<strikedata index="0">
|
||||||
|
<cbdt_bitmap_format_17 name="x">
|
||||||
|
<SmallGlyphMetrics>
|
||||||
|
<height value="128"/>
|
||||||
|
<width value="100"/>
|
||||||
|
<BearingX value="0"/>
|
||||||
|
<BearingY value="96"/>
|
||||||
|
<Advance value="100"/>
|
||||||
|
</SmallGlyphMetrics>
|
||||||
|
<rawimagedata>
|
||||||
|
DEAD
|
||||||
|
</rawimagedata>
|
||||||
|
</cbdt_bitmap_format_17>
|
||||||
|
<cbdt_bitmap_format_17 name="y">
|
||||||
|
<SmallGlyphMetrics>
|
||||||
|
<height value="128"/>
|
||||||
|
<width value="99"/>
|
||||||
|
<BearingX value="0"/>
|
||||||
|
<BearingY value="96"/>
|
||||||
|
<Advance value="99"/>
|
||||||
|
</SmallGlyphMetrics>
|
||||||
|
<rawimagedata>
|
||||||
|
F00D
|
||||||
|
</rawimagedata>
|
||||||
|
</cbdt_bitmap_format_17>
|
||||||
|
</strikedata>
|
||||||
|
</CBDT>
|
||||||
|
|
||||||
|
<CBLC>
|
||||||
|
<header version="2.0"/>
|
||||||
|
<strike index="0">
|
||||||
|
<bitmapSizeTable>
|
||||||
|
<sbitLineMetrics direction="hori">
|
||||||
|
<ascender value="97"/>
|
||||||
|
<descender value="-32"/>
|
||||||
|
<widthMax value="100"/>
|
||||||
|
<caretSlopeNumerator value="0"/>
|
||||||
|
<caretSlopeDenominator value="0"/>
|
||||||
|
<caretOffset value="0"/>
|
||||||
|
<minOriginSB value="0"/>
|
||||||
|
<minAdvanceSB value="0"/>
|
||||||
|
<maxBeforeBL value="0"/>
|
||||||
|
<minAfterBL value="0"/>
|
||||||
|
<pad1 value="0"/>
|
||||||
|
<pad2 value="0"/>
|
||||||
|
</sbitLineMetrics>
|
||||||
|
<sbitLineMetrics direction="vert">
|
||||||
|
<ascender value="97"/>
|
||||||
|
<descender value="-32"/>
|
||||||
|
<widthMax value="100"/>
|
||||||
|
<caretSlopeNumerator value="0"/>
|
||||||
|
<caretSlopeDenominator value="0"/>
|
||||||
|
<caretOffset value="0"/>
|
||||||
|
<minOriginSB value="0"/>
|
||||||
|
<minAdvanceSB value="0"/>
|
||||||
|
<maxBeforeBL value="0"/>
|
||||||
|
<minAfterBL value="0"/>
|
||||||
|
<pad1 value="0"/>
|
||||||
|
<pad2 value="0"/>
|
||||||
|
</sbitLineMetrics>
|
||||||
|
<colorRef value="0"/>
|
||||||
|
<startGlyphIndex value="81"/>
|
||||||
|
<endGlyphIndex value="82"/>
|
||||||
|
<ppemX value="129"/>
|
||||||
|
<ppemY value="129"/>
|
||||||
|
<bitDepth value="32"/>
|
||||||
|
<flags value="1"/>
|
||||||
|
</bitmapSizeTable>
|
||||||
|
<!-- GlyphIds are written but not read. The firstGlyphIndex and
|
||||||
|
lastGlyphIndex values will be recalculated by the compiler. -->
|
||||||
|
<eblc_index_sub_table_1 imageFormat="17" firstGlyphIndex="1" lastGlyphIndex="2">
|
||||||
|
<glyphLoc id="1" name="x"/>
|
||||||
|
<glyphLoc id="2" name="y"/>
|
||||||
|
</eblc_index_sub_table_1>
|
||||||
|
</strike>
|
||||||
|
</CBLC>
|
||||||
|
|
||||||
|
</ttFont>
|
Loading…
x
Reference in New Issue
Block a user