[cu2quPen] Remove deprecated ignore_single_points

This commit is contained in:
Behdad Esfahbod 2023-02-17 11:09:33 -07:00
parent 3a3b8af154
commit 64bce6fc9b
2 changed files with 7 additions and 76 deletions

View File

@ -31,13 +31,6 @@ class Cu2QuPen(AbstractPen):
value equal, or close to UPEM / 1000.
reverse_direction: flip the contours' direction but keep starting point.
stats: a dictionary counting the point numbers of quadratic segments.
ignore_single_points: don't emit contours containing only a single point
NOTE: The "ignore_single_points" argument is deprecated since v1.3.0,
which dropped Robofab support. It's no longer needed to special-case
UFO2-style anchors (aka "named points") when using ufoLib >= 2.0,
as these are no longer drawn onto pens as single-point contours,
but are handled separately as anchors.
"""
def __init__(
@ -46,7 +39,6 @@ class Cu2QuPen(AbstractPen):
max_err,
reverse_direction=False,
stats=None,
ignore_single_points=False,
):
if reverse_direction:
self.pen = ReverseContourPen(other_pen)
@ -54,17 +46,6 @@ class Cu2QuPen(AbstractPen):
self.pen = other_pen
self.max_err = max_err
self.stats = stats
if ignore_single_points:
import warnings
warnings.warn(
"ignore_single_points is deprecated and "
"will be removed in future versions",
UserWarning,
stacklevel=2,
)
self.ignore_single_points = ignore_single_points
self.start_pt = None
self.current_pt = None
def _check_contour_is_open(self):
@ -75,20 +56,14 @@ class Cu2QuPen(AbstractPen):
if self.current_pt is not None:
raise AssertionError("closePath or endPath is required")
def _add_moveTo(self):
if self.start_pt is not None:
self.pen.moveTo(self.start_pt)
self.start_pt = None
def moveTo(self, pt):
self._check_contour_is_closed()
self.start_pt = self.current_pt = pt
if not self.ignore_single_points:
self._add_moveTo()
self.current_pt = pt
self.pen.moveTo(pt)
self.current_pt = pt
def lineTo(self, pt):
self._check_contour_is_open()
self._add_moveTo()
self.pen.lineTo(pt)
self.current_pt = pt
@ -98,7 +73,6 @@ class Cu2QuPen(AbstractPen):
if n == 1:
self.lineTo(points[0])
elif n > 1:
self._add_moveTo()
self.pen.qCurveTo(*points)
self.current_pt = points[-1]
else:
@ -130,16 +104,13 @@ class Cu2QuPen(AbstractPen):
def closePath(self):
self._check_contour_is_open()
if self.start_pt is None:
# if 'start_pt' is _not_ None, we are ignoring single-point paths
self.pen.closePath()
self.current_pt = self.start_pt = None
self.current_pt = None
def endPath(self):
self._check_contour_is_open()
if self.start_pt is None:
self.pen.endPath()
self.current_pt = self.start_pt = None
self.current_pt = None
def addComponent(self, glyphName, transformation):
self._check_contour_is_closed()

View File

@ -271,46 +271,6 @@ class TestCu2QuPen(unittest.TestCase, _TestPenMixin):
],
)
def test_ignore_single_points(self):
pen = DummyPen()
try:
logging.captureWarnings(True)
with CapturingLogHandler("py.warnings", level="WARNING") as log:
quadpen = Cu2QuPen(pen, MAX_ERR, ignore_single_points=True)
finally:
logging.captureWarnings(False)
quadpen.moveTo((0, 0))
quadpen.endPath()
quadpen.moveTo((1, 1))
quadpen.closePath()
self.assertGreaterEqual(len(log.records), 1)
if sys.version_info < (3, 11):
self.assertIn("ignore_single_points is deprecated", log.records[0].args[0])
else:
self.assertIn("ignore_single_points is deprecated", log.records[0].msg)
# single-point contours were ignored, so the pen commands are empty
self.assertFalse(pen.commands)
# redraw without ignoring single points
quadpen.ignore_single_points = False
quadpen.moveTo((0, 0))
quadpen.endPath()
quadpen.moveTo((1, 1))
quadpen.closePath()
self.assertTrue(pen.commands)
self.assertEqual(
str(pen).splitlines(),
[
"pen.moveTo((0, 0))",
"pen.endPath()",
"pen.moveTo((1, 1))",
"pen.closePath()",
],
)
class TestCu2QuPointPen(unittest.TestCase, _TestPenMixin):
def __init__(self, *args, **kwargs):