Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::svg::components::StyleComponent Struct Reference

Contains properties the style="" attribute for an element, local to the element. More...

#include "donner/svg/components/style/StyleComponent.h"

Public Member Functions

bool setStyle (std::string_view style)
 Sets the properties from the value of the element's style="" attribute, replacing the prior style="" contribution on this element.
bool updateStyle (std::string_view style)
 Updates the properties from the value of the element's style="" attribute, adding new properties or updating existing ones.
ParseResult< bool > trySetPresentationAttribute (EntityHandle handle, std::string_view name, std::string_view value)
 Tries to set a common presentation attribute (fill, stroke, opacity, transform, etc.).

Public Attributes

PropertyRegistry properties
 The properties of the element, which are parsed from the style="" attribute.
bool styleParseRejected = false
 True when the most recent inline-style parse exceeded its resource budget.

Detailed Description

Contains properties the style="" attribute for an element, local to the element.

This is used during the CSS cascade, which stores the final element style in ComputedStyleComponent.

Member Function Documentation

◆ setStyle()

bool donner::svg::components::StyleComponent::setStyle ( std::string_view style)
inline

Sets the properties from the value of the element's style="" attribute, replacing the prior style="" contribution on this element.

Presentation-attribute-origin properties (e.g. fill="red") and author-stylesheet properties are left intact - the replacement is scoped to declarations previously tagged with css::Specificity::StyleAttribute().

Safe to call from the SVG parse pipeline (where presentation attributes may already be in the registry) and from the editor's text-edit rewrite path.

Callers that want to merge new declarations into an existing style="" - e.g. a tool that toggles one property - should use updateStyle instead.

Parameters
styleThe value of the style attribute.

◆ trySetPresentationAttribute()

ParseResult< bool > donner::svg::components::StyleComponent::trySetPresentationAttribute ( EntityHandle handle,
std::string_view name,
std::string_view value )
inline

Tries to set a common presentation attribute (fill, stroke, opacity, transform, etc.).

For element-specific attributes (cx, cy, r, d, etc.), callers should also invoke parser::ParsePresentationAttribute separately.

Parameters
handleThe entity to set the attribute on.
nameThe name of the attribute.
valueThe value of the attribute.
Returns
true if the attribute was set, false if the attribute was not recognized.

◆ updateStyle()

bool donner::svg::components::StyleComponent::updateStyle ( std::string_view style)
inline

Updates the properties from the value of the element's style="" attribute, adding new properties or updating existing ones.

Does not remove existing style="" attribute information.

Parameters
styleThe update style to apply, as a CSS style string (e.g. "fill:red;").

The documentation for this struct was generated from the following file: