Add Graphite table tests
This commit is contained in:
parent
84ce740814
commit
b0ae563d4d
@ -58,9 +58,13 @@ class table_F__e_a_t(DefaultTable.DefaultTable):
|
||||
vdat = ""
|
||||
offset = 0
|
||||
for f, v in sorted(self.features.items()):
|
||||
fnum = grUtils.tag2num(f)
|
||||
if self.version >= 2.0:
|
||||
fdat += struct.pack(">LHHLHH", grUtils.tag2num(f), len(v.settings),
|
||||
0, offset * 4 + 12 + 16 * len(self.features), v.flags, v.label)
|
||||
elif fnum > 65535: # self healing for alphabetic ids
|
||||
self.version = 2.0
|
||||
return self.compile(ttFont)
|
||||
else:
|
||||
fdat += struct.pack(">HHLHH", grUtils.tag2num(f), len(v.settings),
|
||||
offset * 4 + 12 + 12 * len(self.features), v.flags, v.label)
|
||||
|
@ -2,14 +2,8 @@ from __future__ import print_function, division, absolute_import
|
||||
from fontTools.misc.py23 import *
|
||||
from fontTools.misc import sstruct
|
||||
from fontTools.misc.textTools import safeEval
|
||||
from itertools import *
|
||||
from functools import partial
|
||||
from . import DefaultTable
|
||||
import array
|
||||
import struct
|
||||
import operator
|
||||
import warnings
|
||||
from _ast import Num
|
||||
|
||||
Gloc_header = '''
|
||||
> # big endian
|
||||
|
@ -3,7 +3,6 @@ from fontTools.misc.py23 import *
|
||||
from fontTools.misc import sstruct
|
||||
from fontTools.misc.textTools import safeEval
|
||||
from itertools import *
|
||||
from functools import partial
|
||||
from . import DefaultTable
|
||||
from . import grUtils
|
||||
from array import array
|
||||
@ -487,7 +486,7 @@ class Silf(object):
|
||||
writer.newline()
|
||||
writer.endtag('justifications')
|
||||
writer.newline()
|
||||
if self.numCritFeatures:
|
||||
if len(self.critFeatures):
|
||||
writer.begintag('critFeatures')
|
||||
writer.newline()
|
||||
writer.write(" ".join(map(str, self.critFeatures)))
|
||||
@ -510,7 +509,7 @@ class Silf(object):
|
||||
writer.endtag('pseudoMap')
|
||||
writer.newline()
|
||||
self.classes.toXML(writer, ttFont, version)
|
||||
if self.numPasses:
|
||||
if len(self.passes):
|
||||
writer.begintag('passes')
|
||||
writer.newline()
|
||||
for i, p in enumerate(self.passes):
|
||||
@ -723,12 +722,12 @@ class Pass(object):
|
||||
data = data[self.numTransitional * self.numColumns * 2 + 1:]
|
||||
self.passConstraints = data[:pConstraint]
|
||||
data = data[pConstraint:]
|
||||
for i in range(len(oConstraints)-1,0,-1):
|
||||
for i in range(len(oConstraints)-2,-1,-1):
|
||||
if oConstraints[i] == 0 :
|
||||
oConstraints[i] = oConstraints[i+1]
|
||||
self.ruleConstraints = [(data[s:e] if (e-s > 1) else "") for (s,e) in izip(oConstraints, oConstraints[1:])]
|
||||
data = data[oConstraints[-1]:]
|
||||
for i in range(len(oActions)-1,0,-1):
|
||||
for i in range(len(oActions)-2,-1,-1):
|
||||
if oActions[i] == 0:
|
||||
oActions[i] = oActions[i+1]
|
||||
self.actions = [(data[s:e] if (e-s > 1) else "") for (s,e) in izip(oActions, oActions[1:])]
|
||||
@ -798,7 +797,7 @@ class Pass(object):
|
||||
writer.newline()
|
||||
writer.begintag('rules')
|
||||
writer.newline()
|
||||
for i in range(self.numRules):
|
||||
for i in range(len(self.actions)):
|
||||
writer.begintag('rule', index=i, precontext=self.rulePreContexts[i],
|
||||
sortkey=self.ruleSortKeys[i])
|
||||
writer.newline()
|
||||
|
BIN
Tests/ttLib/tables/data/graphite/graphite_tests.ttf
Normal file
BIN
Tests/ttLib/tables/data/graphite/graphite_tests.ttf
Normal file
Binary file not shown.
18
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat
Normal file
18
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Feat
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00">
|
||||
|
||||
<Feat>
|
||||
<version version="2.0"/>
|
||||
<feature fid="1" flags="32768" label="258">
|
||||
</feature>
|
||||
<feature fid="nom " flags="32768" label="262">
|
||||
<setting label="261" value="0"/>
|
||||
<setting label="260" value="1"/>
|
||||
</feature>
|
||||
<feature fid="yesm" flags="32768" label="259">
|
||||
<setting label="261" value="0"/>
|
||||
<setting label="260" value="1"/>
|
||||
</feature>
|
||||
</Feat>
|
||||
|
||||
</ttFont>
|
29
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat
Normal file
29
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Glat
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00">
|
||||
|
||||
<Glat>
|
||||
<version compressionScheme="0" version="1.0"/>
|
||||
<glyph name=".notdef">
|
||||
<attribute index="1" value="3"/>
|
||||
<attribute index="2" value="30"/>
|
||||
</glyph>
|
||||
<glyph name="space">
|
||||
<attribute index="1" value="3"/>
|
||||
<attribute index="2" value="15"/>
|
||||
<attribute index="3" value="9"/>
|
||||
</glyph>
|
||||
<glyph name="a">
|
||||
<attribute index="1" value="2"/>
|
||||
<attribute index="2" value="30"/>
|
||||
</glyph>
|
||||
<glyph name="b">
|
||||
<attribute index="1" value="3"/>
|
||||
<attribute index="2" value="30"/>
|
||||
</glyph>
|
||||
<glyph name="c">
|
||||
<attribute index="1" value="1"/>
|
||||
<attribute index="2" value="30"/>
|
||||
</glyph>
|
||||
</Glat>
|
||||
|
||||
</ttFont>
|
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.15">
|
||||
|
||||
<GlyphOrder>
|
||||
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
|
||||
<GlyphID id="0" name=".notdef"/>
|
||||
<GlyphID id="1" name="space"/>
|
||||
<GlyphID id="2" name="a"/>
|
||||
<GlyphID id="3" name="b"/>
|
||||
<GlyphID id="4" name="c"/>
|
||||
</GlyphOrder>
|
||||
|
||||
<maxp>
|
||||
<!-- Most of this table will be recalculated by the compiler -->
|
||||
<tableVersion value="0x10000"/>
|
||||
<numGlyphs value="5"/>
|
||||
<maxPoints value="0"/>
|
||||
<maxContours value="0"/>
|
||||
<maxCompositePoints value="0"/>
|
||||
<maxCompositeContours value="0"/>
|
||||
<maxZones value="2"/>
|
||||
<maxTwilightPoints value="8"/>
|
||||
<maxStorage value="64"/>
|
||||
<maxFunctionDefs value="10"/>
|
||||
<maxInstructionDefs value="0"/>
|
||||
<maxStackElements value="299"/>
|
||||
<maxSizeOfInstructions value="207"/>
|
||||
<maxComponentElements value="0"/>
|
||||
<maxComponentDepth value="0"/>
|
||||
</maxp>
|
||||
|
||||
<cmap>
|
||||
<tableVersion version="0"/>
|
||||
<cmap_format_4 platformID="3" platEncID="1" language="0">
|
||||
<map code="0x20" name="space"/>
|
||||
<map code="0x61" name="a"/>
|
||||
<map code="0x62" name="b"/>
|
||||
<map code="0x63" name="c"/>
|
||||
</cmap_format_4>
|
||||
</cmap>
|
||||
|
||||
<!--
|
||||
<Gloc>
|
||||
<attributes number="8"/>
|
||||
</Gloc>
|
||||
-->
|
||||
</ttFont>
|
||||
|
79
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf
Normal file
79
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Silf
Normal file
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00">
|
||||
|
||||
<Silf>
|
||||
<!-- Attributes starting with _ are informative only -->
|
||||
<version compilerVersion="0" compressionScheme="0" version="2.0"/>
|
||||
<silf>
|
||||
<info direction="1" extraAscent="0" extraDescent="0" flags="4" lbGID="6" maxCompPerLig="0" maxGlyphID="7" numLigComp="0" numUserDefn="0"/>
|
||||
<passindexes iBidi="255" iJust="1" iPos="1" iSubst="0"/>
|
||||
<contexts maxPostContext="0" maxPreContext="0"/>
|
||||
<attributes attCollisions="0" attrBreakWeight="2" attrDirectionality="3" attrMirroring="4" attrPseudo="0" attrSkipPasses="1"/>
|
||||
<classes>
|
||||
<linearClasses>
|
||||
<linear _index="0">
|
||||
c
|
||||
</linear>
|
||||
</linearClasses>
|
||||
<nonLinearClasses>
|
||||
</nonLinearClasses>
|
||||
</classes>
|
||||
<passes>
|
||||
<pass _index="0">
|
||||
<info collisionThreshold="0" flags="0" maxBackup="0" maxRuleContext="3" maxRuleLoop="5" maxRulePreContext="1" minRulePreContext="0"/>
|
||||
<fsminfo numColumns="3" numRows="6" numSuccess="2" numTransitional="5"/>
|
||||
<colmap>
|
||||
.notdef=0 space=0 a=1 b=2 c=0
|
||||
</colmap>
|
||||
<staterulemap>
|
||||
<state number="4" rules="1"/>
|
||||
<state number="5" rules="0"/>
|
||||
</staterulemap>
|
||||
<rules>
|
||||
<rule index="0" precontext="0" sortkey="2">
|
||||
<action>
|
||||
</action>
|
||||
</rule>
|
||||
<rule index="1" precontext="1" sortkey="2">
|
||||
<action>
|
||||
PUT_GLYPH_8BIT_OBS(0)
|
||||
NEXT
|
||||
RET_ZERO
|
||||
</action>
|
||||
</rule>
|
||||
</rules>
|
||||
<fsm>
|
||||
<starts>0 1</starts>
|
||||
<row _i="0">1 1 2</row>
|
||||
<row _i="1">0 3 0</row>
|
||||
<row _i="2">0 4 0</row>
|
||||
<row _i="3">0 0 5</row>
|
||||
<row _i="4">0 0 5</row>
|
||||
</fsm>
|
||||
</pass>
|
||||
<pass _index="1">
|
||||
<info collisionThreshold="10" flags="0" maxBackup="0" maxRuleContext="2" maxRuleLoop="5" maxRulePreContext="0" minRulePreContext="0"/>
|
||||
<fsminfo numColumns="2" numRows="3" numSuccess="1" numTransitional="2"/>
|
||||
<colmap>
|
||||
a=0 c=1
|
||||
</colmap>
|
||||
<staterulemap>
|
||||
<state number="2" rules="0"/>
|
||||
</staterulemap>
|
||||
<rules>
|
||||
<rule index="0" precontext="0" sortkey="2">
|
||||
<action>
|
||||
</action>
|
||||
</rule>
|
||||
</rules>
|
||||
<fsm>
|
||||
<starts>0</starts>
|
||||
<row _i="0">1 0</row>
|
||||
<row _i="1">0 2</row>
|
||||
</fsm>
|
||||
</pass>
|
||||
</passes>
|
||||
</silf>
|
||||
</Silf>
|
||||
|
||||
</ttFont>
|
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.15">
|
||||
|
||||
<GlyphOrder>
|
||||
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
|
||||
<GlyphID id="0" name=".notdef"/>
|
||||
<GlyphID id="1" name="space"/>
|
||||
<GlyphID id="2" name="a"/>
|
||||
<GlyphID id="3" name="b"/>
|
||||
<GlyphID id="4" name="c"/>
|
||||
</GlyphOrder>
|
||||
|
||||
<maxp>
|
||||
<!-- Most of this table will be recalculated by the compiler -->
|
||||
<tableVersion value="0x10000"/>
|
||||
<numGlyphs value="5"/>
|
||||
<maxPoints value="0"/>
|
||||
<maxContours value="0"/>
|
||||
<maxCompositePoints value="0"/>
|
||||
<maxCompositeContours value="0"/>
|
||||
<maxZones value="2"/>
|
||||
<maxTwilightPoints value="8"/>
|
||||
<maxStorage value="64"/>
|
||||
<maxFunctionDefs value="10"/>
|
||||
<maxInstructionDefs value="0"/>
|
||||
<maxStackElements value="299"/>
|
||||
<maxSizeOfInstructions value="207"/>
|
||||
<maxComponentElements value="0"/>
|
||||
<maxComponentDepth value="0"/>
|
||||
</maxp>
|
||||
|
||||
<cmap>
|
||||
<tableVersion version="0"/>
|
||||
<cmap_format_4 platformID="3" platEncID="1" language="0">
|
||||
<map code="0x20" name="space"/>
|
||||
<map code="0x61" name="a"/>
|
||||
<map code="0x62" name="b"/>
|
||||
<map code="0x63" name="c"/>
|
||||
</cmap_format_4>
|
||||
</cmap>
|
||||
|
||||
<!--
|
||||
<Gloc>
|
||||
<attributes number="8"/>
|
||||
</Gloc>
|
||||
-->
|
||||
</ttFont>
|
||||
|
12
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Sill
Normal file
12
Tests/ttLib/tables/data/graphite/graphite_tests.ttx.Sill
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ttFont sfntVersion="\x00\x01\x00\x00">
|
||||
|
||||
<Sill>
|
||||
<version version="1.0"/>
|
||||
<lang name="fred">
|
||||
<feature fid="yesm" val="1"/>
|
||||
<feature fid="nom " val="0"/>
|
||||
</lang>
|
||||
</Sill>
|
||||
|
||||
</ttFont>
|
@ -229,6 +229,7 @@ TESTS = {
|
||||
"aots/lookupflag_ignore_combination_f1.otf": ('GDEF', 'GSUB'),
|
||||
"aots/lookupflag_ignore_ligatures_f1.otf": ('GDEF', 'GSUB'),
|
||||
"aots/lookupflag_ignore_marks_f1.otf": ('GDEF', 'GSUB'),
|
||||
"graphite/graphite_tests.ttf": ('Silf', 'Glat', 'Feat', 'Sill'),
|
||||
}
|
||||
|
||||
|
||||
@ -303,6 +304,11 @@ def test_xml_from_xml(testfile, tableTag):
|
||||
xml_expected = read_expected_ttx(testfile, tableTag)
|
||||
|
||||
font = load_ttx(xml_expected)
|
||||
name = os.path.splitext(testfile)[0]
|
||||
setupfile = getpath("%s.ttx.%s.setup" % (name, tagToXML(tableTag)))
|
||||
if os.path.exists(setupfile):
|
||||
# import pdb; pdb.set_trace()
|
||||
font.importXML(setupfile)
|
||||
xml_from_xml = dump_ttx(font, tableTag)
|
||||
|
||||
assert xml_expected == xml_from_xml
|
||||
|
Loading…
x
Reference in New Issue
Block a user