[ttLib.glyf] Fix flag bug in glyph.drawPoints() (#1774)

This was the same problem as glyph.draw() had, as reported in #1771.
This commit is contained in:
Just van Rossum 2019-12-08 21:55:30 +01:00 committed by GitHub
parent a4b0992472
commit e2c60e3dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -1230,7 +1230,7 @@ class Glyph(object):
# Start with the appropriate segment type based on the final segment
segmentType = "line" if cFlags[-1] == 1 else "qcurve"
for i, pt in enumerate(contour):
if cFlags[i] == 1:
if cFlags[i] & flagOnCurve == 1:
pen.addPoint(pt, segmentType=segmentType)
segmentType = "line"
else:

View File

@ -2,7 +2,7 @@ from fontTools.misc.py23 import *
from fontTools.misc.fixedTools import otRound
from fontTools.misc.testTools import getXML, parseXML
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.pens.recordingPen import RecordingPen
from fontTools.pens.recordingPen import RecordingPen, RecordingPointPen
from fontTools.ttLib import TTFont, newTable, TTLibError
from fontTools.ttLib.tables._g_l_y_f import (
GlyphCoordinates,
@ -311,6 +311,24 @@ class glyfTableTest(unittest.TestCase):
('closePath', ())]
self.assertEqual(pen.value, expected)
def test_bit6_draw_to_pointpen(self):
# https://github.com/fonttools/fonttools/issues/1771
font = TTFont(sfntVersion="\x00\x01\x00\x00")
# glyph00003 contains a bit 6 flag on the first point
# which triggered the issue
font.importXML(GLYF_TTX)
glyfTable = font['glyf']
pen = RecordingPointPen()
glyfTable["glyph00003"].drawPoints(pen, glyfTable=glyfTable)
expected = [
('beginPath', (), {}),
('addPoint', ((501, 1430), 'line', False, None), {}),
('addPoint', ((683, 1430), 'line', False, None), {}),
('addPoint', ((1172, 0), 'line', False, None), {}),
('addPoint', ((983, 0), 'line', False, None), {}),
]
self.assertEqual(pen.value[:len(expected)], expected)
class GlyphComponentTest: