Skip to content

Fix Any subclassing in fpdf2 #9536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stubs/fpdf2/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ fpdf.fpdf.FPDF.output
fpdf.FPDF.set_creation_date
fpdf.fpdf.FPDF.set_creation_date

# fonttools shims since we can't import it
fpdf._fonttools_shims

# Checking the following function crashes stubtest 0.991, but seems to be
# fixed in later versions.
fpdf.FPDF.set_encryption
Expand Down
52 changes: 52 additions & 0 deletions stubs/fpdf2/fpdf/_fonttools_shims.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# from fontTools.misc.loggingTools
from abc import ABCMeta, abstractmethod
from collections.abc import Mapping
from logging import Logger
from typing import Protocol
from typing_extensions import TypeAlias

# from fonttools.ttLib.ttGlyphSet
class _TTGlyph(Protocol):
def __init__(self, glyphSet: _TTGlyphSet, glyphName: str) -> None: ...
def draw(self, pen) -> None: ...
def drawPoints(self, pen) -> None: ...

_TTGlyphSet: TypeAlias = Mapping[str, _TTGlyph] # Simplified for our needs

# from fontTools.misc.loggingTools

class LogMixin:
@property
def log(self) -> Logger: ...

# from fontTools.pens.basePen
class AbstractPen:
@abstractmethod
def moveTo(self, pt: tuple[float, float]) -> None: ...
@abstractmethod
def lineTo(self, pt: tuple[float, float]) -> None: ...
@abstractmethod
def curveTo(self, *points: tuple[float, float]) -> None: ...
@abstractmethod
def qCurveTo(self, *points: tuple[float, float]) -> None: ...
def closePath(self) -> None: ...
def endPath(self) -> None: ...
@abstractmethod
def addComponent(self, glyphName: str, transformation: tuple[float, float, float, float, float, float]) -> None: ...

class LoggingPen(LogMixin, AbstractPen, metaclass=ABCMeta): ...

class DecomposingPen(LoggingPen, metaclass=ABCMeta):
skipMissingComponents: bool
glyphSet: _TTGlyphSet | None
def __init__(self, glyphSet: _TTGlyphSet | None) -> None: ...
def addComponent(self, glyphName: str, transformation: tuple[float, float, float, float, float, float]) -> None: ...

class BasePen(DecomposingPen):
def __init__(self, glyphSet: _TTGlyphSet | None = ...) -> None: ...
def closePath(self) -> None: ...
def endPath(self) -> None: ...
def moveTo(self, pt: tuple[float, float]) -> None: ...
def lineTo(self, pt: tuple[float, float]) -> None: ...
def curveTo(self, *points: tuple[float, float]) -> None: ...
def qCurveTo(self, *points: tuple[float, float]) -> None: ...
13 changes: 7 additions & 6 deletions stubs/fpdf2/fpdf/svg.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from _typeshed import Incomplete
from collections.abc import Callable
from re import Pattern
from typing_extensions import TypeAlias

_BasePen: TypeAlias = Incomplete # actually fontTools.pens.basePen.BasePen
from fpdf.drawing import PaintedPath

from ._fonttools_shims import BasePen, _TTGlyphSet

__pdoc__: dict[str, bool]

Expand Down Expand Up @@ -56,14 +57,14 @@ class ShapeBuilder:

def convert_transforms(tfstr): ...

class PathPen(_BasePen):
pdf_path: Incomplete
class PathPen(BasePen):
pdf_path: PaintedPath
last_was_line_to: bool
first_is_move: bool | None
def __init__(self, pdf_path, *args, **kwargs): ...
def __init__(self, pdf_path: PaintedPath, glyphSet: _TTGlyphSet | None = ...): ...
def arcTo(self, rx, ry, rotation, arc, sweep, end) -> None: ...

def svg_path_converter(pdf_path, svg_path) -> None: ...
def svg_path_converter(pdf_path: PaintedPath, svg_path: str) -> None: ...

class SVGObject:
@classmethod
Expand Down