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
|
@@ -0,0 +1,1082 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import ctypes
|
|
3
|
+
from typing import Optional, Sequence, Tuple, Union
|
|
4
|
+
|
|
5
|
+
from ..base import (
|
|
6
|
+
FillRule,
|
|
7
|
+
GradientStruct,
|
|
8
|
+
PaintStruct,
|
|
9
|
+
PathCommand,
|
|
10
|
+
PointStruct,
|
|
11
|
+
Result,
|
|
12
|
+
StrokeCap,
|
|
13
|
+
StrokeJoin,
|
|
14
|
+
TvgType,
|
|
15
|
+
)
|
|
16
|
+
from ..engine import Engine
|
|
17
|
+
from ..gradient import Gradient
|
|
18
|
+
from ..gradient.linear import LinearGradient
|
|
19
|
+
from ..gradient.radial import RadialGradient
|
|
20
|
+
from . import Paint
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Shape(Paint):
|
|
24
|
+
"""
|
|
25
|
+
Shape API
|
|
26
|
+
|
|
27
|
+
A module for managing two-dimensional figures and their properties.
|
|
28
|
+
|
|
29
|
+
A shape has three major properties: shape outline, stroking, filling. The outline in the shape is retained as the path.
|
|
30
|
+
Path can be composed by accumulating primitive commands such as tvg_shape_move_to(), tvg_shape_line_to(), tvg_shape_cubic_to() or complete shape interfaces such as tvg_shape_append_rect(), tvg_shape_append_circle(), etc.
|
|
31
|
+
Path can consists of sub-paths. One sub-path is determined by a close command.
|
|
32
|
+
|
|
33
|
+
The stroke of a shape is an optional property in case the shape needs to be represented with/without the outline borders.
|
|
34
|
+
It's efficient since the shape path and the stroking path can be shared with each other. It's also convenient when controlling both in one context.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, engine: Engine, paint: Optional[PaintStruct] = None):
|
|
38
|
+
self.engine = engine
|
|
39
|
+
self.thorvg_lib = engine.thorvg_lib
|
|
40
|
+
if paint is None:
|
|
41
|
+
self._paint = self._new()
|
|
42
|
+
else:
|
|
43
|
+
self._paint = paint
|
|
44
|
+
|
|
45
|
+
def _new(self) -> PaintStruct:
|
|
46
|
+
"""Creates a new shape object.
|
|
47
|
+
|
|
48
|
+
Note that you need not call this method as it is auto called when initializing ``Shape()``.
|
|
49
|
+
|
|
50
|
+
:return: A new shape object.
|
|
51
|
+
:rtype: PaintStruct
|
|
52
|
+
"""
|
|
53
|
+
self.thorvg_lib.tvg_shape_new.restype = ctypes.POINTER(PaintStruct)
|
|
54
|
+
return self.thorvg_lib.tvg_shape_new().contents
|
|
55
|
+
|
|
56
|
+
def reset(self) -> Result:
|
|
57
|
+
"""Resets the shape path properties.
|
|
58
|
+
|
|
59
|
+
The color, the fill and the stroke properties are retained.
|
|
60
|
+
|
|
61
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
62
|
+
:rtype: Result
|
|
63
|
+
|
|
64
|
+
.. note::
|
|
65
|
+
The memory, where the path data is stored, is not deallocated at this stage for caching effect.
|
|
66
|
+
"""
|
|
67
|
+
self.thorvg_lib.tvg_shape_reset.argtypes = [ctypes.POINTER(PaintStruct)]
|
|
68
|
+
self.thorvg_lib.tvg_shape_reset.restype = Result
|
|
69
|
+
return self.thorvg_lib.tvg_shape_reset(self._paint)
|
|
70
|
+
|
|
71
|
+
def move_to(self, x: float, y: float) -> Result:
|
|
72
|
+
"""Sets the initial point of the sub-path.
|
|
73
|
+
|
|
74
|
+
The value of the current point is set to the given point.
|
|
75
|
+
|
|
76
|
+
:param float x: The horizontal coordinate of the initial point of the sub-path.
|
|
77
|
+
:param float y: The vertical coordinate of the initial point of the sub-path.
|
|
78
|
+
|
|
79
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
80
|
+
:rtype: Result
|
|
81
|
+
"""
|
|
82
|
+
self.thorvg_lib.tvg_shape_move_to.argtypes = [
|
|
83
|
+
ctypes.POINTER(PaintStruct),
|
|
84
|
+
ctypes.c_float,
|
|
85
|
+
ctypes.c_float,
|
|
86
|
+
]
|
|
87
|
+
self.thorvg_lib.tvg_shape_move_to.restype = Result
|
|
88
|
+
return self.thorvg_lib.tvg_shape_move_to(
|
|
89
|
+
self._paint,
|
|
90
|
+
ctypes.c_float(x),
|
|
91
|
+
ctypes.c_float(y),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def line_to(self, x: float, y: float) -> Result:
|
|
95
|
+
"""Adds a new point to the sub-path, which results in drawing a line from
|
|
96
|
+
the current point to the given end-point.
|
|
97
|
+
|
|
98
|
+
The value of the current point is set to the given end-point.
|
|
99
|
+
|
|
100
|
+
:param float x: The horizontal coordinate of the end-point of the line.
|
|
101
|
+
:param float y: The vertical coordinate of the end-point of the line.
|
|
102
|
+
|
|
103
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
104
|
+
:rtype: Result
|
|
105
|
+
|
|
106
|
+
.. note::
|
|
107
|
+
In case this is the first command in the path, it corresponds to the tvg_shape_move_to() call.
|
|
108
|
+
"""
|
|
109
|
+
self.thorvg_lib.tvg_shape_line_to.argtypes = [
|
|
110
|
+
ctypes.POINTER(PaintStruct),
|
|
111
|
+
ctypes.c_float,
|
|
112
|
+
ctypes.c_float,
|
|
113
|
+
]
|
|
114
|
+
self.thorvg_lib.tvg_shape_line_to.restype = Result
|
|
115
|
+
return self.thorvg_lib.tvg_shape_line_to(
|
|
116
|
+
self._paint,
|
|
117
|
+
ctypes.c_float(x),
|
|
118
|
+
ctypes.c_float(y),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def cubic_to(
|
|
122
|
+
self,
|
|
123
|
+
cx1: float,
|
|
124
|
+
cy1: float,
|
|
125
|
+
cx2: float,
|
|
126
|
+
cy2: float,
|
|
127
|
+
x: float,
|
|
128
|
+
y: float,
|
|
129
|
+
) -> Result:
|
|
130
|
+
"""Adds new points to the sub-path, which results in drawing a cubic Bezier curve.
|
|
131
|
+
|
|
132
|
+
The Bezier curve starts at the current point and ends at the given end-point (``x``, ``y``).
|
|
133
|
+
Two control points (``cx1``, ``cy1``) and (``cx2``, ``cy2``) are used to determine the shape of the curve.
|
|
134
|
+
The value of the current point is set to the given end-point.
|
|
135
|
+
|
|
136
|
+
:param float cx1: The horizontal coordinate of the 1st control point.
|
|
137
|
+
:param float cy1: The vertical coordinate of the 1st control point.
|
|
138
|
+
:param float cx2: The horizontal coordinate of the 2nd control point.
|
|
139
|
+
:param float cy2: The vertical coordinate of the 2nd control point.
|
|
140
|
+
:param float x: The horizontal coordinate of the endpoint of the curve.
|
|
141
|
+
:param float y: The vertical coordinate of the endpoint of the curve.
|
|
142
|
+
|
|
143
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
144
|
+
:rtype: Result
|
|
145
|
+
|
|
146
|
+
.. note::
|
|
147
|
+
In case this is the first command in the path, no data from the path are rendered.
|
|
148
|
+
"""
|
|
149
|
+
self.thorvg_lib.tvg_shape_cubic_to.argtypes = [
|
|
150
|
+
ctypes.POINTER(PaintStruct),
|
|
151
|
+
ctypes.c_float,
|
|
152
|
+
ctypes.c_float,
|
|
153
|
+
ctypes.c_float,
|
|
154
|
+
ctypes.c_float,
|
|
155
|
+
ctypes.c_float,
|
|
156
|
+
ctypes.c_float,
|
|
157
|
+
]
|
|
158
|
+
self.thorvg_lib.tvg_shape_cubic_to.restype = Result
|
|
159
|
+
return self.thorvg_lib.tvg_shape_cubic_to(
|
|
160
|
+
self._paint,
|
|
161
|
+
ctypes.c_float(cx1),
|
|
162
|
+
ctypes.c_float(cy1),
|
|
163
|
+
ctypes.c_float(cx2),
|
|
164
|
+
ctypes.c_float(cy2),
|
|
165
|
+
ctypes.c_float(x),
|
|
166
|
+
ctypes.c_float(y),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
def close(
|
|
170
|
+
self,
|
|
171
|
+
) -> Result:
|
|
172
|
+
"""Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path.
|
|
173
|
+
|
|
174
|
+
The value of the current point is set to the initial point of the closed sub-path.
|
|
175
|
+
|
|
176
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
177
|
+
:rtype: Result
|
|
178
|
+
|
|
179
|
+
.. note::
|
|
180
|
+
In case the sub-path does not contain any points, this function has no effect.
|
|
181
|
+
"""
|
|
182
|
+
self.thorvg_lib.tvg_shape_close.argtypes = [
|
|
183
|
+
ctypes.POINTER(PaintStruct),
|
|
184
|
+
]
|
|
185
|
+
self.thorvg_lib.tvg_shape_close.restype = Result
|
|
186
|
+
return self.thorvg_lib.tvg_shape_close(
|
|
187
|
+
self._paint,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def append_rect(
|
|
191
|
+
self,
|
|
192
|
+
x: float,
|
|
193
|
+
y: float,
|
|
194
|
+
w: float,
|
|
195
|
+
h: float,
|
|
196
|
+
rx: float,
|
|
197
|
+
ry: float,
|
|
198
|
+
) -> Result:
|
|
199
|
+
"""Appends a rectangle to the path.
|
|
200
|
+
|
|
201
|
+
The rectangle with rounded corners can be achieved by setting non-zero values to ``rx`` and ``ry`` arguments.
|
|
202
|
+
The ``rx`` and ``ry`` values specify the radii of the ellipse defining the rounding of the corners.
|
|
203
|
+
|
|
204
|
+
The position of the rectangle is specified by the coordinates of its upper-left corner - ``x`` and ``y`` arguments.
|
|
205
|
+
|
|
206
|
+
The rectangle is treated as a new sub-path - it is not connected with the previous sub-path.
|
|
207
|
+
|
|
208
|
+
The value of the current point is set to (``x`` + ``rx``, ``y``) - in case ``rx`` is greater
|
|
209
|
+
than ``w/2`` the current point is set to (``x`` + ``w/2``, ``y``)
|
|
210
|
+
|
|
211
|
+
:param float x: The horizontal coordinate of the upper-left corner of the rectangle.
|
|
212
|
+
:param float y: The vertical coordinate of the upper-left corner of the rectangle.
|
|
213
|
+
:param float w: The width of the rectangle.
|
|
214
|
+
:param float h: The height of the rectangle.
|
|
215
|
+
:param float rx: The x-axis radius of the ellipse defining the rounded corners of the rectangle.
|
|
216
|
+
:param float ry: The y-axis radius of the ellipse defining the rounded corners of the rectangle.
|
|
217
|
+
|
|
218
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
219
|
+
:rtype: Result
|
|
220
|
+
"""
|
|
221
|
+
self.thorvg_lib.tvg_shape_append_rect.argtypes = [
|
|
222
|
+
ctypes.POINTER(PaintStruct),
|
|
223
|
+
ctypes.c_float,
|
|
224
|
+
ctypes.c_float,
|
|
225
|
+
ctypes.c_float,
|
|
226
|
+
ctypes.c_float,
|
|
227
|
+
ctypes.c_float,
|
|
228
|
+
ctypes.c_float,
|
|
229
|
+
]
|
|
230
|
+
self.thorvg_lib.tvg_shape_append_rect.restype = Result
|
|
231
|
+
return self.thorvg_lib.tvg_shape_append_rect(
|
|
232
|
+
self._paint,
|
|
233
|
+
ctypes.c_float(x),
|
|
234
|
+
ctypes.c_float(y),
|
|
235
|
+
ctypes.c_float(w),
|
|
236
|
+
ctypes.c_float(h),
|
|
237
|
+
ctypes.c_float(rx),
|
|
238
|
+
ctypes.c_float(ry),
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
def append_circle(
|
|
242
|
+
self,
|
|
243
|
+
cx: float,
|
|
244
|
+
cy: float,
|
|
245
|
+
rx: float,
|
|
246
|
+
ry: float,
|
|
247
|
+
) -> Result:
|
|
248
|
+
"""Appends an ellipse to the path.
|
|
249
|
+
|
|
250
|
+
The position of the ellipse is specified by the coordinates of its center - ``cx`` and ``cy`` arguments.
|
|
251
|
+
|
|
252
|
+
The ellipse is treated as a new sub-path - it is not connected with the previous sub-path.
|
|
253
|
+
|
|
254
|
+
The value of the current point is set to (``cx``, ``cy`` - ``ry``).
|
|
255
|
+
|
|
256
|
+
:param float cx: The horizontal coordinate of the center of the ellipse.
|
|
257
|
+
:param float cy: The vertical coordinate of the center of the ellipse.
|
|
258
|
+
:param float rx: The x-axis radius of the ellipse.
|
|
259
|
+
:param float ry: The y-axis radius of the ellipse.
|
|
260
|
+
|
|
261
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
262
|
+
:rtype: Result
|
|
263
|
+
"""
|
|
264
|
+
self.thorvg_lib.tvg_shape_append_circle.argtypes = [
|
|
265
|
+
ctypes.POINTER(PaintStruct),
|
|
266
|
+
ctypes.c_float,
|
|
267
|
+
ctypes.c_float,
|
|
268
|
+
ctypes.c_float,
|
|
269
|
+
ctypes.c_float,
|
|
270
|
+
]
|
|
271
|
+
self.thorvg_lib.tvg_shape_append_circle.restype = Result
|
|
272
|
+
return self.thorvg_lib.tvg_shape_append_circle(
|
|
273
|
+
self._paint,
|
|
274
|
+
ctypes.c_float(cx),
|
|
275
|
+
ctypes.c_float(cy),
|
|
276
|
+
ctypes.c_float(rx),
|
|
277
|
+
ctypes.c_float(ry),
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
def append_arc(
|
|
281
|
+
self,
|
|
282
|
+
cx: float,
|
|
283
|
+
cy: float,
|
|
284
|
+
radius: float,
|
|
285
|
+
startAngle: float,
|
|
286
|
+
sweep: float,
|
|
287
|
+
pie: bool,
|
|
288
|
+
) -> Result:
|
|
289
|
+
"""Appends a circular arc to the path.
|
|
290
|
+
|
|
291
|
+
The arc is treated as a new sub-path - it is not connected with the previous sub-path.
|
|
292
|
+
The current point value is set to the end-point of the arc in case ``pie`` is ``false``, and to the center of the arc otherwise.
|
|
293
|
+
|
|
294
|
+
:param float cx: The horizontal coordinate of the center of the arc.
|
|
295
|
+
:param float cy: The vertical coordinate of the center of the arc.
|
|
296
|
+
:param float radius: The radius of the arc.
|
|
297
|
+
:param float startAngle: The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line.
|
|
298
|
+
:param float sweep: The central angle of the arc given in degrees, measured counter-clockwise from ``startAngle``.
|
|
299
|
+
:param bool pie: Specifies whether to draw radii from the arc's center to both of its end-point - drawn if ``1``.
|
|
300
|
+
|
|
301
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
302
|
+
:rtype: Result
|
|
303
|
+
|
|
304
|
+
.. note::
|
|
305
|
+
Setting ``sweep`` value greater than 360 degrees, is equivalent to calling tvg_shape_append_circle(paint, cx, cy, radius, radius).
|
|
306
|
+
.. deprecated:: 0.15
|
|
307
|
+
"""
|
|
308
|
+
self.thorvg_lib.tvg_shape_append_arc.argtypes = [
|
|
309
|
+
ctypes.POINTER(PaintStruct),
|
|
310
|
+
ctypes.c_float,
|
|
311
|
+
ctypes.c_float,
|
|
312
|
+
ctypes.c_float,
|
|
313
|
+
ctypes.c_float,
|
|
314
|
+
ctypes.c_float,
|
|
315
|
+
ctypes.c_bool,
|
|
316
|
+
]
|
|
317
|
+
self.thorvg_lib.tvg_shape_append_arc.restype = Result
|
|
318
|
+
return self.thorvg_lib.tvg_shape_append_arc(
|
|
319
|
+
self._paint,
|
|
320
|
+
ctypes.c_float(cx),
|
|
321
|
+
ctypes.c_float(cy),
|
|
322
|
+
ctypes.c_float(radius),
|
|
323
|
+
ctypes.c_float(startAngle),
|
|
324
|
+
ctypes.c_float(sweep),
|
|
325
|
+
ctypes.c_bool(pie),
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
def append_path(
|
|
329
|
+
self,
|
|
330
|
+
cmds: Sequence[PathCommand],
|
|
331
|
+
pts: Sequence[PointStruct],
|
|
332
|
+
) -> Result:
|
|
333
|
+
"""Appends a given sub-path to the path.
|
|
334
|
+
|
|
335
|
+
The current point value is set to the last point from the sub-path.
|
|
336
|
+
For each command from the ``cmds`` array, an appropriate number of points in ``pts`` array should be specified.
|
|
337
|
+
If the number of points in the ``pts`` array is different than the number required by the ``cmds`` array, the shape with this sub-path will not be displayed on the screen.
|
|
338
|
+
|
|
339
|
+
:param Sequence[PathCommand] cmds: The array of the commands in the sub-path.
|
|
340
|
+
:param Sequence[PointStruct] pts: The array of the two-dimensional points.
|
|
341
|
+
|
|
342
|
+
:return: INVALID_ARGUMENT A ``nullptr`` passed as the argument or ``cmdCnt`` or ``ptsCnt`` equal to zero.
|
|
343
|
+
:rtype: Result
|
|
344
|
+
"""
|
|
345
|
+
cmds_arr_type = ctypes.c_int * len(cmds)
|
|
346
|
+
pts_arr_type = PointStruct * len(pts)
|
|
347
|
+
cmds_arr = cmds_arr_type(*cmds)
|
|
348
|
+
pts_arr = pts_arr_type(*pts)
|
|
349
|
+
self.thorvg_lib.tvg_shape_append_path.argtypes = [
|
|
350
|
+
ctypes.POINTER(PaintStruct),
|
|
351
|
+
ctypes.POINTER(cmds_arr_type),
|
|
352
|
+
ctypes.c_int,
|
|
353
|
+
ctypes.POINTER(pts_arr_type),
|
|
354
|
+
ctypes.c_int,
|
|
355
|
+
]
|
|
356
|
+
self.thorvg_lib.tvg_shape_append_path.restype = Result
|
|
357
|
+
return self.thorvg_lib.tvg_shape_append_path(
|
|
358
|
+
self._paint,
|
|
359
|
+
ctypes.pointer(cmds_arr),
|
|
360
|
+
ctypes.c_int(len(cmds)),
|
|
361
|
+
ctypes.pointer(pts_arr),
|
|
362
|
+
ctypes.c_int(len(pts)),
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
def get_path_coords(self) -> Tuple[Result, Sequence[PointStruct]]:
|
|
366
|
+
"""Gets the points values of the path.
|
|
367
|
+
|
|
368
|
+
The function does not allocate any data, it operates on internal memory. There is no need to free the ``pts`` sequence.
|
|
369
|
+
|
|
370
|
+
.. code-block:: python
|
|
371
|
+
|
|
372
|
+
from thorvg_python import Engine, Shape
|
|
373
|
+
|
|
374
|
+
engine = Engine()
|
|
375
|
+
shape = Shape(engine)
|
|
376
|
+
|
|
377
|
+
shape.append_circle(10, 10, 50, 50)
|
|
378
|
+
coords = shape.get_path_coords(shape)
|
|
379
|
+
//TVG approximates a circle by four Bezier curves. In the example above the coords sequence stores their coordinates.
|
|
380
|
+
|
|
381
|
+
:return: INVALID_ARGUMENT A ``nullptr`` passed as the argument.
|
|
382
|
+
:rtype: Result
|
|
383
|
+
:return: A sequence of the two-dimensional points from the path.
|
|
384
|
+
:rtype: Sequence[PointStruct]
|
|
385
|
+
"""
|
|
386
|
+
pts_ptr = ctypes.POINTER(PointStruct)()
|
|
387
|
+
cnt = ctypes.c_uint32()
|
|
388
|
+
self.thorvg_lib.tvg_shape_get_path_coords.argtypes = [
|
|
389
|
+
ctypes.POINTER(PaintStruct),
|
|
390
|
+
ctypes.POINTER(ctypes.POINTER(PointStruct)),
|
|
391
|
+
ctypes.POINTER(ctypes.c_uint32),
|
|
392
|
+
]
|
|
393
|
+
self.thorvg_lib.tvg_shape_get_path_coords.restype = Result
|
|
394
|
+
result = self.thorvg_lib.tvg_shape_get_path_coords(
|
|
395
|
+
ctypes.pointer(self._paint), ctypes.pointer(pts_ptr), ctypes.pointer(cnt)
|
|
396
|
+
)
|
|
397
|
+
pts_arr_type = PointStruct * cnt.value
|
|
398
|
+
pts_arr = pts_arr_type.from_address(ctypes.addressof(pts_ptr.contents))
|
|
399
|
+
return result, [pts_arr[i] for i in range(cnt.value)]
|
|
400
|
+
|
|
401
|
+
def get_path_commands(self) -> Tuple[Result, Sequence[PathCommand]]:
|
|
402
|
+
"""Gets the commands data of the path.
|
|
403
|
+
|
|
404
|
+
The function does not allocate any data. There is no need to free the ``cmds`` seqeunce.
|
|
405
|
+
|
|
406
|
+
.. code-block:: python
|
|
407
|
+
|
|
408
|
+
from thorvg_python import Engine, Shape
|
|
409
|
+
|
|
410
|
+
engine = Engine()
|
|
411
|
+
shape = Shape(engine)
|
|
412
|
+
|
|
413
|
+
shape.append_circle(10, 10, 50, 50)
|
|
414
|
+
cmds = shape.get_path_commands()
|
|
415
|
+
//TVG approximates a circle by four Bezier curves. In the example above the cmds seqeunce stores the commands of the path data.
|
|
416
|
+
|
|
417
|
+
:return: INVALID_ARGUMENT A ``nullptr`` passed as the argument.
|
|
418
|
+
:rtype: Result
|
|
419
|
+
:return: A sequence of the commands from the path.
|
|
420
|
+
:rtype: Sequence[PathCommand]
|
|
421
|
+
"""
|
|
422
|
+
cmds_ptr = ctypes.POINTER(ctypes.c_int)()
|
|
423
|
+
cnt = ctypes.c_uint32()
|
|
424
|
+
self.thorvg_lib.tvg_shape_get_path_commands.argtypes = [
|
|
425
|
+
ctypes.POINTER(PaintStruct),
|
|
426
|
+
ctypes.POINTER(ctypes.POINTER(ctypes.c_int)),
|
|
427
|
+
ctypes.POINTER(ctypes.c_uint32),
|
|
428
|
+
]
|
|
429
|
+
self.thorvg_lib.tvg_shape_get_path_commands.restype = Result
|
|
430
|
+
result = self.thorvg_lib.tvg_shape_get_path_commands(
|
|
431
|
+
ctypes.pointer(self._paint), ctypes.pointer(cmds_ptr), ctypes.pointer(cnt)
|
|
432
|
+
)
|
|
433
|
+
cmds_arr_type = ctypes.c_int * cnt.value
|
|
434
|
+
cmds_arr = cmds_arr_type.from_address(ctypes.addressof(cmds_ptr.contents))
|
|
435
|
+
return result, [PathCommand(cmds_arr[i]) for i in range(cnt.value)]
|
|
436
|
+
|
|
437
|
+
def set_stroke_width(self, width: float) -> Result:
|
|
438
|
+
"""Sets the stroke width for all of the figures from the ``paint``.
|
|
439
|
+
|
|
440
|
+
:param float width: The width of the stroke. The default value is 0.
|
|
441
|
+
|
|
442
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
443
|
+
:rtype: Result
|
|
444
|
+
"""
|
|
445
|
+
self.thorvg_lib.tvg_shape_set_stroke_width.argtypes = [
|
|
446
|
+
ctypes.POINTER(PaintStruct),
|
|
447
|
+
ctypes.c_float,
|
|
448
|
+
]
|
|
449
|
+
self.thorvg_lib.tvg_shape_set_stroke_width.restype = Result
|
|
450
|
+
return self.thorvg_lib.tvg_shape_set_stroke_width(
|
|
451
|
+
ctypes.pointer(self._paint),
|
|
452
|
+
ctypes.c_float(width),
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
def get_stroke_width(self) -> Tuple[Result, float]:
|
|
456
|
+
"""Gets the shape's stroke width.
|
|
457
|
+
|
|
458
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
459
|
+
:rtype: Result
|
|
460
|
+
:return: The stroke width.
|
|
461
|
+
:rtype: float
|
|
462
|
+
"""
|
|
463
|
+
width = ctypes.c_float()
|
|
464
|
+
self.thorvg_lib.tvg_shape_get_stroke_width.argtypes = [
|
|
465
|
+
ctypes.POINTER(PaintStruct),
|
|
466
|
+
ctypes.POINTER(ctypes.c_float),
|
|
467
|
+
]
|
|
468
|
+
self.thorvg_lib.tvg_shape_get_stroke_width.restype = Result
|
|
469
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_width(
|
|
470
|
+
ctypes.pointer(self._paint),
|
|
471
|
+
ctypes.pointer(width),
|
|
472
|
+
)
|
|
473
|
+
return result, width.value
|
|
474
|
+
|
|
475
|
+
def set_stroke_color(
|
|
476
|
+
self,
|
|
477
|
+
r: int,
|
|
478
|
+
g: int,
|
|
479
|
+
b: int,
|
|
480
|
+
a: int,
|
|
481
|
+
) -> Result:
|
|
482
|
+
"""Sets the shape's stroke color.
|
|
483
|
+
|
|
484
|
+
:param int r: The red color channel value in the range [0 ~ 255]. The default value is 0.
|
|
485
|
+
:param int g: The green color channel value in the range [0 ~ 255]. The default value is 0.
|
|
486
|
+
:param int b: The blue color channel value in the range [0 ~ 255]. The default value is 0.
|
|
487
|
+
:param int a: The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
|
|
488
|
+
|
|
489
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
490
|
+
:rtype: Result
|
|
491
|
+
|
|
492
|
+
.. note::
|
|
493
|
+
Either a solid color or a gradient fill is applied, depending on what was set as last.
|
|
494
|
+
"""
|
|
495
|
+
self.thorvg_lib.tvg_shape_set_stroke_color.argtypes = [
|
|
496
|
+
ctypes.POINTER(PaintStruct),
|
|
497
|
+
ctypes.c_uint8,
|
|
498
|
+
ctypes.c_uint8,
|
|
499
|
+
ctypes.c_uint8,
|
|
500
|
+
ctypes.c_uint8,
|
|
501
|
+
]
|
|
502
|
+
self.thorvg_lib.tvg_shape_set_stroke_color.restype = Result
|
|
503
|
+
return self.thorvg_lib.tvg_shape_set_stroke_color(
|
|
504
|
+
ctypes.pointer(self._paint),
|
|
505
|
+
ctypes.c_uint8(r),
|
|
506
|
+
ctypes.c_uint8(g),
|
|
507
|
+
ctypes.c_uint8(b),
|
|
508
|
+
ctypes.c_uint8(a),
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
def get_stroke_color(self) -> Tuple[Result, int, int, int, int]:
|
|
512
|
+
"""Gets the shape's stroke color.
|
|
513
|
+
|
|
514
|
+
:return:
|
|
515
|
+
- INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
516
|
+
- INSUFFICIENT_CONDITION No stroke was set.
|
|
517
|
+
:rtype: Result
|
|
518
|
+
:return: The red color channel value in the range [0 ~ 255]. The default value is 0.
|
|
519
|
+
:rtype: int
|
|
520
|
+
:return: The green color channel value in the range [0 ~ 255]. The default value is 0.
|
|
521
|
+
:rtype: int
|
|
522
|
+
:return: The blue color channel value in the range [0 ~ 255]. The default value is 0.
|
|
523
|
+
:rtype: int
|
|
524
|
+
:return: The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
|
|
525
|
+
:rtype: int
|
|
526
|
+
"""
|
|
527
|
+
r = ctypes.c_uint8()
|
|
528
|
+
g = ctypes.c_uint8()
|
|
529
|
+
b = ctypes.c_uint8()
|
|
530
|
+
a = ctypes.c_uint8()
|
|
531
|
+
|
|
532
|
+
self.thorvg_lib.tvg_shape_get_stroke_color.argtypes = [
|
|
533
|
+
ctypes.POINTER(PaintStruct),
|
|
534
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
535
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
536
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
537
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
538
|
+
]
|
|
539
|
+
self.thorvg_lib.tvg_shape_get_stroke_color.restype = Result
|
|
540
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_color(
|
|
541
|
+
ctypes.pointer(self._paint),
|
|
542
|
+
ctypes.pointer(r),
|
|
543
|
+
ctypes.pointer(g),
|
|
544
|
+
ctypes.pointer(b),
|
|
545
|
+
ctypes.pointer(a),
|
|
546
|
+
)
|
|
547
|
+
return result, r.value, g.value, b.value, a.value
|
|
548
|
+
|
|
549
|
+
def set_stroke_linear_gradient(self, grad: "Gradient") -> Result:
|
|
550
|
+
"""Sets the linear gradient fill of the stroke for all of the figures from the path.
|
|
551
|
+
|
|
552
|
+
:param GradientStruct grad: The linear gradient fill.
|
|
553
|
+
|
|
554
|
+
:return:
|
|
555
|
+
- INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
556
|
+
- MEMORY_CORRUPTION An invalid GradientStruct pointer or an error with accessing it.
|
|
557
|
+
:rtype: Result
|
|
558
|
+
|
|
559
|
+
.. note::
|
|
560
|
+
Either a solid color or a gradient fill is applied, depending on what was set as last.
|
|
561
|
+
"""
|
|
562
|
+
self.thorvg_lib.tvg_shape_set_stroke_linear_gradient.argtypes = [
|
|
563
|
+
ctypes.POINTER(PaintStruct),
|
|
564
|
+
GradientStruct,
|
|
565
|
+
]
|
|
566
|
+
self.thorvg_lib.tvg_shape_set_stroke_linear_gradient.restype = Result
|
|
567
|
+
return self.thorvg_lib.tvg_shape_set_stroke_linear_gradient(
|
|
568
|
+
ctypes.pointer(self._paint),
|
|
569
|
+
grad._grad, # type: ignore
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
def set_stroke_radial_gradient(self, grad: "Gradient") -> Result:
|
|
573
|
+
"""Sets the radial gradient fill of the stroke for all of the figures from the path.
|
|
574
|
+
|
|
575
|
+
:param GradientStruct grad: The radial gradient fill.
|
|
576
|
+
|
|
577
|
+
:return:
|
|
578
|
+
- INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
579
|
+
- MEMORY_CORRUPTION An invalid GradientStruct pointer or an error with accessing it.
|
|
580
|
+
:rtype: Result
|
|
581
|
+
|
|
582
|
+
.. note::
|
|
583
|
+
Either a solid color or a gradient fill is applied, depending on what was set as last.
|
|
584
|
+
"""
|
|
585
|
+
self.thorvg_lib.tvg_shape_set_stroke_radial_gradient.argtypes = [
|
|
586
|
+
ctypes.POINTER(PaintStruct),
|
|
587
|
+
GradientStruct,
|
|
588
|
+
]
|
|
589
|
+
self.thorvg_lib.tvg_shape_set_stroke_radial_gradient.restype = Result
|
|
590
|
+
return self.thorvg_lib.tvg_shape_set_stroke_radial_gradient(
|
|
591
|
+
ctypes.pointer(self._paint),
|
|
592
|
+
grad._grad, # type: ignore
|
|
593
|
+
)
|
|
594
|
+
|
|
595
|
+
def get_stroke_gradient(self) -> Tuple[Result, GradientStruct]:
|
|
596
|
+
"""Gets the gradient fill of the shape's stroke.
|
|
597
|
+
|
|
598
|
+
The function does not allocate any memory.
|
|
599
|
+
|
|
600
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
601
|
+
:rtype: Result
|
|
602
|
+
:return: The gradient fill.
|
|
603
|
+
:rtype: GradientStruct
|
|
604
|
+
"""
|
|
605
|
+
grad_ptr = ctypes.POINTER(GradientStruct)()
|
|
606
|
+
self.thorvg_lib.tvg_shape_get_stroke_gradient.argtypes = [
|
|
607
|
+
ctypes.POINTER(PaintStruct),
|
|
608
|
+
ctypes.POINTER(ctypes.POINTER(GradientStruct)),
|
|
609
|
+
]
|
|
610
|
+
self.thorvg_lib.tvg_shape_get_stroke_gradient.restype = Result
|
|
611
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_gradient(
|
|
612
|
+
ctypes.pointer(self._paint),
|
|
613
|
+
ctypes.pointer(grad_ptr),
|
|
614
|
+
)
|
|
615
|
+
return result, grad_ptr.contents
|
|
616
|
+
|
|
617
|
+
def set_stroke_dash(self, dash_pattern: Optional[Sequence[float]]) -> Result:
|
|
618
|
+
"""Sets the shape's stroke dash pattern.
|
|
619
|
+
|
|
620
|
+
:param Optional[Sequence[float]] dashPattern: The array of consecutive pair values of the dash length and the gap length.
|
|
621
|
+
|
|
622
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument and ``cnt`` > 0, the given length of the array is less than two or any of the ``dashPattern`` values is zero or less.
|
|
623
|
+
:rtype: Result
|
|
624
|
+
|
|
625
|
+
.. note::
|
|
626
|
+
To reset the stroke dash pattern, pass ``None`` to ``dashPattern``
|
|
627
|
+
"""
|
|
628
|
+
if dash_pattern is not None:
|
|
629
|
+
cnt = len(dash_pattern)
|
|
630
|
+
dash_pattern_type = ctypes.c_float * cnt
|
|
631
|
+
dash_pattern_type_ptr = ctypes.POINTER(dash_pattern_type)
|
|
632
|
+
dash_pattern_ptr = ctypes.pointer(dash_pattern_type(*dash_pattern))
|
|
633
|
+
else:
|
|
634
|
+
cnt = 0
|
|
635
|
+
dash_pattern_type_ptr = ctypes.c_void_p # type: ignore
|
|
636
|
+
dash_pattern_ptr = ctypes.c_void_p() # type: ignore
|
|
637
|
+
self.thorvg_lib.tvg_shape_set_stroke_dash.argtypes = [
|
|
638
|
+
ctypes.POINTER(PaintStruct),
|
|
639
|
+
dash_pattern_type_ptr,
|
|
640
|
+
ctypes.c_uint32,
|
|
641
|
+
]
|
|
642
|
+
self.thorvg_lib.tvg_shape_set_stroke_dash.restype = Result
|
|
643
|
+
return self.thorvg_lib.tvg_shape_set_stroke_dash(
|
|
644
|
+
ctypes.pointer(self._paint),
|
|
645
|
+
dash_pattern_ptr,
|
|
646
|
+
ctypes.c_uint32(cnt),
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
def get_stroke_dash(self) -> Tuple[Result, Sequence[float]]:
|
|
650
|
+
"""Gets the dash pattern of the stroke.
|
|
651
|
+
|
|
652
|
+
The function does not allocate any memory.
|
|
653
|
+
|
|
654
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
655
|
+
:rtype: Result
|
|
656
|
+
:return: The array of consecutive pair values of the dash length and the gap length.
|
|
657
|
+
:rtype: Sequence[float]
|
|
658
|
+
"""
|
|
659
|
+
dash_pattern_ptr = ctypes.POINTER(ctypes.c_float)()
|
|
660
|
+
cnt = ctypes.c_uint32()
|
|
661
|
+
self.thorvg_lib.tvg_shape_get_stroke_dash.argtypes = [
|
|
662
|
+
ctypes.POINTER(PaintStruct),
|
|
663
|
+
ctypes.POINTER(ctypes.POINTER(ctypes.c_float)),
|
|
664
|
+
ctypes.POINTER(ctypes.c_uint32),
|
|
665
|
+
]
|
|
666
|
+
self.thorvg_lib.tvg_shape_get_stroke_dash.restype = Result
|
|
667
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_dash(
|
|
668
|
+
ctypes.pointer(self._paint),
|
|
669
|
+
ctypes.pointer(dash_pattern_ptr),
|
|
670
|
+
ctypes.pointer(cnt),
|
|
671
|
+
)
|
|
672
|
+
dash_pattern_arr_type = ctypes.c_float * cnt.value
|
|
673
|
+
dash_pattern_arr = dash_pattern_arr_type.from_address(
|
|
674
|
+
ctypes.addressof(dash_pattern_ptr.contents)
|
|
675
|
+
)
|
|
676
|
+
return result, [dash_pattern_arr[i] for i in range(cnt.value)]
|
|
677
|
+
|
|
678
|
+
def set_stroke_cap(
|
|
679
|
+
self,
|
|
680
|
+
cap: StrokeCap,
|
|
681
|
+
) -> Result:
|
|
682
|
+
"""Sets the cap style used for stroking the path.
|
|
683
|
+
|
|
684
|
+
The cap style specifies the shape to be used at the end of the open stroked sub-paths.
|
|
685
|
+
|
|
686
|
+
:param StrokeCap cap: The cap style value. The default value is ``SQUARE``.
|
|
687
|
+
|
|
688
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
689
|
+
:rtype: Result
|
|
690
|
+
"""
|
|
691
|
+
self.thorvg_lib.tvg_shape_set_stroke_cap.argtypes = [
|
|
692
|
+
ctypes.POINTER(PaintStruct),
|
|
693
|
+
ctypes.c_int,
|
|
694
|
+
]
|
|
695
|
+
self.thorvg_lib.tvg_shape_set_stroke_cap.restype = Result
|
|
696
|
+
return self.thorvg_lib.tvg_shape_set_stroke_cap(
|
|
697
|
+
ctypes.pointer(self._paint),
|
|
698
|
+
cap,
|
|
699
|
+
)
|
|
700
|
+
|
|
701
|
+
def get_stroke_cap(self) -> Tuple[Result, StrokeCap]:
|
|
702
|
+
"""Gets the stroke cap style used for stroking the path.
|
|
703
|
+
|
|
704
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
705
|
+
:rtype: Result
|
|
706
|
+
:return: The cap style value.
|
|
707
|
+
:rtype: StrokeCap
|
|
708
|
+
"""
|
|
709
|
+
cap = ctypes.c_int()
|
|
710
|
+
self.thorvg_lib.tvg_shape_get_stroke_cap.argtypes = [
|
|
711
|
+
ctypes.POINTER(PaintStruct),
|
|
712
|
+
ctypes.POINTER(ctypes.c_int),
|
|
713
|
+
]
|
|
714
|
+
self.thorvg_lib.tvg_shape_get_stroke_cap.restype = Result
|
|
715
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_cap(
|
|
716
|
+
ctypes.pointer(self._paint),
|
|
717
|
+
ctypes.pointer(cap),
|
|
718
|
+
)
|
|
719
|
+
return result, StrokeCap(cap.value)
|
|
720
|
+
|
|
721
|
+
def set_stroke_join(self, join: StrokeJoin) -> Result:
|
|
722
|
+
"""Sets the join style for stroked path segments.
|
|
723
|
+
|
|
724
|
+
:param StrokeJoin join: The join style value. The default value is ``BEVEL``.
|
|
725
|
+
|
|
726
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
727
|
+
:rtype: Result
|
|
728
|
+
"""
|
|
729
|
+
self.thorvg_lib.tvg_shape_set_stroke_join.argtypes = [
|
|
730
|
+
ctypes.POINTER(PaintStruct),
|
|
731
|
+
ctypes.c_int,
|
|
732
|
+
]
|
|
733
|
+
self.thorvg_lib.tvg_shape_set_stroke_join.restype = Result
|
|
734
|
+
return self.thorvg_lib.tvg_shape_set_stroke_join(
|
|
735
|
+
ctypes.pointer(self._paint),
|
|
736
|
+
join,
|
|
737
|
+
)
|
|
738
|
+
|
|
739
|
+
def get_stroke_join(self) -> Tuple[Result, StrokeJoin]:
|
|
740
|
+
"""The function gets the stroke join method
|
|
741
|
+
|
|
742
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
743
|
+
:rtype: Result
|
|
744
|
+
:return: The join style value.
|
|
745
|
+
:rtype: StrokeJoin
|
|
746
|
+
"""
|
|
747
|
+
join = ctypes.c_int()
|
|
748
|
+
self.thorvg_lib.tvg_shape_get_stroke_join.argtypes = [
|
|
749
|
+
ctypes.POINTER(PaintStruct),
|
|
750
|
+
ctypes.POINTER(ctypes.c_int),
|
|
751
|
+
]
|
|
752
|
+
self.thorvg_lib.tvg_shape_get_stroke_join.restype = Result
|
|
753
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_join(
|
|
754
|
+
ctypes.pointer(self._paint),
|
|
755
|
+
ctypes.pointer(join),
|
|
756
|
+
)
|
|
757
|
+
return result, StrokeJoin(join.value)
|
|
758
|
+
|
|
759
|
+
def set_stroke_miterlimit(self, miterlimit: float) -> Result:
|
|
760
|
+
"""Sets the stroke miterlimit.
|
|
761
|
+
|
|
762
|
+
:param float miterlimit: The miterlimit imposes a limit on the extent of the stroke join when the ``MITER`` join style is set. The default value is 4.
|
|
763
|
+
|
|
764
|
+
:return: Result enumeration
|
|
765
|
+
INVALID_ARGUMENT An invalid PaintStruct pointer or Unsupported ``miterlimit`` values (less than zero).
|
|
766
|
+
:rtype: Result
|
|
767
|
+
|
|
768
|
+
.. versionadded:: 0.11
|
|
769
|
+
"""
|
|
770
|
+
self.thorvg_lib.tvg_shape_set_stroke_miterlimit.argtypes = [
|
|
771
|
+
ctypes.POINTER(PaintStruct),
|
|
772
|
+
ctypes.c_float,
|
|
773
|
+
]
|
|
774
|
+
self.thorvg_lib.tvg_shape_set_stroke_miterlimit.restype = Result
|
|
775
|
+
return self.thorvg_lib.tvg_shape_set_stroke_miterlimit(
|
|
776
|
+
ctypes.pointer(self._paint),
|
|
777
|
+
miterlimit,
|
|
778
|
+
)
|
|
779
|
+
|
|
780
|
+
def get_stroke_miterlimit(self) -> Tuple[Result, float]:
|
|
781
|
+
"""The function gets the stroke miterlimit.
|
|
782
|
+
|
|
783
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
784
|
+
:rtype: Result
|
|
785
|
+
:return: The stroke miterlimit.
|
|
786
|
+
:rtype: float
|
|
787
|
+
|
|
788
|
+
.. versionadded:: 0.11
|
|
789
|
+
"""
|
|
790
|
+
miterlimit = ctypes.c_float()
|
|
791
|
+
self.thorvg_lib.tvg_shape_get_stroke_miterlimit.argtypes = [
|
|
792
|
+
ctypes.POINTER(PaintStruct),
|
|
793
|
+
ctypes.POINTER(ctypes.c_float),
|
|
794
|
+
]
|
|
795
|
+
self.thorvg_lib.tvg_shape_get_stroke_miterlimit.restype = Result
|
|
796
|
+
result = self.thorvg_lib.tvg_shape_get_stroke_miterlimit(
|
|
797
|
+
ctypes.pointer(self._paint),
|
|
798
|
+
ctypes.pointer(miterlimit),
|
|
799
|
+
)
|
|
800
|
+
return result, miterlimit.value
|
|
801
|
+
|
|
802
|
+
def set_stroke_trim(
|
|
803
|
+
self,
|
|
804
|
+
begin: float,
|
|
805
|
+
end: float,
|
|
806
|
+
simultaneous: bool,
|
|
807
|
+
) -> Result:
|
|
808
|
+
"""Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible.
|
|
809
|
+
|
|
810
|
+
If the values of the arguments ``begin`` and ``end`` exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular.
|
|
811
|
+
|
|
812
|
+
:param float begin: Specifies the start of the segment to display along the path.
|
|
813
|
+
:param float end: Specifies the end of the segment to display along the path.
|
|
814
|
+
:param bool simultaneous: Determines how to trim multiple paths within a single shape. If set to ``true`` (default), trimming is applied simultaneously to all paths;
|
|
815
|
+
Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such.
|
|
816
|
+
|
|
817
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
818
|
+
:rtype: Result
|
|
819
|
+
|
|
820
|
+
.. note::
|
|
821
|
+
Experimental API
|
|
822
|
+
"""
|
|
823
|
+
self.thorvg_lib.tvg_shape_set_stroke_trim.argtypes = [
|
|
824
|
+
ctypes.POINTER(PaintStruct),
|
|
825
|
+
ctypes.c_float,
|
|
826
|
+
ctypes.c_float,
|
|
827
|
+
ctypes.c_bool,
|
|
828
|
+
]
|
|
829
|
+
self.thorvg_lib.tvg_shape_set_stroke_trim.restype = Result
|
|
830
|
+
return self.thorvg_lib.tvg_shape_set_stroke_trim(
|
|
831
|
+
ctypes.pointer(self._paint),
|
|
832
|
+
ctypes.c_float(begin),
|
|
833
|
+
ctypes.c_float(end),
|
|
834
|
+
ctypes.c_bool(simultaneous),
|
|
835
|
+
)
|
|
836
|
+
|
|
837
|
+
def set_fill_color(
|
|
838
|
+
self,
|
|
839
|
+
r: int,
|
|
840
|
+
g: int,
|
|
841
|
+
b: int,
|
|
842
|
+
a: int,
|
|
843
|
+
) -> Result:
|
|
844
|
+
"""Sets the shape's solid color.
|
|
845
|
+
|
|
846
|
+
The parts of the shape defined as inner are colored.
|
|
847
|
+
|
|
848
|
+
:param int r The red color channel value in the range [0 ~ 255]. The default value is 0.
|
|
849
|
+
:param int g: The green color channel value in the range [0 ~ 255]. The default value is 0.
|
|
850
|
+
:param int b: The blue color channel value in the range [0 ~ 255]. The default value is 0.
|
|
851
|
+
:param int a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
|
|
852
|
+
|
|
853
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
854
|
+
:rtype: Result
|
|
855
|
+
|
|
856
|
+
.. note::
|
|
857
|
+
Either a solid color or a gradient fill is applied, depending on what was set as last.
|
|
858
|
+
.. seealso:: Shape.set_fill_rule()
|
|
859
|
+
"""
|
|
860
|
+
self.thorvg_lib.tvg_shape_set_fill_color.argtypes = [
|
|
861
|
+
ctypes.POINTER(PaintStruct),
|
|
862
|
+
ctypes.c_uint8,
|
|
863
|
+
ctypes.c_uint8,
|
|
864
|
+
ctypes.c_uint8,
|
|
865
|
+
ctypes.c_uint8,
|
|
866
|
+
]
|
|
867
|
+
self.thorvg_lib.tvg_shape_set_fill_color.restype = Result
|
|
868
|
+
return self.thorvg_lib.tvg_shape_set_fill_color(
|
|
869
|
+
ctypes.pointer(self._paint),
|
|
870
|
+
ctypes.c_uint8(r),
|
|
871
|
+
ctypes.c_uint8(g),
|
|
872
|
+
ctypes.c_uint8(b),
|
|
873
|
+
ctypes.c_uint8(a),
|
|
874
|
+
)
|
|
875
|
+
|
|
876
|
+
def get_fill_color(self) -> Tuple[Result, int, int, int, int]:
|
|
877
|
+
"""Gets the shape's solid color.
|
|
878
|
+
|
|
879
|
+
:return: The red color channel value in the range [0 ~ 255]. The default value is 0.
|
|
880
|
+
:rtype: int
|
|
881
|
+
:return: The green color channel value in the range [0 ~ 255]. The default value is 0.
|
|
882
|
+
:rtype: int
|
|
883
|
+
:return: The blue color channel value in the range [0 ~ 255]. The default value is 0.
|
|
884
|
+
:rtype: int
|
|
885
|
+
:return: The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
|
|
886
|
+
:rtype: int
|
|
887
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
888
|
+
:rtype: Result
|
|
889
|
+
"""
|
|
890
|
+
r = ctypes.c_uint8()
|
|
891
|
+
g = ctypes.c_uint8()
|
|
892
|
+
b = ctypes.c_uint8()
|
|
893
|
+
a = ctypes.c_uint8()
|
|
894
|
+
self.thorvg_lib.tvg_shape_get_fill_color.argtypes = [
|
|
895
|
+
ctypes.POINTER(PaintStruct),
|
|
896
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
897
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
898
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
899
|
+
ctypes.POINTER(ctypes.c_uint8),
|
|
900
|
+
]
|
|
901
|
+
self.thorvg_lib.tvg_shape_get_fill_color.restype = Result
|
|
902
|
+
result = self.thorvg_lib.tvg_shape_get_fill_color(
|
|
903
|
+
ctypes.pointer(self._paint),
|
|
904
|
+
ctypes.pointer(r),
|
|
905
|
+
ctypes.pointer(g),
|
|
906
|
+
ctypes.pointer(b),
|
|
907
|
+
ctypes.pointer(a),
|
|
908
|
+
)
|
|
909
|
+
|
|
910
|
+
return result, r.value, g.value, b.value, a.value
|
|
911
|
+
|
|
912
|
+
def set_fill_rule(self, rule: FillRule) -> Result:
|
|
913
|
+
"""Sets the shape's fill rule.
|
|
914
|
+
|
|
915
|
+
:param FillRule rule: The fill rule value. The default value is ``WINDING``.
|
|
916
|
+
|
|
917
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
918
|
+
:rtype: Result
|
|
919
|
+
"""
|
|
920
|
+
self.thorvg_lib.tvg_shape_set_fill_rule.argtypes = [
|
|
921
|
+
ctypes.POINTER(PaintStruct),
|
|
922
|
+
ctypes.c_uint8,
|
|
923
|
+
]
|
|
924
|
+
self.thorvg_lib.tvg_shape_set_fill_rule.restype = Result
|
|
925
|
+
return self.thorvg_lib.tvg_shape_set_fill_rule(
|
|
926
|
+
ctypes.pointer(self._paint),
|
|
927
|
+
ctypes.c_uint8(rule),
|
|
928
|
+
)
|
|
929
|
+
|
|
930
|
+
def get_fill_rule(self) -> Tuple[Result, FillRule]:
|
|
931
|
+
"""Gets the shape's fill rule.
|
|
932
|
+
|
|
933
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
934
|
+
:rtype: Result
|
|
935
|
+
:return: shape's fill rule
|
|
936
|
+
:rtype: FillRule
|
|
937
|
+
"""
|
|
938
|
+
rule = ctypes.c_int()
|
|
939
|
+
self.thorvg_lib.tvg_shape_get_fill_rule.argtypes = [
|
|
940
|
+
ctypes.POINTER(PaintStruct),
|
|
941
|
+
ctypes.POINTER(ctypes.c_int),
|
|
942
|
+
]
|
|
943
|
+
self.thorvg_lib.tvg_shape_get_fill_rule.restype = Result
|
|
944
|
+
result = self.thorvg_lib.tvg_shape_get_fill_rule(
|
|
945
|
+
ctypes.pointer(self._paint),
|
|
946
|
+
ctypes.pointer(rule),
|
|
947
|
+
)
|
|
948
|
+
|
|
949
|
+
return result, FillRule(rule.value)
|
|
950
|
+
|
|
951
|
+
def set_paint_order(self, stroke_first: bool) -> Result:
|
|
952
|
+
"""Sets the rendering order of the stroke and the fill.
|
|
953
|
+
|
|
954
|
+
:param bool strokeFirst: If ``true`` the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option).
|
|
955
|
+
|
|
956
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
957
|
+
:rtype: Result
|
|
958
|
+
|
|
959
|
+
.. versionadded:: 0.10
|
|
960
|
+
"""
|
|
961
|
+
self.thorvg_lib.tvg_shape_set_paint_order.argtypes = [
|
|
962
|
+
ctypes.POINTER(PaintStruct),
|
|
963
|
+
ctypes.c_bool,
|
|
964
|
+
]
|
|
965
|
+
self.thorvg_lib.tvg_shape_set_paint_order.restype = Result
|
|
966
|
+
return self.thorvg_lib.tvg_shape_set_paint_order(
|
|
967
|
+
ctypes.pointer(self._paint),
|
|
968
|
+
ctypes.c_bool(stroke_first),
|
|
969
|
+
)
|
|
970
|
+
|
|
971
|
+
def set_linear_gradient(self, grad: "Gradient") -> Result:
|
|
972
|
+
"""Sets the linear gradient fill for all of the figures from the path.
|
|
973
|
+
|
|
974
|
+
The parts of the shape defined as inner are filled.
|
|
975
|
+
|
|
976
|
+
.. code-block:: python
|
|
977
|
+
|
|
978
|
+
from thorvg_python import Engine, Shape, LinearGradient, ColorStop
|
|
979
|
+
|
|
980
|
+
engine = Engine()
|
|
981
|
+
shape = Shape(engine)
|
|
982
|
+
grad = LinearGradient(engine)
|
|
983
|
+
grad.set(700, 700, 800, 800)
|
|
984
|
+
color_stops = [
|
|
985
|
+
ColorStop(0.0 , 0, 0, 0, 255),
|
|
986
|
+
ColorStop(0.25, 255, 0, 0, 255),
|
|
987
|
+
ColorStop(0.5 , 0, 255, 0, 255),
|
|
988
|
+
ColorStop(1.0 , 0, 0, 255, 255)
|
|
989
|
+
]
|
|
990
|
+
grad.set_color_stops(color_stops, 4)
|
|
991
|
+
shape.set_linear_gradient(grad)
|
|
992
|
+
|
|
993
|
+
:param GradientStruct grad: The linear gradient fill.
|
|
994
|
+
|
|
995
|
+
:return:
|
|
996
|
+
- INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
997
|
+
- MEMORY_CORRUPTION An invalid GradientStruct pointer.
|
|
998
|
+
:rtype: Result
|
|
999
|
+
|
|
1000
|
+
.. note::
|
|
1001
|
+
Either a solid color or a gradient fill is applied, depending on what was set as last.
|
|
1002
|
+
.. seealso:: Shape.set_fill_rule()
|
|
1003
|
+
"""
|
|
1004
|
+
self.thorvg_lib.tvg_shape_set_linear_gradient.argtypes = [
|
|
1005
|
+
ctypes.POINTER(PaintStruct),
|
|
1006
|
+
ctypes.POINTER(GradientStruct),
|
|
1007
|
+
]
|
|
1008
|
+
self.thorvg_lib.tvg_shape_set_linear_gradient.restype = Result
|
|
1009
|
+
return self.thorvg_lib.tvg_shape_set_linear_gradient(
|
|
1010
|
+
ctypes.pointer(self._paint),
|
|
1011
|
+
ctypes.pointer(grad._grad), # type: ignore
|
|
1012
|
+
)
|
|
1013
|
+
|
|
1014
|
+
def set_radial_gradient(self, grad: "Gradient") -> Result:
|
|
1015
|
+
"""Sets the radial gradient fill for all of the figures from the path.
|
|
1016
|
+
|
|
1017
|
+
The parts of the shape defined as inner are filled.
|
|
1018
|
+
|
|
1019
|
+
.. code-block:: python
|
|
1020
|
+
|
|
1021
|
+
from thorvg_python import Engine, Shape, RadialGradient, ColorStop
|
|
1022
|
+
|
|
1023
|
+
engine = Engine()
|
|
1024
|
+
shape = Shape(engine)
|
|
1025
|
+
grad = RadialGradient(engine)
|
|
1026
|
+
grad.set(550, 550, 50)
|
|
1027
|
+
color_stops = [
|
|
1028
|
+
ColorStop(0.0 , 0, 0, 0, 255),
|
|
1029
|
+
ColorStop(0.25, 255, 0, 0, 255),
|
|
1030
|
+
ColorStop(0.5 , 0, 255, 0, 255),
|
|
1031
|
+
ColorStop(1.0 , 0, 0, 255, 255)
|
|
1032
|
+
]
|
|
1033
|
+
grad.set_color_stops(color_stops, 4)
|
|
1034
|
+
shape.set_radial_gradient(grad)
|
|
1035
|
+
|
|
1036
|
+
:param GradientStruct grad: The radial gradient fill.
|
|
1037
|
+
|
|
1038
|
+
:return: INVALID_ARGUMENT An invalid PaintStruct pointer.
|
|
1039
|
+
MEMORY_CORRUPTION An invalid GradientStruct pointer.
|
|
1040
|
+
:rtype: Result
|
|
1041
|
+
|
|
1042
|
+
.. note::
|
|
1043
|
+
Either a solid color or a gradient fill is applied, depending on what was set as last.
|
|
1044
|
+
.. seealso:: Shape.set_fill_rule()
|
|
1045
|
+
"""
|
|
1046
|
+
self.thorvg_lib.tvg_shape_set_radial_gradient.argtypes = [
|
|
1047
|
+
ctypes.POINTER(PaintStruct),
|
|
1048
|
+
ctypes.POINTER(GradientStruct),
|
|
1049
|
+
]
|
|
1050
|
+
self.thorvg_lib.tvg_shape_set_radial_gradient.restype = Result
|
|
1051
|
+
return self.thorvg_lib.tvg_shape_set_radial_gradient(
|
|
1052
|
+
ctypes.pointer(self._paint),
|
|
1053
|
+
ctypes.pointer(grad._grad), # type: ignore
|
|
1054
|
+
)
|
|
1055
|
+
|
|
1056
|
+
def get_gradient(self) -> Tuple[Result, Union["LinearGradient", "RadialGradient"]]:
|
|
1057
|
+
"""Gets the gradient fill of the shape.
|
|
1058
|
+
|
|
1059
|
+
The function does not allocate any data.
|
|
1060
|
+
|
|
1061
|
+
:return: INVALID_ARGUMENT An invalid pointer passed as an argument.
|
|
1062
|
+
:rtype: Result
|
|
1063
|
+
:return: The gradient fill.
|
|
1064
|
+
:rtype: GradientStruct
|
|
1065
|
+
"""
|
|
1066
|
+
grad_ptr = ctypes.POINTER(GradientStruct)()
|
|
1067
|
+
self.thorvg_lib.tvg_shape_get_gradient.argtypes = [
|
|
1068
|
+
ctypes.POINTER(PaintStruct),
|
|
1069
|
+
ctypes.POINTER(ctypes.POINTER(GradientStruct)),
|
|
1070
|
+
]
|
|
1071
|
+
self.thorvg_lib.tvg_shape_get_gradient.restype = Result
|
|
1072
|
+
result = self.thorvg_lib.tvg_shape_get_gradient(
|
|
1073
|
+
ctypes.pointer(self._paint),
|
|
1074
|
+
ctypes.pointer(grad_ptr),
|
|
1075
|
+
)
|
|
1076
|
+
_, tvg_type = Gradient(self.engine, grad_ptr.contents).get_type()
|
|
1077
|
+
if tvg_type == TvgType.LINEAR_GRAD:
|
|
1078
|
+
return result, LinearGradient(self.engine, grad_ptr.contents)
|
|
1079
|
+
elif tvg_type == TvgType.RADIAL_GRAD:
|
|
1080
|
+
return result, RadialGradient(self.engine, grad_ptr.contents)
|
|
1081
|
+
else:
|
|
1082
|
+
raise RuntimeError(f"Invalid gradient TvgType: {tvg_type}")
|