From faedfacbae7600063a3cb6eb64ef704e491eab33 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Wed, 25 Oct 2017 11:17:41 +0100 Subject: [PATCH] [reverseContourPen_test] fix expected result for ReverseContourPointPen This test is not normally run. It is skipped when ufoLib is not importable, as it's the case from the test runner's virtual environment. The only reason it exists is so that I could check that the ReverseContourPen I was writing behaves the same as using ufoLib's ReverseContourPointPen when the latter is run through the SegmentToPointPen and PointToSegmentPen converters. The two methods for reversing contours now diverge since https://github.com/fonttools/fonttools/pull/1080, but only nominally because both produce effectively the same results. The only difference is that, when using the point pens with outputImpliedClosingLine=True, the closing lineTo is always there even when it's redundant. In our implmentation, we only output the closing lineTo when it is the same as moveTo (this was necessary in order to fix https://github.com/googlei18n/cu2qu/issues/51) Nevertheless, the total number of points is the same in both cases. Maybe this test should not be here, as it's testing functionalities from a different package. Closes https://github.com/fonttools/fonttools/issues/1081 --- Tests/pens/reverseContourPen_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/pens/reverseContourPen_test.py b/Tests/pens/reverseContourPen_test.py index 41ccfd07e..bace80688 100644 --- a/Tests/pens/reverseContourPen_test.py +++ b/Tests/pens/reverseContourPen_test.py @@ -305,4 +305,15 @@ def test_reverse_point_pen(contour, expected): seg2pt = SegmentToPointPen(revpen) for operator, operands in contour: getattr(seg2pt, operator)(*operands) + + # for closed contours that have a lineTo following the moveTo, + # and whose points don't overlap, our current implementation diverges + # from the ReverseContourPointPen as wrapped by ufoLib's pen converters. + # In the latter case, an extra lineTo is added because of + # outputImpliedClosingLine=True. This is redundant but not incorrect, + # as the number of points is the same in both. + if (contour and contour[-1][0] == "closePath" and + contour[1][0] == "lineTo" and contour[1][1] != contour[0][1]): + expected = expected[:-1] + [("lineTo", contour[0][1])] + expected[-1:] + assert recpen.value == expected