-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Expand file tree
/
Copy pathbackend_pdf.pyi
More file actions
420 lines (402 loc) · 12.7 KB
/
Copy pathbackend_pdf.pyi
File metadata and controls
420 lines (402 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import os
import types
from collections.abc import Callable, Iterable, Sequence
from datetime import datetime
from enum import Enum
from functools import total_ordering
from typing import IO, Any, Literal, Protocol, Self
import numpy as np
from _typeshed import ReadableBuffer, SupportsWrite
from numpy import typing as npt
from matplotlib import _api, path, transforms
from matplotlib._type1font import Type1Font
from matplotlib.backend_bases import FigureCanvasBase, GraphicsContextBase
from matplotlib.dviread import DviFont
from matplotlib.figure import Figure
from matplotlib.font_manager import FontPath, FontProperties
from matplotlib.text import Text
from matplotlib.transforms import BboxBase, Transform, TransformedBbox, TransformedPath
from matplotlib.typing import (
CapStyleType,
ColorType,
JoinStyleType,
LineStyleType,
RGBColorType,
)
from . import _backend_pdf_ps
# XXX: Some of these might be worth moving to `mpl.typing`
type _CommandType = list[_SupportsPdfReprExt]
type _CommandFuncType = Callable[..., _CommandType]
type _RectangleType = tuple[float, float, float, float] | list[float]
# struct definition SketchParams in _backend_agg_basic_types.h
type _SketchParamsType = tuple[float, float, float]
type _HatchType = str
type _HatchStyleType = tuple[
ColorType | None, ColorType | None, _HatchType | None, float
]
class _SupportsPdfRepr(Protocol):
def pdfRepr(self) -> bytes: ...
type _SupportsPdfReprExt = (
_SupportsPdfRepr
| float
| np.floating
| bool
| int
| np.integer
| str
| bytes
| dict[Name | bytes, _SupportsPdfReprExt]
| list[_SupportsPdfReprExt]
| tuple[_SupportsPdfReprExt, ...]
| None
| datetime
| BboxBase
)
type _MetadataDict = dict[str, str | datetime | Name]
def pdfRepr(obj: _SupportsPdfReprExt) -> bytes: ...
class Reference:
def __init__(self, id: int) -> None: ...
def __repr__(self) -> str: ...
def pdfRepr(self) -> bytes: ...
def write(
self, contents: _SupportsPdfReprExt, file: SupportsWrite[bytes]
) -> None: ...
@total_ordering
class Name:
def __init__(self, name: Self | bytes | str) -> None: ...
def __repr__(self) -> str: ...
def __str__(self) -> str: ...
def __eq__(self, other: Any) -> bool: ...
def __lt__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...
def pdfRepr(self) -> bytes: ...
class Verbatim:
def __init__(self, x: bytes) -> None: ...
def pdfRepr(self) -> bytes: ...
class Op(Enum):
close_fill_stroke = b"b"
fill_stroke = b"B"
fill = b"f"
closepath = b"h"
close_stroke = b"s"
stroke = b"S"
endpath = b"n"
begin_text = b"BT"
end_text = b"ET"
curveto = b"c"
rectangle = b"re"
lineto = b"l"
moveto = b"m"
concat_matrix = b"cm"
use_xobject = b"Do"
setgray_stroke = b"G"
setgray_nonstroke = b"g"
setrgb_stroke = b"RG"
setrgb_nonstroke = b"rg"
setcolorspace_stroke = b"CS"
setcolorspace_nonstroke = b"cs"
setcolor_stroke = b"SCN"
setcolor_nonstroke = b"scn"
setdash = b"d"
setlinejoin = b"j"
setlinecap = b"J"
setgstate = b"gs"
gsave = b"q"
grestore = b"Q"
textpos = b"Td"
selectfont = b"Tf"
textmatrix = b"Tm"
textrise = b"Ts"
show = b"Tj"
showkern = b"TJ"
setlinewidth = b"w"
clip = b"W"
shading = b"sh"
def pdfRepr(self) -> bytes: ...
@classmethod
def paint_path(cls, fill: bool, stroke: bool) -> bytes: ...
class Stream:
def __init__(
self,
id: int,
len: Reference | None,
file: PdfFile,
extra: dict[Name, Any] | None = None,
png: dict[Any, Any] | None = None,
) -> None: ...
def end(self) -> None: ...
def write(self, data: bytes) -> None: ...
class PdfFile:
def __init__(
self,
filename: str | os.PathLike | IO[Any],
metadata: _MetadataDict | None = None,
) -> None: ...
@property
def dviFontInfo(self) -> dict[Name, types.SimpleNamespace]: ...
def newPage(self, width: float, height: float) -> None: ...
def newTextnote(
self,
text: _SupportsPdfReprExt,
positionRect: _RectangleType = [-100, -100, 0, 0],
) -> None: ...
def finalize(self) -> None: ...
def close(self) -> None: ...
def write(self, data: ReadableBuffer) -> None: ...
def output(self, *data: _SupportsPdfReprExt) -> None: ...
def beginStream(
self,
id: int,
len: Reference | None,
extra: dict[Name, Any] | None = None,
png: dict[Any, Any] | None = None,
) -> None: ...
def endStream(self) -> None: ...
def outputStream(
self, ref: Reference, data: bytes, *, extra: dict[Name, Any] | None = None
) -> None: ...
def fontName(self, fontprop: FontPath | str, subset: int = 0) -> Name | None: ...
def dviFontName(self, dvifont: DviFont) -> Name: ...
def writeFonts(self) -> None: ...
@_api.delete_parameter("3.11", "fontfile")
def createType1Descriptor(
self, t1font: Type1Font, fontfile: Any = None
) -> Reference: ...
def embedTTF(
self,
filename: Iterable[str | bytes | os.PathLike | FontPath]
| str
| bytes
| os.PathLike
| FontPath,
subset_index: int,
charmap: dict[int, int],
) -> Reference: ...
def alphaState(self, alpha: tuple[float, float]) -> Name: ...
def writeExtGSTates(self) -> None: ...
def hatchPattern(self, hatch_style: _HatchStyleType) -> Name: ...
def writeHatches(self) -> None: ...
def addGouraudTriangles(
self, points: npt.ArrayLike, colors: npt.ArrayLike
) -> tuple[Name, Reference]: ...
def writeGouraudTriangles(self) -> None: ...
def imageObject(self, image: npt.NDArray[np.uint8]) -> Name: ...
def writeImages(self) -> None: ...
def markerObject(
self,
path: path.Path,
trans: Transform,
fill: bool,
stroke: bool,
lw: float,
joinstyle: JoinStyleType,
capstyle: CapStyleType,
) -> Name: ...
def writeMarkers(self) -> None: ...
def pathCollectionObject(
self,
gc: GraphicsContextBase,
path: path.Path,
trans: Transform,
padding: float,
filled: bool,
stroked: bool,
) -> Name: ...
def writePathCollectionTemplates(self) -> None: ...
# types in _path.h::convert_to_string
@staticmethod
def pathOperations(
path: path.Path,
transform: Transform,
clip: _RectangleType | None = None,
simplify: bool | None = None,
sketch: _SketchParamsType | None = None,
) -> list[Verbatim]: ...
def writePath(
self,
path: path.Path,
transform: Transform,
clip: bool = False,
sketch: _SketchParamsType | None = None,
) -> None: ...
def reserveObject(self, name: str = "") -> Reference: ...
def recordXref(self, id: int) -> None: ...
def writeObject(
self, object: _SupportsPdfReprExt, contents: dict[str, _SupportsPdfReprExt]
) -> None: ...
def writeXref(self) -> None: ...
def writeInfoDict(self) -> None: ...
def writeTrailer(self) -> None: ...
class RendererPdf(_backend_pdf_ps.RendererPDFPSBase):
paths: tuple[
Name,
path.Path,
Transform,
Reference,
JoinStyleType,
CapStyleType,
float,
bool,
bool,
]
def __init__(
self, file: PdfFile, image_dpi: float, height: float, width: float
): ...
def finalize(self) -> None: ...
def check_gc(
self, gc: GraphicsContextBase, fillcolor: ColorType | None = None
) -> None: ...
def get_image_magnification(self) -> float: ...
def draw_image(
self,
gc: GraphicsContextBase,
x: float,
y: float,
im: npt.ArrayLike,
transform: transforms.Affine2DBase | None = None,
) -> None: ...
def draw_path(
self,
gc: GraphicsContextBase,
path: path.Path,
transform: Transform,
rgbFace: ColorType | None = None,
) -> None: ...
def draw_path_collection(
self,
gc: GraphicsContextBase,
master_transform: Transform,
paths: Sequence[path.Path],
all_transforms: Sequence[npt.ArrayLike],
offsets: npt.ArrayLike | Sequence[npt.ArrayLike],
offset_trans: Transform,
facecolors: ColorType | Sequence[ColorType],
edgecolors: ColorType | Sequence[ColorType],
linewidths: float | Sequence[float],
linestyles: LineStyleType | Sequence[LineStyleType],
antialiaseds: bool | Sequence[bool],
urls: str | Sequence[str],
offset_position: Any,
*,
hatchcolors: ColorType | Sequence[ColorType] | None = None,
) -> None: ...
# XXX: Here the implementation relies on `fill` and `stroke` which are not
# in the interface of `GraphicsContextBase`. Here we use
# `GraphicsContextPdf` to annotate `gc`, as a result, `RendererPdf` does not
# strictly inherit from `RenderedBase` correctly.
def draw_markers(
self,
gc: GraphicsContextPdf, # type: ignore[override]
marker_path: path.Path,
marker_trans: Transform,
path: path.Path,
trans: Transform,
rgbFace: ColorType | None = None,
) -> None: ...
def draw_gouraud_triangles(
self,
gc: GraphicsContextBase,
points: npt.ArrayLike,
colors: npt.ArrayLike,
trans: Transform,
) -> None: ...
def draw_mathtext(
self,
gc: GraphicsContextBase,
x: float,
y: float,
s: str,
prop: FontProperties,
angle: float,
) -> None: ...
def draw_tex(
self,
gc: GraphicsContextBase,
x: float,
y: float,
s: str,
prop: FontProperties,
angle: float,
*,
mtext: Text | None = None,
) -> None: ...
def encode_string(self, s: str, fonttype: int) -> bytes: ...
def draw_text(
self,
gc: GraphicsContextBase,
x: float,
y: float,
s: str,
prop: FontProperties,
angle: float,
ismath: bool | Literal["TeX"] = False,
mtext: Text | None = None,
) -> None: ...
def new_gc(self) -> GraphicsContextPdf: ...
class GraphicsContextPdf(GraphicsContextBase):
file: PdfFile
capstyles: dict[CapStyleType, int]
joinstyles: dict[JoinStyleType, int]
commands: tuple[tuple[str, ...], _CommandFuncType]
def __init__(self, file: PdfFile): ...
def __repr__(self) -> str: ...
def stroke(self) -> bool: ...
def fill(self, *args: ColorType) -> bool: ...
def paint(self) -> Op: ...
def capstyle_cmd(self, style: CapStyleType) -> _CommandType: ...
def joinstyle_cmd(self, style: JoinStyleType) -> _CommandType: ...
def linewidth_cmd(self, width: float) -> _CommandType: ...
def dash_cmd(self, dashes: tuple[float, Sequence[float]]) -> _CommandType: ...
def alpha_cmd(
self,
alpha: tuple[float, float],
forced: bool,
effective_alphas: tuple[float, float],
) -> _CommandType: ...
def hatch_cmd(
self, hatch: _HatchType, hatch_color: ColorType, hatch_linewidth: float
) -> _CommandType: ...
def rgb_cmd(self, rgb: RGBColorType) -> _CommandType: ...
def fillcolor_cmd(self, rgb: RGBColorType) -> _CommandType: ...
def push(self) -> list[Op]: ...
def pop(self) -> list[Op]: ...
def clip_cmd(
self, cliprect: TransformedBbox, clippath: TransformedPath
) -> _CommandType: ...
def delta(self, other: GraphicsContextBase) -> _CommandType: ...
def copy_properties(self, other: GraphicsContextBase) -> None: ...
def finalize(self) -> list[Op]: ...
class PdfPages:
def __init__(
self,
filename: str | os.PathLike | IO[Any],
keep_empty: None = None,
metadata: _MetadataDict | None = None,
) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: object, exc_tb: object
) -> None: ...
def close(self) -> None: ...
def infodict(self) -> _MetadataDict: ...
def savefig(
self, figure: Figure | int | None = None, **kwargs: dict[str, Any]
) -> None: ...
def get_pagecount(self) -> int: ...
def attach_note(
self,
text: _SupportsPdfReprExt,
positionRect: _RectangleType = [-100, -100, 0, 0],
) -> None: ...
class FigureCanvasPdf(FigureCanvasBase):
filetypes: dict[str, str]
@classmethod
def get_default_filetype(cls) -> str: ...
def print_pdf(
self,
filename: PdfPages | str | os.PathLike | IO[Any],
*,
bbox_inches_restore: _RectangleType | None = None,
metadata: _MetadataDict | None = None,
) -> None: ...
def draw(self) -> None: ...