[AAT] Support prop table with glyph properties

This commit is contained in:
Sascha Brawer 2017-08-17 18:52:21 +02:00
parent 549eef81b3
commit d05617b4bd
6 changed files with 116 additions and 3 deletions

View File

@ -73,6 +73,7 @@ def _moduleFinderHint():
from . import _n_a_m_e
from . import _p_o_s_t
from . import _p_r_e_p
from . import _p_r_o_p
from . import _s_b_i_x
from . import _t_r_a_k
from . import _v_h_e_a

View File

@ -0,0 +1,8 @@
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from .otBase import BaseTTXConverter
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6prop.html
class table__p_r_o_p(BaseTTXConverter):
pass

View File

@ -782,7 +782,6 @@ class FormatSwitchingBaseTable(BaseTable):
def readFormat(self, reader):
self.Format = reader.readUShort()
assert self.Format != 0, (self, reader.pos, len(reader.data))
def writeFormat(self, writer):
writer.writeUShort(self.Format)

View File

@ -1318,4 +1318,25 @@ otData = [
# If the 'morx' table version is 3 or greater, then the last subtable in the chain is followed by a subtableGlyphCoverageArray, as described below.
# ('Offset', 'MarkGlyphSetsDef', None, 'int(round(Version*0x10000)) >= 0x00010002', 'Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)'),
#
# prop
#
('prop', [
('Fixed', 'Version', None, None, 'Version number of the AAT glyphs property table. Version 1.0 is the initial table version. Version 2.0, which is recognized by macOS 8.5 and later, adds support for the “attaches on right” bit. Version 3.0, which gets recognized by macOS X and iOS, adds support for the additional directional properties defined in Unicode 3.0.'),
('struct', 'GlyphProperties', None, None, 'Glyph properties.'),
]),
('GlyphPropertiesFormat0', [
('uint16', 'Format', None, None, 'Format, = 0.'),
('uint16', 'DefaultProperties', None, None, 'Default properties applied to a glyph. Since there is no lookup table in prop format 0, the default properties get applied to every glyph in the font.'),
]),
('GlyphPropertiesFormat1', [
('uint16', 'Format', None, None, 'Format, = 1.'),
('uint16', 'DefaultProperties', None, None, 'Default properties applied to a glyph if that glyph is not present in the Properties lookup table.'),
('AATLookup(uint16)', 'Properties', None, None, 'Lookup data associating glyphs with their properties.'),
]),
]

View File

@ -102,8 +102,8 @@ The following tables are currently supported:
OS/2, SING, STAT, SVG, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID,
TSIJ, TSIP, TSIS, TSIV, TTFA, VDMX, VORG, VVAR, avar, cmap, cvar,
cvt, feat, fpgm, fvar, gasp, glyf, gvar, hdmx, head, hhea, hmtx,
kern, lcar, loca, ltag, maxp, meta, name, post, prep, sbix, trak,
vhea and vmtx
kern, lcar, loca, ltag, maxp, meta, name, post, prep, prop, sbix,
trak, vhea and vmtx
.. end table list
Other tables are dumped as hexadecimal data.

View File

@ -0,0 +1,84 @@
from __future__ import print_function, division, absolute_import, unicode_literals
from fontTools.misc.py23 import *
from fontTools.misc.testTools import FakeFont, getXML, parseXML
from fontTools.misc.textTools import deHexStr, hexStr
from fontTools.ttLib import newTable
import unittest
PROP_FORMAT_0_DATA = deHexStr(
'0001 0000 0000 ' # 0: Version=1.0, Format=0
'0005 ' # 6: DefaultProperties=European number terminator
) # 8: <end>
assert(len(PROP_FORMAT_0_DATA) == 8)
PROP_FORMAT_0_XML = [
'<Version value="1.0"/>',
'<GlyphProperties Format="0">',
' <DefaultProperties value="5"/>',
'</GlyphProperties>',
]
PROP_FORMAT_1_DATA = deHexStr(
'0003 0000 0001 ' # 0: Version=3.0, Format=1
'0000 ' # 6: DefaultProperties=left-to-right; non-whitespace
'0008 0003 0004 ' # 8: LookupFormat=8, FirstGlyph=3, GlyphCount=4
'000B ' # 14: Properties[C]=other neutral
'000A ' # 16: Properties[D]=whitespace
'600B ' # 18: Properties[E]=other neutral; hanging punct
'0005 ' # 20: Properties[F]=European number terminator
) # 22: <end>
assert(len(PROP_FORMAT_1_DATA) == 22)
PROP_FORMAT_1_XML = [
'<Version value="3.0"/>',
'<GlyphProperties Format="1">',
' <DefaultProperties value="0"/>',
' <Properties>',
' <Lookup glyph="C" value="11"/>',
' <Lookup glyph="D" value="10"/>',
' <Lookup glyph="E" value="24587"/>',
' <Lookup glyph="F" value="5"/>',
' </Properties>',
'</GlyphProperties>',
]
class PROPTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.maxDiff = None
cls.font = FakeFont(['.notdef', 'A', 'B', 'C', 'D', 'E', 'F', 'G'])
def test_decompile_toXML_format0(self):
table = newTable('prop')
table.decompile(PROP_FORMAT_0_DATA, self.font)
self.assertEqual(getXML(table.toXML), PROP_FORMAT_0_XML)
def test_compile_fromXML_format0(self):
table = newTable('prop')
for name, attrs, content in parseXML(PROP_FORMAT_0_XML):
table.fromXML(name, attrs, content, font=self.font)
self.assertEqual(hexStr(table.compile(self.font)),
hexStr(PROP_FORMAT_0_DATA))
def test_decompile_toXML_format1(self):
table = newTable('prop')
table.decompile(PROP_FORMAT_1_DATA, self.font)
self.assertEqual(getXML(table.toXML), PROP_FORMAT_1_XML)
def test_compile_fromXML_format1(self):
table = newTable('prop')
for name, attrs, content in parseXML(PROP_FORMAT_1_XML):
table.fromXML(name, attrs, content, font=self.font)
self.assertEqual(hexStr(table.compile(self.font)),
hexStr(PROP_FORMAT_1_DATA))
if __name__ == '__main__':
import sys
sys.exit(unittest.main())