Skip to content
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
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.4"
version = "2.7.6"
upstream_repository = "https://github.com/PyFPDF/fpdf2"
requires = ["types-Pillow>=9.2.0"]

Expand Down
1 change: 1 addition & 0 deletions stubs/fpdf2/fpdf/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ __all__ = [
"FPDF",
"FPDFException",
"Align",
"TextMode",
"XPos",
"YPos",
"Template",
Expand Down
4 changes: 4 additions & 0 deletions stubs/fpdf2/fpdf/deprecation.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from types import ModuleType
from typing import Any, NoReturn

def support_deprecated_txt_arg(fn): ...

class WarnOnDeprecatedModuleAttributes(ModuleType):
def __call__(self) -> NoReturn: ...
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...

def get_stack_level() -> int: ...
47 changes: 32 additions & 15 deletions stubs/fpdf2/fpdf/encryption.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from _typeshed import Incomplete, SupportsLenAndGetItem
from collections.abc import Generator, Iterable
from logging import Logger
from typing import ClassVar, Protocol, TypeVar
from typing import ClassVar, Protocol, TypeVar, overload
from typing_extensions import TypeAlias

from .enums import EncryptionMethod
from .enums import AccessPermission, EncryptionMethod
from .fpdf import FPDF
from .syntax import Name, PDFObject

Expand All @@ -28,7 +28,7 @@ class CryptFilter:
type: Name
c_f_m: Name
length: int
def __init__(self, mode, length) -> None: ...
def __init__(self, mode: str, length: int) -> None: ...
def serialize(self) -> str: ...

class EncryptionDictionary(PDFObject):
Expand All @@ -54,8 +54,8 @@ class StandardSecurityHandler:
encryption_method: EncryptionMethod | None
cf: CryptFilter | None
key_length: int
v: int
r: int
version: int
revision: int
encrypt_metadata: bool

# The following fields are only defined after a call to generate_passwords().
Expand All @@ -64,29 +64,46 @@ class StandardSecurityHandler:
o: str
k: str
u: str
# The following field is only defined after a call to generate_user_password_rev6().
ue: Incomplete
# The following field is only defined after a call to generate_owner_password_rev6().
oe: Incomplete
# The following field is only defined after a call to generate_perms_rev6().
perms_rev6: Incomplete

def __init__(
self,
fpdf: FPDF,
owner_password: str,
user_password: str | None = None,
permission: Incomplete | None = None,
encryption_method: EncryptionMethod | None = None,
permission: AccessPermission = ...,
encryption_method: EncryptionMethod = ...,
encrypt_metadata: bool = False,
) -> None: ...
def generate_passwords(self, file_id) -> None: ...
def generate_passwords(self, file_id: str) -> None: ...
def get_encryption_obj(self) -> EncryptionDictionary: ...
def encrypt(self, text: str | bytes | bytearray, obj_id) -> bytes: ...
def encrypt_string(self, string, obj_id): ...
def encrypt_stream(self, stream, obj_id): ...
@overload
def encrypt(self, text: bytes | bytearray, obj_id: int) -> bytes: ...
@overload
def encrypt(self, text: str, obj_id: int) -> str: ...
def encrypt_string(self, string: str, obj_id: int) -> str: ...
def encrypt_stream(self, stream: bytes, obj_id: int) -> bytes: ...
def is_aes_algorithm(self) -> bool: ...
def encrypt_bytes(self, data, obj_id) -> list[int]: ...
def encrypt_AES_cryptography(self, key, data): ...
def get_initialization_vector(self, size: int) -> bytearray: ...
def encrypt_bytes(self, data: bytes, obj_id: int) -> list[int]: ...
def encrypt_AES_cryptography(self, key: bytes, data: bytes) -> bytes: ...
@classmethod
def get_random_bytes(cls, size: int) -> bytes: ...
@classmethod
def prepare_string(cls, string: str) -> bytes: ...
def padded_password(self, password: str) -> bytearray: ...
def generate_owner_password(self) -> str: ...
def generate_user_password(self) -> str: ...
@classmethod
def compute_hash(cls, input_password: bytes, salt: bytes, user_key: bytes = ...) -> bytes: ...
def generate_user_password_rev6(self) -> None: ...
def generate_owner_password_rev6(self) -> None: ...
def generate_perms_rev6(self) -> None: ...
def generate_encryption_key(self) -> bytes: ...

def md5(data: bytes) -> bytes: ...
def md5(data: bytes | bytearray) -> bytes: ...
def int32(n: int) -> int: ...
16 changes: 16 additions & 0 deletions stubs/fpdf2/fpdf/enums.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Align(CoerciveEnum):
R: str
J: str

class VAlign(CoerciveEnum):
M: str
T: str
B: str

class TextEmphasis(CoerciveIntFlag):
B: int
I: int
Expand Down Expand Up @@ -103,6 +108,16 @@ class YPos(CoerciveEnum):
TMARGIN: str
BMARGIN: str

class Angle(CoerciveIntEnum):
NORTH: int
EAST: int
SOUTH: int
WEST: int
NORTHEAST: int
SOUTHEAST: int
SOUTHWEST: int
NORTHWEST: int

class PageLayout(CoerciveEnum):
SINGLE_PAGE: Name
ONE_COLUMN: Name
Expand Down Expand Up @@ -236,3 +251,4 @@ class EncryptionMethod(Enum):
NO_ENCRYPTION: int
RC4: int
AES_128: int
AES_256: int
78 changes: 78 additions & 0 deletions stubs/fpdf2/fpdf/fonts.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import dataclasses
from _typeshed import Incomplete
from collections.abc import Generator
from dataclasses import dataclass

from .drawing import DeviceGray, DeviceRGB, Number
from .enums import TextEmphasis
from .syntax import PDFObject

@dataclass
class FontFace:
Expand All @@ -24,5 +26,81 @@ class FontFace:

replace = dataclasses.replace

class _FontMixin:
i: int
type: str
name: str
up: int
ut: int
cw: int
fontkey: str
emphasis: TextEmphasis
def encode_text(self, text: str): ...

class CoreFont(_FontMixin):
def __init__(self, fpdf, fontkey: str, style: int) -> None: ...
def get_text_width(self, text: str, font_size_pt: int, _): ...

class TTFFont(_FontMixin):
ttffile: Incomplete
ttfont: Incomplete
scale: Incomplete
desc: Incomplete
cmap: Incomplete
glyph_ids: Incomplete
missing_glyphs: Incomplete
subset: Incomplete
hbfont: Incomplete
def __init__(self, fpdf, font_file_path, fontkey: str, style: int) -> None: ...
def close(self) -> None: ...
def get_text_width(self, text: str, font_size_pt: int, text_shaping_parms): ...
def shaped_text_width(self, text: str, font_size_pt: int, text_shaping_parms): ...
def perform_harfbuzz_shaping(self, text: str, font_size_pt: int, text_shaping_parms): ...
def shape_text(self, text: str, font_size_pt: int, text_shaping_parms): ...

class PDFFontDescriptor(PDFObject):
type: Incomplete
ascent: Incomplete
descent: Incomplete
cap_height: Incomplete
flags: Incomplete
font_b_box: Incomplete
italic_angle: Incomplete
stem_v: Incomplete
missing_width: Incomplete
font_name: Incomplete
def __init__(self, ascent, descent, cap_height, flags, font_b_box, italic_angle, stem_v, missing_width) -> None: ...

class Glyph:
glyph_id: int
unicode: tuple[Incomplete, ...]
glyph_name: str
glyph_width: int
def __hash__(self): ...
def __init__(self, glyph_id, unicode, glyph_name, glyph_width) -> None: ...
def __lt__(self, other): ...
def __gt__(self, other): ...
def __le__(self, other): ...
def __ge__(self, other): ...

__match_args__ = ("glyph_id", "unicode", "glyph_name", "glyph_width")

class SubsetMap:
font: TTFFont
def __init__(self, font: TTFFont, identities: list[int]) -> None: ...
def __len__(self) -> int: ...
def items(self) -> Generator[Incomplete, None, None]: ...
def pick(self, unicode: int): ...
def pick_glyph(self, glyph): ...
def get_glyph(
self,
glyph: Incomplete | None = None,
unicode: Incomplete | None = None,
glyph_name: Incomplete | None = None,
glyph_width: Incomplete | None = None,
) -> Glyph: ...
def get_all_glyph_names(self): ...

CORE_FONTS: dict[str, str]
COURIER_FONT: dict[str, int]
CORE_FONTS_CHARWIDTHS: dict[str, dict[str, int]]
52 changes: 36 additions & 16 deletions stubs/fpdf2/fpdf/fpdf.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from _typeshed import Incomplete, StrPath, Unused
from collections.abc import Callable, Iterable, Sequence
from collections.abc import Callable, Generator, Iterable, Sequence
from contextlib import _GeneratorContextManager
from io import BytesIO
from pathlib import PurePath
Expand Down Expand Up @@ -83,12 +83,6 @@ class ToCPlaceholder(NamedTuple):
y: int
pages: int = ...

class SubsetMap:
def __init__(self, identities: Iterable[int]) -> None: ...
def __len__(self) -> int: ...
def pick(self, unicode: int) -> int: ...
def dict(self) -> dict[int, int]: ...

def get_page_format(format: _Format | tuple[float, float], k: float | None = None) -> tuple[float, float]: ...

# TODO: TypedDicts
Expand All @@ -101,6 +95,7 @@ class FPDF(GraphicsStateMixin):
MARKDOWN_UNDERLINE_MARKER: ClassVar[str]
MARKDOWN_LINK_REGEX: ClassVar[Pattern[str]]
MARKDOWN_LINK_COLOR: ClassVar[Incomplete | None]
MARKDOWN_LINK_UNDERLINE: ClassVar[bool]

HTML2FPDF_CLASS: ClassVar[type[HTML2FPDF]]

Expand Down Expand Up @@ -200,6 +195,14 @@ class FPDF(GraphicsStateMixin):
zoom: Literal["fullpage", "fullwidth", "real", "default"] | float,
layout: Literal["single", "continuous", "two", "default"] = "continuous",
) -> None: ...
def set_text_shaping(
self,
use_shaping_engine: bool = True,
features: dict[str, bool] | None = None,
direction: Literal["ltr", "rtl"] | None = None,
script: str | None = None,
language: str | None = None,
): ...
def set_compression(self, compress: bool) -> None: ...
title: str
def set_title(self, title: str) -> None: ...
Expand Down Expand Up @@ -397,12 +400,13 @@ class FPDF(GraphicsStateMixin):
color: Sequence[float] = (1, 1, 0),
border_width: int = 1,
) -> AnnotationDict: ...
def text(self, x: float, y: float, txt: str = "") -> None: ...
def text(self, x: float, y: float, text: str = "") -> None: ...
def rotate(self, angle: float, x: float | None = None, y: float | None = None) -> None: ...
def rotation(self, angle: float, x: float | None = None, y: float | None = None) -> _GeneratorContextManager[None]: ...
def skew(
self, ax: float = 0, ay: float = 0, x: float | None = None, y: float | None = None
) -> _GeneratorContextManager[None]: ...
def mirror(self, origin, angle) -> Generator[None, None, None]: ...
def local_context(
self,
font_family: Incomplete | None = None,
Expand All @@ -421,13 +425,13 @@ class FPDF(GraphicsStateMixin):
self,
w: float | None = None,
h: float | None = None,
txt: str = "",
text: str = "",
border: bool | Literal[0, 1] | str = 0,
ln: int | Literal["DEPRECATED"] = "DEPRECATED",
align: str | Align = ...,
fill: bool = False,
link: str = "",
center: bool | Literal["DEPRECATED"] = "DEPRECATED",
center: bool = False,
markdown: bool = False,
new_x: XPos | str = ...,
new_y: YPos | str = ...,
Expand All @@ -438,12 +442,12 @@ class FPDF(GraphicsStateMixin):
self,
w: float,
h: float | None = None,
txt: str = "",
text: str = "",
border: bool | Literal[0, 1] | str = 0,
align: str | Align = ...,
fill: bool = False,
split_only: bool = False,
link: str | int = "",
link: str = "",
ln: int | Literal["DEPRECATED"] = "DEPRECATED",
max_line_height: float | None = None,
markdown: bool = False,
Expand All @@ -453,10 +457,26 @@ class FPDF(GraphicsStateMixin):
wrapmode: WrapMode = ...,
dry_run: bool = False,
output: MethodReturnValue | str | int = ...,
center: bool = False,
padding: int = 0,
): ...
def write(
self, h: float | None = None, txt: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = ...
self, h: float | None = None, text: str = "", link: str = "", print_sh: bool = False, wrapmode: WrapMode = ...
) -> bool: ...
def text_columns(
self,
text: str | None = None,
ncols: int = 1,
gutter: float = 10,
balance: bool = False,
text_align: Align | str = "LEFT",
line_height: float = 1,
l_margin: float | None = None,
r_margin: float | None = None,
print_sh: bool = False,
wrapmode: WrapMode = ...,
skip_leading_spaces: bool = False,
): ...
def image(
self,
name: str | Image.Image | BytesIO | StrPath,
Expand All @@ -480,7 +500,7 @@ class FPDF(GraphicsStateMixin):
def get_y(self) -> float: ...
def set_y(self, y: float) -> None: ...
def set_xy(self, x: float, y: float) -> None: ...
def normalize_text(self, txt: str) -> str: ...
def normalize_text(self, text: str) -> str: ...
def sign_pkcs12(
self,
pkcs_filepath: str,
Expand All @@ -505,8 +525,8 @@ class FPDF(GraphicsStateMixin):
flags: tuple[AnnotationFlag, ...] = ...,
) -> None: ...
def file_id(self) -> str: ...
def interleaved2of5(self, txt, x: float, y: float, w: float = 1, h: float = 10) -> None: ...
def code39(self, txt, x: float, y: float, w: float = 1.5, h: float = 5) -> None: ...
def interleaved2of5(self, text, x: float, y: float, w: float = 1, h: float = 10) -> None: ...
def code39(self, text, x: float, y: float, w: float = 1.5, h: float = 5) -> None: ...
def rect_clip(self, x: float, y: float, w: float, h: float) -> _GeneratorContextManager[None]: ...
def elliptic_clip(self, x: float, y: float, w: float, h: float) -> _GeneratorContextManager[None]: ...
def round_clip(self, x: float, y: float, r: float) -> _GeneratorContextManager[None]: ...
Expand Down
Loading