Skip to content

Commit 9a9cc18

Browse files
authored
[reportlab] Add more annotations for pdfgen (#15452)
1 parent de7daeb commit 9a9cc18

File tree

5 files changed

+68
-43
lines changed

5 files changed

+68
-43
lines changed

stubs/reportlab/reportlab/pdfgen/canvas.pyi

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ from collections.abc import Callable
33
from typing import IO, Literal
44

55
from reportlab.lib.colors import Color, _ConvertibleToColor
6+
from reportlab.pdfbase.acroform import AcroForm
7+
from reportlab.pdfbase.pdfdoc import Destination
8+
from reportlab.pdfgen.pathobject import PDFPathObject
69
from reportlab.pdfgen.textobject import PDFTextObject, _PDFColorSetter
710

811
class ShowBoundaryValue:
@@ -18,14 +21,14 @@ class ShowBoundaryValue:
1821
def __bool__(self) -> bool: ...
1922

2023
class Canvas(_PDFColorSetter):
21-
bottomup: int
24+
bottomup: bool | Literal[0, 1]
2225
imageCaching: Incomplete
23-
state_stack: Incomplete
26+
state_stack: list[Incomplete]
2427
def __init__(
2528
self,
2629
filename: str | IO[bytes],
2730
pagesize: tuple[float, float] | None = None,
28-
bottomup: int = 1,
31+
bottomup: bool | Literal[0, 1] = 1,
2932
pageCompression=None,
3033
invariant=None,
3134
verbosity: int = 0,
@@ -46,8 +49,8 @@ class Canvas(_PDFColorSetter):
4649
def init_graphics_state(self) -> None: ...
4750
def push_state_stack(self) -> None: ...
4851
def pop_state_stack(self) -> None: ...
49-
STATE_ATTRIBUTES: Incomplete
50-
STATE_RANGE: Incomplete
52+
STATE_ATTRIBUTES: list[str]
53+
STATE_RANGE: list[int]
5154
def setAuthor(self, author: str | None) -> None: ...
5255
def setDateFormatter(self, dateFormatter) -> None: ...
5356
def addOutlineEntry(self, title, key, level: int = 0, closed=None) -> None: ...
@@ -57,17 +60,17 @@ class Canvas(_PDFColorSetter):
5760
def setCreator(self, creator: str | None) -> None: ...
5861
def setProducer(self, producer: str | None) -> None: ...
5962
def setKeywords(self, keywords: str | None) -> None: ...
60-
def pageHasData(self): ...
63+
def pageHasData(self) -> bool: ...
6164
def showOutline(self) -> None: ...
6265
def showFullScreen0(self) -> None: ...
6366
def setBlendMode(self, v) -> None: ...
6467
def showPage(self) -> None: ...
6568
def setPageCallBack(self, func) -> None: ...
66-
def bookmarkPage(self, key, fit: str = "Fit", left=None, top=None, bottom=None, right=None, zoom=None): ...
67-
def bookmarkHorizontalAbsolute(self, key, top, left: int = 0, fit: str = "XYZ", **kw): ...
69+
def bookmarkPage(self, key, fit: str = "Fit", left=None, top=None, bottom=None, right=None, zoom=None) -> Destination: ...
70+
def bookmarkHorizontalAbsolute(self, key, top, left: int = 0, fit: str = "XYZ", **kw) -> Destination: ...
6871
def bookmarkHorizontal(self, key, relativeX, relativeY, **kw) -> None: ...
6972
def doForm(self, name) -> None: ...
70-
def hasForm(self, name): ...
73+
def hasForm(self, name: str) -> bool: ...
7174
def drawInlineImage(
7275
self,
7376
image,
@@ -80,7 +83,7 @@ class Canvas(_PDFColorSetter):
8083
anchorAtXY: bool = False,
8184
showBoundary: bool = False,
8285
extraReturn=None,
83-
): ...
86+
) -> tuple[Incomplete, Incomplete]: ...
8487
def drawImage(
8588
self,
8689
image,
@@ -94,50 +97,69 @@ class Canvas(_PDFColorSetter):
9497
anchorAtXY: bool = False,
9598
showBoundary: bool = False,
9699
extraReturn=None,
97-
): ...
100+
) -> tuple[Incomplete, Incomplete]: ...
98101
def beginForm(self, name, lowerx: int = 0, lowery: int = 0, upperx=None, uppery=None) -> None: ...
99102
def endForm(self, **extra_attributes) -> None: ...
100103
def addPostScriptCommand(self, command, position: int = 1) -> None: ...
101-
def freeTextAnnotation(self, contents, DA, Rect=None, addtopage: int = 1, name=None, relative: int = 0, **kw) -> None: ...
102-
def textAnnotation(self, contents, Rect=None, addtopage: int = 1, name=None, relative: int = 0, **kw) -> None: ...
104+
def freeTextAnnotation(
105+
self, contents, DA, Rect=None, addtopage: bool | Literal[0, 1] = 1, name=None, relative: bool | Literal[0, 1] = 0, **kw
106+
) -> None: ...
107+
def textAnnotation(
108+
self, contents, Rect=None, addtopage: bool | Literal[0, 1] = 1, name=None, relative: bool | Literal[0, 1] = 0, **kw
109+
) -> None: ...
103110
textAnnotation0 = textAnnotation
104111
def highlightAnnotation(
105-
self, contents, Rect, QuadPoints=None, Color=[0.83, 0.89, 0.95], addtopage: int = 1, name=None, relative: int = 0, **kw
112+
self,
113+
contents,
114+
Rect,
115+
QuadPoints=None,
116+
Color=[0.83, 0.89, 0.95],
117+
addtopage: bool | Literal[0, 1] = 1,
118+
name=None,
119+
relative: bool | Literal[0, 1] = 0,
120+
**kw,
106121
) -> None: ...
107122
def inkAnnotation(
108-
self, contents, InkList=None, Rect=None, addtopage: int = 1, name=None, relative: int = 0, **kw
123+
self,
124+
contents,
125+
InkList=None,
126+
Rect=None,
127+
addtopage: bool | Literal[0, 1] = 1,
128+
name=None,
129+
relative: bool | Literal[0, 1] = 0,
130+
**kw,
109131
) -> None: ...
110132
inkAnnotation0 = inkAnnotation
111133
def linkAbsolute(
112134
self,
113135
contents,
114136
destinationname,
115137
Rect=None,
116-
addtopage: int = 1,
138+
addtopage: bool | Literal[0, 1] = 1,
117139
name=None,
118140
thickness: int = 0,
119141
color: Color | None = None,
120142
dashArray=None,
121143
**kw,
122-
): ...
144+
) -> None: ...
123145
def linkRect(
124146
self,
125147
contents,
126148
destinationname,
127149
Rect=None,
128-
addtopage: int = 1,
150+
addtopage: bool | Literal[0, 1] = 1,
129151
name=None,
130-
relative: int = 1,
152+
relative: bool | Literal[0, 1] = 1,
131153
thickness: int = 0,
132154
color: Color | None = None,
133155
dashArray=None,
134156
**kw,
135-
): ...
157+
) -> None: ...
136158
def linkURL(
137159
self,
138160
url,
139161
rect,
140-
relative: int = 0,
162+
relative: bool | Literal[0, 1] = 0,
141163
thickness: int = 0,
142164
color: Color | None = None,
143165
dashArray=None,
@@ -154,7 +176,7 @@ class Canvas(_PDFColorSetter):
154176
def setBleedBox(self, size) -> None: ...
155177
# NOTE: Only accepts right angles
156178
def setPageRotation(self, rot: float) -> None: ...
157-
def addLiteral(self, s: object, escaped: int = 1) -> None: ...
179+
def addLiteral(self, s: object, escaped: Literal[0, 1] = 1) -> None: ...
158180
def resetTransforms(self) -> None: ...
159181
def transform(self, a: float, b: float, c: float, d: float, e: float, f: float) -> None: ...
160182
def absolutePosition(self, x: float, y: float) -> tuple[float, float]: ...
@@ -237,8 +259,8 @@ class Canvas(_PDFColorSetter):
237259
wordSpace: float | None = None,
238260
shaping: bool = False,
239261
) -> None: ...
240-
def getAvailableFonts(self): ...
241-
def listLoadedFonts0(self): ...
262+
def getAvailableFonts(self) -> list[Incomplete]: ...
263+
def listLoadedFonts0(self) -> list[Incomplete]: ...
242264
def setFont(self, psfontname: str, size: float, leading: float | None = None) -> None: ...
243265
def setFontSize(self, size: float | None = None, leading: float | None = None) -> None: ...
244266
def stringWidth(self, text: str, fontName: str | None = None, fontSize: float | None = None) -> float: ...
@@ -247,26 +269,26 @@ class Canvas(_PDFColorSetter):
247269
def setLineJoin(self, mode) -> None: ...
248270
def setMiterLimit(self, limit) -> None: ...
249271
def setDash(self, array: list[float] | tuple[float, ...] | float = [], phase: float = 0) -> None: ...
250-
def beginPath(self): ...
272+
def beginPath(self) -> PDFPathObject: ...
251273
def drawPath(self, aPath, stroke: int = 1, fill: int = 0, fillMode=None) -> None: ...
252274
def clipPath(self, aPath, stroke: int = 1, fill: int = 0, fillMode=None) -> None: ...
253275
def beginText(self, x: float = 0, y: float = 0, direction: Literal["LTR", "RTL"] | None = None) -> PDFTextObject: ...
254276
def drawText(self, aTextObject: PDFTextObject) -> None: ...
255-
def setPageCompression(self, pageCompression: int = 1) -> None: ...
277+
def setPageCompression(self, pageCompression: bool | Literal[0, 1] | None = 1) -> None: ...
256278
def setPageDuration(self, duration=None) -> None: ...
257279
def setPageTransition(
258280
self, effectname: str | None = None, duration: float = 1, direction: float = 0, dimension: str = "H", motion: str = "I"
259281
) -> None: ...
260-
def getCurrentPageContent(self): ...
282+
def getCurrentPageContent(self) -> str: ...
261283
def setViewerPreference(self, pref, value) -> None: ...
262284
def getViewerPreference(self, pref): ...
263285
def delViewerPreference(self, pref) -> None: ...
264-
def setCatalogEntry(self, key, value) -> None: ...
265-
def getCatalogEntry(self, key): ...
266-
def delCatalogEntry(self, key) -> None: ...
286+
def setCatalogEntry(self, key: str, value) -> None: ...
287+
def getCatalogEntry(self, key: str): ...
288+
def delCatalogEntry(self, key: str) -> None: ...
267289
def addPageLabel(self, pageNum, style=None, start=None, prefix=None) -> None: ...
268290
@property
269-
def acroForm(self): ...
291+
def acroForm(self) -> AcroForm: ...
270292
def drawBoundary(self, sb, x1: float, y1: float, width: float, height: float) -> None: ...
271293
# Following callbacks are accepted: canvas, kind and label
272294
def setNamedCB(self, name: str, cb: Callable[[Canvas, str | None, str], None]) -> None: ...

stubs/reportlab/reportlab/pdfgen/pathobject.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ __version__: Final[str]
44

55
class PDFPathObject:
66
def __init__(self, code=None) -> None: ...
7-
def getCode(self): ...
7+
def getCode(self) -> str: ...
88
def moveTo(self, x, y) -> None: ...
99
def lineTo(self, x, y) -> None: ...
1010
def curveTo(self, x1, y1, x2, y2, x3, y3) -> None: ...
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from _typeshed import Incomplete
12
from typing import Final
23

34
__version__: Final[str]
45

5-
def bezierArc(x1, y1, x2, y2, startAng: int = 0, extent: int = 90): ...
6+
def bezierArc(
7+
x1, y1, x2, y2, startAng: int = 0, extent: int = 90
8+
) -> list[tuple[Incomplete, Incomplete, Incomplete, Incomplete, Incomplete, Incomplete, Incomplete, Incomplete]]: ...
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _typeshed import Incomplete
2-
from typing import Final
2+
from typing import Final, Literal
33

44
__version__: Final[str]
55

@@ -10,16 +10,16 @@ class PDFImage:
1010
width: Incomplete
1111
height: Incomplete
1212
filename: Incomplete
13-
imageCaching: Incomplete
13+
imageCaching: bool | Literal[0, 1]
1414
colorSpace: str
1515
bitsPerComponent: int
1616
filters: Incomplete
1717
source: Incomplete
18-
def __init__(self, image, x, y, width=None, height=None, caching: int = 0) -> None: ...
19-
def jpg_imagedata(self): ...
20-
def cache_imagedata(self): ...
21-
def PIL_imagedata(self): ...
22-
def non_jpg_imagedata(self, image): ...
18+
def __init__(self, image, x, y, width=None, height=None, caching: bool | Literal[0, 1] = 0) -> None: ...
19+
def jpg_imagedata(self) -> tuple[list[str], Incomplete, Incomplete]: ...
20+
def cache_imagedata(self) -> list[str]: ...
21+
def PIL_imagedata(self) -> tuple[list[str], Incomplete, Incomplete]: ...
22+
def non_jpg_imagedata(self, image) -> tuple[list[str], int, int]: ...
2323
imageData: Incomplete
2424
imgwidth: Incomplete
2525
imgheight: Incomplete
@@ -32,5 +32,5 @@ class PDFImage:
3232
anchorAtXY: bool = False,
3333
showBoundary: bool = False,
3434
extraReturn=None,
35-
): ...
36-
def format(self, document): ...
35+
) -> bool: ...
36+
def format(self, document) -> bytes: ...

stubs/reportlab/reportlab/pdfgen/textobject.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ class PDFTextObject(_PDFColorSetter):
6868
def setRise(self, rise: float) -> None: ...
6969
def textOut(self, text: str) -> None: ...
7070
def textLine(self, text: str = "") -> None: ...
71-
def textLines(self, stuff: list[str] | tuple[str, ...] | str, trim: int = 1) -> None: ...
71+
def textLines(self, stuff: list[str] | tuple[str, ...] | str, trim: Literal[0, 1] = 1) -> None: ...
7272
def __nonzero__(self) -> bool: ...

0 commit comments

Comments
 (0)