thorvg-python 1.0.1__py3-none-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thorvg_python/__init__.py +35 -0
- thorvg_python/animation/__init__.py +251 -0
- thorvg_python/animation/lottie.py +162 -0
- thorvg_python/base.py +447 -0
- thorvg_python/canvas/__init__.py +246 -0
- thorvg_python/canvas/sw.py +196 -0
- thorvg_python/engine.py +371 -0
- thorvg_python/gradient/__init__.py +248 -0
- thorvg_python/gradient/linear.py +130 -0
- thorvg_python/gradient/radial.py +114 -0
- thorvg_python/paint/__init__.py +432 -0
- thorvg_python/paint/picture.py +226 -0
- thorvg_python/paint/scene.py +123 -0
- thorvg_python/paint/shape.py +1082 -0
- thorvg_python/paint/text.py +198 -0
- thorvg_python/py.typed +0 -0
- thorvg_python/saver.py +118 -0
- thorvg_python/thorvg-0.dll +0 -0
- thorvg_python-1.0.1.dist-info/METADATA +647 -0
- thorvg_python-1.0.1.dist-info/RECORD +23 -0
- thorvg_python-1.0.1.dist-info/WHEEL +5 -0
- thorvg_python-1.0.1.dist-info/licenses/LICENSE +504 -0
- thorvg_python-1.0.1.dist-info/top_level.txt +1 -0
thorvg_python/base.py
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import ctypes
|
|
3
|
+
from enum import IntEnum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CanvasStruct(ctypes.Structure):
|
|
7
|
+
"""A structure responsible for managing and drawing graphical elements.
|
|
8
|
+
|
|
9
|
+
It sets up the target buffer, which can be drawn on the screen. It stores the PaintStruct objects (Shape, Scene, Picture).
|
|
10
|
+
|
|
11
|
+
.. note::
|
|
12
|
+
You should use ``Canvas`` class instead.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PaintStruct(ctypes.Structure):
|
|
17
|
+
"""A structure representing a graphical element.
|
|
18
|
+
|
|
19
|
+
.. warning::
|
|
20
|
+
The PaintStruct objects cannot be shared between Canvases.
|
|
21
|
+
|
|
22
|
+
.. note::
|
|
23
|
+
You should use ``Paint`` class instead.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class GradientStruct(ctypes.Structure):
|
|
28
|
+
"""A structure representing a gradient fill of a PaintStruct object.
|
|
29
|
+
|
|
30
|
+
.. note::
|
|
31
|
+
You should use ``LinearGradient`` or ``RadialGradient`` class instead.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SaverStruct(ctypes.Structure):
|
|
36
|
+
"""A structure representing an object that enables to save a PaintStruct object into a file.
|
|
37
|
+
|
|
38
|
+
.. note::
|
|
39
|
+
You should use `Saver` class instead.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AnimationStruct(ctypes.Structure):
|
|
44
|
+
"""A structure representing an animation controller object.
|
|
45
|
+
|
|
46
|
+
.. note::
|
|
47
|
+
You should use ``Animation`` class instead.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class EngineBackend(IntEnum):
|
|
52
|
+
"""Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed."""
|
|
53
|
+
|
|
54
|
+
SW = 2 #: CPU rasterizer.
|
|
55
|
+
GL = 4 #: OpenGL rasterizer.
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_param(cls, obj: int) -> int:
|
|
59
|
+
return int(obj)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Result(IntEnum):
|
|
63
|
+
"""Enumeration specifying the result from the APIs.
|
|
64
|
+
|
|
65
|
+
All ThorVG APIs could potentially return one of the values in the list.
|
|
66
|
+
Please note that some APIs may additionally specify the reasons that trigger their return values.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
#: The value returned in case of a correct request execution.
|
|
70
|
+
SUCCESS = 0
|
|
71
|
+
|
|
72
|
+
#: The value returned in the event of a problem with the arguments given to the API
|
|
73
|
+
#: - e.g. empty paths or null pointers.
|
|
74
|
+
INVALID_ARGUMENT = 1
|
|
75
|
+
|
|
76
|
+
#: The value returned in case the request cannot be processed
|
|
77
|
+
#: - e.g. asking for properties of an object, which does not exist.
|
|
78
|
+
INSUFFICIENT_CONDITION = 2
|
|
79
|
+
|
|
80
|
+
#: The value returned in case of unsuccessful memory allocation.
|
|
81
|
+
FAILED_ALLOCATION = 3
|
|
82
|
+
|
|
83
|
+
#: The value returned in the event of bad memory handling
|
|
84
|
+
#: - e.g. failing in pointer releasing or casting
|
|
85
|
+
MEMORY_CORRUPTION = 4
|
|
86
|
+
|
|
87
|
+
#: The value returned in case of choosing unsupported engine features(options).
|
|
88
|
+
NOT_SUPPORTED = 5
|
|
89
|
+
|
|
90
|
+
#: The value returned in all other cases.
|
|
91
|
+
UNKNOWN = 6
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def from_param(cls, obj: int) -> int:
|
|
95
|
+
return int(obj)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class CompositeMethod(IntEnum):
|
|
99
|
+
"""Enumeration indicating the method used in the composition of two objects - the target and the source.
|
|
100
|
+
|
|
101
|
+
.. deprecated:: 0.15
|
|
102
|
+
CLIP_PATH deprecated. Use Paint::clip() instead.
|
|
103
|
+
|
|
104
|
+
.. versionchanged:: 0.9
|
|
105
|
+
Added LUMA_MASK
|
|
106
|
+
|
|
107
|
+
.. versionchanged:: 0.14
|
|
108
|
+
Added INVERSE_LUMA_MAS
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
#: No composition is applied.
|
|
112
|
+
NONE = 0
|
|
113
|
+
|
|
114
|
+
#: The intersection of the source and the target is determined and only the resulting pixels
|
|
115
|
+
#: from the source are rendered. Note that ClipPath only supports the Shape type.
|
|
116
|
+
CLIP_PATH = 1
|
|
117
|
+
|
|
118
|
+
#: The pixels of the source and the target are alpha blended.
|
|
119
|
+
#: As a result, only the part of the source, which intersects with the target is visible.
|
|
120
|
+
ALPHA_MASK = 2
|
|
121
|
+
|
|
122
|
+
#: The pixels of the source and the complement to the target's pixels are alpha blended.
|
|
123
|
+
#: As a result, only the part of the source which is not covered by the target is visible.
|
|
124
|
+
INVERSE_ALPHA_MASK = 3
|
|
125
|
+
|
|
126
|
+
#: The source pixels are converted to grayscale (luma value) and alpha blended with the target.
|
|
127
|
+
#: As a result, only the part of the source which intersects with the target is visible.
|
|
128
|
+
LUMA_MASK = 4
|
|
129
|
+
|
|
130
|
+
#: The source pixels are converted to grayscale (luma value) and complement to the target's pixels
|
|
131
|
+
#: are alpha blended. As a result, only the part of the source which is not covered by the target is visible.
|
|
132
|
+
INVERSE_LUMA_MASK = 5
|
|
133
|
+
|
|
134
|
+
@classmethod
|
|
135
|
+
def from_param(cls, obj: int) -> int:
|
|
136
|
+
return int(obj)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class BlendMethod(IntEnum):
|
|
140
|
+
"""Enumeration indicates the method used for blending paint.
|
|
141
|
+
Please refer to the respective formulas for each method.
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
#: Perform the alpha blending (default). S if (Sa == 255),
|
|
145
|
+
#: otherwise (Sa * S) + (255 - Sa) * D
|
|
146
|
+
NORMAL = 0
|
|
147
|
+
|
|
148
|
+
#: Takes the RGB channel values from 0 to 255 of each pixel in the top layer and
|
|
149
|
+
#: multiplies them with the values for the corresponding pixel from the bottom layer.
|
|
150
|
+
#: (S * D)
|
|
151
|
+
MULTIPLY = 1
|
|
152
|
+
|
|
153
|
+
#: The values of the pixels in the two layers are inverted, multiplied, and then inverted again.
|
|
154
|
+
#: (S + D) - (S * D)
|
|
155
|
+
SCREEN = 2
|
|
156
|
+
|
|
157
|
+
#: Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da),
|
|
158
|
+
#: otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
|
|
159
|
+
OVERLAY = 3
|
|
160
|
+
|
|
161
|
+
#: Creates a pixel that retains the smallest components of the top and bottom layer pixels.
|
|
162
|
+
#: min(S, D)
|
|
163
|
+
DARKEN = 4
|
|
164
|
+
|
|
165
|
+
#: Opposite action of Darken. max(S, D)
|
|
166
|
+
LIGHTEN = 5
|
|
167
|
+
|
|
168
|
+
#: Divides the bottom layer by the inverted top layer. D / (255 - S)
|
|
169
|
+
COLORDODGE = 6
|
|
170
|
+
|
|
171
|
+
#: Divides the inverted bottom layer by the top layer, then inverts the result.
|
|
172
|
+
#: 255 - (255 - D) / S
|
|
173
|
+
COLORBURN = 7
|
|
174
|
+
|
|
175
|
+
#: Same as Overlay but with color roles reversed. (2 * S * D) if (S < Sa),
|
|
176
|
+
#: otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
|
|
177
|
+
HARDLIGHT = 8
|
|
178
|
+
|
|
179
|
+
#: Same as Overlay but applying pure black or white does not result in pure black or white.
|
|
180
|
+
#: (1 - 2 * S) * (D ^ 2) + (2 * S * D)
|
|
181
|
+
SOFTLIGHT = 9
|
|
182
|
+
|
|
183
|
+
#: Subtracts the bottom layer from the top layer or vice versa, always non-negative.
|
|
184
|
+
#: (S - D) if (S > D), otherwise (D - S)
|
|
185
|
+
DIFFERENCE = 10
|
|
186
|
+
|
|
187
|
+
#: Result is twice the product of the top and bottom layers, subtracted from their sum.
|
|
188
|
+
#: S + D - (2 * S * D)
|
|
189
|
+
EXCLUSION = 11
|
|
190
|
+
|
|
191
|
+
#: Reserved. Not supported.
|
|
192
|
+
HUE = 12
|
|
193
|
+
|
|
194
|
+
#: Reserved. Not supported.
|
|
195
|
+
SATURATION = 13
|
|
196
|
+
|
|
197
|
+
#: Reserved. Not supported.
|
|
198
|
+
COLOR = 14
|
|
199
|
+
|
|
200
|
+
#: Reserved. Not supported.
|
|
201
|
+
LUMINOSITY = 15
|
|
202
|
+
|
|
203
|
+
#: Simply adds pixel values of one layer with the other. (S + D)
|
|
204
|
+
ADD = 16
|
|
205
|
+
|
|
206
|
+
#: Reserved. Not supported.
|
|
207
|
+
HARDMIX = 17
|
|
208
|
+
|
|
209
|
+
@classmethod
|
|
210
|
+
def from_param(cls, obj: int) -> int:
|
|
211
|
+
return int(obj)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class Identifier(IntEnum):
|
|
215
|
+
"""see TvgType
|
|
216
|
+
|
|
217
|
+
.. deprecated:: 0.15
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
UNDEF = 0 #: Undefined type.
|
|
221
|
+
SHAPE = 1 #: A shape type paint.
|
|
222
|
+
SCENE = 2 #: A scene type paint.
|
|
223
|
+
PICTURE = 3 #: A picture type paint.
|
|
224
|
+
LINEAR_GRAD = 4 #: A linear gradient type.
|
|
225
|
+
RADIAL_GRAD = 5 #: A radial gradient type.
|
|
226
|
+
TEXT = 6 #: A text type paint.
|
|
227
|
+
|
|
228
|
+
@classmethod
|
|
229
|
+
def from_param(cls, obj: int) -> int:
|
|
230
|
+
return int(obj)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class TvgType(IntEnum):
|
|
234
|
+
"""Enumeration indicating the ThorVG object type value.
|
|
235
|
+
|
|
236
|
+
ThorVG's drawing objects can return object type values, allowing you to identify the specific type of each object.
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
UNDEF = 0 #: Undefined type.
|
|
240
|
+
SHAPE = 1 #: A shape type paint.
|
|
241
|
+
SCENE = 2 #: A scene type paint.
|
|
242
|
+
PICTURE = 3 #: A picture type paint.
|
|
243
|
+
TEXT = 4 #: A text type paint.
|
|
244
|
+
LINEAR_GRAD = 10 #: A linear gradient type.
|
|
245
|
+
RADIAL_GRAD = 11 #: A radial gradient type.
|
|
246
|
+
|
|
247
|
+
@classmethod
|
|
248
|
+
def from_param(cls, obj: int) -> int:
|
|
249
|
+
return int(obj)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class PathCommand(IntEnum):
|
|
253
|
+
"""Enumeration specifying the values of the path commands accepted by ThorVG."""
|
|
254
|
+
|
|
255
|
+
#: Ends the current sub-path and connects it with its initial point.
|
|
256
|
+
#: Corresponds to Z command in the SVG path commands.
|
|
257
|
+
CLOSE = 0
|
|
258
|
+
|
|
259
|
+
#: Sets a new initial point of the sub-path and a new current point.
|
|
260
|
+
#: Corresponds to M command in the SVG path commands.
|
|
261
|
+
MOVE_TO = 1
|
|
262
|
+
|
|
263
|
+
#: Draws a line from the current point to the given point and sets a new value of the current point.
|
|
264
|
+
#: Corresponds to L command in the SVG path commands.
|
|
265
|
+
LINE_TO = 2
|
|
266
|
+
|
|
267
|
+
#: Draws a cubic Bezier curve from the current point to the given point using
|
|
268
|
+
#: two given control points and sets a new value of the current point.
|
|
269
|
+
#: Corresponds to C command in the SVG path commands.
|
|
270
|
+
CUBIC_TO = 3
|
|
271
|
+
|
|
272
|
+
@classmethod
|
|
273
|
+
def from_param(cls, obj: int) -> int:
|
|
274
|
+
return int(obj)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class StrokeCap(IntEnum):
|
|
278
|
+
"""Enumeration determining the ending type of a stroke in the open sub-paths."""
|
|
279
|
+
|
|
280
|
+
#: The stroke is extended in both endpoints of a sub-path by a rectangle,
|
|
281
|
+
#: with the width equal to the stroke width and the length equal to half of the stroke width.
|
|
282
|
+
#: For zero length sub-paths the square is rendered with the size of the stroke width.
|
|
283
|
+
SQUARE = 0
|
|
284
|
+
|
|
285
|
+
#: The stroke is extended in both endpoints of a sub-path by a half circle,
|
|
286
|
+
#: with a radius equal to half of the stroke width. For zero length sub-paths a full circle is rendered.
|
|
287
|
+
ROUND = 1
|
|
288
|
+
|
|
289
|
+
#: The stroke ends exactly at each of the two endpoints of a sub-path.
|
|
290
|
+
#: For zero length sub-paths no stroke is rendered.
|
|
291
|
+
BUTT = 2
|
|
292
|
+
|
|
293
|
+
@classmethod
|
|
294
|
+
def from_param(cls, obj: int) -> int:
|
|
295
|
+
return int(obj)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class StrokeJoin(IntEnum):
|
|
299
|
+
"""Enumeration specifying how to fill the area outside the gradient bounds."""
|
|
300
|
+
|
|
301
|
+
#: The outer corner of the joined path segments is bevelled at the join point.
|
|
302
|
+
#: The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke.
|
|
303
|
+
BEVEL = 0
|
|
304
|
+
|
|
305
|
+
#: The outer corner of the joined path segments is rounded.
|
|
306
|
+
#: The circular region is centered at the join point.
|
|
307
|
+
ROUND = 1
|
|
308
|
+
|
|
309
|
+
#: The outer corner of the joined path segments is spiked.
|
|
310
|
+
#: The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect.
|
|
311
|
+
#: If the extension goes beyond the limit, the join style is converted to the Bevel styl
|
|
312
|
+
MITER = 2
|
|
313
|
+
|
|
314
|
+
@classmethod
|
|
315
|
+
def from_param(cls, obj: int) -> int:
|
|
316
|
+
return int(obj)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class StrokeFill(IntEnum):
|
|
320
|
+
"""Enumeration specifying how to fill the area outside the gradient bounds."""
|
|
321
|
+
|
|
322
|
+
#: The remaining area is filled with the closest stop color.
|
|
323
|
+
PAD = 0
|
|
324
|
+
|
|
325
|
+
#: The gradient pattern is reflected outside the gradient area
|
|
326
|
+
#: until the expected region is filled.
|
|
327
|
+
REFLECT = 1
|
|
328
|
+
|
|
329
|
+
#: The gradient pattern is repeated continuously beyond the gradient area
|
|
330
|
+
#: until the expected region is filled.
|
|
331
|
+
REPEAT = 2
|
|
332
|
+
|
|
333
|
+
@classmethod
|
|
334
|
+
def from_param(cls, obj: int) -> int:
|
|
335
|
+
return int(obj)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
class FillRule(IntEnum):
|
|
339
|
+
"""Enumeration specifying the algorithm used to establish which parts of the shape
|
|
340
|
+
are treated as the inside of the shape.
|
|
341
|
+
"""
|
|
342
|
+
|
|
343
|
+
#: A line from the point to a location outside the shape is drawn.
|
|
344
|
+
#: The intersections of the line with the path segment of the shape are counted.
|
|
345
|
+
#: Starting from zero, if the path segment of the shape crosses the line clockwise,
|
|
346
|
+
#: one is added, otherwise one is subtracted. If the resulting sum is non zero,
|
|
347
|
+
#: the point is inside the shape.
|
|
348
|
+
WINDING = 0
|
|
349
|
+
|
|
350
|
+
#: A line from the point to a location outside the shape is drawn
|
|
351
|
+
#: and its intersections with the path segments of the shape are counted.
|
|
352
|
+
#: If the number of intersections is an odd number, the point is inside the shape.
|
|
353
|
+
EVEN_ODD = 1
|
|
354
|
+
|
|
355
|
+
@classmethod
|
|
356
|
+
def from_param(cls, obj: int) -> int:
|
|
357
|
+
return int(obj)
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
class ColorStop(ctypes.Structure):
|
|
361
|
+
"""A data structure storing the information about the color and its relative position inside the gradient bounds."""
|
|
362
|
+
|
|
363
|
+
_fields_ = [
|
|
364
|
+
("offset", ctypes.c_float),
|
|
365
|
+
("r", ctypes.c_uint8),
|
|
366
|
+
("g", ctypes.c_uint8),
|
|
367
|
+
("b", ctypes.c_uint8),
|
|
368
|
+
("a", ctypes.c_uint8),
|
|
369
|
+
]
|
|
370
|
+
|
|
371
|
+
offset: float #: The relative position of the color.
|
|
372
|
+
r: int #: The red color channel value in the range [0 ~ 255].
|
|
373
|
+
g: int #: The green color channel value in the range [0 ~ 255].
|
|
374
|
+
b: int #: The blue color channel value in the range [0 ~ 255].
|
|
375
|
+
a: int #: The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
class PointStruct(ctypes.Structure):
|
|
379
|
+
"""A data structure representing a point in two-dimensional space."""
|
|
380
|
+
|
|
381
|
+
_fields_ = [
|
|
382
|
+
("x", ctypes.c_float),
|
|
383
|
+
("y", ctypes.c_float),
|
|
384
|
+
]
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
class Matrix(ctypes.Structure):
|
|
388
|
+
"""A data structure representing a three-dimensional matrix.
|
|
389
|
+
|
|
390
|
+
The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor.
|
|
391
|
+
|
|
392
|
+
The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively.
|
|
393
|
+
|
|
394
|
+
The elements e31 and e32 are set to 0, e33 is set to 1.
|
|
395
|
+
"""
|
|
396
|
+
|
|
397
|
+
_fields_ = [
|
|
398
|
+
("e11", ctypes.c_float),
|
|
399
|
+
("e12", ctypes.c_float),
|
|
400
|
+
("e13", ctypes.c_float),
|
|
401
|
+
("e21", ctypes.c_float),
|
|
402
|
+
("e22", ctypes.c_float),
|
|
403
|
+
("e23", ctypes.c_float),
|
|
404
|
+
("e31", ctypes.c_float),
|
|
405
|
+
("e32", ctypes.c_float),
|
|
406
|
+
("e33", ctypes.c_float),
|
|
407
|
+
]
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
class MempoolPolicy(IntEnum):
|
|
411
|
+
"""Enumeration specifying the methods of Memory Pool behavior policy."""
|
|
412
|
+
|
|
413
|
+
DEFAULT = 0 #: Default behavior that ThorVG is designed to.
|
|
414
|
+
SHAREABLE = 1 #: Memory Pool is shared among canvases.
|
|
415
|
+
INDIVIDUAL = 2 #: Allocate designated memory pool that is used only by the current canvas instance.
|
|
416
|
+
|
|
417
|
+
@classmethod
|
|
418
|
+
def from_param(cls, obj: int) -> int:
|
|
419
|
+
return int(obj)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
class Colorspace(IntEnum):
|
|
423
|
+
"""Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.
|
|
424
|
+
|
|
425
|
+
.. versionchanged:: 0.13
|
|
426
|
+
Added ``ABGR8888S`` and ``ARGB8888S``
|
|
427
|
+
"""
|
|
428
|
+
|
|
429
|
+
#: The channels are joined in the order: alpha, blue, green, red.
|
|
430
|
+
#: Colors are alpha-premultiplied. (a << 24 | b << 16 | g << 8 | r)
|
|
431
|
+
ABGR8888 = 0
|
|
432
|
+
|
|
433
|
+
#: The channels are joined in the order: alpha, red, green, blue.
|
|
434
|
+
#: Colors are alpha-premultiplied. (a << 24 | r << 16 | g << 8 | b)
|
|
435
|
+
ARGB8888 = 1
|
|
436
|
+
|
|
437
|
+
#: The channels are joined in the order: alpha, blue, green, red.
|
|
438
|
+
#: Colors are un-alpha-premultiplied.
|
|
439
|
+
ABGR8888S = 2
|
|
440
|
+
|
|
441
|
+
#: The channels are joined in the order: alpha, red, green, blue.
|
|
442
|
+
#: Colors are un-alpha-premultiplied.
|
|
443
|
+
ARGB8888S = 3
|
|
444
|
+
|
|
445
|
+
@classmethod
|
|
446
|
+
def from_param(cls, obj: int) -> int:
|
|
447
|
+
return int(obj)
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import ctypes
|
|
3
|
+
|
|
4
|
+
from ..base import CanvasStruct, PaintStruct, Result
|
|
5
|
+
from ..engine import Engine
|
|
6
|
+
from ..paint import Paint
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Canvas:
|
|
10
|
+
"""
|
|
11
|
+
Common Canvas API
|
|
12
|
+
|
|
13
|
+
A module for managing and drawing graphical elements.
|
|
14
|
+
|
|
15
|
+
A canvas is an entity responsible for drawing the target. It sets up the drawing engine and the buffer, which can be drawn on the screen. It also manages given Paint objects.
|
|
16
|
+
|
|
17
|
+
.. note::
|
|
18
|
+
A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical.
|
|
19
|
+
.. warning::
|
|
20
|
+
The Paint objects belonging to one Canvas can't be shared among multiple Canvases.
|
|
21
|
+
|
|
22
|
+
This is base Canvas class. Please instantiate `SwCanvas`, `GlCanvas` or `WgCanvas` instead
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, engine: Engine, canvas: CanvasStruct):
|
|
26
|
+
self.engine = engine
|
|
27
|
+
self.thorvg_lib = engine.thorvg_lib
|
|
28
|
+
self._canvas = canvas
|
|
29
|
+
|
|
30
|
+
def destroy(self) -> Result:
|
|
31
|
+
"""Clears the canvas internal data, releases all paints stored by the canvas and destroys the canvas object itself.
|
|
32
|
+
|
|
33
|
+
:return: INVALID_ARGUMENT An invalid pointer to the CanvasStruct object is passed.
|
|
34
|
+
:rtype: Result
|
|
35
|
+
|
|
36
|
+
.. note::
|
|
37
|
+
If the paints from the canvas should not be released, the tvg_canvas_clear() with a ``free`` argument value set to ``false`` should be called.
|
|
38
|
+
Please be aware that in such a case TVG is not responsible for the paints release anymore and it has to be done manually in order to avoid memory leaks.
|
|
39
|
+
|
|
40
|
+
.. seealso:: Paint.del(), Canvas.clear()
|
|
41
|
+
"""
|
|
42
|
+
self.thorvg_lib.tvg_canvas_destroy.argtypes = [ctypes.POINTER(CanvasStruct)]
|
|
43
|
+
self.thorvg_lib.tvg_canvas_destroy.restype = Result
|
|
44
|
+
return self.thorvg_lib.tvg_canvas_destroy(ctypes.pointer(self._canvas))
|
|
45
|
+
|
|
46
|
+
def push(
|
|
47
|
+
self,
|
|
48
|
+
paint: "Paint",
|
|
49
|
+
) -> Result:
|
|
50
|
+
"""Inserts a drawing element into the canvas using a PaintStruct object.
|
|
51
|
+
|
|
52
|
+
:param Paint paint: The Paint object to be drawn.
|
|
53
|
+
|
|
54
|
+
Only the paints pushed into the canvas will be drawing targets.
|
|
55
|
+
They are retained by the canvas until you call tvg_canvas_clear().
|
|
56
|
+
|
|
57
|
+
:return:
|
|
58
|
+
- INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument.
|
|
59
|
+
- INSUFFICIENT_CONDITION An internal error.
|
|
60
|
+
:rtype: Result
|
|
61
|
+
|
|
62
|
+
.. note::
|
|
63
|
+
The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering.
|
|
64
|
+
.. seealso:: Canvas.clear()
|
|
65
|
+
"""
|
|
66
|
+
self.thorvg_lib.tvg_canvas_push.argtypes = [
|
|
67
|
+
ctypes.POINTER(CanvasStruct),
|
|
68
|
+
ctypes.POINTER(PaintStruct),
|
|
69
|
+
]
|
|
70
|
+
self.thorvg_lib.tvg_canvas_push.restype = Result
|
|
71
|
+
return self.thorvg_lib.tvg_canvas_push(
|
|
72
|
+
ctypes.pointer(self._canvas),
|
|
73
|
+
ctypes.pointer(paint._paint), # type: ignore
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def reserve(self, n: int) -> Result:
|
|
77
|
+
"""Reserves a memory block where the objects pushed into a canvas are stored.
|
|
78
|
+
|
|
79
|
+
If the number of PaintStructs to be stored in a canvas is known in advance, calling this function reduces the multiple
|
|
80
|
+
memory allocations thus improves the performance.
|
|
81
|
+
|
|
82
|
+
:param int n: The number of objects for which the memory is to be reserved.
|
|
83
|
+
|
|
84
|
+
:return: INVALID_ARGUMENT An invalid CanvasStruct pointer.
|
|
85
|
+
:rtype: Result
|
|
86
|
+
|
|
87
|
+
.. deprecated:: 0.10
|
|
88
|
+
.. note:: Malfunctional
|
|
89
|
+
"""
|
|
90
|
+
self.thorvg_lib.tvg_canvas_reserve.argtypes = [
|
|
91
|
+
ctypes.POINTER(CanvasStruct),
|
|
92
|
+
ctypes.c_uint32,
|
|
93
|
+
]
|
|
94
|
+
self.thorvg_lib.tvg_canvas_reserve.restype = Result
|
|
95
|
+
return self.thorvg_lib.tvg_canvas_reserve(
|
|
96
|
+
ctypes.pointer(self._canvas), ctypes.c_uint32(n)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def clear(
|
|
100
|
+
self,
|
|
101
|
+
free: bool,
|
|
102
|
+
) -> Result:
|
|
103
|
+
"""Sets the total number of the paints pushed into the canvas to be zero.
|
|
104
|
+
PaintStruct objects stored in the canvas are released if ``free`` is set to true, otherwise the memory is not deallocated and
|
|
105
|
+
all paints should be released manually in order to avoid memory leaks.
|
|
106
|
+
|
|
107
|
+
:param bool free: If ``true`` the memory occupied by paints is deallocated, otherwise it is not.
|
|
108
|
+
|
|
109
|
+
:return: INVALID_ARGUMENT An invalid CanvasStruct pointer.
|
|
110
|
+
:rtype: Result
|
|
111
|
+
|
|
112
|
+
.. seealso:: Canvas.destroy()
|
|
113
|
+
"""
|
|
114
|
+
self.thorvg_lib.tvg_canvas_clear.argtypes = [
|
|
115
|
+
ctypes.POINTER(CanvasStruct),
|
|
116
|
+
ctypes.c_bool,
|
|
117
|
+
]
|
|
118
|
+
self.thorvg_lib.tvg_canvas_clear.restype = Result
|
|
119
|
+
return self.thorvg_lib.tvg_canvas_clear(
|
|
120
|
+
ctypes.pointer(self._canvas), ctypes.c_bool(free)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def update(self) -> Result:
|
|
124
|
+
"""Updates all paints in a canvas.
|
|
125
|
+
|
|
126
|
+
Should be called before drawing in order to prepare paints for the rendering.
|
|
127
|
+
|
|
128
|
+
:return: INVALID_ARGUMENT An invalid CanvasStruct pointer.
|
|
129
|
+
:rtype: Result
|
|
130
|
+
|
|
131
|
+
.. seealso:: Canvas.update_paint()
|
|
132
|
+
"""
|
|
133
|
+
self.thorvg_lib.tvg_canvas_update.argtypes = [
|
|
134
|
+
ctypes.POINTER(CanvasStruct),
|
|
135
|
+
]
|
|
136
|
+
self.thorvg_lib.tvg_canvas_update.restype = Result
|
|
137
|
+
return self.thorvg_lib.tvg_canvas_update(
|
|
138
|
+
ctypes.pointer(self._canvas),
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
def update_paint(self, paint: "Paint") -> Result:
|
|
142
|
+
"""Updates the given PaintStruct object from the canvas before the rendering.
|
|
143
|
+
|
|
144
|
+
If a client application using the TVG library does not update the entire canvas with Canvas.update() in the frame
|
|
145
|
+
rendering process, PaintStruct objects previously added to the canvas should be updated manually with this function.
|
|
146
|
+
|
|
147
|
+
:param PaintStruct paint: The PaintStruct object to be updated.
|
|
148
|
+
|
|
149
|
+
:return: INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument.
|
|
150
|
+
:rtype: Result
|
|
151
|
+
|
|
152
|
+
.. seealso:: Canvas.update()
|
|
153
|
+
"""
|
|
154
|
+
self.thorvg_lib.tvg_canvas_update_paint.argtypes = [
|
|
155
|
+
ctypes.POINTER(CanvasStruct),
|
|
156
|
+
ctypes.POINTER(PaintStruct),
|
|
157
|
+
]
|
|
158
|
+
self.thorvg_lib.tvg_canvas_update_paint.restype = Result
|
|
159
|
+
return self.thorvg_lib.tvg_canvas_update_paint(
|
|
160
|
+
ctypes.pointer(self._canvas),
|
|
161
|
+
ctypes.pointer(paint._paint), # type: ignore
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
def draw(self) -> Result:
|
|
165
|
+
"""Requests the canvas to draw the PaintStruct objects.
|
|
166
|
+
|
|
167
|
+
All paints from the given canvas will be rasterized to the buffer.
|
|
168
|
+
|
|
169
|
+
:return: INVALID_ARGUMENT An invalid CanvasStruct pointer.
|
|
170
|
+
:rtype: Result
|
|
171
|
+
|
|
172
|
+
.. note::
|
|
173
|
+
Drawing can be asynchronous based on the assigned thread number. To guarantee the drawing is done, call Canvas.sync() afterwards.
|
|
174
|
+
.. seealso:: Canvas.sync()
|
|
175
|
+
"""
|
|
176
|
+
self.thorvg_lib.tvg_canvas_draw.argtypes = [
|
|
177
|
+
ctypes.POINTER(CanvasStruct),
|
|
178
|
+
]
|
|
179
|
+
self.thorvg_lib.tvg_canvas_draw.restype = Result
|
|
180
|
+
return self.thorvg_lib.tvg_canvas_draw(
|
|
181
|
+
ctypes.pointer(self._canvas),
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def sync(self) -> Result:
|
|
185
|
+
"""Guarantees that the drawing process is finished.
|
|
186
|
+
|
|
187
|
+
Since the canvas rendering can be performed asynchronously, it should be called after the Canvas.draw().
|
|
188
|
+
|
|
189
|
+
:return:
|
|
190
|
+
- INVALID_ARGUMENT An invalid CanvasStruct pointer.
|
|
191
|
+
- INSUFFICIENT_CONDITION ``canvas`` is either already in sync condition or in a damaged condition (a draw is required before syncing).
|
|
192
|
+
:rtype: Result
|
|
193
|
+
|
|
194
|
+
.. seealso:: Canvas.draw()
|
|
195
|
+
"""
|
|
196
|
+
self.thorvg_lib.tvg_canvas_sync.argtypes = [
|
|
197
|
+
ctypes.POINTER(CanvasStruct),
|
|
198
|
+
]
|
|
199
|
+
self.thorvg_lib.tvg_canvas_sync.restype = Result
|
|
200
|
+
return self.thorvg_lib.tvg_canvas_sync(
|
|
201
|
+
ctypes.pointer(self._canvas),
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
def set_viewport(
|
|
205
|
+
self,
|
|
206
|
+
x: int,
|
|
207
|
+
y: int,
|
|
208
|
+
w: int,
|
|
209
|
+
h: int,
|
|
210
|
+
) -> Result:
|
|
211
|
+
"""Sets the drawing region in the canvas.
|
|
212
|
+
|
|
213
|
+
This function defines the rectangular area of the canvas that will be used for drawing operations.
|
|
214
|
+
The specified viewport is used to clip the rendering output to the boundaries of the rectangle.
|
|
215
|
+
|
|
216
|
+
:param int x: The x-coordinate of the upper-left corner of the rectangle.
|
|
217
|
+
:param int y: The y-coordinate of the upper-left corner of the rectangle.
|
|
218
|
+
:param int w: The width of the rectangle.
|
|
219
|
+
:param int h: The height of the rectangle.
|
|
220
|
+
|
|
221
|
+
:return: Result enumeration.
|
|
222
|
+
:rtype: Result
|
|
223
|
+
|
|
224
|
+
.. warning::
|
|
225
|
+
It's not allowed to change the viewport during tvg_canvas_update() - tvg_canvas_sync() or tvg_canvas_push() - tvg_canvas_sync().
|
|
226
|
+
|
|
227
|
+
.. note::
|
|
228
|
+
When resetting the target, the viewport will also be reset to the target size.
|
|
229
|
+
.. seealso:: SwCanvas.set_target()
|
|
230
|
+
.. versionadded:: 0.15
|
|
231
|
+
"""
|
|
232
|
+
self.thorvg_lib.tvg_canvas_set_viewport.argtypes = [
|
|
233
|
+
ctypes.POINTER(CanvasStruct),
|
|
234
|
+
ctypes.c_int32,
|
|
235
|
+
ctypes.c_int32,
|
|
236
|
+
ctypes.c_int32,
|
|
237
|
+
ctypes.c_int32,
|
|
238
|
+
]
|
|
239
|
+
self.thorvg_lib.tvg_canvas_set_viewport.restype = Result
|
|
240
|
+
return self.thorvg_lib.tvg_canvas_set_viewport(
|
|
241
|
+
ctypes.pointer(self._canvas),
|
|
242
|
+
ctypes.c_int32(x),
|
|
243
|
+
ctypes.c_int32(y),
|
|
244
|
+
ctypes.c_int32(w),
|
|
245
|
+
ctypes.c_int32(h),
|
|
246
|
+
)
|