### Install ThorVG with vcpkg Source: https://www.thorvg.org/docs/tutorial Installs ThorVG using the vcpkg package manager. This involves cloning the vcpkg repository, bootstrapping it, and then installing the ThorVG package. ```bash git clone https://github.com/Microsoft/vcpkg.git ./bootstrap-vcpkg.sh ./vcpkg install thorvg ``` -------------------------------- ### Create and Setup Software Canvas Source: https://context7.com/context7/thorvg/llms.txt Sets up a software canvas for rendering and binds it to a target buffer. This example uses a static array as the buffer and specifies the ARGB8888 color format. The canvas handles drawing operations and requires a call to draw() and sync() to render. Ensure tvg::Initializer::init() is called beforehand and tvg::Initializer::term() afterwards. ```cpp #include #define WIDTH 800 #define HEIGHT 600 int main() { tvg::Initializer::init(0); // Allocate a target buffer (ARGB format) static uint32_t buffer[WIDTH * HEIGHT]; // Create a software canvas auto canvas = tvg::SwCanvas::gen(); // Bind the canvas to the buffer // Parameters: buffer pointer, stride, width, height, color format canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::ColorSpace::ARGB8888); // Canvas is ready for drawing operations canvas->draw(); canvas->sync(); tvg::Initializer::term(); return 0; } ``` -------------------------------- ### Install ThorVG with MSYS2 Source: https://www.thorvg.org/docs/tutorial Installs ThorVG using the MSYS2 package manager. This requires MSYS2 to be installed and configured, then the ThorVG package can be installed via pacman. ```bash pacman -S thorvg ``` -------------------------------- ### Build ThorVG with Meson and Ninja Source: https://www.thorvg.org/docs/tutorial Configures and builds ThorVG using the meson build system and ninja. This process generates build artifacts in a specified directory. Ensure meson and ninja are installed prior to execution. ```bash meson setup builddir ninja -C builddir install ``` -------------------------------- ### Install ThorVG with Conan Source: https://www.thorvg.org/docs/tutorial Installs ThorVG using the Conan package manager. This command requires Conan to be set up on the system and will install the ThorVG package and its dependencies. ```bash conan install --requires="thorvg/[*]" --build=missing ``` -------------------------------- ### Setup ThorVG Canvas Target Source: https://www.thorvg.org/docs/tutorial Prepares a canvas buffer for ThorVG rendering. This involves generating a SwCanvas, and then setting its target buffer, stride, dimensions, and color space. The buffer must be allocated with sufficient memory for the specified width and height. ```cpp #include #include // Define WIDTH and HEIGHT appropriately for your application // static uint32_t buffer[WIDTH * HEIGHT]; // Generate a canvas // auto canvas = tvg::SwCanvas::gen(); // Setup the canvas target // canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::ColorSpace::ARGB8888); ``` -------------------------------- ### Render Text with Fonts and Gradients in C++ Source: https://context7.com/context7/thorvg/llms.txt Provides an example of rendering Unicode text using TrueType fonts. It covers creating text with solid colors and applying linear gradients for fills, supporting horizontal layout and proper glyph metrics. Requires ThorVG and a TrueType font file. ```cpp #include void renderText(tvg.SwCanvas* canvas) { // Load global font (shared across all text objects) tvg.Text::load("/path/to/arial.ttf"); // Create solid color text auto text = tvg.Text::gen(); text->font("Arial"); text->font(50); // Font size text->text("ThorVG Solid Text"); text->fill(0, 0, 0); // Black color text->translate(150, 150); canvas->push(text); // Create gradient text auto gradientText = tvg.Text::gen(); gradientText->font("Arial"); gradientText->font(50); gradientText->text("ThorVG Gradient Text"); // Get text bounds for gradient float x, y, w, h; gradientText->bounds(&x, &y, &w, &h); // Apply linear gradient auto fill = tvg.LinearGradient::gen(); fill->linear(x, y + h * 0.5f, x + w, y + h * 0.5f); tvg.Fill.ColorStop colorStops[2]; colorStops[0] = {0.0, 255, 0, 0, 255}; colorStops[1] = {1.0, 255, 255, 0, 255}; fill->colorStops(colorStops, 2); gradientText->fill(std::move(fill)); gradientText->translate(150, 250); canvas->push(gradientText); canvas->draw(); canvas->sync(); // Manually unload font if needed tvg.Text::unload("/path/to/arial.ttf"); } ``` -------------------------------- ### Apply Alpha Masking to Pictures in C++ Source: https://context7.com/context7/thorvg/llms.txt Demonstrates how to apply visual effects like alpha masking to composite graphics. This example shows masking a picture using a shape. Requires the ThorVG library. ```cpp #include void applyMask(tvg.SwCanvas* canvas) { // Load a picture auto picture = tvg.Picture::gen(); picture->load("/path/to/logo.svg"); // Create circular mask auto mask = tvg.Shape::gen(); mask->appendCircle(250, 325, 225, 225); mask->fill(255, 255, 255, 255); // Apply alpha mask to picture picture->mask(std::move(mask), tvg.MaskMethod::Alpha); canvas->push(picture); canvas->draw(); canvas->sync(); } ``` -------------------------------- ### Draw Custom Vector Paths Source: https://context7.com/context7/thorvg/llms.txt Illustrates how to define arbitrary vector shapes using path commands like `moveTo`, `lineTo`, and `close`. This example creates a star shape by specifying its vertices. The path can then be filled with a color and pushed onto the canvas for rendering. The `drawCustomPath` function takes a `tvg::SwCanvas*` and performs these operations. ```cpp #include void drawCustomPath(tvg::SwCanvas* canvas) { // Create a star shape using path commands auto star = tvg::Shape::gen(); // Define star vertices star->moveTo(199, 34); star->lineTo(253, 143); star->lineTo(374, 160); star->lineTo(287, 244); star->lineTo(307, 365); star->lineTo(199, 309); star->lineTo(97, 365); star->lineTo(112, 245); star->lineTo(26, 161); star->lineTo(146, 143); star->close(); // Fill with color star->fill(150, 150, 255); canvas->push(star); canvas->draw(); canvas->sync(); } ``` -------------------------------- ### Initialize ThorVG Engine Source: https://www.thorvg.org/docs/tutorial Initializes the ThorVG engine, preparing it for rendering operations. The first parameter is reserved, and the second parameter specifies the number of threads to use for ThorVG tasks. Using std::thread::hardware_concurrency() is recommended if the exact number is unknown. ```cpp #include // Initialize the ThorVG engine tvg::Initializer::init(0); ``` -------------------------------- ### Configure Visual Studio Project Files with Meson Source: https://www.thorvg.org/docs/tutorial Generates Visual Studio project files for ThorVG using the meson build system with the '--backend=vs' option. The solution file will be located in the build directory. ```bash meson setup builddir --backend=vs ``` -------------------------------- ### Play and Control Lottie Animations with ThorVG Source: https://context7.com/context7/thorvg/llms.txt Demonstrates how to load and control Lottie animations frame-by-frame using ThorVG's Animation API. It requires a tvg::SwCanvas and a Lottie file. The output is the rendered animation frame by frame on the canvas. ```cpp #include void playAnimation(tvg.SwCanvas* canvas) { // Create animation and get associated picture auto animation = tvg.Animation::gen(); auto picture = animation->picture(); // Load Lottie file if (picture->load("/path/to/animation.json") == tvg.Result::Success) { canvas->push(picture); // Get animation properties float duration = animation->duration(); // Total duration in seconds float totalFrames = animation->totalFrame(); // Animation loop for (float progress = 0.0f; progress <= 1.0f; progress += 0.016f) { // Set current frame (0 to totalFrames) animation->frame(totalFrames * progress); // Update canvas with new frame canvas->update(picture); canvas->draw(); canvas->sync(); // Delay for frame timing (e.g., 60 FPS = ~16ms) } } } ``` -------------------------------- ### Configure Xcode Project Files with Meson Source: https://www.thorvg.org/docs/tutorial Generates Xcode project files for ThorVG using the meson build system with the '--backend=xcode' option. The project file will be located in the build directory. ```bash meson setup builddir --backend=xcode ``` -------------------------------- ### Load and Render Images in C++ Source: https://context7.com/context7/thorvg/llms.txt Illustrates how to load and display both vector (SVG) and bitmap (PNG) images. The code demonstrates applying transformations such as resizing and positioning to the loaded pictures. Requires the ThorVG library. ```cpp #include void loadImages(tvg.SwCanvas* canvas) { // Load SVG file auto svg = tvg.Picture::gen(); if (svg->load("/path/to/logo.svg") == tvg.Result::Success) { svg->translate(50, 50); canvas->push(svg); } // Load PNG file with custom size auto png = tvg.Picture::gen(); if (png->load("/path/to/image.png") == tvg.Result::Success) { png->size(300, 300); // Resize to 300x300 png->translate(400, 400); canvas->push(png); } canvas->draw(); canvas->sync(); } ``` -------------------------------- ### Load and Display Pictures in ThorVG Source: https://www.thorvg.org/docs/tutorial Illustrates how to load and render image data using ThorVG's Picture node. Supports various formats like SVG and PNG. The 'load()' method is used to specify the image file, and 'size()' and 'translate()' can be used to control its dimensions and position on the canvas before pushing it. ```cpp auto svg = tvg::Picture::gen(); svg->load("logo.svg"); canvas->push(svg); auto png = tvg::Picture::gen(); png->load("parrots.png"); png->size(300, 300); png->translate(150, 150); canvas->push(png); ``` -------------------------------- ### Draw and Synchronize Canvas in ThorVG Source: https://www.thorvg.org/docs/tutorial This C++ snippet illustrates the final steps of rendering in ThorVG. It includes drawing the canvas content and synchronizing to ensure all asynchronous tasks are completed before proceeding. ```cpp canvas->draw(); canvas->sync(); ``` -------------------------------- ### Initialize ThorVG Engine with Threading Source: https://context7.com/context7/thorvg/llms.txt Initializes the ThorVG engine, enabling threading for parallel task execution. It's recommended to use std::thread::hardware_concurrency() for optimal performance. The function returns a tvg::Result indicating success or failure. Remember to call tvg::Initializer::term() for cleanup. ```cpp #include #include int main() { // Initialize with maximum hardware threads uint32_t threadCount = std::thread::hardware_concurrency(); tvg::Result result = tvg::Initializer::init(threadCount); if (result != tvg::Result::Success) { return -1; } // Your rendering code here // Cleanup when done tvg::Initializer::term(); return 0; } ``` -------------------------------- ### Control Lottie Animation Playback in ThorVG Source: https://www.thorvg.org/docs/tutorial This C++ snippet shows how to load and control a Lottie animation using ThorVG. It covers generating an animation object, loading a JSON file, setting specific frames based on progress, and updating the canvas. ```cpp // Generate an animation auto animation = tvg::Animation::gen(); // Acquire a picture which associated with the animation auto picture = animation->picture(); // Load an animation file. picture->load("lottie.json"); // Figure out the animation duration time in seconds auto duration = animation->duration(); // Push the picture into the canvas canvas->push(picture); // Set a current animation frame to display animation->frame(animation->totalFrame() * progress); // Update the picture to be redrawn canvas->update(animation->picture()); ``` -------------------------------- ### Build and Transform a ThorVG Scene Source: https://www.thorvg.org/docs/tutorial Demonstrates creating a scene graph by composing shapes (round rectangle, circle, ellipse) and then applying transformations (translate, scale, rotate) to the entire scene. Shapes are defined by their dimensions and fill colors, and can be added to a scene using the push() method. The scene itself can then be pushed onto a canvas. ```cpp auto scene = tvg::Scene::gen(); auto rect = tvg::Shape::gen(); rect->appendRect(-235, -250, 400, 400, 50, 50); rect->fill(0, 255, 0); scene->push(rect); auto circle = tvg::Shape::gen(); circle->appendCircle(-165, -150, 200, 200); circle->fill(255, 255, 0, 127); scene->push(circle); auto ellipse = tvg::Shape::gen(); ellipse->appendCircle(265, 250, 150, 100); ellipse->fill(0, 255, 255); scene->push(ellipse); scene->translate(350, 350); scene->scale(0.5); scene->rotate(45); canvas->push(scene); ``` -------------------------------- ### Render Solid Color Text in ThorVG Source: https://www.thorvg.org/docs/tutorial Shows how to render basic text with a solid fill color. Requires loading a font file globally using Text::load(). Text objects are generated using tvg::Text::gen(), with properties like font name, size, text content, and fill color set using respective methods. The text is then positioned and pushed onto the canvas. ```cpp Text::load(EXAMPLE_DIR"/arial.ttf"); auto text = tvg::Text::gen(); text->font("Arial"); text->size(50); text->text("ThorVG Solid Text"); text->fill(0, 0, 0); text->translate(150, 150); canvas->push(text); ``` -------------------------------- ### Create Scene Graphs with Transformations in C++ Source: https://context7.com/context7/thorvg/llms.txt Shows how to organize multiple graphical objects into a hierarchical scene graph. Transformations like translate, scale, and rotate can be applied to the entire scene. This requires the ThorVG library. ```cpp #include void drawScene(tvg.SwCanvas* canvas) { // Create a scene container auto scene = tvg.Scene::gen(); // Add shapes to the scene auto rect = tvg.Shape::gen(); rect->appendRect(-235, -250, 400, 400, 50, 50); rect->fill(0, 255, 0); scene->push(rect); auto circle = tvg.Shape::gen(); circle->appendCircle(-165, -150, 200, 200); circle->fill(255, 255, 0, 127); scene->push(circle); auto ellipse = tvg.Shape::gen(); ellipse->appendCircle(265, 250, 150, 100); ellipse->fill(0, 255, 255); scene->push(ellipse); // Transform the entire scene scene->translate(350, 350); scene->scale(0.5); scene->rotate(45); // degrees canvas->push(scene); canvas->draw(); canvas->sync(); } ``` -------------------------------- ### Render and Synchronize Canvas Operations with ThorVG Source: https://context7.com/context7/thorvg/llms.txt Illustrates the draw/sync pattern in ThorVG for rendering operations and synchronizing them for completed output. This ensures all asynchronous tasks are finished before accessing the buffer. It requires a tvg::SwCanvas and a buffer to store the rendered image. ```cpp #include void renderComplete(tvg.SwCanvas* canvas, uint32_t* buffer) { // Push all paints to canvas first auto shape = tvg.Shape::gen(); shape->appendRect(0, 0, 100, 100); shape->fill(255, 0, 0); canvas->push(shape); // Initiate rendering (async preprocessing) canvas->draw(); // Wait for completion (synchronization point) canvas->sync(); // Buffer now contains completed image // You can now read buffer data or display it // Clear canvas for next frame canvas->clear(); } ``` -------------------------------- ### Render Gradient Color Text in ThorVG Source: https://www.thorvg.org/docs/tutorial Demonstrates rendering text with a linear gradient fill. This involves generating a tvg::Text object, obtaining its bounds, creating a tvg::LinearGradient object, defining color stops for the gradient, and then applying this gradient to the text's fill. Font loading and canvas pushing are similar to solid color text. ```cpp auto text2 = tvg::Text::gen(); text2->font("Arial"); text2->font(50); text2->text("ThorVG Gradient Text"); float x, y, w, h; text2->bounds(&x, &y, &w, &h); auto fill = tvg::LinearGradient::gen(); fill->linear(x, y + h * 0.5f, x + w, y + h * 0.5f); tvg::Fill::ColorStop colorStops[2]; colorStops[0] = {0.0, 255, 0, 0, 0}; colorStops[1] = {1.0, 255, 255, 0, 255}; fill->colorStops(colorStops, 2); text2->fill(fill); text2->translate(150, 250); canvas->push(text2); ``` -------------------------------- ### Define Custom Shape using Path (C++) Source: https://www.thorvg.org/docs/tutorial Illustrates defining an arbitrary shape using a sequence of path commands such as moveTo, lineTo, and close. The resulting path-defined shape is then filled with a specific color and added to the canvas. This is useful for creating complex and custom vector forms. ```cpp auto path = tvg.Shape::gen(); path->moveTo(199, 34); 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); canvas->push(path); ``` -------------------------------- ### Configure Shape Strokes in C++ Source: https://context7.com/context7/thorvg/llms.txt Demonstrates how to add outlines to shapes using customizable width, cap style, join style, and dash patterns. Strokes can be filled with solid colors or gradients. This function requires the ThorVG library. ```cpp #include void drawStroke(tvg.SwCanvas* canvas) { // Create a rounded rectangle with stroke auto rect = tvg.Shape::gen(); rect->appendRect(50, 50, 200, 200, 20, 20); rect->fill(100, 100, 100); // Configure stroke properties rect->strokeWidth(4); rect->strokeFill(50, 50, 50); // Stroke color rect->strokeJoin(tvg.StrokeJoin::Round); rect->strokeCap(tvg.StrokeCap::Round); // Set dash pattern (line length, gap length) float pattern[2] = {7, 10}; rect->strokeDash(pattern, 2); canvas->push(rect); canvas->draw(); canvas->sync(); } ``` -------------------------------- ### Append Circle Shape with Radial Gradient Fill (C++) Source: https://www.thorvg.org/docs/tutorial Shows how to create a circle shape and apply a radial gradient as its fill. The radial gradient is defined with its center, radius, and color stops. This allows for visually rich shapes with smooth color transitions. ```cpp auto circle = tvg.Shape::gen(); circle->appendCircle(400, 400, 100, 100); auto fill = tvg.RadialGradient::gen(); fill->radial(400, 400, 150); tvg.Fill.ColorStop colorStops[2]; colorStops[0] = {0.0, 255, 255, 255, 255}; colorStops[1] = {1.0, 0, 0, 0, 255}; fill->colorStops(colorStops, 2); circle->fill(fill); canvas->push(circle); ``` -------------------------------- ### Generate and Append Rounded Rectangle Shape (C++) Source: https://www.thorvg.org/docs/tutorial Demonstrates generating a shape and appending a rounded rectangle with specified dimensions and corner radii. The shape is then filled with a solid color and pushed to the canvas. This showcases basic shape creation and manipulation. ```cpp auto rect = tvg.Shape::gen(); rect->appendRect(50, 50, 200, 200, 20, 20); rect->fill(100, 100, 100); canvas->push(rect); ``` -------------------------------- ### Draw Basic Shapes (Rectangle and Circle) Source: https://context7.com/context7/thorvg/llms.txt Demonstrates drawing basic geometric shapes like rounded rectangles and circles using the tvg::Shape API. Shapes can be filled with solid colors (RGB or RGBA) and added to the canvas for rendering. The function `drawShapes` takes a tvg::SwCanvas pointer and pushes the created shapes onto it before calling draw() and sync(). ```cpp #include void drawShapes(tvg::SwCanvas* canvas) { // Create a rounded rectangle auto rect = tvg::Shape::gen(); rect->appendRect(50, 50, 200, 200, 20, 20); // x, y, w, h, rx, ry rect->fill(100, 100, 100); // RGB color canvas->push(rect); // Create a circle auto circle = tvg::Shape::gen(); circle->appendCircle(400, 300, 100, 100); // cx, cy, radiusX, radiusY circle->fill(255, 0, 0, 200); // RGBA with transparency canvas->push(circle); // Render all shapes canvas->draw(); canvas->sync(); } ``` -------------------------------- ### Append Rectangle Shape with Stroke Properties (C++) Source: https://www.thorvg.org/docs/tutorial Demonstrates adding stroke properties to a shape, including width, color, cap style, join style, and a dash pattern. A rounded rectangle is created, filled with a solid color, and then its outline is styled before being pushed to the canvas. ```cpp auto rect = tvg.Shape::gen(); rect->appendRect(50, 50, 200, 200, 20, 20); rect->fill(100, 100, 100); rect->strokeWidth(4); rect->strokeFill(50, 50, 50); rect->strokeJoin(tvg.StrokeJoin.Round); rect->strokeCap(tvg.StrokeCap.Round); float pattern[2] = {7, 10}; rect->strokeDash(pattern, 2); canvas->push(rect); ``` -------------------------------- ### Apply Mask to SVG Picture in ThorVG Source: https://www.thorvg.org/docs/tutorial This C++ snippet demonstrates how to load an SVG picture and apply a circular mask to it using ThorVG. It involves generating a picture object, loading an SVG, creating a shape for the mask, and applying it with alpha blending. ```cpp // Generate a picture auto picture = tvg::Picture::gen(); picture->load(EXAMPLE_DIR"/logo.svg"); // Generate a circle for masking auto mask = tvg::Shape::gen(); mask->appendCircle(250, 325, 225, 225); mask->fill(255, 255, 255, 255); // Set the circle's alpha mask to the picture picture->mask(mask, tvg::MaskMethod::Alpha); // Push the picture into the canvas canvas->push(picture); ``` -------------------------------- ### Apply Radial Gradients to Shapes Source: https://context7.com/context7/thorvg/llms.txt Shows how to apply a radial gradient fill to a shape, in this case, a circle. The `tvg::RadialGradient::gen()` creates the gradient object, and its `radial()` method defines the center and radius. Color stops are specified with their offset and RGBA values, allowing for smooth color transitions. The completed gradient is then applied to the shape's fill. ```cpp #include void drawGradient(tvg::SwCanvas* canvas) { // Create a circle for radial gradient auto circle = tvg::Shape::gen(); circle->appendCircle(400, 400, 100, 100); // Create radial gradient auto fill = tvg::RadialGradient::gen(); fill->radial(400, 400, 150); // cx, cy, radius // Define color stops tvg::Fill::ColorStop colorStops[3]; colorStops[0] = {0.0, 255, 255, 255, 255}; // offset, r, g, b, a (white) colorStops[1] = {0.5, 255, 0, 0, 255}; // red at midpoint colorStops[2] = {1.0, 0, 0, 0, 255}; // black at edge fill->colorStops(colorStops, 3); circle->fill(std::move(fill)); canvas->push(circle); canvas->draw(); canvas->sync(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.