Revert ABC changes to Pens, fixes #2198
This commit is contained in:
parent
4de2a4076b
commit
2429a187fc
@ -36,7 +36,6 @@ Coordinates are usually expressed as (x, y) tuples, but generally any
|
|||||||
sequence of length 2 will do.
|
sequence of length 2 will do.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import abc
|
|
||||||
from typing import Any, Tuple
|
from typing import Any, Tuple
|
||||||
|
|
||||||
from fontTools.misc.loggingTools import LogMixin
|
from fontTools.misc.loggingTools import LogMixin
|
||||||
@ -45,42 +44,18 @@ __all__ = ["AbstractPen", "NullPen", "BasePen",
|
|||||||
"decomposeSuperBezierSegment", "decomposeQuadraticSegment"]
|
"decomposeSuperBezierSegment", "decomposeQuadraticSegment"]
|
||||||
|
|
||||||
|
|
||||||
class AbstractPen(abc.ABC):
|
class AbstractPen:
|
||||||
@classmethod
|
|
||||||
def __subclasshook__(cls, subclass: Any) -> bool:
|
|
||||||
if cls is not AbstractPen:
|
|
||||||
return NotImplemented
|
|
||||||
return (
|
|
||||||
hasattr(subclass, "moveTo")
|
|
||||||
and callable(subclass.moveTo)
|
|
||||||
and hasattr(subclass, "lineTo")
|
|
||||||
and callable(subclass.lineTo)
|
|
||||||
and hasattr(subclass, "curveTo")
|
|
||||||
and callable(subclass.curveTo)
|
|
||||||
and hasattr(subclass, "qCurveTo")
|
|
||||||
and callable(subclass.qCurveTo)
|
|
||||||
and hasattr(subclass, "closePath")
|
|
||||||
and callable(subclass.closePath)
|
|
||||||
and hasattr(subclass, "endPath")
|
|
||||||
and callable(subclass.endPath)
|
|
||||||
and hasattr(subclass, "addComponent")
|
|
||||||
and callable(subclass.addComponent)
|
|
||||||
or NotImplemented
|
|
||||||
)
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def moveTo(self, pt: Tuple[float, float]) -> None:
|
def moveTo(self, pt: Tuple[float, float]) -> None:
|
||||||
"""Begin a new sub path, set the current point to 'pt'. You must
|
"""Begin a new sub path, set the current point to 'pt'. You must
|
||||||
end each sub path with a call to pen.closePath() or pen.endPath().
|
end each sub path with a call to pen.closePath() or pen.endPath().
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def lineTo(self, pt: Tuple[float, float]) -> None:
|
def lineTo(self, pt: Tuple[float, float]) -> None:
|
||||||
"""Draw a straight line from the current point to 'pt'."""
|
"""Draw a straight line from the current point to 'pt'."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def curveTo(self, *points: Tuple[float, float]) -> None:
|
def curveTo(self, *points: Tuple[float, float]) -> None:
|
||||||
"""Draw a cubic bezier with an arbitrary number of control points.
|
"""Draw a cubic bezier with an arbitrary number of control points.
|
||||||
|
|
||||||
@ -102,7 +77,6 @@ class AbstractPen(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def qCurveTo(self, *points: Tuple[float, float]) -> None:
|
def qCurveTo(self, *points: Tuple[float, float]) -> None:
|
||||||
"""Draw a whole string of quadratic curve segments.
|
"""Draw a whole string of quadratic curve segments.
|
||||||
|
|
||||||
@ -120,21 +94,18 @@ class AbstractPen(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def closePath(self) -> None:
|
def closePath(self) -> None:
|
||||||
"""Close the current sub path. You must call either pen.closePath()
|
"""Close the current sub path. You must call either pen.closePath()
|
||||||
or pen.endPath() after each sub path.
|
or pen.endPath() after each sub path.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def endPath(self) -> None:
|
def endPath(self) -> None:
|
||||||
"""End the current sub path, but don't close it. You must call
|
"""End the current sub path, but don't close it. You must call
|
||||||
either pen.closePath() or pen.endPath() after each sub path.
|
either pen.closePath() or pen.endPath() after each sub path.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def addComponent(
|
def addComponent(
|
||||||
self,
|
self,
|
||||||
glyphName: str,
|
glyphName: str,
|
||||||
|
@ -12,7 +12,6 @@ This allows the caller to provide more data for each point.
|
|||||||
For instance, whether or not a point is smooth, and its name.
|
For instance, whether or not a point is smooth, and its name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import abc
|
|
||||||
import math
|
import math
|
||||||
from typing import Any, List, Optional, Tuple
|
from typing import Any, List, Optional, Tuple
|
||||||
|
|
||||||
@ -28,36 +27,17 @@ __all__ = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class AbstractPointPen(abc.ABC):
|
class AbstractPointPen:
|
||||||
"""Baseclass for all PointPens."""
|
"""Baseclass for all PointPens."""
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def __subclasshook__(cls, subclass: Any) -> bool:
|
|
||||||
if cls is not AbstractPointPen:
|
|
||||||
return NotImplemented
|
|
||||||
return (
|
|
||||||
hasattr(subclass, "beginPath")
|
|
||||||
and callable(subclass.beginPath)
|
|
||||||
and hasattr(subclass, "endPath")
|
|
||||||
and callable(subclass.endPath)
|
|
||||||
and hasattr(subclass, "addPoint")
|
|
||||||
and callable(subclass.addPoint)
|
|
||||||
and hasattr(subclass, "addComponent")
|
|
||||||
and callable(subclass.addComponent)
|
|
||||||
or NotImplemented
|
|
||||||
)
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def beginPath(self, identifier: Optional[str] = None, **kwargs: Any) -> None:
|
def beginPath(self, identifier: Optional[str] = None, **kwargs: Any) -> None:
|
||||||
"""Start a new sub path."""
|
"""Start a new sub path."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def endPath(self) -> None:
|
def endPath(self) -> None:
|
||||||
"""End the current sub path."""
|
"""End the current sub path."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def addPoint(
|
def addPoint(
|
||||||
self,
|
self,
|
||||||
pt: Tuple[float, float],
|
pt: Tuple[float, float],
|
||||||
@ -70,7 +50,6 @@ class AbstractPointPen(abc.ABC):
|
|||||||
"""Add a point to the current sub path."""
|
"""Add a point to the current sub path."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def addComponent(
|
def addComponent(
|
||||||
self,
|
self,
|
||||||
baseGlyphName: str,
|
baseGlyphName: str,
|
||||||
|
@ -5,29 +5,6 @@ from fontTools.misc.loggingTools import CapturingLogHandler
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
def test_subclasshook():
|
|
||||||
class NullPen:
|
|
||||||
def moveTo(self, pt):
|
|
||||||
pass
|
|
||||||
def lineTo(self, pt):
|
|
||||||
pass
|
|
||||||
def curveTo(self, *points):
|
|
||||||
pass
|
|
||||||
def qCurveTo(self, *points):
|
|
||||||
pass
|
|
||||||
def closePath(self):
|
|
||||||
pass
|
|
||||||
def endPath(self):
|
|
||||||
pass
|
|
||||||
def addComponent(self, glyphName, transformation):
|
|
||||||
pass
|
|
||||||
|
|
||||||
assert issubclass(NullPen, AbstractPen)
|
|
||||||
assert isinstance(NullPen(), AbstractPen)
|
|
||||||
assert not issubclass(NullPen, AbstractPointPen)
|
|
||||||
assert not isinstance(NullPen(), AbstractPointPen)
|
|
||||||
|
|
||||||
|
|
||||||
class _TestPen(BasePen):
|
class _TestPen(BasePen):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
BasePen.__init__(self, glyphSet={})
|
BasePen.__init__(self, glyphSet={})
|
||||||
|
@ -5,23 +5,6 @@ from fontTools.pens.pointPen import AbstractPointPen, PointToSegmentPen, \
|
|||||||
SegmentToPointPen, GuessSmoothPointPen, ReverseContourPointPen
|
SegmentToPointPen, GuessSmoothPointPen, ReverseContourPointPen
|
||||||
|
|
||||||
|
|
||||||
def test_subclasshook():
|
|
||||||
class NullPen:
|
|
||||||
def beginPath(self, identifier, **kwargs) -> None:
|
|
||||||
pass
|
|
||||||
def endPath(self) -> None:
|
|
||||||
pass
|
|
||||||
def addPoint(self, pt, segmentType, smooth, name, identifier, **kwargs) -> None:
|
|
||||||
pass
|
|
||||||
def addComponent(self, baseGlyphName, transformation, identifier, **kwargs) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
assert issubclass(NullPen, AbstractPointPen)
|
|
||||||
assert isinstance(NullPen(), AbstractPointPen)
|
|
||||||
assert not issubclass(NullPen, AbstractPen)
|
|
||||||
assert not isinstance(NullPen(), AbstractPen)
|
|
||||||
|
|
||||||
|
|
||||||
class _TestSegmentPen(AbstractPen):
|
class _TestSegmentPen(AbstractPen):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user