diff --git a/stubs/fpdf2/METADATA.toml b/stubs/fpdf2/METADATA.toml index 4b1457dea..9d6d88794 100644 --- a/stubs/fpdf2/METADATA.toml +++ b/stubs/fpdf2/METADATA.toml @@ -1,2 +1,2 @@ -version = "2.4.*" +version = "2.5.*" requires = ["types-Pillow"] diff --git a/stubs/fpdf2/fpdf/actions.pyi b/stubs/fpdf2/fpdf/actions.pyi index 69feb0a2b..4ade27738 100644 --- a/stubs/fpdf2/fpdf/actions.pyi +++ b/stubs/fpdf2/fpdf/actions.pyi @@ -1,26 +1,30 @@ +from _typeshed import Incomplete from abc import ABC -from typing import Any + +from .syntax import PDFObject class Action(ABC): - def dict_as_string(self) -> None: ... + next: PDFObject | str | None + def __init__(self, next_action: PDFObject | str | None = ...) -> None: ... + def dict_as_string(self, key_values: dict[str, Incomplete] | None = ...) -> str: ... class NamedAction(Action): - action_name: Any - def __init__(self, action_name) -> None: ... - def dict_as_string(self): ... + action_name: Incomplete + def __init__(self, action_name, next_action: PDFObject | str | None = ...) -> None: ... + def dict_as_string(self) -> str: ... # type: ignore[override] class GoToAction(Action): - dest: Any - def __init__(self, dest) -> None: ... - def dict_as_string(self): ... + dest: Incomplete + def __init__(self, dest, next_action: PDFObject | str | None = ...) -> None: ... + def dict_as_string(self) -> str: ... # type: ignore[override] class GoToRemoteAction(Action): - file: Any - dest: Any - def __init__(self, file, dest) -> None: ... - def dict_as_string(self): ... + file: Incomplete + dest: Incomplete + def __init__(self, file, dest, next_action: PDFObject | str | None = ...) -> None: ... + def dict_as_string(self) -> str: ... # type: ignore[override] class LaunchAction(Action): - file: Any - def __init__(self, file) -> None: ... - def dict_as_string(self): ... + file: Incomplete + def __init__(self, file, next_action: PDFObject | str | None = ...) -> None: ... + def dict_as_string(self) -> str: ... # type: ignore[override] diff --git a/stubs/fpdf2/fpdf/enums.pyi b/stubs/fpdf2/fpdf/enums.pyi new file mode 100644 index 000000000..33db22617 --- /dev/null +++ b/stubs/fpdf2/fpdf/enums.pyi @@ -0,0 +1,169 @@ +from _typeshed import Incomplete, Self +from enum import Enum, IntEnum + +from .syntax import Name + +class DocumentState(IntEnum): + UNINITIALIZED: int + READY: int + GENERATING_PAGE: int + CLOSED: int + +class CoerciveEnum(Enum): + @classmethod + def coerce(cls: type[Self], value: Self | str) -> Self: ... + +class CoerciveIntEnum(IntEnum): + @classmethod + def coerce(cls: type[Self], value: Self | str | int) -> Self: ... + +class Align(CoerciveEnum): + C: str + X: str + L: str + R: str + J: str + +class RenderStyle(CoerciveEnum): + D: str + F: str + DF: str + @property + def operator(self) -> str: ... + @property + def is_draw(self) -> bool: ... + @property + def is_fill(self) -> bool: ... + +class TextMode(CoerciveIntEnum): + FILL: int + STROKE: int + FILL_STROKE: int + INVISIBLE: int + FILL_CLIP: int + STROKE_CLIP: int + FILL_STROKE_CLIP: int + CLIP: int + +class XPos(CoerciveEnum): + LEFT: str + RIGHT: str + START: str + END: str + WCONT: str + CENTER: str + LMARGIN: str + RMARGIN: str + +class YPos(CoerciveEnum): + TOP: str + LAST: str + NEXT: str + TMARGIN: str + BMARGIN: str + +class PageLayout(CoerciveEnum): + SINGLE_PAGE: Name + ONE_COLUMN: Name + TWO_COLUMN_LEFT: Name + TWO_COLUMN_RIGHT: Name + TWO_PAGE_LEFT: Name + TWO_PAGE_RIGHT: Name + +class PageMode(CoerciveEnum): + USE_NONE: Name + USE_OUTLINES: Name + USE_THUMBS: Name + FULL_SCREEN: Name + USE_OC: Name + USE_ATTACHMENTS: Name + +class TextMarkupType(CoerciveEnum): + HIGHLIGHT: Name + UNDERLINE: Name + SQUIGGLY: Name + STRIKE_OUT: Name + +class BlendMode(CoerciveEnum): + NORMAL: Name + MULTIPLY: Name + SCREEN: Name + OVERLAY: Name + DARKEN: Name + LIGHTEN: Name + COLOR_DODGE: Name + COLOR_BURN: Name + HARD_LIGHT: Name + SOFT_LIGHT: Name + DIFFERENCE: Name + EXCLUSION: Name + HUE: Name + SATURATION: Name + COLOR: Name + LUMINOSITY: Name + +class AnnotationFlag(CoerciveIntEnum): + INVISIBLE: int + HIDDEN: int + PRINT: int + NO_ZOOM: int + NO_ROTATE: int + NO_VIEW: int + READ_ONLY: int + LOCKED: int + TOGGLE_NO_VIEW: int + LOCKED_CONTENTS: int + +class AnnotationName(CoerciveEnum): + NOTE: Name + COMMENT: Name + HELP: Name + PARAGRAPH: Name + NEW_PARAGRAPH: Name + INSERT: Name + +class IntersectionRule(CoerciveEnum): + NONZERO: str + EVENODD: str + +class PathPaintRule(CoerciveEnum): + STROKE: str + FILL_NONZERO: str + FILL_EVENODD: str + STROKE_FILL_NONZERO: str + STROKE_FILL_EVENODD: str + DONT_PAINT: str + AUTO: str + +class ClippingPathIntersectionRule(CoerciveEnum): + NONZERO: str + EVENODD: str + +class StrokeCapStyle(CoerciveIntEnum): + BUTT: int + ROUND: int + SQUARE: int + +class StrokeJoinStyle(CoerciveIntEnum): + MITER: int + ROUND: int + BEVEL: int + +class PDFStyleKeys(Enum): + FILL_ALPHA: Name + BLEND_MODE: Name + STROKE_ALPHA: Name + STROKE_ADJUSTMENT: Name + STROKE_WIDTH: Name + STROKE_CAP_STYLE: Name + STROKE_JOIN_STYLE: Name + STROKE_MITER_LIMIT: Name + STROKE_DASH_PATTERN: Name + +class Corner(CoerciveEnum): + TOP_RIGHT: str + TOP_LEFT: str + BOTTOM_RIGHT: str + BOTTOM_LEFT: str + +__pdoc__: Incomplete diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index f7b80a2cb..d1703c947 100644 --- a/stubs/fpdf2/fpdf/fpdf.pyi +++ b/stubs/fpdf2/fpdf/fpdf.pyi @@ -1,7 +1,7 @@ import datetime from _typeshed import Incomplete, StrPath from collections import defaultdict -from collections.abc import Callable +from collections.abc import Callable, Sequence from contextlib import _GeneratorContextManager from enum import IntEnum from io import BytesIO @@ -11,6 +11,7 @@ from typing_extensions import Literal, TypeAlias from PIL import Image from .actions import Action +from .enums import Align, AnnotationFlag, AnnotationName, Corner, PageLayout, RenderStyle, TextMarkupType, XPos, YPos from .recorder import FPDFRecorder from .syntax import DestinationXYZ from .util import _Unit @@ -33,10 +34,19 @@ class Annotation(NamedTuple): y: int width: int height: int + flags: tuple[AnnotationFlag, ...] = ... contents: str | None = ... link: str | int | None = ... alt_text: str | None = ... action: Action | None = ... + color: int | None = ... + modification_time: datetime.datetime | None = ... + title: str | None = ... + quad_points: Sequence[int] | None = ... + page: int | None = ... + border_width: int = ... + name: AnnotationName | None = ... + ink_list: tuple[int, ...] = ... class TitleStyle(NamedTuple): font_family: str | None = ... @@ -88,7 +98,6 @@ class FPDF: current_font: _Font font_family: str font_style: str - font_size_pt: int str_alias_nb_pages: str underline: int draw_color: str @@ -128,9 +137,11 @@ class FPDF: orientation: _Orientation = ..., unit: _Unit | float = ..., format: _Format | tuple[float, float] = ..., - font_cache_dir: bool = ..., + font_cache_dir: str | Literal["DEPRECATED"] = ..., ) -> None: ... @property + def font_size_pt(self) -> float: ... + @property def unifontsubset(self) -> bool: ... @property def epw(self) -> float: ... @@ -149,6 +160,7 @@ class FPDF: page_break_trigger: float def set_auto_page_break(self, auto: bool, margin: float = ...) -> None: ... zoom_mode: Literal["fullpage", "fullwidth", "real", "default"] | float + page_layout: PageLayout | None def set_display_mode( self, zoom: Literal["fullpage", "fullwidth", "real", "default"] | float, @@ -195,22 +207,84 @@ class FPDF: def get_string_width(self, s: str, normalized: bool = ..., markdown: bool = ...) -> float: ... def set_line_width(self, width: float) -> None: ... def line(self, x1: float, y1: float, x2: float, y2: float) -> None: ... - def polyline(self, point_list: list[tuple[float, float]], fill: bool = ..., polygon: bool = ...) -> None: ... - def polygon(self, point_list: list[tuple[float, float]], fill: bool = ...) -> None: ... + def polyline( + self, point_list: list[tuple[float, float]], fill: bool = ..., polygon: bool = ..., style: RenderStyle | str | None = ... + ) -> None: ... + def polygon(self, point_list: list[tuple[float, float]], fill: bool = ..., style: RenderStyle | str | None = ...) -> None: ... def dashed_line(self, x1, y1, x2, y2, dash_length: int = ..., space_length: int = ...) -> None: ... - def rect(self, x: float, y: float, w: float, h: float, style: Incomplete | None = ...) -> None: ... - def ellipse(self, x: float, y: float, w: float, h: float, style: Incomplete | None = ...) -> None: ... - def circle(self, x: float, y: float, r, style: Incomplete | None = ...) -> None: ... - def add_font(self, family: str, style: _FontStyle = ..., fname: str | None = ..., uni: bool = ...) -> None: ... + def rect( + self, + x: float, + y: float, + w: float, + h: float, + style: RenderStyle | str | None = ..., + round_corners: tuple[str, ...] | tuple[Corner, ...] | bool = ..., + corner_radius: float = ..., + ) -> None: ... + def ellipse(self, x: float, y: float, w: float, h: float, style: RenderStyle | str | None = ...) -> None: ... + def circle(self, x: float, y: float, r, style: RenderStyle | str | None = ...) -> None: ... + def regular_polygon( + self, + x: float, + y: float, + numSides: int, + polyWidth: float, + rotateDegrees: float = ..., + style: RenderStyle | str | None = ..., + ): ... + def star( + self, + x: float, + y: float, + r_in: float, + r_out: float, + corners: int, + rotate_degrees: float = ..., + style: RenderStyle | str | None = ..., + ): ... + def add_font( + self, family: str, style: _FontStyle = ..., fname: str | None = ..., uni: bool | Literal["DEPRECATED"] = ... + ) -> None: ... def set_font(self, family: str | None = ..., style: _FontStyles = ..., size: int = ...) -> None: ... def set_font_size(self, size: int) -> None: ... font_stretching: float def set_stretching(self, stretching: float) -> None: ... def add_link(self) -> int: ... def set_link(self, link, y: int = ..., x: int = ..., page: int = ..., zoom: float | Literal["null"] = ...) -> None: ... - def link(self, x: float, y: float, w: float, h: float, link: str | int, alt_text: str | None = ...) -> Annotation: ... - def text_annotation(self, x: float, y: float, text: str) -> None: ... + def link( + self, x: float, y: float, w: float, h: float, link: str | int, alt_text: str | None = ..., border_width: int = ... + ) -> Annotation: ... + def text_annotation( + self, + x: float, + y: float, + text: str, + w: float = ..., + h: float = ..., + name: AnnotationName | str | None = ..., + flags: tuple[AnnotationFlag, ...] | tuple[str, ...] = ..., + ) -> None: ... def add_action(self, action, x: float, y: float, w: float, h: float) -> None: ... + def highlight( + self, + text: str, + title: str = ..., + type: TextMarkupType | str = ..., + color: tuple[float, float, float] = ..., + modification_time: datetime.datetime | None = ..., + ) -> _GeneratorContextManager[None]: ... + add_highlight = highlight + def add_text_markup_annotation( + self, + type: str, + text: str, + quad_points: Sequence[int], + title: str = ..., + color: tuple[float, float, float] = ..., + modification_time: datetime.datetime | None = ..., + page: int | None = ..., + ) -> Annotation: ... def text(self, x: float, y: float, txt: str = ...) -> None: ... def rotate(self, angle: float, x: float | None = ..., y: float | None = ...) -> None: ... def rotation(self, angle: float, x: float | None = ..., y: float | None = ...) -> _GeneratorContextManager[None]: ... @@ -222,12 +296,14 @@ class FPDF: h: float | None = ..., txt: str = ..., border: bool | Literal[0, 1] | str = ..., - ln: int = ..., - align: str = ..., + ln: int | Literal["DEPRECATED"] = ..., + align: str | Align = ..., fill: bool = ..., link: str = ..., - center: bool = ..., + center: bool | Literal["DEPRECATED"] = ..., markdown: bool = ..., + new_x: XPos | str = ..., + new_y: YPos | str = ..., ) -> bool: ... def will_page_break(self, height: float) -> bool: ... def multi_cell( @@ -236,15 +312,18 @@ class FPDF: h: float | None = ..., txt: str = ..., border: bool | Literal[0, 1] | str = ..., - align: str = ..., + align: str | Align = ..., fill: bool = ..., split_only: bool = ..., - link: str = ..., - ln: int = ..., + link: str | int = ..., + ln: int | Literal["DEPRECATED"] = ..., max_line_height: float | None = ..., markdown: bool = ..., + print_sh: bool = ..., + new_x: XPos | str = ..., + new_y: YPos | str = ..., ): ... - def write(self, h: float | None = ..., txt: str = ..., link: str = ...) -> None: ... + def write(self, h: float | None = ..., txt: str = ..., link: str = ..., print_sh: bool = ...) -> None: ... def image( self, name: str | Image.Image | BytesIO | StrPath, diff --git a/stubs/fpdf2/fpdf/syntax.pyi b/stubs/fpdf2/fpdf/syntax.pyi index eccb1b845..02cee6b5c 100644 --- a/stubs/fpdf2/fpdf/syntax.pyi +++ b/stubs/fpdf2/fpdf/syntax.pyi @@ -25,7 +25,7 @@ class PDFObject: def ref(self): ... def serialize(self, fpdf: Any | None = ..., obj_dict: Any | None = ...): ... -def camel_case(property_name): ... +def camel_case(snake_case: str) -> str: ... class PDFString(str): def serialize(self): ... @@ -46,3 +46,8 @@ class DestinationXYZ(Destination): self, page: int, x: float = ..., y: float = ..., zoom: float | Literal["null"] = ..., page_as_obj_id: bool = ... ) -> None: ... def as_str(self, pdf: Any | None = ...): ... + +class Raw(str): ... + +class Name(str): + def pdf_repr(self) -> str: ...