Debian Codegraph @

cairo/__init__.pyi

raw symbols SCIP
1 from __future__ import annotations
2
3 from typing import (Any, BinaryIO, ByteString, Callable, Generic, List, Optional,
4 Sequence, Text, Tuple, TypeVar, Union)
5
6 del annotations
7
8 HAS_ATSUI_FONT: bool = ...
9 HAS_FT_FONT: bool = ...
10 HAS_GLITZ_SURFACE: bool = ...
11 HAS_IMAGE_SURFACE: bool = ...
12 HAS_MIME_SURFACE: bool = ...
13 """
14 .. versionadded:: 1.12.0
15 """
16 HAS_PDF_SURFACE: bool = ...
17 HAS_PNG_FUNCTIONS: bool = ...
18 HAS_PS_SURFACE: bool = ...
19 HAS_QUARTZ_SURFACE: bool = ...
20 HAS_RECORDING_SURFACE: bool = ...
21 HAS_SCRIPT_SURFACE: bool = ...
22 """
23 .. versionadded:: 1.12.0
24 """
25 HAS_SVG_SURFACE: bool = ...
26 HAS_TEE_SURFACE: bool = ...
27 """
28 .. versionadded:: 1.15.3
29 """
30 HAS_USER_FONT: bool = ...
31 HAS_WIN32_FONT: bool = ...
32 HAS_WIN32_SURFACE: bool = ...
33 HAS_XCB_SURFACE: bool = ...
34 HAS_XLIB_SURFACE: bool = ...
35 HAS_DWRITE_FONT: bool = ...
36 """
37 .. versionadded:: 1.23.0
38 """
39
40 PDF_OUTLINE_ROOT: int = ...
41 """
42 The root outline item in :meth:`PDFSurface.add_outline`
43
44 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
45 """
46
47 COLOR_PALETTE_DEFAULT: int = ...
48 """
49 The default color palette index. See :meth:`FontOptions.set_color_palette`
50
51 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
52 """
53
54 version: str = ...
55 """the pycairo version, as a string"""
56
57 version_info: Tuple[int, int, int] = ...
58 """the pycairo version, as a tuple"""
59
60 CAIRO_VERSION: int = ...
61 """
62 The version of cairo available at compile-time in the same format as
63 returned by :func:`cairo_version`
64
65 .. versionadded:: 1.18.0
66 """
67
68 CAIRO_VERSION_STRING: str = ...
69 """
70 A human-readable string literal containing the version of cairo available
71 at compile-time, in the form of "X.Y.Z".
72
73 .. versionadded:: 1.18.0
74 """
75
76 CAIRO_VERSION_MAJOR: int = ...
77 """
78 The major component of the version of cairo available at compile-time.
79
80 .. versionadded:: 1.18.0
81 """
82
83 CAIRO_VERSION_MINOR: int = ...
84 """
85 The minor component of the version of cairo available at compile-time.
86
87 .. versionadded:: 1.18.0
88 """
89
90 CAIRO_VERSION_MICRO: int = ...
91 """
92 The micro component of the version of cairo available at compile-time.
93
94 .. versionadded:: 1.18.0
95 """
96
97 def cairo_version() -> int:
98 """
99 :returns: the encoded version
100
101 Returns the version of the underlying C cairo library, encoded in a single
102 integer.
103 """
104
105 def cairo_version_string() -> str:
106 """
107 :returns: the encoded version
108
109 Returns the version of the underlying C cairo library as a human-readable
110 string of the form "X.Y.Z".
111 """
112
113 class Path:
114 """
115 *Path* cannot be instantiated directly, it is created by calling
116 :meth:`Context.copy_path` and :meth:`Context.copy_path_flat`.
117
118 str(path) lists the path elements.
119
120 See :class:`path attributes <cairo.PathDataType>`
121
122 Path is an iterator.
123
124 See examples/warpedtext.py for example usage.
125 """
126
127 class Rectangle(Tuple[float, float, float, float]):
128 """
129 .. versionadded:: 1.15
130 In prior versions a (float, float, float, float) tuple was
131 used instead of :class:`Rectangle`.
132
133 A data structure for holding a rectangle.
134 """
135
136 x: float = ...
137 y: float = ...
138 width: float = ...
139 height: float = ...
140
141 def __init__(self, x: float, y: float, width: float, height: float) -> None:
142 """
143 :param x:
144 X coordinate of the left side of the rectangle
145 :param y:
146 Y coordinate of the the top side of the rectangle
147 :param width:
148 width of the rectangle
149 :param height:
150 height of the rectangle
151 """
152
153 class _IntEnum(int):
154 def __init__(self, value: int) -> None: ...
155
156 class Antialias(_IntEnum):
157 """
158 Specifies the type of antialiasing to do when rendering text or shapes.
159
160 .. versionadded:: 1.13
161 """
162
163 BEST: "Antialias" = ...
164 """
165 Hint that the backend should render at the highest quality, sacrificing
166 speed if necessary.
167 """
168
169 DEFAULT: "Antialias" = ...
170 """Use the default antialiasing for the subsystem and target device"""
171
172 FAST: "Antialias" = ...
173 """
174 Hint that the backend should perform some antialiasing but prefer
175 speed over quality.
176 """
177
178 GOOD: "Antialias" = ...
179 """The backend should balance quality against performance."""
180
181 GRAY: "Antialias" = ...
182 """
183 Perform single-color antialiasing (using shades of gray for black text
184 on a white background, for example).
185 """
186
187 NONE: "Antialias" = ...
188 """Use a bilevel alpha mask"""
189
190 SUBPIXEL: "Antialias" = ...
191 """
192 Perform antialiasing by taking advantage of the order of subpixel
193 elements on devices such as LCD panels.
194 """
195
196 class Content(_IntEnum):
197 """
198 These constants are used to describe the content that a :class:`Surface`
199 will contain, whether color information, alpha information (translucence
200 vs. opacity), or both.
201
202 .. versionadded:: 1.13
203 """
204
205 ALPHA: "Content" = ...
206 """The surface will hold alpha content only."""
207
208 COLOR: "Content" = ...
209 """The surface will hold color content only."""
210
211 COLOR_ALPHA: "Content" = ...
212 """The surface will hold color and alpha content."""
213
214 class FillRule(_IntEnum):
215 """
216 These constants are used to select how paths are filled. For both fill
217 rules, whether or not a point is included in the fill is determined by
218 taking a ray from that point to infinity and looking at intersections with
219 the path. The ray can be in any direction, as long as it doesn't pass
220 through the end point of a segment or have a tricky intersection such as
221 intersecting tangent to the path. (Note that filling is not actually
222 implemented in this way. This is just a description of the rule that is
223 applied.)
224
225 The default fill rule is :attr:`WINDING`.
226
227 .. versionadded:: 1.13
228 """
229
230 EVEN_ODD: "FillRule" = ...
231 """
232 Counts the total number of intersections, without regard to the
233 orientation of the contour. If the total number of intersections is
234 odd, the point will be filled.
235 """
236
237 WINDING: "FillRule" = ...
238 """
239 If the path crosses the ray from left-to-right, counts +1. If the path
240 crosses the ray from right to left, counts -1. (Left and right are
241 determined from the perspective of looking along the ray from the
242 starting point.) If the total count is non-zero, the point will be
243 filled.
244 """
245
246 class Format(_IntEnum):
247 """
248 These constants are used to identify the memory format of
249 :class:`ImageSurface` data.
250
251 New entries may be added in future versions.
252
253 .. versionadded:: 1.13
254 """
255
256 def stride_for_width(self, width: int) -> int:
257 """
258 :param width: the desired width of an :class:`ImageSurface`
259 to be created.
260 :returns: the appropriate stride to use given the desired format and
261 width, or -1 if either the format is invalid or the width too
262 large.
263
264 This method provides a stride value that will respect all alignment
265 requirements of the accelerated image-rendering code within cairo.
266 Typical usage will be of the form::
267
268 format = cairo.Format.RGB24
269 stride = format.stride_for_width(width)
270 surface = cairo.ImageSurface.create_for_data(
271 data, format, width, height, stride)
272
273 Also available under
274 :meth:`cairo.ImageSurface.format_stride_for_width`.
275
276 .. versionadded:: 1.14
277 """
278
279 A1: "Format" = ...
280 """
281 each pixel is a 1-bit quantity holding an alpha value. Pixels are
282 packed together into 32-bit quantities. The ordering of the bits
283 matches the endianess of the platform. On a big-endian machine, the
284 first pixel is in the uppermost bit, on a little-endian machine the
285 first pixel is in the least-significant bit.
286 """
287
288 A8: "Format" = ...
289 """
290 each pixel is a 8-bit quantity holding an alpha value.
291 """
292
293 ARGB32: "Format" = ...
294 """
295 each pixel is a 32-bit quantity, with alpha in the upper 8 bits, then
296 red, then green, then blue. The 32-bit quantities are stored
297 native-endian. Pre-multiplied alpha is used. (That is, 50% transparent
298 red is 0x80800000, not 0x80ff0000.)
299 """
300
301 INVALID: "Format" = ...
302 """no such format exists or is supported."""
303
304 RGB16_565: "Format" = ...
305 """
306 each pixel is a 16-bit quantity with red in the upper 5 bits, then
307 green in the middle 6 bits, and blue in the lower 5 bits.
308 """
309
310 RGB24: "Format" = ...
311 """
312 each pixel is a 32-bit quantity, with the upper 8 bits unused. [#]_ Red,
313 Green, and Blue are stored in the remaining 24 bits in that order.
314
315 .. [#] Cairo operators (for example CLEAR and SRC) may overwrite unused bytes as an implementation side-effect, their values should be considered undefined.
316 """
317
318 RGB30: "Format" = ...
319 """
320 like :data:`RGB24` but with 10bpc.
321 """
322
323 RGB96F: "Format" = ...
324 """
325 3 floats, R, G, B.
326
327 .. versionadded:: 1.23 Only available with cairo 1.17.2+
328 """
329
330 RGBA128F: "Format" = ...
331 """
332 4 floats, R, G, B, A.
333
334 .. versionadded:: 1.23 Only available with cairo 1.17.2+
335 """
336
337 class HintMetrics(_IntEnum):
338 """
339 These constants specify whether to hint font metrics; hinting font metrics
340 means quantizing them so that they are integer values in device space.
341 Doing this improves the consistency of letter and line spacing, however it
342 also means that text will be laid out differently at different zoom
343 factors.
344
345 .. versionadded:: 1.13
346 """
347
348 DEFAULT: "HintMetrics" = ...
349 """
350 Hint metrics in the default manner for the font backend and target
351 device
352 """
353
354 OFF: "HintMetrics" = ...
355 """"Do not hint font metrics"""
356
357 ON: "HintMetrics" = ...
358 """Hint font metrics"""
359
360 class ColorMode(_IntEnum):
361 """
362 Specifies if color fonts are to be rendered using the color glyphs or
363 outline glyphs. Glyphs that do not have a color presentation, and non-color
364 fonts are not affected by this font option.
365
366 .. versionadded:: 1.25 Only available with cairo 1.17.8+
367 """
368
369 DEFAULT: "ColorMode" = ...
370 """
371 Use the default color mode for font backend and target device.
372 """
373
374 NO_COLOR: "ColorMode" = ...
375 """
376 Disable rendering color glyphs. Glyphs are always rendered as outline glyphs
377 """
378
379 COLOR: "ColorMode" = ...
380 """
381 Enable rendering color glyphs. If the font contains a color presentation for
382 a glyph, and when supported by the font backend, the glyph will be rendered
383 in color.
384 """
385
386 class Dither(_IntEnum):
387 """
388 Dither is an intentionally applied form of noise used to randomize
389 quantization error, preventing large-scale patterns such as color banding in
390 images (e.g. for gradients). Ordered dithering applies a precomputed
391 threshold matrix to spread the errors smoothly.
392
393 :class:`Dither` is modeled on pixman dithering algorithm choice. As of
394 Pixman 0.40, FAST corresponds to a 8x8 ordered bayer noise and GOOD and BEST
395 use an ordered 64x64 precomputed blue noise.
396
397 .. versionadded:: 1.25 Only available with cairo 1.18.0+
398 """
399
400 NONE: "Dither" = ...
401 """
402 No dithering.
403 """
404
405 DEFAULT: "Dither" = ...
406 """
407 Default choice at cairo compile time. Currently NONE.
408 """
409
410 FAST: "Dither" = ...
411 """
412 Fastest dithering algorithm supported by the backend
413 """
414
415 GOOD: "Dither" = ...
416 """
417 An algorithm with smoother dithering than FAST
418 """
419
420 BEST: "Dither" = ...
421 """
422 Best algorithm available in the backend
423 """
424
425 class HintStyle(_IntEnum):
426 """
427 These constants specify the type of hinting to do on font outlines.
428 Hinting is the process of fitting outlines to the pixel grid in order to
429 improve the appearance of the result. Since hinting outlines involves
430 distorting them, it also reduces the faithfulness to the original outline
431 shapes. Not all of the outline hinting styles are supported by all font
432 backends.
433
434 New entries may be added in future versions.
435
436 .. versionadded:: 1.13
437 """
438
439 DEFAULT: "HintStyle" = ...
440 """
441 Use the default hint style for font backend and target device
442 """
443
444 FULL: "HintStyle" = ...
445 """
446 Hint outlines to maximize contrast
447 """
448
449 MEDIUM: "HintStyle" = ...
450 """
451 Hint outlines with medium strength giving a compromise between fidelity
452 to the original shapes and contrast
453 """
454
455 NONE: "HintStyle" = ...
456 """Do not hint outlines"""
457
458 SLIGHT: "HintStyle" = ...
459 """
460 Hint outlines slightly to improve contrast while retaining good
461 fidelity to the original shapes.
462 """
463
464 class SubpixelOrder(_IntEnum):
465 """
466 The subpixel order specifies the order of color elements within each pixel
467 on the display device when rendering with an antialiasing mode of
468 :attr:`Antialias.SUBPIXEL`.
469
470 .. versionadded:: 1.13
471 """
472
473 BGR: "SubpixelOrder" = ...
474 """Subpixel elements are arranged horizontally with blue at the left"""
475
476 DEFAULT: "SubpixelOrder" = ...
477 """Use the default subpixel order for for the target device"""
478
479 RGB: "SubpixelOrder" = ...
480 """Subpixel elements are arranged horizontally with red at the left"""
481
482 VBGR: "SubpixelOrder" = ...
483 """Subpixel elements are arranged vertically with blue at the top"""
484
485 VRGB: "SubpixelOrder" = ...
486 """Subpixel elements are arranged vertically with red at the top"""
487
488 class LineCap(_IntEnum):
489 """
490 These constants specify how to render the endpoints of the path when
491 stroking.
492
493 The default line cap style is :attr:`BUTT`
494
495 .. versionadded:: 1.13
496 """
497
498 BUTT: "LineCap" = ...
499 """start(stop) the line exactly at the start(end) point"""
500
501 ROUND: "LineCap" = ...
502 """use a round ending, the center of the circle is the end point"""
503
504 SQUARE: "LineCap" = ...
505 """use squared ending, the center of the square is the end point"""
506
507 class LineJoin(_IntEnum):
508 """
509 These constants specify how to render the junction of two lines when
510 stroking.
511
512 The default line join style is :attr:`MITER`
513
514 .. versionadded:: 1.13
515 """
516
517 BEVEL: "LineJoin" = ...
518 """
519 use a cut-off join, the join is cut off at half the line width from
520 the joint point
521 """
522
523 MITER: "LineJoin" = ...
524 """
525 use a sharp (angled) corner, see :meth:`Context.set_miter_limit`
526 """
527
528 ROUND: "LineJoin" = ...
529 """use a rounded join, the center of the circle is the joint point"""
530
531 class Filter(_IntEnum):
532 """
533 These constants are used to indicate what filtering should be applied when
534 reading pixel values from patterns. See :meth:`Pattern.set_filter` for
535 indicating the desired filter to be used with a particular pattern.
536
537 .. versionadded:: 1.13
538 """
539
540 BEST: "Filter" = ...
541 """
542 The highest-quality available, performance may not be suitable for
543 interactive use.
544 """
545
546 BILINEAR: "Filter" = ...
547 """Linear interpolation in two dimensions"""
548
549 FAST: "Filter" = ...
550 """A high-performance filter, with quality similar *FILTER_NEAREST*"""
551
552 GAUSSIAN: "Filter" = ...
553 """
554 This filter value is currently unimplemented, and should not be used
555 in current code.
556 """
557
558 GOOD: "Filter" = ...
559 """
560 A reasonable-performance filter, with quality similar to
561 *FILTER_BILINEAR*
562 """
563
564 NEAREST: "Filter" = ...
565 """Nearest-neighbor filtering"""
566
567 class Operator(_IntEnum):
568 """
569 These constants are used to set the compositing operator for all cairo
570 drawing operations.
571
572 The default operator is :attr:`OVER`.
573
574 The operators marked as *unbounded* modify their destination even outside
575 of the mask layer (that is, their effect is not bound by the mask layer).
576 However, their effect can still be limited by way of clipping.
577
578 To keep things simple, the operator descriptions here document the
579 behavior for when both source and destination are either fully transparent
580 or fully opaque. The actual implementation works for translucent layers
581 too.
582
583 For a more detailed explanation of the effects of each operator, including
584 the mathematical definitions, see https://cairographics.org/operators.
585
586 .. versionadded:: 1.13
587 """
588
589 ADD: "Operator" = ...
590 """source and destination layers are accumulated"""
591
592 ATOP: "Operator" = ...
593 """draw source on top of destination content and only there"""
594
595 CLEAR: "Operator" = ...
596 """clear destination layer (bounded)"""
597
598 COLOR_BURN: "Operator" = ...
599 """darkens the destination color to reflect the source color."""
600
601 COLOR_DODGE: "Operator" = ...
602 """brightens the destination color to reflect the source color."""
603
604 DARKEN: "Operator" = ...
605 """
606 replaces the destination with the source if it is darker, otherwise
607 keeps the source.
608 """
609
610 DEST: "Operator" = ...
611 """ignore the source"""
612
613 DEST_ATOP: "Operator" = ...
614 """leave destination on top of source content and only there (unbounded)"""
615
616 DEST_IN: "Operator" = ...
617 """leave destination only where there was source content (unbounded)"""
618
619 DEST_OUT: "Operator" = ...
620 """leave destination only where there was no source content"""
621
622 DEST_OVER: "Operator" = ...
623 """draw destination on top of source"""
624
625 DIFFERENCE: "Operator" = ...
626 """Takes the difference of the source and destination color."""
627
628 EXCLUSION: "Operator" = ...
629 """Produces an effect similar to difference, but with lower contrast."""
630
631 HARD_LIGHT: "Operator" = ...
632 """Multiplies or screens, dependent on source color."""
633
634 HSL_COLOR: "Operator" = ...
635 """
636 Creates a color with the hue and saturation of the source and the
637 luminosity of the target. This preserves the gray levels of the target
638 and is useful for coloring monochrome images or tinting color images.
639 """
640
641 HSL_HUE: "Operator" = ...
642 """
643 Creates a color with the hue of the source and the saturation and
644 luminosity of the target.
645 """
646
647 HSL_LUMINOSITY: "Operator" = ...
648 """
649 Creates a color with the luminosity of the source and the hue and
650 saturation of the target. This produces an inverse effect to
651 :attr:`HSL_COLOR`
652 """
653
654 HSL_SATURATION: "Operator" = ...
655 """
656 Creates a color with the saturation of the source and the hue and
657 luminosity of the target. Painting with this mode onto a gray area
658 produces no change.
659 """
660
661 IN: "Operator" = ...
662 """draw source where there was destination content (unbounded)"""
663
664 LIGHTEN: "Operator" = ...
665 """
666 replaces the destination with the source if it is lighter, otherwise
667 keeps the source.
668 """
669
670 MULTIPLY: "Operator" = ...
671 """
672 source and destination layers are multiplied. This causes the result
673 to be at least as dark as the darker inputs.
674 """
675
676 OUT: "Operator" = ...
677 """draw source where there was no destination content (unbounded)"""
678
679 OVER: "Operator" = ...
680 """draw source layer on top of destination layer (bounded)"""
681
682 OVERLAY: "Operator" = ...
683 """
684 multiplies or screens, depending on the lightness of the destination
685 color.
686 """
687
688 SATURATE: "Operator" = ...
689 """like over, but assuming source and dest are disjoint geometries"""
690
691 SCREEN: "Operator" = ...
692 """
693 source and destination are complemented and multiplied. This causes
694 the result to be at least as light as the lighter inputs.
695 """
696
697 SOFT_LIGHT: "Operator" = ...
698 """Darkens or lightens, dependent on source color."""
699
700 SOURCE: "Operator" = ...
701 """replace destination layer (bounded)"""
702
703 XOR: "Operator" = ...
704 """source and destination are shown where there is only one of them"""
705
706 class Extend(_IntEnum):
707 """
708 These constants are used to describe how :class:`Pattern` color/alpha will
709 be determined for areas "outside" the pattern's natural area, (for
710 example, outside the surface bounds or outside the gradient geometry).
711
712 The default extend mode is :attr:`NONE` for :class:`SurfacePattern` and
713 :attr:`PAD` for :class:`Gradient` patterns.
714
715 .. versionadded:: 1.13
716 """
717
718 NONE: "Extend" = ...
719 """pixels outside of the source pattern are fully transparent"""
720
721 PAD: "Extend" = ...
722 """
723 pixels outside of the pattern copy the closest pixel from the source
724 (Since 1.2; but only implemented for surface patterns since 1.6)
725 """
726
727 REFLECT: "Extend" = ...
728 """
729 the pattern is tiled by reflecting at the edges (Implemented for
730 surface patterns since 1.6)
731 """
732
733 REPEAT: "Extend" = ...
734 """the pattern is tiled by repeating"""
735
736 class FontSlant(_IntEnum):
737 """
738 These constants specify variants of a :class:`FontFace` based on their
739 slant.
740
741 .. versionadded:: 1.13
742 """
743
744 ITALIC: "FontSlant" = ...
745 """Italic font style"""
746
747 NORMAL: "FontSlant" = ...
748 """Upright font style"""
749
750 OBLIQUE: "FontSlant" = ...
751 """Oblique font style"""
752
753 class FontWeight(_IntEnum):
754 """
755 These constants specify variants of a :class:`FontFace` based on their
756 weight.
757
758 .. versionadded:: 1.13
759 """
760
761 BOLD: "FontWeight" = ...
762 """Bold font weight"""
763
764 NORMAL: "FontWeight" = ...
765 """Normal font weight"""
766
767 class Status(_IntEnum):
768 """
769 .. versionadded:: 1.13
770 """
771
772 CLIP_NOT_REPRESENTABLE: "Status" = ...
773 DEVICE_ERROR: "Status" = ...
774 DEVICE_FINISHED: "Status" = ...
775 DEVICE_TYPE_MISMATCH: "Status" = ...
776 FILE_NOT_FOUND: "Status" = ...
777 FONT_TYPE_MISMATCH: "Status" = ...
778 INVALID_CLUSTERS: "Status" = ...
779 INVALID_CONTENT: "Status" = ...
780 INVALID_DASH: "Status" = ...
781 INVALID_DSC_COMMENT: "Status" = ...
782 INVALID_FORMAT: "Status" = ...
783 INVALID_INDEX: "Status" = ...
784 INVALID_MATRIX: "Status" = ...
785 INVALID_MESH_CONSTRUCTION: "Status" = ...
786 INVALID_PATH_DATA: "Status" = ...
787 INVALID_POP_GROUP: "Status" = ...
788 INVALID_RESTORE: "Status" = ...
789 INVALID_SIZE: "Status" = ...
790 INVALID_SLANT: "Status" = ...
791 INVALID_STATUS: "Status" = ...
792 INVALID_STRIDE: "Status" = ...
793 INVALID_STRING: "Status" = ...
794 INVALID_VISUAL: "Status" = ...
795 INVALID_WEIGHT: "Status" = ...
796 JBIG2_GLOBAL_MISSING: "Status" = ...
797 """
798 .. versionadded:: 1.14
799 """
800 LAST_STATUS: "Status" = ...
801 NEGATIVE_COUNT: "Status" = ...
802 NO_CURRENT_POINT: "Status" = ...
803 NO_MEMORY: "Status" = ...
804 NULL_POINTER: "Status" = ...
805 PATTERN_TYPE_MISMATCH: "Status" = ...
806 READ_ERROR: "Status" = ...
807 SUCCESS: "Status" = ...
808 SURFACE_FINISHED: "Status" = ...
809 SURFACE_TYPE_MISMATCH: "Status" = ...
810 TEMP_FILE_ERROR: "Status" = ...
811 USER_FONT_ERROR: "Status" = ...
812 USER_FONT_IMMUTABLE: "Status" = ...
813 USER_FONT_NOT_IMPLEMENTED: "Status" = ...
814 WRITE_ERROR: "Status" = ...
815 TAG_ERROR: "Status" = ...
816 """
817 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
818 """
819 FREETYPE_ERROR: "Status" = ...
820 """
821 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
822 """
823 PNG_ERROR: "Status" = ...
824 """
825 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
826 """
827 WIN32_GDI_ERROR: "Status" = ...
828 """
829 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
830 """
831 DWRITE_ERROR: "Status" = ...
832 """
833 .. versionadded:: 1.23.0 Only available with cairo 1.17.6+
834 """
835 SVG_FONT_ERROR: "Status" = ...
836 """
837 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
838 """
839
840 class PDFVersion(_IntEnum):
841 """
842 These constants are used to describe the version number of the PDF
843 specification that a generated PDF file will conform to.
844
845 .. versionadded:: 1.13
846 """
847
848 VERSION_1_4: "PDFVersion" = ...
849 """The version 1.4 of the PDF specification."""
850
851 VERSION_1_5: "PDFVersion" = ...
852 """The version 1.5 of the PDF specification."""
853
854 VERSION_1_6: "PDFVersion" = ...
855 """
856 The version 1.6 of the PDF specification.
857
858 .. versionadded:: 1.23.0 Only available with cairo 1.17.6+
859 """
860
861 VERSION_1_7: "PDFVersion" = ...
862 """
863 The version 1.7 of the PDF specification.
864
865 .. versionadded:: 1.23.0 Only available with cairo 1.17.6+
866 """
867
868 class PSLevel(_IntEnum):
869 """
870 These constants are used to describe the language level of the PostScript
871 Language Reference that a generated PostScript file will conform to.
872 Note: the constants are only defined when cairo has been compiled with PS
873 support enabled.
874
875 .. versionadded:: 1.13
876 """
877
878 LEVEL_2: "PSLevel" = ...
879 """The language level 2 of the PostScript specification."""
880
881 LEVEL_3: "PSLevel" = ...
882 """The language level 3 of the PostScript specification."""
883
884 class PathDataType(_IntEnum):
885 """
886 These constants are used to describe the type of one portion of a path
887 when represented as a :class:`Path`.
888
889 .. versionadded:: 1.13
890 """
891
892 CLOSE_PATH: "PathDataType" = ...
893 """A close-path operation"""
894
895 CURVE_TO: "PathDataType" = ...
896 """A curve-to operation"""
897
898 LINE_TO: "PathDataType" = ...
899 """ A line-to operation"""
900
901 MOVE_TO: "PathDataType" = ...
902 """A move-to operation"""
903
904 class RegionOverlap(_IntEnum):
905 """
906 .. versionadded:: 1.13
907 """
908
909 IN: "RegionOverlap" = ...
910 """The contents are entirely inside the region."""
911
912 OUT: "RegionOverlap" = ...
913 """The contents are entirely outside the region."""
914
915 PART: "RegionOverlap" = ...
916 """The contents are partially inside and partially outside the region."""
917
918 class SVGVersion(_IntEnum):
919 """
920 These constants are used to describe the version number of the SVG
921 specification that a generated SVG file will conform to.
922
923 .. versionadded:: 1.13
924 """
925
926 VERSION_1_1: "SVGVersion" = ...
927 """The version 1.1 of the SVG specification."""
928
929 VERSION_1_2: "SVGVersion" = ...
930 """The version 1.2 of the SVG specification."""
931
932 class SVGUnit(_IntEnum):
933 """
934 :class:`SVGUnit` is used to describe the units valid for coordinates and
935 lengths in the SVG specification.
936
937 See also:
938
939 * https://www.w3.org/TR/SVG/coords.htmlUnits
940 * https://www.w3.org/TR/SVG/types.htmlDataTypeLength
941 * https://www.w3.org/TR/css-values-3/lengths
942
943 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
944 """
945
946 USER: "SVGUnit" = ...
947 """
948 User unit, a value in the current coordinate system. If used in the
949 root element for the initial coordinate systems it corresponds to
950 pixels.
951 """
952
953 EM: "SVGUnit" = ...
954 """The size of the element's font."""
955
956 EX: "SVGUnit" = ...
957 """The x-height of the element’s font."""
958
959 PX: "SVGUnit" = ...
960 """Pixels (1px = 1/96th of 1in)."""
961
962 IN: "SVGUnit" = ...
963 """Inches (1in = 2.54cm = 96px)"""
964
965 CM: "SVGUnit" = ...
966 """Centimeters (1cm = 96px/2.54)."""
967
968 MM: "SVGUnit" = ...
969 """Millimeters (1mm = 1/10th of 1cm)."""
970
971 PT: "SVGUnit" = ...
972 """Points (1pt = 1/72th of 1in)."""
973
974 PC: "SVGUnit" = ...
975 """Picas (1pc = 1/6th of 1in)."""
976
977 PERCENT: "SVGUnit" = ...
978 """Percent, a value that is some fraction of another reference value."""
979
980 class PDFMetadata(_IntEnum):
981 """
982 :class:`PDFMetadata` is used by the :meth:`PDFSurface.set_metadata` method
983 to specify the metadata to set.
984
985 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
986 """
987
988 TITLE: "PDFMetadata" = ...
989 """The document title"""
990
991 AUTHOR: "PDFMetadata" = ...
992 """The document author"""
993
994 SUBJECT: "PDFMetadata" = ...
995 """The document subject"""
996
997 KEYWORDS: "PDFMetadata" = ...
998 """The document keywords"""
999
1000 CREATOR: "PDFMetadata" = ...
1001 """The document creator"""
1002
1003 CREATE_DATE: "PDFMetadata" = ...
1004 """The document creation date"""
1005
1006 MOD_DATE: "PDFMetadata" = ...
1007 """The document modification date"""
1008
1009 class PDFOutlineFlags(_IntEnum):
1010 """
1011 :class:`PDFOutlineFlags` is used by the :meth:`PDFSurface.add_outline`
1012 method to specify the attributes of an outline item. These flags may be
1013 bitwise-or'd to produce any combination of flags.
1014
1015 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
1016 """
1017
1018 OPEN: "PDFOutlineFlags" = ...
1019 """The outline item defaults to open in the PDF viewer"""
1020
1021 BOLD: "PDFOutlineFlags" = ...
1022 """The outline item is displayed by the viewer in bold text"""
1023
1024 ITALIC: "PDFOutlineFlags" = ...
1025 """The outline item is displayed by the viewer in italic text"""
1026
1027 class ScriptMode(_IntEnum):
1028 """
1029 A set of script output variants.
1030
1031 .. versionadded:: 1.14
1032 """
1033
1034 ASCII: "ScriptMode" = ...
1035 """the output will be in readable text (default)"""
1036
1037 BINARY: "ScriptMode" = ...
1038 """the output will use byte codes."""
1039
1040 class Matrix:
1041 """
1042 *Matrix* is used throughout cairo to convert between different coordinate
1043 spaces. A *Matrix* holds an affine transformation, such as a scale,
1044 rotation, shear, or a combination of these. The transformation of a point
1045 (x,y) is given by::
1046
1047 x_new = xx * x + xy * y + x0
1048 y_new = yx * x + yy * y + y0
1049
1050 The current transformation matrix of a :class:`Context`, represented as a
1051 *Matrix*, defines the transformation from user-space coordinates to
1052 device-space coordinates.
1053
1054 Some standard Python operators can be used with matrices:
1055
1056 To read the values from a *Matrix*::
1057
1058 xx, yx, xy, yy, x0, y0 = matrix
1059
1060 To multiply two matrices::
1061
1062 matrix3 = matrix1.multiply(matrix2)
1063 # or equivalently
1064 matrix3 = matrix1 * matrix2
1065
1066 To compare two matrices::
1067
1068 matrix1 == matrix2
1069 matrix1 != matrix2
1070
1071 For more information on matrix transformation see
1072 https://www.cairographics.org/cookbook/matrix_transform/
1073 """
1074
1075 def __init__(self, xx: float = 1.0, yx: float = 0.0, xy: float = 0.0, yy: float = 1.0, x0: float = 0.0, y0: float = 0.0) -> None:
1076 """
1077 :param xx: xx component of the affine transformation
1078 :param yx: yx component of the affine transformation
1079 :param xy: xy component of the affine transformation
1080 :param yy: yy component of the affine transformation
1081 :param x0: X translation component of the affine transformation
1082 :param y0: Y translation component of the affine transformation
1083
1084 Create a new *Matrix* with the affine transformation given by *xx, yx,
1085 xy, yy, x0, y0*. The transformation is given by::
1086
1087 x_new = xx * x + xy * y + x0
1088 y_new = yx * x + yy * y + y0
1089
1090 To create a new identity matrix::
1091
1092 matrix = cairo.Matrix()
1093
1094 To create a matrix with a transformation which translates by tx and ty
1095 in the X and Y dimensions, respectively::
1096
1097 matrix = cairo.Matrix(x0=tx, y0=ty)
1098
1099 To create a matrix with a transformation that scales by sx and sy in the
1100 X and Y dimensions, respectively::
1101
1102 matrix = cairo.Matrix(xx=sy, yy=sy)
1103 """
1104
1105 @classmethod
1106 def init_rotate(cls, radians: float) -> "Matrix":
1107 """
1108 :param radians: angle of rotation, in radians. The direction of rotation
1109 is defined such that positive angles rotate in the direction from the
1110 positive X axis toward the positive Y axis. With the default axis
1111 orientation of cairo, positive angles rotate in a clockwise direction.
1112 :returns: a new *Matrix* set to a transformation that rotates by *radians*.
1113 """
1114
1115 def invert(self) -> Optional["Matrix"]:
1116 """
1117 :returns: If *Matrix* has an inverse, modifies *Matrix* to be the
1118 inverse matrix and returns *None*
1119 :raises: :exc:`cairo.Error` if the *Matrix* as no inverse
1120
1121 Changes *Matrix* to be the inverse of it's original value. Not all
1122 transformation matrices have inverses; if the matrix collapses points
1123 together (it is *degenerate*), then it has no inverse and this function
1124 will fail.
1125 """
1126
1127 def multiply(self, matrix2: "Matrix") -> "Matrix":
1128 """
1129 :param matrix2: a second matrix
1130 :returns: a new *Matrix*
1131
1132 Multiplies the affine transformations in *Matrix* and *matrix2*
1133 together. The effect of the resulting transformation is to first apply
1134 the transformation in *Matrix* to the coordinates and then apply the
1135 transformation in *matrix2* to the coordinates.
1136
1137 It is allowable for result to be identical to either *Matrix* or *matrix2*.
1138 """
1139
1140 def rotate(self, radians: float) -> None:
1141 """
1142 :param radians: angle of rotation, in radians. The direction of rotation
1143 is defined such that positive angles rotate in the direction from the
1144 positive X axis toward the positive Y axis. With the default axis
1145 orientation of cairo, positive angles rotate in a clockwise direction.
1146
1147 Initialize *Matrix* to a transformation that rotates by *radians*.
1148 """
1149
1150 def scale(self, sx: float, sy: float) -> None:
1151 """
1152 :param sx: scale factor in the X direction
1153 :param sy: scale factor in the Y direction
1154
1155 Applies scaling by *sx, sy* to the transformation in *Matrix*. The
1156 effect of the new transformation is to first scale the coordinates by
1157 *sx* and *sy*, then apply the original transformation to the
1158 coordinates.
1159 """
1160
1161 def transform_distance(self, dx: float, dy: float) -> Tuple[float, float]:
1162 """
1163 :param dx: X component of a distance vector.
1164 :param dy: Y component of a distance vector.
1165 :returns: the transformed distance vector (dx,dy), both float
1166
1167 Transforms the distance vector *(dx,dy)* by *Matrix*. This is similar to
1168 :meth:`.transform_point` except that the translation components of
1169 the transformation are ignored. The calculation of the returned vector
1170 is as follows::
1171
1172 dx2 = dx1 * a + dy1 * c
1173 dy2 = dx1 * b + dy1 * d
1174
1175 Affine transformations are position invariant, so the same vector always
1176 transforms to the same vector. If *(x1,y1)* transforms to *(x2,y2)* then
1177 *(x1+dx1,y1+dy1)* will transform to *(x1+dx2,y1+dy2)* for all values
1178 of *x1* and *x2*.
1179 """
1180
1181 def transform_point(self, x: float, y: float) -> Tuple[float, float]:
1182 """
1183 :param x: X position.
1184 :param y: Y position.
1185 :returns: the transformed point (x,y), both float
1186
1187 Transforms the point *(x, y)* by *Matrix*.
1188 """
1189
1190 def translate(self, tx: float, ty: float) -> None:
1191 """
1192 :param tx: amount to translate in the X direction
1193 :param ty: amount to translate in the Y direction
1194
1195 Applies a transformation by *tx, ty* to the transformation in
1196 *Matrix*. The effect of the new transformation is to first translate the
1197 coordinates by *tx* and *ty*, then apply the original transformation to the
1198 coordinates.
1199 """
1200
1201 xx: float = ...
1202 """
1203 xx component of the affine transformation
1204
1205 .. versionadded:: 1.12.0
1206 """
1207
1208 yx: float = ...
1209 """
1210 yx component of the affine transformation
1211
1212 .. versionadded:: 1.12.0
1213 """
1214
1215 xy: float = ...
1216 """
1217 xy component of the affine transformation
1218
1219 .. versionadded:: 1.12.0
1220 """
1221
1222 yy: float = ...
1223 """
1224 yy component of the affine transformation
1225
1226 .. versionadded:: 1.12.0
1227 """
1228
1229 x0: float = ...
1230 """
1231 X translation component of the affine transformation
1232
1233 .. versionadded:: 1.12.0
1234 """
1235
1236 y0: float = ...
1237 """
1238 Y translation component of the affine transformation
1239
1240 .. versionadded:: 1.12.0
1241 """
1242
1243 class Pattern:
1244 """
1245 *Pattern* is the abstract base class from which all the other pattern classes
1246 derive. It cannot be instantiated directly.
1247 """
1248
1249 def get_extend(self) -> Extend:
1250 """
1251 :returns: the current extend strategy used for drawing the *Pattern*.
1252
1253 Gets the current extend mode for the *Pattern*. See
1254 :class:`cairo.Extend` attributes for details on the semantics of each
1255 extend strategy.
1256 """
1257
1258 def get_matrix(self) -> Matrix:
1259 """
1260 :returns: a new :class:`Matrix` which stores a copy of the *Pattern's*
1261 transformation matrix
1262 """
1263
1264 def get_filter(self) -> Filter:
1265 """
1266 :returns: the current filter used for
1267 resizing the pattern.
1268
1269 .. versionadded:: 1.12.0
1270
1271 Used to be a method of :class:`SurfacePattern` before
1272 """
1273
1274 def set_filter(self, filter: Filter) -> None:
1275 """
1276 :param filter: a filter describing the filter
1277 to use for resizing the pattern
1278
1279 Note that you might want to control filtering even when you do not have
1280 an explicit *Pattern* object, (for example when using
1281 :meth:`Context.set_source_surface`). In these cases, it is convenient to
1282 use :meth:`Context.get_source` to get access to the pattern that cairo
1283 creates implicitly. For example::
1284
1285 context.set_source_surface(image, x, y)
1286 context.get_source().set_filter(cairo.FILTER_NEAREST)
1287
1288 .. versionadded:: 1.12.0
1289
1290 Used to be a method of :class:`SurfacePattern` before
1291 """
1292
1293 def set_extend(self, extend: Extend) -> None:
1294 """
1295 :param extend: an extend describing how the
1296 area outside of the *Pattern* will be drawn
1297
1298 Sets the mode to be used for drawing outside the area of a *Pattern*.
1299
1300 The default extend mode is :attr:`cairo.Extend.NONE` for
1301 :class:`SurfacePattern` and :attr:`cairo.Extend.PAD` for
1302 :class:`Gradient` Patterns.
1303 """
1304
1305 def set_matrix(self, matrix: Matrix) -> None:
1306 """
1307 :param matrix: a :class:`Matrix`
1308
1309 Sets the *Pattern's* transformation matrix to *matrix*. This matrix is a
1310 transformation from user space to pattern space.
1311
1312 When a *Pattern* is first created it always has the identity matrix for
1313 its transformation matrix, which means that pattern space is initially
1314 identical to user space.
1315
1316 Important: Please note that the direction of this transformation matrix
1317 is from user space to pattern space. This means that if you imagine the
1318 flow from a *Pattern* to user space (and on to device space), then
1319 coordinates in that flow will be transformed by the inverse of the
1320 *Pattern* matrix.
1321
1322 For example, if you want to make a *Pattern* appear twice as large as it
1323 does by default the correct code to use is::
1324
1325 matrix = cairo.Matrix(xx=0.5,yy=0.5)
1326 pattern.set_matrix(matrix)
1327
1328 Meanwhile, using values of 2.0 rather than 0.5 in the code above would
1329 cause the *Pattern* to appear at half of its default size.
1330
1331 Also, please note the discussion of the user-space locking semantics of
1332 :class:`Context.set_source`.
1333 """
1334
1335 def get_dither(self) -> Dither:
1336 """
1337 :returns: the current dithering mode.
1338
1339 Gets the current dithering mode, as set by :meth:`Pattern.set_dither`.
1340
1341 .. versionadded:: 1.25.0 Only available with cairo 1.18.0+
1342 """
1343
1344 def set_dither(self, dither: Dither) -> None:
1345 """
1346 :param dither: a :class:`Dither` describing the new dithering mode
1347
1348 Set the dithering mode of the rasterizer used for drawing shapes. This
1349 value is a hint, and a particular backend may or may not support a
1350 particular value. At the current time, only pixman is supported.
1351
1352 .. versionadded:: 1.25.0 Only available with cairo 1.18.0+
1353 """
1354
1355 class Glyph(Tuple[int, float, float]):
1356 """
1357 The :class:`Glyph` holds information about a single glyph when drawing or
1358 measuring text. A font is (in simple terms) a collection of shapes used to
1359 draw text. A glyph is one of these shapes. There can be multiple glyphs
1360 for a single character (alternates to be used in different contexts, for
1361 example), or a glyph can be a ligature of multiple characters. Cairo
1362 doesn't expose any way of converting input text into glyphs, so in order
1363 to use the Cairo interfaces that take arrays of glyphs, you must directly
1364 access the appropriate underlying font system.
1365
1366 Note that the offsets given by x and y are not cumulative. When drawing or
1367 measuring text, each glyph is individually positioned with respect to the
1368 overall origin
1369
1370 .. versionadded:: 1.15
1371 In prior versions a (int, float, float) tuple was used instead
1372 of :class:`Glyph`.
1373 """
1374
1375 index: int = ... # type: ignore
1376 x: float = ...
1377 y: float = ...
1378
1379 def __init__(self, index: int, x: float, y: float) -> None:
1380 """
1381 :param index:
1382 glyph index in the font. The exact interpretation of the glyph index
1383 depends on the font technology being used.
1384 :param x:
1385 the offset in the X direction between the origin used for drawing or
1386 measuring the string and the origin of this glyph.
1387 :param y:
1388 the offset in the Y direction between the origin used for drawing or
1389 measuring the string and the origin of this glyph.
1390 """
1391
1392 class TextCluster(Tuple[int, int]):
1393 """
1394 .. versionadded:: 1.15
1395
1396 The :class:`TextCluster` structure holds information about a single text
1397 cluster. A text cluster is a minimal mapping of some glyphs corresponding
1398 to some UTF-8 text.
1399
1400 For a cluster to be valid, both ``num_bytes`` and ``num_glyphs`` should be
1401 non-negative, and at least one should be non-zero. Note that clusters with
1402 zero glyphs are not as well supported as normal clusters. For example, PDF
1403 rendering applications typically ignore those clusters when PDF text is
1404 being selected.
1405
1406 See :meth:`Context.show_text_glyphs` for how clusters are used in advanced
1407 text operations.
1408 """
1409 num_bytes: int = ...
1410 num_glyphs: int = ...
1411 def __init__(self, num_bytes: int, num_glyphs: int) -> None:
1412 """
1413 :param num_bytes:
1414 the number of bytes of UTF-8 text covered by cluster
1415 :param num_glyphs:
1416 the number of glyphs covered by cluster
1417 """
1418
1419 class TextClusterFlags(_IntEnum):
1420 """
1421 Specifies properties of a text cluster mapping.
1422
1423 .. versionadded:: 1.14
1424 """
1425
1426 BACKWARD: "TextClusterFlags" = ...
1427 """
1428 The clusters in the cluster array map to glyphs in the glyph array
1429 from end to start.
1430 """
1431
1432 class TextExtents(Tuple[float, float, float, float, float, float]):
1433 """
1434 .. versionadded:: 1.15
1435 In prior versions a (float, float, float, float, float, float) tuple
1436 was used instead of :class:`TextExtents`.
1437
1438 The :class:`TextExtents` class stores the extents of a single glyph or a
1439 string of glyphs in user-space coordinates. Because text extents are in
1440 user-space coordinates, they are mostly, but not entirely, independent of
1441 the current transformation matrix. If you call ``context.scale(2.0,
1442 2.0)``, text will be drawn twice as big, but the reported text extents
1443 will not be doubled. They will change slightly due to hinting (so you
1444 can't assume that metrics are independent of the transformation matrix),
1445 but otherwise will remain unchanged.
1446 """
1447 x_bearing: float = ...
1448 y_bearing: float = ...
1449 width: float = ...
1450 height: float = ...
1451 x_advance: float = ...
1452 y_advance: float = ...
1453 def __init__(self, x_bearing: float, y_bearing: float, width: float, height: float, x_advance: float, y_advance: float) -> None:
1454 """
1455 :param x_bearing:
1456 the horizontal distance from the origin to the leftmost part of the
1457 glyphs as drawn. Positive if the glyphs lie entirely to the right of
1458 the origin.
1459 :param y_bearing:
1460 the vertical distance from the origin to the topmost part of the
1461 glyphs as drawn. Positive only if the glyphs lie completely below the
1462 origin; will usually be negative.
1463 :param width:
1464 width of the glyphs as drawn
1465 :param height:
1466 height of the glyphs as drawn
1467 :param x_advance:
1468 distance to advance in the X direction after drawing these glyphs
1469 :param y_advance:
1470 distance to advance in the Y direction after drawing these glyphs.
1471 Will typically be zero except for vertical text layout as found in
1472 East-Asian languages.
1473 """
1474
1475 class RectangleInt:
1476 """
1477 RectangleInt is a data structure for holding a rectangle with integer coordinates.
1478
1479 .. versionadded:: 1.11.0
1480 """
1481
1482 height: int = ...
1483 width: int = ...
1484 x: int = ...
1485 y: int = ...
1486
1487 def __init__(self, x: int=0, y: int=0, width: int=0, height: int=0) -> None:
1488 """
1489 :param x:
1490 X coordinate of the left side of the rectangle.
1491 :param y:
1492 Y coordinate of the top side of the rectangle.
1493 :param width:
1494 Width of the rectangle.
1495 :param height:
1496 Height of the rectangle.
1497
1498 Allocates a new RectangleInt object.
1499 """
1500
1501
1502 class FontFace:
1503 """
1504 A *cairo.FontFace* specifies all aspects of a font other than the size or font
1505 matrix (a font matrix is used to distort a font by sheering it or scaling it
1506 unequally in the two directions). A *FontFace* can be set on a
1507 :class:`Context` by using :meth:`Context.set_font_face` the size and font
1508 matrix are set with :meth:`Context.set_font_size` and
1509 :meth:`Context.set_font_matrix`.
1510
1511 There are various types of *FontFace*, depending on the font backend they
1512 use.
1513
1514 .. note:: This class cannot be instantiated directly, it is returned by
1515 :meth:`Context.get_font_face`.
1516 """
1517
1518 class FontOptions:
1519 """
1520 An opaque structure holding all options that are used when rendering fonts.
1521
1522 Individual features of a *FontOptions* can be set or accessed using functions
1523 named *FontOptions.set_<feature_name>* and
1524 *FontOptions.get_<feature_name>*, like :meth:`FontOptions.set_antialias`
1525 and :meth:`FontOptions.get_antialias`.
1526
1527 New features may be added to a *FontOptions* in the future. For this reason,
1528 :meth:`FontOptions.copy()`, :meth:`FontOptions.equal()`,
1529 :meth:`FontOptions.merge()`, and :meth:`FontOptions.hash()` should be used to
1530 copy, check for equality, merge, or compute a hash value of FontOptions
1531 objects.
1532
1533 Implements `__eq__` and `__ne__` using `equal()` since 1.12.0.
1534 """
1535
1536 def __init__(self) -> None:
1537 """
1538 Allocates a new FontOptions object with all options initialized to default
1539 values.
1540 """
1541
1542 def get_antialias(self) -> Antialias:
1543 """
1544 :returns: the antialias mode for the *FontOptions* object
1545 """
1546
1547 def get_hint_style(self) -> HintStyle:
1548 """
1549 :returns: the hint style for the *FontOptions* object
1550 """
1551
1552 def get_subpixel_order(self) -> SubpixelOrder:
1553 """
1554 :returns: the subpixel order for the *FontOptions* object
1555 """
1556
1557 def set_antialias(self, antialias: Antialias) -> None:
1558 """
1559 :param antialias: the antialias mode
1560
1561 This specifies the type of antialiasing to do when rendering text.
1562 """
1563
1564 def set_hint_metrics(self, hint_metrics: HintMetrics) -> None:
1565 """
1566 :param hint_metrics: the hint metrics mode
1567
1568 This controls whether metrics are quantized to integer values in device
1569 units.
1570 """
1571
1572 def set_hint_style(self, hint_style: HintStyle) -> None:
1573 """
1574 :param hint_style: the hint style
1575
1576 This controls whether to fit font outlines to the pixel grid, and if so,
1577 whether to optimize for fidelity or contrast.
1578 """
1579
1580 def merge(self, other: "FontOptions") -> None:
1581 """
1582 :param FontOptions other: another :class:`FontOptions`
1583
1584 Merges non-default options from other into options , replacing existing
1585 values. This operation can be thought of as somewhat similar to
1586 compositing other onto options with the operation of
1587 :attr:`Operator.OVER`.
1588
1589 .. versionadded:: 1.12.0
1590 """
1591
1592 def copy(self) -> "FontOptions":
1593 """
1594 :returns: a new :class:`FontOptions`
1595
1596 Returns a new font options object copying the option values from
1597 original.
1598
1599 .. versionadded:: 1.12.0
1600 """
1601
1602 def hash(self) -> int:
1603 """
1604 :returns: the hash value for the font options object
1605
1606 Compute a hash for the font options object; this value will be useful
1607 when storing an object containing a :class:`FontOptions` in a hash
1608 table.
1609
1610 .. versionadded:: 1.12.0
1611 """
1612
1613 def equal(self, other: "FontOptions") -> bool:
1614 """
1615 :param other: another :class:`FontOptions`
1616 :returns: :obj:`True` if all fields of the two font options objects
1617 match. Note that this function will return :obj:`False` if either
1618 object is in error.
1619
1620 Compares two font options objects for equality.
1621
1622 .. versionadded:: 1.12.0
1623 """
1624
1625 def set_variations(self, variations: Optional[str]) -> None:
1626 """
1627 :param variations: the new font variations, or :obj:`None`
1628
1629 Sets the OpenType font variations for the font options object. Font
1630 variations are specified as a string with a format that is similar to
1631 the CSS font-variation-settings. The string contains a comma-separated
1632 list of axis assignments, which each assignment consists of a
1633 4-character axis name and a value, separated by whitespace and
1634 optional equals sign.
1635
1636 Examples:
1637
1638 * wght=200,wdth=140.5
1639 * wght 200 , wdth 140.5
1640
1641 .. versionadded:: 1.18.0 Only available with cairo 1.15.12+
1642 """
1643
1644 def get_variations(self) -> str:
1645 """
1646 :returns:
1647 the font variations for the font options object. The returned
1648 string belongs to the options and must not be modified. It is
1649 valid until either the font options object is destroyed or the
1650 font variations in this object is modified with
1651 :meth:`set_variations`.
1652
1653 Gets the OpenType font variations for the font options object. See
1654 :meth:`set_variations` for details about the string format.
1655
1656 .. versionadded:: 1.18.0 Only available with cairo 1.15.12+
1657 """
1658
1659 def get_hint_metrics(self) -> HintMetrics:
1660 """
1661 :returns: the hint metrics mode for the *FontOptions* object
1662 """
1663
1664 def set_subpixel_order(self, subpixel_order: SubpixelOrder) -> None:
1665 """
1666 :param subpixel_order: the subpixel order
1667
1668 The subpixel order specifies the order of color elements within each
1669 pixel on the display device when rendering with an antialiasing mode of
1670 :attr:`cairo.Antialias.SUBPIXEL`.
1671 """
1672
1673 def set_color_mode(self, color_mode: ColorMode) -> None:
1674 """
1675 :param color_mode: the new color mode
1676
1677 Sets the color mode for the font options object. This controls whether
1678 color fonts are to be rendered in color or as outlines. See the
1679 documentation for :class:`ColorMode` for full details.
1680
1681 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
1682 """
1683
1684 def get_color_mode(self) -> ColorMode:
1685 """
1686 :returns: the color mode for the font options object
1687
1688 Gets the color mode for the font options object. See the documentation
1689 for :class:`ColorMode` for full details.
1690
1691 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
1692 """
1693
1694 def set_color_palette(self, palette_index: int) -> None:
1695 """
1696 :param palette_index: the palette index in the CPAL table
1697
1698 Sets the OpenType font color palette for the font options object.
1699 OpenType color fonts with a CPAL table may contain multiple palettes.
1700 The default color palette index is :data:`COLOR_PALETTE_DEFAULT`. If
1701 palette_index is invalid, the default palette is used.
1702
1703 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
1704 """
1705
1706 def get_color_palette(self) -> int:
1707 """
1708 :returns: the palette index
1709
1710 Gets the OpenType color font palette for the font options object.
1711
1712 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
1713 """
1714
1715 def set_custom_palette_color(self, index: int, red: float, green: float, blue: float, alpha: float) -> None:
1716 """
1717 :param index: the index of the color to set
1718 :param red: red component of color
1719 :param green: green component of color
1720 :param blue: blue component of color
1721 :param alpha: alpha component of color
1722
1723 Sets a custom palette color for the font options object. This overrides
1724 the palette color at the specified color index. This override is
1725 independent of the selected palette index and will remain in place even
1726 if :meth:`FontOptions.set_color_palette` is called to change the palette
1727 index.
1728
1729 It is only possible to override color indexes already in the font
1730 palette.
1731
1732 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
1733 """
1734
1735 def get_custom_palette_color(self, index: int) -> Tuple[float, float, float, float]:
1736 """
1737 :param index: the index of the color to get
1738 :returns: a (red, green, blue, alpha) tuple of float
1739 :raises Error: if no custom color exists for the color index.
1740
1741 Gets the custom palette color for the color index for the font options
1742 object.
1743
1744 .. versionadded:: 1.25.0 Only available with cairo 1.17.8+
1745 """
1746
1747 class ScaledFont:
1748 """
1749 A *ScaledFont* is a font scaled to a particular size and device resolution. A
1750 *ScaledFont* is most useful for low-level font usage where a library or
1751 application wants to cache a reference to a scaled font to speed up the
1752 computation of metrics.
1753
1754 There are various types of scaled fonts, depending on the font backend they
1755 use.
1756 """
1757
1758 def __init__(self, font_face: FontFace, font_matrix: Matrix, ctm: Matrix, options: FontOptions) -> None:
1759 """
1760 :param font_face: a :class:`FontFace` instance
1761 :param font_matrix: font space to user space transformation :class:`Matrix`
1762 for the font. In the simplest case of a N point font, this matrix is just
1763 a scale by N, but it can also be used to shear the font or stretch it
1764 unequally along the two axes. See :meth:`Context.set_font_matrix`.
1765 :param ctm: user to device transformation :class:`Matrix` with which the
1766 font will be used.
1767 :param options: a :class:`FontOptions` instance to use when getting metrics
1768 for the font and rendering with it.
1769
1770 Creates a *ScaledFont* object from a *FontFace* and matrices that describe
1771 the size of the font and the environment in which it will be used.
1772 """
1773
1774 def extents(self) -> Tuple[float, float, float, float, float]:
1775 """
1776 Gets the metrics for a *ScaledFont*.
1777 """
1778
1779 def get_ctm(self) -> Matrix:
1780 """
1781 :returns: the CTM
1782
1783 Returns the CTM with which scaled_font was created into ctm. Note that
1784 the translation offsets (x0, y0) of the CTM are ignored by
1785 :func:`ScaledFont`. So, the matrix this function returns always has 0,
1786 0 as x0, y0.
1787
1788 .. versionadded:: 1.12.0
1789 """
1790
1791 def get_font_face(self) -> FontFace:
1792 """
1793 :returns: the :class:`FontFace` that this *ScaledFont* was created for.
1794
1795 .. versionadded:: 1.2
1796 """
1797
1798 def get_font_matrix(self) -> Matrix:
1799 """
1800 :returns: the matrix
1801
1802 Returns the font matrix with which scaled_font was created.
1803 """
1804
1805 def get_font_options(self) -> FontOptions:
1806 """
1807 :returns: font options
1808
1809 Returns the font options with which scaled_font was created.
1810
1811 .. versionadded:: 1.12.0
1812 """
1813
1814 def get_scale_matrix(self) -> Matrix:
1815 """
1816 :returns: the scale :class:`Matrix`
1817
1818 The scale matrix is product of the font matrix and the ctm associated
1819 with the scaled font, and hence is the matrix mapping from font space to
1820 device space.
1821
1822 .. versionadded:: 1.8
1823 """
1824
1825 def glyph_extents(self, glyphs: Sequence[Glyph]) -> TextExtents:
1826 """
1827 :param glyphs: glyphs, a sequence of :class:`Glyph`
1828
1829 .. versionadded:: 1.15
1830
1831 Gets the extents for a list of glyphs. The extents describe a user-space
1832 rectangle that encloses the "inked" portion of the glyphs, (as they
1833 would be drawn by :meth:`Context.show_glyphs` if the cairo graphics
1834 state were set to the same font_face, font_matrix, ctm, and font_options
1835 as scaled_font ). Additionally, the x_advance and y_advance values
1836 indicate the amount by which the current point would be advanced by
1837 cairo_show_glyphs().
1838
1839 Note that whitespace glyphs do not contribute to the size of the
1840 rectangle (extents.width and extents.height).
1841 """
1842
1843 def text_extents(self, text: str) -> TextExtents:
1844 """
1845 :param text: text
1846
1847 Gets the extents for a string of text. The extents describe a user-space
1848 rectangle that encloses the "inked" portion of the text drawn at the
1849 origin (0,0) (as it would be drawn by :meth:`Context.show_text` if the
1850 cairo graphics state were set to the same font_face, font_matrix, ctm,
1851 and font_options as *ScaledFont*). Additionally, the x_advance and
1852 y_advance values indicate the amount by which the current point would be
1853 advanced by :meth:`Context.show_text`.
1854
1855 Note that whitespace characters do not directly contribute to the size
1856 of the rectangle (width and height). They do contribute indirectly by
1857 changing the position of non-whitespace characters. In particular,
1858 trailing whitespace characters are likely to not affect the size of the
1859 rectangle, though they will affect the x_advance and y_advance values.
1860
1861 .. versionadded:: 1.2
1862 """
1863
1864 def text_to_glyphs(self, x: float, y: float, utf8: str, with_clusters: bool = True) -> Union[Tuple[List[Glyph], List["TextCluster"], TextClusterFlags], List[Glyph]]:
1865 """
1866 :param x: X position to place first glyph
1867 :param y: Y position to place first glyph
1868 :param utf8: a string of text
1869 :param with_clusters:
1870 If :obj:`False` only the glyph list will computed and returned
1871 :returns:
1872 a tuple of ([:class:`Glyph`], [:class:`TextCluster`],
1873 :class:`TextClusterFlags`)
1874 :raises Error:
1875
1876 .. versionadded:: 1.15
1877
1878 Converts UTF-8 text to a list of glyphs, with cluster mapping, that can
1879 be used to render later.
1880
1881 For details of how clusters, and cluster_flags map input UTF-8 text to
1882 the output glyphs see :meth:`Context.show_text_glyphs`.
1883
1884 The output values can be readily passed to
1885 :meth:`Context.show_text_glyphs` :meth:`Context.show_glyphs`, or related
1886 functions, assuming that the exact same scaled font is used for the
1887 operation.
1888 """
1889
1890 _SomeDevice = TypeVar("_SomeDevice", bound="Device")
1891
1892 class Device:
1893 """
1894 A :class:`Device` represents the driver interface for drawing operations
1895 to a :class:`Surface`.
1896
1897 .. versionadded:: 1.14
1898
1899 .. note::
1900
1901 .. versionadded:: 1.17.0
1902
1903 :class:`cairo.Device` can be used as a context manager:
1904
1905 .. code:: python
1906
1907 # device.finish() will be called on __exit__
1908 with cairo.ScriptDevice(f) as device:
1909 pass
1910 """
1911
1912 def finish(self) -> None:
1913 """
1914 This function finishes the device and drops all references to external
1915 resources. All surfaces, fonts and other objects created for this
1916 device will be finished, too. Further operations on the device will
1917 not affect the device but will instead trigger a
1918 :attr:`Status.DEVICE_FINISHED` error.
1919
1920 This function may acquire devices.
1921
1922 .. versionadded:: 1.14
1923 """
1924
1925 def flush(self) -> None:
1926 """
1927 Finish any pending operations for the device and also restore any
1928 temporary modifications cairo has made to the device's state. This
1929 function must be called before switching from using the device with
1930 Cairo to operating on it directly with native APIs. If the device
1931 doesn't support direct access, then this function does nothing.
1932
1933 This function may acquire devices.
1934
1935 .. versionadded:: 1.14
1936 """
1937
1938 def acquire(self) -> None:
1939 """
1940 :raises cairo.Error:
1941 If the device is in an error state and could not be acquired.
1942
1943 Acquires the device for the current thread. This function will block
1944 until no other thread has acquired the device.
1945
1946 If the does not raise, you successfully acquired the device. From now
1947 on your thread owns the device and no other thread will be able to
1948 acquire it until a matching call to :meth:`release`. It is allowed to
1949 recursively acquire the device multiple times from the same thread.
1950
1951 After a successful call to :meth:`acquire`, a matching call to
1952 :meth:`release` is required.
1953
1954 .. note::
1955
1956 You must never acquire two different devices at the same time
1957 unless this is explicitly allowed. Otherwise the possibility of
1958 deadlocks exist. As various Cairo functions can acquire devices
1959 when called, these functions may also cause deadlocks when you
1960 call them with an acquired device. So you must not have a device
1961 acquired when calling them. These functions are marked in the
1962 documentation.
1963
1964 .. versionadded:: 1.14
1965 """
1966
1967 def release(self) -> None:
1968 """
1969 Releases a device previously acquired using :meth:`acquire`. See that
1970 function for details.
1971
1972 .. versionadded:: 1.14
1973 """
1974
1975 def __enter__(self: _SomeDevice) -> _SomeDevice: ...
1976 __exit__: Any = ...
1977
1978 _PathLike = Union[Text, ByteString]
1979 _FileLike = BinaryIO
1980 _SomeSurface = TypeVar("_SomeSurface", bound="Surface")
1981
1982 class Surface:
1983 """
1984 cairo.Surface is the abstract type representing all different drawing targets
1985 that cairo can render to. The actual drawings are performed using a
1986 :class:`Context`.
1987
1988 A cairo.Surface is created by using backend-specific constructors
1989 of the form cairo.<XXX>Surface().
1990
1991 *Surface* is the abstract base class from which all the other surface
1992 classes derive. It cannot be instantiated directly.
1993
1994 .. note::
1995
1996 .. versionadded:: 1.17.0
1997
1998 :class:`cairo.Surface` can be used as a context manager:
1999
2000 .. code:: python
2001
2002 # surface.finish() will be called on __exit__
2003 with cairo.SVGSurface("example.svg", 200, 200) as surface:
2004 pass
2005
2006 # surface.unmap_image(image_surface) will be called on __exit__
2007 with surface.map_to_image(None) as image_surface:
2008 pass
2009 """
2010
2011 def copy_page(self) -> None:
2012 """
2013 Emits the current page for backends that support multiple pages, but
2014 doesn't clear it, so that the contents of the current page will be
2015 retained for the next page. Use :meth:`.show_page` if you want to get an
2016 empty page after the emission.
2017
2018 :meth:`Context.copy_page` is a convenience function for this.
2019
2020 .. versionadded:: 1.6
2021 """
2022
2023 def create_for_rectangle(self, x: float, y: float, width: float, height: float) -> "Surface":
2024 """
2025 :param x: the x-origin of the sub-surface from the top-left of the
2026 target surface (in device-space units)
2027 :param y: the y-origin of the sub-surface from the top-left of the
2028 target surface (in device-space units)
2029 :param width: width of the sub-surface (in device-space units)
2030 :param height: height of the sub-surface (in device-space units)
2031 :returns: a new surface
2032
2033 Create a new surface that is a rectangle within the target surface. All
2034 operations drawn to this surface are then clipped and translated onto
2035 the target surface. Nothing drawn via this sub-surface outside of its
2036 bounds is drawn onto the target surface, making this a useful method for
2037 passing constrained child surfaces to library routines that draw
2038 directly onto the parent surface, i.e. with no further backend
2039 allocations, double buffering or copies.
2040
2041 .. note::
2042
2043 The semantics of subsurfaces have not been finalized yet unless the
2044 rectangle is in full device units, is contained within the extents of
2045 the target surface, and the target or subsurface's device transforms
2046 are not changed.
2047
2048 .. versionadded:: 1.12.0
2049 """
2050
2051 def create_similar(self, content: Content, width: int, height: int) -> "Surface":
2052 """
2053 :param content: the content for the new
2054 surface
2055 :param width: width of the new surface, (in device-space units)
2056 :param height: height of the new surface (in device-space units)
2057
2058 :returns: a newly allocated *Surface*.
2059
2060 Create a *Surface* that is as compatible as possible with the existing
2061 surface. For example the new surface will have the same fallback
2062 resolution and :class:`FontOptions`. Generally, the new surface will
2063 also use the same backend, unless that is not possible for some
2064 reason.
2065
2066 Initially the surface contents are all 0 (transparent if contents have
2067 transparency, black otherwise.)
2068 """
2069
2070 def create_similar_image(self, format: Format, width: int, height: int) -> "ImageSurface":
2071 """
2072 :param cairo.Format format: the format for the new surface
2073 :param width: width of the new surface, (in device-space units)
2074 :param height: height of the new surface, (in device-space units)
2075 :returns: a new image surface
2076
2077 Create a new image surface that is as compatible as possible for
2078 uploading to and the use in conjunction with an existing surface.
2079 However, this surface can still be used like any normal image surface.
2080
2081 Initially the surface contents are all 0 (transparent if contents have
2082 transparency, black otherwise.)
2083
2084 .. versionadded:: 1.12.0
2085 """
2086
2087 def finish(self) -> None:
2088 """
2089 This method finishes the Surface and drops all references to external
2090 resources. For example, for the Xlib backend it means that cairo will no
2091 longer access the drawable, which can be freed. After calling finish()
2092 the only valid operations on a Surface are flushing and finishing it.
2093 Further drawing to the surface will not affect the surface but will
2094 instead trigger a `cairo.Error` exception.
2095 """
2096
2097 def flush(self) -> None:
2098 """
2099 Do any pending drawing for the *Surface* and also restore any temporary
2100 modification's cairo has made to the *Surface's* state. This method
2101 must be called before switching from drawing on the *Surface* with cairo
2102 to drawing on it directly with native APIs. If the *Surface* doesn't
2103 support direct access, then this function does nothing.
2104 """
2105
2106 def get_content(self) -> Content:
2107 """
2108 :returns: The content type of *Surface*,
2109 which indicates whether the *Surface* contains color and/or alpha
2110 information.
2111
2112 .. versionadded:: 1.2
2113 """
2114
2115 def get_device(self) -> Optional["Device"]:
2116 """
2117 :returns: the device or :obj:`None` if the surface does not have an
2118 associated device
2119
2120 This function returns the device for a surface.
2121
2122 .. versionadded:: 1.14.0
2123 """
2124
2125 def get_device_offset(self) -> Tuple[float, float]:
2126 """
2127 :returns: (x_offset, y_offset) a tuple of float
2128
2129 * x_offset: the offset in the X direction, in device units
2130 * y_offset: the offset in the Y direction, in device units
2131
2132 This method returns the previous device offset set by
2133 :meth:`.set_device_offset`.
2134
2135 .. versionadded:: 1.2
2136 """
2137
2138 def get_device_scale(self) -> Tuple[float, float]:
2139 """
2140 :returns: (x_scale,y_scale) a 2-tuple of float
2141
2142 This function returns the previous device offset set by
2143 :meth:`Surface.set_device_scale`.
2144
2145 .. versionadded:: 1.14.0
2146 """
2147
2148 def get_fallback_resolution(self) -> Tuple[float, float]:
2149 """
2150 :returns: (x_pixels_per_inch, y_pixels_per_inch) a tuple of float
2151
2152 * x_pixels_per_inch: horizontal pixels per inch
2153 * y_pixels_per_inch: vertical pixels per inch
2154
2155 This method returns the previous fallback resolution set by
2156 :meth:`.set_fallback_resolution`, or default fallback resolution if
2157 never set.
2158
2159 .. versionadded:: 1.8
2160 """
2161
2162 def get_font_options(self) -> FontOptions:
2163 """
2164 :returns: a :class:`FontOptions`
2165
2166 Retrieves the default font rendering options for the *Surface*. This
2167 allows display surfaces to report the correct subpixel order for
2168 rendering on them, print surfaces to disable hinting of metrics and so
2169 forth. The result can then be used with :class:`ScaledFont`.
2170 """
2171
2172 def get_mime_data(self, mime_type: str) -> Optional[bytes]:
2173 """
2174 :param mime_type: the MIME type of the image data
2175 (:ref:`constants_MIME_TYPE`)
2176 :returns: :class:`bytes` or :obj:`None`
2177
2178 Return mime data previously attached to surface
2179 with :meth:`set_mime_data` using the specified mime type.
2180 If no data has been attached with the given mime type,
2181 :obj:`None` is returned.
2182
2183 .. versionadded:: 1.12.0
2184 """
2185
2186 def has_show_text_glyphs(self) -> bool:
2187 """
2188 :returns: :obj:`True` if surface supports
2189 :meth:`Context.show_text_glyphs`, :obj:`False` otherwise
2190
2191 Returns whether the surface supports sophisticated
2192 :meth:`Context.show_text_glyphs` operations. That is, whether it
2193 actually uses the provided text and cluster data to a
2194 :meth:`Context.show_text_glyphs` call.
2195
2196 Note: Even if this function returns :obj:`False`, a
2197 :meth:`Context.show_text_glyphs` operation targeted at surface will
2198 still succeed. It just will act like a :meth:`Context.show_glyphs`
2199 operation. Users can use this function to avoid computing UTF-8 text and
2200 cluster mapping if the target surface does not use it.
2201
2202 .. versionadded:: 1.12.0
2203 """
2204
2205 def map_to_image(self, extents: Optional[RectangleInt]) -> "ImageSurface":
2206 """
2207 :param extents: limit the extraction to an rectangular
2208 region or :obj:`None` for the whole surface
2209
2210 :returns: newly allocated image surface
2211 :raises Error:
2212
2213 Returns an image surface that is the most efficient mechanism for
2214 modifying the backing store of the target surface.
2215
2216 Note, the use of the original surface as a target or source whilst it is
2217 mapped is undefined. The result of mapping the surface multiple times is
2218 undefined. Calling :meth:`Surface.finish` on the resulting image surface
2219 results in undefined behavior. Changing the device transform of the
2220 image surface or of surface before the image surface is unmapped results
2221 in undefined behavior.
2222
2223 The caller must use :meth:`Surface.unmap_image` to destroy this image
2224 surface.
2225
2226 .. versionadded:: 1.15.0
2227 """
2228
2229 def mark_dirty(self) -> None:
2230 """
2231 Tells cairo that drawing has been done to *Surface* using means other
2232 than cairo, and that cairo should reread any cached areas. Note that you
2233 must call :meth:`.flush` before doing such drawing.
2234 """
2235
2236 def mark_dirty_rectangle(self, x: int, y: int, width: int, height: int) -> None:
2237 """
2238 :param x: X coordinate of dirty rectangle
2239 :param y: Y coordinate of dirty rectangle
2240 :param width: width of dirty rectangle
2241 :param height: height of dirty rectangle
2242
2243 Like :meth:`.mark_dirty`, but drawing has been done only to the
2244 specified rectangle, so that cairo can retain cached contents for other
2245 parts of the surface.
2246
2247 Any cached clip set on the *Surface* will be reset by this function, to
2248 make sure that future cairo calls have the clip set that they expect.
2249 """
2250
2251 def set_device_offset(self, x_offset: float, y_offset: float) -> None:
2252 """
2253 :param x_offset: the offset in the X direction, in device units
2254 :param y_offset: the offset in the Y direction, in device units
2255
2256 Sets an offset that is added to the device coordinates determined by the
2257 CTM when drawing to *Surface*. One use case for this function is when we
2258 want to create a *Surface* that redirects drawing for a portion of an
2259 onscreen surface to an offscreen surface in a way that is completely
2260 invisible to the user of the cairo API. Setting a transformation via
2261 :meth:`Context.translate` isn't sufficient to do this, since functions
2262 like :meth:`Context.device_to_user` will expose the hidden offset.
2263
2264 Note that the offset affects drawing to the surface as well as using the
2265 surface in a source pattern.
2266 """
2267
2268 def set_device_scale(self, x_scale: float, y_scale: float) -> None:
2269 """
2270 :param x_scale: a scale factor in the X direction
2271 :param y_scale: a scale factor in the Y direction
2272
2273 Sets a scale that is multiplied to the device coordinates determined by
2274 the CTM when drawing to surface . One common use for this is to render
2275 to very high resolution display devices at a scale factor, so that code
2276 that assumes 1 pixel will be a certain size will still work. Setting a
2277 transformation via :meth:`Context.translate` isn't sufficient to do
2278 this, since functions like :meth:`Context.device_to_user` will expose
2279 the hidden scale.
2280
2281 .. versionadded:: 1.14.0
2282 """
2283
2284 def set_fallback_resolution(self, x_pixels_per_inch: float, y_pixels_per_inch: float) -> None:
2285 """
2286 :param x_pixels_per_inch: horizontal setting for pixels per inch
2287 :param y_pixels_per_inch: vertical setting for pixels per inch
2288
2289 Set the horizontal and vertical resolution for image fallbacks.
2290
2291 When certain operations aren't supported natively by a backend, cairo
2292 will fallback by rendering operations to an image and then overlaying
2293 that image onto the output. For backends that are natively
2294 vector-oriented, this function can be used to set the resolution used
2295 for these image fallbacks, (larger values will result in more detailed
2296 images, but also larger file sizes).
2297
2298 Some examples of natively vector-oriented backends are the ps, pdf, and
2299 svg backends.
2300
2301 For backends that are natively raster-oriented, image fallbacks are
2302 still possible, but they are always performed at the native device
2303 resolution. So this function has no effect on those backends.
2304
2305 Note: The fallback resolution only takes effect at the time of
2306 completing a page (with :meth:`Context.show_page` or
2307 :meth:`Context.copy_page`) so there is currently no way to have more
2308 than one fallback resolution in effect on a single page.
2309
2310 The default fallback resoultion is 300 pixels per inch in both
2311 dimensions.
2312
2313 .. versionadded:: 1.2
2314 """
2315
2316 def set_mime_data(self, mime_type: str, data: bytes) -> None:
2317 """
2318 :param mime_type: the MIME type of the image data
2319 (:ref:`constants_MIME_TYPE`)
2320 :param data: the image data to attach to the surface
2321
2322 Attach an image in the format ``mime_type`` to *Surface*.
2323 To remove the data from a surface,
2324 call this function with same mime type and :obj:`None` for data.
2325
2326 The attached image (or filename) data can later be used
2327 by backends which support it
2328 (currently: PDF, PS, SVG and Win32 Printing surfaces)
2329 to emit this data instead of making a snapshot of the surface.
2330 This approach tends to be faster and requires less memory and disk space.
2331
2332 The recognized MIME types are listed under :ref:`constants_MIME_TYPE`.
2333
2334 See corresponding backend surface docs for details
2335 about which MIME types it can handle.
2336 Caution: the associated MIME data will be discarded
2337 if you draw on the surface afterwards.
2338 Use this function with care.
2339
2340 .. versionadded:: 1.12.0
2341 """
2342
2343 def show_page(self) -> None:
2344 """
2345 Emits and clears the current page for backends that support multiple
2346 pages. Use :meth:`.copy_page` if you don't want to clear the page.
2347
2348 There is a convenience function for this that takes a
2349 :meth:`Context.show_page`.
2350
2351 .. versionadded:: 1.6
2352 """
2353
2354 def supports_mime_type(self, mime_type: str) -> bool:
2355 """
2356 :param mime_type: the mime type (:ref:`constants_MIME_TYPE`)
2357 :returns: :obj:`True` if surface supports mime_type, :obj:`False`
2358 otherwise
2359
2360 Return whether surface supports ``mime_type``.
2361
2362 .. versionadded:: 1.12.0
2363 """
2364
2365 def write_to_png(self, fobj: Union[_FileLike, _PathLike]) -> None:
2366 """
2367 :param fobj: a filename or writable file object
2368 :raises: :exc:`MemoryError` if memory could not be allocated for the operation
2369
2370 :exc:`IOError` if an I/O error occurs while attempting to write
2371 the file
2372
2373 Writes the contents of *Surface* to *fobj* as a PNG image. *fobj* can either be
2374 a filename or a file object opened in binary mode.
2375 """
2376
2377 def unmap_image(self, image: "ImageSurface") -> None:
2378 """
2379 :param image: the currently mapped image
2380
2381 Unmaps the image surface as returned from :meth:`Surface.map_to_image`.
2382
2383 The content of the image will be uploaded to the target surface.
2384 Afterwards, the image is destroyed.
2385
2386 Using an image surface which wasn't returned by
2387 :meth:`Surface.map_to_image` results in undefined behavior.
2388
2389 .. versionadded:: 1.15.0
2390 """
2391
2392 def __enter__(self: _SomeSurface) -> _SomeSurface: ...
2393 __exit__: Any = ...
2394
2395 class ImageSurface(Surface):
2396 """
2397 A *cairo.ImageSurface* provides the ability to render to memory buffers
2398 either allocated by cairo or by the calling code. The supported image
2399 formats are those defined in :class:`cairo.Format`.
2400 """
2401
2402 def __init__(self, format: Format, width: int, height: int) -> None:
2403 """
2404 :param format: format of pixels in the surface to create
2405 :param width: width of the surface, in pixels
2406 :param height: height of the surface, in pixels
2407 :returns: a new *ImageSurface*
2408
2409 Creates an *ImageSurface* of the specified format and dimensions. Initially
2410 the surface contents are all 0. (Specifically, within each pixel, each
2411 color or alpha channel belonging to format will be 0. The contents of bits
2412 within a pixel, but not belonging to the given format are undefined).
2413 """
2414
2415 @classmethod
2416 def create_for_data(cls, data: memoryview, format: Format, width: int, height: int, stride: int = ...) -> "ImageSurface":
2417 """
2418 :param data: a writable Python buffer/memoryview object
2419 :param format: the format of pixels in the
2420 buffer
2421 :param width: the width of the image to be stored in the buffer
2422 :param height: the height of the image to be stored in the buffer
2423 :param stride: the number of bytes between the start of rows in the
2424 buffer as allocated. If not given the value from
2425 :meth:`cairo.Format.stride_for_width` is used.
2426 :returns: a new *ImageSurface*
2427 :raises: :exc:`MemoryError` in case of no memory.
2428
2429 :exc:`cairo.Error` in case of invalid *stride* value.
2430
2431 Creates an *ImageSurface* for the provided pixel data. The initial
2432 contents of buffer will be used as the initial image contents; you must
2433 explicitly clear the buffer, using, for example, cairo_rectangle() and
2434 cairo_fill() if you want it cleared.
2435
2436 Note that the *stride* may be larger than width*bytes_per_pixel to
2437 provide proper alignment for each pixel and row. This alignment is
2438 required to allow high-performance rendering within cairo. The correct
2439 way to obtain a legal stride value is to call
2440 :meth:`cairo.Format.stride_for_width` with the desired format and
2441 maximum image width value, and use the resulting stride value to
2442 allocate the data and to create the :class:`ImageSurface`. See
2443 :meth:`cairo.Format.stride_for_width` for example code.
2444 """
2445
2446 @classmethod
2447 def create_from_png(cls, fobj: Union[_PathLike, _FileLike]) -> "ImageSurface":
2448 """
2449 :param fobj:
2450 a :obj:`_PathLike`, file, or file-like object of the PNG to load.
2451 :returns: a new *ImageSurface* initialized the contents to the given PNG
2452 file.
2453
2454 Creates a new image surface and initializes the contents to the given
2455 PNG file. *fobj* can either be a filename or a file object opened in
2456 binary mode.
2457 """
2458
2459 format_stride_for_width = Format.stride_for_width
2460 """
2461 See :meth:`cairo.Format.stride_for_width`.
2462
2463 .. versionadded:: 1.6
2464 """
2465
2466 def get_data(self) -> memoryview:
2467 """
2468 :returns: a Python buffer object for the data of the *ImageSurface*, for
2469 direct inspection or modification. On Python 3 a memoryview object is
2470 returned.
2471
2472 .. versionadded:: 1.2
2473 """
2474
2475 def get_format(self) -> Format:
2476 """
2477 :returns: the format of the *ImageSurface*.
2478 :rtype: cairo.Format
2479
2480 .. versionadded:: 1.2
2481 """
2482
2483 def get_height(self) -> int:
2484 """
2485 :returns: the height of the *ImageSurface* in pixels.
2486 """
2487
2488 def get_stride(self) -> int:
2489 """
2490 :returns: the stride of the *ImageSurface* in bytes. The stride is the
2491 distance in bytes from the beginning of one row of the image data to
2492 the beginning of the next row.
2493 """
2494
2495 def get_width(self) -> int:
2496 """
2497 :returns: the width of the *ImageSurface* in pixels.
2498 """
2499
2500 class SurfacePattern(Pattern):
2501
2502 def __init__(self, surface: Surface) -> None:
2503 """
2504 :param surface: a cairo :class:`Surface`
2505 """
2506
2507 def get_surface(self) -> Surface:
2508 """
2509 :returns: the :class:`Surface` of the *SurfacePattern*.
2510
2511 .. versionadded:: 1.4
2512 """
2513
2514 class Context(Generic[_SomeSurface]):
2515 """
2516 *Context* is the main object used when drawing with cairo. To draw with cairo,
2517 you create a *Context*, set the target surface, and drawing options for the
2518 *Context*, create shapes with functions like :meth:`Context.move_to` and
2519 :meth:`Context.line_to`, and then draw shapes with :meth:`Context.stroke` or
2520 :meth:`Context.fill`.
2521
2522 *Contexts* can be pushed to a stack via :meth:`Context.save`. They may then
2523 safely be changed, without losing the current state. Use
2524 :meth:`Context.restore` to restore to the saved state.
2525 """
2526
2527 def __init__(self, target: _SomeSurface) -> None:
2528 """
2529 :param target: target :class:`Surface` for the context
2530 :raises: :exc:`MemoryError` in case of no memory
2531
2532 Creates a new *Context* with all graphics state parameters set to default
2533 values and with *target* as a target surface. The target surface should be
2534 constructed with a backend-specific function such as :class:`ImageSurface`
2535 (or any other cairo backend surface create variant).
2536 """
2537
2538 def append_path(self, path: Path) -> None:
2539 """
2540 :param path: :class:`Path` to be appended
2541
2542 Append the *path* onto the current path. The *path* may be either the
2543 return value from one of :meth:`Context.copy_path` or
2544 :meth:`Context.copy_path_flat` or it may be constructed manually (in C).
2545 """
2546
2547 def arc(self, xc: float, yc: float, radius: float, angle1: float, angle2: float) -> None:
2548 """
2549 :param xc: X position of the center of the arc
2550 :param yc: Y position of the center of the arc
2551 :param radius: the radius of the arc
2552 :param angle1: the start angle, in radians
2553 :param angle2: the end angle, in radians
2554
2555 Adds a circular arc of the given *radius* to the current path. The arc
2556 is centered at (*xc, yc*), begins at *angle1* and proceeds in the
2557 direction of increasing angles to end at *angle2*. If *angle2* is less
2558 than *angle1* it will be progressively increased by 2*PI until it is
2559 greater than *angle1*.
2560
2561 If there is a current point, an initial line segment will be added to
2562 the path to connect the current point to the beginning of the arc. If
2563 this initial line is undesired, it can be avoided by calling
2564 :meth:`Context.new_sub_path` before calling :meth:`Context.arc`.
2565
2566 Angles are measured in radians. An angle of 0.0 is in the direction of
2567 the positive X axis (in user space). An angle of PI/2.0 radians (90
2568 degrees) is in the direction of the positive Y axis (in user
2569 space). Angles increase in the direction from the positive X axis toward
2570 the positive Y axis. So with the default transformation matrix, angles
2571 increase in a clockwise direction.
2572
2573 To convert from degrees to radians, use ``degrees * (math.pi / 180)``.
2574
2575 This function gives the arc in the direction of increasing angles; see
2576 :meth:`Context.arc_negative` to get the arc in the direction of
2577 decreasing angles.
2578
2579 The arc is circular in user space. To achieve an elliptical arc,
2580 you can scale the current transformation matrix by different
2581 amounts in the X and Y directions. For example, to draw an ellipse
2582 in the box given by *x, y, width, height*::
2583
2584 ctx.save()
2585 ctx.translate(x + width / 2., y + height / 2.)
2586 ctx.scale(width / 2., height / 2.)
2587 ctx.arc(0., 0., 1., 0., 2 * math.pi)
2588 ctx.restore()
2589 """
2590
2591 def arc_negative(self, xc: float, yc: float, radius: float, angle1: float, angle2: float) -> None:
2592 """
2593 :param xc: X position of the center of the arc
2594 :param yc: Y position of the center of the arc
2595 :param radius: the radius of the arc
2596 :param angle1: the start angle, in radians
2597 :param angle2: the end angle, in radians
2598
2599 Adds a circular arc of the given *radius* to the current path. The arc
2600 is centered at (*xc, yc*), begins at *angle1* and proceeds in the
2601 direction of decreasing angles to end at *angle2*. If *angle2* is
2602 greater than *angle1* it will be progressively decreased by 2*PI until
2603 it is less than *angle1*.
2604
2605 See :meth:`Context.arc` for more details. This function differs only in
2606 the direction of the arc between the two angles.
2607 """
2608
2609 def clip(self) -> None:
2610 """
2611 Establishes a new clip region by intersecting the current clip region
2612 with the current path as it would be filled by :meth:`Context.fill` and
2613 according to the current :class:`fill rule <cairo.FillRule>` (see
2614 :meth:`Context.set_fill_rule`).
2615
2616 After :meth:`.clip`, the current path will be cleared from the
2617 :class:`Context`.
2618
2619 The current clip region affects all drawing operations by effectively
2620 masking out any changes to the surface that are outside the current clip
2621 region.
2622
2623 Calling :meth:`.clip` can only make the clip region smaller, never
2624 larger. But the current clip is part of the graphics state, so a
2625 temporary restriction of the clip region can be achieved by calling
2626 :meth:`.clip` within a :meth:`Context.save`/:meth:`Context.restore`
2627 pair. The only other means of increasing the size of the clip region is
2628 :meth:`Context.reset_clip`.
2629 """
2630
2631 def clip_extents(self) -> Tuple[float, float, float, float]:
2632 """
2633 :returns: (x1, y1, x2, y2), all float
2634
2635 * *x1*: left of the resulting extents
2636 * *y1*: top of the resulting extents
2637 * *x2*: right of the resulting extents
2638 * *y2*: bottom of the resulting extents
2639
2640 Computes a bounding box in user coordinates covering the area inside the
2641 current clip.
2642
2643 .. versionadded:: 1.4
2644 """
2645
2646 def clip_preserve(self) -> None:
2647 """
2648 Establishes a new clip region by intersecting the current clip region
2649 with the current path as it would be filled by :meth:`Context.fill` and
2650 according to the current :class:`fill rule <cairo.FillRule>` (see
2651 :meth:`Context.set_fill_rule`).
2652
2653 Unlike :meth:`Context.clip`, :meth:`.clip_preserve` preserves the path
2654 within the :class:`Context`.
2655
2656 The current clip region affects all drawing operations by effectively
2657 masking out any changes to the surface that are outside the current clip
2658 region.
2659
2660 Calling :meth:`.clip_preserve` can only make the clip region smaller,
2661 never larger. But the current clip is part of the graphics state, so a
2662 temporary restriction of the clip region can be achieved by calling
2663 :meth:`.clip_preserve` within a
2664 :meth:`Context.save`/:meth:`Context.restore` pair. The only other means
2665 of increasing the size of the clip region is :meth:`Context.reset_clip`.
2666 """
2667
2668 def close_path(self) -> None:
2669 """
2670 Adds a line segment to the path from the current point to the beginning
2671 of the current sub-path, (the most recent point passed to
2672 :meth:`Context.move_to`), and closes this sub-path. After this call the
2673 current point will be at the joined endpoint of the sub-path.
2674
2675 The behavior of :meth:`.close_path` is distinct from simply calling
2676 :meth:`Context.line_to` with the equivalent coordinate in the case of
2677 stroking. When a closed sub-path is stroked, there are no caps on the
2678 ends of the sub-path. Instead, there is a line join connecting the final
2679 and initial segments of the sub-path.
2680
2681 If there is no current point before the call to :meth:`.close_path`,
2682 this function will have no effect.
2683
2684 Note: As of cairo version 1.2.4 any call to :meth:`.close_path` will
2685 place an explicit MOVE_TO element into the path immediately after the
2686 CLOSE_PATH element, (which can be seen in :meth:`Context.copy_path` for
2687 example). This can simplify path processing in some cases as it may not
2688 be necessary to save the "last move_to point" during processing as the
2689 MOVE_TO immediately after the CLOSE_PATH will provide that point.
2690 """
2691
2692 def copy_clip_rectangle_list(self) -> List[Rectangle]:
2693 """
2694 :returns: the current clip region as a list of rectangles in user
2695 coordinates. Returns a list of :class:`Rectangle`
2696
2697 .. versionadded:: 1.4
2698 """
2699
2700 def copy_page(self) -> None:
2701 """
2702 Emits the current page for backends that support multiple pages, but
2703 doesn't clear it, so, the contents of the current page will be retained
2704 for the next page too. Use :meth:`Context.show_page` if you want to get
2705 an empty page after the emission.
2706
2707 This is a convenience function that simply calls
2708 :meth:`Surface.copy_page` on *Context's* target.
2709 """
2710
2711 def copy_path(self) -> Path:
2712 """
2713 :returns: :class:`Path`
2714 :raises: :exc:`MemoryError` in case of no memory
2715
2716 Creates a copy of the current path and returns it to the user as a
2717 :class:`Path`.
2718 """
2719
2720 def copy_path_flat(self) -> Path:
2721 """
2722 :returns: :class:`Path`
2723 :raises: :exc:`MemoryError` in case of no memory
2724
2725 Gets a flattened copy of the current path and returns it to the
2726 user as a :class:`Path`.
2727
2728 This function is like :meth:`Context.copy_path` except that any curves
2729 in the path will be approximated with piecewise-linear approximations,
2730 (accurate to within the current tolerance value). That is, the result is
2731 guaranteed to not have any elements of type CAIRO_PATH_CURVE_TO which
2732 will instead be replaced by a series of CAIRO_PATH_LINE_TO elements.
2733 """
2734
2735 def curve_to(self, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float) -> None:
2736 """
2737 :param x1: the X coordinate of the first control point
2738 :param y1: the Y coordinate of the first control point
2739 :param x2: the X coordinate of the second control point
2740 :param y2: the Y coordinate of the second control point
2741 :param x3: the X coordinate of the end of the curve
2742 :param y3: the Y coordinate of the end of the curve
2743
2744 Adds a cubic Bézier spline to the path from the current point to
2745 position *(x3, y3)* in user-space coordinates, using *(x1, y1)* and
2746 *(x2, y2)* as the control points. After this call the current point will
2747 be *(x3, y3)*.
2748
2749 If there is no current point before the call to :meth:`.curve_to`
2750 this function will behave as if preceded by a call to
2751 ``ctx.move_to(x1, y1)``.
2752 """
2753
2754 def device_to_user(self, x: float, y: float) -> Tuple[float, float]:
2755 """
2756 :param x: X value of coordinate
2757 :param y: Y value of coordinate
2758 :returns: (x, y), both float
2759
2760 Transform a coordinate from device space to user space by multiplying
2761 the given point by the inverse of the current transformation matrix
2762 (CTM).
2763 """
2764
2765 def device_to_user_distance(self, dx: float, dy: float) -> Tuple[float, float]:
2766 """
2767 :param dx: X component of a distance vector
2768 :param dy: Y component of a distance vector
2769 :returns: (dx, dy), both float
2770
2771 Transform a distance vector from device space to user space. This
2772 function is similar to :meth:`Context.device_to_user` except that the
2773 translation components of the inverse CTM will be ignored when
2774 transforming *(dx,dy)*.
2775 """
2776
2777 def fill(self) -> None:
2778 """
2779 A drawing operator that fills the current path according to the current
2780 :class:`fill rule <cairo.FillRule>`, (each sub-path is implicitly
2781 closed before being filled). After :meth:`.fill`, the current path will
2782 be cleared from the :class:`Context`. See :meth:`Context.set_fill_rule`
2783 and :meth:`Context.fill_preserve`.
2784 """
2785
2786 def fill_extents(self) -> Tuple[float, float, float, float]:
2787 """
2788 :returns: (x1, y1, x2, y2), all float
2789
2790 * *x1*: left of the resulting extents
2791 * *y1*: top of the resulting extents
2792 * *x2*: right of the resulting extents
2793 * *y2*: bottom of the resulting extents
2794
2795 Computes a bounding box in user coordinates covering the area that would
2796 be affected, (the "inked" area), by a :meth:`Context.fill` operation
2797 given the current path and fill parameters. If the current path is
2798 empty, returns an empty rectangle (0,0,0,0). Surface dimensions and
2799 clipping are not taken into account.
2800
2801 Contrast with :meth:`Context.path_extents`, which is similar, but returns
2802 non-zero extents for some paths with no inked area, (such as a
2803 simple line segment).
2804
2805 Note that :meth:`.fill_extents` must necessarily do more work to compute
2806 the precise inked areas in light of the fill rule, so
2807 :meth:`Context.path_extents` may be more desirable for sake of
2808 performance if the non-inked path extents are desired.
2809
2810 See :meth:`Context.fill`, :meth:`Context.set_fill_rule` and
2811 :meth:`Context.fill_preserve`.
2812 """
2813
2814 def fill_preserve(self) -> None:
2815 """
2816 A drawing operator that fills the current path according to the current
2817 :class:`fill rule <cairo.FillRule>`, (each sub-path is implicitly
2818 closed before being filled). Unlike :meth:`Context.fill`,
2819 :meth:`.fill_preserve` preserves the path within the :class:`Context`.
2820
2821 See :meth:`Context.set_fill_rule` and :meth:`Context.fill`.
2822 """
2823
2824 def font_extents(self) -> Tuple[float, float, float, float, float]:
2825 """
2826 :returns: (ascent, descent, height, max_x_advance, max_y_advance),
2827 all float
2828
2829 Gets the font extents for the currently selected font.
2830 """
2831
2832 def get_antialias(self) -> Antialias:
2833 """
2834 :returns: the current antialias mode,
2835 as set by :meth:`Context.set_antialias`.
2836 """
2837
2838 def get_current_point(self) -> Tuple[float, float]:
2839 """
2840 :returns: (x, y), both float
2841
2842 * *x*: X coordinate of the current point
2843 * *y*: Y coordinate of the current point
2844
2845 Gets the current point of the current path, which is conceptually the
2846 final point reached by the path so far.
2847
2848 The current point is returned in the user-space coordinate system. If
2849 there is no defined current point or if :class:`Context` is in an error
2850 status, *x* and *y* will both be set to 0.0. It is possible to check this
2851 in advance with :meth:`Context.has_current_point`.
2852
2853 Most path construction functions alter the current point. See the
2854 following for details on how they affect the current point:
2855 :meth:`Context.new_path`, :meth:`Context.new_sub_path`,
2856 :meth:`Context.append_path`, :meth:`Context.close_path`,
2857 :meth:`Context.move_to`, :meth:`Context.line_to`,
2858 :meth:`Context.curve_to`, :meth:`Context.rel_move_to`,
2859 :meth:`Context.rel_line_to`, :meth:`Context.rel_curve_to`,
2860 :meth:`Context.arc`, :meth:`Context.arc_negative`,
2861 :meth:`Context.rectangle`, :meth:`Context.text_path`,
2862 :meth:`Context.glyph_path`.
2863
2864 Some functions use and alter the current point but do not otherwise
2865 change current path:
2866 :meth:`Context.show_text`.
2867
2868 Some functions unset the current path and as a result, current point:
2869 :meth:`Context.fill`, :meth:`Context.stroke`.
2870 """
2871
2872 def get_dash(self) -> Tuple[List[float], float]:
2873 """
2874 :returns: (dashes, offset)
2875
2876 * *dashes*: return value as a tuple for the dash array
2877 * *offset*: return value as float for the current dash offset
2878
2879 Gets the current dash array.
2880
2881 .. versionadded:: 1.4
2882 """
2883
2884 def get_dash_count(self) -> int:
2885 """
2886 :returns: the length of the dash array, or 0 if no dash array set.
2887
2888 See also :meth:`Context.set_dash` and :meth:`Context.get_dash`.
2889
2890 .. versionadded:: 1.4
2891 """
2892
2893 def get_fill_rule(self) -> FillRule:
2894 """
2895 :returns: the current fill rule, as
2896 set by :meth:`Context.set_fill_rule`.
2897 """
2898
2899 def get_font_face(self) -> FontFace:
2900 """
2901 :returns: the current :class:`FontFace` for the :class:`Context`.
2902 """
2903
2904 def get_font_matrix(self) -> Matrix:
2905 """
2906 :returns: the current :class:`Matrix` for the :class:`Context`.
2907
2908 See :meth:`Context.set_font_matrix`.
2909 """
2910
2911 def get_font_options(self) -> FontOptions:
2912 """
2913 :returns: the current :class:`FontOptions` for the :class:`Context`.
2914
2915 Retrieves font rendering options set via
2916 :meth:`Context.set_font_options`. Note that the returned options do not
2917 include any options derived from the underlying surface; they are
2918 literally the options passed to :meth:`Context.set_font_options`.
2919 """
2920
2921 def get_group_target(self) -> Surface:
2922 """
2923 :returns: the target :class:`Surface`.
2924
2925 Gets the current destination :class:`Surface` for the
2926 :class:`Context`. This is either the original target surface as passed
2927 to :class:`Context` or the target surface for the current group as
2928 started by the most recent call to :meth:`Context.push_group` or
2929 :meth:`Context.push_group_with_content`.
2930
2931 .. versionadded:: 1.2
2932 """
2933
2934 def get_hairline(self) -> bool:
2935 """
2936 :returns: whether hairline mode is set.
2937
2938 Returns whether or not hairline mode is set, as set by
2939 :meth:`Context.set_hairline`.
2940
2941 .. versionadded:: 1.23 Only available with cairo 1.17.6+
2942 """
2943
2944 def get_line_cap(self) -> LineCap:
2945 """
2946 :returns: the current line cap style, as
2947 set by :meth:`Context.set_line_cap`.
2948 """
2949
2950 def get_line_join(self) -> LineJoin:
2951 """
2952 :returns: the current line join style, as
2953 set by :meth:`Context.set_line_join`.
2954 """
2955
2956 def get_line_width(self) -> float:
2957 """
2958 :returns: the current line width
2959
2960 This function returns the current line width value exactly as set by
2961 :meth:`Context.set_line_width`. Note that the value is unchanged even if
2962 the CTM has changed between the calls to :meth:`Context.set_line_width`
2963 and :meth:`.get_line_width`.
2964 """
2965
2966 def get_matrix(self) -> Matrix:
2967 """
2968 :returns: the current transformation :class:`Matrix` (CTM)
2969 """
2970
2971 def get_miter_limit(self) -> float:
2972 """
2973 :returns: the current miter limit, as set by
2974 :meth:`Context.set_miter_limit`.
2975 """
2976
2977 def get_operator(self) -> Operator:
2978 """
2979 :returns: the current compositing operator
2980 for a :class:`Context`.
2981 """
2982
2983 def get_scaled_font(self) -> ScaledFont:
2984 """
2985 :returns: the current :class:`ScaledFont` for a :class:`Context`.
2986
2987 .. versionadded:: 1.4
2988 """
2989
2990 def get_source(self) -> Pattern:
2991 """
2992 :returns: the current source :class:`Pattern` for a :class:`Context`.
2993 """
2994
2995 def get_target(self) -> _SomeSurface:
2996 """
2997 :returns: the target :class:`Surface` for the :class:`Context`
2998 """
2999
3000 def get_tolerance(self) -> float:
3001 """
3002 :returns: the current tolerance value, as set by
3003 :meth:`Context.set_tolerance`
3004 """
3005
3006 def glyph_extents(self, glyphs: Sequence[Glyph]) -> TextExtents:
3007 """
3008 :param glyphs: glyphs, a sequence of :class:`Glyph`
3009
3010 Gets the extents for an array of glyphs. The extents describe a
3011 user-space rectangle that encloses the "inked" portion of the glyphs,
3012 (as they would be drawn by :meth:`Context.show_glyphs`). Additionally,
3013 the x_advance and y_advance values indicate the amount by which the
3014 current point would be advanced by :meth:`Context.show_glyphs`.
3015
3016 Note that whitespace glyphs do not contribute to the size of the
3017 rectangle (extents.width and extents.height).
3018 """
3019
3020 def glyph_path(self, glyphs: Sequence[Glyph]) -> None:
3021 """
3022 :param glyphs: glyphs to show, a sequence of :class:`Glyph`
3023
3024 Adds closed paths for the glyphs to the current path. The generated path
3025 if filled, achieves an effect similar to that of
3026 :meth:`Context.show_glyphs`.
3027 """
3028
3029 def has_current_point(self) -> bool:
3030 """
3031 :returns: True iff a current point is defined on the current path.
3032 See :meth:`Context.get_current_point` for details on the current point.
3033
3034 .. versionadded:: 1.6
3035 """
3036
3037 def identity_matrix(self) -> None:
3038 """
3039 Resets the current transformation :class:`Matrix` (CTM) by setting it
3040 equal to the identity matrix. That is, the user-space and device-space
3041 axes will be aligned and one user-space unit will transform to one
3042 device-space unit.
3043 """
3044
3045 def in_clip(self, x: float, y: float) -> bool:
3046 """
3047 :param x: X coordinate of the point to test
3048 :param y: Y coordinate of the point to test
3049 :returns: :obj:`True` if the point is inside, or :obj:`False` if outside.
3050
3051 Tests whether the given point is inside the area that would be visible
3052 through the current clip, i.e. the area that would be filled by a
3053 :meth:`paint` operation.
3054
3055 See :meth:`clip`, and :meth:`clip_preserve`.
3056
3057 .. versionadded:: 1.12.0
3058 """
3059
3060 def in_fill(self, x: float, y: float) -> bool:
3061 """
3062 :param x: X coordinate of the point to test
3063 :param y: Y coordinate of the point to test
3064 :returns: True iff the point is inside the area that would be affected
3065 by a :meth:`Context.fill` operation given the current path and filling
3066 parameters. Surface dimensions and clipping are not taken into account.
3067
3068 See :meth:`Context.fill`, :meth:`Context.set_fill_rule` and
3069 :meth:`Context.fill_preserve`.
3070 """
3071
3072 def in_stroke(self, x: float, y: float) -> bool:
3073 """
3074 :param x: X coordinate of the point to test
3075 :param y: Y coordinate of the point to test
3076
3077 :returns: True iff the point is inside the area that would be affected
3078 by a :meth:`Context.stroke` operation given the current path and
3079 stroking parameters. Surface dimensions and clipping are not taken
3080 into account.
3081
3082 See :meth:`Context.stroke`, :meth:`Context.set_line_width`,
3083 :meth:`Context.set_line_join`, :meth:`Context.set_line_cap`,
3084 :meth:`Context.set_dash`, and :meth:`Context.stroke_preserve`.
3085 """
3086
3087 def line_to(self, x: float, y: float) -> None:
3088 """
3089 :param x: the X coordinate of the end of the new line
3090 :param y: the Y coordinate of the end of the new line
3091
3092 Adds a line to the path from the current point to position *(x, y)* in
3093 user-space coordinates. After this call the current point will be *(x,
3094 y)*.
3095
3096 If there is no current point before the call to :meth:`.line_to`
3097 this function will behave as ``ctx.move_to(x, y)``.
3098 """
3099
3100 def mask(self, pattern: Pattern) -> None:
3101 """
3102 :param pattern: a :class:`Pattern`
3103
3104 A drawing operator that paints the current source using the alpha
3105 channel of *pattern* as a mask. (Opaque areas of *pattern* are painted
3106 with the source, transparent areas are not painted.)
3107 """
3108
3109 def mask_surface(self, surface: Surface, x: float = 0.0, y: float = 0.0) -> None:
3110 """
3111 :param surface: a :class:`Surface`
3112 :param x: X coordinate at which to place the origin of *surface*
3113 :param y: Y coordinate at which to place the origin of *surface*
3114
3115 A drawing operator that paints the current source using the alpha
3116 channel of *surface* as a mask. (Opaque areas of *surface* are painted
3117 with the source, transparent areas are not painted.)
3118 """
3119
3120 def move_to(self, x: float, y: float) -> None:
3121 """
3122 :param x: the X coordinate of the new position
3123 :param y: the Y coordinate of the new position
3124
3125 Begin a new sub-path. After this call the current point will be *(x,
3126 y)*.
3127 """
3128
3129 def new_path(self) -> None:
3130 """
3131 Clears the current path. After this call there will be no path and no
3132 current point.
3133 """
3134
3135 def new_sub_path(self) -> None:
3136 """
3137 Begin a new sub-path. Note that the existing path is not affected. After
3138 this call there will be no current point.
3139
3140 In many cases, this call is not needed since new sub-paths are
3141 frequently started with :meth:`Context.move_to`.
3142
3143 A call to :meth:`.new_sub_path` is particularly useful when beginning a
3144 new sub-path with one of the :meth:`Context.arc` calls. This makes
3145 things easier as it is no longer necessary to manually compute the arc's
3146 initial coordinates for a call to :meth:`Context.move_to`.
3147
3148 .. versionadded:: 1.6
3149 """
3150
3151 def paint(self) -> None:
3152 """
3153 A drawing operator that paints the current source everywhere within the
3154 current clip region.
3155 """
3156
3157 def paint_with_alpha(self, alpha: float) -> None:
3158 """
3159 :param alpha: alpha value, between 0 (transparent) and 1 (opaque)
3160
3161 A drawing operator that paints the current source everywhere within the
3162 current clip region using a mask of constant alpha value *alpha*. The
3163 effect is similar to :meth:`Context.paint`, but the drawing is faded out
3164 using the alpha value.
3165 """
3166
3167 def path_extents(self) -> Tuple[float, float, float, float]:
3168 """
3169 :returns: (x1, y1, x2, y2), all float
3170
3171 * *x1*: left of the resulting extents
3172 * *y1*: top of the resulting extents
3173 * *x2*: right of the resulting extents
3174 * *y2*: bottom of the resulting extents
3175
3176 Computes a bounding box in user-space coordinates covering the points on
3177 the current path. If the current path is empty, returns an empty
3178 rectangle (0, 0, 0, 0). Stroke parameters, fill rule, surface
3179 dimensions and clipping are not taken into account.
3180
3181 Contrast with :meth:`Context.fill_extents` and
3182 :meth:`Context.stroke_extents` which return the extents of only the area
3183 that would be "inked" by the corresponding drawing operations.
3184
3185 The result of :meth:`.path_extents` is defined as equivalent to the
3186 limit of :meth:`Context.stroke_extents` with cairo.LINE_CAP_ROUND as the
3187 line width approaches 0.0, (but never reaching the empty-rectangle
3188 returned by :meth:`Context.stroke_extents` for a line width of 0.0).
3189
3190 Specifically, this means that zero-area sub-paths such as
3191 :meth:`Context.move_to`; :meth:`Context.line_to` segments, (even
3192 degenerate cases where the coordinates to both calls are identical),
3193 will be considered as contributing to the extents. However, a lone
3194 :meth:`Context.move_to` will not contribute to the results of
3195 :meth:`Context.path_extents`.
3196
3197 .. versionadded:: 1.6
3198 """
3199
3200 def pop_group(self) -> SurfacePattern:
3201 """
3202 :returns: a newly created :class:`SurfacePattern` containing the results
3203 of all drawing operations performed to the group.
3204
3205 Terminates the redirection begun by a call to :meth:`Context.push_group`
3206 or :meth:`Context.push_group_with_content` and returns a new pattern
3207 containing the results of all drawing operations performed to the group.
3208
3209 The :meth:`.pop_group` function calls :meth:`Context.restore`,
3210 (balancing a call to :meth:`Context.save` by the
3211 :meth:`Context.push_group` function), so that any changes to the graphics
3212 state will not be visible outside the group.
3213
3214 .. versionadded:: 1.2
3215 """
3216
3217 def pop_group_to_source(self) -> None:
3218 """
3219 Terminates the redirection begun by a call to :meth:`Context.push_group`
3220 or :meth:`Context.push_group_with_content` and installs the resulting
3221 pattern as the source :class:`Pattern` in the given :class:`Context`.
3222
3223 The behavior of this function is equivalent to the sequence of
3224 operations::
3225
3226 group = cairo_pop_group()
3227 ctx.set_source(group)
3228
3229 but is more convenient as their is no need for a variable to store
3230 the short-lived pointer to the pattern.
3231
3232 The :meth:`Context.pop_group` function calls :meth:`Context.restore`,
3233 (balancing a call to :meth:`Context.save` by the
3234 :meth:`Context.push_group` function), so that any changes to the graphics
3235 state will not be visible outside the group.
3236
3237 .. versionadded:: 1.2
3238 """
3239
3240 def push_group(self) -> None:
3241 """
3242 Temporarily redirects drawing to an intermediate surface known as a
3243 group. The redirection lasts until the group is completed by a call to
3244 :meth:`Context.pop_group` or :meth:`Context.pop_group_to_source`. These
3245 calls provide the result of any drawing to the group as a pattern,
3246 (either as an explicit object, or set as the source pattern).
3247
3248 This group functionality can be convenient for performing intermediate
3249 compositing. One common use of a group is to render objects as opaque
3250 within the group, (so that they occlude each other), and then blend the
3251 result with translucence onto the destination.
3252
3253 Groups can be nested arbitrarily deep by making balanced calls to
3254 :meth:`Context.push_group`/:meth:`Context.pop_group`. Each call
3255 pushes/pops the new target group onto/from a stack.
3256
3257 The :meth:`.push_group` function calls :meth:`Context.save` so that any
3258 changes to the graphics state will not be visible outside the group,
3259 (the pop_group functions call :meth:`Context.restore`).
3260
3261 By default the intermediate group will have a :class:`cairo.Content`
3262 type of :attr:`cairo.Content.COLOR_ALPHA`. Other content types can be
3263 chosen for the group by using :meth:`Context.push_group_with_content`
3264 instead.
3265
3266 As an example, here is how one might fill and stroke a path with
3267 translucence, but without any portion of the fill being visible
3268 under the stroke::
3269
3270 ctx.push_group()
3271 ctx.set_source(fill_pattern)
3272 ctx.fill_preserve()
3273 ctx.set_source(stroke_pattern)
3274 ctx.stroke()
3275 ctx.pop_group_to_source()
3276 ctx.paint_with_alpha(alpha)
3277
3278 .. versionadded:: 1.2
3279 """
3280
3281 def push_group_with_content(self, content: Content) -> None:
3282 """
3283 :param cairo.Content content: a content indicating the
3284 type of group that will be created
3285
3286 Temporarily redirects drawing to an intermediate surface known as a
3287 group. The redirection lasts until the group is completed by a call to
3288 :meth:`Context.pop_group` or :meth:`Context.pop_group_to_source`. These
3289 calls provide the result of any drawing to the group as a pattern,
3290 (either as an explicit object, or set as the source pattern).
3291
3292 The group will have a content type of *content*. The ability to control
3293 this content type is the only distinction between this function and
3294 :meth:`Context.push_group` which you should see for a more detailed
3295 description of group rendering.
3296
3297 .. versionadded:: 1.2
3298 """
3299
3300 def rectangle(self, x: float, y: float, width: float, height: float) -> None:
3301 """
3302 :param x: the X coordinate of the top left corner of the rectangle
3303 :param y: the Y coordinate to the top left corner of the rectangle
3304 :param width: the width of the rectangle
3305 :param height: the height of the rectangle
3306
3307 Adds a closed sub-path rectangle of the given size to the current path
3308 at position *(x, y)* in user-space coordinates.
3309
3310 This function is logically equivalent to::
3311
3312 ctx.move_to(x, y)
3313 ctx.rel_line_to(width, 0)
3314 ctx.rel_line_to(0, height)
3315 ctx.rel_line_to(-width, 0)
3316 ctx.close_path()
3317 """
3318
3319 def rel_curve_to(self, dx1: float, dy1: float, dx2: float, dy2: float, dx3: float, dy3: float) -> None:
3320 """
3321 :param dx1: the X offset to the first control point
3322 :param dy1: the Y offset to the first control point
3323 :param dx2: the X offset to the second control point
3324 :param dy2: the Y offset to the second control point
3325 :param dx3: the X offset to the end of the curve
3326 :param dy3: the Y offset to the end of the curve
3327 :raises: :exc:`cairo.Error` if called with no current point.
3328
3329 Relative-coordinate version of :meth:`Context.curve_to`. All
3330 offsets are relative to the current point. Adds a cubic Bézier spline to
3331 the path from the current point to a point offset from the current point
3332 by *(dx3, dy3)*, using points offset by *(dx1, dy1)* and *(dx2, dy2)* as
3333 the control points. After this call the current point will be offset by
3334 *(dx3, dy3)*.
3335
3336 Given a current point of (x, y), ``ctx.rel_curve_to(dx1, dy1, dx2, dy2,
3337 dx3, dy3)`` is logically equivalent to ``ctx.curve_to(x+dx1, y+dy1,
3338 x+dx2, y+dy2, x+dx3, y+dy3)``.
3339 """
3340
3341 def rel_line_to(self, dx: float, dy: float) -> None:
3342 """
3343 :param dx: the X offset to the end of the new line
3344 :param dy: the Y offset to the end of the new line
3345 :raises: :exc:`cairo.Error` if called with no current point.
3346
3347 Relative-coordinate version of :meth:`Context.line_to`. Adds a line to
3348 the path from the current point to a point that is offset from the
3349 current point by *(dx, dy)* in user space. After this call the current
3350 point will be offset by *(dx, dy)*.
3351
3352 Given a current point of (x, y), ``ctx.rel_line_to(dx, dy)`` is logically
3353 equivalent to ``ctx.line_to(x + dx, y + dy)``.
3354 """
3355
3356 def rel_move_to(self, dx: float, dy: float) -> None:
3357 """
3358 :param dx: the X offset
3359 :param dy: the Y offset
3360 :raises: :exc:`cairo.Error` if called with no current point.
3361
3362 Begin a new sub-path. After this call the current point will offset by
3363 *(dx, dy)*.
3364
3365 Given a current point of (x, y), ``ctx.rel_move_to(dx, dy)`` is logically
3366 equivalent to ``ctx.(x + dx, y + dy)``.
3367 """
3368
3369 def reset_clip(self) -> None:
3370 """
3371 Reset the current clip region to its original, unrestricted state. That
3372 is, set the clip region to an infinitely large shape containing the
3373 target surface. Equivalently, if infinity is too hard to grasp, one can
3374 imagine the clip region being reset to the exact bounds of the target
3375 surface.
3376
3377 Note that code meant to be reusable should not call :meth:`.reset_clip`
3378 as it will cause results unexpected by higher-level code which calls
3379 :meth:`.clip`. Consider using :meth:`.save` and :meth:`.restore` around
3380 :meth:`.clip` as a more robust means of temporarily restricting the clip
3381 region.
3382 """
3383
3384 def restore(self) -> None:
3385 """
3386 Restores :class:`Context` to the state saved by a preceding call to
3387 :meth:`.save` and removes that state from the stack of saved states.
3388 """
3389
3390 def rotate(self, angle: float) -> None:
3391 """
3392 :param angle: angle (in radians) by which the user-space axes will be
3393 rotated
3394
3395 Modifies the current transformation matrix (CTM) by rotating the
3396 user-space axes by *angle* radians. The rotation of the axes takes places
3397 after any existing transformation of user space. The rotation direction
3398 for positive angles is from the positive X axis toward the positive Y
3399 axis.
3400 """
3401
3402 def save(self) -> None:
3403 """
3404 Makes a copy of the current state of :class:`Context` and saves it on an
3405 internal stack of saved states. When :meth:`.restore` is called,
3406 :class:`Context` will be restored to the saved state. Multiple calls to
3407 :meth:`.save` and :meth:`.restore` can be nested; each call to
3408 :meth:`.restore` restores the state from the matching paired
3409 :meth:`.save`.
3410 """
3411
3412 def scale(self, sx: float, sy: float) -> None:
3413 """
3414 :param sx: scale factor for the X dimension
3415 :param sy: scale factor for the Y dimension
3416
3417 Modifies the current transformation matrix (CTM) by scaling the X and Y
3418 user-space axes by *sx* and *sy* respectively. The scaling of the axes
3419 takes place after any existing transformation of user space.
3420 """
3421
3422 def select_font_face(self, family: str, slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL) -> None:
3423 """
3424 :param family: a font family name
3425 :param slant: the font slant of the font,
3426 defaults to :attr:`cairo.FontSlant.NORMAL`.
3427 :param weight: the font weight of the
3428 font, defaults to :attr:`cairo.FontWeight.NORMAL`.
3429
3430 Note: The :meth:`.select_font_face` function call is part of what the
3431 cairo designers call the "toy" text API. It is convenient for short
3432 demos and simple programs, but it is not expected to be adequate for
3433 serious text-using applications.
3434
3435 Selects a family and style of font from a simplified description as a
3436 family name, slant and weight. Cairo provides no operation to list
3437 available family names on the system (this is a "toy", remember), but
3438 the standard CSS2 generic family names, ("serif", "sans-serif",
3439 "cursive", "fantasy", "monospace"), are likely to work as expected.
3440
3441 For "real" font selection, see the font-backend-specific
3442 font_face_create functions for the font backend you are using. (For
3443 example, if you are using the freetype-based cairo-ft font backend, see
3444 cairo_ft_font_face_create_for_ft_face() or
3445 cairo_ft_font_face_create_for_pattern().) The resulting font face could
3446 then be used with cairo_scaled_font_create() and
3447 cairo_set_scaled_font().
3448
3449 Similarly, when using the "real" font support, you can call directly
3450 into the underlying font system, (such as fontconfig or freetype), for
3451 operations such as listing available fonts, etc.
3452
3453 It is expected that most applications will need to use a more
3454 comprehensive font handling and text layout library, (for example,
3455 pango), in conjunction with cairo.
3456
3457 If text is drawn without a call to :meth:`.select_font_face`, (nor
3458 :meth:`.set_font_face` nor :meth:`.set_scaled_font`), the default family
3459 is platform-specific, but is essentially "sans-serif". Default slant is
3460 :attr:`cairo.FontSlant.NORMAL`, and default weight is
3461 :attr:`cairo.FontWeight.NORMAL`.
3462
3463 This function is equivalent to a call to :class:`ToyFontFace`
3464 followed by :meth:`.set_font_face`.
3465 """
3466
3467 def set_antialias(self, antialias: Antialias) -> None:
3468 """
3469 :param antialias: the new antialias mode
3470
3471 Set the antialiasing mode of the rasterizer used for drawing shapes.
3472 This value is a hint, and a particular backend may or may not support a
3473 particular value. At the current time, no backend supports
3474 :attr:`cairo.Antialias.SUBPIXEL` when drawing shapes.
3475
3476 Note that this option does not affect text rendering, instead see
3477 :meth:`FontOptions.set_antialias`.
3478 """
3479
3480 def set_dash(self, dashes: Sequence[float], offset: float = 0) -> None:
3481 """
3482 :param dashes: a sequence specifying alternate lengths of on and off
3483 stroke portions as float.
3484 :param offset: an offset into the dash pattern at which the stroke
3485 should start, defaults to 0.
3486 :raises: :exc:`cairo.Error` if any value in *dashes* is negative, or if
3487 all values are 0.
3488
3489 Sets the dash pattern to be used by :meth:`.stroke`. A dash pattern is
3490 specified by *dashes* - a sequence of positive values. Each value
3491 provides the length of alternate "on" and "off" portions of the
3492 stroke. The *offset* specifies an offset into the pattern at which the
3493 stroke begins.
3494
3495 Each "on" segment will have caps applied as if the segment were a
3496 separate sub-path. In particular, it is valid to use an "on" length of
3497 0.0 with :attr:`cairo.LineCap.ROUND` or :attr:`cairo.LineCap.SQUARE`
3498 in order to distributed dots or squares along a path.
3499
3500 Note: The length values are in user-space units as evaluated at the time
3501 of stroking. This is not necessarily the same as the user space at the
3502 time of :meth:`.set_dash`.
3503
3504 If the number of dashes is 0 dashing is disabled.
3505
3506 If the number of dashes is 1 a symmetric pattern is assumed with
3507 alternating on and off portions of the size specified by the single
3508 value in *dashes*.
3509 """
3510
3511 def set_fill_rule(self, fill_rule: FillRule) -> None:
3512 """
3513 :param fill_rule: a fill rule to set the
3514 within the cairo context. The fill rule is used to determine which
3515 regions are inside or outside a complex (potentially
3516 self-intersecting) path. The current fill rule affects both
3517 :meth:`.fill` and :meth:`.clip`.
3518
3519 The default fill rule is :attr:`cairo.FillRule.WINDING`.
3520 """
3521
3522 def set_font_face(self, font_face: Optional[FontFace]) -> None:
3523 """
3524 :param font_face: a :class:`FontFace`, or None to restore to the
3525 default :class:`FontFace`
3526
3527 Replaces the current :class:`FontFace` object in the :class:`Context`
3528 with *font_face*.
3529 """
3530
3531 def set_font_matrix(self, matrix: Matrix) -> None:
3532 """
3533 :param matrix: a :class:`Matrix` describing a transform to be applied to
3534 the current font.
3535
3536 Sets the current font matrix to *matrix*. The font matrix gives a
3537 transformation from the design space of the font (in this space, the
3538 em-square is 1 unit by 1 unit) to user space. Normally, a simple scale
3539 is used (see :meth:`.set_font_size`), but a more complex font matrix can
3540 be used to shear the font or stretch it unequally along the two axes
3541 """
3542
3543 def set_font_options(self, options: FontOptions) -> None:
3544 """
3545 :param options: :class:`FontOptions` to use
3546
3547 Sets a set of custom font rendering options for the :class:`Context`.
3548 Rendering options are derived by merging these options with the options
3549 derived from underlying surface; if the value in *options* has a default
3550 value (like :attr:`cairo.Antialias.DEFAULT`), then the value from the
3551 surface is used.
3552 """
3553
3554 def set_font_size(self, size: float) -> None:
3555 """
3556 :param size: the new font size, in user space units
3557
3558 Sets the current font matrix to a scale by a factor of *size*, replacing
3559 any font matrix previously set with :meth:`.set_font_size` or
3560 :meth:`.set_font_matrix`. This results in a font size of *size* user
3561 space units. (More precisely, this matrix will result in the font's
3562 em-square being a *size* by *size* square in user space.)
3563
3564 If text is drawn without a call to :meth:`.set_font_size`, (nor
3565 :meth:`.set_font_matrix` nor :meth:`.set_scaled_font`), the default font
3566 size is 10.0.
3567 """
3568
3569 def set_hairline(self, set_hairline: bool) -> None:
3570 """
3571 :param set_hairline: whether or not to set hairline mode
3572
3573 Sets lines within the cairo context to be hairlines. Hairlines are
3574 logically zero-width lines that are drawn at the thinnest renderable
3575 width possible in the current context. On surfaces with native hairline
3576 support, the native hairline functionality will be used. Surfaces that
3577 support hairlines include:
3578
3579 - pdf/ps: Encoded as 0-width line.
3580 - win32_printing: Rendered with PS_COSMETIC pen.
3581 - svg: Encoded as 1px non-scaling-stroke.
3582 - script: Encoded with set-hairline function.
3583
3584 Cairo will always render hairlines at 1 device unit wide, even if an
3585 anisotropic scaling was applied to the stroke width. In the wild,
3586 handling of this situation is not well-defined. Some PDF, PS, and SVG
3587 renderers match Cairo's output, but some very popular implementations
3588 (Acrobat, Chrome, rsvg) will scale the hairline unevenly. As such, best
3589 practice is to reset any anisotropic scaling before calling
3590 :meth:`.stroke`. See https://cairographics.org/cookbook/ellipses/ for an
3591 example.
3592
3593 .. versionadded:: 1.23 Only available with cairo 1.17.6+
3594 """
3595
3596 def set_line_cap(self, line_cap: LineCap) -> None:
3597 """
3598 :param line_cap: a line cap style
3599
3600 Sets the current line cap style within the :class:`Context`.
3601
3602 As with the other stroke parameters, the current line cap style is
3603 examined by :meth:`.stroke` and :meth:`.stroke_extents`, but does not
3604 have any effect during path construction.
3605
3606 The default line cap style is :attr:`cairo.LineCap.BUTT`.
3607 """
3608
3609 def set_line_join(self, line_join: LineJoin) -> None:
3610 """
3611 :param line_join: a line join style
3612
3613 Sets the current line join style within the :class:`Context`.
3614
3615 As with the other stroke parameters, the current line join style is
3616 examined by :meth:`.stroke` and :meth:`.stroke_extents`, but does not
3617 have any effect during path construction.
3618
3619 The default line join style is :attr:`cairo.LineJoin.MITER`.
3620 """
3621
3622 def set_line_width(self, width: float) -> None:
3623 """
3624 :param width: a line width
3625
3626 Sets the current line width within the :class:`Context`. The line width
3627 value specifies the diameter of a pen that is circular in user space,
3628 (though device-space pen may be an ellipse in general due to
3629 scaling/shear/rotation of the CTM).
3630
3631 Note: When the description above refers to user space and CTM it refers
3632 to the user space and CTM in effect at the time of the stroking
3633 operation, not the user space and CTM in effect at the time of the call
3634 to :meth:`.set_line_width`. The simplest usage makes both of these
3635 spaces identical. That is, if there is no change to the CTM between a
3636 call to :meth:`.set_line_width` and the stroking operation, then one can
3637 just pass user-space values to :meth:`.set_line_width` and ignore this
3638 note.
3639
3640 As with the other stroke parameters, the current line width is examined
3641 by :meth:`.stroke` and :meth:`.stroke_extents`, but does not have any
3642 effect during path construction.
3643
3644 The default line width value is 2.0.
3645 """
3646
3647 def set_matrix(self, matrix: Matrix) -> None:
3648 """
3649 :param matrix: a transformation :class:`Matrix` from user space to
3650 device space.
3651
3652 Modifies the current transformation matrix (CTM) by setting it equal to
3653 *matrix*.
3654 """
3655
3656 def set_miter_limit(self, limit: float) -> None:
3657 """
3658 :param limit: miter limit to set
3659
3660 Sets the current miter limit within the :class:`Context`.
3661
3662 If the current line join style is set to :attr:`cairo.LineJoin.MITER`
3663 (see :meth:`.set_line_join`), the miter limit is used to determine
3664 whether the lines should be joined with a bevel instead of a miter.
3665 Cairo divides the length of the miter by the line width. If the result
3666 is greater than the miter limit, the style is converted to a bevel.
3667
3668 As with the other stroke parameters, the current line miter limit is
3669 examined by :meth:`.stroke` and :meth:`.stroke_extents`, but does not
3670 have any effect during path construction.
3671
3672 The default miter limit value is 10.0, which will convert joins with
3673 interior angles less than 11 degrees to bevels instead of miters. For
3674 reference, a miter limit of 2.0 makes the miter cutoff at 60 degrees,
3675 and a miter limit of 1.414 makes the cutoff at 90 degrees.
3676
3677 A miter limit for a desired angle can be computed as::
3678
3679 miter limit = 1/math.sin(angle/2)
3680 """
3681
3682 def set_operator(self, op: Operator) -> None:
3683 """
3684 :param op: the compositing operator to set
3685 for use in all drawing operations.
3686
3687 The default operator is :attr:`cairo.Operator.OVER`.
3688 """
3689
3690 def set_scaled_font(self, scaled_font: ScaledFont) -> None:
3691 """
3692 :param scaled_font: a :class:`ScaledFont`
3693
3694 Replaces the current font face, font matrix, and font options in the
3695 :class:`Context` with those of the :class:`ScaledFont`. Except for some
3696 translation, the current CTM of the :class:`Context` should be the same
3697 as that of the :class:`ScaledFont`, which can be accessed using
3698 :meth:`ScaledFont.get_ctm`.
3699
3700 .. versionadded:: 1.2
3701 """
3702
3703 def set_source(self, source: Pattern) -> None:
3704 """
3705 :param source: a :class:`Pattern` to be used as the source for
3706 subsequent drawing operations.
3707
3708 Sets the source pattern within :class:`Context` to *source*. This
3709 pattern will then be used for any subsequent drawing operation until a
3710 new source pattern is set.
3711
3712 Note: The pattern's transformation matrix will be locked to the user
3713 space in effect at the time of :meth:`.set_source`. This means that
3714 further modifications of the current transformation matrix will not
3715 affect the source pattern. See :meth:`Pattern.set_matrix`.
3716
3717 The default source pattern is a solid pattern that is opaque black,
3718 (that is, it is equivalent to ``set_source_rgb(0.0, 0.0, 0.0)``.
3719 """
3720
3721 def set_source_rgb(self, red: float, green: float, blue: float) -> None:
3722 """
3723 :param red: red component of color
3724 :param green: green component of color
3725 :param blue: blue component of color
3726
3727 Sets the source pattern within :class:`Context` to an opaque color. This
3728 opaque color will then be used for any subsequent drawing operation
3729 until a new source pattern is set.
3730
3731 The color components are floating point numbers in the range 0 to
3732 1. If the values passed in are outside that range, they will be
3733 clamped.
3734
3735 The default source pattern is opaque black, (that is, it is
3736 equivalent to ``set_source_rgb(0.0, 0.0, 0.0)``.
3737 """
3738
3739 def set_source_rgba(self, red: float, green: float, blue: float, alpha: float = 1.0) -> None:
3740 """
3741 :param red: red component of color
3742 :param green: green component of color
3743 :param blue: blue component of color
3744 :param alpha: alpha component of color
3745
3746 Sets the source pattern within :class:`Context` to a translucent
3747 color. This color will then be used for any subsequent drawing operation
3748 until a new source pattern is set.
3749
3750 The color and alpha components are floating point numbers in the range 0
3751 to 1. If the values passed in are outside that range, they will be
3752 clamped.
3753
3754 The default source pattern is opaque black, (that is, it is
3755 equivalent to ``set_source_rgba(0.0, 0.0, 0.0, 1.0)``.
3756 """
3757
3758 def set_source_surface(self, surface: Surface, x: float = 0.0, y: float = 0.0) -> None:
3759 """
3760 :param surface: a :class:`Surface` to be used to set the source pattern
3761 :param x: User-space X coordinate for surface origin
3762 :param y: User-space Y coordinate for surface origin
3763
3764 This is a convenience function for creating a pattern from a
3765 :class:`Surface` and setting it as the source in :class:`Context` with
3766 :meth:`.set_source`.
3767
3768 The *x* and *y* parameters give the user-space coordinate at which the
3769 surface origin should appear. (The surface origin is its upper-left
3770 corner before any transformation has been applied.) The *x* and *y*
3771 patterns are negated and then set as translation values in the pattern
3772 matrix.
3773
3774 Other than the initial translation pattern matrix, as described above,
3775 all other pattern attributes, (such as its extend mode), are set to the
3776 default values as in :class:`SurfacePattern`. The resulting pattern can
3777 be queried with :meth:`.get_source` so that these attributes can be
3778 modified if desired, (eg. to create a repeating pattern with
3779 :meth:`.Pattern.set_extend`).
3780 """
3781
3782 def set_tolerance(self, tolerance: float) -> None:
3783 """
3784 :param tolerance: the tolerance, in device units (typically pixels)
3785
3786 Sets the tolerance used when converting paths into trapezoids. Curved
3787 segments of the path will be subdivided until the maximum deviation
3788 between the original path and the polygonal approximation is less than
3789 *tolerance*. The default value is 0.1. A larger value will give better
3790 performance, a smaller value, better appearance. (Reducing the value
3791 from the default value of 0.1 is unlikely to improve appearance
3792 significantly.) The accuracy of paths within Cairo is limited by the
3793 precision of its internal arithmetic, and the prescribed *tolerance* is
3794 restricted to the smallest representable internal value.
3795 """
3796
3797 def show_glyphs(self, glyphs: Sequence[Glyph]) -> None:
3798 """
3799 :param glyphs: glyphs to show as a sequence of :class:`Glyph`
3800
3801 A drawing operator that generates the shape from an array of glyphs,
3802 rendered according to the current font face, font size (font matrix),
3803 and font options.
3804 """
3805
3806 def show_page(self) -> None:
3807 """
3808 Emits and clears the current page for backends that support multiple
3809 pages. Use :meth:`.copy_page` if you don't want to clear the page.
3810
3811 This is a convenience function that simply calls
3812 ``ctx.get_target() . show_page()``
3813 """
3814
3815 def show_text(self, text: str) -> None:
3816 """
3817 :param text: text
3818
3819 A drawing operator that generates the shape from a string of text,
3820 rendered according to the current font_face, font_size (font_matrix),
3821 and font_options.
3822
3823 This function first computes a set of glyphs for the string of text. The
3824 first glyph is placed so that its origin is at the current point. The
3825 origin of each subsequent glyph is offset from that of the previous
3826 glyph by the advance values of the previous glyph.
3827
3828 After this call the current point is moved to the origin of where the
3829 next glyph would be placed in this same progression. That is, the
3830 current point will be at the origin of the final glyph offset by its
3831 advance values. This allows for easy display of a single logical string
3832 with multiple calls to :meth:`.show_text`.
3833
3834 Note: The :meth:`.show_text` function call is part of what the cairo
3835 designers call the "toy" text API. It is convenient for short demos
3836 and simple programs, but it is not expected to be adequate for
3837 serious text-using applications. See :meth:`.show_glyphs` for the
3838 "real" text display API in cairo.
3839 """
3840
3841 def show_text_glyphs(self, utf8: str, glyphs: List["Glyph"], clusters: List[TextCluster], cluster_flags: TextClusterFlags) -> None:
3842 """
3843 :param utf8: a string of text
3844 :param glyphs: list of glyphs to show
3845 :param clusters: list of cluster mapping information
3846 :param cluster_flags: cluster mapping flags
3847 :raises Error:
3848
3849 .. versionadded:: 1.15
3850
3851 This operation has rendering effects similar to
3852 :meth:`Context.show_glyphs` but, if the target surface supports it, uses
3853 the provided text and cluster mapping to embed the text for the glyphs
3854 shown in the output. If the target does not support the extended
3855 attributes, this function acts like the basic
3856 :meth:`Context.show_glyphs` as if it had been passed ``glyphs`` .
3857
3858 The mapping between utf8 and glyphs is provided by a list of clusters.
3859 Each cluster covers a number of text bytes and glyphs, and neighboring
3860 clusters cover neighboring areas of utf8 and glyphs . The clusters
3861 should collectively cover utf8 and glyphs in entirety.
3862
3863 The first cluster always covers bytes from the beginning of utf8 . If
3864 ``cluster_flags`` do not have the :attr:`TextClusterFlags.BACKWARD` set,
3865 the first cluster also covers the beginning of glyphs , otherwise it
3866 covers the end of the glyphs array and following clusters move backward.
3867
3868 See :class:`TextCluster` for constraints on valid clusters.
3869 """
3870
3871 def stroke(self) -> None:
3872 """
3873 A drawing operator that strokes the current path according to the
3874 current line width, line join, line cap, and dash settings. After
3875 :meth:`.stroke`, the current path will be cleared from the cairo
3876 context. See :meth:`.set_line_width`, :meth:`.set_line_join`,
3877 :meth:`.set_line_cap`, :meth:`.set_dash`, and :meth:`.stroke_preserve`.
3878
3879 Note: Degenerate segments and sub-paths are treated specially and
3880 provide a useful result. These can result in two different situations:
3881
3882 1. Zero-length "on" segments set in :meth:`.set_dash`. If the cap
3883 style is :attr:`cairo.LineCap.ROUND` or :attr:`cairo.LineCap.SQUARE`
3884 then these segments will be drawn as circular dots or squares
3885 respectively. In the case of :attr:`cairo.LineCap.SQUARE`, the
3886 orientation of the squares is determined by the direction of the
3887 underlying path.
3888
3889 2. A sub-path created by :meth:`.move_to` followed by either a
3890 :meth:`.close_path` or one or more calls to :meth:`.line_to` to the same
3891 coordinate as the :meth:`.move_to`. If the cap style is
3892 :attr:`cairo.LineCap.ROUND` then these sub-paths will be drawn as
3893 circular dots. Note that in the case of :attr:`cairo.LineCap.SQUARE` a
3894 degenerate sub-path will not be drawn at all, (since the correct
3895 orientation is indeterminate).
3896
3897 In no case will a cap style of :attr:`cairo.LineCap.BUTT` cause anything
3898 to be drawn in the case of either degenerate segments or sub-paths.
3899 """
3900
3901 def stroke_extents(self) -> Tuple[float, float, float, float]:
3902 """
3903 :returns: (x1, y1, x2, y2), all float
3904
3905 * *x1*: left of the resulting extents
3906 * *y1*: top of the resulting extents
3907 * *x2*: right of the resulting extents
3908 * *y2*: bottom of the resulting extents
3909
3910 Computes a bounding box in user coordinates covering the area that would
3911 be affected, (the "inked" area), by a :meth:`.stroke` operation given
3912 the current path and stroke parameters. If the current path is empty,
3913 returns an empty rectangle (0, 0, 0, 0). Surface dimensions and
3914 clipping are not taken into account.
3915
3916 Note that if the line width is set to exactly zero, then
3917 :meth:`.stroke_extents` will return an empty rectangle. Contrast with
3918 :meth:`.path_extents` which can be used to compute the non-empty bounds
3919 as the line width approaches zero.
3920
3921 Note that :meth:`.stroke_extents` must necessarily do more work to
3922 compute the precise inked areas in light of the stroke parameters, so
3923 :meth:`.path_extents` may be more desirable for sake of performance if
3924 non-inked path extents are desired.
3925
3926 See :meth:`.stroke`, :meth:`.set_line_width`, :meth:`.set_line_join`,
3927 :meth:`.set_line_cap`, :meth:`.set_dash`, and :meth:`.stroke_preserve`.
3928 """
3929
3930 def stroke_preserve(self) -> None:
3931 """
3932 A drawing operator that strokes the current path according to the
3933 current line width, line join, line cap, and dash settings. Unlike
3934 :meth:`.stroke`, :meth:`.stroke_preserve` preserves the path within the
3935 cairo context.
3936
3937 See :meth:`.set_line_width`, :meth:`.set_line_join`,
3938 :meth:`.set_line_cap`, :meth:`.set_dash`, and :meth:`.stroke_preserve`.
3939 """
3940
3941 def tag_begin(self, tag_name: str, attributes: str) -> None:
3942 """
3943 :param tag_name: tag name
3944 :param attributes: tag attributes
3945
3946 Marks the beginning of the tag_name structure. Call :meth:`tag_end`
3947 with the same tag_name to mark the end of the structure.
3948
3949 The attributes string is of the form "key1=value2 key2=value2 ...".
3950 Values may be boolean (true/false or 1/0), integer, float, string, or
3951 an array.
3952
3953 String values are enclosed in single quotes ('). Single quotes and
3954 backslashes inside the string should be escaped with a backslash.
3955
3956 Boolean values may be set to true by only specifying the key. eg the
3957 attribute string "key" is the equivalent to "key=true".
3958
3959 Arrays are enclosed in '[]'. eg "rect=[1.2 4.3 2.0 3.0]".
3960
3961 If no attributes are required, attributes can be an empty string.
3962
3963 See `Tags and Links Description
3964 <https://www.cairographics.org/manual/cairo-Tags-and-Links.html#cairo-Tags-and-Links.description>`__
3965 for the list of tags and attributes.
3966
3967 Invalid nesting of tags or invalid attributes will cause the context
3968 to shutdown with a status of :attr:`Status.TAG_ERROR`.
3969
3970 See :meth:`tag_end`.
3971
3972 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
3973 """
3974
3975 def tag_end(self, tag_name: str) -> None:
3976 """
3977 :param tag_name: tag name
3978
3979 Marks the end of the tag_name structure.
3980
3981 Invalid nesting of tags will cause the context to shutdown with a
3982 status of :attr:`Status.TAG_ERROR`.
3983
3984 See :meth:`tag_begin`.
3985
3986 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
3987 """
3988
3989 def text_extents(self, text: str) -> TextExtents:
3990 """
3991 :param text: text to get extents for
3992
3993 Gets the extents for a string of text. The extents describe a user-space
3994 rectangle that encloses the "inked" portion of the text, (as it would be
3995 drawn by :meth:`Context.show_text`). Additionally, the x_advance and
3996 y_advance values indicate the amount by which the current point would be
3997 advanced by :meth:`Context.show_text`.
3998
3999 Note that whitespace characters do not directly contribute to the size
4000 of the rectangle (extents.width and extents.height). They do contribute
4001 indirectly by changing the position of non-whitespace characters. In
4002 particular, trailing whitespace characters are likely to not affect the
4003 size of the rectangle, though they will affect the x_advance and
4004 y_advance values.
4005 """
4006
4007 def text_path(self, text: str) -> None:
4008 """
4009 :param text: text
4010
4011 Adds closed paths for text to the current path. The generated path if
4012 filled, achieves an effect similar to that of :meth:`Context.show_text`.
4013
4014 Text conversion and positioning is done similar to
4015 :meth:`Context.show_text`.
4016
4017 Like :meth:`Context.show_text`, After this call the current point is
4018 moved to the origin of where the next glyph would be placed in this same
4019 progression. That is, the current point will be at the origin of the
4020 final glyph offset by its advance values. This allows for chaining
4021 multiple calls to to :meth:`Context.text_path` without having to set
4022 current point in between.
4023
4024 Note: The :meth:`.text_path` function call is part of what the cairo
4025 designers call the "toy" text API. It is convenient for short demos and
4026 simple programs, but it is not expected to be adequate for serious
4027 text-using applications. See :meth:`Context.glyph_path` for the "real"
4028 text path API in cairo.
4029 """
4030
4031 def transform(self, matrix: Matrix) -> None:
4032 """
4033 :param matrix: a transformation :class:`Matrix` to be applied to the
4034 user-space axes
4035
4036 Modifies the current transformation matrix (CTM) by applying *matrix* as
4037 an additional transformation. The new transformation of user space takes
4038 place after any existing transformation.
4039 """
4040
4041 def translate(self, tx: float, ty: float) -> None:
4042 """
4043 :param tx: amount to translate in the X direction
4044 :param ty: amount to translate in the Y direction
4045
4046 Modifies the current transformation matrix (CTM) by translating the
4047 user-space origin by *(tx, ty)*. This offset is interpreted as a
4048 user-space coordinate according to the CTM in place before the new call
4049 to :meth:`.translate`. In other words, the translation of the user-space
4050 origin takes place after any existing transformation.
4051 """
4052
4053 def user_to_device(self, x: float, y: float) -> Tuple[float, float]:
4054 """
4055 :param x: X value of coordinate
4056 :param y: Y value of coordinate
4057 :returns: (x, y), both float
4058
4059 * *x*: X value of coordinate
4060 * *y*: Y value of coordinate
4061
4062 Transform a coordinate from user space to device space by multiplying
4063 the given point by the current transformation matrix (CTM).
4064 """
4065
4066 def user_to_device_distance(self, dx: float, dy: float) -> Tuple[float, float]:
4067 """
4068 :param dx: X value of a distance vector
4069 :param dy: Y value of a distance vector
4070 :returns: (dx, dy), both float
4071
4072 * *dx*: X value of a distance vector
4073 * *dy*: Y value of a distance vector
4074
4075 Transform a distance vector from user space to device space. This
4076 function is similar to :meth:`Context.user_to_device` except that the
4077 translation components of the CTM will be ignored when transforming
4078 *(dx,dy)*.
4079 """
4080
4081 class Error(Exception):
4082 """This exception is raised when a cairo object returns an error status."""
4083 status: Status = ...
4084
4085 CairoError = Error
4086 """
4087 An alias for :exc:`Error`
4088
4089 .. versionadded:: 1.12.0
4090 """
4091
4092 class Gradient(Pattern):
4093 """
4094 *Gradient* is an abstract base class from which other *Pattern* classes
4095 derive. It cannot be instantiated directly.
4096 """
4097
4098 def add_color_stop_rgb(self, offset: float, red: float, green: float, blue: float) -> None:
4099 """
4100 :param offset: an offset in the range [0.0 .. 1.0]
4101 :param red: red component of color
4102 :param green: green component of color
4103 :param blue: blue component of color
4104
4105 Adds an opaque color stop to a *Gradient* pattern. The offset specifies
4106 the location along the gradient's control vector. For example, a
4107 *LinearGradient's* control vector is from (x0,y0) to (x1,y1) while a
4108 *RadialGradient's* control vector is from any point on the start circle
4109 to the corresponding point on the end circle.
4110
4111 The color is specified in the same way as in :meth:`Context.set_source_rgb`.
4112
4113 If two (or more) stops are specified with identical offset values, they
4114 will be sorted according to the order in which the stops are added,
4115 (stops added earlier will compare less than stops added later). This can
4116 be useful for reliably making sharp color transitions instead of the
4117 typical blend.
4118 """
4119
4120 def add_color_stop_rgba(self, offset: float, red: float, green: float, blue: float, alpha: float) -> None:
4121 """
4122 :param offset: an offset in the range [0.0 .. 1.0]
4123 :param red: red component of color
4124 :param green: green component of color
4125 :param blue: blue component of color
4126 :param alpha: alpha component of color
4127
4128 Adds an opaque color stop to a *Gradient* pattern. The offset specifies
4129 the location along the gradient's control vector. For example, a
4130 *LinearGradient's* control vector is from (x0,y0) to (x1,y1) while a
4131 *RadialGradient's* control vector is from any point on the start circle
4132 to the corresponding point on the end circle.
4133
4134 The color is specified in the same way as in :meth:`Context.set_source_rgb`.
4135
4136 If two (or more) stops are specified with identical offset values, they
4137 will be sorted according to the order in which the stops are added,
4138 (stops added earlier will compare less than stops added later). This can
4139 be useful for reliably making sharp color transitions instead of the
4140 typical blend.
4141 """
4142
4143 def get_color_stops_rgba(self) -> List[Tuple[float, float, float, float, float]]:
4144 """
4145 :returns: a list of (offset, red, green, blue, alpha) tuples of float
4146
4147 Gets the color and offset information for all color stops specified in
4148 the given gradient pattern.
4149
4150 .. versionadded:: 1.14
4151 """
4152
4153 class LinearGradient(Gradient):
4154 def __init__(self, x0: float, y0: float, x1: float, y1: float) -> None:
4155 """
4156 :param x0: x coordinate of the start point
4157 :param y0: y coordinate of the start point
4158 :param x1: x coordinate of the end point
4159 :param y1: y coordinate of the end point
4160
4161 Create a new *LinearGradient* along the line defined by (x0, y0) and (x1,
4162 y1). Before using the *Gradient* pattern, a number of color stops should
4163 be defined using :meth:`Gradient.add_color_stop_rgb` or
4164 :meth:`Gradient.add_color_stop_rgba`
4165
4166 Note: The coordinates here are in pattern space. For a new *Pattern*,
4167 pattern space is identical to user space, but the relationship between the
4168 spaces can be changed with :meth:`Pattern.set_matrix`
4169 """
4170
4171 def get_linear_points(self) -> Tuple[float, float, float, float]:
4172 """
4173 :returns: (x0, y0, x1, y1) - a tuple of float
4174
4175 * x0: return value for the x coordinate of the first point
4176 * y0: return value for the y coordinate of the first point
4177 * x1: return value for the x coordinate of the second point
4178 * y1: return value for the y coordinate of the second point
4179
4180 Gets the gradient endpoints for a *LinearGradient*.
4181
4182 .. versionadded:: 1.4
4183 """
4184
4185 class MeshPattern(Pattern):
4186 """
4187 Mesh patterns are tensor-product patch meshes (type 7 shadings in PDF).
4188 Mesh patterns may also be used to create other types of shadings that are
4189 special cases of tensor-product patch meshes such as Coons patch meshes
4190 (type 6 shading in PDF) and Gouraud-shaded triangle meshes (type 4 and 5
4191 shadings in PDF).
4192
4193 Mesh patterns consist of one or more tensor-product patches, which should
4194 be defined before using the mesh pattern. Using a mesh pattern with a
4195 partially defined patch as source or mask will put the context in an error
4196 status with a status of :attr:`cairo.Status.INVALID_MESH_CONSTRUCTION`.
4197
4198 A tensor-product patch is defined by 4 Bézier curves (side 0, 1, 2, 3) and
4199 by 4 additional control points (P0, P1, P2, P3) that provide further
4200 control over the patch and complete the definition of the tensor-product
4201 patch. The corner C0 is the first point of the patch.
4202
4203 Degenerate sides are permitted so straight lines may be used. A zero
4204 length line on one side may be used to create 3 sided patches.
4205
4206 ::
4207
4208 C1 Side 1 C2
4209 +---------------+
4210 | |
4211 | P1 P2 |
4212 | |
4213 Side 0 | | Side 2
4214 | |
4215 | |
4216 | P0 P3 |
4217 | |
4218 +---------------+
4219 C0 Side 3 C3
4220
4221 Each patch is constructed by first calling :meth:`begin_patch`, then
4222 :meth:`move_to` to specify the first point in the patch (C0). Then the
4223 sides are specified with calls to :meth:`curve_to` and :meth:`line_to`.
4224
4225 The four additional control points (P0, P1, P2, P3) in a patch can be
4226 specified with :meth:`set_control_point`.
4227
4228 At each corner of the patch (C0, C1, C2, C3) a color may be specified with
4229 :meth:`set_corner_color_rgb` or :meth:`set_corner_color_rgba`. Any corner
4230 whose color is not explicitly specified defaults to transparent black.
4231
4232 A Coons patch is a special case of the tensor-product patch where the
4233 control points are implicitly defined by the sides of the patch. The
4234 default value for any control point not specified is the implicit value
4235 for a Coons patch, i.e. if no control points are specified the patch is a
4236 Coons patch.
4237
4238 A triangle is a special case of the tensor-product patch where the control
4239 points are implicitly defined by the sides of the patch, all the sides are
4240 lines and one of them has length 0, i.e. if the patch is specified using
4241 just 3 lines, it is a triangle. If the corners connected by the 0-length
4242 side have the same color, the patch is a Gouraud-shaded triangle.
4243
4244 Patches may be oriented differently to the above diagram. For example the
4245 first point could be at the top left. The diagram only shows the
4246 relationship between the sides, corners and control points. Regardless of
4247 where the first point is located, when specifying colors, corner 0 will
4248 always be the first point, corner 1 the point between side 0 and side 1
4249 etc.
4250
4251 Calling :meth:`end_patch` completes the current patch. If less than 4
4252 sides have been defined, the first missing side is defined as a line from
4253 the current point to the first point of the patch (C0) and the other sides
4254 are degenerate lines from C0 to C0. The corners between the added sides
4255 will all be coincident with C0 of the patch and their color will be set to
4256 be the same as the color of C0.
4257
4258 Additional patches may be added with additional calls to
4259 :meth:`begin_patch`/:meth:`end_patch`.
4260
4261 ::
4262
4263 # Add a Coons patch
4264 pattern = cairo.MeshPattern()
4265 pattern.begin_patch()
4266 pattern.move_to(0, 0)
4267 pattern.curve_to(30, -30, 60, 30, 100, 0)
4268 pattern.curve_to(60, 30, 130, 60, 100, 100)
4269 pattern.curve_to(60, 70, 30, 130, 0, 100)
4270 pattern.curve_to(30, 70, -30, 30, 0, 0)
4271 pattern.set_corner_color_rgb(0, 1, 0, 0)
4272 pattern.set_corner_color_rgb(1, 0, 1, 0)
4273 pattern.set_corner_color_rgb(2, 0, 0, 1)
4274 pattern.set_corner_color_rgb(3, 1, 1, 0)
4275 pattern.end_patch()
4276
4277 # Add a Gouraud-shaded triangle
4278 pattern = cairo.MeshPattern()
4279 pattern.begin_patch()
4280 pattern.move_to(100, 100)
4281 pattern.line_to(130, 130)
4282 pattern.line_to(130, 70)
4283 pattern.set_corner_color_rgb(0, 1, 0, 0)
4284 pattern.set_corner_color_rgb(1, 0, 1, 0)
4285 pattern.set_corner_color_rgb(2, 0, 0, 1)
4286 pattern.end_patch()
4287
4288 When two patches overlap, the last one that has been added is drawn over
4289 the first one.
4290
4291 When a patch folds over itself, points are sorted depending on their
4292 parameter coordinates inside the patch. The v coordinate ranges from 0 to
4293 1 when moving from side 3 to side 1; the u coordinate ranges from 0 to 1
4294 when going from side 0 to side
4295
4296 Points with higher v coordinate hide points with lower v coordinate. When
4297 two points have the same v coordinate, the one with higher u coordinate is
4298 above. This means that points nearer to side 1 are above points nearer to
4299 side 3; when this is not sufficient to decide which point is above (for
4300 example when both points belong to side 1 or side 3) points nearer to side
4301 2 are above points nearer to side 0.
4302
4303 For a complete definition of tensor-product patches, see the PDF
4304 specification (ISO32000), which describes the parametrization in detail.
4305
4306 Note: The coordinates are always in pattern space. For a new pattern,
4307 pattern space is identical to user space, but the relationship between the
4308 spaces can be changed with :meth:`Pattern.set_matrix`.
4309
4310 .. versionadded:: 1.14
4311 """
4312
4313 def __init__(self) -> None:
4314 """
4315 Create a new mesh pattern.
4316
4317 .. versionadded:: 1.14
4318 """
4319
4320 def begin_patch(self) -> None:
4321 """
4322 :raises Error:
4323
4324 Begin a patch in a mesh pattern.
4325
4326 After calling this function, the patch shape should be defined with
4327 :meth:`move_to`, :meth:`line_to` and :meth:`curve_to`.
4328
4329 After defining the patch, :meth:`end_patch` must be called before
4330 using pattern as a source or mask.
4331 """
4332
4333 def curve_to(self, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float) -> None:
4334 """
4335 :param x1: the X coordinate of the first control point
4336 :param y1: the Y coordinate of the first control point
4337 :param x2: the X coordinate of the second control point
4338 :param y2: the Y coordinate of the second control point
4339 :param x3: the X coordinate of the end of the curve
4340 :param y3: the Y coordinate of the end of the curve
4341 :raises Error:
4342
4343 Adds a cubic Bézier spline to the current patch from the current point
4344 to position (x3 , y3 ) in pattern-space coordinates, using (x1 , y1 )
4345 and (x2 , y2 ) as the control points.
4346
4347 If the current patch has no current point before the call to
4348 :meth:`curve_to`, this function will behave as if
4349 preceded by a call to ``pattern.move_to(x1, y1)``.
4350
4351 After this call the current point will be (x3 , y3 ).
4352 """
4353
4354 def end_patch(self) -> None:
4355 """
4356 :raises Error:
4357
4358 Indicates the end of the current patch in a mesh pattern.
4359
4360 If the current patch has less than 4 sides, it is closed with a
4361 straight line from the current point to the first point of the patch
4362 as if :meth:`line_to` was used.
4363 """
4364
4365 def get_control_point(self, patch_num: int, point_num: int) -> Tuple[float, float]:
4366 """
4367 :param patch_num: the patch number to return data for
4368 :param point_num: he control point number to return data for
4369 :returns: a (x, y) tuple of float - coordinates of the control point
4370 :raises Error:
4371
4372 Gets the control point point_num of patch patch_num for a mesh
4373 pattern.
4374
4375 ``patch_num`` can range from 0 to n-1 where n is the number returned
4376 by :meth:`get_patch_count`.
4377
4378 Valid values for ``point_num`` are from 0 to 3 and identify the control
4379 points as explained in :class:`MeshPattern`.
4380 """
4381
4382 def get_corner_color_rgba(self, patch_num: int, corner_num: int) -> Tuple[float, float, float, float]:
4383 """
4384 :param patch_num: the patch number to return data for
4385 :param corner_num: the corner number to return data for
4386 :returns: a (red, green, blue, alpha) tuple of float
4387 :raises Error:
4388
4389 Gets the color information in corner ``corner_num`` of patch
4390 ``patch_num`` for a mesh pattern.
4391
4392 ``patch_num`` can range from 0 to n-1 where n is the number returned
4393 by :meth:`get_patch_count`.
4394
4395 Valid values for ``corner_num`` are from 0 to 3 and identify the
4396 corners as explained in :class:`MeshPattern`.
4397 """
4398
4399 def get_patch_count(self) -> int:
4400 """
4401 :returns: number of patches
4402
4403 Gets the number of patches specified in the given mesh pattern.
4404
4405 The number only includes patches which have been finished by calling
4406 :meth:`end_patch`. For example it will be 0 during the definition of
4407 the first patch.
4408 """
4409
4410 def line_to(self, x: float, y: float) -> None:
4411 """
4412 :param x: the X coordinate of the end of the new line
4413 :param y: the Y coordinate of the end of the new line
4414 :raises Error:
4415
4416 Adds a line to the current patch from the current point to position (x
4417 , y ) in pattern-space coordinates.
4418
4419 If there is no current point before the call to :meth:`line_to` this
4420 function will behave as ``pattern.move_to(x ,y)``.
4421
4422 After this call the current point will be (x , y ).
4423 """
4424
4425 def move_to(self, x: float, y: float) -> None:
4426 """
4427 :param x: the X coordinate of the new position
4428 :param y: the Y coordinate of the new position
4429 :raises Error:
4430
4431 Define the first point of the current patch in a mesh pattern.
4432
4433 After this call the current point will be (x , y ).
4434 """
4435
4436 def set_control_point(self, point_num: int, x: float, y: float) -> None:
4437 """
4438 :param point_num: the control point to set the position for
4439 :param x: the X coordinate of the control point
4440 :param y: the Y coordinate of the control point
4441 :raises Error:
4442
4443 Set an internal control point of the current patch.
4444
4445 Valid values for point_num are from 0 to 3 and identify the control
4446 points as explained in :class:`MeshPattern`.
4447 """
4448
4449 def set_corner_color_rgb(self, corner_num: int, red: float, green: float, blue: float) -> None:
4450 """
4451 :param corner_num: the corner to set the color for
4452 :param red: red component of color
4453 :param green: green component of color
4454 :param blue: blue component of color
4455 :raises Error:
4456
4457 Sets the color of a corner of the current patch in a mesh pattern.
4458
4459 The color is specified in the same way as in
4460 :meth:`Context.set_source_rgb`.
4461
4462 Valid values for corner_num are from 0 to 3 and identify the corners
4463 as explained in :class:`MeshPattern`.
4464 """
4465
4466 def set_corner_color_rgba(self, corner_num: int, red: float, green: float, blue: float, alpha: float) -> None:
4467 """
4468 :param corner_num: the corner to set the color for
4469 :param red: red component of color
4470 :param green: green component of color
4471 :param blue: blue component of color
4472 :param alpha: alpha component of color
4473 :raises Error:
4474
4475 Sets the color of a corner of the current patch in a mesh pattern.
4476
4477 The color is specified in the same way as in
4478 :meth:`Context.set_source_rgba`.
4479
4480 Valid values for corner_num are from 0 to 3 and identify the corners
4481 as explained in :class:`MeshPattern`.
4482 """
4483
4484 def get_path(self, patch_num: int) -> Path:
4485 """
4486 :param patch_num: the patch number to return data for
4487 :returns: the path defining the patch
4488 :raises Error:
4489
4490 Gets path defining the patch ``patch_num`` for a mesh pattern.
4491
4492 ``patch_num`` can range from 0 to n-1 where n is the number returned
4493 by :meth:`get_patch_count`.
4494 """
4495
4496 class PDFSurface(Surface):
4497 """
4498 The PDFSurface is used to render cairo graphics to Adobe PDF files and is a
4499 multi-page vector surface backend.
4500
4501 .. versionadded:: 1.2
4502 """
4503
4504 def __init__(self, fobj: Union[_PathLike, _FileLike], width_in_points: float, height_in_points: float) -> None:
4505 """
4506 :param fobj: a filename or writable file object. None may be used to
4507 specify no output. This will generate a *PDFSurface* that may be
4508 queried and used as a source, without generating a temporary file.
4509 :param width_in_points: width of the surface, in points (1 point ==
4510 1/72.0 inch)
4511 :param height_in_points: height of the surface, in points (1 point ==
4512 1/72.0 inch)
4513 :returns: a new *PDFSurface* of the specified size in points to be
4514 written to *fobj*.
4515
4516 .. versionadded:: 1.2
4517 """
4518
4519 def set_custom_metadata(self, name: str, value: Optional[str]) -> None:
4520 """
4521 :param name: The name of the custom metadata item to set.
4522 :param value: The value of the metadata.
4523
4524 Set custom document metadata. *name* may be any string except for the
4525 following names reserved by PDF: "Title", "Author", "Subject",
4526 "Keywords", "Creator", "Producer", "CreationDate", "ModDate", "Trapped".
4527
4528 If *value* is :obj:`None` or an empty string, the *name* metadata will
4529 not be set.
4530
4531 For example::
4532
4533 surface.set_custom_metadata("ISBN", "978-0123456789")
4534
4535 .. versionadded:: 1.23.0 Only available with cairo 1.17.6+
4536 """
4537
4538 def set_size(self, width_in_points: float, height_in_points: float) -> None:
4539 """
4540 :param width_in_points: new surface width, in points
4541 (1 point == 1/72.0 inch)
4542 :param height_in_points: new surface height, in points
4543 (1 point == 1/72.0 inch)
4544
4545 Changes the size of a *PDFSurface* for the current (and subsequent) pages.
4546
4547 This function should only be called before any drawing operations have
4548 been performed on the current page. The simplest way to do this is to
4549 call this function immediately after creating the surface or immediately
4550 after completing a page with either :meth:`Context.show_page` or
4551 :meth:`Context.copy_page`.
4552
4553 .. versionadded:: 1.2
4554 """
4555
4556 def restrict_to_version(self, version: PDFVersion) -> None:
4557 """
4558 :param version: PDF version
4559
4560 Restricts the generated PDF file to version . See :meth:`get_versions`
4561 for a list of available version values that can be used here.
4562
4563 This function should only be called before any drawing operations have
4564 been performed on the given surface. The simplest way to do this is to
4565 call this function immediately after creating the surface.
4566
4567 .. versionadded:: 1.12.0
4568 """
4569
4570 @staticmethod
4571 def get_versions() -> List[PDFVersion]:
4572 """
4573 :returns: supported version list
4574
4575 Retrieve the list of supported versions. See
4576 :meth:`restrict_to_version`.
4577
4578 .. versionadded:: 1.12.0
4579 """
4580
4581 @staticmethod
4582 def version_to_string(version: PDFVersion) -> str:
4583 """
4584 :param version: PDF version
4585 :returns: the string associated to the given version
4586 :raises ValueError: if version isn't valid
4587
4588 Get the string representation of the given version id. See
4589 :meth:`get_versions` for a way to get the list of valid version ids.
4590
4591 .. versionadded:: 1.12.0
4592 """
4593
4594 def add_outline(self, parent_id: int, utf8: str, link_attribs: str, flags: PDFOutlineFlags) -> int:
4595 """
4596 :param parent_id:
4597 the id of the parent item or :data:`PDF_OUTLINE_ROOT` if this is a top
4598 level item.
4599 :param utf8:
4600 the name of the outline
4601 :param link_attribs:
4602 the link attributes specifying where this outline links to
4603 :param flags:
4604 outline item flags
4605 :returns: the id for the added item.
4606
4607 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
4608 """
4609
4610 def set_metadata(self, metadata: PDFMetadata, utf8: str) -> None:
4611 """
4612 :param metadata: The metadata item to set.
4613 :param utf8: metadata value
4614
4615 Set document metadata. The :attr:`PDFMetadata.CREATE_DATE` and
4616 :attr:`PDFMetadata.MOD_DATE` values must be in ISO-8601 format:
4617 YYYY-MM-DDThh:mm:ss. An optional timezone of the form "[+/-]hh:mm" or
4618 "Z" for UTC time can be appended. All other metadata values can be any
4619 UTF-8 string.
4620
4621 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
4622 """
4623
4624 def set_page_label(self, utf8: str) -> None:
4625 """
4626 :param utf8: metadata value
4627
4628 Set page label for the current page.
4629
4630 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
4631 """
4632
4633 def set_thumbnail_size(self, width: int, height: int) -> None:
4634 """
4635 :param width: Thumbnail width.
4636 :param height: Thumbnail height
4637
4638 Set the thumbnail image size for the current and all subsequent pages.
4639 Setting a width or height of 0 disables thumbnails for the current and
4640 subsequent pages.
4641
4642 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
4643 """
4644
4645 class PSSurface(Surface):
4646 """
4647 The *PSSurface* is used to render cairo graphics to Adobe PostScript files and
4648 is a multi-page vector surface backend.
4649 """
4650
4651 def __init__(self, fobj: Union[_FileLike, _PathLike], width_in_points: float, height_in_points: float) -> None:
4652 """
4653 :param fobj: a filename or writable file object. None may be used to specify no output. This will generate a *PSSurface* that may be queried and used as a source, without generating a temporary file.
4654 :param width_in_points: width of the surface, in points
4655 (1 point == 1/72.0 inch)
4656 :param height_in_points: height of the surface, in points
4657 (1 point == 1/72.0 inch)
4658 :returns: a new *PDFSurface* of the specified size in points to be written
4659 to *fobj*.
4660 :raises: :exc:`MemoryError` in case of no memory
4661
4662 Note that the size of individual pages of the PostScript output can
4663 vary. See :meth:`.set_size`.
4664 """
4665
4666 def dsc_begin_page_setup(self) -> None:
4667 """
4668 This method indicates that subsequent calls to
4669 :meth:`.dsc_comment` should direct comments to the PageSetup
4670 section of the PostScript output.
4671
4672 This method call is only needed for the first page of a surface. It
4673 should be called after any call to :meth:`.dsc_begin_setup` and
4674 before any drawing is performed to the surface.
4675
4676 See :meth:`.dsc_comment` for more details.
4677
4678 .. versionadded:: 1.2
4679 """
4680
4681 def dsc_begin_setup(self) -> None:
4682 """
4683 This function indicates that subsequent calls to :meth:`.dsc_comment`
4684 should direct comments to the Setup section of the PostScript output.
4685
4686 This function should be called at most once per surface, and must be
4687 called before any call to :meth:`.dsc_begin_page_setup` and before any
4688 drawing is performed to the surface.
4689
4690 See :meth:`.dsc_comment` for more details.
4691
4692 .. versionadded:: 1.2
4693 """
4694
4695 def dsc_comment(self, comment: str) -> None:
4696 """
4697 :param comment: a comment string to be emitted into the PostScript output
4698
4699 Emit a comment into the PostScript output for the given surface.
4700
4701 The comment is expected to conform to the PostScript Language
4702 Document Structuring Conventions (DSC). Please see that manual for
4703 details on the available comments and their meanings. In
4704 particular, the %%IncludeFeature comment allows a
4705 device-independent means of controlling printer device features. So
4706 the PostScript Printer Description Files Specification will also be
4707 a useful reference.
4708
4709 The comment string must begin with a percent character (%) and the
4710 total length of the string (including any initial percent
4711 characters) must not exceed 255 characters. Violating either of
4712 these conditions will place *PSSurface* into an error state. But
4713 beyond these two conditions, this function will not enforce
4714 conformance of the comment with any particular specification.
4715
4716 The comment string should not have a trailing newline.
4717
4718 The DSC specifies different sections in which particular comments
4719 can appear. This function provides for comments to be emitted
4720 within three sections: the header, the Setup section, and the
4721 PageSetup section. Comments appearing in the first two sections
4722 apply to the entire document while comments in the BeginPageSetup
4723 section apply only to a single page.
4724
4725 For comments to appear in the header section, this function should
4726 be called after the surface is created, but before a call to
4727 :meth:`.dsc_begin_setup`.
4728
4729 For comments to appear in the Setup section, this function should be
4730 called after a call to :meth:`.dsc_begin_setup` but before a call to
4731 :meth:`.dsc_begin_page_setup`.
4732
4733 For comments to appear in the PageSetup section, this function should be
4734 called after a call to :meth:`.dsc_begin_page_setup`.
4735
4736 Note that it is only necessary to call :meth:`.dsc_begin_page_setup` for
4737 the first page of any surface. After a call to :meth:`Context.show_page`
4738 or :meth:`Context.copy_page` comments are unambiguously directed to the
4739 PageSetup section of the current page. But it doesn't hurt to call this
4740 function at the beginning of every page as that consistency may make the
4741 calling code simpler.
4742
4743 As a final note, cairo automatically generates several comments on
4744 its own. As such, applications must not manually generate any of
4745 the following comments:
4746
4747 Header section: %!PS-Adobe-3.0, %Creator, %CreationDate, %Pages,
4748 %BoundingBox, %DocumentData, %LanguageLevel, %EndComments.
4749
4750 Setup section: %BeginSetup, %EndSetup
4751
4752 PageSetup section: %BeginPageSetup, %PageBoundingBox,
4753 %EndPageSetup.
4754
4755 Other sections: %BeginProlog, %EndProlog, %Page, %Trailer, %EOF
4756
4757 Here is an example sequence showing how this function might be used::
4758
4759 surface = PSSurface (filename, width, height)
4760 ...
4761 surface.dsc_comment (surface, "%%Title: My excellent document")
4762 surface.dsc_comment (surface, "%%Copyright: Copyright (C) 2006 Cairo Lover")
4763 ...
4764 surface.dsc_begin_setup (surface)
4765 surface.dsc_comment (surface, "%%IncludeFeature: *MediaColor White")
4766 ...
4767 surface.dsc_begin_page_setup (surface)
4768 surface.dsc_comment (surface, "%%IncludeFeature: *PageSize A3")
4769 surface.dsc_comment (surface, "%%IncludeFeature: *InputSlot LargeCapacity")
4770 surface.dsc_comment (surface, "%%IncludeFeature: *MediaType Glossy")
4771 surface.dsc_comment (surface, "%%IncludeFeature: *MediaColor Blue")
4772 ... draw to first page here ..
4773 ctx.show_page (cr)
4774 ...
4775 surface.dsc_comment (surface, "%%IncludeFeature: PageSize A5");
4776 ...
4777
4778 .. versionadded:: 1.2
4779 """
4780
4781 def get_eps(self) -> bool:
4782 """
4783 :returns: True iff the *PSSurface* will output Encapsulated PostScript.
4784
4785 .. versionadded:: 1.6
4786 """
4787
4788 @staticmethod
4789 def level_to_string(level: PSLevel) -> str:
4790 """
4791 :param level: a PS level
4792 :returns: the string associated to given level.
4793
4794 Get the string representation of the given *level*. See
4795 :meth:`get_levels` for a way to get the list of valid level
4796 ids.
4797
4798 .. note:: Prior to 1.12 this was available under
4799 :meth:`ps_level_to_string`
4800
4801 .. versionadded:: 1.12.0
4802 """
4803
4804 ps_level_to_string = level_to_string
4805 """
4806 Alias for :meth:`level_to_string`
4807
4808 .. versionadded:: 1.6
4809 """
4810
4811 def restrict_to_level(self, level: PSLevel) -> None:
4812 """
4813 :param level: a PS level
4814
4815 Restricts the generated PostSript file to *level*. See
4816 :meth:`get_levels` for a list of available level values that
4817 can be used here.
4818
4819 This function should only be called before any drawing operations have
4820 been performed on the given surface. The simplest way to do this is to
4821 call this function immediately after creating the surface.
4822
4823 .. versionadded:: 1.6
4824 """
4825
4826 def set_eps(self, eps: bool) -> None:
4827 """
4828 :param eps: True to output EPS format PostScript
4829
4830 If *eps* is True, the PostScript surface will output Encapsulated
4831 PostScript.
4832
4833 This function should only be called before any drawing operations have
4834 been performed on the current page. The simplest way to do this is to
4835 call this function immediately after creating the surface. An
4836 Encapsulated PostScript file should never contain more than one page.
4837
4838 .. versionadded:: 1.6
4839 """
4840
4841 def set_size(self, width_in_points: float, height_in_points: float) -> None:
4842 """
4843 :param width_in_points: new surface width, in points (1 point == 1/72.0 inch)
4844 :param height_in_points: new surface height, in points (1 point == 1/72.0 inch)
4845
4846 Changes the size of a PostScript surface for the current (and
4847 subsequent) pages.
4848
4849 This function should only be called before any drawing operations
4850 have been performed on the current page. The simplest way to do
4851 this is to call this function immediately after creating the
4852 surface or immediately after completing a page with either
4853 :meth:`Context.show_page` or :meth:`Context.copy_page`.
4854
4855 .. versionadded:: 1.2
4856 """
4857
4858 @staticmethod
4859 def get_levels() -> List[PSLevel]:
4860 """
4861 :returns: supported level list
4862
4863 Retrieve the list of supported levels. See
4864 :meth:`restrict_to_level`.
4865
4866 .. versionadded:: 1.12.0
4867 """
4868
4869 class SVGSurface(Surface):
4870 """
4871 The *SVGSurface* is used to render cairo graphics to SVG files and is a
4872 multi-page vector surface backend
4873 """
4874
4875 def __init__(self, fobj: "Union[_PathLike, _FileLike]", width_in_points: float, height_in_points: float) -> None:
4876 """
4877 :param fobj: a filename or writable file object. None may be used to specify no output. This will generate a *SVGSurface* that may be queried and used as a source, without generating a temporary file.
4878 :param width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
4879 :param height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
4880 """
4881
4882 def restrict_to_version(self, version: SVGVersion) -> None:
4883 """
4884 :param version: SVG version
4885
4886 Restricts the generated SVG file to version . See :meth:`get_versions`
4887 for a list of available version values that can be used here.
4888
4889 This function should only be called before any drawing operations have
4890 been performed on the given surface. The simplest way to do this is to
4891 call this function immediately after creating the surface.
4892
4893 .. versionadded:: 1.12.0
4894 """
4895
4896 @staticmethod
4897 def get_versions() -> List[SVGVersion]:
4898 """
4899 :returns: supported version list
4900
4901 Retrieve the list of supported versions. See
4902 :meth:`restrict_to_version`.
4903
4904 .. versionadded:: 1.12.0
4905 """
4906
4907 @staticmethod
4908 def version_to_string(version: SVGVersion) -> str:
4909 """
4910 :param version: SVG version
4911 :returns: the string associated to the given version
4912 :raises ValueError: if version isn't valid
4913
4914 Get the string representation of the given version id. See
4915 :meth:`get_versions` for a way to get the list of valid version ids.
4916
4917 .. versionadded:: 1.12.0
4918 """
4919
4920 def get_document_unit(self) -> SVGUnit:
4921 """
4922 :returns: the SVG unit of the SVG surface.
4923 :rtype: SVGUnit
4924
4925 Get the unit of the SVG surface.
4926
4927 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
4928 """
4929
4930 def set_document_unit(self, unit: SVGUnit) -> None:
4931 """
4932 :param SVGUnit unit: SVG unit
4933
4934 Use the specified unit for the width and height of the generated SVG
4935 file. See :class:`SVGUnit` for a list of available unit values that can
4936 be used here.
4937
4938 This function can be called at any time before generating the SVG file.
4939
4940 However to minimize the risk of ambiguities it's recommended to call it
4941 before any drawing operations have been performed on the given surface,
4942 to make it clearer what the unit used in the drawing operations is.
4943
4944 The simplest way to do this is to call this function immediately after
4945 creating the SVG surface.
4946
4947 Note if this function is never called, the default unit for SVG
4948 documents generated by cairo will be "pt". This is for historical
4949 reasons.
4950
4951 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
4952 """
4953
4954 class RadialGradient(Gradient):
4955
4956 def __init__(self, cx0: float, cy0: float, radius0: float, cx1: float, cy1: float, radius1: float) -> None:
4957 """
4958 :param cx0: x coordinate for the center of the start circle
4959 :param cy0: y coordinate for the center of the start circle
4960 :param radius0: radius of the start circle
4961 :param cx1: x coordinate for the center of the end circle
4962 :param cy1: y coordinate for the center of the end circle
4963 :param radius1: radius of the end circle
4964
4965 Creates a new *RadialGradient* pattern between the two circles defined by
4966 (cx0, cy0, radius0) and (cx1, cy1, radius1). Before using the gradient
4967 pattern, a number of color stops should be defined using
4968 :meth:`Gradient.add_color_stop_rgb` or :meth:`Gradient.add_color_stop_rgba`.
4969
4970 Note: The coordinates here are in pattern space. For a new pattern, pattern
4971 space is identical to user space, but the relationship between the spaces
4972 can be changed with :meth:`Pattern.set_matrix`.
4973 """
4974
4975 def get_radial_circles(self) -> Tuple[float, float, float, float, float, float]:
4976 """
4977 :returns: (x0, y0, r0, x1, y1, r1) - a tuple of float
4978
4979 * x0: return value for the x coordinate of the center of the first circle
4980 * y0: return value for the y coordinate of the center of the first circle
4981 * r0: return value for the radius of the first circle
4982 * x1: return value for the x coordinate of the center of the second circle
4983 * y1: return value for the y coordinate of the center of the second circle
4984 * r1: return value for the radius of the second circle
4985
4986 Gets the *Gradient* endpoint circles for a *RadialGradient*, each
4987 specified as a center coordinate and a radius.
4988
4989 .. versionadded:: 1.4
4990 """
4991
4992 _AcquireCallback = Callable[[Surface, RectangleInt], Surface]
4993 _ReleaseCallback = Callable[[Surface], None]
4994
4995 class RasterSourcePattern(Pattern):
4996 """
4997 The raster source provides the ability to supply arbitrary pixel data whilst
4998 rendering. The pixels are queried at the time of rasterisation by means of
4999 user callback functions, allowing for the ultimate flexibility. For example,
5000 in handling compressed image sources, you may keep a MRU cache of decompressed
5001 images and decompress sources on the fly and discard old ones to conserve
5002 memory.
5003
5004 For the raster source to be effective, you must at least specify the acquire
5005 and release callbacks which are used to retrieve the pixel data for the region
5006 of interest and demark when it can be freed afterwards. Other callbacks are
5007 provided for when the pattern is copied temporarily during rasterisation, or
5008 more permanently as a snapshot in order to keep the pixel data available for
5009 printing.
5010
5011 .. versionadded:: 1.15
5012 """
5013
5014 def __init__(self, content: Content, width: int, height: int) -> None:
5015 """
5016 :param content:
5017 content type for the pixel data that will be returned. Knowing the
5018 content type ahead of time is used for analysing the operation and
5019 picking the appropriate rendering path.
5020 :param width:
5021 maximum size of the sample area
5022 :param height:
5023 maximum size of the sample area
5024
5025 Creates a new user pattern for providing pixel data.
5026
5027 Use the setter functions to associate callbacks with the returned pattern.
5028
5029 .. versionadded:: 1.15
5030 """
5031
5032 def set_acquire(self, acquire: Optional[_AcquireCallback], release: Optional[_ReleaseCallback]) -> None:
5033 """
5034 :param acquire:
5035 acquire callback or :obj:`None` to unset it
5036 :type acquire: :obj:`callable`
5037 :param release:
5038 (optional) release callback or :obj:`None`
5039 :type release: :obj:`callable`
5040 :raises Error:
5041
5042 Specifies the callbacks used to generate the image surface for a
5043 rendering operation (acquire) and the function used to cleanup that
5044 surface afterwards.
5045
5046 The acquire callback should create a surface (preferably an image
5047 surface created to match the target using
5048 :meth:`Surface.create_similar_image`) that defines at least the region
5049 of interest specified by extents. The surface is allowed to be the
5050 entire sample area, but if it does contain a subsection of the sample
5051 area, the surface extents should be provided by setting the device
5052 offset (along with its width and height) using
5053 :meth:`Surface.set_device_offset`.
5054
5055 .. function:: acquire(target, extents)
5056
5057 :param Surface target:
5058 the rendering target surface
5059 :param RectangleInt extents:
5060 rectangular region of interest in pixels in sample space
5061 :rtype: Surface
5062
5063 This function is called when a pattern is being rendered from. It
5064 should create a surface that provides the pixel data for the
5065 region of interest as defined by extents, though the surface
5066 itself does not have to be limited to that area. For convenience
5067 the surface should probably be of image type, created with
5068 :meth:`Surface.create_similar_image` for the target (which enables
5069 the number of copies to be reduced during transfer to the device).
5070 Another option, might be to return a similar surface to the target
5071 for explicit handling by the application of a set of cached
5072 sources on the device. The region of sample data provided should
5073 be defined using :meth:`Surface.set_device_offset` to specify the
5074 top-left corner of the sample data (along with width and height of
5075 the surface).
5076
5077 .. function:: release(surface)
5078
5079 :param Surface surface:
5080 the surface created during acquire
5081
5082 This function is called when the pixel data is no longer being
5083 accessed by the pattern for the rendering operation.
5084
5085 .. versionadded:: 1.15
5086 """
5087
5088 def get_acquire(self) -> Tuple[Optional[_AcquireCallback], Optional[_ReleaseCallback]]:
5089 """
5090 :returns: a (acquire, release) tuple of callables or None as set
5091 through :meth:`set_acquire`
5092
5093 Queries the current acquire and release callbacks.
5094
5095 .. versionadded:: 1.15
5096 """
5097
5098 class RecordingSurface(Surface):
5099 """
5100 A *RecordingSurface* is a surface that records all drawing operations at the
5101 highest level of the surface backend interface, (that is, the level of paint,
5102 mask, stroke, fill, and show_text_glyphs). The recording surface can then be
5103 "replayed" against any target surface by using it as a source surface.
5104
5105 If you want to replay a surface so that the results in target will be
5106 identical to the results that would have been obtained if the original
5107 operations applied to the recording surface had instead been applied to the
5108 target surface, you can use code like this::
5109
5110 cr = cairo.Context(target)
5111 cr.set_source_surface(recording_surface, 0.0, 0.0)
5112 cr.paint()
5113
5114 A *RecordingSurface* is logically unbounded, i.e. it has no implicit
5115 constraint on the size of the drawing surface. However, in practice this is
5116 rarely useful as you wish to replay against a particular target surface with
5117 known bounds. For this case, it is more efficient to specify the target
5118 extents to the recording surface upon creation.
5119
5120 The recording phase of the recording surface is careful to snapshot all
5121 necessary objects (paths, patterns, etc.), in order to achieve accurate
5122 replay.
5123
5124 .. versionadded:: 1.11.0
5125 """
5126
5127 def __init__(self, content: Content, rectangle: Rectangle) -> None:
5128 """
5129 :param content: the content for the new surface
5130 :param rectangle: or None to record unbounded operations.
5131
5132 Creates a *RecordingSurface* which can be used to record all drawing
5133 operations at the highest level (that is, the level of paint, mask, stroke,
5134 fill and show_text_glyphs). The *RecordingSurface* can then be "replayed"
5135 against any target surface by using it as a source to drawing operations.
5136
5137 The recording phase of the *RecordingSurface* is careful to snapshot all
5138 necessary objects (paths, patterns, etc.), in order to achieve accurate
5139 replay.
5140
5141 .. versionadded:: 1.11.0
5142 """
5143
5144 def ink_extents(self) -> Tuple[float, float, float, float]:
5145 """
5146 * x0: the x-coordinate of the top-left of the ink bounding box
5147 * y0: the y-coordinate of the top-left of the ink bounding box
5148 * width: the width of the ink bounding box
5149 * height: the height of the ink bounding box
5150
5151 Measures the extents of the operations stored within the
5152 *RecordingSurface*. This is useful to compute the required size of an
5153 *ImageSurface* (or equivalent) into which to replay the full sequence of
5154 drawing operations.
5155
5156 .. versionadded:: 1.11.0
5157 """
5158
5159 def get_extents(self) -> Optional[Rectangle]:
5160 """
5161 :returns: a rectangle or :obj:`None` if the surface is unbounded.
5162
5163 Get the extents of the recording-surface.
5164
5165 .. versionadded:: 1.12.0
5166 """
5167
5168 class Region:
5169 """
5170 Region is a simple graphical data type representing an area of
5171 integer-aligned rectangles. They are often used on raster surfaces to track
5172 areas of interest, such as change or clip areas.
5173
5174 .. versionadded:: 1.11.0
5175 """
5176
5177 def __init__(self, rectangle: Union[RectangleInt, List[RectangleInt]]) -> None:
5178 """
5179 :param rectangle_int: a rectangle or a list of rectangle
5180
5181 Allocates a new empty region object or a region object with the
5182 containing rectangle(s).
5183 """
5184
5185 def copy(self) -> "Region":
5186 """
5187 :returns: A newly allocated :class:`Region`.
5188
5189 Allocates a new *Region* object copying the area from original.
5190 """
5191
5192 def get_extents(self) -> RectangleInt:
5193 """
5194 :returns: The bounding rectangle of region
5195 """
5196
5197 def num_rectangles(self) -> int:
5198 """
5199 :returns: The number of rectangles contained in region
5200 """
5201
5202 def get_rectangle(self, nth: int) -> RectangleInt:
5203 """
5204 :param nth: a number indicating which rectangle should be returned
5205 :returns: The *nth* rectangle from the region
5206 """
5207
5208 def is_empty(self) -> bool:
5209 """
5210 :returns: Whether region is empty
5211 """
5212
5213 def contains_point(self, x: int, y: int) -> bool:
5214 """
5215 :param x: The x coordinate of a point
5216 :param y: The y coordinate of a point
5217 :returns: Whether (x , y) is contained in the region
5218 """
5219
5220 def contains_rectangle(self, rectangle: RectangleInt) -> RegionOverlap:
5221 """
5222 :param rectangle: a region
5223 :returns: region overlap
5224
5225 Checks whether rectangle is inside, outside or partially contained in
5226 region
5227 """
5228
5229 def equal(self, region: "Region") -> bool:
5230 """
5231 :param region: a region
5232 :returns: Whether both regions contained the same coverage
5233 """
5234
5235 def translate(self, dx: int, dy: int) -> None:
5236 """
5237 :param dx: Amount to translate in the x direction
5238 :param dy: Amount to translate in the y direction
5239
5240 Translates region by (dx , dy ).
5241 """
5242
5243 def intersect(self, other: "Union[Region, RectangleInt]") -> "Region":
5244 """
5245 :param other: region or rectangle
5246 :returns: The intersection of the region and the passed region or
5247 rectangle
5248 """
5249
5250 def subtract(self, other: "Union[Region, RectangleInt]") -> "Region":
5251 """
5252 :param other: region or rectangle
5253 :returns: The result of the subtraction of the region and the passed
5254 region or rectangle
5255 """
5256
5257 def union(self, other: "Union[Region, RectangleInt]") -> "Region":
5258 """
5259 :param other: region or rectangle
5260 :returns: The union of the region and the passed region or rectangle
5261 """
5262
5263 def xor(self, other: "Union[Region, RectangleInt]") -> "Region":
5264 """
5265 :param other: region or rectangle
5266 :returns: The exclusive difference of the region and the passed region
5267 or rectangle
5268 """
5269
5270 class ScriptDevice(Device):
5271 """
5272 .. versionadded:: 1.14
5273 """
5274
5275 def __init__(self, fobj: Union[_FileLike, _PathLike]) -> None:
5276 """
5277 :param fobj: a filename or writable file object.
5278
5279 Creates a output device for emitting the script, used when creating the
5280 individual surfaces.
5281 """
5282
5283 def set_mode(self, mode: ScriptMode) -> None:
5284 """
5285 :param mode: the new mode
5286
5287 Change the output mode of the script
5288 """
5289
5290 def get_mode(self) -> ScriptMode:
5291 """
5292 :returns: the current output mode of the script
5293
5294 Queries the script for its current output mode.
5295 """
5296
5297 def write_comment(self, comment: str) -> None:
5298 """
5299 :param comment: the string to emit
5300
5301 Emit a string verbatim into the script.
5302 """
5303
5304 def from_recording_surface(self, recording_surface: RecordingSurface) -> None:
5305 """
5306 :param recording_surface:
5307 the recording surface to replay
5308 :raises cairo.Error:
5309
5310 Converts the record operations in recording_surface into a script.
5311 """
5312
5313 class ScriptSurface(Surface):
5314 """
5315 The script surface provides the ability to render to a native script that
5316 matches the cairo drawing model. The scripts can be replayed using tools
5317 under the util/cairo-script directory, or with cairo-perf-trace.
5318
5319 .. versionadded:: 1.14
5320 """
5321
5322 def __init__(self, script: ScriptDevice, content: Content, width: float, height: float) -> None:
5323 """
5324 :param script: the script (output device)
5325 :param content: the content of the surface
5326 :param width: width in pixels
5327 :param height: height in pixels
5328 :raises cairo.Error:
5329
5330 Create a new surface that will emit its rendering through ``script``.
5331 """
5332
5333 @classmethod
5334 def create_for_target(cls, script: ScriptDevice, target: Surface) -> "ScriptSurface":
5335 """
5336 :param script: the script (output device)
5337 :param target: a target surface to wrap
5338 :raises cairo.Error:
5339
5340 Create a proxy surface that will render to ``target`` and record the
5341 operations to ``device``.
5342
5343 .. versionadded:: 1.14
5344 """
5345
5346 class Win32Surface(Surface):
5347 """
5348 The Microsoft Windows surface is used to render cairo graphics to Microsoft
5349 Windows windows, bitmaps, and printing device contexts.
5350 """
5351
5352 def __init__(self, hdc: int) -> None:
5353 """
5354 :param hdc: the DC to create a surface for
5355 :type hdc: int
5356
5357 Creates a cairo surface that targets the given DC. The DC will be
5358 queried for its initial clip extents, and this will be used as the size
5359 of the cairo surface. The resulting surface will always be of format
5360 cairo.FORMAT_RGB24, see :class:`cairo.Format`.
5361 """
5362
5363 class Win32PrintingSurface(Surface):
5364 """
5365 The Win32PrintingSurface is a multi-page vector surface type.
5366 """
5367
5368 def __init__(self, hdc: int) -> None:
5369 """
5370 :param hdc: the DC to create a surface for
5371 :returns: the newly created surface
5372
5373 Creates a cairo surface that targets the given DC. The DC will be queried
5374 for its initial clip extents, and this will be used as the size of the
5375 cairo surface. The DC should be a printing DC; antialiasing will be
5376 ignored, and GDI will be used as much as possible to draw to the surface.
5377
5378 The returned surface will be wrapped using the paginated surface to provide
5379 correct complex rendering behaviour; :meth:`cairo.Surface.show_page` and
5380 associated methods must be used for correct output.
5381 """
5382
5383 class SolidPattern(Pattern):
5384
5385 def __init__(self, red: float, green: float, blue: float, alpha: float=1.0) -> None:
5386 """
5387 :param red: red component of the color
5388 :param green: green component of the color
5389 :param blue: blue component of the color
5390 :param alpha: alpha component of the color
5391
5392 Creates a new *SolidPattern* corresponding to a translucent color. The
5393 color components are floating point numbers in the range 0 to 1. If the
5394 values passed in are outside that range, they will be clamped.
5395 """
5396
5397 def get_rgba(self) -> Tuple[float, float, float, float]:
5398 """
5399 :returns: (red, green, blue, alpha) a tuple of float
5400
5401 Gets the solid color for a *SolidPattern*.
5402
5403 .. versionadded:: 1.4
5404 """
5405
5406 class SurfaceObserverMode(_IntEnum):
5407 """
5408 Whether operations should be recorded.
5409
5410 .. versionadded:: 1.14
5411 """
5412
5413 NORMAL: "SurfaceObserverMode" = ...
5414 """no recording is done"""
5415
5416 RECORD_OPERATIONS: "SurfaceObserverMode" = ...
5417 """operations are recorded"""
5418
5419 class TeeSurface(Surface):
5420 """
5421 This surface supports redirecting all its input to multiple surfaces.
5422
5423 .. versionadded:: 1.14
5424 """
5425
5426 def __init__(self, master: Surface) -> None: ...
5427
5428 def add(self, target: Surface) -> None:
5429 """
5430 :param target:
5431 :raises cairo.Error:
5432
5433 Add the surface
5434
5435 .. versionadded:: 1.14
5436 """
5437
5438 def remove(self, target: Surface) -> None:
5439 """
5440 :param target:
5441 :raises cairo.Error:
5442
5443 Remove the surface
5444
5445 .. versionadded:: 1.14
5446 """
5447
5448 def index(self, index: int) -> Surface:
5449 """
5450 :param index:
5451 :raises cairo.Error:
5452
5453 Returns the surface at index ``index``. The master surface is
5454 at index 0.
5455
5456 .. versionadded:: 1.14
5457 """
5458
5459 class ToyFontFace(FontFace):
5460 """
5461 The *cairo.ToyFontFace* class can be used instead of :meth:`Context.select_font_face` to create a toy font independently of a context.
5462
5463 .. versionadded:: 1.8.4
5464 """
5465
5466 def __init__(self, family: str, slant: FontSlant=..., weight: FontWeight=...) -> None:
5467 """
5468 :param family: a font family name
5469 :param slant: the font slant of the font,
5470 defaults to :attr:`cairo.FontSlant.NORMAL`.
5471 :param weight: the font weight of the font,
5472 defaults to :attr:`cairo.FontWeight.NORMAL`.
5473
5474 Creates a *ToyFontFace* from a triplet of family, slant, and weight. These
5475 font faces are used in implementation of the the "toy" font API.
5476
5477 If family is the zero-length string "", the platform-specific default
5478 family is assumed. The default family then can be queried using
5479 :meth:`.get_family`.
5480
5481 The :meth:`Context.select_font_face` method uses this to create font
5482 faces. See that function for limitations of toy font faces.
5483 """
5484
5485 def get_family(self) -> str:
5486 """
5487 :returns: the family name of a toy font
5488
5489 .. versionadded:: 1.8.4
5490 """
5491
5492 def get_slant(self) -> FontSlant:
5493 """
5494 :returns: the font slant value
5495
5496 .. versionadded:: 1.8.4
5497 """
5498
5499 def get_weight(self) -> FontWeight:
5500 """
5501 :returns: the font weight value
5502
5503 .. versionadded:: 1.8.4
5504 """
5505
5506 class XCBSurface(Surface):
5507 """
5508 The XCB surface is used to render cairo graphics to X Window System windows
5509 and pixmaps using the XCB library.
5510
5511 Note that the XCB surface automatically takes advantage of the X render
5512 extension if it is available.
5513 """
5514
5515 def __init__(self, connection: Any, drawable: Any, visualtype: Any, width: int, height: int) -> None:
5516 """
5517 :param connection: an XCB connection
5518 :param drawable: a X drawable
5519 :param visualtype: a X visualtype
5520 :param width: The surface width
5521 :param height: The surface height
5522
5523 Creates a cairo surface that targets the given drawable (pixmap or window).
5524
5525 .. note:: This type isn't implemented. Please file a bug if you need it.
5526 """
5527
5528 def set_size(self, width: int, height: int) -> None:
5529 """
5530 :param width: The width of the surface
5531 :param height: The height of the surface
5532
5533 Informs cairo of the new size of the X Drawable underlying the surface.
5534 For a surface created for a Window (rather than a Pixmap), this function
5535 must be called each time the size of the window changes. (For a
5536 subwindow, you are normally resizing the window yourself, but for a
5537 toplevel window, it is necessary to listen for ConfigureNotify events.)
5538
5539 A Pixmap can never change size, so it is never necessary to call this
5540 function on a surface created for a Pixmap.
5541 """
5542
5543 class XlibSurface(Surface):
5544 """
5545 The XLib surface is used to render cairo graphics to X Window System windows
5546 and pixmaps using the XLib library.
5547
5548 Note that the XLib surface automatically takes advantage of X render
5549 extension if it is available.
5550
5551 .. note:: *XlibSurface* cannot be instantiated directly because Python
5552 interaction with Xlib would require open source Python bindings to Xlib
5553 which provided a C API.
5554 However, an *XlibSurface* instance can be returned from a function call
5555 when using pygtk http://www.pygtk.org/.
5556 """
5557
5558 def get_depth(self) -> int:
5559 """
5560 :returns: the number of bits used to represent each pixel value.
5561
5562 .. versionadded:: 1.2
5563 """
5564
5565 def get_height(self) -> int:
5566 """
5567 :returns: the height of the X Drawable underlying the surface in pixels.
5568
5569 .. versionadded:: 1.2
5570 """
5571
5572 def get_width(self) -> int:
5573 """
5574 :returns: the width of the X Drawable underlying the surface in pixels.
5575
5576 .. versionadded:: 1.2
5577 """
5578
5579 def get_include() -> str:
5580 """
5581 :returns: a path to the directory containing the C header files
5582
5583 Gives the include path which should be passed to the compiler.
5584
5585 .. versionadded:: 1.16.0
5586 """
5587
5588 MIME_TYPE_JP2: str = ...
5589 """
5590 The Joint Photographic Experts Group (JPEG) 2000 image coding standard
5591 (ISO/IEC 15444-1).
5592
5593 .. versionadded:: 1.12.0
5594 """
5595
5596 MIME_TYPE_JPEG: str = ...
5597 """
5598 The Joint Photographic Experts Group (JPEG) image coding standard (ISO/IEC
5599 10918-1).
5600
5601 .. versionadded:: 1.12.0
5602 """
5603
5604 MIME_TYPE_PNG: str = ...
5605 """
5606 The Portable Network Graphics image file format (ISO/IEC 15948).
5607
5608 .. versionadded:: 1.12.0
5609 """
5610
5611 MIME_TYPE_URI: str = ...
5612 """
5613 URI for an image file (unofficial MIME type).
5614
5615 .. versionadded:: 1.12.0
5616 """
5617
5618 MIME_TYPE_UNIQUE_ID: str = ...
5619 """
5620 Unique identifier for a surface (cairo specific MIME type). All surfaces
5621 with the same unique identifier will only be embedded once.
5622
5623 .. versionadded:: 1.12.0
5624 """
5625
5626 MIME_TYPE_CCITT_FAX: str = ...
5627 """
5628 Group 3 or Group 4 CCITT facsimile encoding (International
5629 Telecommunication Union, Recommendations T.4 and T.6.)
5630
5631 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
5632 """
5633
5634 MIME_TYPE_CCITT_FAX_PARAMS: str = ...
5635 """
5636 Decode parameters for Group 3 or Group 4 CCITT facsimile encoding. See
5637 `CCITT Fax Images
5638 <https://cairographics.org/manual/cairo-PDF-Surfaces.html#ccitt>`__.
5639
5640 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
5641 """
5642
5643 MIME_TYPE_EPS: str = ...
5644 """
5645 Encapsulated PostScript file. Encapsulated PostScript File Format
5646 Specification
5647
5648 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
5649 """
5650
5651 MIME_TYPE_EPS_PARAMS: str = ...
5652 """
5653 Embedding parameters Encapsulated PostScript data. See Embedding EPS files.
5654
5655 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
5656 """
5657
5658 MIME_TYPE_JBIG2: str = ...
5659 """
5660 Joint Bi-level Image Experts Group image coding standard (ISO/IEC 11544).
5661
5662 .. versionadded:: 1.18.0
5663 """
5664
5665 MIME_TYPE_JBIG2_GLOBAL: str = ...
5666 """
5667 Joint Bi-level Image Experts Group image coding standard (ISO/IEC 11544)
5668 global segment.
5669
5670 .. versionadded:: 1.18.0
5671 """
5672
5673 MIME_TYPE_JBIG2_GLOBAL_ID: str = ...
5674 """
5675 An unique identifier shared by a JBIG2 global segment and all JBIG2 images
5676 that depend on the global segment.
5677
5678 .. versionadded:: 1.18.0
5679 """
5680
5681 TAG_DEST: str = ...
5682 """
5683 Create a destination for a hyperlink. Destination tag attributes are
5684 detailed at Destinations.
5685
5686 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
5687 """
5688
5689 TAG_LINK: str = ...
5690 """
5691 Create hyperlink. Link tag attributes are detailed at Links.
5692
5693 .. versionadded:: 1.18.0 Only available with cairo 1.15.10+
5694 """
5695
5696 TAG_CONTENT: str = ...
5697 """
5698 Create a content tag.
5699
5700 .. versionadded:: 1.25.0 Only available with cairo 1.18.0+
5701 """
5702
5703 TAG_CONTENT_REF: str = ...
5704 """
5705 Create a content reference tag.
5706
5707 .. versionadded:: 1.25.0 Only available with cairo 1.18.0+
5708 """
5709
5710 CAPI: Any = ...
5711
5712 ANTIALIAS_BEST = Antialias.BEST
5713 ANTIALIAS_DEFAULT = Antialias.DEFAULT
5714 ANTIALIAS_FAST = Antialias.FAST
5715 ANTIALIAS_GOOD = Antialias.GOOD
5716 ANTIALIAS_GRAY = Antialias.GRAY
5717 ANTIALIAS_NONE = Antialias.NONE
5718 ANTIALIAS_SUBPIXEL = Antialias.SUBPIXEL
5719 CONTENT_ALPHA = Content.ALPHA
5720 CONTENT_COLOR = Content.COLOR
5721 CONTENT_COLOR_ALPHA = Content.COLOR_ALPHA
5722 EXTEND_NONE = Extend.NONE
5723 EXTEND_PAD = Extend.PAD
5724 EXTEND_REFLECT = Extend.REFLECT
5725 EXTEND_REPEAT = Extend.REPEAT
5726 FILL_RULE_EVEN_ODD = FillRule.EVEN_ODD
5727 FILL_RULE_WINDING = FillRule.WINDING
5728 FILTER_BEST = Filter.BEST
5729 FILTER_BILINEAR = Filter.BILINEAR
5730 FILTER_FAST = Filter.FAST
5731 FILTER_GAUSSIAN = Filter.GAUSSIAN
5732 FILTER_GOOD = Filter.GOOD
5733 FILTER_NEAREST = Filter.NEAREST
5734 FONT_SLANT_ITALIC = FontSlant.ITALIC
5735 FONT_SLANT_NORMAL = FontSlant.NORMAL
5736 FONT_SLANT_OBLIQUE = FontSlant.OBLIQUE
5737 FONT_WEIGHT_BOLD = FontWeight.BOLD
5738 FONT_WEIGHT_NORMAL = FontWeight.NORMAL
5739 FORMAT_A1 = Format.A1
5740 FORMAT_A8 = Format.A8
5741 FORMAT_ARGB32 = Format.ARGB32
5742 FORMAT_INVALID = Format.INVALID
5743 FORMAT_RGB16_565 = Format.RGB16_565
5744 FORMAT_RGB24 = Format.RGB24
5745 FORMAT_RGB30 = Format.RGB30
5746 FORMAT_RGB96F = Format.RGB96F
5747 FORMAT_RGBA128F = Format.RGBA128F
5748 HINT_METRICS_DEFAULT = HintMetrics.DEFAULT
5749 HINT_METRICS_OFF = HintMetrics.OFF
5750 HINT_METRICS_ON = HintMetrics.ON
5751 HINT_STYLE_DEFAULT = HintStyle.DEFAULT
5752 HINT_STYLE_FULL = HintStyle.FULL
5753 HINT_STYLE_MEDIUM = HintStyle.MEDIUM
5754 HINT_STYLE_NONE = HintStyle.NONE
5755 HINT_STYLE_SLIGHT = HintStyle.SLIGHT
5756 LINE_CAP_BUTT = LineCap.BUTT
5757 LINE_CAP_ROUND = LineCap.ROUND
5758 LINE_CAP_SQUARE = LineCap.SQUARE
5759 LINE_JOIN_BEVEL = LineJoin.BEVEL
5760 LINE_JOIN_MITER = LineJoin.MITER
5761 LINE_JOIN_ROUND = LineJoin.ROUND
5762 OPERATOR_ADD = Operator.ADD
5763 OPERATOR_ATOP = Operator.ATOP
5764 OPERATOR_CLEAR = Operator.CLEAR
5765 OPERATOR_COLOR_BURN = Operator.COLOR_BURN
5766 OPERATOR_COLOR_DODGE = Operator.COLOR_DODGE
5767 OPERATOR_DARKEN = Operator.DARKEN
5768 OPERATOR_DEST = Operator.DEST
5769 OPERATOR_DEST_ATOP = Operator.DEST_ATOP
5770 OPERATOR_DEST_IN = Operator.DEST_IN
5771 OPERATOR_DEST_OUT = Operator.DEST_OUT
5772 OPERATOR_DEST_OVER = Operator.DEST_OVER
5773 OPERATOR_DIFFERENCE = Operator.DIFFERENCE
5774 OPERATOR_EXCLUSION = Operator.EXCLUSION
5775 OPERATOR_HARD_LIGHT = Operator.HARD_LIGHT
5776 OPERATOR_HSL_COLOR = Operator.HSL_COLOR
5777 OPERATOR_HSL_HUE = Operator.HSL_HUE
5778 OPERATOR_HSL_LUMINOSITY = Operator.HSL_LUMINOSITY
5779 OPERATOR_HSL_SATURATION = Operator.HSL_SATURATION
5780 OPERATOR_IN = Operator.IN
5781 OPERATOR_LIGHTEN = Operator.LIGHTEN
5782 OPERATOR_MULTIPLY = Operator.MULTIPLY
5783 OPERATOR_OUT = Operator.OUT
5784 OPERATOR_OVER = Operator.OVER
5785 OPERATOR_OVERLAY = Operator.OVERLAY
5786 OPERATOR_SATURATE = Operator.SATURATE
5787 OPERATOR_SCREEN = Operator.SCREEN
5788 OPERATOR_SOFT_LIGHT = Operator.SOFT_LIGHT
5789 OPERATOR_SOURCE = Operator.SOURCE
5790 OPERATOR_XOR = Operator.XOR
5791 PATH_CLOSE_PATH = PathDataType.CLOSE_PATH
5792 PATH_CURVE_TO = PathDataType.CURVE_TO
5793 PATH_LINE_TO = PathDataType.LINE_TO
5794 PATH_MOVE_TO = PathDataType.MOVE_TO
5795 PDF_VERSION_1_4 = PDFVersion.VERSION_1_4
5796 PDF_VERSION_1_5 = PDFVersion.VERSION_1_5
5797 PDF_VERSION_1_6 = PDFVersion.VERSION_1_6
5798 PDF_VERSION_1_7 = PDFVersion.VERSION_1_7
5799 PS_LEVEL_2 = PSLevel.LEVEL_2
5800 PS_LEVEL_3 = PSLevel.LEVEL_3
5801 REGION_OVERLAP_IN = RegionOverlap.IN
5802 REGION_OVERLAP_OUT = RegionOverlap.OUT
5803 REGION_OVERLAP_PART = RegionOverlap.PART
5804 SCRIPT_MODE_ASCII = ScriptMode.ASCII
5805 SCRIPT_MODE_BINARY = ScriptMode.BINARY
5806 STATUS_CLIP_NOT_REPRESENTABLE = Status.CLIP_NOT_REPRESENTABLE
5807 STATUS_DEVICE_ERROR = Status.DEVICE_ERROR
5808 STATUS_DEVICE_FINISHED = Status.DEVICE_FINISHED
5809 STATUS_DEVICE_TYPE_MISMATCH = Status.DEVICE_TYPE_MISMATCH
5810 STATUS_FILE_NOT_FOUND = Status.FILE_NOT_FOUND
5811 STATUS_FONT_TYPE_MISMATCH = Status.FONT_TYPE_MISMATCH
5812 STATUS_INVALID_CLUSTERS = Status.INVALID_CLUSTERS
5813 STATUS_INVALID_CONTENT = Status.INVALID_CONTENT
5814 STATUS_INVALID_DASH = Status.INVALID_DASH
5815 STATUS_INVALID_DSC_COMMENT = Status.INVALID_DSC_COMMENT
5816 STATUS_INVALID_FORMAT = Status.INVALID_FORMAT
5817 STATUS_INVALID_INDEX = Status.INVALID_INDEX
5818 STATUS_INVALID_MATRIX = Status.INVALID_MATRIX
5819 STATUS_INVALID_MESH_CONSTRUCTION = Status.INVALID_MESH_CONSTRUCTION
5820 STATUS_INVALID_PATH_DATA = Status.INVALID_PATH_DATA
5821 STATUS_INVALID_POP_GROUP = Status.INVALID_POP_GROUP
5822 STATUS_INVALID_RESTORE = Status.INVALID_RESTORE
5823 STATUS_INVALID_SIZE = Status.INVALID_SIZE
5824 STATUS_INVALID_SLANT = Status.INVALID_SLANT
5825 STATUS_INVALID_STATUS = Status.INVALID_STATUS
5826 STATUS_INVALID_STRIDE = Status.INVALID_STRIDE
5827 STATUS_INVALID_STRING = Status.INVALID_STRING
5828 STATUS_INVALID_VISUAL = Status.INVALID_VISUAL
5829 STATUS_INVALID_WEIGHT = Status.INVALID_WEIGHT
5830 STATUS_JBIG2_GLOBAL_MISSING = Status.JBIG2_GLOBAL_MISSING
5831 STATUS_LAST_STATUS = Status.LAST_STATUS
5832 STATUS_NEGATIVE_COUNT = Status.NEGATIVE_COUNT
5833 STATUS_NO_CURRENT_POINT = Status.NO_CURRENT_POINT
5834 STATUS_NO_MEMORY = Status.NO_MEMORY
5835 STATUS_NULL_POINTER = Status.NULL_POINTER
5836 STATUS_PATTERN_TYPE_MISMATCH = Status.PATTERN_TYPE_MISMATCH
5837 STATUS_READ_ERROR = Status.READ_ERROR
5838 STATUS_SUCCESS = Status.SUCCESS
5839 STATUS_SURFACE_FINISHED = Status.SURFACE_FINISHED
5840 STATUS_SURFACE_TYPE_MISMATCH = Status.SURFACE_TYPE_MISMATCH
5841 STATUS_TEMP_FILE_ERROR = Status.TEMP_FILE_ERROR
5842 STATUS_USER_FONT_ERROR = Status.USER_FONT_ERROR
5843 STATUS_USER_FONT_IMMUTABLE = Status.USER_FONT_IMMUTABLE
5844 STATUS_USER_FONT_NOT_IMPLEMENTED = Status.USER_FONT_NOT_IMPLEMENTED
5845 STATUS_WRITE_ERROR = Status.WRITE_ERROR
5846 SUBPIXEL_ORDER_BGR = SubpixelOrder.BGR
5847 SUBPIXEL_ORDER_DEFAULT = SubpixelOrder.DEFAULT
5848 SUBPIXEL_ORDER_RGB = SubpixelOrder.RGB
5849 SUBPIXEL_ORDER_VBGR = SubpixelOrder. VBGR
5850 SUBPIXEL_ORDER_VRGB = SubpixelOrder.VRGB
5851 SURFACE_OBSERVER_NORMAL = SurfaceObserverMode.NORMAL
5852 SURFACE_OBSERVER_RECORD_OPERATIONS = SurfaceObserverMode.RECORD_OPERATIONS
5853 SVG_VERSION_1_1 = SVGVersion.VERSION_1_1
5854 SVG_VERSION_1_2 = SVGVersion.VERSION_1_2
5855 TEXT_CLUSTER_FLAG_BACKWARD = TextClusterFlags.BACKWARD
5856 PDF_METADATA_TITLE = PDFMetadata.TITLE
5857 PDF_METADATA_AUTHOR = PDFMetadata.AUTHOR
5858 PDF_METADATA_SUBJECT = PDFMetadata.SUBJECT
5859 PDF_METADATA_KEYWORDS = PDFMetadata.KEYWORDS
5860 PDF_METADATA_CREATOR = PDFMetadata.CREATOR
5861 PDF_METADATA_CREATE_DATE = PDFMetadata.CREATE_DATE
5862 PDF_METADATA_MOD_DATE = PDFMetadata.MOD_DATE
5863 SVG_UNIT_USER = SVGUnit.USER
5864 SVG_UNIT_EM = SVGUnit.EM
5865 SVG_UNIT_EX = SVGUnit.EX
5866 SVG_UNIT_PX = SVGUnit.PX
5867 SVG_UNIT_IN = SVGUnit.IN
5868 SVG_UNIT_CM = SVGUnit.CM
5869 SVG_UNIT_MM = SVGUnit.MM
5870 SVG_UNIT_PT = SVGUnit.PT
5871 SVG_UNIT_PC = SVGUnit.PC
5872 SVG_UNIT_PERCENT = SVGUnit.PERCENT
5873 STATUS_TAG_ERROR = Status.TAG_ERROR
5874 STATUS_FREETYPE_ERROR = Status.FREETYPE_ERROR
5875 STATUS_WIN32_GDI_ERROR = Status.WIN32_GDI_ERROR
5876 STATUS_PNG_ERROR = Status.PNG_ERROR
5877 STATUS_DWRITE_ERROR = Status.DWRITE_ERROR
5878 STATUS_SVG_FONT_ERROR = Status.SVG_FONT_ERROR
5879 PDF_OUTLINE_FLAG_OPEN = PDFOutlineFlags.OPEN
5880 PDF_OUTLINE_FLAG_BOLD = PDFOutlineFlags.BOLD
5881 PDF_OUTLINE_FLAG_ITALIC = PDFOutlineFlags.ITALIC
5882 COLOR_MODE_DEFAULT = ColorMode.DEFAULT
5883 COLOR_MODE_NO_COLOR = ColorMode.NO_COLOR
5884 COLOR_MODE_COLOR = ColorMode.COLOR
5885 DITHER_NONE = Dither.NONE
5886 DITHER_DEFAULT = Dither.DEFAULT
5887 DITHER_FAST = Dither.FAST
5888 DITHER_GOOD = Dither.GOOD
5889 DITHER_BEST = Dither.BEST