thorvg.h
#ifndef _THORVG_H_
#define _THORVG_H_
#include <memory>
#ifdef TVG_BUILD
#define TVG_EXPORT __attribute__ ((visibility ("default")))
#else
#define TVG_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define _TVG_DECLARE_PRIVATE(A) \
protected: \
struct Impl; \
Impl* pImpl; \
A(const A&) = delete; \
const A& operator=(const A&) = delete; \
A()
#define _TVG_DISABLE_CTOR(A) \
A() = delete; \
~A() = delete
#define _TVG_DECLARE_ACCESSOR() \
friend Canvas; \
friend Scene; \
friend Picture
#define _TVG_DECALRE_IDENTIFIER() \
auto id() const { return _id; } \
protected: \
unsigned _id
namespace tvg
{
class RenderMethod;
class Scene;
class Picture;
class Canvas;
enum class TVG_EXPORT Result
{
Success = 0,
InvalidArguments,
InsufficientCondition,
FailedAllocation,
MemoryCorruption,
NonSupport,
Unknown
};
enum class TVG_EXPORT PathCommand
{
Close = 0,
MoveTo,
LineTo,
CubicTo
};
enum class TVG_EXPORT StrokeCap
{
Square = 0,
Round,
Butt
};
enum class TVG_EXPORT StrokeJoin
{
Bevel = 0,
Round,
Miter
};
enum class TVG_EXPORT FillSpread
{
Pad = 0,
Reflect,
Repeat
};
enum class TVG_EXPORT FillRule
{
Winding = 0,
EvenOdd
};
enum class TVG_EXPORT CompositeMethod
{
None = 0,
ClipPath,
AlphaMask,
InvAlphaMask
};
enum class TVG_EXPORT CanvasEngine
{
Sw = (1 << 1),
Gl = (1 << 2)
};
struct Point
{
float x, y;
};
struct Matrix
{
float e11, e12, e13;
float e21, e22, e23;
float e31, e32, e33;
};
class TVG_EXPORT Paint
{
public:
virtual ~Paint();
Result rotate(float degree) noexcept;
Result scale(float factor) noexcept;
Result translate(float x, float y) noexcept;
Result transform(const Matrix& m) noexcept;
Result opacity(uint8_t o) noexcept;
Result composite(std::unique_ptr<Paint> target, CompositeMethod method) const noexcept;
Result bounds(float* x, float* y, float* w, float* h) const noexcept;
Paint* duplicate() const noexcept;
uint8_t opacity() const noexcept;
_TVG_DECLARE_ACCESSOR();
_TVG_DECLARE_PRIVATE(Paint);
};
class TVG_EXPORT Fill
{
public:
struct ColorStop
{
float offset;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
virtual ~Fill();
Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
Result spread(FillSpread s) noexcept;
uint32_t colorStops(const ColorStop** colorStops) const noexcept;
FillSpread spread() const noexcept;
Fill* duplicate() const noexcept;
_TVG_DECALRE_IDENTIFIER();
_TVG_DECLARE_PRIVATE(Fill);
};
class TVG_EXPORT Canvas
{
public:
Canvas(RenderMethod*);
virtual ~Canvas();
Result reserve(uint32_t n) noexcept;
virtual Result push(std::unique_ptr<Paint> paint) noexcept;
virtual Result clear(bool free = true) noexcept;
virtual Result update(Paint* paint) noexcept;
virtual Result draw() noexcept;
virtual Result sync() noexcept;
_TVG_DECLARE_PRIVATE(Canvas);
};
class TVG_EXPORT LinearGradient final : public Fill
{
public:
~LinearGradient();
Result linear(float x1, float y1, float x2, float y2) noexcept;
Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
static std::unique_ptr<LinearGradient> gen() noexcept;
_TVG_DECLARE_PRIVATE(LinearGradient);
};
class TVG_EXPORT RadialGradient final : public Fill
{
public:
~RadialGradient();
Result radial(float cx, float cy, float radius) noexcept;
Result radial(float* cx, float* cy, float* radius) const noexcept;
static std::unique_ptr<RadialGradient> gen() noexcept;
_TVG_DECLARE_PRIVATE(RadialGradient);
};
class TVG_EXPORT Shape final : public Paint
{
public:
~Shape();
Result reset() noexcept;
Result moveTo(float x, float y) noexcept;
Result lineTo(float x, float y) noexcept;
Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
Result close() noexcept;
Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
Result stroke(float width) noexcept;
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
Result stroke(std::unique_ptr<Fill> f) noexcept;
Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
Result stroke(StrokeCap cap) noexcept;
Result stroke(StrokeJoin join) noexcept;
Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
Result fill(std::unique_ptr<Fill> f) noexcept;
Result fill(FillRule r) noexcept;
uint32_t pathCommands(const PathCommand** cmds) const noexcept;
uint32_t pathCoords(const Point** pts) const noexcept;
const Fill* fill() const noexcept;
Result fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
FillRule fillRule() const noexcept;
float strokeWidth() const noexcept;
Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
const Fill* strokeFill() const noexcept;
uint32_t strokeDash(const float** dashPattern) const noexcept;
StrokeCap strokeCap() const noexcept;
StrokeJoin strokeJoin() const noexcept;
static std::unique_ptr<Shape> gen() noexcept;
_TVG_DECLARE_PRIVATE(Shape);
};
class TVG_EXPORT Picture final : public Paint
{
public:
~Picture();
Result load(const std::string& path) noexcept;
Result load(const char* data, uint32_t size) noexcept;
Result size(float w, float h) noexcept;
Result size(float* w, float* h) const noexcept;
const uint32_t* data() const noexcept;
Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept;
Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
static std::unique_ptr<Picture> gen() noexcept;
_TVG_DECLARE_PRIVATE(Picture);
};
class TVG_EXPORT Scene final : public Paint
{
public:
~Scene();
Result push(std::unique_ptr<Paint> paint) noexcept;
Result reserve(uint32_t size) noexcept;
Result clear() noexcept;
static std::unique_ptr<Scene> gen() noexcept;
_TVG_DECLARE_PRIVATE(Scene);
};
class TVG_EXPORT SwCanvas final : public Canvas
{
public:
~SwCanvas();
enum Colorspace
{
ABGR8888 = 0,
ARGB8888
};
enum MempoolPolicy
{
Default = 0,
Shareable,
Individual
};
Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept;
Result mempool(MempoolPolicy policy) noexcept;
static std::unique_ptr<SwCanvas> gen() noexcept;
_TVG_DECLARE_PRIVATE(SwCanvas);
};
class TVG_EXPORT GlCanvas final : public Canvas
{
public:
~GlCanvas();
Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
static std::unique_ptr<GlCanvas> gen() noexcept;
_TVG_DECLARE_PRIVATE(GlCanvas);
};
class TVG_EXPORT Initializer final
{
public:
static Result init(CanvasEngine engine, uint32_t threads) noexcept;
static Result term(CanvasEngine engine) noexcept;
_TVG_DISABLE_CTOR(Initializer);
};
} //namespace
#ifdef __cplusplus
}
#endif
#endif //_THORVG_H_
tvg::CompositeMethod::AlphaMask
The pixels of the source and the target are alpha blended. As a result, only the part of the source...
tvg::PathCommand::LineTo
Draws a line from the current point to the given point and sets a new value of the current point...
tvg::StrokeCap::Round
The stroke is extended in both end-points of a sub-path by a half circle, with a radius equal to the ...
tvg::Result::Unknown
The value returned in all other cases.
tvg::Result::FailedAllocation
The value returned in case of unsuccessful memory allocation.
tvg::SwCanvas::MempoolPolicy
MempoolPolicy
Enumeration specifying the methods of Memory Pool behavior policy.
Definition: thorvg.h:1140
tvg::PathCommand::Close
Ends the current sub-path and connects it with its initial point. This command doesn&#39;t expect any poi...
tvg::Fill
An abstract class representing the gradient fill of the Shape object.
Definition: thorvg.h:307
tvg::Fill::ColorStop::r
uint8_t r
Definition: thorvg.h:316
tvg::PathCommand::MoveTo
Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the s...
tvg::Result::InsufficientCondition
The value returned in case the request cannot be processed - e.g. asking for properties of an object...
tvg::StrokeCap
StrokeCap
Enumeration determining the ending type of a stroke in the open sub-paths.
Definition: thorvg.h:98
tvg::CompositeMethod::ClipPath
The intersection of the source and the target is determined and only the resulting pixels from the so...
tvg::RadialGradient
A class representing the radial gradient fill of the Shape object.
Definition: thorvg.h:533
tvg::FillRule
FillRule
Enumeration specifying the algorithm used to establish which parts of the shape are treated as the in...
Definition: thorvg.h:128
tvg::Scene
A class to composite children paints.
Definition: thorvg.h:1063
tvg::Result::MemoryCorruption
The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting...
tvg::FillSpread::Reflect
The gradient pattern is reflected outside the gradient area until the expected region is filled...
tvg::FillSpread
FillSpread
Enumeration specifying how to fill the area outside the gradient bounds.
Definition: thorvg.h:118
tvg::Fill::ColorStop::a
uint8_t a
Definition: thorvg.h:319
tvg::Point
A data structure representing a point in two-dimensional space.
Definition: thorvg.h:158
tvg::Shape
A class representing two-dimensional figures and their properties.
Definition: thorvg.h:587
tvg::SwCanvas::Shareable
Memory Pool is shared among the SwCanvases.
Definition: thorvg.h:1143
tvg::CompositeMethod::None
No composition is applied.
tvg::FillRule::Winding
A line from the point to a location outside the shape is drawn. The intersections of the line with th...
tvg::CompositeMethod::InvAlphaMask
The pixels of the source and the complement to the target&#39;s pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible.
tvg::StrokeJoin
StrokeJoin
Enumeration determining the style used at the corners of joined stroked path segments.
Definition: thorvg.h:108
tvg::CanvasEngine::Gl
OpenGL rasterizer.
tvg
Definition: thorvg.h:52
tvg::Picture
A class representing an image read in one of the supported formats: raw, svg, png and etc...
Definition: thorvg.h:956
tvg::FillSpread::Pad
The remaining area is filled with the closest stop color.
tvg::CanvasEngine::Sw
CPU rasterizer.
tvg::PathCommand
PathCommand
Enumeration specifying the values of the path commands accepted by TVG.
Definition: thorvg.h:87
tvg::Result::InvalidArguments
The value returned in the event of a problem with the arguments given to the API - e...
tvg::Result::Success
The value returned in case of a correct request execution.
tvg::SwCanvas
A class for the rendering graphical elements with a software raster engine.
Definition: thorvg.h:1121
tvg::PathCommand::CubicTo
Draws a cubic Bezier curve from the current point to the given point using two given control points a...
tvg::StrokeCap::Butt
The stroke ends exactly at each of the two end-points of a sub-path. For zero length sub-paths no str...
tvg::FillSpread::Repeat
The gradient pattern is repeated continuously beyond the gradient area until the expected region is f...
tvg::SwCanvas::Colorspace
Colorspace
Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color...
Definition: thorvg.h:1129
tvg::GlCanvas
A class for the rendering graphic elements with a GL raster engine.
Definition: thorvg.h:1211
tvg::StrokeJoin::Bevel
The outer corner of the joined path segments is bevelled at the join point. The triangular region of ...
tvg::StrokeCap::Square
The stroke is extended in both end-points of a sub-path by a rectangle, with the width equal to the s...
tvg::Fill::ColorStop
A data structure storing the information about the color and its relative position inside the gradien...
Definition: thorvg.h:313
tvg::Fill::ColorStop::b
uint8_t b
Definition: thorvg.h:318
tvg::Result
Result
Enumeration specifying the result from the APIs.
Definition: thorvg.h:70
tvg::CompositeMethod
CompositeMethod
Enumeration indicating the method used in the composition of two objects - the target and the source...
Definition: thorvg.h:137
tvg::Paint
An abstract class for managing graphical elements.
Definition: thorvg.h:188
tvg::Result::NonSupport
The value returned in case of choosing unsupported options.
tvg::Canvas
An abstract class for drawing graphical elements.
Definition: thorvg.h:383
tvg::Fill::ColorStop::offset
float offset
Definition: thorvg.h:315
tvg::Fill::ColorStop::g
uint8_t g
Definition: thorvg.h:317
tvg::FillRule::EvenOdd
A line from the point to a location outside the shape is drawn and its intersections with the path se...
tvg::Matrix
A data structure representing a three-dimensional matrix.
Definition: thorvg.h:171
tvg::CanvasEngine
CanvasEngine
Enumeration specifying the engine type used for the graphics backend. For multiple backeneds bitwise ...
Definition: thorvg.h:148
tvg::StrokeJoin::Miter
The outer corner of the joined path segments is spiked. The spike is created by extension beyond the ...
tvg::LinearGradient
A class representing the linear gradient fill of the Shape object.
Definition: thorvg.h:479
tvg::Initializer
A class that enables initialization and termination of the TVG engines.
Definition: thorvg.h:1243