[GX] Leave 'gvar' coordinates unchanged when round-tripping through TTX
Before this change, a rounding issue in fixedToFloat() would sometimes change 'gvar' coordinate values when round-tripping Skia.ttf through TTX. This change works around https://github.com/behdad/fonttools/issues/286.
This commit is contained in:
parent
9dd0a7e4cd
commit
cd8af14991
@ -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
|
||||
|
||||
|
@ -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"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user