From ec1130adcc12431ba85415a6533da68c3692b2cb Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 3 May 2023 17:06:12 +0200 Subject: [PATCH] [fpdf2] Update to 2.7.1 (#9978) --- stubs/fpdf2/@tests/stubtest_allowlist.txt | 9 +- stubs/fpdf2/METADATA.toml | 2 +- stubs/fpdf2/fpdf/__init__.pyi | 5 +- stubs/fpdf2/fpdf/deprecation.pyi | 6 +- stubs/fpdf2/fpdf/encryption.pyi | 3 + stubs/fpdf2/fpdf/enums.pyi | 33 +++++- stubs/fpdf2/fpdf/fonts.pyi | 30 +++++- stubs/fpdf2/fpdf/fpdf.pyi | 124 +++++++++++++++------- stubs/fpdf2/fpdf/graphics_state.pyi | 3 + stubs/fpdf2/fpdf/html.pyi | 16 ++- stubs/fpdf2/fpdf/image_parsing.pyi | 28 ++++- stubs/fpdf2/fpdf/line_break.pyi | 16 ++- stubs/fpdf2/fpdf/output.pyi | 14 ++- stubs/fpdf2/fpdf/prefs.pyi | 2 +- stubs/fpdf2/fpdf/sign.pyi | 2 +- stubs/fpdf2/fpdf/syntax.pyi | 17 ++- stubs/fpdf2/fpdf/table.pyi | 65 ++++++++++++ stubs/fpdf2/fpdf/util.pyi | 22 ++-- 18 files changed, 306 insertions(+), 91 deletions(-) create mode 100644 stubs/fpdf2/fpdf/table.pyi diff --git a/stubs/fpdf2/@tests/stubtest_allowlist.txt b/stubs/fpdf2/@tests/stubtest_allowlist.txt index 1c5d0a0ce..7675d7912 100644 --- a/stubs/fpdf2/@tests/stubtest_allowlist.txt +++ b/stubs/fpdf2/@tests/stubtest_allowlist.txt @@ -1,7 +1,3 @@ -# The "dest" argument is unused and will be removed. -fpdf.FPDF.output -fpdf.fpdf.FPDF.output - # Argument has default at runtime, but using it raises a TypeError. fpdf.FPDF.set_creation_date fpdf.fpdf.FPDF.set_creation_date @@ -13,3 +9,8 @@ fpdf._fonttools_shims # fixed in later versions. fpdf.FPDF.set_encryption fpdf.fpdf.FPDF.set_encryption + +# Runtime has some internal arguments. +fpdf.syntax.build_obj_dict +fpdf.ViewerPreferences.serialize +fpdf\.[a-z]+\.[A-Za-z]+\.serialize diff --git a/stubs/fpdf2/METADATA.toml b/stubs/fpdf2/METADATA.toml index c83645ebf..5c4e24e32 100644 --- a/stubs/fpdf2/METADATA.toml +++ b/stubs/fpdf2/METADATA.toml @@ -1,4 +1,4 @@ -version = "2.6.1" +version = "2.7.1" requires = ["types-Pillow>=9.2.0"] [tool.stubtest] diff --git a/stubs/fpdf2/fpdf/__init__.pyi b/stubs/fpdf2/fpdf/__init__.pyi index 250fb72a4..9d17a7f7e 100644 --- a/stubs/fpdf2/fpdf/__init__.pyi +++ b/stubs/fpdf2/fpdf/__init__.pyi @@ -1,7 +1,7 @@ from pathlib import Path -from .enums import Align as Align, XPos as XPos, YPos as YPos -from .fpdf import FPDF as FPDF, TitleStyle as TitleStyle +from .enums import Align as Align, TextMode as TextMode, XPos as XPos, YPos as YPos +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 from .template import FlexTemplate as FlexTemplate, Template as Template @@ -15,6 +15,7 @@ __all__ = [ "__version__", "__license__", "FPDF", + "FPDFException", "Align", "XPos", "YPos", diff --git a/stubs/fpdf2/fpdf/deprecation.pyi b/stubs/fpdf2/fpdf/deprecation.pyi index 91885bd3d..89ab11760 100644 --- a/stubs/fpdf2/fpdf/deprecation.pyi +++ b/stubs/fpdf2/fpdf/deprecation.pyi @@ -1,5 +1,7 @@ from types import ModuleType +from typing import Any, NoReturn class WarnOnDeprecatedModuleAttributes(ModuleType): - def __getattr__(self, name: str): ... - def __setattr__(self, name: str, value) -> None: ... + def __call__(self) -> NoReturn: ... + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... diff --git a/stubs/fpdf2/fpdf/encryption.pyi b/stubs/fpdf2/fpdf/encryption.pyi index 1888d6f3b..45349dae5 100644 --- a/stubs/fpdf2/fpdf/encryption.pyi +++ b/stubs/fpdf2/fpdf/encryption.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete, SupportsLenAndGetItem from collections.abc import Generator, Iterable +from logging import Logger from typing import ClassVar, Protocol, TypeVar from typing_extensions import TypeAlias @@ -10,6 +11,8 @@ from .syntax import Name, PDFObject _Key: TypeAlias = SupportsLenAndGetItem[int] _T_co = TypeVar("_T_co", covariant=True) +LOGGER: Logger + import_error: ImportError | None class _SupportsGetItem(Protocol[_T_co]): diff --git a/stubs/fpdf2/fpdf/enums.pyi b/stubs/fpdf2/fpdf/enums.pyi index 9f82c6008..191129fee 100644 --- a/stubs/fpdf2/fpdf/enums.pyi +++ b/stubs/fpdf2/fpdf/enums.pyi @@ -15,6 +15,14 @@ class CoerciveIntEnum(IntEnum): @classmethod def coerce(cls, value: Self | str | int) -> Self: ... +class CoerciveIntFlag(IntFlag): + @classmethod + def coerce(cls, value: Self | str | int) -> Self: ... + +class WrapMode(CoerciveEnum): + WORD: str + CHAR: str + class CharVPos(CoerciveEnum): SUP: str SUB: str @@ -29,6 +37,29 @@ class Align(CoerciveEnum): R: str J: str +class TextEmphasis(CoerciveIntFlag): + B: int + I: int + U: int + + @property + def style(self) -> str: ... + +class TableBordersLayout(CoerciveEnum): + ALL: str + NONE: str + INTERNAL: str + MINIMAL: str + HORIZONTAL_LINES: str + NO_HORIZONTAL_LINES: str + SINGLE_TOP_LINE: str + +class TableCellFillMode(CoerciveEnum): + NONE: str + ALL: str + ROWS: str + COLUMNS: str + class RenderStyle(CoerciveEnum): D: str F: str @@ -200,5 +231,3 @@ class EncryptionMethod(Enum): NO_ENCRYPTION: int RC4: int AES_128: int - -__pdoc__: dict[str, bool] diff --git a/stubs/fpdf2/fpdf/fonts.pyi b/stubs/fpdf2/fpdf/fonts.pyi index 5a894fff6..b559d9f76 100644 --- a/stubs/fpdf2/fpdf/fonts.pyi +++ b/stubs/fpdf2/fpdf/fonts.pyi @@ -1,4 +1,28 @@ -from typing import Any +import dataclasses +from _typeshed import Incomplete +from dataclasses import dataclass -courier: Any -fpdf_charwidths: Any +from .drawing import DeviceGray, DeviceRGB, Number +from .enums import TextEmphasis + +@dataclass +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 + + def __init__( + self, + family: str | None = None, + emphasis: Incomplete | None = None, + size_pt: int | None = None, + color: int | tuple[Number, Number, Number] | DeviceGray | DeviceRGB | None = None, + fill_color: int | tuple[Number, Number, Number] | DeviceGray | DeviceRGB | None = None, + ) -> None: ... + + replace = dataclasses.replace + +COURIER_FONT: dict[str, int] +CORE_FONTS_CHARWIDTHS: dict[str, dict[str, int]] diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index 1c65fb915..0fa22a4f2 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -1,5 +1,5 @@ import datetime -from _typeshed import Incomplete, StrPath +from _typeshed import Incomplete, StrPath, Unused from collections.abc import Callable, Iterable, Sequence from contextlib import _GeneratorContextManager from io import BytesIO @@ -12,7 +12,7 @@ from fpdf import ViewerPreferences from PIL import Image from .annotations import AnnotationDict, PDFEmbeddedFile -from .drawing import DrawingContext, PaintedPath +from .drawing import DeviceGray, DeviceRGB, DrawingContext, PaintedPath from .enums import ( Align, AnnotationFlag, @@ -22,19 +22,26 @@ from .enums import ( PageLayout, PathPaintRule, RenderStyle, + TableBordersLayout, + TableCellFillMode, TextMarkupType, TextMode as TextMode, + WrapMode as WrapMode, XPos as XPos, YPos as YPos, ) +from .errors import FPDFException as FPDFException +from .fonts import FontFace +from .graphics_state import GraphicsStateMixin from .html import HTML2FPDF -from .output import PDFPage +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", "TextMode", "TitleStyle", "PAGE_FORMATS"] +__all__ = ["FPDF", "XPos", "YPos", "get_page_format", "ImageInfo", "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"] @@ -42,15 +49,32 @@ _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 TitleStyle(NamedTuple): - font_family: str | None = ... - font_style: str | None = ... - font_size_pt: int | None = ... - color: int | tuple[int, int, int] | None = ... - underline: bool = ... - t_margin: int | None = ... - l_margin: int | None = ... - b_margin: int | None = ... +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: ... + +class TitleStyle(FontFace): + t_margin: int | None + l_margin: int | None + b_margin: int | None + + def __init__( + self, + font_family: str | None = None, + font_style: str | None = None, + font_size_pt: int | None = None, + color: int | tuple[int, int, int] | None = None, + underline: bool = False, + t_margin: int | None = None, + l_margin: int | None = None, + b_margin: int | None = None, + ) -> None: ... class ToCPlaceholder(NamedTuple): render_function: Callable[[FPDF, Any], object] @@ -70,7 +94,7 @@ def get_page_format(format: _Format | tuple[float, float], k: float | None = Non _Font: TypeAlias = dict[str, Any] _Image: TypeAlias = dict[str, Any] -class FPDF: +class FPDF(GraphicsStateMixin): MARKDOWN_BOLD_MARKER: ClassVar[str] MARKDOWN_ITALICS_MARKER: ClassVar[str] MARKDOWN_UNDERLINE_MARKER: ClassVar[str] @@ -104,20 +128,7 @@ class FPDF: font_aliases: dict[str, str] k: float - font_family: str - font_style: str - font_size_pt: float - font_stretching: float - char_spacing: float - underline: bool - current_font: _Font - draw_color: str - fill_color: str - text_color: str page_background: Incomplete | None - dash_pattern: dict[str, int] # TODO: TypedDict - line_width: float - text_mode: TextMode dw_pt: float dh_pt: float @@ -148,15 +159,14 @@ class FPDF: format: _Format | tuple[float, float] = "A4", font_cache_dir: Literal["DEPRECATED"] = "DEPRECATED", ) -> None: ... - # The following definition crashes stubtest 0.991, but seems to be fixed - # in later versions. + # The following definition crashes stubtest 1.1.1. # def set_encryption( - # self, - # owner_password: str, - # user_password: str | None = None, - # encryption_method: EncryptionMethod | str = ..., - # permissions: AccessPermission = ..., - # encrypt_metadata: bool = False, + # self, + # owner_password: str, + # user_password: str | None = None, + # encryption_method: EncryptionMethod | str = ..., + # permissions: AccessPermission = ..., + # encrypt_metadata: bool = False, # ) -> None: ... # args and kwargs are passed to HTML2FPDF_CLASS constructor. def write_html(self, text: str, *args: Any, **kwargs: Any) -> None: ... @@ -312,6 +322,7 @@ class FPDF: def set_font_size(self, size: float) -> None: ... def set_char_spacing(self, spacing: float) -> None: ... def set_stretching(self, stretching: float) -> None: ... + def set_fallback_fonts(self, fallback_fonts: Iterable[str], exact_match: bool = True) -> None: ... def add_link(self, y: float = 0, x: float = 0, page: int = -1, zoom: float | Literal["null"] = "null") -> int: ... def set_link(self, link, y: float = 0, x: float = 0, page: int = -1, zoom: float | Literal["null"] = "null") -> None: ... def link( @@ -420,6 +431,7 @@ class FPDF: new_x: XPos | str = ..., new_y: YPos | str = ..., ) -> bool: ... + def get_fallback_font(self, char: str, style: str = "") -> str | None: ... def will_page_break(self, height: float) -> bool: ... def multi_cell( self, @@ -437,8 +449,11 @@ class FPDF: print_sh: bool = False, new_x: XPos | str = ..., new_y: YPos | str = ..., + wrapmode: WrapMode = ..., ): ... - def write(self, h: float | None = None, txt: str = "", link: str = "", print_sh: bool = False) -> None: ... + def write( + self, h: float | None = None, txt: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = ... + ) -> bool: ... def image( self, name: str | Image.Image | BytesIO | StrPath, @@ -451,17 +466,17 @@ class FPDF: title: str | None = None, alt_text: str | None = None, dims: tuple[float, float] | None = None, + keep_aspect_ratio: bool = False, ) -> _Image: ... + def preload_image( + self, name: str | Image.Image | BytesIO, dims: tuple[float, float] | None = None + ) -> tuple[str, Any, ImageInfo]: ... def ln(self, h: float | None = None) -> None: ... def get_x(self) -> float: ... def set_x(self, x: float) -> None: ... def get_y(self) -> float: ... def set_y(self, y: float) -> None: ... def set_xy(self, x: float, y: float) -> None: ... - @overload - def output(self, name: Literal[""] = "") -> bytearray: ... # type: ignore[misc] - @overload - def output(self, name: str) -> None: ... def normalize_text(self, txt: str) -> str: ... def sign_pkcs12( self, @@ -506,3 +521,32 @@ class FPDF: level6: TitleStyle | None = None, ) -> None: ... def start_section(self, name: str, level: int = 0, strict: bool = True) -> None: ... + def use_font_face(self, font_face: FontFace) -> _GeneratorContextManager[None]: ... + def table( + self, + rows: Iterable[Incomplete] = (), + *, + align: str | Align = "CENTER", + borders_layout: str | TableBordersLayout = ..., + cell_fill_color: int | tuple[Incomplete, ...] | DeviceGray | DeviceRGB | None = None, + cell_fill_mode: str | TableCellFillMode = ..., + col_widths: int | tuple[int, ...] | None = None, + first_row_as_headings: bool = True, + headings_style: FontFace = ..., + line_height: int | None = None, + markdown: bool = False, + text_align: str | Align = "JUSTIFY", + width: int | None = None, + ) -> _GeneratorContextManager[Table]: ... + @overload + def output( # type: ignore[misc] + self, + name: Literal[""] | None = "", + dest: Unused = "", + linearize: bool = False, + output_producer_class: Callable[[FPDF], OutputProducer] = ..., + ) -> None: ... + @overload + def output( + self, name: str, dest: Unused = "", linearize: bool = False, output_producer_class: Callable[[FPDF], OutputProducer] = ... + ) -> bytearray: ... diff --git a/stubs/fpdf2/fpdf/graphics_state.pyi b/stubs/fpdf2/fpdf/graphics_state.pyi index a364a5275..029b4f6bf 100644 --- a/stubs/fpdf2/fpdf/graphics_state.pyi +++ b/stubs/fpdf2/fpdf/graphics_state.pyi @@ -1,5 +1,7 @@ from typing import Any, ClassVar +from fpdf.fonts import FontFace + from .drawing import DeviceGray, DeviceRGB from .enums import TextMode @@ -100,3 +102,4 @@ class GraphicsStateMixin: def denom_lift(self): ... @denom_lift.setter def denom_lift(self, v) -> None: ... + def font_face(self) -> FontFace: ... diff --git a/stubs/fpdf2/fpdf/html.pyi b/stubs/fpdf2/fpdf/html.pyi index 1cd38573f..70186a8b8 100644 --- a/stubs/fpdf2/fpdf/html.pyi +++ b/stubs/fpdf2/fpdf/html.pyi @@ -26,6 +26,7 @@ def color_as_decimal(color: str | None = "#000000") -> tuple[int, int, int] | No class HTML2FPDF(HTMLParser): HTML_UNCLOSED_TAGS: ClassVar[tuple[str, ...]] + pdf: Incomplete image_map: Incomplete li_tag_indent: Incomplete @@ -58,6 +59,11 @@ class HTML2FPDF(HTMLParser): heading_above: float heading_below: float warn_on_tags_not_matching: bool + + # Not initialized in __init__: + font_face: Incomplete + h: float + def __init__( self, pdf: FPDF, @@ -70,19 +76,9 @@ class HTML2FPDF(HTMLParser): warn_on_tags_not_matching: bool = True, **_: Unused, ): ... - def width2unit(self, length): ... def handle_data(self, data) -> None: ... - def box_shadow(self, w, h, bgcolor) -> None: ... - def output_table_header(self) -> None: ... - tfooter_out: bool - def output_table_footer(self) -> None: ... - def output_table_sep(self) -> None: ... - font_face: Incomplete - table_offset: Incomplete def handle_starttag(self, tag, attrs) -> None: ... - tbody: Incomplete def handle_endtag(self, tag) -> None: ... - h: Incomplete def set_font(self, face: Incomplete | None = None, size: Incomplete | None = None) -> None: ... def set_style(self, tag: Incomplete | None = None, enable: bool = False) -> None: ... def set_text_color(self, r: Incomplete | None = None, g: int = 0, b: int = 0) -> None: ... diff --git a/stubs/fpdf2/fpdf/image_parsing.pyi b/stubs/fpdf2/fpdf/image_parsing.pyi index 352086bf7..acf3b6758 100644 --- a/stubs/fpdf2/fpdf/image_parsing.pyi +++ b/stubs/fpdf2/fpdf/image_parsing.pyi @@ -1,15 +1,37 @@ from _typeshed import Incomplete +from io import BytesIO +from logging import Logger +from types import TracebackType from typing import Any from typing_extensions import Literal, TypeAlias -from PIL.Image import Resampling +from PIL import Image _ImageFilter: TypeAlias = Literal["AUTO", "FlateDecode", "DCTDecode", "JPXDecode"] -RESAMPLE: Resampling +RESAMPLE: Image.Resampling +LOGGER: Logger SUPPORTED_IMAGE_FILTERS: tuple[_ImageFilter, ...] +TIFFBitRevTable: list[int] def load_image(filename): ... +def is_iccp_valid(iccp, filename) -> bool: ... # Returned dict could be typed as a TypedDict. -def get_img_info(img, image_filter: _ImageFilter = "AUTO", dims: Incomplete | None = None) -> dict[str, Any]: ... +def get_img_info( + filename, img: BytesIO | Image.Image | None = None, image_filter: _ImageFilter = "AUTO", dims: Incomplete | None = None +) -> dict[str, Any]: ... + +class temp_attr: + obj: Any + field: str + value: Any + exists: bool # defined after __enter__ is called + def __init__(self, obj: Any, field: str, value: Any) -> None: ... + def __enter__(self) -> None: ... + def __exit__( + self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None + ) -> None: ... + +def ccitt_payload_location_from_pil(img: Image.Image) -> tuple[int, int]: ... +def transcode_monochrome(img: Image.Image): ... diff --git a/stubs/fpdf2/fpdf/line_break.pyi b/stubs/fpdf2/fpdf/line_break.pyi index 27888c13d..55a601e09 100644 --- a/stubs/fpdf2/fpdf/line_break.pyi +++ b/stubs/fpdf2/fpdf/line_break.pyi @@ -2,6 +2,8 @@ from _typeshed import Incomplete from collections.abc import Sequence from typing import NamedTuple +from .enums import WrapMode + SOFT_HYPHEN: str HYPHEN: str SPACE: str @@ -101,16 +103,20 @@ class CurrentLine: original_character_index: int, url: str | None = None, ): ... + def trim_trailing_spaces(self) -> None: ... def manual_break(self, justify: bool = False, trailing_nl: bool = False): ... def automatic_break_possible(self): ... def automatic_break(self, justify: bool): ... class MultiLineBreak: - styled_text_fragments: Incomplete - justify: Incomplete - print_sh: Incomplete + styled_text_fragments: Sequence[Fragment] + justify: bool + print_sh: bool + wrap_mode: WrapMode fragment_index: int character_index: int - idx_last_forced_break: Incomplete - def __init__(self, styled_text_fragments: Sequence[Fragment], justify: bool = False, print_sh: bool = False) -> None: ... + idx_last_forced_break: int | None + def __init__( + self, styled_text_fragments: Sequence[Fragment], justify: bool = False, print_sh: bool = False, wrapmode: WrapMode = ... + ) -> None: ... def get_line_of_given_width(self, maximum_width: float, wordsplit: bool = True): ... diff --git a/stubs/fpdf2/fpdf/output.pyi b/stubs/fpdf2/fpdf/output.pyi index 7dc1776ec..1b01fb9fc 100644 --- a/stubs/fpdf2/fpdf/output.pyi +++ b/stubs/fpdf2/fpdf/output.pyi @@ -5,7 +5,7 @@ from typing_extensions import Final from .annotations import AnnotationDict from .encryption import StandardSecurityHandler -from .syntax import Name, PDFArray, PDFContentStream, PDFObject +from .syntax import Name, PDFArray, PDFContentStream, PDFObject, PDFString LOGGER: Logger ZOOM_CONFIGS: Final[dict[str, tuple[str, ...]]] @@ -53,10 +53,9 @@ class PDFFontDescriptor(PDFObject): def __init__(self, ascent, descent, cap_height, flags, font_b_box, italic_angle, stem_v, missing_width) -> None: ... class CIDSystemInfo(PDFObject): - registry: str - ordering: str - supplement: Incomplete - def __init__(self, registry: str | None, ordering: str | None, supplement) -> None: ... + registry: PDFString + ordering: PDFString + supplement: int class PDFInfo(PDFObject): title: str | None @@ -145,6 +144,11 @@ class PDFXObject(PDFContentStream): decode_parms: Incomplete | None = None, ) -> None: ... +class PDFICCPObject(PDFContentStream): + n: Incomplete + alternate: Name + def __init__(self, contents: bytes, n, alternate: str) -> None: ... + class PDFPage(PDFObject): type: Name contents: Incomplete diff --git a/stubs/fpdf2/fpdf/prefs.pyi b/stubs/fpdf2/fpdf/prefs.pyi index 8317b3434..bd9f243e8 100644 --- a/stubs/fpdf2/fpdf/prefs.pyi +++ b/stubs/fpdf2/fpdf/prefs.pyi @@ -21,4 +21,4 @@ class ViewerPreferences: def non_full_screen_page_mode(self): ... @non_full_screen_page_mode.setter def non_full_screen_page_mode(self, page_mode) -> None: ... - def serialize(self): ... + def serialize(self) -> str: ... diff --git a/stubs/fpdf2/fpdf/sign.pyi b/stubs/fpdf2/fpdf/sign.pyi index 8130207e0..a34fbe831 100644 --- a/stubs/fpdf2/fpdf/sign.pyi +++ b/stubs/fpdf2/fpdf/sign.pyi @@ -17,6 +17,6 @@ class Signature: m: Incomplete | None = None, reason: Incomplete | None = None, ) -> None: ... - def serialize(self): ... + def serialize(self) -> str: ... def sign_content(signer, buffer, key, cert, extra_certs, hashalgo, sign_time): ... diff --git a/stubs/fpdf2/fpdf/syntax.pyi b/stubs/fpdf2/fpdf/syntax.pyi index 7e65e3b7c..3671c05ae 100644 --- a/stubs/fpdf2/fpdf/syntax.pyi +++ b/stubs/fpdf2/fpdf/syntax.pyi @@ -1,8 +1,9 @@ +import datetime from _typeshed import Incomplete, SupportsItems from abc import ABC, abstractmethod from re import Pattern from typing import ClassVar, Generic, TypeVar -from typing_extensions import Literal +from typing_extensions import Literal, Self from .encryption import StandardSecurityHandler @@ -16,7 +17,7 @@ def create_dictionary_string( field_join: str = "\n", key_value_join: str = " ", has_empty_fields: bool = False, -): ... +) -> str: ... def create_list_string(list_): ... def iobj_ref(n): ... def create_stream( @@ -30,7 +31,6 @@ class Name(str): def serialize(self) -> str: ... class PDFObject: - def __init__(self) -> None: ... @property def id(self) -> int: ... @id.setter @@ -44,13 +44,22 @@ class PDFContentStream(PDFObject): filter: Name | None length: int def __init__(self, contents: bytes, compress: bool = False) -> None: ... - def encrypt(self, security_handler: StandardSecurityHandler) -> None: ... def build_obj_dict(key_values: SupportsItems[str, Incomplete]) -> dict[str, str]: ... def camel_case(snake_case: str) -> str: ... class PDFString(str): USE_HEX_ENCODING: ClassVar[bool] + encrypt: bool + def __new__(cls, content: str, encrypt: bool = False) -> Self: ... + def serialize(self) -> str: ... + +class PDFDate: + date: datetime.datetime + with_tz: bool + encrypt: bool + + def __init__(self, date: datetime.datetime, with_tz: bool = False, encrypt: bool = False) -> None: ... def serialize(self) -> str: ... class PDFArray(list[_T], Generic[_T]): diff --git a/stubs/fpdf2/fpdf/table.pyi b/stubs/fpdf2/fpdf/table.pyi new file mode 100644 index 000000000..013176f33 --- /dev/null +++ b/stubs/fpdf2/fpdf/table.pyi @@ -0,0 +1,65 @@ +from _typeshed import Incomplete +from collections.abc import Iterable +from dataclasses import dataclass +from io import BytesIO +from typing_extensions import Literal + +from PIL import Image + +from .drawing import DeviceGray, DeviceRGB +from .enums import Align, TableBordersLayout, TableCellFillMode +from .fonts import FontFace +from .fpdf import FPDF + +DEFAULT_HEADINGS_STYLE: FontFace + +class Table: + rows: list[Row] + + def __init__( + self, + fpdf: FPDF, + rows: Iterable[str] = (), + *, + align: str | Align = "CENTER", + borders_layout: str | TableBordersLayout = ..., + cell_fill_color: int | tuple[Incomplete, ...] | DeviceGray | DeviceRGB | None = None, + cell_fill_mode: str | TableCellFillMode = ..., + col_widths: int | tuple[int, ...] | None = None, + first_row_as_headings: bool = True, + headings_style: FontFace = ..., + line_height: int | None = None, + markdown=False, + text_align: str | Align = "JUSTIFY", + width: int | None = None, + ) -> None: ... + def row(self, cells: Iterable[str] = ()) -> Row: ... + def render(self) -> None: ... + def get_cell_border(self, i, j) -> str | Literal[0, 1]: ... + +class Row: + cells: list[Cell] + style: FontFace + def __init__(self, fpdf: FPDF) -> None: ... + @property + def cols_count(self) -> int: ... + def cell( + self, + text: str = "", + align: str | Align | None = None, + style: FontFace | None = None, + img: str | Image.Image | BytesIO | None = None, + img_fill_width: bool = False, + colspan: int = 1, + ) -> Cell: ... + +@dataclass +class Cell: + text: str + align: str | Align | None + style: FontFace | None + img: str | None + img_fill_width: bool + colspan: int + + def write(self, text, align: Incomplete | None = None): ... diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index 7b33a2bce..d078ec0ab 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -1,15 +1,13 @@ -import datetime from collections.abc import Iterable -from typing import Any -from typing_extensions import Literal, TypeAlias +from typing import Any, AnyStr +from typing_extensions import Final, Literal, TypeAlias _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] +PIL_MEM_BLOCK_SIZE_IN_MIB: Final = 16 + def buffer_subst(buffer: bytearray, placeholder: str, value: str) -> bytearray: ... -def format_date(date: datetime.datetime, with_tz: bool = False) -> str: ... -def enclose_in_parens(s: str) -> str: ... -def escape_parens(s): ... -def b(s): ... +def escape_parens(s: AnyStr) -> AnyStr: ... def get_scale_factor(unit: _Unit | float) -> float: ... def convert_unit( # to_convert has a recursive type @@ -17,4 +15,12 @@ def convert_unit( old_unit: str | float, new_unit: str | float, ) -> float | tuple[float, ...]: ... -def dochecks() -> None: ... +def print_mem_usage(prefix: str) -> None: ... +def get_mem_usage(prefix: str) -> str: ... +def get_process_rss() -> str: ... +def get_process_rss_as_mib() -> float | None: ... +def get_process_heap_and_stack_sizes() -> tuple[str, str]: ... +def get_pymalloc_allocated_over_total_size() -> str: ... +def get_gc_managed_objs_total_size() -> str: ... +def get_tracemalloc_traced_memory() -> str: ... +def get_pillow_allocated_memory() -> str: ...