4 * The main APIs enabling the TVG initialization, preparation of the canvas and provisioning of its content:
5 * - drawing shapes: line, arc, curve, path, polygon...
6 * - drawing pictures: tvg, svg, png, jpg, bitmap...
7 * - drawing fillings: solid, linear and radial gradient...
8 * - drawing stroking: continuous stroking with arbitrary width, join, cap, dash styles.
9 * - drawing composition: blending, masking, path clipping...
10 * - drawing scene graph & affine transformation (translation, rotation, scale, ...)
11 * and finally drawing the canvas and TVG termination.
23 #if defined(_WIN32) && !defined(__clang__)
24 #define TVG_EXPORT __declspec(dllexport)
25 #define TVG_DEPRECATED __declspec(deprecated)
27 #define TVG_EXPORT __attribute__ ((visibility ("default")))
28 #define TVG_DEPRECATED __attribute__ ((__deprecated__))
32 #define TVG_DEPRECATED
39 #define _TVG_DECLARE_PRIVATE(A) \
43 A(const A&) = delete; \
44 const A& operator=(const A&) = delete; \
47 #define _TVG_DISABLE_CTOR(A) \
51 #define _TVG_DECLARE_ACCESSOR() \
56 friend IteratorAccessor
63 class IteratorAccessor;
70 * @defgroup ThorVG ThorVG
71 * @brief ThorVG classes and enumerations providing C++ APIs.
77 * @brief Enumeration specifying the result from the APIs.
81 Success = 0, ///< The value returned in case of a correct request execution.
82 InvalidArguments, ///< The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers.
83 InsufficientCondition, ///< The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.
84 FailedAllocation, ///< The value returned in case of unsuccessful memory allocation.
85 MemoryCorruption, ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting
86 NonSupport, ///< The value returned in case of choosing unsupported options.
87 Unknown ///< The value returned in all other cases.
91 * @brief Enumeration specifying the values of the path commands accepted by TVG.
93 * Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others).
94 * TVG interprets all of them and translates to the ones from the PathCommand values.
96 enum class PathCommand
98 Close = 0, ///< Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
99 MoveTo, ///< Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
100 LineTo, ///< Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.
101 CubicTo ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.
105 * @brief Enumeration determining the ending type of a stroke in the open sub-paths.
109 Square = 0, ///< The stroke is extended in both end-points of a sub-path by a rectangle, with the width equal to the stroke width and the length equal to the half of the stroke width. For zero length sub-paths the square is rendered with the size of the stroke width.
110 Round, ///< The stroke is extended in both end-points of a sub-path by a half circle, with a radius equal to the half of a stroke width. For zero length sub-paths a full circle is rendered.
111 Butt ///< The stroke ends exactly at each of the two end-points of a sub-path. For zero length sub-paths no stroke is rendered.
115 * @brief Enumeration determining the style used at the corners of joined stroked path segments.
117 enum class StrokeJoin
119 Bevel = 0, ///< The outer corner of the joined path segments is bevelled at the join point. The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke.
120 Round, ///< The outer corner of the joined path segments is rounded. The circular region is centered at the join point.
121 Miter ///< The outer corner of the joined path segments is spiked. The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect. In case the extension goes beyond the limit, the join style is converted to the Bevel style.
125 * @brief Enumeration specifying how to fill the area outside the gradient bounds.
127 enum class FillSpread
129 Pad = 0, ///< The remaining area is filled with the closest stop color.
130 Reflect, ///< The gradient pattern is reflected outside the gradient area until the expected region is filled.
131 Repeat ///< The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.
135 * @brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.
139 Winding = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape.
140 EvenOdd ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape.
144 * @brief Enumeration indicating the method used in the composition of two objects - the target and the source.
146 enum class CompositeMethod
148 None = 0, ///< No composition is applied.
149 ClipPath, ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered.
150 AlphaMask, ///< The pixels of the source and the target are alpha blended. As a result, only the part of the source, which alpha intersects with the target is visible.
151 InvAlphaMask, ///< The pixels of the source and the complement to the target's pixels are alpha blended. As a result, only the part of the source which alpha is not covered by the target is visible.
152 LumaMask ///< @BETA_API The source pixels are converted to the grayscale (luma value) and alpha blended with the target. As a result, only the part of the source, which intersects with the target is visible.
156 * @brief Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed.
158 enum class CanvasEngine
160 Sw = (1 << 1), ///< CPU rasterizer.
161 Gl = (1 << 2) ///< OpenGL rasterizer.
166 * @brief A data structure representing a point in two-dimensional space.
175 * @brief A data structure representing a three-dimensional matrix.
177 * The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor.
178 * The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively.
179 * The elements e31 and e32 are set to 0, e33 is set to 1.
189 * @brief A data structure representing a texture mesh vertex
191 * @param pt The vertex coordinate
192 * @param uv The normalized texture coordinate in the range (0.0..1.0, 0.0..1.0)
204 * @brief A data structure representing a triange in a texture mesh
206 * @param vertex The three vertices that make up the polygon
219 * @brief An abstract class for managing graphical elements.
221 * A graphical element in TVG is any object composed into a Canvas.
222 * Paint represents such a graphical object and its behaviors such as duplication, transformation and composition.
223 * TVG recommends the user to regard a paint as a set of volatile commands. They can prepare a Paint and then request a Canvas to run them.
225 class TVG_EXPORT Paint
231 * @brief Sets the angle by which the object is rotated.
233 * The angle in measured clockwise from the horizontal axis.
234 * The rotational axis passes through the point on the object with zero coordinates.
236 * @param[in] degree The value of the angle in degrees.
238 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
240 Result rotate(float degree) noexcept;
243 * @brief Sets the scale value of the object.
245 * @param[in] factor The value of the scaling factor. The default value is 1.
247 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
249 Result scale(float factor) noexcept;
252 * @brief Sets the values by which the object is moved in a two-dimensional space.
254 * The origin of the coordinate system is in the upper left corner of the canvas.
255 * The horizontal and vertical axes point to the right and down, respectively.
257 * @param[in] x The value of the horizontal shift.
258 * @param[in] y The value of the vertical shift.
260 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
262 Result translate(float x, float y) noexcept;
265 * @brief Sets the matrix of the affine transformation for the object.
267 * The augmented matrix of the transformation is expected to be given.
269 * @param[in] m The 3x3 augmented matrix.
271 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
273 Result transform(const Matrix& m) noexcept;
276 * @brief Gets the matrix of the affine transformation of the object.
278 * The values of the matrix can be set by the transform() API, as well by the translate(),
279 * scale() and rotate(). In case no transformation was applied, the identity matrix is returned.
281 * @retval The augmented transformation matrix.
285 Matrix transform() noexcept;
288 * @brief Sets the opacity of the object.
290 * @param[in] o The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
292 * @return Result::Success when succeed.
294 * @note Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible.
295 * @note ClipPath won't use the opacity value. (see: enum class CompositeMethod::ClipPath)
297 Result opacity(uint8_t o) noexcept;
300 * @brief Sets the composition target object and the composition method.
302 * @param[in] target The paint of the target object.
303 * @param[in] method The method used to composite the source object with the target.
305 * @return Result::Success when succeed, Result::InvalidArguments otherwise.
307 Result composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept;
310 * @brief Gets the bounding box of the paint object before any transformation.
312 * @param[out] x The x coordinate of the upper left corner of the object.
313 * @param[out] y The y coordinate of the upper left corner of the object.
314 * @param[out] w The width of the object.
315 * @param[out] h The height of the object.
317 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
319 * @note The bounding box doesn't indicate the final rendered region. It's the smallest rectangle that encloses the object.
320 * @see Paint::bounds(float* x, float* y, float* w, float* h, bool transformed);
322 TVG_DEPRECATED Result bounds(float* x, float* y, float* w, float* h) const noexcept;
325 * @brief Gets the axis-aligned bounding box of the paint object.
327 * In case @p transform is @c true, all object's transformations are applied first, and then the bounding box is established. Otherwise, the bounding box is determined before any transformations.
329 * @param[out] x The x coordinate of the upper left corner of the object.
330 * @param[out] y The y coordinate of the upper left corner of the object.
331 * @param[out] w The width of the object.
332 * @param[out] h The height of the object.
333 * @param[in] transformed If @c true, the paint's transformations are taken into account, otherwise they aren't.
335 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
337 * @note The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.
339 Result bounds(float* x, float* y, float* w, float* h, bool transformed) const noexcept;
342 * @brief Duplicates the object.
344 * Creates a new object and sets its all properties as in the original object.
346 * @return The created object when succeed, @c nullptr otherwise.
348 Paint* duplicate() const noexcept;
351 * @brief Gets the opacity value of the object.
353 * @return The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
355 uint8_t opacity() const noexcept;
358 * @brief Gets the composition target object and the composition method.
360 * @param[out] target The paint of the target object.
362 * @return The method used to composite the source object with the target.
366 CompositeMethod composite(const Paint** target) const noexcept;
369 * @brief Return the unique id value of the paint instance.
371 * This method can be called for checking the current concrete instance type.
373 * @return The type id of the Paint instance.
375 uint32_t identifier() const noexcept;
377 _TVG_DECLARE_ACCESSOR();
378 _TVG_DECLARE_PRIVATE(Paint);
385 * @brief An abstract class representing the gradient fill of the Shape object.
387 * It contains the information about the gradient colors and their arrangement
388 * inside the gradient bounds. The gradients bounds are defined in the LinearGradient
389 * or RadialGradient class, depending on the type of the gradient to be used.
390 * It specifies the gradient behavior in case the area defined by the gradient bounds
391 * is smaller than the area to be filled.
393 class TVG_EXPORT Fill
397 * @brief A data structure storing the information about the color and its relative position inside the gradient bounds.
401 float offset; /**< The relative position of the color. */
402 uint8_t r; /**< The red color channel value in the range [0 ~ 255]. */
403 uint8_t g; /**< The green color channel value in the range [0 ~ 255]. */
404 uint8_t b; /**< The blue color channel value in the range [0 ~ 255]. */
405 uint8_t a; /**< The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. */
411 * @brief Sets the parameters of the colors of the gradient and their position.
413 * @param[in] colorStops An array of ColorStop data structure.
414 * @param[in] cnt The count of the @p colorStops array equal to the colors number used in the gradient.
416 * @return Result::Success when succeed.
418 Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
421 * @brief Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds.
423 * @param[in] s The FillSpread value.
425 * @return Result::Success when succeed.
427 Result spread(FillSpread s) noexcept;
430 * @brief Sets the matrix of the affine transformation for the gradient fill.
432 * The augmented matrix of the transformation is expected to be given.
434 * @param[in] m The 3x3 augmented matrix.
436 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
438 Result transform(const Matrix& m) noexcept;
441 * @brief Gets the parameters of the colors of the gradient, their position and number.
443 * @param[out] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
445 * @return The number of colors used in the gradient. This value corresponds to the length of the @p colorStops array.
447 uint32_t colorStops(const ColorStop** colorStops) const noexcept;
450 * @brief Gets the FillSpread value of the fill.
452 * @return The FillSpread value of this Fill.
454 FillSpread spread() const noexcept;
457 * @brief Gets the matrix of the affine transformation of the gradient fill.
459 * In case no transformation was applied, the identity matrix is returned.
461 * @retval The augmented transformation matrix.
463 Matrix transform() const noexcept;
466 * @brief Creates a copy of the Fill object.
468 * Return a newly created Fill object with the properties copied from the original.
470 * @return A copied Fill object when succeed, @c nullptr otherwise.
472 Fill* duplicate() const noexcept;
475 * @brief Return the unique id value of the Fill instance.
477 * This method can be called for checking the current concrete instance type.
479 * @return The type id of the Fill instance.
481 uint32_t identifier() const noexcept;
483 _TVG_DECLARE_PRIVATE(Fill);
490 * @brief An abstract class for drawing graphical elements.
492 * 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.
494 * @note A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical.
495 * @warning The Paint objects belonging to one Canvas can't be shared among multiple Canvases.
497 class TVG_EXPORT Canvas
500 Canvas(RenderMethod*);
504 * @brief Sets the size of the container, where all the paints pushed into the Canvas are stored.
506 * If the number of objects pushed into the Canvas is known in advance, calling the function
507 * prevents multiple memory reallocation, thus improving the performance.
509 * @param[in] n The number of objects for which the memory is to be reserved.
511 * @return Result::Success when succeed.
513 Result reserve(uint32_t n) noexcept;
516 * @brief Passes drawing elements to the Canvas using Paint objects.
518 * Only pushed paints in the canvas will be drawing targets.
519 * They are retained by the canvas until you call Canvas::clear().
520 * If you know the number of the pushed objects in advance, please call Canvas::reserve().
522 * @param[in] paint A Paint object to be drawn.
524 * @retval Result::Success When succeed.
525 * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument.
526 * @retval Result::InsufficientCondition An internal error.
528 * @note The rendering order of the paints is the same as the order as they were pushed into the canvas. Consider sorting the paints before pushing them if you intend to use layering.
529 * @see Canvas::reserve()
530 * @see Canvas::clear()
532 virtual Result push(std::unique_ptr<Paint> paint) noexcept;
535 * @brief Sets the total number of the paints pushed into the canvas to be zero.
536 * Depending on the value of the @p free argument, the paints are freed or not.
538 * @param[in] free If @c true, the memory occupied by paints is deallocated, otherwise it is not.
540 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
542 * @warning If you don't free the paints they become dangled. They are supposed to be reused, otherwise you are responsible for their lives. Thus please use the @p free argument only when you know how it works, otherwise it's not recommended.
544 virtual Result clear(bool free = true) noexcept;
547 * @brief Request the canvas to update the paint objects.
549 * If a @c nullptr is passed all paint objects retained by the Canvas are updated,
550 * otherwise only the paint to which the given @p paint points.
552 * @param[in] paint A pointer to the Paint object or @c nullptr.
554 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
556 * @note The Update behavior can be asynchronous if the assigned thread number is greater than zero.
558 virtual Result update(Paint* paint = nullptr) noexcept;
561 * @brief Requests the canvas to draw the Paint objects.
563 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
565 * @note Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards.
566 * @see Canvas::sync()
568 virtual Result draw() noexcept;
571 * @brief Guarantees that drawing task is finished.
573 * The Canvas rendering can be performed asynchronously. To make sure that rendering is finished,
574 * the sync() must be called after the draw() regardless of threading.
576 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
577 * @see Canvas::draw()
579 virtual Result sync() noexcept;
581 _TVG_DECLARE_PRIVATE(Canvas);
586 * @class LinearGradient
588 * @brief A class representing the linear gradient fill of the Shape object.
590 * Besides the APIs inherited from the Fill class, it enables setting and getting the linear gradient bounds.
591 * The behavior outside the gradient bounds depends on the value specified in the spread API.
593 class TVG_EXPORT LinearGradient final : public Fill
599 * @brief Sets the linear gradient bounds.
601 * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing
602 * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking
603 * (@p x1, @p y1) and (@p x2, @p y2).
605 * @param[in] x1 The horizontal coordinate of the first point used to determine the gradient bounds.
606 * @param[in] y1 The vertical coordinate of the first point used to determine the gradient bounds.
607 * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds.
608 * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds.
610 * @return Result::Success when succeed.
612 * @note In case the first and the second points are equal, an object filled with such a gradient fill is not rendered.
614 Result linear(float x1, float y1, float x2, float y2) noexcept;
617 * @brief Gets the linear gradient bounds.
619 * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing
620 * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking
621 * (@p x1, @p y1) and (@p x2, @p y2).
623 * @param[out] x1 The horizontal coordinate of the first point used to determine the gradient bounds.
624 * @param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds.
625 * @param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds.
626 * @param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds.
628 * @return Result::Success when succeed.
630 Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
633 * @brief Creates a new LinearGradient object.
635 * @return A new LinearGradient object.
637 static std::unique_ptr<LinearGradient> gen() noexcept;
640 * @brief Return the unique id value of this class.
642 * This method can be referred for identifying the LinearGradient class type.
644 * @return The type id of the LinearGradient class.
646 static uint32_t identifier() noexcept;
648 _TVG_DECLARE_PRIVATE(LinearGradient);
653 * @class RadialGradient
655 * @brief A class representing the radial gradient fill of the Shape object.
658 class TVG_EXPORT RadialGradient final : public Fill
664 * @brief Sets the radial gradient bounds.
666 * The radial gradient bounds are defined as a circle centered in a given point (@p cx, @p cy) of a given radius.
668 * @param[in] cx The horizontal coordinate of the center of the bounding circle.
669 * @param[in] cy The vertical coordinate of the center of the bounding circle.
670 * @param[in] radius The radius of the bounding circle.
672 * @return Result::Success when succeed, Result::InvalidArguments in case the @p radius value is zero or less.
674 Result radial(float cx, float cy, float radius) noexcept;
677 * @brief Gets the radial gradient bounds.
679 * The radial gradient bounds are defined as a circle centered in a given point (@p cx, @p cy) of a given radius.
681 * @param[out] cx The horizontal coordinate of the center of the bounding circle.
682 * @param[out] cy The vertical coordinate of the center of the bounding circle.
683 * @param[out] radius The radius of the bounding circle.
685 * @return Result::Success when succeed.
687 Result radial(float* cx, float* cy, float* radius) const noexcept;
690 * @brief Creates a new RadialGradient object.
692 * @return A new RadialGradient object.
694 static std::unique_ptr<RadialGradient> gen() noexcept;
697 * @brief Return the unique id value of this class.
699 * This method can be referred for identifying the RadialGradient class type.
701 * @return The type id of the RadialGradient class.
703 static uint32_t identifier() noexcept;
705 _TVG_DECLARE_PRIVATE(RadialGradient);
712 * @brief A class representing two-dimensional figures and their properties.
714 * A shape has three major properties: shape outline, stroking, filling. The outline in the Shape is retained as the path.
715 * Path can be composed by accumulating primitive commands such as moveTo(), lineTo(), cubicTo(), or complete shape interfaces such as appendRect(), appendCircle(), etc.
716 * Path can consists of sub-paths. One sub-path is determined by a close command.
718 * The stroke of Shape is an optional property in case the Shape needs to be represented with/without the outline borders.
719 * 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.
721 class TVG_EXPORT Shape final : public Paint
727 * @brief Resets the properties of the shape path.
729 * The color, the fill and the stroke properties are retained.
731 * @return Result::Success when succeed.
733 * @note The memory, where the path data is stored, is not deallocated at this stage for caching effect.
735 Result reset() noexcept;
738 * @brief Sets the initial point of the sub-path.
740 * The value of the current point is set to the given point.
742 * @param[in] x The horizontal coordinate of the initial point of the sub-path.
743 * @param[in] y The vertical coordinate of the initial point of the sub-path.
745 * @return Result::Success when succeed.
747 Result moveTo(float x, float y) noexcept;
750 * @brief Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point.
752 * The value of the current point is set to the given end-point.
754 * @param[in] x The horizontal coordinate of the end-point of the line.
755 * @param[in] y The vertical coordinate of the end-point of the line.
757 * @return Result::Success when succeed.
759 * @note In case this is the first command in the path, it corresponds to the moveTo() call.
761 Result lineTo(float x, float y) noexcept;
764 * @brief Adds new points to the sub-path, which results in drawing a cubic Bezier curve starting
765 * at the current point and ending at the given end-point (@p x, @p y) using the control points (@p cx1, @p cy1) and (@p cx2, @p cy2).
767 * The value of the current point is set to the given end-point.
769 * @param[in] cx1 The horizontal coordinate of the 1st control point.
770 * @param[in] cy1 The vertical coordinate of the 1st control point.
771 * @param[in] cx2 The horizontal coordinate of the 2nd control point.
772 * @param[in] cy2 The vertical coordinate of the 2nd control point.
773 * @param[in] x The horizontal coordinate of the end-point of the curve.
774 * @param[in] y The vertical coordinate of the end-point of the curve.
776 * @return Result::Success when succeed.
778 * @note In case this is the first command in the path, no data from the path are rendered.
780 Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
783 * @brief Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path.
785 * The value of the current point is set to the initial point of the closed sub-path.
787 * @return Result::Success when succeed.
789 * @note In case the sub-path does not contain any points, this function has no effect.
791 Result close() noexcept;
794 * @brief Appends a rectangle to the path.
796 * The rectangle with rounded corners can be achieved by setting non-zero values to @p rx and @p ry arguments.
797 * The @p rx and @p ry values specify the radii of the ellipse defining the rounding of the corners.
799 * The position of the rectangle is specified by the coordinates of its upper left corner - @p x and @p y arguments.
801 * The rectangle is treated as a new sub-path - it is not connected with the previous sub-path.
803 * The value of the current point is set to (@p x + @p rx, @p y) - in case @p rx is greater
804 * than @p w/2 the current point is set to (@p x + @p w/2, @p y)
806 * @param[in] x The horizontal coordinate of the upper left corner of the rectangle.
807 * @param[in] y The vertical coordinate of the upper left corner of the rectangle.
808 * @param[in] w The width of the rectangle.
809 * @param[in] h The height of the rectangle.
810 * @param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle.
811 * @param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle.
813 * @return Result::Success when succeed.
815 * @note For @p rx and @p ry greater than or equal to the half of @p w and the half of @p h, respectively, the shape become an ellipse.
817 Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
820 * @brief Appends an ellipse to the path.
822 * The position of the ellipse is specified by the coordinates of its center - @p cx and @p cy arguments.
824 * The ellipse is treated as a new sub-path - it is not connected with the previous sub-path.
826 * The value of the current point is set to (@p cx, @p cy - @p ry).
828 * @param[in] cx The horizontal coordinate of the center of the ellipse.
829 * @param[in] cy The vertical coordinate of the center of the ellipse.
830 * @param[in] rx The x-axis radius of the ellipse.
831 * @param[in] ry The y-axis radius of the ellipse.
833 * @return Result::Success when succeed.
835 Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
838 * @brief Appends a circular arc to the path.
840 * The arc is treated as a new sub-path - it is not connected with the previous sub-path.
841 * The current point value is set to the end-point of the arc in case @p pie is @c false, and to the center of the arc otherwise.
843 * @param[in] cx The horizontal coordinate of the center of the arc.
844 * @param[in] cy The vertical coordinate of the center of the arc.
845 * @param[in] radius The radius of the arc.
846 * @param[in] startAngle The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line.
847 * @param[in] sweep The central angle of the arc given in degrees, measured counter-clockwise from @p startAngle.
848 * @param[in] pie Specifies whether to draw radii from the arc's center to both of its end-point - drawn if @c true.
850 * @return Result::Success when succeed.
852 * @note Setting @p sweep value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius).
854 Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
857 * @brief Appends a given sub-path to the path.
859 * The current point value is set to the last point from the sub-path.
860 * For each command from the @p cmds array, an appropriate number of points in @p pts array should be specified.
861 * If the number of points in the @p pts array is different than the number required by the @p cmds array, the shape with this sub-path will not be displayed on the screen.
863 * @param[in] cmds The array of the commands in the sub-path.
864 * @param[in] cmdCnt The number of the sub-path's commands.
865 * @param[in] pts The array of the two-dimensional points.
866 * @param[in] ptsCnt The number of the points in the @p pts array.
868 * @return Result::Success when succeed, Result::InvalidArguments otherwise.
870 * @note The interface is designed for optimal path setting if the caller has a completed path commands already.
872 Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
875 * @brief Sets the stroke width for all of the figures from the path.
877 * @param[in] width The width of the stroke. The default value is 0.
879 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
881 Result stroke(float width) noexcept;
884 * @brief Sets the color of the stroke for all of the figures from the path.
886 * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0.
887 * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0.
888 * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
889 * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
891 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
893 Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
896 * @brief Sets the gradient fill of the stroke for all of the figures from the path.
898 * @param[in] f The gradient fill.
900 * @retval Result::Success When succeed.
901 * @retval Result::FailedAllocation An internal error with a memory allocation for an object to be filled.
902 * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument.
904 Result stroke(std::unique_ptr<Fill> f) noexcept;
907 * @brief Sets the dash pattern of the stroke.
909 * @param[in] dashPattern The array of consecutive pair values of the dash length and the gap length.
910 * @param[in] cnt The length of the @p dashPattern array.
912 * @retval Result::Success When succeed.
913 * @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed.
914 * @retval Result::InvalidArguments In case @p dashPattern is @c nullptr and @p cnt > 0, @p cnt is zero, any of the dash pattern values is zero or less.
916 * @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt.
917 * @warning @p cnt must be greater than 1 if the dash pattern is valid.
919 Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
922 * @brief Sets the cap style of the stroke in the open sub-paths.
924 * @param[in] cap The cap style value. The default value is @c StrokeCap::Square.
926 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
928 Result stroke(StrokeCap cap) noexcept;
931 * @brief Sets the join style for stroked path segments.
933 * The join style is used for joining the two line segment while stroking the path.
935 * @param[in] join The join style value. The default value is @c StrokeJoin::Bevel.
937 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
939 Result stroke(StrokeJoin join) noexcept;
942 * @brief Sets the solid color for all of the figures from the path.
944 * The parts of the shape defined as inner are colored.
946 * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0.
947 * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0.
948 * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
949 * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
951 * @return Result::Success when succeed.
953 * @note Either a solid color or a gradient fill is applied, depending on what was set as last.
954 * @note ClipPath won't use the fill values. (see: enum class CompositeMethod::ClipPath)
956 Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
959 * @brief Sets the gradient fill for all of the figures from the path.
961 * The parts of the shape defined as inner are filled.
963 * @param[in] f The unique pointer to the gradient fill.
965 * @return Result::Success when succeed, Result::MemoryCorruption otherwise.
967 * @note Either a solid color or a gradient fill is applied, depending on what was set as last.
969 Result fill(std::unique_ptr<Fill> f) noexcept;
972 * @brief Sets the fill rule for the Shape object.
974 * @param[in] r The fill rule value. The default value is @c FillRule::Winding.
976 * @return Result::Success when succeed.
978 Result fill(FillRule r) noexcept;
981 * @brief Gets the commands data of the path.
983 * @param[out] cmds The pointer to the array of the commands from the path.
985 * @return The length of the @p cmds array when succeed, zero otherwise.
987 uint32_t pathCommands(const PathCommand** cmds) const noexcept;
990 * @brief Gets the points values of the path.
992 * @param[out] pts The pointer to the array of the two-dimensional points from the path.
994 * @return The length of the @p pts array when succeed, zero otherwise.
996 uint32_t pathCoords(const Point** pts) const noexcept;
999 * @brief Gets the pointer to the gradient fill of the shape.
1001 * @return The pointer to the gradient fill of the stroke when succeed, @c nullptr in case no fill was set.
1003 const Fill* fill() const noexcept;
1006 * @brief Gets the solid color of the shape.
1008 * @param[out] r The red color channel value in the range [0 ~ 255].
1009 * @param[out] g The green color channel value in the range [0 ~ 255].
1010 * @param[out] b The blue color channel value in the range [0 ~ 255].
1011 * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
1013 * @return Result::Success when succeed.
1015 Result fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
1018 * @brief Gets the fill rule value.
1020 * @return The fill rule value of the shape.
1022 FillRule fillRule() const noexcept;
1025 * @brief Gets the stroke width.
1027 * @return The stroke width value when succeed, zero if no stroke was set.
1029 float strokeWidth() const noexcept;
1032 * @brief Gets the color of the shape's stroke.
1034 * @param[out] r The red color channel value in the range [0 ~ 255].
1035 * @param[out] g The green color channel value in the range [0 ~ 255].
1036 * @param[out] b The blue color channel value in the range [0 ~ 255].
1037 * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
1039 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
1041 Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
1044 * @brief Gets the pointer to the gradient fill of the stroke.
1046 * @return The pointer to the gradient fill of the stroke when succeed, @c nullptr otherwise.
1048 const Fill* strokeFill() const noexcept;
1051 * @brief Gets the dash pattern of the stroke.
1053 * @param[out] dashPattern The pointer to the memory, where the dash pattern array is stored.
1055 * @return The length of the @p dashPattern array.
1057 uint32_t strokeDash(const float** dashPattern) const noexcept;
1060 * @brief Gets the cap style used for stroking the path.
1062 * @return The cap style value of the stroke.
1064 StrokeCap strokeCap() const noexcept;
1067 * @brief Gets the join style value used for stroking the path.
1069 * @return The join style value of the stroke.
1071 StrokeJoin strokeJoin() const noexcept;
1074 * @brief Creates a new Shape object.
1076 * @return A new Shape object.
1078 static std::unique_ptr<Shape> gen() noexcept;
1081 * @brief Return the unique id value of this class.
1083 * This method can be referred for identifying the Shape class type.
1085 * @return The type id of the Shape class.
1087 static uint32_t identifier() noexcept;
1089 _TVG_DECLARE_PRIVATE(Shape);
1096 * @brief A class representing an image read in one of the supported formats: raw, svg, png, jpg and etc.
1097 * Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas.
1099 * @note Supported formats are depended on the available TVG loaders.
1101 class TVG_EXPORT Picture final : public Paint
1107 * @brief Loads a picture data directly from a file.
1109 * @param[in] path A path to the picture file.
1111 * @retval Result::Success When succeed.
1112 * @retval Result::InvalidArguments In case the @p path is invalid.
1113 * @retval Result::NonSupport When trying to load a file with an unknown extension.
1114 * @retval Result::Unknown If an error occurs at a later stage.
1116 * @note The Load behavior can be asynchronous if the assigned thread number is greater than zero.
1117 * @see Initializer::init()
1119 Result load(const std::string& path) noexcept;
1122 * @brief Loads a picture data from a memory block of a given size.
1124 * @param[in] data A pointer to a memory location where the content of the picture file is stored.
1125 * @param[in] size The size in bytes of the memory occupied by the @p data.
1126 * @param[in] copy Decides whether the data should be copied into the engine local buffer.
1128 * @retval Result::Success When succeed.
1129 * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
1130 * @retval Result::NonSupport When trying to load a file with an unknown extension.
1131 * @retval Result::Unknown If an error occurs at a later stage.
1133 * @warning: you have responsibility to release the @p data memory if the @p copy is true
1134 * @deprecated Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead.
1135 * @see Result load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false) noexcept
1137 TVG_DEPRECATED Result load(const char* data, uint32_t size, bool copy = false) noexcept;
1140 * @brief Loads a picture data from a memory block of a given size.
1142 * @param[in] data A pointer to a memory location where the content of the picture file is stored.
1143 * @param[in] size The size in bytes of the memory occupied by the @p data.
1144 * @param[in] mimeType Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.
1145 * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not.
1147 * @retval Result::Success When succeed.
1148 * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
1149 * @retval Result::NonSupport When trying to load a file with an unknown extension.
1150 * @retval Result::Unknown If an error occurs at a later stage.
1152 * @warning: It's the user responsibility to release the @p data memory if the @p copy is @c true.
1156 Result load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false) noexcept;
1159 * @brief Resizes the picture content to the given width and height.
1161 * The picture content is resized while keeping the default size aspect ratio.
1162 * The scaling factor is established for each of dimensions and the smaller value is applied to both of them.
1164 * @param[in] w A new width of the image in pixels.
1165 * @param[in] h A new height of the image in pixels.
1167 * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
1169 Result size(float w, float h) noexcept;
1172 * @brief Gets the size of the image.
1174 * @param[out] w The width of the image in pixels.
1175 * @param[out] h The height of the image in pixels.
1177 * @return Result::Success when succeed.
1179 Result size(float* w, float* h) const noexcept;
1182 * @brief Gets the pixels information of the picture.
1184 * @note The data must be pre-multiplied by the alpha channels.
1186 * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1190 const uint32_t* data(uint32_t* w, uint32_t* h) const noexcept;
1193 * @brief Loads a raw data from a memory block with a given size.
1195 * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1199 Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept;
1202 * @brief Sets or removes the triangle mesh to deform the image.
1204 * If a mesh is provided, the transform property of the Picture will apply to the triangle mesh, and the
1205 * image data will be used as the texture.
1207 * If @p triangles is @c nullptr, or @p triangleCnt is 0, the mesh will be removed.
1209 * Only raster image types are supported at this time (png, jpg). Vector types like svg and tvg do not support.
1210 * mesh deformation. However, if required you should be able to render a vector image to a raster image and then apply a mesh.
1212 * @param[in] triangles An array of Polygons(triangles) that make up the mesh, or null to remove the mesh.
1213 * @param[in] triangleCnt The number of Polygons(triangles) provided, or 0 to remove the mesh.
1215 * @retval Result::Success When succeed.
1216 * @retval Result::Unknown If fails
1218 * @note The Polygons are copied internally, so modifying them after calling Mesh::mesh has no affect.
1219 * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1223 Result mesh(const Polygon* triangles, const uint32_t triangleCnt) noexcept;
1226 * @brief Return the number of triangles in the mesh, and optionally get a pointer to the array of triangles in the mesh.
1228 * @param[out] triangles Optional. A pointer to the array of Polygons used by this mesh.
1230 * @return uint32_t The number of polygons in the array.
1232 * @note Modifying the triangles returned by this method will modify them directly within the mesh.
1233 * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1237 uint32_t mesh(const Polygon** triangles) const noexcept;
1240 * @brief Gets the position and the size of the loaded SVG picture.
1242 * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1246 Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
1249 * @brief Creates a new Picture object.
1251 * @return A new Picture object.
1253 static std::unique_ptr<Picture> gen() noexcept;
1256 * @brief Return the unique id value of this class.
1258 * This method can be referred for identifying the Picture class type.
1260 * @return The type id of the Picture class.
1262 static uint32_t identifier() noexcept;
1264 _TVG_DECLARE_PRIVATE(Picture);
1271 * @brief A class to composite children paints.
1273 * As the traditional graphics rendering method, TVG also enables scene-graph mechanism.
1274 * This feature supports an array function for managing the multiple paints as one group paint.
1276 * As a group, the scene can be transformed, made translucent and composited with other target paints,
1277 * its children will be affected by the scene world.
1279 class TVG_EXPORT Scene final : public Paint
1285 * @brief Passes drawing elements to the Scene using Paint objects.
1287 * Only the paints pushed into the scene will be the drawn targets.
1288 * The paints are retained by the scene until Scene::clear() is called.
1289 * If you know the number of the pushed objects in advance, please call Scene::reserve().
1291 * @param[in] paint A Paint object to be drawn.
1293 * @return Result::Success when succeed, Result::MemoryCorruption otherwise.
1295 * @note 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.
1296 * @see Scene::reserve()
1298 Result push(std::unique_ptr<Paint> paint) noexcept;
1301 * @brief Sets the size of the container, where all the paints pushed into the Scene are stored.
1303 * If the number of objects pushed into the scene is known in advance, calling the function
1304 * prevents multiple memory reallocation, thus improving the performance.
1306 * @param[in] size The number of objects for which the memory is to be reserved.
1308 * @return Result::Success when succeed, Result::FailedAllocation otherwise.
1310 Result reserve(uint32_t size) noexcept;
1313 * @brief Sets the total number of the paints pushed into the scene to be zero.
1314 * Depending on the value of the @p free argument, the paints are freed or not.
1316 * @param[in] free If @c true, the memory occupied by paints is deallocated, otherwise it is not.
1318 * @return Result::Success when succeed
1320 * @warning If you don't free the paints they become dangled. They are supposed to be reused, otherwise you are responsible for their lives. Thus please use the @p free argument only when you know how it works, otherwise it's not recommended.
1324 Result clear(bool free = true) noexcept;
1327 * @brief Creates a new Scene object.
1329 * @return A new Scene object.
1331 static std::unique_ptr<Scene> gen() noexcept;
1334 * @brief Return the unique id value of this class.
1336 * This method can be referred for identifying the Scene class type.
1338 * @return The type id of the Scene class.
1340 static uint32_t identifier() noexcept;
1342 _TVG_DECLARE_PRIVATE(Scene);
1349 * @brief A class for the rendering graphical elements with a software raster engine.
1351 class TVG_EXPORT SwCanvas final : public Canvas
1357 * @brief Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.
1361 ABGR8888 = 0, ///< The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied.
1362 ARGB8888, ///< The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied.
1363 ABGR8888_STRAIGHT, ///< @BETA_API The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied.
1364 ARGB8888_STRAIGHT, ///< @BETA_API The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied.
1368 * @brief Enumeration specifying the methods of Memory Pool behavior policy.
1373 Default = 0, ///< Default behavior that ThorVG is designed to.
1374 Shareable, ///< Memory Pool is shared among the SwCanvases.
1375 Individual ///< Allocate designated memory pool that is only used by current instance.
1379 * @brief Sets the target buffer for the rasterization.
1381 * The buffer of a desirable size should be allocated and owned by the caller.
1383 * @param[in] buffer A pointer to a memory block of the size @p stride x @p h, where the raster data are stored.
1384 * @param[in] stride The stride of the raster image - greater than or equal to @p w.
1385 * @param[in] w The width of the raster image.
1386 * @param[in] h The height of the raster image.
1387 * @param[in] cs The value specifying the way the 32-bits colors should be read/written.
1389 * @retval Result::Success When succeed.
1390 * @retval Result::MemoryCorruption When casting in the internal function implementation failed.
1391 * @retval Result::InvalidArguments In case no valid pointer is provided or the width, or the height or the stride is zero.
1392 * @retval Result::NonSupport In case the software engine is not supported.
1394 * @warning Do not access @p buffer during Canvas::draw() - Canvas::sync(). It should not be accessed while TVG is writing on it.
1396 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept;
1399 * @brief Set sw engine memory pool behavior policy.
1401 * Basically ThorVG draws a lot of shapes, it allocates/deallocates a few chunk of memory
1402 * while processing rendering. It internally uses one shared memory pool
1403 * which can be reused among the canvases in order to avoid memory overhead.
1405 * Thus ThorVG suggests using a memory pool policy to satisfy user demands,
1406 * if it needs to guarantee the thread-safety of the internal data access.
1408 * @param[in] policy The method specifying the Memory Pool behavior. The default value is @c MempoolPolicy::Default.
1410 * @retval Result::Success When succeed.
1411 * @retval Result::InsufficientCondition If the canvas contains some paints already.
1412 * @retval Result::NonSupport In case the software engine is not supported.
1414 * @note When @c policy is set as @c MempoolPolicy::Individual, the current instance of canvas uses its own individual
1415 * memory data, which is not shared with others. This is necessary when the canvas is accessed on a worker-thread.
1417 * @warning It's not allowed after pushing any paints.
1421 Result mempool(MempoolPolicy policy) noexcept;
1424 * @brief Creates a new SwCanvas object.
1425 * @return A new SwCanvas object.
1427 static std::unique_ptr<SwCanvas> gen() noexcept;
1429 _TVG_DECLARE_PRIVATE(SwCanvas);
1436 * @brief A class for the rendering graphic elements with a GL raster engine.
1438 * @warning Please do not use it. This class is not fully supported yet.
1442 class TVG_EXPORT GlCanvas final : public Canvas
1448 * @brief Sets the target buffer for the rasterization.
1450 * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1454 Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
1457 * @brief Creates a new GlCanvas object.
1459 * @return A new GlCanvas object.
1463 static std::unique_ptr<GlCanvas> gen() noexcept;
1465 _TVG_DECLARE_PRIVATE(GlCanvas);
1470 * @class Initializer
1472 * @brief A class that enables initialization and termination of the TVG engines.
1474 class TVG_EXPORT Initializer final
1478 * @brief Initializes TVG engines.
1480 * TVG requires the running-engine environment.
1481 * TVG runs its own task-scheduler for parallelizing rendering tasks efficiently.
1482 * You can indicate the number of threads, the count of which is designated @p threads.
1483 * In the initialization step, TVG will generate/spawn the threads as set by @p threads count.
1485 * @param[in] engine The engine types to initialize. This is relative to the Canvas types, in which it will be used. For multiple backends bitwise operation is allowed.
1486 * @param[in] threads The number of additional threads. Zero indicates only the main thread is to be used.
1488 * @retval Result::Success When succeed.
1489 * @retval Result::FailedAllocation An internal error possibly with memory allocation.
1490 * @retval Result::InvalidArguments If unknown engine type chosen.
1491 * @retval Result::NonSupport In case the engine type is not supported on the system.
1492 * @retval Result::Unknown Others.
1494 * @note The Initializer keeps track of the number of times it was called. Threads count is fixed at the first init() call.
1495 * @see Initializer::term()
1497 static Result init(CanvasEngine engine, uint32_t threads) noexcept;
1500 * @brief Terminates TVG engines.
1502 * @param[in] engine The engine types to terminate. This is relative to the Canvas types, in which it will be used. For multiple backends bitwise operation is allowed
1504 * @retval Result::Success When succeed.
1505 * @retval Result::InsufficientCondition In case there is nothing to be terminated.
1506 * @retval Result::InvalidArguments If unknown engine type chosen.
1507 * @retval Result::NonSupport In case the engine type is not supported on the system.
1508 * @retval Result::Unknown Others.
1510 * @note Initializer does own reference counting for multiple calls.
1511 * @see Initializer::init()
1513 static Result term(CanvasEngine engine) noexcept;
1515 _TVG_DISABLE_CTOR(Initializer);
1522 * @brief A class for exporting a paint object into a specified file, from which to recover the paint data later.
1524 * ThorVG provides a feature for exporting & importing paint data. The Saver role is to export the paint data to a file.
1525 * It's useful when you need to save the composed scene or image from a paint object and recreate it later.
1527 * The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment.
1528 * If it doesn't support the file format, the save() method returns the @c Result::NonSuppport result.
1530 * Once you export a paint to the file successfully, you can recreate it using the Picture class.
1532 * @see Picture::load()
1536 class TVG_EXPORT Saver final
1542 * @brief Exports the given @p paint data to the given @p path
1544 * If the saver module supports any compression mechanism, it will optimize the data size.
1545 * This might affect the encoding/decoding time in some cases. You can turn off the compression
1546 * if you wish to optimize for speed.
1548 * @param[in] paint The paint to be saved with all its associated properties.
1549 * @param[in] path A path to the file, in which the paint data is to be saved.
1550 * @param[in] compress If @c true then compress data if possible.
1552 * @retval Result::Success When succeed.
1553 * @retval Result::InsufficientCondition If currently saving other resources.
1554 * @retval Result::NonSupport When trying to save a file with an unknown extension or in an unsupported format.
1555 * @retval Result::MemoryCorruption An internal error.
1556 * @retval Result::Unknown In case an empty paint is to be saved.
1558 * @note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards.
1559 * @see Saver::sync()
1563 Result save(std::unique_ptr<Paint> paint, const std::string& path, bool compress = true) noexcept;
1566 * @brief Guarantees that the saving task is finished.
1568 * The behavior of the Saver works on a sync/async basis, depending on the threading setting of the Initializer.
1569 * Thus, if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time.
1570 * Otherwise, you can call sync() immediately.
1572 * @retval Result::Success when succeed.
1573 * @retval Result::InsufficientCondition otherwise.
1575 * @note The asynchronous tasking is dependent on the Saver module implementation.
1576 * @see Saver::save()
1580 Result sync() noexcept;
1583 * @brief Creates a new Saver object.
1585 * @return A new Saver object.
1589 static std::unique_ptr<Saver> gen() noexcept;
1591 _TVG_DECLARE_PRIVATE(Saver);
1598 * @brief The Accessor is a utility class to debug the Scene structure by traversing the scene-tree.
1600 * The Accessor helps you search specific nodes to read the property information, figure out the structure of the scene tree and its size.
1602 * @warning We strongly warn you not to change the paints of a scene unless you really know the design-structure.
1606 class TVG_EXPORT Accessor final
1612 * @brief Set the access function for traversing the Picture scene tree nodes.
1614 * @param[in] picture The picture node to traverse the internal scene-tree.
1615 * @param[in] func The callback function calling for every paint nodes of the Picture.
1617 * @return Return the given @p picture instance.
1619 * @note The bitmap based picture might not have the scene-tree.
1623 std::unique_ptr<Picture> set(std::unique_ptr<Picture> picture, std::function<bool(const Paint* paint)> func) noexcept;
1626 * @brief Creates a new Accessor object.
1628 * @return A new Accessor object.
1632 static std::unique_ptr<Accessor> gen() noexcept;
1634 _TVG_DECLARE_PRIVATE(Accessor);