diff --git a/Lib/fontTools/ttLib/tables/_g_v_a_r.py b/Lib/fontTools/ttLib/tables/_g_v_a_r.py index 9cb692093..e9f7b1cb3 100644 --- a/Lib/fontTools/ttLib/tables/_g_v_a_r.py +++ b/Lib/fontTools/ttLib/tables/_g_v_a_r.py @@ -2,7 +2,7 @@ from __future__ import print_function, division, absolute_import from fontTools.misc.py23 import * from fontTools import ttLib from fontTools.misc import sstruct -from fontTools.misc.fixedTools import fixedToFloat, floatToFixed +from fontTools.misc.fixedTools import floatToFixed from fontTools.misc.textTools import safeEval from fontTools.ttLib import TTLibError from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates @@ -478,7 +478,10 @@ class GlyphVariation(object): coord = {} pos = offset for axis in axisTags: - coord[axis] = fixedToFloat(struct.unpack(">h", data[pos:pos+2])[0], 14) + # Work around https://github.com/behdad/fonttools/issues/286 + # coord[axis] = fixedToFloat(struct.unpack(">h", data[pos:pos+2])[0], 14) + fixedValue = struct.unpack(">h", data[pos:pos+2])[0] + coord[axis] = float(fixedValue) / (1 << 14) pos += 2 return coord, pos diff --git a/Lib/fontTools/ttLib/tables/_g_v_a_r_test.py b/Lib/fontTools/ttLib/tables/_g_v_a_r_test.py index 33a131c49..2c0fb86fd 100644 --- a/Lib/fontTools/ttLib/tables/_g_v_a_r_test.py +++ b/Lib/fontTools/ttLib/tables/_g_v_a_r_test.py @@ -352,6 +352,14 @@ class GlyphVariationTest(unittest.TestCase): data = deHexStr("DE AD C0 00 20 00 DE AD") self.assertEqual(({"wght": -1.0, "wdth": 0.5}, 6), decompileCoord(["wght", "wdth"], data, 2)) + def test_decompileCoord_roundTrip(self): + # Make sure we are not affected by https://github.com/behdad/fonttools/issues/286 + data = deHexStr("7F B9 80 35") + values, _ = GlyphVariation.decompileCoord_(["wght", "wdth"], data, 0) + axisValues = dict([(axis, (val, val, val)) for axis, val in values.items()]) + gvar = GlyphVariation(axisValues, GlyphCoordinates.zeros(4)) + self.assertEqual("7F B9 80 35", hexencode(gvar.compileCoord(["wght", "wdth"]))) + def test_decompileCoords(self): decompileCoords = GlyphVariation.decompileCoords_ axes = ["wght", "wdth", "opsz"]