Systems hold the logic of the ECS architecture and are responsible for updating the components of entities. More...
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... | |
| class | donner::svg::components::TextSystem |
| System to compute text layout spans from raw text and positioning attributes. More... | |
Systems hold the logic of the ECS architecture and are responsible for updating the components of entities.
Systems may depend on other systems, but there are no circular dependencies.
graph LR
LayoutSystem
ShapeSystem
StyleSystem
PaintSystem
ShadowTreeSystem
FilterSystem
ShapeSystem --> LayoutSystem
ShapeSystem --> StyleSystem
LayoutSystem --> StyleSystem
PaintSystem --> StyleSystem
| class donner::svg::components::FilterSystem |
Handles parsing and instantiating SVG filter effects from the SVG DOM.
Public Member Functions | |
| void | createComputedFilter (EntityHandle handle, const FilterComponent &component, ParseWarningSink &warningSink) |
| Create ComputedFilterComponent for the given entity, applying style information and style inheritance. | |
| void | instantiateAllComputedComponents (Registry ®istry, ParseWarningSink &warningSink) |
| Create all ComputedFilterComponent in the tree. | |
| void donner::svg::components::FilterSystem::createComputedFilter | ( | EntityHandle | handle, |
| const FilterComponent & | component, | ||
| ParseWarningSink & | warningSink ) |
Create ComputedFilterComponent for the given entity, applying style information and style inheritance.
| handle | Entity handle to apply the filter to. |
| component | Filter effect for the current entity, so that this may only be called if one is present. |
| warningSink | Warnings generated during parsing. |
| void donner::svg::components::FilterSystem::instantiateAllComputedComponents | ( | Registry & | registry, |
| ParseWarningSink & | warningSink ) |
Create all ComputedFilterComponent in the tree.
| registry | Registry to operate on. |
| warningSink | Warnings generated during parsing. |
| 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.
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 ®istry) const |
| Calculate the document size of the current entity. | |
| Box2d | getViewBox (EntityHandle entity) |
| Get the viewBox affecting the current entity. | |
| bool | overridesViewBox (EntityHandle entity) const |
| Returns true if the given entity overrides the viewBox. | |
| Vector2i | calculateCanvasScaledDocumentSize (Registry ®istry, InvalidSizeBehavior behavior) const |
| Get the document size scaled to fit the canvas. | |
| Transform2d | getRawEntityFromParentTransform (EntityHandle entity) |
| Returns the parentFromEntity transform without modifiers (e.g. | |
| Transform2d | getEntityFromParentTransform (EntityHandle entity) |
| Returns the parentFromEntity transform with modifiers. | |
| Transform2d | getCanvasFromDocumentTransform (Registry ®istry) |
| Get the transform that maps viewBox-space points to canvas-scaled output space, baking in the root preserveAspectRatio fit. | |
| Transform2d | 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. | |
| Transform2d | getEntityContentFromParentTransform (EntityHandle entity) |
| Get the entityContent-from-parent transform: getEntityContentFromEntityTransform composed with the entity's own transform, or with no transform for elements whose rendering behavior ignores it. | |
| void | setRawEntityFromParentTransform (EntityHandle entity, const Transform2d &parentFromEntity) |
| Set the parentFromEntity transform for the current entity. | |
| const ComputedAbsoluteTransformComponent & | getAbsoluteTransformComponent (EntityHandle entity) |
| Get the computed absolute transform for the current entity. | |
| Transform2d | 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, bool viewportChanged=false) |
| Invalidate cached state for the current entity, such as the computed viewBox and entity-from-world transform. | |
| void | invalidateAbsoluteTransforms (EntityHandle entity) |
Drop the cached absolute transforms of entity and its descendants, which depend on where the entity is placed, while keeping its computed size, viewBox and local transform. | |
Computed properties | |
| void | instantiateAllComputedComponents (Registry ®istry, ParseWarningSink &warningSink) |
| Create all computed components, such as ComputedViewBoxComponent and ComputedSizedElementComponent. | |
| void | recomputeInvalidatedLayout (EntityHandle entity, ParseWarningSink &warningSink) |
| Recreate the computed layout of one entity that invalidate dropped while its viewport stayed the same (for example after a transform write), matching what instantiateAllComputedComponents computes for it: its computed size, local transform and viewBox. | |
| SizedElementProperties | resolveSizeProperties (const SizedElementProperties &sizeProperties, const std::map< RcString, parser::UnparsedProperty > &unparsedProperties, ParseWarningSink &warningSink) |
| Apply the size-property cascade while preserving unresolved lengths. | |
| Box2d | computeSizeProperties (EntityHandle entity, const SizedElementProperties &sizeProperties, const std::map< RcString, parser::UnparsedProperty > &unparsedProperties, const Box2d &viewBox, FontMetrics fontMetrics, ParseWarningSink &warningSink) |
| Evaluates SizedElementProperties and returns the resulting bounds, using precomputed style information. | |
| bool | createShadowSizedElementComponent (Registry ®istry, Entity shadowEntity, EntityHandle useEntity, Entity symbolEntity, ShadowBranchType branchType, ParseWarningSink &warningSink) |
| Creates a ComputedShadowSizedElementComponent for shadow trees where a parent element's size properties should override target element's size properties (e.g., use element overriding symbol element's size). | |
| const ComputedSizedElementComponent & | createComputedSizedElementComponentWithStyle (EntityHandle handle, const ComputedStyleComponent &style, FontMetrics fontMetrics, ParseWarningSink &warningSink) |
| Creates a ComputedSizedElementComponent for the linked entity, using precomputed style information. | |
| const ComputedLocalTransformComponent & | createComputedLocalTransformComponentWithStyle (EntityHandle handle, const ComputedStyleComponent &style, const FontMetrics &fontMetrics, ParseWarningSink &warningSink) |
| Creates a ComputedLocalTransformComponent for the linked entity, using precomputed style information. | |
| std::optional< Box2d > | clipRect (EntityHandle handle) const |
| If this element establishes a clipping context, returns the clip rect in the parent's coordinate system. | |
| Transform2d | elementContentFromViewBoxTransform (EntityHandle handle, const ComputedSizedElementComponent &computedSizedElement) const |
| Computes the elementContent-from-viewBox transform (using dest-from-source notation), from the from the parent's coordinate system (resized to the viewBox of this element) to the element's coordinate system for children (content). | |
|
strong |
Controls the behavior of LayoutSystem::calculateCanvasScaledDocumentSize for invalid sizes.
| Enumerator | |
|---|---|
| ZeroSize | Return a size of 0x0. |
| ReturnDefault | Return the default document size (512x512). |
| Vector2i donner::svg::components::LayoutSystem::calculateCanvasScaledDocumentSize | ( | Registry & | registry, |
| InvalidSizeBehavior | behavior ) const |
Get the document size scaled to fit the canvas.
| registry | ECS registry |
| behavior | Controls the behavior when the document size is invalid, either returning a default size or empty box. |
Calculate the document size of the current entity.
This is the size of the document viewBox (the area that the SVG content is rendered into).
| registry | ECS registry |
| std::optional< Box2d > 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.
| handle | Entity handle. |
| Box2d donner::svg::components::LayoutSystem::computeSizeProperties | ( | EntityHandle | entity, |
| const SizedElementProperties & | sizeProperties, | ||
| const std::map< RcString, parser::UnparsedProperty > & | unparsedProperties, | ||
| const Box2d & | viewBox, | ||
| FontMetrics | fontMetrics, | ||
| ParseWarningSink & | warningSink ) |
Evaluates SizedElementProperties and returns the resulting bounds, using precomputed style information.
| entity | Entity handle. |
| sizeProperties | Size properties to evaluate. |
| unparsedProperties | Unparsed properties to evaluate. |
| viewBox | ViewBox to use when converting size percentages. |
| fontMetrics | Font metrics, used to scale lengths. |
| warningSink | Output vector of parse errors, if any. |
| const ComputedLocalTransformComponent & donner::svg::components::LayoutSystem::createComputedLocalTransformComponentWithStyle | ( | EntityHandle | handle, |
| const ComputedStyleComponent & | style, | ||
| const FontMetrics & | fontMetrics, | ||
| ParseWarningSink & | warningSink ) |
Creates a ComputedLocalTransformComponent for the linked entity, using precomputed style information.
| handle | Entity handle. |
| style | Precomputed style information for this element |
| fontMetrics | Font metrics, used to scale lengths |
| warningSink | Output vector of parse errors, if any. |
| const ComputedSizedElementComponent & donner::svg::components::LayoutSystem::createComputedSizedElementComponentWithStyle | ( | EntityHandle | handle, |
| const ComputedStyleComponent & | style, | ||
| FontMetrics | fontMetrics, | ||
| ParseWarningSink & | warningSink ) |
Creates a ComputedSizedElementComponent for the linked entity, using precomputed style information.
| handle | Entity handle. |
| style | Precomputed style information for this element |
| fontMetrics | Font metrics, used to scale lengths |
| warningSink | Output vector of parse errors, if any. |
| bool donner::svg::components::LayoutSystem::createShadowSizedElementComponent | ( | Registry & | registry, |
| Entity | shadowEntity, | ||
| EntityHandle | useEntity, | ||
| Entity | symbolEntity, | ||
| ShadowBranchType | branchType, | ||
| ParseWarningSink & | warningSink ) |
Creates a ComputedShadowSizedElementComponent for shadow trees where a parent element's size properties should override target element's size properties (e.g., use element overriding symbol element's size).
| registry | ECS registry. |
| shadowEntity | The shadow entity to create a computed component for. |
| useEntity | The source <use> that may provide size override. |
| symbolEntity | The target <symbol> entity whose properties might be overridden. |
| branchType | The type of branch being created. |
| warningSink | Output vector of parse errors, if any. |
| Transform2d donner::svg::components::LayoutSystem::elementContentFromViewBoxTransform | ( | EntityHandle | handle, |
| const ComputedSizedElementComponent & | computedSizedElement ) const |
Computes the elementContent-from-viewBox transform (using dest-from-source notation), from the from the parent's coordinate system (resized to the viewBox of this element) to the element's coordinate system for children (content).
| handle | Entity handle. |
| computedSizedElement | Precomputed sized element information. |
| const ComputedAbsoluteTransformComponent & donner::svg::components::LayoutSystem::getAbsoluteTransformComponent | ( | EntityHandle | entity | ) |
Get the computed absolute transform for the current entity.
This is the same as getEntityFromWorldTransform except it returns the component containing additional flags as well.
| entity | Current entity. |
| Transform2d donner::svg::components::LayoutSystem::getCanvasFromDocumentTransform | ( | Registry & | registry | ) |
Get the transform that maps viewBox-space points to canvas-scaled output space, baking in the root preserveAspectRatio fit.
Despite the previous getDocumentFromCanvasTransform name, this is a canvasFromDocument transform (input = document/viewBox, output = canvas).
| registry | ECS registry |
| Transform2d 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):
| entity | Current entity. |
| Transform2d donner::svg::components::LayoutSystem::getEntityContentFromParentTransform | ( | EntityHandle | entity | ) |
Get the entityContent-from-parent transform: getEntityContentFromEntityTransform composed with the entity's own transform, or with no transform for elements whose rendering behavior ignores it.
Each ancestor contributes this factor to an absolute transform.
| entity | Current entity. |
| Transform2d donner::svg::components::LayoutSystem::getEntityFromParentTransform | ( | EntityHandle | entity | ) |
Returns the parentFromEntity transform with modifiers.
| entity | Current entity. |
| Transform2d 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.
| entity | Current entity. |
| Transform2d donner::svg::components::LayoutSystem::getRawEntityFromParentTransform | ( | EntityHandle | entity | ) |
Returns the parentFromEntity transform without modifiers (e.g.
not including transform-origin)
| entity | Current entity. |
| Box2d donner::svg::components::LayoutSystem::getViewBox | ( | EntityHandle | entity | ) |
Get the viewBox affecting the current entity.
This may be the viewBox of a viewBox-defining parent element or the document viewBox.
| entity | Current entity. |
| void donner::svg::components::LayoutSystem::instantiateAllComputedComponents | ( | Registry & | registry, |
| ParseWarningSink & | warningSink ) |
Create all computed components, such as ComputedViewBoxComponent and ComputedSizedElementComponent.
| registry | ECS registry. |
| warningSink | Output vector of parse errors, if any. |
| 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.
| entity | Current entity. |
| void donner::svg::components::LayoutSystem::invalidate | ( | EntityHandle | entity, |
| bool | viewportChanged = false ) |
Invalidate cached state for the current entity, such as the computed viewBox and entity-from-world transform.
| entity | Current entity. |
| viewportChanged | Also invalidate descendant viewport-dependent layout caches. |
| void donner::svg::components::LayoutSystem::invalidateAbsoluteTransforms | ( | EntityHandle | entity | ) |
Drop the cached absolute transforms of entity and its descendants, which depend on where the entity is placed, while keeping its computed size, viewBox and local transform.
Marks nothing dirty.
| entity | Root of the subtree. |
| bool donner::svg::components::LayoutSystem::overridesViewBox | ( | EntityHandle | entity | ) | const |
Returns true if the given entity overrides the viewBox.
| entity | Current entity. |
| void donner::svg::components::LayoutSystem::recomputeInvalidatedLayout | ( | EntityHandle | entity, |
| ParseWarningSink & | warningSink ) |
Recreate the computed layout of one entity that invalidate dropped while its viewport stayed the same (for example after a transform write), matching what instantiateAllComputedComponents computes for it: its computed size, local transform and viewBox.
Descendants keep their computed layout; only their absolute transforms were dropped, and those are recomputed on demand.
| entity | Entity whose layout was invalidated. Must have a computed style. |
| warningSink | Output vector of parse errors, if any. |
| SizedElementProperties donner::svg::components::LayoutSystem::resolveSizeProperties | ( | const SizedElementProperties & | sizeProperties, |
| const std::map< RcString, parser::UnparsedProperty > & | unparsedProperties, | ||
| ParseWarningSink & | warningSink ) |
Apply the size-property cascade while preserving unresolved lengths.
| sizeProperties | Typed properties, including their cascade specificity. |
| unparsedProperties | CSS declarations to apply. |
| warningSink | Destination for invalid-property diagnostics. |
| void donner::svg::components::LayoutSystem::setRawEntityFromParentTransform | ( | EntityHandle | entity, |
| const Transform2d & | parentFromEntity ) |
Set the parentFromEntity transform for the current entity.
This will be transformed with modifiers such as transform-origin before being applied to the entity.
| entity | Current entity. |
| parentFromEntity | New transform. |
| 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.
Public Member Functions | |
| const ComputedStopComponent & | createComputedStop (EntityHandle handle, const StopComponent &stop, ParseWarningSink &warningSink) |
| Create a ComputedStopComponent for the given entity handle and its attached StopComponent, which applies CSS styling information and presentation attributes. | |
| void | instantiateAllComputedComponents (Registry ®istry, ParseWarningSink &warningSink) |
| Create ComputedGradientComponent for all entities in the registry that have a GradientComponent. | |
| void | createShadowTrees (Registry ®istry, ParseWarningSink &warningSink) |
| Create shadow trees for all gradient and pattern elements in the registry that have a valid href="" attribute. | |
| const ComputedStopComponent & donner::svg::components::PaintSystem::createComputedStop | ( | EntityHandle | handle, |
| const StopComponent & | stop, | ||
| ParseWarningSink & | warningSink ) |
Create a ComputedStopComponent for the given entity handle and its attached StopComponent, which applies CSS styling information and presentation attributes.
| handle | Entity handle to create the computed gradient for |
| stop | Stop component attached to handle |
| warningSink | Containing any warnings found |
| void donner::svg::components::PaintSystem::createShadowTrees | ( | Registry & | registry, |
| ParseWarningSink & | warningSink ) |
Create shadow trees for all gradient and pattern elements in the registry that have a valid href="" attribute.
This must be called before instantiateAllComputedComponents.
| registry | Registry used to find all GradientComponent and PatternComponent components to compute shadow trees |
| warningSink | Containing any warnings found |
| void donner::svg::components::PaintSystem::instantiateAllComputedComponents | ( | Registry & | registry, |
| ParseWarningSink & | warningSink ) |
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.
| registry | Registry used to find all GradientComponent |
| warningSink | Containing any warnings found |
| 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.
Public Member Functions | |
| ShadowTreeSystem (ShadowSizedElementHandler sizedElementHandler=nullptr) | |
| Constructor. | |
| void | teardown (Registry ®istry, ComputedShadowTreeComponent &shadow) |
| Destroy the instantiated shadow tree. | |
| void | teardownInstances (EntityHandle handle) |
Destroy every shadow tree instantiated on handle, if any. | |
| std::optional< size_t > | populateInstance (EntityHandle entity, ComputedShadowTreeComponent &shadow, ShadowBranchType branchType, Entity lightTarget, const RcString &href, ParseWarningSink &warningSink) |
| Create a new computed shadow tree instance, such as the shadow tree for a <use> element or a <pattern> element. | |
Static Public Member Functions | |
| static void | beginRebuild (Registry ®istry) |
| Reset aggregate shadow admission before a full render-tree rebuild. | |
| static bool | appendStyleOccurrences (Registry ®istry, std::vector< Entity > &entities) |
| Include the live in-document copies of affected sources and their shadow descendants. | |
|
inlineexplicit |
Constructor.
| sizedElementHandler | Optional callback for handling sized elements in shadow trees. |
|
staticnodiscard |
Include the live in-document copies of affected sources and their shadow descendants.
The caller validates the selector dependency and old computed style of every returned entity before it removes any computed styles.
| registry | Document registry, held for mutation. |
| entities | Affected light entities. Shadow entities are appended on success. |
| std::optional< size_t > donner::svg::components::ShadowTreeSystem::populateInstance | ( | EntityHandle | entity, |
| ComputedShadowTreeComponent & | shadow, | ||
| ShadowBranchType | branchType, | ||
| Entity | lightTarget, | ||
| const RcString & | href, | ||
| ParseWarningSink & | warningSink ) |
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.
| entity | The entity to create the shadow tree for. |
| shadow | The computed shadow tree component to populate. |
| branchType | Determines 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. |
| lightTarget | Target entity to reflect in the shadow tree. |
| href | The value of the href attribute for the shadow tree, for diagnostics. |
| warningSink | If provided, warnings will be added to this vector. |
branchType is not the ShadowBranchType::Main branch. Returns std::nullopt if it is. | void donner::svg::components::ShadowTreeSystem::teardown | ( | Registry & | registry, |
| ComputedShadowTreeComponent & | shadow ) |
Destroy the instantiated shadow tree.
| registry | The registry. |
| shadow | The computed shadow tree component to tear down. |
| void donner::svg::components::ShadowTreeSystem::teardownInstances | ( | EntityHandle | handle | ) |
Destroy every shadow tree instantiated on handle, if any.
Call this before removing an entity's ComputedShadowTreeComponent to force its shadow trees to be regenerated. Removing the component on its own orphans the cloned entities: they stay parented into the tree with nothing left recording them, so the next render instantiates a second copy that draws on top of the first.
| handle | The shadow host whose instances should be destroyed. |
| class donner::svg::components::ShapeSystem |
Public Member Functions | |
| void | instantiateShadowComputedPaths (Registry ®istry, std::span< const Entity > entities, ParseWarningSink &warningSink) |
| Prepare newly created shadow instances without resampling the rest of the document. | |
| template<typename T> | |
| ComputedPathComponent * | createComputedPath (EntityHandle handle, const T &component, const FontMetrics &fontMetrics, ParseWarningSink &warningSink) |
| Convert the given shape to a path, evaluating CSS styling information and presentation attributes. | |
| ComputedPathComponent * | createComputedPathIfShape (EntityHandle handle, const FontMetrics &fontMetrics, ParseWarningSink &warningSink) |
| Convert the given shape to a path, if the provided entity contains a shape. | |
| void | instantiateAllComputedPaths (Registry ®istry, ParseWarningSink &warningSink) |
| Create ComputedPathComponent for all entities in the registry that have a shape component. | |
| bool | recomputeStyledPaths (Registry ®istry, std::span< const Entity > entities, ParseWarningSink &warningSink) |
| Recompute the prepared authored and instance paths whose styles changed in a retained edit. | |
| std::optional< Box2d > | getShapeBounds (EntityHandle handle) |
| Get the bounds for the given entity in the entity's local space, if it has a shape component. | |
| bool | collectShapeGeometry (EntityHandle handle, const Transform2d &spaceFromEntity, const BoundsGeometryCollector &collector) |
| Collect the geometry getShapeBounds bounds, placed in a measurement space, so that its bounds in any later target space follow from BoundGeometryPieces without visiting the entity again. | |
| std::optional< Box2d > | getStrokeBounds (EntityHandle handle) |
| Return the SVG stroke-shape bounds, including descendant object and stroke geometry. | |
| Path | circleClipPath (EntityHandle handle, const CircleClipPath &circle, CircleClipGeometryBudget &budget) |
| Resolve a circle clipping shape in element-local coordinates; invalid geometry is empty. | |
| Path | ellipseClipPath (EntityHandle handle, const EllipseClipPath &ellipse, CircleClipGeometryBudget &budget) |
| Resolve an ellipse clipping shape in element-local coordinates. | |
| Path | polygonClipPath (EntityHandle handle, const PolygonClipPath &polygon, CircleClipGeometryBudget &budget) |
| Resolve a polygon clipping shape in element-local coordinates. | |
| Path | insetClipPath (EntityHandle handle, const InsetClipPath &inset, CircleClipGeometryBudget &budget) |
| Resolve a non-rounded inset clipping shape in element-local coordinates. | |
| Path | pathClipPath (EntityHandle handle, const PathClipPath &path, CircleClipGeometryBudget &budget) |
| Resolve an SVG path clipping shape in element-local coordinates. | |
| std::optional< Box2d > | getShapeWorldBounds (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. | |
Static Public Member Functions | |
| static EntityHandle | geometryHandle (EntityHandle instance) |
| Select path/cache ownership without changing the instance's transform or resource owner. | |
| Path donner::svg::components::ShapeSystem::circleClipPath | ( | EntityHandle | handle, |
| const CircleClipPath & | circle, | ||
| CircleClipGeometryBudget & | budget ) |
Resolve a circle clipping shape in element-local coordinates; invalid geometry is empty.
| handle | Styled element supplying reference geometry and length metrics. |
| circle | Parsed circle and reference-box selection. |
| budget | Shared admission budget for the render preparation. |
| bool donner::svg::components::ShapeSystem::collectShapeGeometry | ( | EntityHandle | handle, |
| const Transform2d & | spaceFromEntity, | ||
| const BoundsGeometryCollector & | collector ) |
Collect the geometry getShapeBounds bounds, placed in a measurement space, so that its bounds in any later target space follow from BoundGeometryPieces without visiting the entity again.
| handle | Entity handle to collect the geometry of |
| spaceFromEntity | Transform from the entity's local space to the measurement space |
| collector | Receives the geometry. A path whose copy does not fit its allowance is collected as its bounding box |
|
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:
| handle | Entity handle to create the computed path for |
| component | Shape component attached to handle |
| fontMetrics | Font metrics, used to scale lengths |
| warningSink | Containing any warnings found |
| ComputedPathComponent * donner::svg::components::ShapeSystem::createComputedPathIfShape | ( | EntityHandle | handle, |
| const FontMetrics & | fontMetrics, | ||
| ParseWarningSink & | warningSink ) |
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.
| handle | Entity handle to create the computed path for |
| fontMetrics | Font metrics, used to scale lengths |
| warningSink | Containing any warnings found |
| Path donner::svg::components::ShapeSystem::ellipseClipPath | ( | EntityHandle | handle, |
| const EllipseClipPath & | ellipse, | ||
| CircleClipGeometryBudget & | budget ) |
Resolve an ellipse clipping shape in element-local coordinates.
| handle | Styled element supplying reference geometry and length metrics. |
| ellipse | Parsed ellipse and reference-box selection. |
| budget | Shared admission budget for the render preparation. |
|
static |
Select path/cache ownership without changing the instance's transform or resource owner.
| instance | Style/tree entity. |
| std::optional< Box2d > 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.
| handle | Entity handle to get the bounds for |
| std::optional< Box2d > donner::svg::components::ShapeSystem::getShapeWorldBounds | ( | EntityHandle | handle | ) |
Get the bounds for the given entity in world space, if it has a shape component.
| handle | Entity handle to get the bounds for |
| std::optional< Box2d > donner::svg::components::ShapeSystem::getStrokeBounds | ( | EntityHandle | handle | ) |
Return the SVG stroke-shape bounds, including descendant object and stroke geometry.
| handle | Element whose local reference box is required. |
| Path donner::svg::components::ShapeSystem::insetClipPath | ( | EntityHandle | handle, |
| const InsetClipPath & | inset, | ||
| CircleClipGeometryBudget & | budget ) |
Resolve a non-rounded inset clipping shape in element-local coordinates.
| handle | Styled element supplying reference geometry and length metrics. |
| inset | Parsed offsets and reference-box selection. |
| budget | Shared admission budget for render preparation. |
| void donner::svg::components::ShapeSystem::instantiateAllComputedPaths | ( | Registry & | registry, |
| ParseWarningSink & | warningSink ) |
Create ComputedPathComponent for all entities in the registry that have a shape component.
This assumes that StyleSystem::computeAllStyles has already been called.
| registry | Registry used to find all shape components |
| warningSink | Containing any warnings found |
| void donner::svg::components::ShapeSystem::instantiateShadowComputedPaths | ( | Registry & | registry, |
| std::span< const Entity > | entities, | ||
| ParseWarningSink & | warningSink ) |
Prepare newly created shadow instances without resampling the rest of the document.
| registry | Document storage. |
| entities | Admitted shadow entity span. |
| warningSink | Diagnostic sink. |
| Path donner::svg::components::ShapeSystem::pathClipPath | ( | EntityHandle | handle, |
| const PathClipPath & | path, | ||
| CircleClipGeometryBudget & | budget ) |
Resolve an SVG path clipping shape in element-local coordinates.
| handle | Styled element supplying reference geometry. |
| path | Parsed path and reference-box selection. |
| budget | Shared admission budget for render preparation. |
| 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.
| handle | Entity handle containing the shape |
| point | Point to intersect |
| fillRule | Fill rule to use for the intersection test |
| 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.
| handle | Entity handle containing the shape |
| point | Point to intersect |
| strokeWidth | Stroke width to use for the intersection test |
| Path donner::svg::components::ShapeSystem::polygonClipPath | ( | EntityHandle | handle, |
| const PolygonClipPath & | polygon, | ||
| CircleClipGeometryBudget & | budget ) |
Resolve a polygon clipping shape in element-local coordinates.
| handle | Styled element supplying reference geometry and length metrics. |
| polygon | Parsed vertices and reference-box selection. |
| budget | Shared admission budget for render preparation. |
|
nodiscard |
Recompute the prepared authored and instance paths whose styles changed in a retained edit.
| registry | Document registry with freshly computed styles. |
| entities | Entities selected by the retained update plan. |
| warningSink | Destination for geometry diagnostics. |
| class donner::svg::components::StyleSystem |
Computes stylesheet information for elements, applying the CSS cascade and inheritance rules.
Public Types | |
| enum class | FullRestyle { DiscardAndRecompute , ComputeMissing } |
| What computeAllStyles does with existing computed styles when the whole document needs restyling (RenderTreeState::needsFullStyleRecompute on a built document). More... | |
| using | ApplyRetainedStyle |
| Apply styles through the retained renderer after a selective edit scan. | |
Public Member Functions | |
| const ComputedStyleComponent & | computeStyle (EntityHandle handle, ParseWarningSink &warningSink) |
| Compute the style for the given entity handle, applying the CSS cascade and inheritance rules. | |
| void | computeAllStyles (Registry ®istry, ParseWarningSink &warningSink, FullRestyle fullRestyle=FullRestyle::DiscardAndRecompute, StylePassScheduler scheduler={}) |
| Computes the style for all entities in the registry. | |
| void | computeStylesFor (Registry ®istry, std::span< const Entity > entities, ParseWarningSink &warningSink) |
| Computes the style for the given entities in the registry. | |
| bool | updateStyle (EntityHandle handle, std::string_view style, bool invalidateCachedStyle=true) |
| Update the style attribute on an element, merging new declarations with existing ones. | |
| std::vector< MatchedStyleRule > | collectMatchedStyleRules (EntityHandle handle, bool includeDeclarations=true) const |
Collect stylesheet rules that match handle using the same selector matching and specificity adjustments used by computeStyle. | |
| std::optional< SourceRange > | mapStylesheetSourceRange (Registry ®istry, Entity stylesheetEntity, const SourceRange &cssRange) const |
| Map a decoded range in one embedded stylesheet to original document bytes. | |
| CustomPropertyDeclarationBatchResult | findCustomPropertyDeclarations (EntityHandle handle, std::span< const std::string_view > names, std::size_t maxWork) const |
| Resolve source provenance for multiple prepared custom properties with one work allowance. | |
| std::optional< StyleRuleAtSourceOffset > | findStyleRuleAtSourceOffset (Registry ®istry, std::size_t documentSourceOffset) const |
Find the author stylesheet rule at documentSourceOffset. | |
| void | invalidateComputed (EntityHandle handle) |
| Invalidate the computed style for a given entity. | |
| bool | anyStylesheetUsesAttributeInSelector (Registry ®istry, std::string_view localName) const |
Returns true if any stylesheet loaded into registry contains an attribute selector that could match an attribute with the given local name. | |
| void | invalidateAll (EntityHandle handle) |
| Invalidate the full style and reparse attributes. | |
Static Public Member Functions | |
| static std::size_t | CandidateListCapacityForTesting () |
| Capacity of the calling thread's candidate list, in entries, for tests of the retention cap. | |
| static void | computePreparedStyle (const Registry ®istry, Entity entity, ComputedStyleComponent &output, CascadePass &pass, ParseWarningSink &warnings) |
| Cascade a static element after its parent and the document root have been published. | |
| static std::size_t | StylesheetSourceIndexBuildsForTesting () |
| Number of stylesheet source indices constructed on this thread. | |
| static std::optional< bool > | preparedCustomPropertyHasValue (EntityHandle handle, std::string_view name) |
| Check whether the prepared cascade contains a usable custom property. | |
| static void | synchronizeDocumentFontFaces (Registry ®istry) |
| Register document fonts and compute their active ordering when cascade layers apply. | |
| static void | discardComputedStyles (Registry ®istry) |
| Discard every cached computed style and its retained style budget, for changes that affect selector matching across the whole document, such as reloaded stylesheet imports. | |
| static void | discardComputedStylesForFullRestyle (Registry ®istry) |
| Discard every computed style and its retained style budget to restyle the whole document, counted in StyleCascadeCounters::fullClears. | |
| static ResolvedPaintServer | externalHostPaint (Registry ®istry, bool stroke) |
| Inherit fallback values from an external-use computed parent without transferring specificity. Resolved ordinary host paint, retained only during the guarded occurrence. | |
| static void | rejectExternalHostResource (Registry ®istry) |
| Record a refused inherited resource for the occurrence's static diagnostic. | |
| static std::optional< PaintServer > | localPaintForInstantiation (const ComputedStyleComponent &style, bool stroke) |
| Local paints alone create child-registry resource shadow trees. | |
| static void | inheritExternalParent (PropertyRegistry &properties, const PropertyRegistry &parent) |
| Apply inherited values from an external parent in place while retaining local declaration precedence. | |
| static bool | computeEditedFrameStyles (Registry ®istry, ParseWarningSink &warningSink, StylePassScheduler scheduler, bool(*compute)(Registry &, ParseWarningSink &, StylePassScheduler, bool(*)(const Registry &))) |
| Run one selective frame against a tentative warning sink. | |
| static void | markEditedStyleTargets (Registry ®istry, std::span< const Entity > affected, ApplyRetainedStyle applyRetained) |
| Mark an admitted list of edited styles, recording the last rendered order when available. | |
| static bool | invalidateStylesheetRules (Registry ®istry, std::span< const css::SelectorRule > removed, std::span< const css::SelectorRule > added, ApplyRetainedStyle applyRetained) |
| Schedule a bounded selective style pass for the union of old and new rule matches. | |
| static std::uint8_t | styleEditDependencies (const Registry ®istry, std::string_view attribute, std::span< const std::string_view > changedClasses) |
| Relations affected by an attribute and any changed class tokens. Ancestors requires a full restyle because a relative selector can reach beyond the edited branch. | |
| static bool | isStyleEditSubtreeBoundary (const Registry ®istry, Entity entity) |
| Whether this element can be restyled without rebuilding resource or text subtrees. | |
| static std::optional< uint32_t > | retainedStyleOrder (const Registry ®istry, Entity entity) |
| Comparable order inputs for local geometry and paint, or nullopt for a nonlocal style. | |
Static Public Attributes | |
| static constexpr std::size_t | kRetainedCandidateCapacity = 4096 |
| Candidate rule positions the per-thread list used by the cascade keeps between elements, in entries: an element's cascade that needed more releases the list afterwards, so a large stylesheet does not pin its memory for the life of the thread. Equal to the stylesheet parser's rule limit, the most candidates one sheet has once duplicates are removed. | |
| static constexpr std::size_t | kMaximumCustomPropertyDeclarationQueryWork = 16 * 1024 * 1024 |
| Maximum defensive work accepted by the legacy one-name query. | |
Apply styles through the retained renderer after a selective edit scan.
| registry | Document registry containing the marked style targets. |
| warningSink | Destination for accepted diagnostics. |
| scheduler | Scheduler available to the style pass. |
|
strong |
What computeAllStyles does with existing computed styles when the whole document needs restyling (RenderTreeState::needsFullStyleRecompute on a built document).
| Enumerator | |
|---|---|
| DiscardAndRecompute | Discard every computed style, then compute the whole document. |
| ComputeMissing | Compute only entities without a computed style. For a caller that already discarded the stale styles with discardComputedStylesForFullRestyle and runs several passes over one rebuild, so each entity is cascaded once. |
| bool donner::svg::components::StyleSystem::anyStylesheetUsesAttributeInSelector | ( | Registry & | registry, |
| std::string_view | localName ) const |
Returns true if any stylesheet loaded into registry contains an attribute selector that could match an attribute with the given local name.
Writing such an attribute changes selector matching, and can do so for elements other than the one written (sibling combinators, descendant selectors), which per-entity dirty flags do not track. Callers use this to decide whether an attribute write needs a whole-tree restyle.
| registry | Document registry. |
| localName | Attribute local name that is about to be written. |
| std::vector< MatchedStyleRule > donner::svg::components::StyleSystem::collectMatchedStyleRules | ( | EntityHandle | handle, |
| bool | includeDeclarations = true ) const |
Collect stylesheet rules that match handle using the same selector matching and specificity adjustments used by computeStyle.
Only rules of each <style> element's own stylesheet are reported; rules loaded through @import have no document source and are not indexed by MatchedStyleRule::ruleIndex. Match collection is complete, but source-range projection is resource-bounded. A matched rule can therefore retain its stylesheet-local CSS ranges while its document source ranges are absent. Individual source mapping through mapStylesheetSourceRange remains exact.
| handle | Entity handle to trace stylesheet matches for. |
| includeDeclarations | Project declarations in addition to rule and selector ranges. |
| void donner::svg::components::StyleSystem::computeAllStyles | ( | Registry & | registry, |
| ParseWarningSink & | warningSink, | ||
| FullRestyle | fullRestyle = FullRestyle::DiscardAndRecompute, | ||
| StylePassScheduler | scheduler = {} ) |
Computes the style for all entities in the registry.
| registry | Registry to compute the styles, used to query for all entities in the tree. |
| warningSink | Containing any warnings found |
| fullRestyle | What a whole-document restyle does with existing computed styles. |
| scheduler | Optional scheduler borrowed for this invocation. |
|
static |
Run one selective frame against a tentative warning sink.
| registry | Prepared document registry containing the style budget and dirty style slots. |
| warningSink | Destination for warnings, updated only after the callback succeeds. |
| scheduler | Scheduler forwarded to the style callback. |
| compute | Non-null callback that computes the dirty frame styles and returns false when its pass must be abandoned, including budget refusal. |
|
static |
Cascade a static element after its parent and the document root have been published.
The caller holds document access, initializes the component types before dispatch, and keeps the pools stable until the join. The cache belongs to this document and stylesheet generation. Animated documents and external occurrences use the serial cascade.
| registry | Read-only document storage. |
| entity | Element whose slot the caller owns exclusively. |
| output | Previously emplaced computed-style slot for the element. |
| pass | Mutable work and cache state exclusive to this worker. |
| warnings | Worker-owned diagnostic sink. |
| const ComputedStyleComponent & donner::svg::components::StyleSystem::computeStyle | ( | EntityHandle | handle, |
| ParseWarningSink & | warningSink ) |
Compute the style for the given entity handle, applying the CSS cascade and inheritance rules.
| handle | Entity handle to compute the style for |
| warningSink | Containing any warnings found |
| void donner::svg::components::StyleSystem::computeStylesFor | ( | Registry & | registry, |
| std::span< const Entity > | entities, | ||
| ParseWarningSink & | warningSink ) |
Computes the style for the given entities in the registry.
| registry | Registry containing the entities |
| entities | Entities to compute |
| warningSink | Containing any warnings found |
|
static |
Discard every cached computed style and its retained style budget, for changes that affect selector matching across the whole document, such as reloaded stylesheet imports.
Unlike RenderTreeState::needsFullStyleRecompute, this also covers styles computed by queries before the render tree was first built.
| registry | Registry containing the document. |
|
static |
Discard every computed style and its retained style budget to restyle the whole document, counted in StyleCascadeCounters::fullClears.
Style passes that follow with FullRestyle::ComputeMissing then compute every entity again, once.
| registry | Registry containing the document. |
| CustomPropertyDeclarationBatchResult donner::svg::components::StyleSystem::findCustomPropertyDeclarations | ( | EntityHandle | handle, |
| std::span< const std::string_view > | names, | ||
| std::size_t | maxWork ) const |
Resolve source provenance for multiple prepared custom properties with one work allowance.
| handle | Element whose computed style supplies the values. |
| names | Custom-property identifiers in request order. |
| maxWork | Remaining query work available to the caller. |
| std::optional< StyleRuleAtSourceOffset > donner::svg::components::StyleSystem::findStyleRuleAtSourceOffset | ( | Registry & | registry, |
| std::size_t | documentSourceOffset ) const |
Find the author stylesheet rule at documentSourceOffset.
If the offset is inside one selector-list entry, StyleRuleAtSourceOffset::selectorEntryIndex is set so callers can focus that selector branch. If the offset is elsewhere inside the rule, such as a declaration block, the entry is unset and the whole selector list is considered active.
| registry | SVG document registry to inspect. |
| documentSourceOffset | Offset in the SVG document source. |
documentSourceOffset, or std::nullopt.
|
static |
Apply inherited values from an external parent in place while retaining local declaration precedence.
| properties | Declarations in the referenced document, which receive the external-parent fallback values. |
| parent | Computed declarations inherited from the referencing element. |
| void donner::svg::components::StyleSystem::invalidateAll | ( | EntityHandle | handle | ) |
Invalidate the full style and reparse attributes.
| handle | Entity handle to invalidate |
| void donner::svg::components::StyleSystem::invalidateComputed | ( | EntityHandle | handle | ) |
Invalidate the computed style for a given entity.
| handle | Entity handle to invalidate |
|
static |
Schedule a bounded selective style pass for the union of old and new rule matches.
| registry | Built document registry eligible for a selective edit scan. A pending full rebuild/restyle, prior budget refusal, unsupported subtree boundary, or oversized scan makes the call decline. |
| removed | Previous rules replaced or removed by the source edit. |
| added | Replacement or inserted rules from the updated stylesheet. |
| applyRetained | Optional retained-update callback forwarded to markEditedStyleTargets. A null callback selects ordinary style-cascade invalidation. |
|
static |
Mark an admitted list of edited styles, recording the last rendered order when available.
| registry | Built document registry containing RenderTreeState and every affected entity. |
| affected | Valid tree entities admitted by the edit analysis. An empty span is a no-op. |
| applyRetained | Optional retained-update callback. A null callback selects ordinary style-cascade invalidation. An entity without a retained order also selects that path. |
|
static |
Check whether the prepared cascade contains a usable custom property.
| handle | Element whose computed style is inspected. |
| name | Decoded, case-sensitive custom-property identifier. |
std::nullopt if the source or style is unavailable. | bool donner::svg::components::StyleSystem::updateStyle | ( | EntityHandle | handle, |
| std::string_view | style, | ||
| bool | invalidateCachedStyle = true ) |
Update the style attribute on an element, merging new declarations with existing ones.
Declarations in style override existing declarations with the same property name. The merged result is written back to the style attribute and the PropertyRegistry is updated.
| handle | Entity handle to update. |
| style | CSS style string to merge, e.g. "fill: red; opacity: 0.5". |
| invalidateCachedStyle | False when the caller needs the old style for edit routing. |
| class donner::svg::components::TextSystem |
System to compute text layout spans from raw text and positioning attributes.
Public Member Functions | |
| void | instantiateAllComputedComponents (Registry ®istry, ParseWarningSink &warningSink) |
| Instantiate computed text spans for all entities with TextComponent. | |
| void | instantiateComputedComponent (EntityHandle handle, ParseWarningSink &warningSink) |
| Instantiate computed text spans for a specific text root. | |
| void donner::svg::components::TextSystem::instantiateAllComputedComponents | ( | Registry & | registry, |
| ParseWarningSink & | warningSink ) |
Instantiate computed text spans for all entities with TextComponent.
| registry | The registry to instantiate the computed text spans for. |
| warningSink | If non-null, a vector to store any warnings that occur during the instantiation. |
| void donner::svg::components::TextSystem::instantiateComputedComponent | ( | EntityHandle | handle, |
| ParseWarningSink & | warningSink ) |
Instantiate computed text spans for a specific text root.
| handle | Text root handle. |
| warningSink | If non-null, warnings are appended here. |