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.
@@ -0,0 +1,432 @@
1
+ #!/usr/bin/env python3
2
+ import ctypes
3
+ from typing import Optional, Tuple
4
+
5
+ from ..base import (
6
+ BlendMethod,
7
+ CompositeMethod,
8
+ Identifier,
9
+ Matrix,
10
+ PaintStruct,
11
+ Result,
12
+ TvgType,
13
+ )
14
+ from ..engine import Engine
15
+
16
+
17
+ class Paint:
18
+ """
19
+ Paint API
20
+
21
+ A module for managing graphical elements. It enables duplication, transformation and composition.
22
+
23
+ This is base Paint class. Please instantiate with Shape, Picture, Scene or Text instead.
24
+ """
25
+
26
+ def __init__(self, engine: Engine, paint: PaintStruct):
27
+ self.engine = engine
28
+ self.thorvg_lib = engine.thorvg_lib
29
+ self._paint = paint
30
+
31
+ def _del(self) -> Result:
32
+ """Releases the given PaintStruct object.
33
+
34
+ :return: INVALID_ARGUMENT An invalid PaintStruct pointer.
35
+
36
+ .. warning::
37
+ If this function is used, tvg_canvas_clear() with the ``free`` argument value set to ``false`` should be used in order to avoid unexpected behaviours.
38
+
39
+ .. seealso:: Canvas.clear(), Canvas.destroy()
40
+ """
41
+ self.thorvg_lib.tvg_paint_del.argtypes = [
42
+ ctypes.POINTER(PaintStruct),
43
+ ]
44
+ self.thorvg_lib.tvg_paint_del.restype = Result
45
+ return self.thorvg_lib.tvg_paint_del(
46
+ ctypes.pointer(self._paint),
47
+ )
48
+
49
+ def scale(self, factor: float) -> Result:
50
+ """Scales the given PaintStruct object by the given factor.
51
+
52
+ :param float factor: The value of the scaling factor. The default value is 1.
53
+
54
+ :return:
55
+ - INVALID_ARGUMENT An invalid PaintStruct pointer.
56
+ - INSUFFICIENT_CONDITION in case a custom transform is applied.
57
+ :rtype: Result
58
+
59
+ .. seealso:: Paint.set_transform()
60
+ """
61
+ self.thorvg_lib.tvg_paint_scale.argtypes = [
62
+ ctypes.POINTER(PaintStruct),
63
+ ctypes.c_float,
64
+ ]
65
+ self.thorvg_lib.tvg_paint_scale.restype = Result
66
+ return self.thorvg_lib.tvg_paint_scale(
67
+ ctypes.pointer(self._paint),
68
+ ctypes.c_float(factor),
69
+ )
70
+
71
+ def rotate(
72
+ self,
73
+ degree: float,
74
+ ) -> Result:
75
+ """Rotates the given PaintStruct by the given angle.
76
+
77
+ The angle in measured clockwise from the horizontal axis.
78
+ The rotational axis passes through the point on the object with zero coordinates.
79
+
80
+ :param float degree: The value of the rotation angle in degrees.
81
+
82
+ :return:
83
+ - INVALID_ARGUMENT An invalid PaintStruct pointer.
84
+ - INSUFFICIENT_CONDITION in case a custom transform is applied.
85
+ :rtype: Result
86
+
87
+ .. seealso:: Paint.set_transform()
88
+ """
89
+ self.thorvg_lib.tvg_paint_rotate.argtypes = [
90
+ ctypes.POINTER(PaintStruct),
91
+ ctypes.c_float,
92
+ ]
93
+ self.thorvg_lib.tvg_paint_rotate.restype = Result
94
+ return self.thorvg_lib.tvg_paint_rotate(
95
+ ctypes.pointer(self._paint),
96
+ ctypes.c_float(degree),
97
+ )
98
+
99
+ def translate(
100
+ self,
101
+ x: float,
102
+ y: float,
103
+ ) -> Result:
104
+ """Moves the given PaintStruct in a two-dimensional space.
105
+
106
+ The origin of the coordinate system is in the upper-left corner of the canvas.
107
+ The horizontal and vertical axes point to the right and down, respectively.
108
+
109
+ :param float x: The value of the horizontal shift.
110
+ :param float y: The value of the vertical shift.
111
+
112
+ :return:
113
+ - INVALID_ARGUMENT An invalid PaintStruct pointer.
114
+ - INSUFFICIENT_CONDITION in case a custom transform is applied.
115
+ :rtype: Result
116
+
117
+ .. seealso:: Paint.set_transform()
118
+ """
119
+ self.thorvg_lib.tvg_paint_translate.argtypes = [
120
+ ctypes.POINTER(PaintStruct),
121
+ ctypes.c_float,
122
+ ctypes.c_float,
123
+ ]
124
+ self.thorvg_lib.tvg_paint_translate.restype = Result
125
+ return self.thorvg_lib.tvg_paint_translate(
126
+ ctypes.pointer(self._paint),
127
+ ctypes.c_float(x),
128
+ ctypes.c_float(y),
129
+ )
130
+
131
+ def set_transform(
132
+ self,
133
+ m: Matrix,
134
+ ) -> Result:
135
+ """Transforms the given PaintStruct using the augmented transformation matrix.
136
+
137
+ The augmented matrix of the transformation is expected to be given.
138
+
139
+ :param Matrix m: The 3x3 augmented matrix.
140
+
141
+ :return: INVALID_ARGUMENT A ``nullptr`` is passed as the argument.
142
+ :rtype: Result
143
+ """
144
+ self.thorvg_lib.tvg_paint_set_transform.argtypes = [
145
+ ctypes.POINTER(PaintStruct),
146
+ ctypes.POINTER(Matrix),
147
+ ]
148
+ self.thorvg_lib.tvg_paint_set_transform.restype = Result
149
+ return self.thorvg_lib.tvg_paint_set_transform(
150
+ ctypes.pointer(self._paint),
151
+ ctypes.pointer(m),
152
+ )
153
+
154
+ def get_transform(
155
+ self,
156
+ ) -> Tuple[Result, Matrix]:
157
+ """Gets the matrix of the affine transformation of the given PaintStruct object.
158
+
159
+ In case no transformation was applied, the identity matrix is returned.
160
+
161
+ :return: INVALID_ARGUMENT A ``nullptr`` is passed as the argument.
162
+ :rtype: Result
163
+ :return: The 3x3 augmented matrix.
164
+ :rtype: Matrix
165
+ """
166
+ m = Matrix()
167
+ self.thorvg_lib.tvg_paint_get_transform.argtypes = [
168
+ ctypes.POINTER(PaintStruct),
169
+ ctypes.POINTER(Matrix),
170
+ ]
171
+ self.thorvg_lib.tvg_paint_get_transform.restype = Result
172
+ result = self.thorvg_lib.tvg_paint_get_transform(
173
+ ctypes.pointer(self._paint),
174
+ ctypes.pointer(m),
175
+ )
176
+ return result, m
177
+
178
+ def set_opacity(
179
+ self,
180
+ opacity: int,
181
+ ) -> Result:
182
+ """Sets the opacity of the given PaintStruct.
183
+
184
+ :param int opacity: The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
185
+
186
+ :return: INVALID_ARGUMENT An invalid PaintStruct pointer.
187
+ :rtype: Result
188
+
189
+ .. note::
190
+ Setting the opacity with this API may require multiple renderings using a composition.
191
+ It is recommended to avoid changing the opacity if possible.
192
+ """
193
+ self.thorvg_lib.tvg_paint_set_opacity.argtypes = [
194
+ ctypes.POINTER(PaintStruct),
195
+ ctypes.c_uint8,
196
+ ]
197
+ self.thorvg_lib.tvg_paint_set_opacity.restype = Result
198
+ return self.thorvg_lib.tvg_paint_set_opacity(
199
+ ctypes.pointer(self._paint),
200
+ ctypes.c_uint8(opacity),
201
+ )
202
+
203
+ def get_opacity(
204
+ self,
205
+ ) -> Tuple[Result, int]:
206
+ """Gets the opacity of the given PaintStruct.
207
+
208
+ :return: INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument.
209
+ :rtype: Result
210
+ :return: The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
211
+ :rtype: int
212
+ """
213
+ opacity = ctypes.c_uint8()
214
+ self.thorvg_lib.tvg_paint_get_opacity.argtypes = [
215
+ ctypes.POINTER(PaintStruct),
216
+ ctypes.POINTER(ctypes.c_uint8),
217
+ ]
218
+ self.thorvg_lib.tvg_paint_get_opacity.restype = Result
219
+ result = self.thorvg_lib.tvg_paint_get_opacity(
220
+ ctypes.pointer(self._paint),
221
+ ctypes.pointer(opacity),
222
+ )
223
+ return result, opacity.value
224
+
225
+ def duplicate(
226
+ self,
227
+ ) -> Optional[PaintStruct]:
228
+ """Duplicates the given PaintStruct object.
229
+
230
+ Creates a new object and sets its all properties as in the original object.
231
+
232
+ :return: A copied PaintStruct object if succeed, ``nullptr`` otherwise.
233
+ :rtype: Optional[PaintStruct]
234
+ """
235
+ self.thorvg_lib.tvg_paint_duplicate.argtypes = [
236
+ ctypes.POINTER(PaintStruct),
237
+ ]
238
+ self.thorvg_lib.tvg_paint_duplicate.restype = ctypes.POINTER(PaintStruct)
239
+ return self.thorvg_lib.tvg_paint_duplicate(
240
+ ctypes.pointer(self._paint),
241
+ ).contents
242
+
243
+ def get_bounds(
244
+ self,
245
+ transformed: bool = False,
246
+ ) -> Tuple[Result, float, float, float, float]:
247
+ """Gets the axis-aligned bounding box of the PaintStruct object.
248
+
249
+ :param bool transformed: If ``true``, the paint's transformations are taken into account in the scene it belongs to. Otherwise they aren't.
250
+
251
+ :return: INVALID_ARGUMENT An invalid PaintStruct pointer.
252
+ :rtype: Result
253
+ :return: The x-coordinate of the upper-left corner of the object.
254
+ :rtype: float
255
+ :return: The y-coordinate of the upper-left corner of the object.
256
+ :rtype: float
257
+ :return: The width of the object.
258
+ :rtype: float
259
+ :return: The height of the object.
260
+ :rtype: float
261
+
262
+ .. note::
263
+ This is useful when you need to figure out the bounding box of the paint in the canvas space.
264
+ .. note::
265
+ The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.
266
+ .. note::
267
+ If ``transformed`` is ``true``, the paint needs to be pushed into a canvas and updated before this api is called.
268
+ .. seealso:: Canvas.update_paint()
269
+ """
270
+ x = ctypes.c_float(0.0)
271
+ y = ctypes.c_float(0.0)
272
+ w = ctypes.c_float(0.0)
273
+ h = ctypes.c_float(0.0)
274
+ self.thorvg_lib.tvg_paint_get_bounds.argtypes = [
275
+ ctypes.POINTER(PaintStruct),
276
+ ctypes.POINTER(ctypes.c_float),
277
+ ctypes.POINTER(ctypes.c_float),
278
+ ctypes.POINTER(ctypes.c_float),
279
+ ctypes.POINTER(ctypes.c_float),
280
+ ctypes.c_bool,
281
+ ]
282
+ self.thorvg_lib.tvg_paint_get_bounds.restype = Result
283
+ result = self.thorvg_lib.tvg_paint_get_bounds(
284
+ ctypes.pointer(self._paint),
285
+ ctypes.pointer(x),
286
+ ctypes.pointer(y),
287
+ ctypes.pointer(w),
288
+ ctypes.pointer(h),
289
+ ctypes.c_bool(transformed),
290
+ )
291
+ return result, x.value, y.value, w.value, h.value
292
+
293
+ def set_composite_method(
294
+ self,
295
+ target: "Paint",
296
+ method: CompositeMethod,
297
+ ) -> Result:
298
+ """Sets the composition target object and the composition method.
299
+
300
+ :param Paint target: The target object of the composition.
301
+ :param CompositeMethod method: The method used to composite the source object with the target.
302
+
303
+ :return: INVALID_ARGUMENT An invalid ``paint`` or ``target`` object or the ``method`` equal to NONE.
304
+ :rtype: Result
305
+ """
306
+ self.thorvg_lib.tvg_paint_set_composite_method.argtypes = [
307
+ ctypes.POINTER(PaintStruct),
308
+ ctypes.POINTER(PaintStruct),
309
+ ctypes.c_int,
310
+ ]
311
+ self.thorvg_lib.tvg_paint_set_composite_method.restype = Result
312
+ return self.thorvg_lib.tvg_paint_set_composite_method(
313
+ ctypes.pointer(self._paint), ctypes.pointer(target._paint), method
314
+ )
315
+
316
+ def get_composite_method(
317
+ self,
318
+ ) -> Tuple[Result, PaintStruct, CompositeMethod]:
319
+ """Gets the composition target object and the composition method.
320
+
321
+ :return: INVALID_ARGUMENT A ``nullptr`` is passed as the argument.
322
+ :rtype: Result
323
+ :return: The target object of the composition.
324
+ :rtype: PaintStruct
325
+ :return: The method used to composite the source object with the target.
326
+ :rtype: CompositeMethod
327
+ """
328
+ target = PaintStruct()
329
+ method = ctypes.c_int()
330
+ self.thorvg_lib.tvg_paint_get_composite_method.argtypes = [
331
+ ctypes.POINTER(PaintStruct),
332
+ ctypes.POINTER(ctypes.POINTER(PaintStruct)),
333
+ ctypes.POINTER(ctypes.c_int),
334
+ ]
335
+ self.thorvg_lib.tvg_paint_get_composite_method.restype = Result
336
+ result = self.thorvg_lib.tvg_paint_get_composite_method(
337
+ ctypes.pointer(self._paint),
338
+ ctypes.pointer(ctypes.pointer(target)),
339
+ ctypes.pointer(method),
340
+ )
341
+ return result, target, CompositeMethod(method.value)
342
+
343
+ def set_clip(self, clipper: "Paint") -> Result:
344
+ """Clip the drawing region of the paint object.
345
+
346
+ This function restricts the drawing area of the paint object to the specified shape's paths.
347
+
348
+ :param Paint clipper: The shape object as the clipper.
349
+
350
+ :return:
351
+ - INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument.
352
+ - NOT_SUPPORTED If the ``clipper`` type is not Shape.
353
+ :rtype: Result
354
+
355
+ .. note::
356
+ Experimental API
357
+ """
358
+ self.thorvg_lib.tvg_paint_set_clip.argtypes = [
359
+ ctypes.POINTER(PaintStruct),
360
+ ctypes.POINTER(PaintStruct),
361
+ ]
362
+ self.thorvg_lib.tvg_paint_set_clip.restype = Result
363
+ return self.thorvg_lib.tvg_paint_set_clip(
364
+ ctypes.pointer(self._paint),
365
+ ctypes.pointer(clipper._paint),
366
+ )
367
+
368
+ def get_type(self) -> Tuple[Result, TvgType]:
369
+ """
370
+ Gets the unique value of the paint instance indicating the instance type.
371
+
372
+ :return: INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument.
373
+ :rtype: Result
374
+ :return: The unique type of the paint instance type.
375
+ :rtype: TvgType
376
+
377
+ .. note::
378
+ Experimental API
379
+ """
380
+ _type = ctypes.c_int()
381
+ self.thorvg_lib.tvg_paint_get_type.argtypes = [
382
+ ctypes.POINTER(PaintStruct),
383
+ ctypes.POINTER(ctypes.c_int),
384
+ ]
385
+ self.thorvg_lib.tvg_paint_get_type.restype = Result
386
+ result = self.thorvg_lib.tvg_paint_get_type(
387
+ ctypes.pointer(self._paint),
388
+ ctypes.pointer(_type),
389
+ )
390
+ return result, TvgType(_type.value)
391
+
392
+ def get_identifier(self) -> Tuple[Result, Identifier]:
393
+ """
394
+ .. deprecated:: 0.15
395
+
396
+ .. seealso:: Paint.get_type()
397
+ """
398
+ identifier = ctypes.c_int()
399
+ self.thorvg_lib.tvg_paint_get_identifier.argtypes = [
400
+ ctypes.POINTER(PaintStruct),
401
+ ctypes.POINTER(ctypes.c_int),
402
+ ]
403
+ self.thorvg_lib.tvg_paint_get_identifier.restype = Result
404
+ result = self.thorvg_lib.tvg_paint_get_identifier(
405
+ ctypes.pointer(self._paint),
406
+ ctypes.pointer(identifier),
407
+ )
408
+ return result, Identifier(identifier.value)
409
+
410
+ def set_blend_method(self, method: BlendMethod) -> Result:
411
+ """Sets the blending method for the paint object.
412
+
413
+ The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others.
414
+ its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations.
415
+ The blending operation is determined by the chosen ``BlendMethod``, which specifies how the colors or images are combined.
416
+
417
+ :param BlendMethod method: The blending method to be set.
418
+
419
+ :return: INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument.
420
+ :rtype: Result
421
+
422
+ .. versionadded:: 0.15
423
+ """
424
+ self.thorvg_lib.tvg_paint_set_blend_method.argtypes = [
425
+ ctypes.POINTER(PaintStruct),
426
+ ctypes.c_int,
427
+ ]
428
+ self.thorvg_lib.tvg_paint_set_blend_method.restype = Result
429
+ return self.thorvg_lib.tvg_paint_set_blend_method(
430
+ ctypes.pointer(self._paint),
431
+ method,
432
+ )
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env python3
2
+ import ctypes
3
+ from typing import Optional, Tuple
4
+
5
+ from ..base import PaintStruct, Result
6
+ from ..engine import Engine
7
+ from . import Paint
8
+
9
+
10
+ class Picture(Paint):
11
+ """
12
+ Picture API
13
+
14
+ A module enabling to create and to load an image in one of the supported formats: svg, png, jpg, lottie and raw.
15
+ """
16
+
17
+ def __init__(self, engine: Engine, paint: Optional[PaintStruct] = None):
18
+ self.engine = engine
19
+ self.thorvg_lib = engine.thorvg_lib
20
+ if paint is None:
21
+ self._paint = self._new()
22
+ else:
23
+ self._paint = paint
24
+
25
+ def _new(self) -> PaintStruct:
26
+ """Creates a new picture object.
27
+
28
+ Note that you need not call this method as it is auto called when initializing ``Picture()``.
29
+
30
+ :return: A new picture object.
31
+ :rtype: PaintStruct
32
+ """
33
+ self.thorvg_lib.tvg_picture_new.restype = ctypes.POINTER(PaintStruct)
34
+ return self.thorvg_lib.tvg_picture_new().contents
35
+
36
+ def load(
37
+ self,
38
+ path: str,
39
+ ) -> Result:
40
+ """Loads a picture data directly from a file.
41
+
42
+ ThorVG efficiently caches the loaded data using the specified ``path`` as a key.
43
+ This means that loading the same file again will not result in duplicate operations;
44
+ instead, ThorVG will reuse the previously loaded picture data.
45
+
46
+ :param str path: The absolute path to the image file.
47
+
48
+ :return:
49
+ - INVALID_ARGUMENT An invalid PaintStruct pointer or an empty ``path``.
50
+ - NOT_SUPPORTED A file with an unknown extension.
51
+ :rtype: Result
52
+ """
53
+ path_bytes = path.encode() + b"\x00"
54
+ path_char = ctypes.create_string_buffer(path_bytes)
55
+ self.thorvg_lib.tvg_picture_load.argtypes = [
56
+ ctypes.POINTER(PaintStruct),
57
+ ctypes.c_char * ctypes.sizeof(path_char),
58
+ ]
59
+ return self.thorvg_lib.tvg_picture_load(
60
+ ctypes.pointer(self._paint),
61
+ path_char,
62
+ )
63
+
64
+ def load_raw(
65
+ self,
66
+ data: bytes,
67
+ w: int,
68
+ h: int,
69
+ copy: bool,
70
+ ) -> Result:
71
+ """Loads a picture data from a memory block of a given size.
72
+
73
+ ThorVG efficiently caches the loaded data using the specified ``data`` address as a key
74
+ when the ``copy`` has ``false``. This means that loading the same data again will not result in duplicate operations
75
+ for the sharable ``data``. Instead, ThorVG will reuse the previously loaded picture data.
76
+
77
+ :param bytes data: A pointer to a memory location where the content of the picture raw data is stored.
78
+ :param int w: The width of the image ``data`` in pixels.
79
+ :param int h: The height of the image ``data`` in pixels.
80
+ :param bool copy: If ``true`` the data are copied into the engine local buffer, otherwise they are not.
81
+
82
+ :return: INVALID_ARGUMENT An invalid PaintStruct pointer or no data are provided or the ``width`` or ``height`` value is zero or less.
83
+ FAILED_ALLOCATION A problem with memory allocation occurs.
84
+ :rtype: Result
85
+
86
+ .. versionadded:: 0.9
87
+ """
88
+ data_arr_type = ctypes.c_uint32 * int(len(data) / 4)
89
+ data_arr = data_arr_type.from_buffer_copy(data)
90
+ self.thorvg_lib.tvg_picture_load_raw.argtypes = [
91
+ ctypes.POINTER(PaintStruct),
92
+ ctypes.POINTER(data_arr_type),
93
+ ctypes.c_uint32,
94
+ ctypes.c_uint32,
95
+ ctypes.c_bool,
96
+ ]
97
+ return self.thorvg_lib.tvg_picture_load_raw(
98
+ ctypes.pointer(self._paint),
99
+ ctypes.pointer(data_arr),
100
+ ctypes.c_uint32(w),
101
+ ctypes.c_uint32(h),
102
+ ctypes.c_bool(copy),
103
+ )
104
+
105
+ def load_data(
106
+ self,
107
+ data: bytes,
108
+ mimetype: str,
109
+ copy: bool,
110
+ ) -> Result:
111
+ """Loads a picture data from a memory block of a given size.
112
+
113
+ ThorVG efficiently caches the loaded data using the specified ``data`` address as a key
114
+ when the ``copy`` has ``false``. This means that loading the same data again will not result in duplicate operations
115
+ for the sharable ``data``. Instead, ThorVG will reuse the previously loaded picture data.
116
+
117
+ :param bytes data: A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if ``copy`` is ``false``
118
+ :param str mimetype: Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lottie", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.
119
+ :param bool copy: If ``true`` the data are copied into the engine local buffer, otherwise they are not.
120
+
121
+ :return: INVALID_ARGUMENT In case a ``nullptr`` is passed as the argument or the ``size`` is zero or less.
122
+ NOT_SUPPORTED A file with an unknown extension.
123
+ :rtype: Result
124
+
125
+ .. warning::
126
+ : It's the user responsibility to release the ``data`` memory if the ``copy`` is ``true``.
127
+ """
128
+ mimetype_bytes = mimetype.encode() + b"\x00"
129
+ data_arr_type = ctypes.c_char * len(data)
130
+ data_arr = data_arr_type.from_buffer_copy(data)
131
+ mimetype_char_type = ctypes.c_char * len(mimetype_bytes)
132
+ mimetype_char = mimetype_char_type.from_buffer_copy(mimetype_bytes)
133
+ self.thorvg_lib.tvg_picture_load_data.argtypes = [
134
+ ctypes.POINTER(PaintStruct),
135
+ ctypes.POINTER(data_arr_type),
136
+ ctypes.c_uint32,
137
+ ctypes.POINTER(mimetype_char_type),
138
+ ctypes.c_bool,
139
+ ]
140
+ return self.thorvg_lib.tvg_picture_load_data(
141
+ ctypes.pointer(self._paint),
142
+ ctypes.pointer(data_arr),
143
+ ctypes.c_uint32(ctypes.sizeof(data_arr)),
144
+ ctypes.pointer(mimetype_char),
145
+ ctypes.c_bool(copy),
146
+ )
147
+
148
+ def set_size(
149
+ self,
150
+ w: float,
151
+ h: float,
152
+ ) -> Result:
153
+ """Resizes the picture content to the given width and height.
154
+
155
+ The picture content is resized while keeping the default size aspect ratio.
156
+ The scaling factor is established for each of dimensions and the smaller value is applied to both of them.
157
+
158
+ :param float w: A new width of the image in pixels.
159
+ :param float h: A new height of the image in pixels.
160
+
161
+ :return: INVALID_ARGUMENT An invalid PaintStruct pointer.
162
+ :rtype: Result
163
+ """
164
+ self.thorvg_lib.tvg_picture_set_size.argtypes = [
165
+ ctypes.POINTER(PaintStruct),
166
+ ctypes.c_float,
167
+ ctypes.c_float,
168
+ ]
169
+ self.thorvg_lib.tvg_picture_set_size.restype = Result
170
+ return self.thorvg_lib.tvg_picture_set_size(
171
+ ctypes.pointer(self._paint),
172
+ ctypes.c_float(w),
173
+ ctypes.c_float(h),
174
+ )
175
+
176
+ def get_size(self) -> Tuple[Result, float, float]:
177
+ """Gets the size of the loaded picture.
178
+
179
+ :return: INVALID_ARGUMENT An invalid PaintStruct pointer.
180
+ :rtype: Result
181
+ :return: A width of the image in pixels.
182
+ :rtype: float
183
+ :return: A height of the image in pixels.
184
+ :rtype: float
185
+ """
186
+ w = ctypes.c_float()
187
+ h = ctypes.c_float()
188
+ self.thorvg_lib.tvg_picture_get_size.argtypes = [
189
+ ctypes.POINTER(PaintStruct),
190
+ ctypes.POINTER(ctypes.c_float),
191
+ ctypes.POINTER(ctypes.c_float),
192
+ ]
193
+ self.thorvg_lib.tvg_picture_get_size.restype = Result
194
+ result = self.thorvg_lib.tvg_picture_get_size(
195
+ ctypes.pointer(self._paint),
196
+ ctypes.pointer(w),
197
+ ctypes.pointer(h),
198
+ )
199
+ return result, w.value, h.value
200
+
201
+ def get_paint(self, _id: int) -> Optional[Paint]:
202
+ """Retrieve a paint object from the Picture scene by its Unique ID.
203
+
204
+ This function searches for a paint object within the Picture scene that matches the provided ``id``.
205
+
206
+ :param int _id: The Unique ID of the paint object.
207
+ :return: A pointer to the paint object that matches the given identifier, or ``nullptr`` if no matching paint object is found.
208
+ :rtype: PaintStruct
209
+
210
+ .. seealso:: Engine.accessor_generate_id()
211
+ .. note::
212
+ experimental API
213
+ """
214
+ self.thorvg_lib.tvg_picture_get_size.argtypes = [
215
+ ctypes.POINTER(PaintStruct),
216
+ ctypes.POINTER(ctypes.c_uint32),
217
+ ]
218
+ self.thorvg_lib.tvg_picture_get_size.restype = ctypes.POINTER(PaintStruct)
219
+ paint_struct = self.thorvg_lib.tvg_picture_get_size(
220
+ ctypes.pointer(self._paint),
221
+ ctypes.c_uint32(_id),
222
+ ).contents
223
+ if paint_struct is not None:
224
+ return Paint(self.engine, paint_struct)
225
+ else:
226
+ return None