[GX] Add 'fvar' table support

I might change the table format in the future, but it's functional now.
This commit is contained in:
Behdad Esfahbod 2015-03-11 15:29:35 -07:00
parent 61cda14c1b
commit b9ac90a8f9
4 changed files with 74 additions and 28 deletions

View File

@ -42,7 +42,7 @@ When using TTX from the command line there are a bunch of extra options, these a
The following tables are currently supported: The following tables are currently supported:
<BLOCKQUOTE><TT> <BLOCKQUOTE><TT>
<!-- begin table list --> <!-- begin table list -->
BASE, CBDT, CBLC, CFF, COLR, CPAL, DSIG, EBDT, EBLC, FFTM, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, MATH, META, OS/2, SING, SVG, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VDMX, VORG, cmap, cvt, feat, fpgm, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, maxp, name, post, prep, sbix, vhea and vmtx BASE, CBDT, CBLC, CFF, COLR, CPAL, DSIG, EBDT, EBLC, FFTM, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, MATH, META, OS/2, SING, SVG, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VDMX, VORG, cmap, cvt, feat, fpgm, fvar, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, maxp, name, post, prep, sbix, vhea and vmtx
<!-- end table list --> <!-- end table list -->
</TT></BLOCKQUOTE> </TT></BLOCKQUOTE>
Other tables are dumped as hexadecimal data. Other tables are dumped as hexadecimal data.

View File

@ -42,6 +42,7 @@ def _moduleFinderHint():
from . import _c_v_t from . import _c_v_t
from . import _f_e_a_t from . import _f_e_a_t
from . import _f_p_g_m from . import _f_p_g_m
from . import _f_v_a_r
from . import _g_a_s_p from . import _g_a_s_p
from . import _g_l_y_f from . import _g_l_y_f
from . import _h_d_m_x from . import _h_d_m_x

View File

@ -62,7 +62,7 @@ class BaseConverter(object):
self.tableClass = tableClass self.tableClass = tableClass
self.isCount = name.endswith("Count") self.isCount = name.endswith("Count")
self.isLookupType = name.endswith("LookupType") self.isLookupType = name.endswith("LookupType")
self.isPropagated = name in ["ClassCount", "Class2Count", "FeatureTag", "SettingsCount"] self.isPropagated = name in ["ClassCount", "Class2Count", "FeatureTag", "SettingsCount", "AxisCount"]
def read(self, reader, font, tableDict): def read(self, reader, font, tableDict):
"""Read a value from the reader.""" """Read a value from the reader."""
@ -104,32 +104,6 @@ class ULong(IntValue):
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):
writer.writeULong(value) writer.writeULong(value)
class Version(BaseConverter):
def read(self, reader, font, tableDict):
value = reader.readLong()
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
return fi2fl(value, 16)
def write(self, writer, font, tableDict, value, repeatIndex=None):
if value < 0x10000:
value = fl2fi(value, 16)
value = int(round(value))
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
writer.writeLong(value)
def xmlRead(self, attrs, content, font):
value = attrs["value"]
value = float(int(value, 0)) if value.startswith("0") else float(value)
if value >= 0x10000:
value = fi2fl(value, 16)
return value
def xmlWrite(self, xmlWriter, font, value, name, attrs):
if value >= 0x10000:
value = fi2fl(value, 16)
if value % 1 != 0:
# Write as hex
value = "0x%08x" % fl2fi(value, 16)
xmlWriter.simpletag(name, attrs + [("value", value)])
xmlWriter.newline()
class Short(IntValue): class Short(IntValue):
def read(self, reader, font, tableDict): def read(self, reader, font, tableDict):
return reader.readShort() return reader.readShort()
@ -181,6 +155,41 @@ class DeciPoints(FloatValue):
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):
writer.writeUShort(int(round(value * 10))) writer.writeUShort(int(round(value * 10)))
class Fixed(FloatValue):
def read(self, reader, font, tableDict):
value = reader.readLong()
return fi2fl(value, 16)
def write(self, writer, font, tableDict, value, repeatIndex=None):
value = fl2fi(value, 16)
writer.writeLong(value)
class Version(BaseConverter):
def read(self, reader, font, tableDict):
value = reader.readLong()
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
return fi2fl(value, 16)
def write(self, writer, font, tableDict, value, repeatIndex=None):
if value < 0x10000:
value = fl2fi(value, 16)
value = int(round(value))
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
writer.writeLong(value)
def xmlRead(self, attrs, content, font):
value = attrs["value"]
value = float(int(value, 0)) if value.startswith("0") else float(value)
if value >= 0x10000:
value = fi2fl(value, 16)
return value
def xmlWrite(self, xmlWriter, font, value, name, attrs):
if value >= 0x10000:
value = fi2fl(value, 16)
if value % 1 != 0:
# Write as hex
value = "0x%08x" % fl2fi(value, 16)
xmlWriter.simpletag(name, attrs + [("value", value)])
xmlWriter.newline()
class Struct(BaseConverter): class Struct(BaseConverter):
def read(self, reader, font, tableDict): def read(self, reader, font, tableDict):
@ -383,6 +392,7 @@ converterMapping = {
"Tag": Tag, "Tag": Tag,
"GlyphID": GlyphID, "GlyphID": GlyphID,
"DeciPoints": DeciPoints, "DeciPoints": DeciPoints,
"Fixed": Fixed,
"struct": Struct, "struct": Struct,
"Offset": Table, "Offset": Table,
"LOffset": LTable, "LOffset": LTable,

View File

@ -1017,4 +1017,39 @@ otData = [
('uint16', 'SettingNameID', None, None, 'The name table index for the setting name.'), ('uint16', 'SettingNameID', None, None, 'The name table index for the setting name.'),
]), ]),
##
## Apple TrueType GX tables
##
#
# fvar
#
('fvar', [
('Version', 'Version', None, None, 'Version of the fvar table-initially set to 0x00010000.'),
('uint16', 'OffsetToData', None, None, 'Set to 16.'),
('uint16', 'CountSizePairs', None, None, 'Set to 2.'),
('uint16', 'AxisCount', None, None, 'Number of style axes in this font.'),
('uint16', 'AxisSize', None, None, 'Set to 20.'),
('uint16', 'InstanceCount', None, None, 'Number of named instances in this font.'),
('uint16', 'InstanceSize', None, None, 'Number of bytes in each instance.'),
('VariationAxis', 'VariationAxis', 'AxisCount', 0, 'The variation axes array.'),
('NamedInstance', 'NamedInstance', 'InstanceCount', 0, 'The named instances array.'),
]),
('VariationAxis', [
('Tag', 'AxisTag', None, None, '4-byte AxisTag identifier'),
('Fixed', 'MinValue', None, None, 'The minimum style coordinate for the axis.'),
('Fixed', 'DefaultValue', None, None, 'The default style coordinate for the axis.'),
('Fixed', 'MaxValue', None, None, 'The maximum style coordinate for the axis.'),
('uint16', 'Flags', None, None, 'Set to zero.'),
('uint16', 'NameID', None, None, 'The name table index for the setting name.'),
]),
('NamedInstance', [
('uint16', 'NameID', None, None, 'The name table index for the instance name.'),
('uint16', 'Flags', None, None, 'Set to zero.'),
('Fixed', 'Coords', 'AxisCount', 0, 'The maximum style coordinate for the axis.'),
]),
] ]