Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
ECS Systems

Classes

class  donner::svg::components::FilterSystem
 Handles parsing and instantiating SVG filter effects from the SVG DOM. More...
 
class  donner::svg::components::LayoutSystem
 Handles layout and bounds calculations for SVG elements. More...
 
class  donner::svg::components::PaintSystem
 Manages Paint Servers for gradients and patterns, handling style and structural inheritance and creating "computed" state and shadow trees for these elements. More...
 
class  donner::svg::components::ShadowTreeSystem
 Instantiates shadow trees for elements that are not part of the main render graph, such as "<use>" and "<pattern>" elements. More...
 
class  donner::svg::components::ShapeSystem
 Creates computed path for shapes such as "<circle>", "<line>", and "<path>". More...
 
class  donner::svg::components::StyleSystem
 Computes stylesheet information for elements, applying the CSS cascade and inheritance rules. More...
 

Detailed Description

Systems are the core of the ECS architecture. They contain the logic and are responsible for updating the components of entities.


Class Documentation

◆ donner::svg::components::FilterSystem

class donner::svg::components::FilterSystem

Handles parsing and instantiating SVG filter effects from the SVG DOM.

See also
https://drafts.fxtf.org/filter-effects/

Public Member Functions

void createComputedFilter (EntityHandle handle, const FilterComponent &component, std::vector< parser::ParseError > *outWarnings)
 Create ComputedFilterComponent for the given entity, applying style information and style inheritance.
 
void instantiateAllComputedComponents (Registry &registry, std::vector< parser::ParseError > *outWarnings)
 Create all ComputedFilterComponent in the tree.
 

Member Function Documentation

◆ createComputedFilter()

void donner::svg::components::FilterSystem::createComputedFilter ( EntityHandle handle,
const FilterComponent & component,
std::vector< parser::ParseError > * outWarnings )

Create ComputedFilterComponent for the given entity, applying style information and style inheritance.

Parameters
handleEntity handle to apply the filter to.
componentFilter effect for the current entity, so that this may only be called if one is present.
outWarningsWarnings generated during parsing.

◆ instantiateAllComputedComponents()

void donner::svg::components::FilterSystem::instantiateAllComputedComponents ( Registry & registry,
std::vector< parser::ParseError > * outWarnings )

Create all ComputedFilterComponent in the tree.

Parameters
registryRegistry to operate on.
outWarningsWarnings generated during parsing.

◆ donner::svg::components::LayoutSystem

class donner::svg::components::LayoutSystem

Handles layout and bounds calculations for SVG elements.

This system is responsible for calculating the the document size, viewboxes, and the bounds for elements.

See also
https://www.w3.org/TR/SVG2/coords.html

Public Types

enum class  InvalidSizeBehavior {
  ZeroSize ,
  ReturnDefault
}
 Controls the behavior of LayoutSystem::calculateCanvasScaledDocumentSize for invalid sizes. More...
 

Public Member Functions

Regular properties
std::optional< float > intrinsicAspectRatio (EntityHandle entity) const
 Calculate the intrinsic aspect ratio per https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS, which defines how content is scaled to fit the viewport.
 
Vector2i calculateDocumentSize (Registry &registry) const
 Calculate the document size of the current entity.
 
Boxd getViewport (EntityHandle entity)
 Get the viewport affecting the current entity.
 
bool overridesViewport (EntityHandle entity) const
 Returns true if the given entity overrides the viewport.
 
Vector2i calculateCanvasScaledDocumentSize (Registry &registry, InvalidSizeBehavior behavior) const
 Get the document size scaled to fit the canvas.
 
Transformd getEntityFromParentTranform (EntityHandle entity)
 Get the entity-from-parent transform for the current entity.
 
Transformd getEntityContentFromEntityTransform (EntityHandle entity)
 Get the transform for entityContent-from-entity, which is an additional transform for specific elements that define their own coordinate system, such as nested "<svg>" and "<use>" elements.
 
void setEntityFromParentTransform (EntityHandle entity, const Transformd &entityFromParent)
 Set the entity-from-parent transform for the current entity.
 
Transformd getEntityFromWorldTransform (EntityHandle entity)
 Get the entity-from-world transform for the current entity, representing the entity position relative to the world after applying all parent transformations.
 
void invalidate (EntityHandle entity)
 Invalidate cached state for the current entity, such as the computed viewport and entity-from-world transform.
 
Computed properties
void instantiateAllComputedComponents (Registry &registry, std::vector< parser::ParseError > *outWarnings)
 Create all computed components, such as ComputedViewboxComponent and ComputedSizedElementComponent.
 
Boxd computeSizeProperties (EntityHandle entity, const SizedElementProperties &sizeProperties, const std::map< RcString, parser::UnparsedProperty > &unparsedProperties, const Boxd &viewbox, FontMetrics fontMetrics, std::vector< parser::ParseError > *outWarnings)
 Evaluates SizedElementProperties and returns the resulting bounds, using precomputed style information.
 
const ComputedSizedElementComponentcreateComputedSizedElementComponentWithStyle (EntityHandle handle, const ComputedStyleComponent &style, FontMetrics fontMetrics, std::vector< parser::ParseError > *outWarnings)
 Creates a ComputedSizedElementComponent for the linked entity, using precomputed style information.
 
const ComputedLocalTransformComponentcreateComputedLocalTransformComponentWithStyle (EntityHandle handle, const ComputedStyleComponent &style, const FontMetrics &fontMetrics, std::vector< parser::ParseError > *outWarnings)
 Creates a ComputedLocalTransformComponent for the linked entity, using precomputed style information.
 
std::optional< BoxdclipRect (EntityHandle handle) const
 If this element establishes a clipping context, returns the clip rect in the parent's coordinate system.
 
Transformd computeSizedElementTransform (EntityHandle handle, const ComputedSizedElementComponent &computedSizedElement) const
 Computes the transformation from the parent's coordinate system into the coordinate system established by this sized element.
 

Member Enumeration Documentation

◆ InvalidSizeBehavior

Controls the behavior of LayoutSystem::calculateCanvasScaledDocumentSize for invalid sizes.

Enumerator
ZeroSize 

Return a size of 0x0.

ReturnDefault 

Return the default document size (512x512).

Member Function Documentation

◆ calculateCanvasScaledDocumentSize()

Vector2i donner::svg::components::LayoutSystem::calculateCanvasScaledDocumentSize ( Registry & registry,
InvalidSizeBehavior behavior ) const

Get the document size scaled to fit the canvas.

Parameters
registryECS registry
behaviorControls the behavior when the document size is invalid, either returning a default size or empty box.

◆ calculateDocumentSize()

Vector2i donner::svg::components::LayoutSystem::calculateDocumentSize ( Registry & registry) const

Calculate the document size of the current entity.

This is the size of the document viewport (the area that the SVG content is rendered into).

Parameters
registryECS registry

◆ clipRect()

std::optional< Boxd > donner::svg::components::LayoutSystem::clipRect ( EntityHandle handle) const

If this element establishes a clipping context, returns the clip rect in the parent's coordinate system.

Parameters
handleEntity handle.
Returns
std::optional<Boxd> Clip rect, or std::nullopt if this element does not establish a clipping context.

◆ computeSizedElementTransform()

Transformd donner::svg::components::LayoutSystem::computeSizedElementTransform ( EntityHandle handle,
const ComputedSizedElementComponent & computedSizedElement ) const

Computes the transformation from the parent's coordinate system into the coordinate system established by this sized element.

Parameters
handleEntity handle.
computedSizedElementPrecomputed sized element information.
Returns
Transformd Transformation from the parent's coordinate system into the sized element's coordinate system.

◆ computeSizeProperties()

Boxd donner::svg::components::LayoutSystem::computeSizeProperties ( EntityHandle entity,
const SizedElementProperties & sizeProperties,
const std::map< RcString, parser::UnparsedProperty > & unparsedProperties,
const Boxd & viewbox,
FontMetrics fontMetrics,
std::vector< parser::ParseError > * outWarnings )

Evaluates SizedElementProperties and returns the resulting bounds, using precomputed style information.

Parameters
entityEntity handle.
sizePropertiesSize properties to evaluate.
unparsedPropertiesUnparsed properties to evaluate.
viewboxViewbox to use when converting size percentages.
fontMetricsFont metrics, used to scale lengths.
outWarningsOutput vector of parse errors, if any.
Returns
Computed bounds.

◆ createComputedLocalTransformComponentWithStyle()

const ComputedLocalTransformComponent & donner::svg::components::LayoutSystem::createComputedLocalTransformComponentWithStyle ( EntityHandle handle,
const ComputedStyleComponent & style,
const FontMetrics & fontMetrics,
std::vector< parser::ParseError > * outWarnings )

Creates a ComputedLocalTransformComponent for the linked entity, using precomputed style information.

Parameters
handleEntity handle.
stylePrecomputed style information for this element
fontMetricsFont metrics, used to scale lengths
outWarningsOutput vector of parse errors, if any.

◆ createComputedSizedElementComponentWithStyle()

const ComputedSizedElementComponent & donner::svg::components::LayoutSystem::createComputedSizedElementComponentWithStyle ( EntityHandle handle,
const ComputedStyleComponent & style,
FontMetrics fontMetrics,
std::vector< parser::ParseError > * outWarnings )

Creates a ComputedSizedElementComponent for the linked entity, using precomputed style information.

Parameters
handleEntity handle.
stylePrecomputed style information for this element
fontMetricsFont metrics, used to scale lengths
outWarningsOutput vector of parse errors, if any.
Returns
reference to the computed component

◆ getEntityContentFromEntityTransform()

Transformd donner::svg::components::LayoutSystem::getEntityContentFromEntityTransform ( EntityHandle entity)

Get the transform for entityContent-from-entity, which is an additional transform for specific elements that define their own coordinate system, such as nested "<svg>" and "<use>" elements.

This transform is used to convert coordinates from the entity's coordinate system to the coordinate system of its content.

For example, a nested SVG element, where for the inner SVG element the content transform is scale(2) translate(50 50):

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<svg x="50" y="50" width="100" height="100" viewBox="0 0 50 50">
<rect x="0" y="0" width="50" height="50" fill="red"/>
</svg>
</svg>
Parameters
entityCurrent entity.

◆ getEntityFromParentTranform()

Transformd donner::svg::components::LayoutSystem::getEntityFromParentTranform ( EntityHandle entity)

Get the entity-from-parent transform for the current entity.

Parameters
entityCurrent entity.

◆ getEntityFromWorldTransform()

Transformd donner::svg::components::LayoutSystem::getEntityFromWorldTransform ( EntityHandle entity)

Get the entity-from-world transform for the current entity, representing the entity position relative to the world after applying all parent transformations.

Parameters
entityCurrent entity.

◆ getViewport()

Boxd donner::svg::components::LayoutSystem::getViewport ( EntityHandle entity)

Get the viewport affecting the current entity.

This may be the viewport of a viewport-defining parent element or the document viewport.

Parameters
entityCurrent entity.

◆ instantiateAllComputedComponents()

void donner::svg::components::LayoutSystem::instantiateAllComputedComponents ( Registry & registry,
std::vector< parser::ParseError > * outWarnings )

Create all computed components, such as ComputedViewboxComponent and ComputedSizedElementComponent.

Parameters
registryECS registry.
outWarningsOutput vector of parse errors, if any.

◆ intrinsicAspectRatio()

std::optional< float > donner::svg::components::LayoutSystem::intrinsicAspectRatio ( EntityHandle entity) const

Calculate the intrinsic aspect ratio per https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS, which defines how content is scaled to fit the viewport.

This may return std::nullopt if the aspect ratio is not defined.

Parameters
entityCurrent entity.

◆ invalidate()

void donner::svg::components::LayoutSystem::invalidate ( EntityHandle entity)

Invalidate cached state for the current entity, such as the computed viewport and entity-from-world transform.

Parameters
entityCurrent entity.

◆ overridesViewport()

bool donner::svg::components::LayoutSystem::overridesViewport ( EntityHandle entity) const

Returns true if the given entity overrides the viewport.

Parameters
entityCurrent entity.

◆ setEntityFromParentTransform()

void donner::svg::components::LayoutSystem::setEntityFromParentTransform ( EntityHandle entity,
const Transformd & entityFromParent )

Set the entity-from-parent transform for the current entity.

Parameters
entityCurrent entity.
entityFromParentNew transform.

◆ donner::svg::components::PaintSystem

class donner::svg::components::PaintSystem

Manages Paint Servers for gradients and patterns, handling style and structural inheritance and creating "computed" state and shadow trees for these elements.

See also
https://www.w3.org/TR/SVG2/pservers.html

Public Member Functions

const ComputedStopComponentcreateComputedStop (EntityHandle handle, const StopComponent &stop, std::vector< parser::ParseError > *outWarnings)
 Create a ComputedStopComponent for the given entity handle and its attached StopComponent, which applies CSS styling information and presentation attributes.
 
void instantiateAllComputedComponents (Registry &registry, std::vector< parser::ParseError > *outWarnings)
 Create ComputedGradientComponent for all entities in the registry that have a GradientComponent.
 
void createShadowTrees (Registry &registry, std::vector< parser::ParseError > *outWarnings)
 Create shadow trees for all gradient and pattern elements in the registry that have a valid href="" attribute.
 

Member Function Documentation

◆ createComputedStop()

const ComputedStopComponent & donner::svg::components::PaintSystem::createComputedStop ( EntityHandle handle,
const StopComponent & stop,
std::vector< parser::ParseError > * outWarnings )

Create a ComputedStopComponent for the given entity handle and its attached StopComponent, which applies CSS styling information and presentation attributes.

Parameters
handleEntity handle to create the computed gradient for
stopStop component attached to handle
outWarningsContaining any warnings found

◆ createShadowTrees()

void donner::svg::components::PaintSystem::createShadowTrees ( Registry & registry,
std::vector< parser::ParseError > * outWarnings )

Create shadow trees for all gradient and pattern elements in the registry that have a valid href="" attribute.

This must be called before instantiateAllComputedComponents.

Parameters
registryRegistry used to find all GradientComponent and PatternComponent components to compute shadow trees
outWarningsContaining any warnings found

◆ instantiateAllComputedComponents()

void donner::svg::components::PaintSystem::instantiateAllComputedComponents ( Registry & registry,
std::vector< parser::ParseError > * outWarnings )

Create ComputedGradientComponent for all entities in the registry that have a GradientComponent.

This assumes that createShadowTrees has already been called.

Note that this function does not produce any warnings, its signature is used to create a common API pattern.

Parameters
registryRegistry used to find all GradientComponent
outWarningsContaining any warnings found

◆ donner::svg::components::ShadowTreeSystem

class donner::svg::components::ShadowTreeSystem

Instantiates shadow trees for elements that are not part of the main render graph, such as "<use>" and "<pattern>" elements.

See also
https://www.w3.org/TR/SVG2/struct.html#UseShadowTree
https://www.w3.org/TR/SVG2/pservers.html#PaintServerTemplates

Public Member Functions

void teardown (Registry &registry, ComputedShadowTreeComponent &shadow)
 Destroy the instantiated shadow tree.
 
std::optional< size_t > populateInstance (EntityHandle entity, ComputedShadowTreeComponent &shadow, ShadowBranchType branchType, Entity lightTarget, const RcString &href, std::vector< parser::ParseError > *outWarnings)
 Create a new computed shadow tree instance, such as the shadow tree for a "<use>" element or a "<pattern>" element.
 

Member Function Documentation

◆ populateInstance()

std::optional< size_t > donner::svg::components::ShadowTreeSystem::populateInstance ( EntityHandle entity,
ComputedShadowTreeComponent & shadow,
ShadowBranchType branchType,
Entity lightTarget,
const RcString & href,
std::vector< parser::ParseError > * outWarnings )

Create a new computed shadow tree instance, such as the shadow tree for a "<use>" element or a "<pattern>" element.

For "<pattern>" paint servers, there may be multiple shadow trees originating from the same entity, for both a 'fill' and a 'stroke', so this component can hold multiple shadow trees simultaneously.

Parameters
entityThe entity to create the shadow tree for.
shadowThe computed shadow tree component to populate.
branchTypeDetermines which branch of the tree to attach to. There may be multiple instances with a shadow tree, but only ShadowBranchType::Main will be traversed in the render tree.
lightTargetTarget entity to reflect in the shadow tree.
hrefThe value of the href attribute for the shadow tree, for diagnostics.
outWarningsIf provided, warnings will be added to this vector.
Returns
The index of the offscreen shadow tree, if branchType is not the ShadowBranchType::Main branch. Returns std::nullopt if it is.

◆ teardown()

void donner::svg::components::ShadowTreeSystem::teardown ( Registry & registry,
ComputedShadowTreeComponent & shadow )

Destroy the instantiated shadow tree.

Parameters
registryThe registry.
shadowThe computed shadow tree component to tear down.

◆ donner::svg::components::ShapeSystem

class donner::svg::components::ShapeSystem

Creates computed path for shapes such as "<circle>", "<line>", and "<path>".

See also
https://www.w3.org/TR/SVG2/shapes.html

Public Member Functions

template<typename T >
ComputedPathComponentcreateComputedPath (EntityHandle handle, const T &component, const FontMetrics &fontMetrics, std::vector< parser::ParseError > *outWarnings)
 Convert the given shape to a path, evaluating CSS styling information and presentation attributes.
 
ComputedPathComponentcreateComputedPathIfShape (EntityHandle handle, const FontMetrics &fontMetrics, std::vector< parser::ParseError > *outWarnings)
 Convert the given shape to a path, if the provided entity contains a shape.
 
void instantiateAllComputedPaths (Registry &registry, std::vector< parser::ParseError > *outWarnings)
 Create ComputedPathComponent for all entities in the registry that have a shape component.
 
std::optional< BoxdgetShapeBounds (EntityHandle handle)
 Get the bounds for the given entity in the entity's local space, if it has a shape component.
 
std::optional< BoxdgetShapeWorldBounds (EntityHandle handle)
 Get the bounds for the given entity in world space, if it has a shape component.
 
bool pathFillIntersects (EntityHandle handle, const Vector2d &point, FillRule fillRule)
 Returns true if the shape's path fill intersects the given point.
 
bool pathStrokeIntersects (EntityHandle handle, const Vector2d &point, double strokeWidth)
 Returns true if the shape's path stroke intersects the given point, using an approximate computation from the stroke-width.
 

Member Function Documentation

◆ createComputedPath()

template<typename T >
ComputedPathComponent * donner::svg::components::ShapeSystem::createComputedPath ( EntityHandle handle,
const T & component,
const FontMetrics & fontMetrics,
std::vector< parser::ParseError > * outWarnings )
inline

Convert the given shape to a path, evaluating CSS styling information and presentation attributes.

Returns the ComputedPathComponent if the path was successfully created, or nullptr if the path could not be created.

Paths may not be created if the shape is invalid, such as a circle with a negative radius.

Suported components:

Parameters
handleEntity handle to create the computed path for
componentShape component attached to handle
fontMetricsFont metrics, used to scale lengths
outWarningsContaining any warnings found

◆ createComputedPathIfShape()

ComputedPathComponent * donner::svg::components::ShapeSystem::createComputedPathIfShape ( EntityHandle handle,
const FontMetrics & fontMetrics,
std::vector< parser::ParseError > * outWarnings )

Convert the given shape to a path, if the provided entity contains a shape.

Returns the ComputedPathComponent if the path was successfully created, or nullptr if the path could not be created.

Paths may not be created if the shape is invalid, such as a circle with a negative radius.

Parameters
handleEntity handle to create the computed path for
fontMetricsFont metrics, used to scale lengths
outWarningsContaining any warnings found

◆ getShapeBounds()

std::optional< Boxd > donner::svg::components::ShapeSystem::getShapeBounds ( EntityHandle handle)

Get the bounds for the given entity in the entity's local space, if it has a shape component.

Parameters
handleEntity handle to get the bounds for

◆ getShapeWorldBounds()

std::optional< Boxd > donner::svg::components::ShapeSystem::getShapeWorldBounds ( EntityHandle handle)

Get the bounds for the given entity in world space, if it has a shape component.

Parameters
handleEntity handle to get the bounds for

◆ instantiateAllComputedPaths()

void donner::svg::components::ShapeSystem::instantiateAllComputedPaths ( Registry & registry,
std::vector< parser::ParseError > * outWarnings )

Create ComputedPathComponent for all entities in the registry that have a shape component.

This assumes that StyleSystem::computeAllStyles has already been called.

Parameters
registryRegistry used to find all shape components
outWarningsContaining any warnings found

◆ pathFillIntersects()

bool donner::svg::components::ShapeSystem::pathFillIntersects ( EntityHandle handle,
const Vector2d & point,
FillRule fillRule )

Returns true if the shape's path fill intersects the given point.

Parameters
handleEntity handle containing the shape
pointPoint to intersect
fillRuleFill rule to use for the intersection test

◆ pathStrokeIntersects()

bool donner::svg::components::ShapeSystem::pathStrokeIntersects ( EntityHandle handle,
const Vector2d & point,
double strokeWidth )

Returns true if the shape's path stroke intersects the given point, using an approximate computation from the stroke-width.

Parameters
handleEntity handle containing the shape
pointPoint to intersect
strokeWidthStroke width to use for the intersection test

◆ donner::svg::components::StyleSystem

class donner::svg::components::StyleSystem

Computes stylesheet information for elements, applying the CSS cascade and inheritance rules.

See also
https://www.w3.org/TR/SVG2/shapes.html

Public Member Functions

const ComputedStyleComponentcomputeStyle (EntityHandle handle, std::vector< parser::ParseError > *outWarnings)
 Compute the style for the given entity handle, applying the CSS cascade and inheritance rules.
 
void computeAllStyles (Registry &registry, std::vector< parser::ParseError > *outWarnings)
 Computes the style for all entities in the registry.
 
void computeStylesFor (Registry &registry, std::span< const Entity > entities, std::vector< parser::ParseError > *outWarnings)
 Computes the style for the given entities in the registry.
 

Member Function Documentation

◆ computeAllStyles()

void donner::svg::components::StyleSystem::computeAllStyles ( Registry & registry,
std::vector< parser::ParseError > * outWarnings )

Computes the style for all entities in the registry.

Parameters
registryRegistry to compute the styles, used to query for all entities in the tree.
outWarningsContaining any warnings found

◆ computeStyle()

const ComputedStyleComponent & donner::svg::components::StyleSystem::computeStyle ( EntityHandle handle,
std::vector< parser::ParseError > * outWarnings )

Compute the style for the given entity handle, applying the CSS cascade and inheritance rules.

Parameters
handleEntity handle to compute the style for
outWarningsContaining any warnings found
Returns
Computed style component for the entity

◆ computeStylesFor()

void donner::svg::components::StyleSystem::computeStylesFor ( Registry & registry,
std::span< const Entity > entities,
std::vector< parser::ParseError > * outWarnings )

Computes the style for the given entities in the registry.

Parameters
registryRegistry containing the entities
entitiesEntities to compute
outWarningsContaining any warnings found