From 1ca554332c9f1aa9c5737640aabae84d555a9a69 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Wed, 7 Jun 2023 18:05:48 +0100 Subject: [PATCH] _getCoordinatesAndControls: make sure coords are rounded toInt() as gvar expects ufo2ft will no longer send varLib already-rounded master glyf tables (to give it an opportunity to compute implied oncurves on the pre-rounded coords) so when retrieving coordinates off the glyf table in order to compute gvar deltas we have to round --- Lib/fontTools/ttLib/tables/_g_l_y_f.py | 6 +++++- Tests/varLib/instancer/instancer_test.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index b953061d9..3493ca974 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -369,7 +369,9 @@ class table__g_l_y_f(DefaultTable.DefaultTable): (0, bottomSideY), ] - def _getCoordinatesAndControls(self, glyphName, hMetrics, vMetrics=None): + def _getCoordinatesAndControls( + self, glyphName, hMetrics, vMetrics=None, roundCoordinates=True + ): """Return glyph coordinates and controls as expected by "gvar" table. The coordinates includes four "phantom points" for the glyph metrics, @@ -442,6 +444,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable): # Add phantom points for (left, right, top, bottom) positions. phantomPoints = self._getPhantomPoints(glyphName, hMetrics, vMetrics) coords.extend(phantomPoints) + if roundCoordinates: + coords.toInt() return coords, controls def _setCoordinates(self, glyphName, coord, hMetrics, vMetrics=None): diff --git a/Tests/varLib/instancer/instancer_test.py b/Tests/varLib/instancer/instancer_test.py index 499f9d4f0..e574384de 100644 --- a/Tests/varLib/instancer/instancer_test.py +++ b/Tests/varLib/instancer/instancer_test.py @@ -51,8 +51,15 @@ def fvarAxes(): def _get_coordinates(varfont, glyphname): # converts GlyphCoordinates to a list of (x, y) tuples, so that pytest's # assert will give us a nicer diff - with pytest.deprecated_call(): - return list(varfont["glyf"].getCoordinatesAndControls(glyphname, varfont)[0]) + return list( + varfont["glyf"]._getCoordinatesAndControls( + glyphname, + varfont["hmtx"].metrics, + varfont["vmtx"].metrics, + # the tests expect float coordinates + roundCoordinates=False, + )[0] + ) class InstantiateGvarTest(object):