|
|
Donner
C++20 SVG rendering library
|
Represents an SVG document, which holds a collection of SVGElement as the document tree. More...
#include "donner/svg/SVGDocument.h"
Classes | |
| struct | Settings |
| Document settings which configure the document behavior. More... | |
Public Member Functions | |
| SVGDocument (Settings settings=Settings()) | |
| Constructor to create an empty SVGDocument. | |
| Registry & | registry () |
| Get the underlying ECS Registry, which holds all data for the document, for advanced use. | |
| const Registry & | registry () const |
| Get the underlying ECS Registry, which holds all data for the document, for advanced use. | |
| EntityHandle | rootEntityHandle () const |
| Get the root ECS Entity of the document, for advanced use. | |
| SVGSVGElement | svgElement () const |
| Get the root "<svg>" element of the document. | |
| void | setCanvasSize (int width, int height) |
| Set the canvas size to a fixed width and height, in pixels. | |
| void | useAutomaticCanvasSize () |
| Automatically determine the canvas size based on the size of the root "<svg>" element. | |
| Vector2i | canvasSize () const |
| Get the current canvas size, or the default size (512x512) if the canvas size has not been explicitly set. | |
| int | width () const |
| Get the width of the SVG document, in pixels. | |
| int | height () const |
| Get the height of the SVG document, in pixels. | |
| Transformd | documentFromCanvasTransform () const |
| Get the scale transform from the canvas to the SVG document. | |
| bool | operator== (const SVGDocument &other) const |
| Returns true if the two SVGDocument handles reference the same underlying document. | |
| std::optional< SVGElement > | querySelector (std::string_view selector) |
| Find the first element in the tree that matches the given CSS selector. | |
Friends | |
| class | SVGElement |
| class | parser::SVGParserImpl |
Represents an SVG document, which holds a collection of SVGElement as the document tree.
Each SVGElement may only belong to a single document, and each document can have only one root. SVGDocument is responsible for managing the lifetime of all elements in the document, by storing a shared pointer to the internal Registry data-store.
Data is stored using the Entity Component System (Entity Component System (ECS)) pattern, which is a data-oriented design optimized for fast data access and cache locality, particularly during rendering.
SVGDocument and SVGElement provide a facade over the ECS, and surface a familiar Document Object Model (DOM) API to traverse and manipulate the document tree, which is internally stored within Components in the ECS. This makes SVGElement a thin wrapper around an Entity, making the object lightweight and usable on the stack.
| struct donner::svg::SVGDocument::Settings |
Document settings which configure the document behavior.
| Class Members | ||
|---|---|---|
| unique_ptr< ResourceLoaderInterface > | resourceLoader | Resource loader to use for loading external resources. |
Constructor to create an empty SVGDocument.
To load a document from an SVG file, use donner::svg::parser::SVGParser::ParseSVG.
| settings | Settings to configure the document. |
|
inline |
Get the height of the SVG document, in pixels.
This is the height of the canvas, which may be different from the height of the SVG content.
| std::optional< SVGElement > donner::svg::SVGDocument::querySelector | ( | std::string_view | selector | ) |
Find the first element in the tree that matches the given CSS selector.
Complex selectors are supported:
| selector | CSS selector to match. |
| void donner::svg::SVGDocument::setCanvasSize | ( | int | width, |
| int | height ) |
Set the canvas size to a fixed width and height, in pixels.
| width | Width of the canvas, in pixels. |
| height | Height of the canvas, in pixels. |
|
inline |
Get the width of the SVG document, in pixels.
This is the width of the canvas, which may be different from the width of the SVG content.