Thor Vector Graphics is a lightweight portable library used for drawing vector-based scenes and animations including SVG and Lottie. It can be freely utilized across various software platforms and applications to visualize graphical contents.
Find a file
Mira Grudzinska 286f700305 svg_loader: handling the ColorStop offset values
The ColorStop offset < 0 and > 1 should be treated as 0 and 1 respectively.
The offset value < than the previous offset value should be replaced
by the previous value - without this change segfault occurred.
Validating the APIs parameters values is the user responsibility.
2021-06-24 20:54:03 +09:00
.github/workflows infra CI: Upload unit test result to artifact 2021-06-17 21:50:13 +09:00
docs docs: fixed relative thorvg image path to the absolute one. 2021-05-25 15:31:07 +09:00
inc fix a build break in MSVC 2021-06-22 14:35:46 +09:00
pc renamed project name tizenvg => thorvg 2020-06-25 13:57:41 +09:00
res infra Documentation: Update main page and remove treeview 2021-05-25 15:15:51 +09:00
src svg_loader: handling the ColorStop offset values 2021-06-24 20:54:03 +09:00
test test Scene: Separate tests into SECTION() 2021-06-21 19:46:19 +09:00
tools/formats tools format: remove tizen specific 2020-12-25 20:06:26 +09:00
.gitignore capi: Added doxygen comments and doxygen config file. 2021-01-25 23:25:11 +09:00
.gitmodules infra Documentation: Introduce ThorVG documentation page. 2021-05-25 14:21:09 +09:00
AUTHORS updated AUTHORS 2021-03-09 20:20:43 +09:00
CONTRIBUTING.md Update CONTRIBUTING.md 2021-06-04 17:46:04 +09:00
LICENSE replace license from Apache 2.0 to MIT 2020-08-13 16:53:38 +09:00
meson.build infra: add memory sanitize option in meson 2021-06-23 11:55:52 +09:00
meson_options.txt tvg_loader: code refactoring. 2021-06-11 20:51:50 +09:00
README.md Update README.md 2021-05-22 16:14:12 +09:00
wasm_build.sh wasm: work with log option 2020-12-15 17:38:22 +09:00
wasm_cross.txt thorvg viewer: introduce thorvg viewer 2020-10-13 19:04:46 +09:00

Continuous-integration Gitter

ThorVG

ThorVG is a platform-independent portable library for drawing vector-based scene and animation. It's an open-source software that is freely used by a variety of software platforms and applications. ThorVG provides neat and easy APIs, its library has no dependencies and keeps cheat and super compact size. It serves as the vector graphics engine for Tizen OS that powers many products.

The following list shows primitives that are supported by ThorVG:

  • Shapes: Line, Arc, Curve, Path, Polygon, ...
  • Filling: Solid, Linear and Radial Gradient
  • Scene Graph & Affine Transformation (translation, rotation, scale, ...)
  • Stroking: Width, Join, Cap, Dash
  • Composition: Blending, Masking, Path Clipping, ...
  • Pictures: SVG, PNG, Bitmap, ...


Your program could call neat TVG APIs while switching drawing context If you have your own drawing engine. During the API calls, ThorVG serializes drawing commands among the volatile paints' nodes then performs synchronous/asynchronous rendering using own backend raster engines. ThorVG supports vector images such as SVG, also expand supporting other popular formats on demand. On the rendering, it could spawn intermediate frame-buffers for compositing scenes only when it's necessary. The next figure shows you a brief strategy on how to use ThorVG on your system.


Contents


Building ThorVG

ThorVG supports meson build system.

Meson Build

Install meson and ninja if not already installed.

Run meson to configure ThorVG:

meson build

Run ninja to build & install ThorVG:

ninja -C build install

Back to contents

Quick Start

ThorVG renders vector shapes to a given canvas buffer. The following is a quick start to show you how to use the basic APIs.

First, you should initialize the ThorVG engine:

tvg::Initializer::init(tvg::CanvasEngine::Sw, 0);   //engine method, thread count

Then you should prepare an empty canvas for drawing on it:

static uint32_t buffer[WIDTH * HEIGHT];                                 //canvas target buffer

auto canvas = tvg::SwCanvas::gen();                                     //generate a canvas
canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);  //buffer, stride, w, h, Colorspace

Next you can draw multiple shapes on the canvas:

auto rect = tvg::Shape::gen();               //generate a shape
rect->appendRect(50, 50, 200, 200, 20, 20);  //define it as a rounded rectangle (x, y, w, h, rx, ry)
rect->fill(100, 100, 100, 255);              //set its color (r, g, b, a)
canvas->push(move(rect));                    //push the rectangle into the canvas

auto circle = tvg::Shape::gen();             //generate a shape
circle->appendCircle(400, 400, 100, 100);    //define it as a circle (cx, cy, rx, ry)

auto fill = tvg::RadialGradient::gen();      //generate a radial gradient
fill->radial(400, 400, 150);                 //set the radial gradient geometry info (cx, cy, radius)

tvg::Fill::ColorStop colorStops[2];          //gradient colors
colorStops[0] = {0.0, 255, 255, 255, 255};   //1st color values (offset, r, g, b, a)
colorStops[1] = {1.0, 0, 0, 0, 255};         //2nd color values (offset, r, g, b, a)
fill->colorStops(colorStops, 2);             //set the gradient colors info

circle->fill(move(fill));                    //set the circle fill
canvas->push(move(circle));                  //push the circle into the canvas

This code generates the following result:

You can also draw you own shapes and use dashed stroking:

auto path = tvg::Shape::gen();               //generate a path
path->moveTo(199, 34);                       //set sequential path coordinates
path->lineTo(253, 143);
path->lineTo(374, 160);
path->lineTo(287, 244);
path->lineTo(307, 365);
path->lineTo(199, 309);
path->lineTo(97, 365);
path->lineTo(112, 245);
path->lineTo(26, 161);
path->lineTo(146, 143);
path->close();

path->fill(150, 150, 255, 255);              //path color

path->stroke(3);                             //stroke width
path->stroke(0, 0, 255, 255);                //stroke color
path->stroke(tvg::StrokeJoin::Round);        //stroke join style
path->stroke(tvg::StrokeCap::Round);         //stroke cap style

float pattern[2] = {10, 10};                 //stroke dash pattern (line, gap)
path->stroke(pattern, 2);                    //set the stroke pattern

canvas->push(move(path));                    //push the path into the canvas

The code generates the following result:

Now begin rendering & finish it at a particular time:

canvas->draw();
canvas->sync();

Then you can acquire the rendered image from the buffer memory.

Lastly, terminate the engine after its usage:

tvg::Initializer::term(tvg::CanvasEngine::Sw);

Back to contents

SVG

ThorVG supports SVG (Scalable Vector Graphics) rendering through its own SVG interpreter. It satisfies the SVG Tiny Specification in order to keep it lightweight, so it's useful for the embedded systems. Among the SVG Tiny specs, unsupported features in the ThorVG are the following:

  • Animation
  • Fonts & Text
  • Interactivity
  • Multimedia
  • Scripting

The following code snippet shows how to draw SVG image using ThorVG:

auto picture = tvg::Picture::gen();         //generate a picture
picture->load("tiger.svg");                 //load SVG file
canvas->push(move(picture));                //push the picture into the canvas

The result:

Back to contents

Practices

Tizen

ThorVG is integrated into the Tizen platform as the vector graphics engine. It's being used for vector primitive drawings and scalable image contents such as SVG and Lottie Animation among the Tizen powered products.

Back to contents

Rive

We're also building a Rive port which supports Rive Animation run through the ThorVG backend. Rive is a brand new animation platform that supports fancy, user interactive vector animations. For more details see Rive-Tizen on Github.

Back to contents

Examples

There are various examples available in thorvg/src/examples, to help you understand ThorVG APIs.

To execute these examples, you can build them with the following meson option:

meson -Dexamples=true . build

Note that these examples require the EFL elementary package for launching. If you're using Linux-based OS, you can easily install this package from your OS distribution server. Otherwise, please visit the official EFL page for more information.

Back to contents

Tools

ThorVG Viewer

ThorVG viewer supports immediate rendering through your browser. You can drag & drop SVG files on the page and see the rendering result on the spot.

Back to contents

SVG to PNG

ThorVG provides an executable svg2png converter which generates a PNG file from an SVG file.

To use svg2png, you must turn on this feature in the build option:

meson -Dtools=svg2png . build

Alternatively, you can add the svg2png value to the tools option in meson_option.txt. The build output will be located in {builddir}/src/bin/svg2png/.

Examples of the usage of the svg2png:

Usage:
   svg2png [svgFileName] [Resolution] [bgColor]

Examples:
    $ svg2png input.svg
    $ svg2png input.svg 200x200
    $ svg2png input.svg 200x200 ff00ff

Back to contents

API Bindings

Our main development APIs are written in C++ but ThorVG also provides API bindings for C.

Back to contents

Issues or Feature Requests

For support please reach us in Gitter.