Represents a parsed SVG document containing a tree of SVGElement nodes.
More...
#include "donner/svg/SVGDocument.h"
|
| struct | Settings |
| | Document settings which configure the document behavior. More...
|
|
|
| SVGDocument () |
| | Constructor to create an empty SVGDocument with default settings.
|
| | SVGDocument (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.
|
| SVGDocumentHandle | handle () const |
| | Get the internal shared document handle used by this value facade.
|
|
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 (output image) size to a fixed width and height, in pixels.
|
| void | useAutomaticCanvasSize () |
| | Automatically determine the canvas size from the root <svg> element's width and height attributes.
|
|
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.
|
|
Transform2d | 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.
|
|
|
class | SVGElement |
|
class | parser::SVGParserImpl |
Represents a parsed SVG document containing a tree of SVGElement nodes.
To create a document, parse SVG content with donner::svg::parser::SVGParser::ParseSVG, or construct an empty document and build the tree programmatically. Access the root <svg> element with svgElement(), find elements with querySelector(), and render with Renderer.
SVGDocument and SVGElement expose a familiar DOM API for traversal and manipulation (e.g., firstChild(), appendChild(), querySelector()). Elements are lightweight value types that can be copied and passed on the stack.
SVGDocument is not thread-safe — do not access the same document from multiple threads concurrently.
- Note
- Internally, data is stored using an Entity Component System (ECS) for cache-friendly access during rendering. The registry() and entityHandle() accessors expose this for advanced use cases, but most users can ignore the ECS layer entirely.
- See also
- SVGElement
- Examples
- svg_filter_interaction.cc, svg_text_interaction.cc, and svg_to_png.cc.
◆ SVGDocument::Settings
| struct SVGDocument::Settings |
Document settings which configure the document behavior.
| Class Members |
|
ProcessingMode |
processingMode = ProcessingMode::DynamicInteractive |
Processing mode for this document. Defaults to ProcessingMode::DynamicInteractive. |
|
unique_ptr< ResourceLoaderInterface > |
resourceLoader |
Resource loader to use for loading external resources. |
|
SvgParseCallback |
svgParseCallback |
Callback to parse SVG content into sub-documents. |
◆ SvgParseCallback
| using donner::svg::SVGDocument::SvgParseCallback |
Initial value: std::function<std::optional<SVGDocumentHandle>(
const std::vector<uint8_t>& svgContent, ParseWarningSink& warningSink)>
◆ SVGDocument()
| donner::svg::SVGDocument::SVGDocument |
( |
Settings | settings | ) |
|
|
explicit |
◆ CreateFromHandle()
Rehydrate an SVGDocument facade from an internal shared document handle.
- Parameters
-
| handle | Shared document-state handle to wrap. |
- Returns
- A new SVGDocument facade referencing the same underlying document state.
◆ handle()
Get the internal shared document handle used by this value facade.
- Returns
- Shared document-state handle backing this SVGDocument.
◆ height()
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.
◆ querySelector()
Find the first element in the tree that matches the given CSS selector.
auto element = document.querySelector("#elementId");
Complex selectors are supported:
auto element = document.querySelector("svg > g:nth-child(2) > rect");
- Parameters
-
| selector | CSS selector to match. |
- Returns
- The first matching element, or std::nullopt if no element matches.
- Examples
- svg_filter_interaction.cc, and svg_text_interaction.cc.
◆ setCanvasSize()
Set the canvas (output image) size to a fixed width and height, in pixels.
This controls the rendered output dimensions and may differ from the SVG's viewBox. If not set, defaults to 512x512 or the size specified by the root <svg> element's width/height attributes (when using useAutomaticCanvasSize()).
- Parameters
-
| width | Width of the canvas, in pixels. |
| height | Height of the canvas, in pixels. |
- Examples
- svg_to_png.cc.
◆ useAutomaticCanvasSize()
Automatically determine the canvas size from the root <svg> element's width and height attributes.
If those attributes are not set, falls back to the default size (512x512).
◆ width()
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.
The documentation for this class was generated from the following files: