Skip to content

Commit

Permalink
Bump fpdf2 to 2.7.7 (#11149)
Browse files Browse the repository at this point in the history
Closes: #11145
  • Loading branch information
srittau authored Dec 13, 2023
1 parent 0e5277c commit 3171cb4
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 59 deletions.
2 changes: 1 addition & 1 deletion stubs/fpdf2/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "2.7.6"
version = "2.7.7"
upstream_repository = "https://github.com/PyFPDF/fpdf2"
requires = ["types-Pillow>=9.2.0"]

Expand Down
2 changes: 2 additions & 0 deletions stubs/fpdf2/fpdf/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from .enums import Align as Align, TextMode as TextMode, XPos as XPos, YPos as YPos
from .fonts import FontFace as FontFace
from .fpdf import FPDF as FPDF, FPDFException as FPDFException, TitleStyle as TitleStyle
from .html import HTML2FPDF as HTML2FPDF, HTMLMixin as HTMLMixin
from .prefs import ViewerPreferences as ViewerPreferences
Expand All @@ -16,6 +17,7 @@ __all__ = [
"__license__",
"FPDF",
"FPDFException",
"FontFace",
"Align",
"TextMode",
"XPos",
Expand Down
4 changes: 3 additions & 1 deletion stubs/fpdf2/fpdf/annotations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from .actions import Action
from .enums import AnnotationFlag, AnnotationName, FileAttachmentAnnotationName
from .syntax import Destination, Name, PDFContentStream, PDFObject

DEFAULT_ANNOT_FLAGS: Incomplete
DEFAULT_ANNOT_FLAGS: tuple[AnnotationFlag, ...]

class AnnotationMixin:
type: Name
Expand All @@ -27,6 +27,7 @@ class AnnotationMixin:
name: AnnotationName | FileAttachmentAnnotationName | None
ink_list: str | None
f_s: str | None
d_a: str | None
def __init__(
self,
subtype: str,
Expand All @@ -48,6 +49,7 @@ class AnnotationMixin:
file_spec: str | None = None,
field_type: str | None = None,
value: Incomplete | None = None,
default_appearance: str | None = None,
) -> None: ...

class PDFAnnotation(AnnotationMixin, PDFObject): ...
Expand Down
14 changes: 11 additions & 3 deletions stubs/fpdf2/fpdf/drawing.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import decimal
from _typeshed import Incomplete
from collections import OrderedDict
from collections.abc import Callable, Generator, Iterator
from collections.abc import Callable, Generator, Iterator, Sequence
from contextlib import contextmanager
from re import Pattern
from typing import Any, ClassVar, NamedTuple, TypeVar
from typing_extensions import Self, TypeAlias
from typing import Any, ClassVar, NamedTuple, TypeVar, overload
from typing_extensions import Literal, Self, TypeAlias

from .syntax import Name, Raw

Expand Down Expand Up @@ -70,6 +70,14 @@ class DeviceCMYK(_DeviceCMYKBase):

def rgb8(r, g, b, a: Incomplete | None = None) -> DeviceRGB: ...
def gray8(g, a: Incomplete | None = None) -> DeviceGray: ...
@overload
def convert_to_device_color(r: DeviceGray, g: int = -1, b: int = -1) -> DeviceGray: ...
@overload
def convert_to_device_color(r: DeviceRGB, g: int = -1, b: int = -1) -> DeviceRGB: ...
@overload
def convert_to_device_color(r: int, g: Literal[-1] = -1, b: Literal[-1] = -1) -> DeviceGray: ...
@overload
def convert_to_device_color(r: Sequence[int] | int, g: int, b: int) -> DeviceGray | DeviceRGB: ...
def cmyk8(c, m, y, k, a: Incomplete | None = None) -> DeviceCMYK: ...
def color_from_hex_string(hexstr) -> DeviceRGB: ...
def color_from_rgb_string(rgbstr) -> DeviceRGB: ...
Expand Down
2 changes: 2 additions & 0 deletions stubs/fpdf2/fpdf/enums.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class TableCellFillMode(CoerciveEnum):
ROWS: str
COLUMNS: str

def should_fill_cell(self, i: int, j: int) -> bool: ...

class RenderStyle(CoerciveEnum):
D: str
F: str
Expand Down
12 changes: 10 additions & 2 deletions stubs/fpdf2/fpdf/fonts.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dataclasses
from _typeshed import Incomplete
from collections.abc import Generator
from dataclasses import dataclass
from typing import overload

from .drawing import DeviceGray, DeviceRGB, Number
from .enums import TextEmphasis
Expand All @@ -12,8 +13,8 @@ class FontFace:
family: str | None
emphasis: TextEmphasis | None
size_pt: int | None
color: int | tuple[Number, Number, Number] | DeviceGray | DeviceRGB | None
fill_color: int | tuple[Number, Number, Number] | DeviceGray | DeviceRGB | None
color: DeviceGray | DeviceRGB | None
fill_color: DeviceGray | DeviceRGB | None

def __init__(
self,
Expand All @@ -26,6 +27,13 @@ class FontFace:

replace = dataclasses.replace

@overload
@staticmethod
def combine(default_style: None, override_style: None) -> None: ... # type: ignore[misc]
@overload
@staticmethod
def combine(default_style: FontFace | None, override_style: FontFace | None) -> FontFace: ...

class _FontMixin:
i: int
type: str
Expand Down
58 changes: 40 additions & 18 deletions stubs/fpdf2/fpdf/fpdf.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from io import BytesIO
from pathlib import PurePath
from re import Pattern
from typing import Any, ClassVar, NamedTuple, overload
from typing_extensions import Literal, TypeAlias
from typing_extensions import Final, Literal, TypeAlias, deprecated

from fpdf import ViewerPreferences
from PIL import Image
Expand Down Expand Up @@ -35,30 +35,40 @@ from .errors import FPDFException as FPDFException
from .fonts import FontFace
from .graphics_state import GraphicsStateMixin
from .html import HTML2FPDF
from .image_datastructures import (
ImageCache,
ImageInfo as ImageInfo,
RasterImageInfo as RasterImageInfo,
VectorImageInfo as VectorImageInfo,
_AlignLiteral,
)
from .output import OutputProducer, PDFPage
from .recorder import FPDFRecorder
from .structure_tree import StructureTreeBuilder
from .syntax import DestinationXYZ
from .table import Table
from .util import _Unit

__all__ = ["FPDF", "XPos", "YPos", "get_page_format", "ImageInfo", "TextMode", "TitleStyle", "PAGE_FORMATS"]
__all__ = [
"FPDF",
"XPos",
"YPos",
"get_page_format",
"ImageInfo",
"RasterImageInfo",
"VectorImageInfo",
"TextMode",
"TitleStyle",
"PAGE_FORMATS",
]

_Orientation: TypeAlias = Literal["", "portrait", "p", "P", "landscape", "l", "L"]
_Format: TypeAlias = Literal["", "a3", "A3", "a4", "A4", "a5", "A5", "letter", "Letter", "legal", "Legal"]
_FontStyle: TypeAlias = Literal["", "B", "I"]
_FontStyles: TypeAlias = Literal["", "B", "I", "U", "BU", "UB", "BI", "IB", "IU", "UI", "BIU", "BUI", "IBU", "IUB", "UBI", "UIB"]
PAGE_FORMATS: dict[_Format, tuple[float, float]]

class ImageInfo(dict[str, Any]):
@property
def width(self) -> int: ...
@property
def height(self) -> int: ...
@property
def rendered_width(self) -> int: ...
@property
def rendered_height(self) -> int: ...
FPDF_VERSION: Final[str]
PAGE_FORMATS: dict[_Format, tuple[float, float]]

class TitleStyle(FontFace):
t_margin: int | None
Expand Down Expand Up @@ -87,7 +97,6 @@ def get_page_format(format: _Format | tuple[float, float], k: float | None = Non

# TODO: TypedDicts
_Font: TypeAlias = dict[str, Any]
_Image: TypeAlias = dict[str, Any]

class FPDF(GraphicsStateMixin):
MARKDOWN_BOLD_MARKER: ClassVar[str]
Expand All @@ -102,15 +111,14 @@ class FPDF(GraphicsStateMixin):
page: int
pages: dict[int, PDFPage]
fonts: dict[str, _Font]
images: dict[str, _Image]
links: dict[int, DestinationXYZ]
embedded_files: list[PDFEmbeddedFile]
image_cache: ImageCache

in_footer: bool
str_alias_nb_pages: str

xmp_metadata: str | None
image_filter: str
page_duration: int
page_transition: Incomplete | None
allow_images_transparency: bool
Expand Down Expand Up @@ -148,6 +156,8 @@ class FPDF(GraphicsStateMixin):
w: float
h: float

text_shaping: dict[str, Incomplete] | None # TODO: TypedDict

def __init__(
self,
orientation: _Orientation = "portrait",
Expand Down Expand Up @@ -371,7 +381,16 @@ class FPDF(GraphicsStateMixin):
h: float = 1,
name: AnnotationName | str | None = None,
flags: tuple[AnnotationFlag, ...] | tuple[str, ...] = ...,
) -> None: ...
) -> AnnotationDict: ...
def free_text_annotation(
self,
text: str,
x: float | None = None,
y: float | None = None,
w: float | None = None,
h: float | None = None,
flags: tuple[AnnotationFlag, ...] | tuple[str, ...] = ...,
) -> AnnotationDict: ...
def add_action(self, action, x: float, y: float, w: float, h: float) -> None: ...
def highlight(
self,
Expand Down Expand Up @@ -466,10 +485,12 @@ class FPDF(GraphicsStateMixin):
def text_columns(
self,
text: str | None = None,
img: str | None = None,
img_fill_width: bool = False,
ncols: int = 1,
gutter: float = 10,
balance: bool = False,
text_align: Align | str = "LEFT",
text_align: Align | _AlignLiteral = "LEFT",
line_height: float = 1,
l_margin: float | None = None,
r_margin: float | None = None,
Expand All @@ -490,7 +511,8 @@ class FPDF(GraphicsStateMixin):
alt_text: str | None = None,
dims: tuple[float, float] | None = None,
keep_aspect_ratio: bool = False,
) -> _Image: ...
) -> RasterImageInfo | VectorImageInfo: ...
@deprecated("Deprecated since 2.7.7; use fpdf.image_parsing.preload_image() instead")
def preload_image(
self, name: str | Image.Image | BytesIO, dims: tuple[float, float] | None = None
) -> tuple[str, Any, ImageInfo]: ...
Expand Down
4 changes: 4 additions & 0 deletions stubs/fpdf2/fpdf/graphics_state.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ class GraphicsStateMixin:
def denom_lift(self): ...
@denom_lift.setter
def denom_lift(self, v) -> None: ...
@property
def text_shaping(self): ...
@text_shaping.setter
def text_shaping(self, v) -> None: ...
def font_face(self) -> FontFace: ...
59 changes: 59 additions & 0 deletions stubs/fpdf2/fpdf/image_datastructures.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from _typeshed import Incomplete
from dataclasses import dataclass
from typing import Any
from typing_extensions import Literal, TypeAlias

from fpdf.enums import Align
from fpdf.fpdf import FPDF

from .image_parsing import _ImageFilter

_AlignLiteral: TypeAlias = Literal[
"",
"CENTER",
"X_CENTER",
"LEFT",
"RIGHT",
"JUSTIFY",
"center",
"x_center",
"left",
"right",
"justify",
"C",
"X",
"L",
"R",
"J",
"c",
"x",
"l",
"r",
"j",
]

class ImageInfo(dict[str, Any]):
@property
def width(self) -> int: ...
@property
def height(self) -> int: ...
@property
def rendered_width(self) -> int: ...
@property
def rendered_height(self) -> int: ...
def scale_inside_box(self, x: float, y: float, w: float, h: float) -> tuple[float, float, float, float]: ...
@staticmethod
def x_by_align(x: Align | _AlignLiteral, w: float, pdf: FPDF, keep_aspect_ratio: Literal[False]) -> float: ...

class RasterImageInfo(ImageInfo):
def size_in_document_units(self, w: float, h: float, scale=1) -> tuple[float, float]: ...

class VectorImageInfo(ImageInfo): ...

@dataclass
class ImageCache:
images: dict[str, dict[Incomplete, Incomplete]] = ...
icc_profiles: dict[bytes, int] = ...
image_filter: _ImageFilter = "AUTO"

def reset_usages(self) -> None: ...
15 changes: 15 additions & 0 deletions stubs/fpdf2/fpdf/image_parsing.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from dataclasses import dataclass
from io import BytesIO
from logging import Logger
from types import TracebackType
Expand All @@ -7,15 +8,29 @@ from typing_extensions import Literal, TypeAlias

from PIL import Image

from .image_datastructures import ImageCache, ImageInfo, VectorImageInfo
from .svg import SVGObject

_ImageFilter: TypeAlias = Literal["AUTO", "FlateDecode", "DCTDecode", "JPXDecode"]

RESAMPLE: Image.Resampling

@dataclass
class ImageSettings:
compression_level: int = -1

LOGGER: Logger
SUPPORTED_IMAGE_FILTERS: tuple[_ImageFilter, ...]
SETTINGS: ImageSettings

TIFFBitRevTable: list[int]

def preload_image(
image_cache: ImageCache, name: str | BytesIO | Image.Image, dims: tuple[float, float] | None = None
) -> tuple[str, BytesIO | Image.Image | None, ImageInfo]: ...
def load_image(filename): ...
def is_iccp_valid(iccp, filename) -> bool: ...
def get_svg_info(filename: str, img: BytesIO, image_cache: ImageCache) -> tuple[str, SVGObject, VectorImageInfo]: ...

# Returned dict could be typed as a TypedDict.
def get_img_info(
Expand Down
Loading

0 comments on commit 3171cb4

Please sign in to comment.