thorvg.h
Defines
- 
TVG_BUILD
 
- 
TVG_API
 
- 
TVG_DEPRECATED
 
- 
_TVG_DECLARE_PRIVATE(A)
 
- 
_TVG_DISABLE_CTOR(A)
 
- 
_TVG_DECLARE_ACCESSOR(A)
 
- 
namespace tvg
 Enums
- 
enum class Result
 Enumeration specifying the result from the APIs.
All ThorVG APIs could potentially return one of the values in the list. Please note that some APIs may additionally specify the reasons that trigger their return values.
Values:
- 
enumerator Success
 The value returned in case of a correct request execution.
- 
enumerator InvalidArguments
 The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers.
- 
enumerator InsufficientCondition
 The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.
- 
enumerator FailedAllocation
 The value returned in case of unsuccessful memory allocation.
- 
enumerator MemoryCorruption
 The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting.
- 
enumerator NonSupport
 The value returned in case of choosing unsupported engine features(options).
- 
enumerator Unknown
 The value returned in all other cases.
- 
enumerator Success
 
- 
enum class PathCommand
 Enumeration specifying the values of the path commands accepted by TVG.
Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others). TVG interprets all of them and translates to the ones from the PathCommand values.
Values:
- 
enumerator Close
 Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
- 
enumerator MoveTo
 Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
- 
enumerator 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.
- 
enumerator 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.
- 
enumerator Close
 
- 
enum class StrokeCap
 Enumeration determining the ending type of a stroke in the open sub-paths.
Values:
- 
enumerator Square
 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.
- 
enumerator 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.
- 
enumerator 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.
- 
enumerator Square
 
- 
enum class StrokeJoin
 Enumeration determining the style used at the corners of joined stroked path segments.
Values:
- 
enumerator Bevel
 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.
- 
enumerator Round
 The outer corner of the joined path segments is rounded. The circular region is centered at the join point.
- 
enumerator 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.
- 
enumerator Bevel
 
- 
enum class FillSpread
 Enumeration specifying how to fill the area outside the gradient bounds.
Values:
- 
enumerator Pad
 The remaining area is filled with the closest stop color.
- 
enumerator Reflect
 The gradient pattern is reflected outside the gradient area until the expected region is filled.
- 
enumerator Repeat
 The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.
- 
enumerator Pad
 
- 
enum class FillRule
 Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.
Values:
- 
enumerator Winding
 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.
- 
enumerator 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.
- 
enumerator Winding
 
- 
enum class CompositeMethod
 Enumeration indicating the method used in the composition of two objects - the target and the source.
Notation: S(Source), T(Target), SA(Source Alpha), TA(Target Alpha)
Values:
- 
enumerator None
 No composition is applied.
- 
enumerator ClipPath
 The intersection of the source and the target is determined and only the resulting pixels from the source are rendered. Note that ClipPath only supports the Shape type.
- Deprecated:
 Use Paint::clip() instead.
- 
enumerator AlphaMask
 Alpha Masking using the compositing target's pixels as an alpha value.
- 
enumerator InvAlphaMask
 Alpha Masking using the complement to the compositing target's pixels as an alpha value.
- 
enumerator LumaMask
 Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels.
- Since
 0.9
- 
enumerator InvLumaMask
 Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the complement to the compositing target's pixels.
- Since
 0.11
- 
enumerator AddMask
 Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) (Experimental API)
- 
enumerator SubtractMask
 Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) (Experimental API)
- 
enumerator IntersectMask
 Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) (Experimental API)
- 
enumerator DifferenceMask
 Calculates the absolute difference between the target color and the source color multiplied by the complement of the target alpha. abs(T - S * (255 - TA)) (Experimental API)
- 
enumerator LightenMask
 Where multiple masks intersect, the highest transparency value is used. (Experimental API)
- 
enumerator DarkenMask
 Where multiple masks intersect, the lowest transparency value is used. (Experimental API)
- 
enumerator None
 
- 
enum class BlendMethod : uint8_t
 Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method.
Notation: S(source paint as the top layer), D(destination as the bottom layer), Sa(source paint alpha), Da(destination alpha)
- Since
 0.15
Values:
- 
enumerator Normal
 Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D.
- 
enumerator Multiply
 Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D)
- 
enumerator Screen
 The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D)
- 
enumerator Overlay
 Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
- 
enumerator SrcOver
 Replace the bottom layer with the top layer.
- 
enumerator Darken
 Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D)
- 
enumerator Lighten
 Only has the opposite action of Darken Only. max(S, D)
- 
enumerator ColorDodge
 Divides the bottom layer by the inverted top layer. D / (255 - S)
- 
enumerator ColorBurn
 Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S.
- 
enumerator HardLight
 The same as Overlay but with the color roles reversed. (2 * S * D) if (S < Sa), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
- 
enumerator SoftLight
 The same as Overlay but with applying pure black or white does not result in pure black or white. (1 - 2 * S) * (D ^ 2) + (2 * S * D)
- 
enumerator Difference
 Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S)
- 
enumerator Exclusion
 The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d)
- 
enumerator Hue
 Reserved. Not supported.
- 
enumerator Saturation
 Reserved. Not supported.
- 
enumerator Color
 Reserved. Not supported.
- 
enumerator Luminosity
 Reserved. Not supported.
- 
enumerator Add
 Simply adds pixel values of one layer with the other. (S + D)
- 
enumerator HardMix
 Reserved. Not supported.
- 
enum class SceneEffect : uint8_t
 Enumeration that defines methods used for Scene Effects.
This enum provides options to apply various post-processing effects to a scene. Scene effects are typically applied to modify the final appearance of a rendered scene, such as blurring.
备注
Experimental API
Values:
- 
enumerator ClearAll
 Reset all previously applied scene effects, restoring the scene to its original state.
- 
enumerator GaussianBlur
 Apply a blur effect with a Gaussian filter. Param(3) = {sigma(float)[> 0], direction(int)[both: 0 / horizontal: 1 / vertical: 2], border(int)[duplicate: 0 / wrap: 1], quality(int)[0 - 100]}.
- 
enumerator ClearAll
 
- 
enum class CanvasEngine
 Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed.
Values:
- 
enumerator Sw
 CPU rasterizer.
- 
enumerator Gl
 OpenGL rasterizer.
- 
enumerator Wg
 WebGPU rasterizer.
- Since
 0.15
- 
enumerator Sw
 
- 
enum class Type : uint8_t
 Enumeration specifying the ThorVG class type value.
ThorVG's drawing objects can return class type values, allowing you to identify the specific class of each object.
参见
备注
Experimental API
Values:
- 
enumerator Undefined
 Unkown class.
- 
enumerator LinearGradient
 LinearGradient class.
- 
enumerator RadialGradient
 RadialGradient class.
- 
enumerator Undefined
 
Functions
- 
struct Point
 - #include <thorvg.h>
A data structure representing a point in two-dimensional space.
 
- 
struct Matrix
 - #include <thorvg.h>
A data structure representing a three-dimensional matrix.
The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. The elements e31 and e32 are set to 0, e33 is set to 1.
 
- 
class Paint
 - #include <thorvg.h>
An abstract class for managing graphical elements.
A graphical element in TVG is any object composed into a Canvas. Paint represents such a graphical object and its behaviors such as duplication, transformation and composition. 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.
Subclassed by tvg::Picture, tvg::Scene, tvg::Shape, tvg::Text
Public Functions
- 
virtual ~Paint()
 
- 
Result rotate(float degree) noexcept
 Sets the angle by which the object is rotated.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- 参数:
 degree -- [in] The value of the angle in degrees.
- 返回值:
 Result::InsufficientCondition -- in case a custom transform is applied.
- 
Result scale(float factor) noexcept
 Sets the scale value of the object.
- 参数:
 factor -- [in] The value of the scaling factor. The default value is 1.
- 返回值:
 Result::InsufficientCondition -- in case a custom transform is applied.
- 
Result translate(float x, float y) noexcept
 Sets the values by which the object is moved in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- 参数:
 x -- [in] The value of the horizontal shift.
y -- [in] The value of the vertical shift.
- 返回值:
 Result::InsufficientCondition -- in case a custom transform is applied.
- 
Result transform(const Matrix &m) noexcept
 Sets the matrix of the affine transformation for the object.
The augmented matrix of the transformation is expected to be given.
- 参数:
 m -- [in] The 3x3 augmented matrix.
- 
Matrix transform() noexcept
 Gets the matrix of the affine transformation of the object.
The values of the matrix can be set by the transform() API, as well by the translate(), scale() and rotate(). In case no transformation was applied, the identity matrix is returned.
- Since
 0.4
- 返回:
 The augmented transformation matrix.
- 
Result opacity(uint8_t o) noexcept
 Sets the opacity of the object.
备注
Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible.
- 参数:
 o -- [in] The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
- 
Result composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept
 Sets the composition target object and the composition method.
- 参数:
 target -- [in] The paint of the target object.
method -- [in] The method used to composite the source object with the target.
- 
Result clip(std::unique_ptr<Paint> clipper) noexcept
 Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape's paths.
备注
clipperonly supports the Shape type.备注
Experimental API
- 参数:
 clipper -- [in] The shape object as the clipper.
- 返回值:
 Result::NonSupport -- If the
clippertype is not Shape.
- 
Result blend(BlendMethod method) noexcept
 Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen
BlendMethod, which specifies how the colors or images are combined.备注
Experimental API
- 参数:
 method -- [in] The blending method to be set.
- 
Result bounds(float *x, float *y, float *w, float *h) const noexcept
 - Deprecated:
 Use bounds(float* x, float* y, float* w, float* h, bool transformed) instead
- 
Result bounds(float *x, float *y, float *w, float *h, bool transformed) const noexcept
 Gets the axis-aligned bounding box of the paint object.
备注
This is useful when you need to figure out the bounding box of the paint in the canvas space.
备注
The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.
备注
If
transformedistrue, the paint needs to be pushed into a canvas and updated before this api is called.- 参数:
 x -- [out] The x-coordinate of the upper-left corner of the object.
y -- [out] The y-coordinate of the upper-left corner of the object.
w -- [out] The width of the object.
h -- [out] The height of the object.
transformed -- [in] If
true, the paint's transformations are taken into account in the scene it belongs to. Otherwise they aren't.
- 
Paint *duplicate() const noexcept
 Duplicates the object.
Creates a new object and sets its all properties as in the original object.
- 返回:
 The created object when succeed,
nullptrotherwise.
- 
uint8_t opacity() const noexcept
 Gets the opacity value of the object.
- 返回:
 The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
- 
CompositeMethod composite(const Paint **target) const noexcept
 Gets the composition target object and the composition method.
- Since
 0.5
- 参数:
 target -- [out] The paint of the target object.
- 返回:
 The method used to composite the source object with the target.
- 
virtual Type type() const noexcept = 0
 Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
 Experimental API
- 返回:
 The class type ID of the Paint instance.
- 
uint32_t identifier() const noexcept
 
 - 
virtual ~Paint()
 
- 
class Fill
 - #include <thorvg.h>
An abstract class representing the gradient fill of the Shape object.
It contains the information about the gradient colors and their arrangement inside the gradient bounds. The gradients bounds are defined in the LinearGradient or RadialGradient class, depending on the type of the gradient to be used. It specifies the gradient behavior in case the area defined by the gradient bounds is smaller than the area to be filled.
Subclassed by tvg::LinearGradient, tvg::RadialGradient
Public Functions
- 
virtual ~Fill()
 
- 
Result colorStops(const ColorStop *colorStops, uint32_t cnt) noexcept
 Sets the parameters of the colors of the gradient and their position.
- 参数:
 colorStops -- [in] An array of ColorStop data structure.
cnt -- [in] The count of the
colorStopsarray equal to the colors number used in the gradient.
- 
Result spread(FillSpread s) noexcept
 Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds.
- 参数:
 s -- [in] The FillSpread value.
- 
Result transform(const Matrix &m) noexcept
 Sets the matrix of the affine transformation for the gradient fill.
The augmented matrix of the transformation is expected to be given.
- 参数:
 m -- [in] The 3x3 augmented matrix.
- 
uint32_t colorStops(const ColorStop **colorStops) const noexcept
 Gets the parameters of the colors of the gradient, their position and number.
- 参数:
 colorStops -- [out] A pointer to the memory location, where the array of the gradient's ColorStop is stored.
- 返回:
 The number of colors used in the gradient. This value corresponds to the length of the
colorStopsarray.
- 
FillSpread spread() const noexcept
 Gets the FillSpread value of the fill.
- 返回:
 The FillSpread value of this Fill.
- 
Matrix transform() const noexcept
 Gets the matrix of the affine transformation of the gradient fill.
In case no transformation was applied, the identity matrix is returned.
- 返回:
 The augmented transformation matrix.
- 
Fill *duplicate() const noexcept
 Creates a copy of the Fill object.
Return a newly created Fill object with the properties copied from the original.
- 返回:
 A copied Fill object when succeed,
nullptrotherwise.
- 
virtual Type type() const noexcept = 0
 Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
 Experimental API
- 返回:
 The class type ID of the Fill instance.
- 
uint32_t identifier() const noexcept
 参见
Public Members
- 
Impl *pImpl
 
Protected Functions
- 
Fill()
 
- 
struct ColorStop
 - #include <thorvg.h>
A data structure storing the information about the color and its relative position inside the gradient bounds.
Public Members
- 
float offset
 The relative position of the color.
- 
uint8_t r
 The red color channel value in the range [0 ~ 255].
- 
uint8_t g
 The green color channel value in the range [0 ~ 255].
- 
uint8_t b
 The blue color channel value in the range [0 ~ 255].
- 
uint8_t a
 The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
 - 
float offset
 
 - 
virtual ~Fill()
 
- 
class Canvas
 - #include <thorvg.h>
An abstract class for drawing graphical elements.
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.
备注
A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical.
Subclassed by tvg::GlCanvas, tvg::SwCanvas, tvg::WgCanvas
Public Functions
- 
Canvas(RenderMethod*)
 
- 
virtual ~Canvas()
 
- 
std::list<Paint*> &paints() noexcept
 Returns the list of the paints that currently held by the Canvas.
This function provides the list of paint nodes, allowing users a direct opportunity to modify the scene tree.
备注
Experimental API
- 
virtual Result push(std::unique_ptr<Paint> paint) noexcept
 Passes drawing elements to the Canvas using Paint objects.
Only pushed paints in the canvas will be drawing targets. They are retained by the canvas until you call Canvas::clear().
备注
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.
- 参数:
 paint -- [in] A Paint object to be drawn.
- 返回值:
 Result::MemoryCorruption -- In case a
nullptris passed as the argument.
- 
virtual Result clear(bool free = true) noexcept
 Clear the internal canvas resources that used for the drawing.
This API sets the total number of paints pushed into the canvas to zero. Depending on the value of the
freeargument, the paints are either freed or retained. So if you need to update paint properties while maintaining the existing scene structure, you can setfree= false.- 参数:
 free -- [in] If
true, the memory occupied by paints is deallocated, otherwise it is not.
- 
virtual Result update(Paint *paint = nullptr) noexcept
 Request the canvas to update the paint objects.
If a
nullptris passed all paint objects retained by the Canvas are updated, otherwise only the paint to which the givenpaintpoints.备注
The Update behavior can be asynchronous if the assigned thread number is greater than zero.
- 参数:
 paint -- [in] A pointer to the Paint object or
nullptr.
- 
virtual Result draw() noexcept
 Requests the canvas to draw the Paint objects.
备注
Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards.
- 
virtual Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept
 Sets the drawing region in the canvas.
This function defines the rectangular area of the canvas that will be used for drawing operations. The specified viewport is used to clip the rendering output to the boundaries of the rectangle.
- Since
 0.15
备注
When resetting the target, the viewport will also be reset to the target size.
警告
It's not allowed to change the viewport during Canvas::push() - Canvas::sync() or Canvas::update() - Canvas::sync().
- 参数:
 x -- [in] The x-coordinate of the upper-left corner of the rectangle.
y -- [in] The y-coordinate of the upper-left corner of the rectangle.
w -- [in] The width of the rectangle.
h -- [in] The height of the rectangle.
- 
virtual Result sync() noexcept
 Guarantees that drawing task is finished.
The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, the sync() must be called after the draw() regardless of threading.
- 返回值:
 Result::InsufficientCondition -- The canvas is either already in sync condition or in a damaged condition (a draw is required before syncing).
Public Members
- 
Impl *pImpl
 
 - 
Canvas(RenderMethod*)
 
- 
class LinearGradient : public tvg::Fill
 - #include <thorvg.h>
A class representing the linear gradient fill of the Shape object.
Besides the APIs inherited from the Fill class, it enables setting and getting the linear gradient bounds. The behavior outside the gradient bounds depends on the value specified in the spread API.
Public Functions
- 
~LinearGradient()
 
- 
Result linear(float x1, float y1, float x2, float y2) noexcept
 Sets the linear gradient bounds.
The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing the given points (
x1,y1) and (x2,y2), respectively. Both lines are perpendicular to the line linking (x1,y1) and (x2,y2).备注
In case the first and the second points are equal, an object is filled with a single color using the last color specified in the colorStops().
- 参数:
 x1 -- [in] The horizontal coordinate of the first point used to determine the gradient bounds.
y1 -- [in] The vertical coordinate of the first point used to determine the gradient bounds.
x2 -- [in] The horizontal coordinate of the second point used to determine the gradient bounds.
y2 -- [in] The vertical coordinate of the second point used to determine the gradient bounds.
- 
Result linear(float *x1, float *y1, float *x2, float *y2) const noexcept
 Gets the linear gradient bounds.
The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing the given points (
x1,y1) and (x2,y2), respectively. Both lines are perpendicular to the line linking (x1,y1) and (x2,y2).- 参数:
 x1 -- [out] The horizontal coordinate of the first point used to determine the gradient bounds.
y1 -- [out] The vertical coordinate of the first point used to determine the gradient bounds.
x2 -- [out] The horizontal coordinate of the second point used to determine the gradient bounds.
y2 -- [out] The vertical coordinate of the second point used to determine the gradient bounds.
- 
virtual Type type() const noexcept override
 Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
 Experimental API
- 返回:
 The class type ID of the LinearGradient instance.
Public Members
- 
Impl *pImpl
 
Public Static Functions
- 
static std::unique_ptr<LinearGradient> gen() noexcept
 Creates a new LinearGradient object.
- 返回:
 A new LinearGradient object.
- 
static uint32_t identifier() noexcept
 
Protected Functions
- 
LinearGradient(const LinearGradient&) = delete
 
- 
const LinearGradient &operator=(const LinearGradient&) = delete
 
- 
LinearGradient()
 
 - 
~LinearGradient()
 
- 
class RadialGradient : public tvg::Fill
 - #include <thorvg.h>
A class representing the radial gradient fill of the Shape object.
Public Functions
- 
~RadialGradient()
 
- 
Result radial(float cx, float cy, float radius) noexcept
 Sets the radial gradient bounds.
The radial gradient bounds are defined as a circle centered in a given point (
cx,cy) of a given radius.备注
In case the
radiusis zero, an object is filled with a single color using the last color specified in the colorStops().- 参数:
 cx -- [in] The horizontal coordinate of the center of the bounding circle.
cy -- [in] The vertical coordinate of the center of the bounding circle.
radius -- [in] The radius of the bounding circle.
- 返回值:
 Result::InvalidArguments -- in case the
radiusvalue is zero or less.
- 
Result radial(float *cx, float *cy, float *radius) const noexcept
 Gets the radial gradient bounds.
The radial gradient bounds are defined as a circle centered in a given point (
cx,cy) of a given radius.- 参数:
 cx -- [out] The horizontal coordinate of the center of the bounding circle.
cy -- [out] The vertical coordinate of the center of the bounding circle.
radius -- [out] The radius of the bounding circle.
- 
virtual Type type() const noexcept override
 Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
 Experimental API
- 返回:
 The class type ID of the LinearGradient instance.
Public Members
- 
Impl *pImpl
 
Public Static Functions
- 
static std::unique_ptr<RadialGradient> gen() noexcept
 Creates a new RadialGradient object.
- 返回:
 A new RadialGradient object.
- 
static uint32_t identifier() noexcept
 
Protected Functions
- 
RadialGradient(const RadialGradient&) = delete
 
- 
const RadialGradient &operator=(const RadialGradient&) = delete
 
- 
RadialGradient()
 
 - 
~RadialGradient()
 
- 
class Shape : public tvg::Paint
 - #include <thorvg.h>
A class representing two-dimensional figures and their properties.
A shape has three major properties: shape outline, stroking, filling. The outline in the Shape is retained as the path. Path can be composed by accumulating primitive commands such as moveTo(), lineTo(), cubicTo(), or complete shape interfaces such as appendRect(), appendCircle(), etc. Path can consists of sub-paths. One sub-path is determined by a close command.
The stroke of Shape is an optional property in case the Shape needs to be represented with/without the outline borders. 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.
Public Functions
- 
~Shape()
 
- 
Result reset() noexcept
 Resets the shape path.
The transformation matrix, color, fill, and stroke properties are retained.
备注
The memory where the path data is stored is not deallocated at this stage to allow for caching.
- 
Result moveTo(float x, float y) noexcept
 Sets the initial point of the sub-path.
The value of the current point is set to the given point.
- 参数:
 x -- [in] The horizontal coordinate of the initial point of the sub-path.
y -- [in] The vertical coordinate of the initial point of the sub-path.
- 
Result lineTo(float x, float y) noexcept
 Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point.
The value of the current point is set to the given end-point.
备注
In case this is the first command in the path, it corresponds to the moveTo() call.
- 参数:
 x -- [in] The horizontal coordinate of the end-point of the line.
y -- [in] The vertical coordinate of the end-point of the line.
- 
Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept
 Adds new points to the sub-path, which results in drawing a cubic Bezier curve starting at the current point and ending at the given end-point (
x,y) using the control points (cx1,cy1) and (cx2,cy2).The value of the current point is set to the given end-point.
备注
In case this is the first command in the path, no data from the path are rendered.
- 参数:
 cx1 -- [in] The horizontal coordinate of the 1st control point.
cy1 -- [in] The vertical coordinate of the 1st control point.
cx2 -- [in] The horizontal coordinate of the 2nd control point.
cy2 -- [in] The vertical coordinate of the 2nd control point.
x -- [in] The horizontal coordinate of the end-point of the curve.
y -- [in] The vertical coordinate of the end-point of the curve.
- 
Result close() noexcept
 Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path.
The value of the current point is set to the initial point of the closed sub-path.
备注
In case the sub-path does not contain any points, this function has no effect.
- 
Result appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0) noexcept
 Appends a rectangle to the path.
The rectangle with rounded corners can be achieved by setting non-zero values to
rxandryarguments. Therxandryvalues specify the radii of the ellipse defining the rounding of the corners.The position of the rectangle is specified by the coordinates of its upper-left corner -
xandyarguments.The rectangle is treated as a new sub-path - it is not connected with the previous sub-path.
The value of the current point is set to (
x+rx,y) - in caserxis greater thanw/2the current point is set to (x+w/2,y)备注
For
rxandrygreater than or equal to the half ofwand the half ofh, respectively, the shape become an ellipse.- 参数:
 x -- [in] The horizontal coordinate of the upper-left corner of the rectangle.
y -- [in] The vertical coordinate of the upper-left corner of the rectangle.
w -- [in] The width of the rectangle.
h -- [in] The height of the rectangle.
rx -- [in] The x-axis radius of the ellipse defining the rounded corners of the rectangle.
ry -- [in] The y-axis radius of the ellipse defining the rounded corners of the rectangle.
- 
Result appendCircle(float cx, float cy, float rx, float ry) noexcept
 Appends an ellipse to the path.
The position of the ellipse is specified by the coordinates of its center -
cxandcyarguments.The ellipse is treated as a new sub-path - it is not connected with the previous sub-path.
The value of the current point is set to (
cx,cy-ry).- 参数:
 cx -- [in] The horizontal coordinate of the center of the ellipse.
cy -- [in] The vertical coordinate of the center of the ellipse.
rx -- [in] The x-axis radius of the ellipse.
ry -- [in] The y-axis radius of the ellipse.
- 
Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept
 Appends a circular arc to the path.
The arc is treated as a new sub-path - it is not connected with the previous sub-path. The current point value is set to the end-point of the arc in case
pieisfalse, and to the center of the arc otherwise.备注
Setting
sweepvalue greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius).- 参数:
 cx -- [in] The horizontal coordinate of the center of the arc.
cy -- [in] The vertical coordinate of the center of the arc.
radius -- [in] The radius of the arc.
startAngle -- [in] The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line.
sweep -- [in] The central angle of the arc given in degrees, measured counter-clockwise from
startAngle.pie -- [in] Specifies whether to draw radii from the arc's center to both of its end-point - drawn if
true.
- 
Result appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point *pts, uint32_t ptsCnt) noexcept
 Appends a given sub-path to the path.
The current point value is set to the last point from the sub-path. For each command from the
cmdsarray, an appropriate number of points inptsarray should be specified. If the number of points in theptsarray is different than the number required by thecmdsarray, the shape with this sub-path will not be displayed on the screen.备注
The interface is designed for optimal path setting if the caller has a completed path commands already.
- 参数:
 cmds -- [in] The array of the commands in the sub-path.
cmdCnt -- [in] The number of the sub-path's commands.
pts -- [in] The array of the two-dimensional points.
ptsCnt -- [in] The number of the points in the
ptsarray.
- 
Result stroke(float width) noexcept
 Sets the stroke width for all of the figures from the path.
- 参数:
 width -- [in] The width of the stroke. The default value is 0.
- 
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept
 Sets the color of the stroke for all of the figures from the path.
- 参数:
 r -- [in] The red color channel value in the range [0 ~ 255]. The default value is 0.
g -- [in] The green color channel value in the range [0 ~ 255]. The default value is 0.
b -- [in] The blue color channel value in the range [0 ~ 255]. The default value is 0.
a -- [in] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
- 
Result stroke(std::unique_ptr<Fill> f) noexcept
 Sets the gradient fill of the stroke for all of the figures from the path.
- 参数:
 f -- [in] The gradient fill.
- 返回值:
 Result::MemoryCorruption -- In case a
nullptris passed as the argument.
- 
Result stroke(const float *dashPattern, uint32_t cnt) noexcept
 Sets the dash pattern of the stroke.
备注
To reset the stroke dash pattern, pass
nullptrtodashPatternand zero tocnt.警告
cntmust be greater than 1 if the dash pattern is valid.- 参数:
 dashPattern -- [in] The array of consecutive pair values of the dash length and the gap length.
cnt -- [in] The length of the
dashPatternarray.
- 返回值:
 Result::InvalidArguments -- In case
dashPatternisnullptrandcnt> 0,cntis zero, any of the dash pattern values is zero or less.
- 
Result stroke(StrokeCap cap) noexcept
 Sets the cap style of the stroke in the open sub-paths.
- 参数:
 cap -- [in] The cap style value. The default value is
StrokeCap::Square.
- 
Result stroke(StrokeJoin join) noexcept
 Sets the join style for stroked path segments.
The join style is used for joining the two line segment while stroking the path.
- 参数:
 join -- [in] The join style value. The default value is
StrokeJoin::Bevel.
- 
Result strokeMiterlimit(float miterlimit) noexcept
 Sets the stroke miterlimit.
- Since
 0.11
- 参数:
 miterlimit -- [in] The miterlimit imposes a limit on the extent of the stroke join, when the
StrokeJoin::Miterjoin style is set. The default value is 4.- 返回值:
 Result::InvalidArgument -- for
miterlimitvalues less than zero.
- 
Result strokeTrim(float begin, float end, bool simultaneous = true) noexcept
 Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible.
If the values of the arguments
beginandendexceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular.备注
Experimental API
- 参数:
 begin -- [in] Specifies the start of the segment to display along the path.
end -- [in] Specifies the end of the segment to display along the path.
simultaneous -- [in] Determines how to trim multiple paths within a single shape. If set to
true(default), trimming is applied simultaneously to all paths; 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.
- 
Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept
 Sets the solid color for all of the figures from the path.
The parts of the shape defined as inner are colored.
备注
Either a solid color or a gradient fill is applied, depending on what was set as last.
- 参数:
 r -- [in] The red color channel value in the range [0 ~ 255]. The default value is 0.
g -- [in] The green color channel value in the range [0 ~ 255]. The default value is 0.
b -- [in] The blue color channel value in the range [0 ~ 255]. The default value is 0.
a -- [in] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
- 
Result fill(std::unique_ptr<Fill> f) noexcept
 Sets the gradient fill for all of the figures from the path.
The parts of the shape defined as inner are filled.
备注
Either a solid color or a gradient fill is applied, depending on what was set as last.
- 参数:
 f -- [in] The unique pointer to the gradient fill.
- 
Result fill(FillRule r) noexcept
 Sets the fill rule for the Shape object.
- 参数:
 r -- [in] The fill rule value. The default value is
FillRule::Winding.
- 
Result order(bool strokeFirst) noexcept
 Sets the rendering order of the stroke and the fill.
- Since
 0.10
- 参数:
 strokeFirst -- [in] If
truethe stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option).
- 
uint32_t pathCommands(const PathCommand **cmds) const noexcept
 Gets the commands data of the path.
- 参数:
 cmds -- [out] The pointer to the array of the commands from the path.
- 返回:
 The length of the
cmdsarray when succeed, zero otherwise.
- 
uint32_t pathCoords(const Point **pts) const noexcept
 Gets the points values of the path.
- 参数:
 pts -- [out] The pointer to the array of the two-dimensional points from the path.
- 返回:
 The length of the
ptsarray when succeed, zero otherwise.
- 
const Fill *fill() const noexcept
 Gets the pointer to the gradient fill of the shape.
- 返回:
 The pointer to the gradient fill of the stroke when succeed,
nullptrin case no fill was set.
- 
Result fillColor(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a = nullptr) const noexcept
 Gets the solid color of the shape.
- 参数:
 r -- [out] The red color channel value in the range [0 ~ 255].
g -- [out] The green color channel value in the range [0 ~ 255].
b -- [out] The blue color channel value in the range [0 ~ 255].
a -- [out] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
- 
float strokeWidth() const noexcept
 Gets the stroke width.
- 返回:
 The stroke width value when succeed, zero if no stroke was set.
- 
Result strokeColor(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a = nullptr) const noexcept
 Gets the color of the shape's stroke.
- 参数:
 r -- [out] The red color channel value in the range [0 ~ 255].
g -- [out] The green color channel value in the range [0 ~ 255].
b -- [out] The blue color channel value in the range [0 ~ 255].
a -- [out] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
- 
const Fill *strokeFill() const noexcept
 Gets the pointer to the gradient fill of the stroke.
- 返回:
 The pointer to the gradient fill of the stroke when succeed,
nullptrotherwise.
- 
uint32_t strokeDash(const float **dashPattern) const noexcept
 Gets the dash pattern of the stroke.
- 参数:
 dashPattern -- [out] The pointer to the memory, where the dash pattern array is stored.
- 返回:
 The length of the
dashPatternarray.
- 
StrokeCap strokeCap() const noexcept
 Gets the cap style used for stroking the path.
- 返回:
 The cap style value of the stroke.
- 
StrokeJoin strokeJoin() const noexcept
 Gets the join style value used for stroking the path.
- 返回:
 The join style value of the stroke.
- 
float strokeMiterlimit() const noexcept
 Gets the stroke miterlimit.
- Since
 0.11
- 返回:
 The stroke miterlimit value when succeed, 4 if no stroke was set.
Public Members
- 
Impl *pImpl
 
Public Static Functions
- 
static uint32_t identifier() noexcept
 
 - 
~Shape()
 
- 
class Picture : public tvg::Paint
 - #include <thorvg.h>
A class representing an image read in one of the supported formats: raw, svg, png, jpg, lottie(json) and etc. Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas.
备注
Supported formats are depended on the available TVG loaders.
备注
See Animation class if the picture data is animatable.
Public Functions
- 
~Picture()
 
- 
Result load(const std::string &path) noexcept
 Loads a picture data directly from a file.
ThorVG efficiently caches the loaded data using the specified
pathas a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded picture data.备注
The Load behavior can be asynchronous if the assigned thread number is greater than zero.
- 参数:
 path -- [in] A path to the picture file.
- 返回值:
 Result::InvalidArguments -- In case the
pathis invalid.Result::NonSupport -- When trying to load a file with an unknown extension.
- 
Result load(const char *data, uint32_t size, bool copy = false) noexcept
 - Deprecated:
 Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead.
- 
Result load(const char *data, uint32_t size, const std::string &mimeType, bool copy = false) noexcept
 Loads a picture data from a memory block of a given size.
ThorVG efficiently caches the loaded data using the specified
dataaddress as a key when thecopyhasfalse. This means that loading the same data again will not result in duplicate operations for the sharabledata. Instead, ThorVG will reuse the previously loaded picture data.- Since
 0.5
备注
If you are unsure about the MIME type, you can provide an empty value like
"", and thorvg will attempt to figure it out.警告
It's the user responsibility to release the
datamemory.- 参数:
 data -- [in] 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
copyisfalse.size -- [in] The size in bytes of the memory occupied by the
data.mimeType -- [in] Mimetype or extension of data such as "jpg", "jpeg", "lottie", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.
copy -- [in] If
truethe data are copied into the engine local buffer, otherwise they are not.
- 返回值:
 Result::InvalidArguments -- In case no data are provided or the
sizeis zero or less.Result::NonSupport -- When trying to load a file with an unknown extension.
- 
Result size(float w, float h) noexcept
 Resizes the picture content to the given width and height.
The picture content is resized while keeping the default size aspect ratio. The scaling factor is established for each of dimensions and the smaller value is applied to both of them.
- 参数:
 w -- [in] A new width of the image in pixels.
h -- [in] A new height of the image in pixels.
- 
Result size(float *w, float *h) const noexcept
 Gets the size of the image.
- 参数:
 w -- [out] The width of the image in pixels.
h -- [out] The height of the image in pixels.
- 
Result load(uint32_t *data, uint32_t w, uint32_t h, bool copy) noexcept
 Loads raw data in ARGB8888 format from a memory block of the given size.
ThorVG efficiently caches the loaded data using the specified
dataaddress as a key when thecopyhasfalse. This means that loading the same data again will not result in duplicate operations for the sharabledata. Instead, ThorVG will reuse the previously loaded picture data.- Since
 0.9
- 参数:
 data -- [in] A pointer to a memory location where the content of the picture raw data is stored.
w -- [in] The width of the image
datain pixels.h -- [in] The height of the image
datain pixels.premultiplied -- [in] If
true, the given image data is alpha-premultiplied.copy -- [in] If
truethe data are copied into the engine local buffer, otherwise they are not.
- 
const Paint *paint(uint32_t id) noexcept
 Retrieve a paint object from the Picture scene by its Unique ID.
This function searches for a paint object within the Picture scene that matches the provided
id.备注
Experimental API
- 参数:
 id -- [in] The Unique ID of the paint object.
- 返回:
 A pointer to the paint object that matches the given identifier, or
nullptrif no matching paint object is found.
 - 
~Picture()
 
- 
class Scene : public tvg::Paint
 - #include <thorvg.h>
A class to composite children paints.
As the traditional graphics rendering method, TVG also enables scene-graph mechanism. This feature supports an array function for managing the multiple paints as one group paint.
As a group, the scene can be transformed, made translucent and composited with other target paints, its children will be affected by the scene world.
Public Functions
- 
~Scene()
 
- 
Result push(std::unique_ptr<Paint> paint) noexcept
 Passes drawing elements to the Scene using Paint objects.
Only the paints pushed into the scene will be the drawn targets. The paints are retained by the scene until Scene::clear() is called.
备注
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.
- 参数:
 paint -- [in] A Paint object to be drawn.
- 
std::list<Paint*> &paints() noexcept
 Returns the list of the paints that currently held by the Scene.
This function provides the list of paint nodes, allowing users a direct opportunity to modify the scene tree.
备注
Experimental API
警告
Please avoid accessing the paints during Scene update/draw. You can access them after calling Canvas::sync().
- 
Result clear(bool free = true) noexcept
 Sets the total number of the paints pushed into the scene to be zero. Depending on the value of the
freeargument, the paints are freed or not.- Since
 0.2
警告
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
freeargument only when you know how it works, otherwise it's not recommended.- 参数:
 free -- [in] If
true, the memory occupied by paints is deallocated, otherwise it is not.
- 
Result push(SceneEffect effect, ...) noexcept
 Apply a post-processing effect to the scene.
This function adds a specified scene effect, such as clearing all effects or applying a Gaussian blur, to the scene after it has been rendered. Multiple effects can be applied in sequence.
备注
Experimental API
- 参数:
 effect -- [in] The scene effect to apply. Options are defined in the SceneEffect enum. For example, use SceneEffect::GaussianBlur to apply a blur with specific parameters.
... -- [in] Additional variadic parameters required for certain effects (e.g., sigma and direction for GaussianBlur).
Public Members
- 
Impl *pImpl
 
Public Static Functions
- 
static uint32_t identifier() noexcept
 
 - 
~Scene()
 
- 
class Text : public tvg::Paint
 - #include <thorvg.h>
A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text.
- Since
 0.15
Public Functions
- 
~Text()
 
- 
Result font(const char *name, float size, const char *style = nullptr) noexcept
 Sets the font properties for the text.
This function allows you to define the font characteristics used for text rendering. It sets the font name, size and optionally the style.
备注
Experimental API
- 参数:
 name -- [in] The name of the font. This should correspond to a font available in the canvas.
size -- [in] The size of the font in points. This determines how large the text will appear.
style -- [in] The style of the font. It can be used to set the font to 'italic'. If not specified, the default style is used. Only 'italic' style is supported currently.
- 返回值:
 Result::InsufficientCondition -- when the specified
namecannot be found.
- 
Result text(const char *text) noexcept
 Assigns the given unicode text to be rendered.
This function sets the unicode string that will be displayed by the rendering system. The text is set according to the specified UTF encoding method, which defaults to UTF-8.
备注
Experimental API
- 参数:
 text -- [in] The multi-byte text encoded with utf8 string to be rendered.
- 
Result fill(uint8_t r, uint8_t g, uint8_t b) noexcept
 Sets the text color.
参见
- Since
 0.15
- 参数:
 r -- [in] The red color channel value in the range [0 ~ 255]. The default value is 0.
g -- [in] The green color channel value in the range [0 ~ 255]. The default value is 0.
b -- [in] The blue color channel value in the range [0 ~ 255]. The default value is 0.
- 
Result fill(std::unique_ptr<Fill> f) noexcept
 Sets the gradient fill for all of the figures from the text.
The parts of the text defined as inner are filled.
参见
- Since
 0.15
备注
Either a solid color or a gradient fill is applied, depending on what was set as last.
- 参数:
 f -- [in] The unique pointer to the gradient fill.
Public Members
- 
Impl *pImpl
 
Public Static Functions
- 
static Result load(const std::string &path) noexcept
 Loads a scalable font data (ttf) from a file.
ThorVG efficiently caches the loaded data using the specified
pathas a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded font data.- Since
 0.15
- 参数:
 path -- [in] The path to the font file.
- 返回值:
 Result::InvalidArguments -- In case the
pathis invalid.Result::NonSupport -- When trying to load a file with an unknown extension.
- 
static Result load(const char *name, const char *data, uint32_t size, const std::string &mimeType = "ttf", bool copy = false) noexcept
 Loads a scalable font data (ttf) from a memory block of a given size.
ThorVG efficiently caches the loaded font data using the specified
nameas a key. This means that loading the same fonts again will not result in duplicate operations. Instead, ThorVG will reuse the previously loaded font data.备注
To unload the font data loaded using this API, pass the proper
nameandnullptrasdata.备注
If you are unsure about the MIME type, you can provide an empty value like
"", and thorvg will attempt to figure it out.备注
0.15
警告
It's the user responsibility to release the
datamemory.- 参数:
 name -- [in] The name under which the font will be stored and accessible (e.x. in a
font()API).data -- [in] A pointer to a memory location where the content of the font data is stored.
size -- [in] The size in bytes of the memory occupied by the
data.mimeType -- [in] Mimetype or extension of font data. In case an empty string is provided the loader will be determined automatically.
copy -- [in] If
truethe data are copied into the engine local buffer, otherwise they are not (default).
- 返回值:
 Result::InvalidArguments -- If no name is provided or if
sizeis zero whiledatapoints to a valid memory location.Result::NonSupport -- When trying to load a file with an unsupported extension.
Result::InsufficientCondition -- If attempting to unload the font data that has not been previously loaded.
- 
static Result unload(const std::string &path) noexcept
 Unloads the specified scalable font data (TTF) that was previously loaded.
This function is used to release resources associated with a font file that has been loaded into memory.
- Since
 0.15
备注
If the font data is currently in use, it will not be immediately unloaded.
- 参数:
 path -- [in] The file path of the loaded font.
- 返回值:
 Result::InsufficientCondition -- Fails if the loader is not initialized.
 
- 
class SwCanvas : public tvg::Canvas
 - #include <thorvg.h>
A class for the rendering graphical elements with a software raster engine.
Public Types
- 
enum Colorspace
 Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.
Values:
- 
enumerator ABGR8888
 The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. (a << 24 | b << 16 | g << 8 | r)
- 
enumerator ARGB8888
 The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. (a << 24 | r << 16 | g << 8 | b)
- 
enumerator ABGR8888S
 The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied.
- Since
 0.12
- 
enumerator ARGB8888S
 The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied.
- Since
 0.12
- 
enumerator ABGR8888
 
- 
enum MempoolPolicy
 Enumeration specifying the methods of Memory Pool behavior policy.
- Since
 0.4
Values:
- 
enumerator Default
 Default behavior that ThorVG is designed to.
Memory Pool is shared among the SwCanvases.
- 
enumerator Individual
 Allocate designated memory pool that is only used by current instance.
Public Functions
- 
~SwCanvas()
 
- 
Result target(uint32_t *buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept
 Sets the drawing target for the rasterization.
The buffer of a desirable size should be allocated and owned by the caller.
警告
Do not access
bufferduring Canvas::push() - Canvas::sync(). It should not be accessed while the engine is writing on it.- 参数:
 buffer -- [in] A pointer to a memory block of the size
stridexh, where the raster data are stored.stride -- [in] The stride of the raster image - greater than or equal to
w.w -- [in] The width of the raster image.
h -- [in] The height of the raster image.
cs -- [in] The value specifying the way the 32-bits colors should be read/written.
- 返回值:
 Result::InvalidArguments -- In case no valid pointer is provided or the width, or the height or the stride is zero.
Result::InsufficientCondition -- if the canvas is performing rendering. Please ensure the canvas is synced.
Result::NonSupport -- In case the software engine is not supported.
- 
Result mempool(MempoolPolicy policy) noexcept
 Set sw engine memory pool behavior policy.
Basically ThorVG draws a lot of shapes, it allocates/deallocates a few chunk of memory while processing rendering. It internally uses one shared memory pool which can be reused among the canvases in order to avoid memory overhead.
Thus ThorVG suggests using a memory pool policy to satisfy user demands, if it needs to guarantee the thread-safety of the internal data access.
- Since
 0.4
备注
When
policyis set asMempoolPolicy::Individual, the current instance of canvas uses its own individual memory data, which is not shared with others. This is necessary when the canvas is accessed on a worker-thread.警告
It's not allowed after pushing any paints.
- 参数:
 policy -- [in] The method specifying the Memory Pool behavior. The default value is
MempoolPolicy::Default.- 返回值:
 Result::InsufficientCondition -- If the canvas contains some paints already.
Result::NonSupport -- In case the software engine is not supported.
Public Members
- 
Impl *pImpl
 
Public Static Functions
 - 
enum Colorspace
 
- 
class GlCanvas : public tvg::Canvas
 - #include <thorvg.h>
A class for the rendering graphic elements with a GL raster engine.
- Since
 0.14
Public Functions
- 
~GlCanvas()
 
- 
Result target(int32_t id, uint32_t w, uint32_t h) noexcept
 Sets the drawing target for rasterization.
This function specifies the drawing target where the rasterization will occur. It can target a specific framebuffer object (FBO) or the main surface.
备注
Currently, this only allows the GL_RGBA8 color space format.
备注
Experimental API
- 参数:
 id -- [in] The GL target ID, usually indicating the FBO ID. A value of
0specifies the main surface.w -- [in] The width (in pixels) of the raster image.
h -- [in] The height (in pixels) of the raster image.
- 返回值:
 Result::InsufficientCondition -- if the canvas is performing rendering. Please ensure the canvas is synced.
Result::NonSupport -- In case the gl engine is not supported.
Public Members
- 
Impl *pImpl
 
Public Static Functions
 
- 
class WgCanvas : public tvg::Canvas
 - #include <thorvg.h>
A class for the rendering graphic elements with a WebGPU raster engine.
- Since
 0.15
警告
Please do not use it. This class is not fully supported yet.
Public Functions
- 
~WgCanvas()
 
- 
Result target(void *instance, void *surface, uint32_t w, uint32_t h, void *device = nullptr) noexcept
 Sets the drawing target for the rasterization.
备注
Experimental API
- 参数:
 instance -- [in] WGPUInstance, context for all other wgpu objects.
surface -- [in] WGPUSurface, handle to a presentable surface.
w -- [in] The width of the surface.
h -- [in] The height of the surface.
device -- [in] WGPUDevice, a desired handle for the wgpu device. If it is
nullptr, ThorVG will assign an appropriate device internally.
- 返回值:
 Result::InsufficientCondition -- if the canvas is performing rendering. Please ensure the canvas is synced.
Result::NonSupport -- In case the wg engine is not supported.
Public Members
- 
Impl *pImpl
 
Public Static Functions
 
- 
class Initializer
 - #include <thorvg.h>
A class that enables initialization and termination of the TVG engines.
Public Static Functions
- 
static Result init(CanvasEngine engine, uint32_t threads) noexcept
 Initializes TVG engines.
TVG requires the running-engine environment. TVG runs its own task-scheduler for parallelizing rendering tasks efficiently. You can indicate the number of threads, the count of which is designated
threads. In the initialization step, TVG will generate/spawn the threads as set bythreadscount.备注
The Initializer keeps track of the number of times it was called. Threads count is fixed at the first init() call.
- 参数:
 engine -- [in] 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.
threads -- [in] The number of additional threads. Zero indicates only the main thread is to be used.
- 返回值:
 Result::NonSupport -- In case the engine type is not supported on the system.
- 
static Result term(CanvasEngine engine) noexcept
 Terminates TVG engines.
备注
Initializer does own reference counting for multiple calls.
- 参数:
 engine -- [in] 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
- 返回值:
 Result::InsufficientCondition -- In case there is nothing to be terminated.
Result::NonSupport -- In case the engine type is not supported on the system.
- 
static const char *version(uint32_t *major, uint32_t *minor, uint32_t *micro) noexcept
 Retrieves the version of the TVG engine.
- Since
 0.15
- 参数:
 major -- [out] A major version number.
minor -- [out] A minor version number.
micro -- [out] A micro version number.
- 返回:
 The version of the engine in the format major.minor.micro, or a
nullptrin case of an internal error.
 - 
static Result init(CanvasEngine engine, uint32_t threads) noexcept
 
- 
class Animation
 - #include <thorvg.h>
The Animation class enables manipulation of animatable images.
This class supports the display and control of animation frames.
- Since
 0.13
Subclassed by tvg::LottieAnimation
Public Functions
- 
~Animation()
 
- 
Result frame(float no) noexcept
 Specifies the current frame in the animation.
参见
备注
For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value is less than 0.001. In such cases, it returns
Result::InsufficientCondition. Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.- 参数:
 no -- [in] The index of the animation frame to be displayed. The index should be less than the totalFrame().
- 返回值:
 Result::InsufficientCondition -- if the given
nois the same as the current frame value.Result::NonSupport -- The current Picture data does not support animations.
- 
Picture *picture() const noexcept
 Retrieves a picture instance associated with this animation instance.
This function provides access to the picture instance that can be used to load animation formats, such as Lottie(json). After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames with this Animation instance.
警告
The picture instance is owned by Animation. It should not be deleted manually.
- 返回:
 A picture instance that is tied to this animation.
- 
float curFrame() const noexcept
 Retrieves the current frame number of the animation.
备注
If the Picture is not properly configured, this function will return 0.
- 返回:
 The current frame number of the animation, between 0 and totalFrame() - 1.
- 
float totalFrame() const noexcept
 Retrieves the total number of frames in the animation.
备注
Frame numbering starts from 0.
备注
If the Picture is not properly configured, this function will return 0.
- 返回:
 The total number of frames in the animation.
- 
float duration() const noexcept
 Retrieves the duration of the animation in seconds.
备注
If the Picture is not properly configured, this function will return 0.
- 返回:
 The duration of the animation in seconds.
- 
Result segment(float begin, float end) noexcept
 Specifies the playback segment of the animation.
The set segment is designated as the play area of the animation. This is useful for playing a specific segment within the entire animation. After setting, the number of animation frames and the playback time are calculated by mapping the playback segment as the entire range.
备注
Animation allows a range from 0.0 to 1.0.
endshould not be higher thanbegin.备注
If a marker has been specified, its range will be disregarded.
备注
Experimental API
- 参数:
 begin -- [in] segment start.
end -- [in] segment end.
- 返回值:
 Result::InsufficientCondition -- In case the animation is not loaded.
Result::NonSupport -- When it's not animatable.
Public Members
- 
Impl *pImpl
 
Public Static Functions
 
- 
class Saver
 - #include <thorvg.h>
A class for exporting a paint object into a specified file, from which to recover the paint data later.
ThorVG provides a feature for exporting & importing paint data. The Saver role is to export the paint data to a file. It's useful when you need to save the composed scene or image from a paint object and recreate it later.
The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment. If it doesn't support the file format, the save() method returns the
Result::NonSupportresult.Once you export a paint to the file successfully, you can recreate it using the Picture class.
- Since
 0.5
Public Functions
- 
~Saver()
 
- 
Result background(std::unique_ptr<Paint> paint) noexcept
 Sets the base background content for the saved image.
备注
Experimental API
- 参数:
 paint -- [in] The paint to be drawn as the background image for the saving paint.
- 
Result save(std::unique_ptr<Paint> paint, const std::string &path, bool compress = true) noexcept
 Exports the given
paintdata to the givenpath.If the saver module supports any compression mechanism, it will optimize the data size. This might affect the encoding/decoding time in some cases. You can turn off the compression if you wish to optimize for speed.
- Since
 0.5
备注
Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards.
- 参数:
 paint -- [in] The paint to be saved with all its associated properties.
path -- [in] A path to the file, in which the paint data is to be saved.
compress -- [in] If
truethen compress data if possible.
- 返回值:
 Result::InsufficientCondition -- If currently saving other resources.
Result::NonSupport -- When trying to save a file with an unknown extension or in an unsupported format.
Result::Unknown -- In case an empty paint is to be saved.
- 
Result save(std::unique_ptr<Animation> animation, const std::string &path, uint32_t quality = 100, uint32_t fps = 0) noexcept
 Export the provided animation data to the specified file path.
This function exports the given animation data to the provided file path. You can also specify the desired frame rate in frames per second (FPS) by providing the fps parameter.
备注
A higher frames per second (FPS) would result in a larger file size. It is recommended to use the default value.
备注
Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards.
备注
Experimental API
- 参数:
 animation -- [in] The animation to be saved, including all associated properties.
path -- [in] The path to the file where the animation will be saved.
quality -- [in] The encoded quality level.
0is the minimum,100is the maximum value(recommended).fps -- [in] The desired frames per second (FPS). For example, to encode data at 60 FPS, pass 60. Pass 0 to keep the original frame data.
- 返回值:
 Result::InsufficientCondition -- if there are ongoing resource-saving operations.
Result::NonSupport -- if an attempt is made to save the file with an unknown extension or in an unsupported format.
Result::Unknown -- if attempting to save an empty paint.
- 
Result sync() noexcept
 Guarantees that the saving task is finished.
The behavior of the Saver works on a sync/async basis, depending on the threading setting of the Initializer. Thus, if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time. Otherwise, you can call sync() immediately.
- Since
 0.5
备注
The asynchronous tasking is dependent on the Saver module implementation.
Public Members
- 
Impl *pImpl
 
Public Static Functions
 
- 
class Accessor
 - #include <thorvg.h>
The Accessor is a utility class to debug the Scene structure by traversing the scene-tree.
The Accessor helps you search specific nodes to read the property information, figure out the structure of the scene tree and its size.
- Since
 0.10
警告
We strongly warn you not to change the paints of a scene unless you really know the design-structure.
Public Functions
- 
~Accessor()
 
- 
std::unique_ptr<Picture> set(std::unique_ptr<Picture> picture, std::function<bool(const Paint *paint)> func) noexcept
 
- 
Result set(const Picture *picture, std::function<bool(const Paint *paint, void *data)> func, void *data) noexcept
 Set the access function for traversing the Picture scene tree nodes.
备注
The bitmap based picture might not have the scene-tree.
备注
Experimental API
- 参数:
 picture -- [in] The picture node to traverse the internal scene-tree.
func -- [in] The callback function calling for every paint nodes of the Picture.
data -- [in] Data passed to the
funcas its argument.
Public Members
- 
Impl *pImpl
 
Public Static Functions
- 
static uint32_t id(const char *name) noexcept
 Generate a unique ID (hash key) from a given name.
This function computes a unique identifier value based on the provided string. You can use this to assign a unique ID to the Paint object.
参见
备注
Experimental API
- 参数:
 name -- [in] The input string to generate the unique identifier from.
- 返回:
 The generated unique identifier value.
 
- 
enum class Result