Donner provides several standalone APIs for core functionality which can be used in any project.
Each library has minimal dependencies and can be used in external projects. For example, the CSS API may be used to add CSS support to your project using an adapter that satisfies the donner::ElementLike concept.
flowchart TD SVG(SVG) CSS(CSS) Rendering(SVG Rendering) SVGParsing(SVG Parsing) XML(XML Parsing) SVG --> CSS Rendering --> SVG SVGParsing --> SVG SVGParsing --> XML
Callers can use if init-statements to check for success:
For example, the donner::ElementLike concept is used to make the CSS library usable without depending on the SVG library, or within a test context with FakeElement.
SVGDocument uses single-threaded access by default for the lowest overhead. Applications that need to inspect or mutate the same document from multiple threads can opt into concurrent DOM mode with SVGDocument::setThreadingMode().
For repeated reads or groups of writes, use the batching APIs: SVGDocument::withReadAccess() and SVGDocument::withWriteAccess(). Batching is more efficient because it keeps one access scope for the whole operation instead of entering document access for each individual DOM call.
See SVG DOM Threading And Lifetime for the full public behavior, including removed-element lifetime and rendering while the DOM is being modified.
To parse an SVG document, use the SVGParser class:
donner::ParseResult contains either the document or an error, which can be checked with hasError() and error():
donner::svg::parser::SVGParser::ParseSVG accepts a string containing SVG data.
Store the resulting donner::svg::SVGDocument to keep the document in memory, then inspect or modify it.
For example, to get the donner::svg::SVGPathElement for a <path> element:
donner::svg::SVGElement implements a DOM-like API for querying and modifying the SVG document.
The document tree is traversable with firstChild(), lastChild(), nextSibling(), and previousSibling(). The element's tag name can be retrieved with tagName().
Example iterating over children:
Every SVG element has its own DOM type:
To add a child to an element, use one of these methods:
To remove an element from the tree:
Removed elements stay valid while user code holds an SVGElement handle to them. Donner reclaims removed subtrees after public handles and in-progress renders no longer need them. See SVG DOM Threading And Lifetime for details.
To create an element, use the element-specific Create method:
To render an SVG document, use the donner::svg::Renderer class.
Renderer resolves to the backend selected at build time, either tiny_skia or Geode.
The output size comes from the donner::svg::SVGDocument. It is detected from the file itself, or overridden with these APIs:
The donner::svg::DonnerController class provides geometry-aware spatial queries on top of the DOM, for pointer interaction in a viewer or editor. All queries take a point in SVG canvas coordinates (the same space as the root <svg> element's viewBox) and honor pointer-events, visibility, display, paint-order, transforms, and per-shape fill/stroke geometry. They are independent of the active renderer.
hitTestLink implements the SVG enclosing-<a> semantics: a point over any descendant of an <a> resolves to that link, so the whole subtree of a link is clickable. Donner never navigates; it returns the link target verbatim (a raw href such as "#section", "../other.svg", or an absolute URL) and the embedding application resolves and follows it. The query is stateless rather than a navigation callback, so the application calls it from its own pointer events and uses the same call for a click (activate the link) and for hover (show a pointer cursor, a hover highlight, or a tooltip).
The CSS API is used internally within the SVG library, but can be used standalone.
To parse CSS stylesheets, style strings, or selectors, use the donner::css::CSS wrapper API.
donner::css::CSS::ParseStylesheet can parse a .css file into a Stylesheet, which contains a list of SelectorRule.
Selectors are available within a parsed stylesheet, or can be parsed from a string using donner::css::CSS::ParseSelector(std::string_view).
Use Selector::matches(const ElementLike& target) to see if a selector matches against a specific element. This can be repeatedly applied to all elements of a document to find all matches.