From c4483a7b019705e157118185b7badc6c59dfd3c5 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 11 Sep 2022 15:27:19 +0100 Subject: [PATCH] Update `fdpf2` stubs for v2.5.7 (#8721) Co-authored-by: Akuli --- stubs/fpdf2/fpdf/enums.pyi | 20 +++++++++- stubs/fpdf2/fpdf/fpdf.pyi | 69 +++++++++++++++++++++++++++++++--- stubs/fpdf2/fpdf/html.pyi | 2 + stubs/fpdf2/fpdf/ttfonts.pyi | 72 ------------------------------------ stubs/fpdf2/fpdf/util.pyi | 1 - 5 files changed, 84 insertions(+), 80 deletions(-) delete mode 100644 stubs/fpdf2/fpdf/ttfonts.pyi diff --git a/stubs/fpdf2/fpdf/enums.pyi b/stubs/fpdf2/fpdf/enums.pyi index 33db22617..5f5390104 100644 --- a/stubs/fpdf2/fpdf/enums.pyi +++ b/stubs/fpdf2/fpdf/enums.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, Self -from enum import Enum, IntEnum +from enum import Enum, Flag, IntEnum from .syntax import Name @@ -17,6 +17,13 @@ class CoerciveIntEnum(IntEnum): @classmethod def coerce(cls: type[Self], value: Self | str | int) -> Self: ... +class CharVPos(CoerciveEnum): + SUP: str + SUB: str + NOM: str + DENOM: str + LINE: str + class Align(CoerciveEnum): C: str X: str @@ -122,6 +129,11 @@ class AnnotationName(CoerciveEnum): NEW_PARAGRAPH: Name INSERT: Name +class FileAttachmentAnnotationName(CoerciveEnum): + PUSH_PIN: Name + GRAPH_PUSH_PIN: Name + PAPERCLIP_TAG: Name + class IntersectionRule(CoerciveEnum): NONZERO: str EVENODD: str @@ -166,4 +178,10 @@ class Corner(CoerciveEnum): BOTTOM_RIGHT: str BOTTOM_LEFT: str +class FontDescriptorFlags(Flag): + FIXED_PITCH: int + SYMBOLIC: int + ITALIC: int + FORCE_BOLD: int + __pdoc__: Incomplete diff --git a/stubs/fpdf2/fpdf/fpdf.pyi b/stubs/fpdf2/fpdf/fpdf.pyi index b39016d4b..01d7a2376 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, Sequence +from collections.abc import Callable, Iterable, Sequence from contextlib import _GeneratorContextManager from enum import IntEnum from io import BytesIO @@ -11,7 +11,18 @@ 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 .enums import ( + Align, + AnnotationFlag, + AnnotationName, + Corner, + FileAttachmentAnnotationName, + PageLayout, + RenderStyle, + TextMarkupType, + XPos, + YPos, +) from .recorder import FPDFRecorder from .syntax import DestinationXYZ from .util import _Unit @@ -47,9 +58,20 @@ class Annotation(NamedTuple): border_width: int = ... name: AnnotationName | None = ... ink_list: tuple[int, ...] = ... + embedded_file_name: str | None = ... field_type: str | None = ... value: str | None = ... +class EmbeddedFile(NamedTuple): + basename: str + bytes: bytes + desc: str = ... + creation_date: datetime.datetime | None = ... + modification_date: datetime.datetime | None = ... + compress: bool = ... + checksum: bool = ... + def file_spec(self, embedded_file_ref) -> str: ... + class TitleStyle(NamedTuple): font_family: str | None = ... font_style: str | None = ... @@ -95,17 +117,21 @@ class FPDF: images: dict[str, _Image] annots: defaultdict[int, list[Annotation]] links: dict[int, DestinationXYZ] + embedded_files: list[Incomplete] + embedded_files_per_pdf_ref: dict[Incomplete, Incomplete] in_footer: int lasth: int current_font: _Font font_family: str font_style: str + font_stretching: float + char_spacing: float + underline: bool str_alias_nb_pages: str - underline: int draw_color: str fill_color: str text_color: str - ws: int + page_background: Incomplete | None angle: int xmp_metadata: str | None image_filter: str @@ -144,7 +170,7 @@ class FPDF: @property def font_size_pt(self) -> float: ... @property - def unifontsubset(self) -> bool: ... + def is_ttf_font(self) -> bool: ... @property def epw(self) -> float: ... @property @@ -208,6 +234,7 @@ class FPDF: def set_text_color(self, r: int, g: int = ..., b: int = ...) -> None: ... def get_string_width(self, s: str, normalized: bool = ..., markdown: bool = ...) -> float: ... def set_line_width(self, width: float) -> None: ... + def set_page_background(self, background) -> 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 = ..., style: RenderStyle | str | None = ... @@ -250,13 +277,43 @@ class FPDF: ) -> None: ... def set_font(self, family: str | None = ..., style: _FontStyles = ..., size: int = ...) -> None: ... def set_font_size(self, size: float) -> None: ... - font_stretching: float + def set_char_spacing(self, spacing: float) -> None: ... 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 = ..., border_width: int = ... ) -> Annotation: ... + def embed_file( + self, + file_path: StrPath | None = ..., + bytes: bytes | None = ..., + basename: str | None = ..., + modification_date: datetime.datetime | None = ..., + *, + creation_date: datetime.datetime | None = ..., + desc: str = ..., + compress: bool = ..., + checksum: bool = ..., + ) -> str: ... + def file_attachment_annotation( + self, + file_path: StrPath, + x: float, + y: float, + w: float = ..., + h: float = ..., + name: FileAttachmentAnnotationName | str | None = ..., + flags: Iterable[AnnotationFlag | str] = ..., + *, + bytes: bytes | None = ..., + basename: str | None = ..., + creation_date: datetime.datetime | None = ..., + modification_date: datetime.datetime | None = ..., + desc: str = ..., + compress: bool = ..., + checksum: bool = ..., + ) -> Annotation: ... def text_annotation( self, x: float, diff --git a/stubs/fpdf2/fpdf/html.pyi b/stubs/fpdf2/fpdf/html.pyi index c2e9a3a59..68d78d2ff 100644 --- a/stubs/fpdf2/fpdf/html.pyi +++ b/stubs/fpdf2/fpdf/html.pyi @@ -39,6 +39,8 @@ class HTML2FPDF(HTMLParser): table_row_height: int heading_level: Any heading_sizes: Any + heading_above: float + heading_below: float def __init__( self, pdf, diff --git a/stubs/fpdf2/fpdf/ttfonts.pyi b/stubs/fpdf2/fpdf/ttfonts.pyi deleted file mode 100644 index 84990f260..000000000 --- a/stubs/fpdf2/fpdf/ttfonts.pyi +++ /dev/null @@ -1,72 +0,0 @@ -from typing import Any - -GF_WORDS: Any -GF_SCALE: Any -GF_MORE: Any -GF_XYSCALE: Any -GF_TWOBYTWO: Any - -def sub32(x, y): ... -def calcChecksum(data): ... - -class TTFontFile: - maxStrLenRead: int - def __init__(self) -> None: ... - filename: Any - charWidths: Any - glyphPos: Any - charToGlyph: Any - tables: Any - otables: Any - ascent: int - descent: int - version: Any - def getMetrics(self, file) -> None: ... - numTables: Any - searchRange: Any - entrySelector: Any - rangeShift: Any - def readTableDirectory(self) -> None: ... - def get_table_pos(self, tag): ... - def seek(self, pos) -> None: ... - def skip(self, delta) -> None: ... - def seek_table(self, tag, offset_in_table: int = ...): ... - def read_tag(self): ... - def read_short(self): ... - def read_ushort(self): ... - def read_ulong(self): ... - def get_ushort(self, pos): ... - @staticmethod - def splice(stream, offset, value): ... - def get_chunk(self, pos, length): ... - def get_table(self, tag): ... - def add(self, tag, data) -> None: ... - sFamilyClass: int - sFamilySubClass: int - name: Any - familyName: Any - styleName: Any - fullName: Any - uniqueFontID: Any - unitsPerEm: Any - bbox: Any - capHeight: Any - stemV: Any - italicAngle: Any - underlinePosition: Any - underlineThickness: Any - flags: int - def extractInfo(self) -> None: ... - maxUni: int - codeToGlyph: Any - glyphdata: Any - def makeSubset(self, file, subset): ... - def getGlyphs(self, originalGlyphIdx, nonlocals) -> None: ... - defaultWidth: Any - def getHMTX(self, numberOfHMetrics, numGlyphs, glyphToChar, scale) -> None: ... - def getHMetric(self, numberOfHMetrics, gid): ... - def getLOCA(self, indexToLocFormat, numGlyphs) -> None: ... - maxUniChar: int - def getCMAP4(self, unicode_cmap_offset, glyphToChar, charToGlyph) -> None: ... - def getCMAP12(self, unicode_cmap_offset, glyphToChar, charToGlyph) -> None: ... - def endTTFile(self, stm): ... diff --git a/stubs/fpdf2/fpdf/util.pyi b/stubs/fpdf2/fpdf/util.pyi index a98988cbe..aaccbbac9 100644 --- a/stubs/fpdf2/fpdf/util.pyi +++ b/stubs/fpdf2/fpdf/util.pyi @@ -4,7 +4,6 @@ from typing_extensions import Literal, TypeAlias _Unit: TypeAlias = Literal["pt", "mm", "cm", "in"] -def substr(s, start, length: int = ...): ... def enclose_in_parens(s): ... def escape_parens(s): ... def b(s): ...