Repository: fonttools/fonttools

Issue:
undefined variable in method _synthesizeVMetrics() of class table__g_l_y_f
While fixing issue #2292 I found another one. Variable "topSideBearing" in method _synthesizeVMetrics() is not defined. I' not sure if topSideBearing is ment to be the same as topSideY.


Discussion:

Resolving patch:
diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
--- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py
+++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
@@ -25,6 +25,7 @@
 import os
 from fontTools.misc import xmlWriter
 from fontTools.misc.filenames import userNameToFileName
+from fontTools.misc.loggingTools import deprecateFunction
 
 log = logging.getLogger(__name__)
 
@@ -412,9 +413,13 @@ def _synthesizeVMetrics(self, glyphName, ttFont, defaultVerticalOrigin):
 					topSideY = defaultVerticalOrigin
 				else:
 					topSideY = verticalAdvanceWidth
+			glyph = self[glyphName]
+			glyph.recalcBounds(self)
+			topSideBearing = otRound(topSideY - glyph.yMax)
 			vMetrics = {glyphName: (verticalAdvanceWidth, topSideBearing)}
 		return vMetrics
 
+	@deprecateFunction("use '_getPhantomPoints' instead", category=DeprecationWarning)
 	def getPhantomPoints(self, glyphName, ttFont, defaultVerticalOrigin=None):
 		"""Old public name for self._getPhantomPoints().
 		See: https://github.com/fonttools/fonttools/pull/2266"""
@@ -422,6 +427,7 @@ def getPhantomPoints(self, glyphName, ttFont, defaultVerticalOrigin=None):
 		vMetrics = self._synthesizeVMetrics(glyphName, ttFont, defaultVerticalOrigin)
 		return self._getPhantomPoints(glyphName, hMetrics, vMetrics)
 
+	@deprecateFunction("use '_getCoordinatesAndControls' instead", category=DeprecationWarning)
 	def getCoordinatesAndControls(self, glyphName, ttFont, defaultVerticalOrigin=None):
 		"""Old public name for self._getCoordinatesAndControls().
 		See: https://github.com/fonttools/fonttools/pull/2266"""
@@ -429,6 +435,7 @@ def getCoordinatesAndControls(self, glyphName, ttFont, defaultVerticalOrigin=Non
 		vMetrics = self._synthesizeVMetrics(glyphName, ttFont, defaultVerticalOrigin)
 		return self._getCoordinatesAndControls(glyphName, hMetrics, vMetrics)
 
+	@deprecateFunction("use '_setCoordinates' instead", category=DeprecationWarning)
 	def setCoordinates(self, glyphName, ttFont):
 		"""Old public name for self._setCoordinates().
 		See: https://github.com/fonttools/fonttools/pull/2266"""


Test patch:
diff --git a/Tests/ttLib/tables/_g_l_y_f_test.py b/Tests/ttLib/tables/_g_l_y_f_test.py
--- a/Tests/ttLib/tables/_g_l_y_f_test.py
+++ b/Tests/ttLib/tables/_g_l_y_f_test.py
@@ -362,6 +362,23 @@ def test_decompile_empty_table(self):
         self.assertEqual(font["glyf"][".notdef"].numberOfContours, 0)
         self.assertEqual(font["glyf"]["space"].numberOfContours, 0)
 
+    def test_getPhantomPoints(self):
+        # https://github.com/fonttools/fonttools/issues/2295
+        font = TTFont()
+        glyphNames = [".notdef"]
+        font.setGlyphOrder(glyphNames)
+        font["loca"] = newTable("loca")
+        font["loca"].locations = [0] * (len(glyphNames) + 1)
+        font["glyf"] = newTable("glyf")
+        font["glyf"].decompile(b"\x00", font)
+        font["hmtx"] = newTable("hmtx")
+        font["hmtx"].metrics = {".notdef": (100,0)}
+        font["head"] = newTable("head")
+        font["head"].unitsPerEm = 1000
+        self.assertEqual(
+            font["glyf"].getPhantomPoints(".notdef", font, 0), 
+            [(0, 0), (100, 0), (0, 0), (0, -1000)]
+        )
 
 class GlyphTest: