From b9ac90a8f912ad3044bda592b4ff4177475d74a8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Mar 2015 15:29:35 -0700 Subject: [PATCH] [GX] Add 'fvar' table support I might change the table format in the future, but it's functional now. --- Doc/documentation.html | 2 +- Lib/fontTools/ttLib/tables/__init__.py | 1 + Lib/fontTools/ttLib/tables/otConverters.py | 64 +++++++++++++--------- Lib/fontTools/ttLib/tables/otData.py | 35 ++++++++++++ 4 files changed, 74 insertions(+), 28 deletions(-) diff --git a/Doc/documentation.html b/Doc/documentation.html index b0f8d56df..0aae7322e 100644 --- a/Doc/documentation.html +++ b/Doc/documentation.html @@ -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:
-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
Other tables are dumped as hexadecimal data. diff --git a/Lib/fontTools/ttLib/tables/__init__.py b/Lib/fontTools/ttLib/tables/__init__.py index 04a479f94..6b13f3e6e 100644 --- a/Lib/fontTools/ttLib/tables/__init__.py +++ b/Lib/fontTools/ttLib/tables/__init__.py @@ -42,6 +42,7 @@ def _moduleFinderHint(): from . import _c_v_t from . import _f_e_a_t from . import _f_p_g_m + from . import _f_v_a_r from . import _g_a_s_p from . import _g_l_y_f from . import _h_d_m_x diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py index b90493146..56775a540 100644 --- a/Lib/fontTools/ttLib/tables/otConverters.py +++ b/Lib/fontTools/ttLib/tables/otConverters.py @@ -62,7 +62,7 @@ class BaseConverter(object): self.tableClass = tableClass self.isCount = name.endswith("Count") 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): """Read a value from the reader.""" @@ -104,32 +104,6 @@ class ULong(IntValue): def write(self, writer, font, tableDict, value, repeatIndex=None): 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): def read(self, reader, font, tableDict): return reader.readShort() @@ -181,6 +155,41 @@ class DeciPoints(FloatValue): def write(self, writer, font, tableDict, value, repeatIndex=None): 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): def read(self, reader, font, tableDict): @@ -383,6 +392,7 @@ converterMapping = { "Tag": Tag, "GlyphID": GlyphID, "DeciPoints": DeciPoints, + "Fixed": Fixed, "struct": Struct, "Offset": Table, "LOffset": LTable, diff --git a/Lib/fontTools/ttLib/tables/otData.py b/Lib/fontTools/ttLib/tables/otData.py index f6a73bdf9..c2d84b682 100644 --- a/Lib/fontTools/ttLib/tables/otData.py +++ b/Lib/fontTools/ttLib/tables/otData.py @@ -1017,4 +1017,39 @@ otData = [ ('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.'), + ]), + ]