ThorVG  v0.13
ThorVG

ThorVG classes and enumerations providing C++ APIs. More...

Classes

struct  Point
 A data structure representing a point in two-dimensional space. More...
 
struct  Matrix
 A data structure representing a three-dimensional matrix. More...
 
struct  Vertex
 A data structure representing a texture mesh vertex. More...
 
struct  Polygon
 A data structure representing a triange in a texture mesh. More...
 
class  Paint
 An abstract class for managing graphical elements. More...
 
class  Fill
 An abstract class representing the gradient fill of the Shape object. More...
 
class  Canvas
 An abstract class for drawing graphical elements. More...
 
class  LinearGradient
 A class representing the linear gradient fill of the Shape object. More...
 
class  RadialGradient
 A class representing the radial gradient fill of the Shape object. More...
 
class  Shape
 A class representing two-dimensional figures and their properties. More...
 
class  Picture
 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. More...
 
class  Scene
 A class to composite children paints. More...
 
class  Text
 A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text. More...
 
class  SwCanvas
 A class for the rendering graphical elements with a software raster engine. More...
 
class  GlCanvas
 A class for the rendering graphic elements with a GL raster engine. More...
 
class  WgCanvas
 A class for the rendering graphic elements with a WebGPU raster engine. More...
 
class  Initializer
 A class that enables initialization and termination of the TVG engines. More...
 
class  Animation
 The Animation class enables manipulation of animatable images. More...
 
class  Saver
 A class for exporting a paint object into a specified file, from which to recover the paint data later. More...
 
class  Accessor
 The Accessor is a utility class to debug the Scene structure by traversing the scene-tree. More...
 

Enumerations

enum class  Result {
  Success = 0 , InvalidArguments , InsufficientCondition , FailedAllocation ,
  MemoryCorruption , NonSupport , Unknown
}
 Enumeration specifying the result from the APIs. More...
 
enum class  PathCommand { Close = 0 , MoveTo , LineTo , CubicTo }
 Enumeration specifying the values of the path commands accepted by TVG. More...
 
enum class  StrokeCap { Square = 0 , Round , Butt }
 Enumeration determining the ending type of a stroke in the open sub-paths. More...
 
enum class  StrokeJoin { Bevel = 0 , Round , Miter }
 Enumeration determining the style used at the corners of joined stroked path segments. More...
 
enum class  FillSpread { Pad = 0 , Reflect , Repeat }
 Enumeration specifying how to fill the area outside the gradient bounds. More...
 
enum class  FillRule { Winding = 0 , EvenOdd }
 Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape. More...
 
enum class  CompositeMethod {
  None = 0 , ClipPath , AlphaMask , InvAlphaMask ,
  LumaMask , InvLumaMask , AddMask , SubtractMask ,
  IntersectMask , DifferenceMask
}
 Enumeration indicating the method used in the composition of two objects - the target and the source. More...
 
enum class  BlendMethod : uint8_t {
  Normal = 0 , Add , Screen , Multiply ,
  Overlay , Difference , Exclusion , SrcOver ,
  Darken , Lighten , ColorDodge , ColorBurn ,
  HardLight , SoftLight
}
 Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method. More...
 
enum class  CanvasEngine { Sw = (1 << 1) , Gl = (1 << 2) , Wg = (1 << 3) }
 Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed. More...
 

Functions

template<typename T = tvg::Paint>
std::unique_ptr< T > cast (Paint *paint)
 The cast() function is a utility function used to cast a 'Paint' to type 'T'. More...
 
template<typename T = tvg::Fill>
std::unique_ptr< T > cast (Fill *fill)
 The cast() function is a utility function used to cast a 'Fill' to type 'T'. More...
 

Detailed Description

ThorVG classes and enumerations providing C++ APIs.

Enumeration Type Documentation

◆ BlendMethod

enum BlendMethod : uint8_t
strong

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)

See also
Paint::blend()
Note
Experimental API
Enumerator
Normal 

Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D.

Add 

Simply adds pixel values of one layer with the other. (S + D)

Screen 

The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D)

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)

Overlay 

Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)

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)

Exclusion 

The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d)

SrcOver 

Replace the bottom layer with the top layer.

Darken 

Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D)

Lighten 

Only has the opposite action of Darken Only. max(S, D)

ColorDodge 

Divides the bottom layer by the inverted top layer. D / (255 - S)

ColorBurn 

Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S.

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)

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)

◆ CanvasEngine

enum CanvasEngine
strong

Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed.

Enumerator
Sw 

CPU rasterizer.

Gl 

OpenGL rasterizer.

Wg 

WebGPU rasterizer. (Experimental API)

◆ CompositeMethod

enum CompositeMethod
strong

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)

See also
Paint::composite()
Enumerator
None 

No composition is applied.

ClipPath 

The intersection of the source and the target is determined and only the resulting pixels from the source are rendered.

AlphaMask 

Alpha Masking using the compositing target's pixels as an alpha value.

InvAlphaMask 

Alpha Masking using the complement to the compositing target's pixels as an alpha value.

LumaMask 

Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels.

Since
0.9
InvLumaMask 

Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the complement to the compositing target's pixels.

AddMask 

Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) (Experimental API)

SubtractMask 

Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) (Experimental API)

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)

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)

◆ FillRule

enum FillRule
strong

Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.

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.

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.

◆ FillSpread

enum FillSpread
strong

Enumeration specifying how to fill the area outside the gradient bounds.

Enumerator
Pad 

The remaining area is filled with the closest stop color.

Reflect 

The gradient pattern is reflected outside the gradient area until the expected region is filled.

Repeat 

The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.

◆ PathCommand

enum PathCommand
strong

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.

Enumerator
Close 

Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.

MoveTo 

Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.

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.

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.

◆ Result

enum Result
strong

Enumeration specifying the result from the APIs.

Enumerator
Success 

The value returned in case of a correct request execution.

InvalidArguments 

The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers.

InsufficientCondition 

The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.

FailedAllocation 

The value returned in case of unsuccessful memory allocation.

MemoryCorruption 

The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting.

NonSupport 

The value returned in case of choosing unsupported options.

Unknown 

The value returned in all other cases.

◆ StrokeCap

enum StrokeCap
strong

Enumeration determining the ending type of a stroke in the open sub-paths.

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.

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.

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.

◆ StrokeJoin

enum StrokeJoin
strong

Enumeration determining the style used at the corners of joined stroked path segments.

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.

Round 

The outer corner of the joined path segments is rounded. The circular region is centered at the join point.

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.

Function Documentation

◆ cast() [1/2]

std::unique_ptr<T> tvg::cast ( Fill fill)

The cast() function is a utility function used to cast a 'Fill' to type 'T'.

Since
0.11

◆ cast() [2/2]

std::unique_ptr<T> tvg::cast ( Paint paint)

The cast() function is a utility function used to cast a 'Paint' to type 'T'.

Since
0.11