Skip to content

Commit dd85323

Browse files
authored
[fpdf2] Update to 2.8.3 (#13871)
1 parent e07284f commit dd85323

15 files changed

Lines changed: 320 additions & 41 deletions

stubs/fpdf2/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "2.8.2"
1+
version = "2.8.3"
22
upstream_repository = "https://github.com/PyFPDF/fpdf2"
33
requires = ["Pillow>=10.3.0"]
44

stubs/fpdf2/fpdf/_fonttools_shims.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from abc import ABCMeta, abstractmethod
33
from collections.abc import Mapping
44
from logging import Logger
5-
from typing import Protocol
5+
from typing import Any, Protocol
66
from typing_extensions import TypeAlias
77

88
# from fonttools.ttLib.ttGlyphSet
@@ -13,6 +13,9 @@ class _TTGlyph(Protocol):
1313

1414
_TTGlyphSet: TypeAlias = Mapping[str, _TTGlyph] # Simplified for our needs
1515

16+
# fonttools.ttLib.TTFont
17+
_TTFont: TypeAlias = Any # noqa: Y047
18+
1619
# from fontTools.misc.loggingTools
1720

1821
class LogMixin:

stubs/fpdf2/fpdf/enums.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TextEmphasis(CoerciveIntFlag):
5656
B = 1
5757
I = 2
5858
U = 4
59+
S = 8
5960

6061
@property
6162
def style(self) -> str: ...
@@ -296,6 +297,11 @@ class TextDirection(CoerciveEnum):
296297
TTB = "TTB"
297298
BTT = "BTT"
298299

300+
class OutputIntentSubType(CoerciveEnum):
301+
PDFX = "GTS_PDFX"
302+
PDFA = "GTS_PDFA1"
303+
ISOPDF = "ISO_PDFE1"
304+
299305
class PageLabelStyle(CoerciveEnum):
300306
NUMBER = "D"
301307
UPPER_ROMAN = "R"
@@ -322,3 +328,13 @@ class PageOrientation(CoerciveEnum):
322328

323329
@classmethod
324330
def coerce(cls, value: Self | str) -> Self: ... # type: ignore[override]
331+
332+
class PDFResourceType(Enum):
333+
EXT_G_STATE = "ExtGState"
334+
COLOR_SPACE = "ColorSpace"
335+
PATTERN = "Pattern"
336+
SHADDING = "Shading"
337+
X_OBJECT = "XObject"
338+
FONT = "Font"
339+
PROC_SET = "ProcSet"
340+
PROPERTIES = "Properties"

stubs/fpdf2/fpdf/fonts.pyi

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import dataclasses
2-
from _typeshed import Incomplete
2+
from _typeshed import Incomplete, Unused
3+
from collections import defaultdict
34
from collections.abc import Generator
45
from dataclasses import dataclass
6+
from logging import Logger
57
from typing import Final, overload
68
from typing_extensions import Self, deprecated
79

10+
from ._fonttools_shims import _TTFont
811
from .drawing import DeviceGray, DeviceRGB, Number
912
from .enums import Align, TextEmphasis
1013
from .syntax import PDFObject
1114

15+
LOGGER: Logger
16+
1217
# Only defined if harfbuzz is installed.
1318
class HarfBuzzFont(Incomplete): # derives from uharfbuzz.Font
1419
def __deepcopy__(self, _memo: object) -> Self: ...
@@ -73,37 +78,48 @@ class TitleStyle(TextStyle): ...
7378

7479
__pdoc__: Final[dict[str, bool]]
7580

76-
class _FontMixin:
81+
class CoreFont:
7782
i: int
7883
type: str
7984
name: str
8085
up: int
8186
ut: int
87+
sp: int
88+
ss: int
8289
cw: int
8390
fontkey: str
8491
emphasis: TextEmphasis
85-
def encode_text(self, text: str): ...
86-
87-
class CoreFont(_FontMixin):
8892
def __init__(self, fpdf, fontkey: str, style: int) -> None: ...
89-
def get_text_width(self, text: str, font_size_pt: int, _): ...
93+
def get_text_width(self, text: str, font_size_pt: int, _: Unused) -> float: ...
94+
def encode_text(self, text: str) -> str: ...
9095

91-
class TTFFont(_FontMixin):
96+
class TTFFont:
97+
i: int
98+
type: str
9299
ttffile: Incomplete
93-
ttfont: Incomplete
94-
scale: Incomplete
95-
desc: Incomplete
100+
fontkey: str
101+
ttfont: _TTFont
102+
scale: float
103+
desc: PDFFontDescriptor
104+
cw: defaultdict[str, int]
96105
cmap: Incomplete
97-
glyph_ids: Incomplete
98-
missing_glyphs: Incomplete
99-
subset: Incomplete
106+
glyph_ids: dict[Incomplete, Incomplete]
107+
missing_glyphs: list[Incomplete]
108+
name: str
109+
up: int
110+
ut: int
111+
sp: int
112+
ss: int
113+
emphasis: TextEmphasis
114+
subset: SubsetMap
100115
hbfont: HarfBuzzFont | None # Not always defined.
101116
def __init__(self, fpdf, font_file_path, fontkey: str, style: int) -> None: ...
102117
def close(self) -> None: ...
103-
def get_text_width(self, text: str, font_size_pt: int, text_shaping_parms): ...
104-
def shaped_text_width(self, text: str, font_size_pt: int, text_shaping_parms): ...
105-
def perform_harfbuzz_shaping(self, text: str, font_size_pt: int, text_shaping_parms): ...
106-
def shape_text(self, text: str, font_size_pt: int, text_shaping_parms): ...
118+
def get_text_width(self, text: str, font_size_pt: int, text_shaping_params): ...
119+
def shaped_text_width(self, text: str, font_size_pt: int, text_shaping_params): ...
120+
def perform_harfbuzz_shaping(self, text: str, font_size_pt: int, text_shaping_params): ...
121+
def encode_text(self, text: str) -> str: ...
122+
def shape_text(self, text: str, font_size_pt: int, text_shaping_params): ...
107123

108124
class PDFFontDescriptor(PDFObject):
109125
type: Incomplete
@@ -128,7 +144,7 @@ class Glyph:
128144

129145
class SubsetMap:
130146
font: TTFFont
131-
def __init__(self, font: TTFFont, identities: list[int]) -> None: ...
147+
def __init__(self, font: TTFFont) -> None: ...
132148
def __len__(self) -> int: ...
133149
def items(self) -> Generator[Incomplete, None, None]: ...
134150
def pick(self, unicode: int): ...

stubs/fpdf2/fpdf/fpdf.pyi

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from .enums import (
2323
EncryptionMethod,
2424
FileAttachmentAnnotationName,
2525
MethodReturnValue,
26+
OutputIntentSubType,
2627
PageLabelStyle,
2728
PageLayout,
2829
PageMode,
@@ -53,7 +54,7 @@ from .image_datastructures import (
5354
VectorImageInfo as VectorImageInfo,
5455
_TextAlign,
5556
)
56-
from .output import OutputProducer, PDFPage
57+
from .output import OutputProducer, PDFICCProfile, PDFPage
5758
from .recorder import FPDFRecorder
5859
from .structure_tree import StructureTreeBuilder
5960
from .syntax import DestinationXYZ
@@ -77,7 +78,35 @@ __all__ = [
7778
_Orientation: TypeAlias = Literal["", "portrait", "p", "P", "landscape", "l", "L"]
7879
_Format: TypeAlias = Literal["", "a3", "A3", "a4", "A4", "a5", "A5", "letter", "Letter", "legal", "Legal"]
7980
_FontStyle: TypeAlias = Literal["", "B", "I", "BI"]
80-
_FontStyles: TypeAlias = Literal["", "B", "I", "U", "BU", "UB", "BI", "IB", "IU", "UI", "BIU", "BUI", "IBU", "IUB", "UBI", "UIB"]
81+
_FontStyles: TypeAlias = Literal[
82+
"",
83+
"B",
84+
"I",
85+
"U",
86+
"S",
87+
"BU",
88+
"UB",
89+
"BI",
90+
"IB",
91+
"IU",
92+
"UI",
93+
"BS",
94+
"SB",
95+
"IS",
96+
"SI",
97+
"BIU",
98+
"BUI",
99+
"IBU",
100+
"IUB",
101+
"UBI",
102+
"UIB",
103+
"BIS",
104+
"BSI",
105+
"IBS",
106+
"ISB",
107+
"SBI",
108+
"SIB",
109+
]
81110

82111
FPDF_VERSION: Final[str]
83112
PAGE_FORMATS: dict[_Format, tuple[float, float]]
@@ -88,12 +117,14 @@ class ToCPlaceholder(NamedTuple):
88117
y: int
89118
page_orientation: str
90119
pages: int = 1
120+
reset_page_indices: bool = True
91121

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

94124
class FPDF(GraphicsStateMixin):
95125
MARKDOWN_BOLD_MARKER: ClassVar[str]
96126
MARKDOWN_ITALICS_MARKER: ClassVar[str]
127+
MARKDOWN_STRIKETHROUGH_MARKER: ClassVar[str]
97128
MARKDOWN_UNDERLINE_MARKER: ClassVar[str]
98129
MARKDOWN_ESCAPE_CHARACTER: ClassVar[str]
99130
MARKDOWN_LINK_REGEX: ClassVar[Pattern[str]]
@@ -145,7 +176,6 @@ class FPDF(GraphicsStateMixin):
145176
compress: bool
146177
pdf_version: str
147178
creation_date: datetime.datetime
148-
graphics_style_names_per_page_number: dict[int, set[str]]
149179

150180
buffer: bytearray | None
151181

@@ -179,6 +209,19 @@ class FPDF(GraphicsStateMixin):
179209
def is_ttf_font(self) -> bool: ...
180210
@property
181211
def page_mode(self) -> PageMode: ...
212+
@page_mode.setter
213+
def page_mode(self, page_mode: PageMode) -> None: ...
214+
@property
215+
def output_intents(self): ...
216+
def add_output_intent(
217+
self,
218+
subtype: OutputIntentSubType,
219+
output_condition_identifier: str | None = None,
220+
output_condition: str | None = None,
221+
registry_name: str | None = None,
222+
dest_output_profile: PDFICCProfile | None = None,
223+
info: str | None = None,
224+
) -> None: ...
182225
@property
183226
def epw(self) -> float: ...
184227
@property
@@ -336,14 +379,15 @@ class FPDF(GraphicsStateMixin):
336379
closed: bool = False,
337380
style: RenderStyle | Literal["D", "F", "DF", "FD"] | None = None,
338381
) -> None: ...
382+
def use_pattern(self, shading) -> _GeneratorContextManager[None]: ...
339383
def add_font(
340384
self,
341385
family: str | None = None,
342386
style: _FontStyle = "",
343387
fname: str | PurePath | None = None,
344388
uni: bool | Literal["DEPRECATED"] = "DEPRECATED",
345389
) -> None: ...
346-
def set_font(self, family: str | None = None, style: _FontStyles = "", size: int = 0) -> None: ...
390+
def set_font(self, family: str | None = None, style: _FontStyles | TextEmphasis = "", size: int = 0) -> None: ...
347391
def set_font_size(self, size: float) -> None: ...
348392
def set_char_spacing(self, spacing: float) -> None: ...
349393
def set_stretching(self, stretching: float) -> None: ...
@@ -618,7 +662,11 @@ class FPDF(GraphicsStateMixin):
618662
def unbreakable(self) -> _GeneratorContextManager[FPDFRecorder]: ...
619663
def offset_rendering(self) -> _GeneratorContextManager[FPDFRecorder]: ...
620664
def insert_toc_placeholder(
621-
self, render_toc_function: Callable[[FPDF, list[OutlineSection]], object], pages: int = 1, allow_extra_pages: bool = False
665+
self,
666+
render_toc_function: Callable[[FPDF, list[OutlineSection]], object],
667+
pages: int = 1,
668+
allow_extra_pages: bool = False,
669+
reset_page_indices: bool = True,
622670
) -> None: ...
623671
def set_section_title_styles(
624672
self,

stubs/fpdf2/fpdf/graphics_state.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, ClassVar, Literal, TypedDict, type_check_only
1+
from typing import Any, ClassVar, Final, Literal, TypedDict, type_check_only
22

33
from .drawing import DeviceGray, DeviceRGB
44
from .enums import TextMode
@@ -36,6 +36,10 @@ class GraphicsStateMixin:
3636
@underline.setter
3737
def underline(self, v: bool) -> None: ...
3838
@property
39+
def strikethrough(self) -> bool: ...
40+
@strikethrough.setter
41+
def strikethrough(self, v: bool) -> None: ...
42+
@property
3943
def font_style(self) -> str: ...
4044
@font_style.setter
4145
def font_style(self, v: str) -> None: ...
@@ -64,6 +68,10 @@ class GraphicsStateMixin:
6468
@current_font.setter
6569
def current_font(self, v: dict[str, Any]) -> None: ...
6670
@property
71+
def current_font_is_set_on_page(self) -> bool: ...
72+
@current_font_is_set_on_page.setter
73+
def current_font_is_set_on_page(self, v: bool) -> None: ...
74+
@property
6775
def dash_pattern(self) -> dict[str, float]: ...
6876
@dash_pattern.setter
6977
def dash_pattern(self, v: dict[str, float]) -> None: ...
@@ -116,3 +124,5 @@ class GraphicsStateMixin:
116124
@text_shaping.setter
117125
def text_shaping(self, v: _TextShaping | None) -> None: ...
118126
def font_face(self) -> FontFace: ...
127+
128+
__pdoc__: Final[dict[str, bool]]

stubs/fpdf2/fpdf/line_break.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class Fragment:
4343
@property
4444
def text_mode(self): ...
4545
@property
46-
def underline(self): ...
46+
def underline(self) -> bool: ...
47+
@property
48+
def strikethrough(self) -> bool: ...
4749
@property
4850
def draw_color(self): ...
4951
@property
@@ -90,6 +92,7 @@ class TextLine(NamedTuple):
9092
max_width: float
9193
trailing_nl: bool = False
9294
trailing_form_feed: bool = False
95+
indent: float = 0
9396
def get_ordered_fragments(self) -> tuple[Fragment, ...]: ...
9497

9598
class SpaceHint(NamedTuple):
@@ -114,13 +117,14 @@ class HyphenHint(NamedTuple):
114117

115118
class CurrentLine:
116119
max_width: float
117-
print_sh: Incomplete
120+
print_sh: bool
121+
indent: float
118122
fragments: list[Fragment]
119123
height: int
120124
number_of_spaces: int
121125
space_break_hint: Incomplete
122126
hyphen_break_hint: Incomplete
123-
def __init__(self, max_width: float, print_sh: bool = False) -> None: ...
127+
def __init__(self, max_width: float, print_sh: bool = False, indent: float = 0) -> None: ...
124128
@property
125129
def width(self) -> float: ...
126130
def add_character(
@@ -150,6 +154,7 @@ class MultiLineBreak:
150154
fragment_index: int
151155
character_index: int
152156
idx_last_forced_break: int | None
157+
first_line_indent: float
153158
def __init__(
154159
self,
155160
fragments: Sequence[Fragment],
@@ -160,5 +165,6 @@ class MultiLineBreak:
160165
wrapmode: WrapMode = ...,
161166
line_height: float = 1.0,
162167
skip_leading_spaces: bool = False,
168+
first_line_indent: float = 0,
163169
) -> None: ...
164170
def get_line(self) -> TextLine: ...

stubs/fpdf2/fpdf/outline.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from _typeshed import Incomplete
22
from collections.abc import Generator, Iterable
3-
from typing import NamedTuple
3+
from dataclasses import dataclass
44

55
from .fonts import TextStyle
66
from .fpdf import FPDF
77
from .structure_tree import StructElem
88
from .syntax import Destination, PDFObject, PDFString
99

10-
class OutlineSection(NamedTuple):
10+
@dataclass
11+
class OutlineSection:
1112
name: str
1213
level: int
1314
page_number: int

0 commit comments

Comments
 (0)