Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg Namespace Reference

Donner SVG library, which can load, manipulate and render SVG files. More...

Namespaces

namespace  components
 Contains the implementation of the Donner ECS,.
 
namespace  parser
 Parsers for the SVG XML format, SVGParser, as well as individual parsers for SVG components, such as PathParser and TransformParser.
 

Classes

struct  AsciiImage
 Stores an ASCII representation of a rendered image, and supports diffing it to another image. More...
 
class  CssTransform
 Compared to an SVG transform, CSS transforms have additional features, such as the ability to add units to the translate() function, such as translate(1em 30px). More...
 
class  DonnerController
 Allows querying and controlling the Donner scene, beyond what the DOM provides. More...
 
struct  FilterEffect
 Filter effect container, which can contain a reference to another filter effect, or a filter effect itself (of any type). More...
 
struct  GradientStop
 Values for a gradient stop, https://www.w3.org/TR/SVG2/pservers.html#StopElement. More...
 
struct  Image
 Stores an uncompressed RGBA-format image. More...
 
struct  ImageComparisonParams
 
struct  ImageComparisonTestcase
 
class  ImageComparisonTestFixture
 
class  ImageLoader
 Utility class for loading images from a URI. More...
 
struct  ImageResource
 
struct  MarkerOrient
 Represents the orientation of a marker. More...
 
struct  PaintServer
 Represents a paint server, which can be a solid color, a reference to another element, or a special value like "none" or "context-fill". More...
 
struct  ParsedFragment
 
class  PathSpline
 Container for a spline, which is a series of points connected by lines and curves. More...
 
class  PreserveAspectRatio
 Handles SVG's preserveAspectRatio attribute. More...
 
struct  Property
 Holds a CSS property, which has a name and value, and integrates with inheritance to allow cascading values using the CSS model with specificity. More...
 
class  PropertyRegistry
 Holds CSS properties for a single element. More...
 
struct  RecursionGuard
 Helper to guard against recursion when evaluating references. More...
 
struct  Reference
 Represents a reference to an SVG entity by its href, typically created from a url(#id) string. More...
 
class  RendererImageIO
 Utility class for saving images to disk. More...
 
class  RendererSkia
 Rendering backend using Skia, https://github.com/google/skia. More...
 
class  RendererTestUtils
 Test utilities for rendering and saving SVGs in tests. More...
 
class  RendererUtils
 Utility functions for the renderer. More...
 
class  RendererWasmCanvas
 
struct  RenderingInstanceView
 A view containing a list of components::RenderingInstanceComponent which can be iterated over. More...
 
struct  ResolvedReference
 Represents a resolved reference to an SVG entity. More...
 
class  ResourceLoaderInterface
 Interface for loading external resources, such as images. More...
 
class  SandboxedFileResourceLoader
 Interface for loading external resources, such as images. More...
 
class  SVGCircleElement
 DOM object for a "<circle>" element. More...
 
class  SVGClipPathElement
 DOM object for a "<clipPath>" element. More...
 
class  SVGDefsElement
 DOM object for a "<defs>" element. More...
 
class  SVGDocument
 Represents an SVG document, which holds a collection of SVGElement as the document tree. More...
 
class  SVGElement
 Represents an SVG entity belonging to an SVGDocument. More...
 
class  SVGEllipseElement
 DOM object for a "<ellipse>" element. More...
 
class  SVGFEGaussianBlurElement
 DOM object for a "<feGaussianBlur>" element. More...
 
class  SVGFilterElement
 DOM object for a "<filter>" element. More...
 
class  SVGFilterPrimitiveStandardAttributes
 Handles standard attributes for filter primitives, which are children of the "<filter>" element. More...
 
class  SVGGElement
 DOM object for a "<g>" element. More...
 
class  SVGGeometryElement
 Base class for all Elements: Basic shapes. More...
 
class  SVGGradientElement
 Base class for SVG gradient elements, such as SVGLinearGradientElement and SVGRadialGradientElement. More...
 
class  SVGGraphicsElement
 Base class for elements which render or impact the rendering tree, such as "<path>" and "<g>". More...
 
class  SVGImageElement
 DOM object for a "<image>" element. More...
 
class  SVGLinearGradientElement
 DOM object for a "<linearGradient>" element. More...
 
class  SVGLineElement
 DOM object for a "<line>" element. More...
 
class  SVGMarkerElement
 DOM object for a "<marker>" element, which is used to define graphical objects that can be used repeatedly along a path, such as arrowheads or other markers on paths. More...
 
class  SVGMaskElement
 Represents the "<mask>" element in SVG, which is used to define a mask for graphical elements. More...
 
class  SVGPathElement
 DOM object for a "<path>" element. More...
 
class  SVGPatternElement
 DOM object for a "<pattern>" element. More...
 
class  SVGPolygonElement
 DOM object for a "<polygon>" element. More...
 
class  SVGPolylineElement
 DOM object for a "<polyline>" element. More...
 
class  SVGRadialGradientElement
 DOM object for a "<radialGradient>" element. More...
 
class  SVGRectElement
 DOM object for the "<rect>" element. More...
 
class  SVGStopElement
 DOM object for a "<stop>" element. More...
 
class  SVGStyleElement
 DOM object for a "<style>" element, which contains a CSS stylesheet. More...
 
class  SVGSVGElement
 DOM object for a "<svg>" element. More...
 
class  SVGUnknownElement
 DOM object for an unknown SVG element. More...
 
class  SVGUseElement
 DOM object for a "<use>" element. More...
 
class  Trace
 Implements a simple RAII execution time tracer. More...
 

Typedefs

using AllSVGElements
 A type list of all SVG element types, used by donner::svg::parser::AttributeParser and donner::svg::parser::SVGParser.
 
using StrokeDasharray = std::vector<Lengthd>
 The parsed result of the 'stroke-dasharray' property, see: https://www.w3.org/TR/SVG2/painting.html#StrokeDasharrayProperty.
 
template<typename T >
using GetInitialFn = std::optional<T> (*)()
 Callback function to get the initial value of a property.
 
using Params = ImageComparisonParams
 

Enumerations

enum class  FilterUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = ObjectBoundingBox
}
 Values for the "filterUnits" attribute which defines the coordinate system for attributes x, y, width, height. More...
 
enum class  PrimitiveUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = UserSpaceOnUse
}
 Values for the "primitiveUnits" attribute which specifies the coordinate system for the various length values within the filter primitives and for the attributes that define the filter primitive subregion. More...
 
enum class  ClipPathUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = UserSpaceOnUse
}
 Values for the "clipPathUnits" attribute, https://drafts.fxtf.org/css-masking-1/#element-attrdef-clippath-clippathunits. More...
 
enum class  ClipRule {
  NonZero ,
  EvenOdd
}
 The parsed result of the clip-rule property, see: https://drafts.fxtf.org/css-masking-1/#propdef-clip-rule. More...
 
enum class  Display {
  Inline ,
  Block ,
  ListItem ,
  InlineBlock ,
  Table ,
  InlineTable ,
  TableRowGroup ,
  TableHeaderGroup ,
  TableFooterGroup ,
  TableRow ,
  TableColumnGroup ,
  TableColumn ,
  TableCell ,
  TableCaption ,
  None
}
 The parsed result of the CSS 'display' property, see https://www.w3.org/TR/CSS2/visuren.html#propdef-display. More...
 
enum class  FillRule {
  NonZero ,
  EvenOdd
}
 The parsed result of the 'fill-rule' property, see: https://www.w3.org/TR/SVG2/painting.html#FillRuleProperty. More...
 
enum class  GradientUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = ObjectBoundingBox
}
 Values for the "gradientUnits" attribute, https://www.w3.org/TR/SVG2/pservers.html#LinearGradientElementGradientUnitsAttribute and https://www.w3.org/TR/SVG2/pservers.html#RadialGradientElementGradientUnitsAttribute. More...
 
enum class  GradientSpreadMethod {
  Pad ,
  Reflect ,
  Repeat ,
  Default = Pad
}
 Values for the gradient "spreadMethod" attribute, https://www.w3.org/TR/SVG2/pservers.html#LinearGradientElementSpreadMethodAttribute and https://www.w3.org/TR/SVG2/pservers.html#RadialGradientElementSpreadMethodAttribute. More...
 
enum class  MarkerUnits {
  StrokeWidth ,
  UserSpaceOnUse ,
  Default = StrokeWidth
}
 Values for the "markerUnits" attribute, https://www.w3.org/TR/SVG2/painting.html#MarkerUnitsAttribute. More...
 
enum class  MaskUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = ObjectBoundingBox
}
 Values for the "maskUnits" attribute, https://drafts.fxtf.org/css-masking-1/#element-attrdef-mask-maskunits. More...
 
enum class  MaskContentUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = UserSpaceOnUse
}
 Values for the "maskContentUnits" attribute, https://drafts.fxtf.org/css-masking-1/#element-attrdef-mask-maskcontentunits. More...
 
enum class  Overflow {
  Visible ,
  Hidden ,
  Scroll ,
  Auto
}
 The parsed result of the CSS 'overflow' property, see https://www.w3.org/TR/CSS2/visufx.html#overflow and https://www.w3.org/TR/SVG2/render.html#OverflowAndClipProperties. More...
 
enum class  PatternUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = ObjectBoundingBox
}
 PatternUnits controls the coordinate system of the x/y/width/height attributes: More...
 
enum class  PatternContentUnits {
  UserSpaceOnUse ,
  ObjectBoundingBox ,
  Default = UserSpaceOnUse
}
 PatternContentUnits controls the coordinate system of the children of the pattern: More...
 
enum class  PointerEvents {
  None ,
  BoundingBox ,
  VisiblePainted ,
  VisibleFill ,
  VisibleStroke ,
  Visible ,
  Painted ,
  Fill ,
  Stroke ,
  All
}
 Values for the 'pointer-events' property, which defines how mouse events interact with an element. More...
 
enum class  StrokeLinecap {
  Butt ,
  Round ,
  Square
}
 The parsed result of the 'stroke-linecap' property, see: https://www.w3.org/TR/SVG2/painting.html#StrokeLinecapProperty. More...
 
enum class  StrokeLinejoin {
  Miter ,
  MiterClip ,
  Round ,
  Bevel ,
  Arcs
}
 The parsed result of the 'stroke-linejoin' property, see: https://www.w3.org/TR/SVG2/painting.html#StrokeLinejoinProperty. More...
 
enum class  Visibility {
  Visible ,
  Hidden ,
  Collapse
}
 The parsed result of the 'visibility' property, see: https://www.w3.org/TR/CSS2/visufx.html#propdef-visibility. More...
 
enum class  ElementType {
  Circle ,
  ClipPath ,
  Defs ,
  Ellipse ,
  FeGaussianBlur ,
  Filter ,
  G ,
  Image ,
  Line ,
  LinearGradient ,
  Marker ,
  Mask ,
  Path ,
  Pattern ,
  Polygon ,
  Polyline ,
  RadialGradient ,
  Rect ,
  Stop ,
  Style ,
  SVG ,
  Unknown ,
  Use
}
 SVG element types, corresponds to each XML element name, such as "<circle>", "<svg>", "<rect>", etc. More...
 
enum class  PropertyCascade {
  None ,
  Inherit ,
  PaintInherit
}
 Defines how this property cascades between the parent and child elements. More...
 
enum class  PropertyState {
  NotSet = 0 ,
  Set = 1 ,
  Inherit = 2 ,
  ExplicitInitial = 3 ,
  ExplicitUnset = 4
}
 The current property state, which can be either set, not set, or a specific CSS keyword such as "inherit", "initial", or "unset". More...
 
enum class  PropertyInheritOptions {
  All ,
  NoPaint
}
 Options to control how inheritance is performed, to either inherit everything or conditionally disable inheritance of paint servers. More...
 
enum class  ImageLoaderError {
  NotFound ,
  UnsupportedFormat ,
  InvalidDataUrl ,
  ImageCorrupt
}
 Enum of possible errors that can occur when loading an image. More...
 
enum class  ResourceLoaderError {
  NotFound ,
  SandboxViolation
}
 Error codes for resource loading. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const FilterEffect &paint)
 Ostream output operator.
 
std::ostream & operator<< (std::ostream &os, ClipPathUnits units)
 Ostream output operator for ClipPathUnits enum, outputs the enum name with prefix, e.g. ClipPathUnits::UserSpaceOnUse.
 
std::ostream & operator<< (std::ostream &os, const ClipRule &clipRule)
 Output stream operator for ClipRule enum.
 
std::ostream & operator<< (std::ostream &os, Display value)
 Ostream output operator for Display enum, outputs the CSS value.
 
std::ostream & operator<< (std::ostream &os, FillRule value)
 Ostream output operator for FillRule enum, outputs the CSS value.
 
std::ostream & operator<< (std::ostream &os, MarkerUnits units)
 Ostream output operator for MarkerUnits enum, outputs the enum name with prefix, e.g. MarkerUnits::UserSpaceOnUse.
 
std::ostream & operator<< (std::ostream &os, MaskUnits units)
 Ostream output operator for MaskUnits enum, outputs the enum name with prefix, e.g. MaskUnits::UserSpaceOnUse.
 
std::ostream & operator<< (std::ostream &os, MaskContentUnits units)
 Ostream output operator for MaskContentUnits enum, outputs the enum name with prefix, e.g. MaskContentUnits::UserSpaceOnUse.
 
std::ostream & operator<< (std::ostream &os, Overflow value)
 Ostream output operator for Overflow enum, outputs the CSS value.
 
std::ostream & operator<< (std::ostream &os, PathSpline::CommandType type)
 
std::ostream & operator<< (std::ostream &os, const PathSpline::Command &command)
 
std::ostream & operator<< (std::ostream &os, const PathSpline &spline)
 
std::ostream & operator<< (std::ostream &os, PointerEvents value)
 Output stream operator for PointerEvents, outputs the CSS string representation for this enum, e.g. "none", "bounding-box", etc.
 
std::ostream & operator<< (std::ostream &os, const PreserveAspectRatio &value)
 
std::ostream & operator<< (std::ostream &os, PreserveAspectRatio::Align value)
 Outputs Align value to stream (e.g., "Align::XMidYMid")
 
std::ostream & operator<< (std::ostream &os, PreserveAspectRatio::MeetOrSlice value)
 Outputs MeetOrSlice value to stream (e.g., "MeetOrSlice::Meet")
 
std::ostream & operator<< (std::ostream &os, StrokeLinecap value)
 Ostream output operator for StrokeLinecap enum, outputs the CSS value.
 
std::ostream & operator<< (std::ostream &os, StrokeLinejoin value)
 Ostream output operator for StrokeLinejoin enum, outputs the CSS value.
 
std::ostream & operator<< (std::ostream &os, const StrokeDasharray &value)
 Ostream output operator for StrokeDasharray enum, outputs the CSS value.
 
 MATCHER_P2 (PointsAndCommandsAre, pointsMatcher, commandsMatcher, "")
 Matches the points and commands of a PathSpline.
 
 MATCHER_P (VertexPointsAre, pointsMatcher, "")
 Matches the points of a from the PathSpline vertices list.
 
template<typename... Matchers>
auto VertexPointsAre (Matchers... matchers)
 Matches the points of a from the PathSpline vertices list.
 
std::ostream & operator<< (std::ostream &os, Visibility value)
 Ostream output operator for Visibility enum, outputs the CSS value.
 
std::ostream & operator<< (std::ostream &os, ElementType type)
 Ostream output operator for ElementType, outputs the element name.
 
template<typename ReturnType , typename FnT >
ReturnType ToConstexpr (ElementType type, FnT fn)
 Converts a ElementType runtime value to a compile-time value, allowing conditional behavior for different element types with constexpr.
 
void DumpTree (SVGElement element, int depth=0)
 Dump the SVG tree to the console, starting with element.
 
int main (int argc, char *argv[])
 Tool entry point, usage is described in the file header.
 
std::ostream & operator<< (std::ostream &os, const PaintServer &paint)
 Output stream operator for PaintServer.
 
template<typename T , PropertyCascade kCascade>
std::ostream & operator<< (std::ostream &os, const Property< T, kCascade > &property)
 Ostream output operator, which outputs the current property value, how it was set (e.g.
 
std::ostream & operator<< (std::ostream &os, const PropertyRegistry &registry)
 
std::tuple< Lengthd, double > CalculateRadiusMaybeAuto (const Property< Lengthd > &property, const Property< Lengthd > &fallbackProperty, const Boxd &viewbox, const FontMetrics &fontMetrics)
 Calculates the the radius for elements with rx and ry radius, in pixels, taking into account the "auto" identifier and handling negative values.
 
std::string TestNameFromFilename (const testing::TestParamInfo< ImageComparisonTestcase > &info)
 
 TEST_P (ImageComparisonTestFixture, ResvgTest)
 
 INSTANTIATE_TEST_SUITE_P (Color, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-color", { {"a-color-interpolation-filters-001.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Display, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-display", { {"a-display-005.svg", Params::Skip()}, {"a-display-006.svg", Params::Skip()}, {"a-display-009.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Fill, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-fill", { {"a-fill-010.svg", Params::Skip()}, {"a-fill-015.svg", Params::Skip()}, {"a-fill-027.svg", Params::Skip()}, {"a-fill-031.svg", Params::Skip()}, {"a-fill-032.svg", Params::Skip()}, {"a-fill-033.svg", Params::Skip()}, {"a-fill-opacity-004.svg", Params::Skip()}, {"a-fill-opacity-006.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (MarkerAttrib, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-marker")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Opacity, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-opacity", { {"a-opacity-005.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Overflow, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-overflow")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Shape, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-shape", { {"a-shape-rendering-005.svg", Params::Skip()}, {"a-shape-rendering-008.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (StopAttributes, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-stop")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Stroke, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-stroke", { {"a-stroke-007.svg", Params::Skip()}, {"a-stroke-008.svg", Params::Skip()}, {"a-stroke-009.svg", Params::Skip()}, {"a-stroke-dasharray-005.svg", Params::Skip()}, {"a-stroke-dasharray-007.svg", Params::Skip()}, {"a-stroke-dasharray-009.svg", Params::Skip()}, {"a-stroke-dasharray-013.svg", Params::WithThreshold(0.13f)}, {"a-stroke-dashoffset-004.svg", Params::Skip()}, {"a-stroke-linejoin-004.svg", Params::Skip()}, {"a-stroke-linejoin-005.svg", Params::Skip()}, {"a-stroke-opacity-004.svg", Params::Skip()}, {"a-stroke-opacity-006.svg", Params::Skip()}, {"a-stroke-width-004.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Style, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-style", { {"a-style-003.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Transform, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-transform", { {"a-transform-007.svg", Params::WithThreshold(0.05f)}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Visibility, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("a-visibility", { {"a-visibility-003.svg", Params::Skip()}, {"a-visibility-004.svg", Params::Skip()}, {"a-visibility-007.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Circle, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-circle")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (ClipPath, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-clipPath", { {"e-clipPath-007.svg", Params::Skip()}, {"e-clipPath-009.svg", Params::Skip()}, {"e-clipPath-010.svg", Params::Skip()}, {"e-clipPath-011.svg", Params::Skip()}, {"e-clipPath-012.svg", Params::Skip()}, {"e-clipPath-042.svg", Params::Skip()}, {"e-clipPath-044.svg", Params::Skip()}, {"e-clipPath-046.svg", Params::Skip()}, {"e-clipPath-047.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Defs, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-defs", { {"e-defs-007.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Ellipse, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-ellipse")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (G, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-g")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Image, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-image", { {"e-image-003.svg", Params::Skip()}, {"e-image-006.svg", Params::Skip()}, {"e-image-007.svg", Params::Skip()}, {"e-image-008.svg", Params::Skip()}, {"e-image-017.svg", Params::Skip()}, {"e-image-018.svg", Params::Skip()}, {"e-image-019.svg", Params::Skip()}, {"e-image-020.svg", Params::Skip()}, {"e-image-021.svg", Params::Skip()}, {"e-image-022.svg", Params::Skip()}, {"e-image-023.svg", Params::Skip()}, {"e-image-024.svg", Params::Skip()}, {"e-image-029.svg", Params::Skip()}, {"e-image-030.svg", Params::Skip()}, {"e-image-031.svg", Params::Skip()}, {"e-image-032.svg", Params::Skip()}, {"e-image-033.svg", Params::Skip()}, {"e-image-034.svg", Params::Skip()}, {"e-image-039.svg", Params::Skip()}, {"e-image-040.svg", Params::Skip()}, {"e-image-041.svg", Params::Skip()}, }, Params::WithThreshold(0.2f).disableDebugSkpOnFailure())), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Line, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-line-", { {"e-line-001.svg", Params::WithThreshold(0.02f)}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (LinearGradient, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-linearGradient", { {"e-linearGradient-037.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Marker, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-marker", { {"e-marker-008.svg", Params::Skip()}, {"e-marker-017.svg", Params::Skip()}, {"e-marker-018.svg", Params::Skip()}, {"e-marker-019.svg", Params::Skip()}, {"e-marker-022.svg", Params::Skip()}, {"e-marker-032.svg", Params::Skip()}, {"e-marker-044.svg", Params::Skip()}, {"e-marker-045.svg", Params::WithGoldenOverride("donner/svg/renderer/testdata/golden/resvg-e-marker-045.png")}, {"e-marker-051.svg", Params::WithGoldenOverride("donner/svg/renderer/testdata/golden/resvg-e-marker-051.png")}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Mask, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-mask", { {"e-mask-017.svg", Params::Skip()}, {"e-mask-022.svg", Params::Skip()}, {"e-mask-025.svg", Params::Skip()}, {"e-mask-026.svg", Params::Skip()}, {"e-mask-027.svg", Params::Skip()}, {"e-mask-029.svg", Params::Skip()}, {"e-mask-030.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Path, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-path")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Pattern, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-pattern", { {"e-pattern-003.svg", Params::Skip()}, {"e-pattern-008.svg", Params::WithThreshold(kDefaultThreshold, 250)}, {"e-pattern-010.svg", Params::WithThreshold(kDefaultThreshold, 150)}, {"e-pattern-018.svg", Params::Skip()}, {"e-pattern-019.svg", Params::WithThreshold(0.2f)}, {"e-pattern-020.svg", Params::WithThreshold(0.6f, 300)}, {"e-pattern-021.svg", Params::WithThreshold(0.2f)}, {"e-pattern-022.svg", Params::WithThreshold(0.2f)}, {"e-pattern-023.svg", Params::WithThreshold(0.2f)}, {"e-pattern-028.svg", Params::Skip()}, {"e-pattern-030.svg", Params::WithThreshold(0.02f)}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Polygon, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-polygon")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Polyline, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-polyline")), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (RadialGradient, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-radialGradient", { {"e-radialGradient-031.svg", Params::Skip()}, {"e-radialGradient-032.svg", Params::Skip()}, {"e-radialGradient-039.svg", Params::Skip()}, {"e-radialGradient-040.svg", Params::Skip()}, {"e-radialGradient-043.svg", Params::Skip()}, {"e-radialGradient-044.svg", Params::Skip()}, {"e-radialGradient-045.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Rect, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-rect", { {"e-rect-022.svg", Params::Skip()}, {"e-rect-023.svg", Params::Skip()}, {"e-rect-029.svg", Params::Skip()}, {"e-rect-031.svg", Params::Skip()}, {"e-rect-034.svg", Params::Skip()}, {"e-rect-036.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (StopElement, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-stop", { {"e-stop-011.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (StyleElement, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-style", { {"e-style-012.svg", Params::Skip()}, {"e-style-014.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (SvgElement, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-svg", { {"e-svg-002.svg", Params::Skip()}, {"e-svg-003.svg", Params::Skip()}, {"e-svg-004.svg", Params::Skip()}, {"e-svg-005.svg", Params::Skip()}, {"e-svg-007.svg", Params::Skip()}, {"e-svg-008.svg", Params::WithThreshold(0.13f)}, {"e-svg-009.svg", Params::WithThreshold(0.13f)}, {"e-svg-010.svg", Params::WithThreshold(0.13f)}, {"e-svg-011.svg", Params::WithThreshold(0.13f)}, {"e-svg-012.svg", Params::WithThreshold(0.13f)}, {"e-svg-013.svg", Params::WithThreshold(0.13f)}, {"e-svg-014.svg", Params::WithThreshold(0.13f)}, {"e-svg-015.svg", Params::WithThreshold(0.13f)}, {"e-svg-016.svg", Params::WithThreshold(0.13f)}, {"e-svg-017.svg", Params::WithThreshold(0.13f)}, {"e-svg-018.svg", Params::Skip()}, {"e-svg-019.svg", Params::Skip()}, {"e-svg-020.svg", Params::Skip()}, {"e-svg-021.svg", Params::Skip()}, {"e-svg-028.svg", Params::Skip()}, {"e-svg-029.svg", Params::Skip()}, {"e-svg-031.svg", Params::Skip()}, {"e-svg-032.svg", Params::Skip()}, {"e-svg-033.svg", Params::Skip()}, {"e-svg-036.svg", Params::Skip()}, })), TestNameFromFilename)
 
 INSTANTIATE_TEST_SUITE_P (Use, ImageComparisonTestFixture, ValuesIn(getTestsWithPrefix("e-use", { {"e-use-008.svg", Params::Skip()}, })), TestNameFromFilename)
 
base::parser::ParseResult< std::vector< uint8_t > > DecodeBase64Data (std::string_view base64String)
 Decode a base64-encoded string into a byte array.
 
std::string_view ToString (ImageLoaderError err)
 
SVGDocument instantiateSubtree (std::string_view str, const parser::SVGParser::Options &options, const Vector2i &size)
 
ParsedFragment instantiateSubtreeElement (std::string_view str, const parser::SVGParser::Options &options, Vector2i size)
 
template<typename ElementT >
ParsedFragment< ElementT > instantiateSubtreeElementAs (std::string_view str, const parser::SVGParser::Options &options={}, Vector2i size=kTestSvgDefaultSize)
 

Detailed Description

Donner SVG library, which can load, manipulate and render SVG files.

Loading SVG files can be done using donner::svg::parser::SVGParser

std::string_view svgSource("<svg>...</svg>");
std::vector<ParseError> warnings;
auto maybeResult = SVGParser::ParseSVG(svgSource, &warnings);
if (maybeResult.hasError()) {
const auto& e = maybeResult.error();
std::cerr << "Parse Error: " << e << "\n";
exit(1);
}
std::cout << "Parsed successfully.\n";
if (!warnings.empty()) {
std::cout << "Warnings:\n";
for (auto& w : warnings) {
std::cout << " " << w << "\n";
}
}

The resulting SVGDocument can be used to traverse the SVG file:

SVGDocument document = std::move(maybeResult.result());
if (auto myPath = document.querySelector("#myPath")) {
std::cout << "Found #myPath" << std::endl;
myPath->setStyle("fill: red");
myPath->setStyle("stroke: white");
}
Represents an SVG document, which holds a collection of SVGElement as the document tree.
Definition SVGDocument.h:32
std::optional< SVGElement > querySelector(std::string_view selector)
Find the first element in the tree that matches the given CSS selector.
Definition SVGDocument.cc:65

The SVG file can be rendered using donner::svg::RendererSkia

RendererSkia renderer;
renderer.draw(document);
if (renderer.save("output.png")) {
std::cout << "Saved to output.png\n";
} else {
std::cerr << "Failed to save to file\n";
}
Rendering backend using Skia, https://github.com/google/skia.
Definition RendererSkia.h:26
void draw(SVGDocument &document)
Draw the SVG document using the renderer.
Definition RendererSkia.cc:1181
bool save(const char *filename)
Save the rendered image to a PNG file.
Definition RendererSkia.cc:1269

Class Documentation

◆ donner::svg::GradientStop

struct donner::svg::GradientStop

Values for a gradient stop, https://www.w3.org/TR/SVG2/pservers.html#StopElement.

This is used on "<stop>" elements.

Collaboration diagram for donner::svg::GradientStop:
[legend]
Class Members
Color color {css::RGBA(0, 0, 0, 0xFF)} Color of the gradient stop.
float offset = 0.0 Offset of the gradient stop, in the range [0, 1].
float opacity = 1.0f Opacity of the gradient stop, in the range [0, 1].

◆ donner::svg::Image

struct donner::svg::Image

Stores an uncompressed RGBA-format image.

Loaded by RendererTestUtils::readRgbaImageFromPngFile.

Collaboration diagram for donner::svg::Image:
[legend]
Class Members
vector< uint8_t > data Pixel data, in RGBA format. Rows are are strideInPixels long (byte length is strideInPixels * 4).
int height Image height in pixels.
size_t strideInPixels The stride of data, in pixels.
int width Image width in pixels.

◆ donner::svg::ImageResource

struct donner::svg::ImageResource
Collaboration diagram for donner::svg::ImageResource:
[legend]
Class Members
vector< uint8_t > data Pixel data in RGBA format.
int height Height of the image, in pixels.
int width Width of the image, in pixels.

Typedef Documentation

◆ AllSVGElements

Initial value:
entt::type_list<
SVGCircleElement,
SVGClipPathElement,
SVGDefsElement,
SVGEllipseElement,
SVGFEGaussianBlurElement,
SVGFilterElement,
SVGGElement,
SVGImageElement,
SVGLineElement,
SVGLinearGradientElement,
SVGMarkerElement,
SVGMaskElement,
SVGStopElement,
SVGRadialGradientElement,
SVGPathElement,
SVGPatternElement,
SVGPolygonElement,
SVGPolylineElement,
SVGRectElement,
SVGStyleElement,
SVGSVGElement,
SVGUseElement>

A type list of all SVG element types, used by donner::svg::parser::AttributeParser and donner::svg::parser::SVGParser.

◆ GetInitialFn

template<typename T >
using donner::svg::GetInitialFn = std::optional<T> (*)()

Callback function to get the initial value of a property.

The function returns a std::optional to allow for properties that have no initial value.

Enumeration Type Documentation

◆ ClipPathUnits

enum class donner::svg::ClipPathUnits
strong

Values for the "clipPathUnits" attribute, https://drafts.fxtf.org/css-masking-1/#element-attrdef-clippath-clippathunits.

This is used on the "<clipPath>" element, and defines the coordinate system for the contents of the clip path.

Enumerator
UserSpaceOnUse 

The clip path is defined in user space, which is the coordinate system of the element that references the clip path.

ObjectBoundingBox 

The clip path is defined in object space, where (0, 0) is the top-left corner of the element that references the clip path, and (1, 1) is the bottom-right corner.

Note that this may result in non-uniform scaling if the element is not square.

Default 

The default value for the "clipPathUnits" attribute, which is userSpaceOnUse.

◆ ClipRule

enum class donner::svg::ClipRule
strong

The parsed result of the clip-rule property, see: https://drafts.fxtf.org/css-masking-1/#propdef-clip-rule.

Enumerator
NonZero 

[DEFAULT] Determines "insideness" of a point by counting crossings of a ray drawn from that point to infinity and path segments. If crossings is non-zero, the point is inside, else outside.

EvenOdd 

Determines "insideness" of a point by counting the number of path segments from the shape crossed by a ray drawn from that point to infinity. If count is odd, point is inside, else outside.

◆ Display

enum class donner::svg::Display
strong

The parsed result of the CSS 'display' property, see https://www.w3.org/TR/CSS2/visuren.html#propdef-display.

Note that in SVG2, there are only two distinct behaviors, 'none', and everything else rendered as normal, see https://www.w3.org/TR/SVG2/render.html#VisibilityControl

‍Elements that have any other display value than none are rendered as normal.

Enumerator
Inline 

[DEFAULT] "inline": Causes an element to generate one or more inline boxes.

Block 

"block": Causes an element to generate a block box.

ListItem 

"list-item": Causes an element to act as a list item.

InlineBlock 

"inline-block": Causes an element to generate an inline-level block container.

Table 

"table": Specifies that an element defines a block-level table, see https://www.w3.org/TR/CSS2/tables.html#table-display.

InlineTable 

"inline-table": Specifies that an element defines a inline-level table, see https://www.w3.org/TR/CSS2/tables.html#table-display.

TableRowGroup 

"table-row-group": Specifies that an element groups one or more rows.

TableHeaderGroup 

"table-header-group": Like 'table-row-group', but for visual formatting, the row group is always displayed before all other rows and row groups and after any top captions.

TableFooterGroup 

"table-footer-group": Like 'table-row-group', but for visual formatting, the row group is always displayed after all other rows and row groups and before any bottom captions.

TableRow 

"table-row": Specifies that an element is a row of cells.

TableColumnGroup 

"table-column-group": Specifies that an element groups one or more columns.

TableColumn 

"table-column": Specifies that an element is a column of cells.

TableCell 

"table-cell": Specifies that an element represents a table cell.

TableCaption 

"table-caption": Specifies a caption for the table.

None 

"none": The element is not rendered.

◆ ElementType

enum class donner::svg::ElementType
strong

SVG element types, corresponds to each XML element name, such as "<circle>", "<svg>", "<rect>", etc.

Enumerator
Circle 

"<circle>"

ClipPath 

"<clipPath>"

Defs 

"<defs>"

Ellipse 

"<ellipse>"

FeGaussianBlur 

"<feGaussianBlur>"

Filter 

"<filter>"

"<g>"

Image 

"<image>"

Line 

"<line>"

LinearGradient 

"<linearGradient>"

Marker 

"<marker>"

Mask 

"<mask>"

Path 

"<path>"

Pattern 

"<pattern>"

Polygon 

"<polygon>"

Polyline 

"<polyline>"

RadialGradient 

"<radialGradient>"

Rect 

"<rect>"

Stop 

"<stop>", for gradient stops.

Style 

"<style>"

SVG 

"<svg>", SVG root element.

Unknown 

For unknown elements.

Use 

"<use>"

◆ FillRule

enum class donner::svg::FillRule
strong

The parsed result of the 'fill-rule' property, see: https://www.w3.org/TR/SVG2/painting.html#FillRuleProperty.

Enumerator
NonZero 

[DEFAULT] Determines "insideness" of a point by counting crossings of a ray drawn from that point to infinity and path segments. If crossings is non-zero, the point is inside, else outside.

EvenOdd 

Determines "insideness" of a point by counting the number of path segments from the shape crossed by a ray drawn from that point to infinity. If count is odd, point is inside, else outside.

◆ FilterUnits

enum class donner::svg::FilterUnits
strong

Values for the "filterUnits" attribute which defines the coordinate system for attributes x, y, width, height.

See also
https://www.w3.org/TR/filter-effects/#element-attrdef-filter-filterunits.

This is used on "<filter>" element.

Enumerator
UserSpaceOnUse 

If filterUnits is equal to userSpaceOnUse, x, y, width, height represent values in the current user coordinate system in place at the time when the filter element is referenced (i.e., the user coordinate system for the element referencing the filter element via a filter property).

ObjectBoundingBox 

If filterUnits is equal to objectBoundingBox, then x, y, width, height represent fractions or percentages of the bounding box on the referencing element (see object bounding box units).

Default 

The default value for the "filterUnits" attribute, which is objectBoundingBox.

◆ GradientSpreadMethod

Values for the gradient "spreadMethod" attribute, https://www.w3.org/TR/SVG2/pservers.html#LinearGradientElementSpreadMethodAttribute and https://www.w3.org/TR/SVG2/pservers.html#RadialGradientElementSpreadMethodAttribute.

Specifies what happens at the start or end of a gradient, when the gradient coordinates are inside the bounds of the referencing element.

This is used on "<linearGradient>" and "<radialGradient>" elements.

Default Pad Reflect Repeat

Enumerator
Pad 

The gradient is filled with the start or end color.

Reflect 

The gradient is reflected at the start or end.

Repeat 

The gradient is repeated at the start or end.

Default 

The default value for the "spreadMethod" attribute, which is Pad.

◆ GradientUnits

enum class donner::svg::GradientUnits
strong

Values for the "gradientUnits" attribute, https://www.w3.org/TR/SVG2/pservers.html#LinearGradientElementGradientUnitsAttribute and https://www.w3.org/TR/SVG2/pservers.html#RadialGradientElementGradientUnitsAttribute.

This is used on "<linearGradient>" and "<radialGradient>" elements.

  • For linear gradients, this defines the coordinate system for attributes x1, y1, x2, and y2.
  • For radial gradients, this defines the coordinate system for attributes cx, cy, r, fx, fy, and fr.
Enumerator
UserSpaceOnUse 

The gradient is defined in user space, which is the coordinate system of the element that references the gradient.

ObjectBoundingBox 

The gradient is defined in object space, where (0, 0) is the top-left corner of the element that references the gradient, and (1, 1) is the bottom-right corner.

Note that this may result in non-uniform scaling if the element is not square.

Default 

The default value for the "gradientUnits" attribute, which is objectBoundingBox.

◆ ImageLoaderError

enum class donner::svg::ImageLoaderError
strong

Enum of possible errors that can occur when loading an image.

Enumerator
NotFound 

The file was not found.

UnsupportedFormat 

The image format is not supported (mime type must be either "image/png" or "image/jpeg").

InvalidDataUrl 

The data URL is invalid.

ImageCorrupt 

The image data is corrupt.

◆ MarkerUnits

enum class donner::svg::MarkerUnits
strong

Values for the "markerUnits" attribute, https://www.w3.org/TR/SVG2/painting.html#MarkerUnitsAttribute.

This is used on the "<marker>" element, and defines the coordinate system for markerWidth, markerHeight, and the contents of the marker.

Enumerator
StrokeWidth 

Marker scales to the stroke width.

Defines a coordinate system where 1.0 is scaled to the stroke-width of the shape.

UserSpaceOnUse 

The marker contents are defined in user space, which is the coordinate system of the element that references the marker.

Default 

The default value for the "markerUnits" attribute, which is strokeWidth.

◆ MaskContentUnits

enum class donner::svg::MaskContentUnits
strong

Values for the "maskContentUnits" attribute, https://drafts.fxtf.org/css-masking-1/#element-attrdef-mask-maskcontentunits.

This is used on the "<mask>" element, and defines the coordinate system for the contents of the mask.

Enumerator
UserSpaceOnUse 

The mask contents are defined in user space, which is the coordinate system of the element that references the mask.

ObjectBoundingBox 

The mask contents are defined in object space, where (0, 0) is the top-left corner of the element that references the mask, and (1, 1) is the bottom-right corner.

Note that this may result in non-uniform scaling if the element is not square.

Default 

The default value for the "maskContentUnits" attribute, which is userSpaceOnUse.

◆ MaskUnits

enum class donner::svg::MaskUnits
strong

Values for the "maskUnits" attribute, https://drafts.fxtf.org/css-masking-1/#element-attrdef-mask-maskunits.

This is used on the "<mask>" element, and defines the coordinate system for the x, y, width, and height attributes of the mask.

Enumerator
UserSpaceOnUse 

The attributes are defined in user space, which is the coordinate system of the element that references the mask.

ObjectBoundingBox 

The attributes are defined in object space, where (0, 0) is the top-left corner of the element that references the mask, and (1, 1) is the bottom-right corner.

Default 

The default value for the "maskUnits" attribute, which is objectBoundingBox.

◆ Overflow

enum class donner::svg::Overflow
strong

The parsed result of the CSS 'overflow' property, see https://www.w3.org/TR/CSS2/visufx.html#overflow and https://www.w3.org/TR/SVG2/render.html#OverflowAndClipProperties.

The 'overflow' property specifies whether to clip content, render scrollbars, or display content outside the element's box.

In SVG, the 'overflow' property applies to container elements and determines how to handle content that exceeds the bounds of the viewport.

Enumerator
Visible 

[DEFAULT] "visible": Content is not clipped, and may render outside the box.

Hidden 

"hidden": Content is clipped, and no scrollbars are provided.

Scroll 

"scroll": Content is clipped, but scrollbars are provided to scroll the content. Donner does not implement scrolling so this is equivalent to "hidden".

Auto 

"auto": If content overflows, scrollbars are provided.

◆ PatternContentUnits

PatternContentUnits controls the coordinate system of the children of the pattern:

With userSpaceOnUse, as the shape size changes, padding will be added between tiles. With objectBoundingBox, the tiles will be stretched to fill the shape.

<pattern id="contentUserspace" patternContentUnits="userSpaceOnUse"
x="0" y="0.2" width="0.5" height="0.5">
<rect x="0" y="0" width="12" height="12" fill="lime" />
<rect x="10" y="10" width="12" height="12" fill="gray" />
</pattern>
<pattern id="contentBbox" patternContentUnits="objectBoundingBox"
x="0" y="0.2" width="0.5" height="0.5">
<rect x="0" y="0" width="0.24" height="0.24" fill="lime" />
<rect x="0.2" y="0.2" width="0.24" height="0.24" fill="gray" />
</pattern>

PatternContentUnits userSpaceOnUse (default) objectBoundingBox

Enumerator
UserSpaceOnUse 

The children of the pattern are specified in the current user space where the pattern is referenced.

ObjectBoundingBox 

The children of the pattern are specified as percentages of the object bounding box, where 0.0 is the left and 1.0 is the right, and similarly for the y axis.

Default 

The default value, PatternContentUnits::UserSpaceOnUse.

◆ PatternUnits

enum class donner::svg::PatternUnits
strong

PatternUnits controls the coordinate system of the x/y/width/height attributes:

  • For PatternUnits::ObjectBoundingBox (default), coordinates are percentages of the object bounding box, where 0.0 is the left and 1.0 is the right, and similarly for the y axis.
  • For PatternUnits::UserSpaceOnUse, patternUnits="objectBoundingBox", coordinates are specified in the current user space where the pattern is referenced.

See also: PatternContentUnits

For example, both of these patterns appear the same when applied to a 50x50 shape, but the objectBoundingBox one changes based on the shape the pattern is applied to:

<pattern id="bbox" x="0.1" y="0.2" width="0.5" height="0.5">
<rect x="0" y="0" width="12" height="12" fill="lime" />
<rect x="10" y="10" width="12" height="12" fill="gray" />
</pattern>
<pattern id="userspace" patternUnits="userSpaceOnUse" x="5" y="10" width="25" height="25">
<rect x="0" y="0" width="12" height="12" fill="lime" />
<rect x="10" y="10" width="12" height="12" fill="gray" />
</pattern>

See also: PatternUnits

PatternUnits objectBoundingBox (default) userSpaceOnUse

Enumerator
UserSpaceOnUse 

The pattern's x/y/width/height attributes are specified in the current user space where the pattern is referenced.

ObjectBoundingBox 

The pattern's x/y/width/height attributes are specified as percentages of the object bounding.

Default 

The default value, PatternUnits::ObjectBoundingBox.

◆ PointerEvents

enum class donner::svg::PointerEvents
strong

Values for the 'pointer-events' property, which defines how mouse events interact with an element.

See also
https://www.w3.org/TR/SVG2/interact.html#PointerEventsProp
Enumerator
None 

Do not respond to pointer events.

BoundingBox 

The element's bounding box is used instead of the path.

VisiblePainted 

Responds to pointer events only if the element is visible and the pointer is over the painted area, which is the fill or stroke if they are not none.

VisibleFill 

Responds to pointer events only if the element is visible and within the fill, regardless of fill value.

VisibleStroke 

Responds to pointer events only if the element is visible and within the stroke, regardless of stroke value.

Visible 

Responds to pointer events only if the element is visible, if the pointer is within either the fill or stroke, regardless of their value.

Painted 

Responds to pointer events only if the pointer is over the painted area, which is the fill or stroke if they are not none. Ignores the visibility property.

Fill 

Responds to pointer events only if the pointer is within the fill area, regardless of fill or visibility property values.

Stroke 

Responds to pointer events only if the pointer is within the stroke area, regardless of stroke or visibility property values.

All 

Responds to pointer events regardless of the element's visibility or painted area, if the pointer is within either the fill or stroke areas.

◆ PrimitiveUnits

enum class donner::svg::PrimitiveUnits
strong

Values for the "primitiveUnits" attribute which specifies the coordinate system for the various length values within the filter primitives and for the attributes that define the filter primitive subregion.

See also
https://www.w3.org/TR/filter-effects/#element-attrdef-filter-primitiveunits

This is used on "<filter>" element.

Enumerator
UserSpaceOnUse 

If primitiveUnits is equal to userSpaceOnUse, any length values within the filter definitions represent values in the current local coordinate system in place at the time when the "<filter>" element is referenced (i.e., the user coordinate system for the element referencing the filter element via a filter property).

ObjectBoundingBox 

If primitiveUnits is equal to objectBoundingBox, then any length values within the filter definitions represent fractions or percentages of the bounding box on the referencing element (see object bounding box units).

Note that if only one number was specified in a <number-optional-number> value this number is expanded out before the primitiveUnits computation takes place.

Default 

The default value for the "primitiveUnits" attribute, which is userSpaceOnUse.

◆ PropertyCascade

enum class donner::svg::PropertyCascade
strong

Defines how this property cascades between the parent and child elements.

Enumerator
None 

Property does not inherit.

Inherit 

Property inherits unconditionally.

PaintInherit 

Property inherits unless the child is instantiated as a paint server. This is handled as a special case to prevent recursion for "<pattern>".

◆ PropertyInheritOptions

Options to control how inheritance is performed, to either inherit everything or conditionally disable inheritance of paint servers.

Enumerator
All 

Inherit everything (default).

NoPaint 

Inherit everything except paint servers, for "<pattern>" elements.

◆ PropertyState

enum class donner::svg::PropertyState
strong

The current property state, which can be either set, not set, or a specific CSS keyword such as "inherit", "initial", or "unset".

Enumerator
NotSet 

If the property has no value set.

Set 

If the property has a value set.

Inherit 

If the property's value is "inherit".

ExplicitInitial 

If the property's value is "initial", explicitly set by the user.

Sets the property to its initial value with a specificity.

ExplicitUnset 

If the property's value is "unset", explicitly set by the user.

Resolves to either inherit or initial, depending on if the property is inheritable.

See also
https://www.w3.org/TR/css-cascade-3/#inherit-initial

◆ ResourceLoaderError

Error codes for resource loading.

Enumerator
NotFound 

File not found.

SandboxViolation 

File access violation, such as attempting to access a file outside the sandbox.

◆ StrokeLinecap

enum class donner::svg::StrokeLinecap
strong

The parsed result of the 'stroke-linecap' property, see: https://www.w3.org/TR/SVG2/painting.html#StrokeLinecapProperty.

Enumerator
Butt 

[DEFAULT] The stroke is squared off at the endpoint of the path.

Round 

The stroke is rounded at the endpoint of the path.

Square 

The stroke extends beyond the endpoint of the path by half of the stroke width and is squared off.

◆ StrokeLinejoin

enum class donner::svg::StrokeLinejoin
strong

The parsed result of the 'stroke-linejoin' property, see: https://www.w3.org/TR/SVG2/painting.html#StrokeLinejoinProperty.

Enumerator
Miter 

[DEFAULT] The outer edges of the strokes for the two segments are extended until they meet at an angle, creating a sharp point.

MiterClip 

Same as miter except the stroke will be clipped if the miter limit is exceeded.

Round 

The corners of the stroke are rounded off using an arc of a circle with a radius equal to the half of the stroke width.

Bevel 

A triangular shape is used to fill the area between the two stroked segments.

Arcs 

Similar to miter join, but uses an elliptical arc to join the segments, creating a smoother joint than miter join when the angle is acute. It is only used for large angles where a miter join would be too sharp.

◆ Visibility

enum class donner::svg::Visibility
strong

The parsed result of the 'visibility' property, see: https://www.w3.org/TR/CSS2/visufx.html#propdef-visibility.

This determines whether the element is visible or hidden, and whether it affects layout.

Enumerator
Visible 

[DEFAULT] Visible is the default value.

Hidden 

Hidden elements are invisible, but still affect layout.

Collapse 

Collapsed elements are invisible, and do not affect layout.

Function Documentation

◆ CalculateRadiusMaybeAuto()

std::tuple< Lengthd, double > donner::svg::CalculateRadiusMaybeAuto ( const Property< Lengthd > & property,
const Property< Lengthd > & fallbackProperty,
const Boxd & viewbox,
const FontMetrics & fontMetrics )

Calculates the the radius for elements with rx and ry radius, in pixels, taking into account the "auto" identifier and handling negative values.

This is used for "<rect>" or "<ellipse>".

Parameters
propertyThe property to compute, the storage for either rx or ry.
fallbackPropertyThe other property to use if the first one is "auto".
viewboxThe viewbox to use for computing the length.
fontMetricsThe font metrics to use for computing the length.
Returns
Tuple containing the resolved length, and the converted length to pixels.

◆ DecodeBase64Data()

base::parser::ParseResult< std::vector< uint8_t > > donner::svg::DecodeBase64Data ( std::string_view base64String)

Decode a base64-encoded string into a byte array.

If the string is not valid base64, an error is returned.

Parameters
base64StringThe base64-encoded string to decode.

◆ DumpTree()

void donner::svg::DumpTree ( SVGElement element,
int depth = 0 )

Dump the SVG tree to the console, starting with element.

Parameters
elementThe root element of the tree to dump.
depthThe depth of the current element in the tree, used to control indentation. Defaults to 0 for the root.

◆ MATCHER_P2()

donner::svg::MATCHER_P2 ( PointsAndCommandsAre ,
pointsMatcher ,
commandsMatcher ,
""  )

Matches the points and commands of a PathSpline.

Parameters
pointsMatcherPoints array matcher.
commandsMatcherCommands array matcher.

◆ operator<<() [1/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
const ClipRule & clipRule )
inline

Output stream operator for ClipRule enum.

Parameters
osThe output stream.
clipRuleThe ClipRule value to output.
Returns
The output stream.

◆ operator<<() [2/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
const PaintServer & paint )

Output stream operator for PaintServer.

Ostream output operator.

◆ operator<<() [3/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
const PathSpline & spline )
Parameters
osOutput stream.
splineSpline to output.

◆ operator<<() [4/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
const PathSpline::Command & command )
Parameters
osOutput stream.
commandCommand to output.

◆ operator<<() [5/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
const PreserveAspectRatio & value )

Format: "PreserveAspectRatio {<align>, <meetOrSlice>}" Example: "PreserveAspectRatio {Align::XMidYMid, MeetOrSlice::Meet}"

◆ operator<<() [6/8]

template<typename T , PropertyCascade kCascade>
std::ostream & donner::svg::operator<< ( std::ostream & os,
const Property< T, kCascade > & property )

Ostream output operator, which outputs the current property value, how it was set (e.g.

directly set or inherited, see PropertyState), and the property's specificity.

Example output:

color: Color(rgba(0, 255, 0, 255)) (set) @ Specificity(0, 0, 0)
Parameters
osOutput stream to write to.
propertyProperty to output.

◆ operator<<() [7/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
const PropertyRegistry & registry )

Example output:

color: Color(rgba(0, 255, 0, 255)) (set) @ Specificity(0, 0, 0)
}
Holds CSS properties for a single element.
Definition PropertyRegistry.h:98
Parameters
osOutput stream.
registryPropertyRegistry to output.

◆ operator<<() [8/8]

std::ostream & donner::svg::operator<< ( std::ostream & os,
PathSpline::CommandType type )

CommandType::MoveTo.

Parameters
osOutput stream.
typeCommand type.

◆ ToConstexpr()

template<typename ReturnType , typename FnT >
ReturnType donner::svg::ToConstexpr ( ElementType type,
FnT fn )

Converts a ElementType runtime value to a compile-time value, allowing conditional behavior for different element types with constexpr.

Takes the runtime value and invokes a function with std::integral_constant<ElementType> as a parameter.

Example 1:

SVGElement element = ...;
ToConstexpr<void>(element.type(), [&](auto elementType) {
if constexpr (std::is_same_v<elementType(), ElementType::Circle>) {
// Handle circle element.
return ParseCircleAttributes(element);
}
}
Represents an SVG entity belonging to an SVGDocument.
Definition SVGElement.h:55
ElementType type() const
Get the ElementType for known XML element types.
Definition SVGElement.cc:55

Example 2:

template <ElementType Type>
ParseResult<bool> myFunction();
ElementType type = element.type();
return ToConstexpr<ParseResult<bool>>(type, [&](auto elementType) {
return ParsePresentationAttribute<elementType()>(element, name, value);
*});
ElementType
SVG element types, corresponds to each XML element name, such as "<circle>", "<svg>",...
Definition ElementType.h:12
Template Parameters
ReturnTypeReturn type of the function.
FnTFunction type, with signature ReturnType(std::integral_constant<ElementType>).
Parameters
typeRuntime element type.
fnFunction to call with the compile-time element type, with signature ReturnType(std::integral_constant<ElementType>).

◆ VertexPointsAre()

template<typename... Matchers>
auto donner::svg::VertexPointsAre ( Matchers... matchers)

Matches the points of a from the PathSpline vertices list.

Variadic template function that accepts matchers or expected values for each vertex point.