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

Holds CSS properties for a single element. More...

#include "donner/svg/properties/PropertyRegistry.h"

Collaboration diagram for donner::svg::PropertyRegistry:
[legend]

Public Member Functions

 PropertyRegistry ()
 Constructor.
 
 ~PropertyRegistry ()
 Destructor.
 
 PropertyRegistry (const PropertyRegistry &)
 Copy constructor.
 
 PropertyRegistry (PropertyRegistry &&) noexcept
 Move constructor.
 
PropertyRegistryoperator= (const PropertyRegistry &)
 Copy assignment operator.
 
PropertyRegistryoperator= (PropertyRegistry &&) noexcept
 Move assignment operator.
 
auto allProperties () const
 Return a tuple of all properties within the PropertyRegistry.
 
auto allPropertiesMutable ()
 Return a mutable tuple of all properties within the PropertyRegistry.
 
PropertyRegistry inheritFrom (const PropertyRegistry &parent, PropertyInheritOptions options=PropertyInheritOptions::All) const
 Inherit the value of each element in the stylesheet.
 
std::optional< parser::ParseErrorparseProperty (const css::Declaration &declaration, css::Specificity specificity)
 Parse a single declaration, adding it to the property registry.
 
void parseStyle (std::string_view str)
 Parse a SVG style attribute, and set the parsed values on this PropertyRegistry.
 
parser::ParseResult< bool > parsePresentationAttribute (std::string_view name, std::string_view value, std::optional< ElementType > type=std::nullopt, EntityHandle handle=EntityHandle())
 Parse a presentation attribute, which can contain a CSS value.
 

Static Public Member Functions

static constexpr size_t numProperties ()
 Return the size of the tuple returned by allProperties().
 
template<size_t Start, size_t End, class F >
static constexpr void forEachProperty (const F &f)
 Calls a compile time functor for each property in the registry.
 

Public Attributes

Property< css::Color, PropertyCascade::Inheritcolor
 color property, which stores the context color of the element. For painting shapes, use stroke or fill instead.
 
Property< Displaydisplay {"display", []() -> std::optional<Display> { return Display::Inline; }}
 display property, which determines how the element is rendered. Set to Display::None to hide the element.
 
Property< double > opacity {"opacity", []() -> std::optional<double> { return 1.0; }}
 opacity property, which determines the opacity of the element. A value of 0.0 will make the element invisible.
 
Property< Visibility, PropertyCascade::Inheritvisibility
 visibility property, which determines whether the element is visible. Set to Visibility::Hidden to hide the element. Compared to display with Display::None, hiding the element will not remove it from the document, so it will still contribute to bounding boxes.
 
Property< Overflowoverflow
 overflow property, which determines how content that overflows the element's box is handled. Defaults to visible.
 
Property< PaintServer, PropertyCascade::PaintInheritfill
 fill property, which determines the color of the element's interior. Defaults to black.
 
Property< FillRule, PropertyCascade::InheritfillRule
 fill-rule property, which determines how the interior of the element is filled in the case of overlapping shapes. Defaults to FillRule::NonZero.
 
Property< double, PropertyCascade::InheritfillOpacity
 fill-opacity property, which determines the opacity of the element's interior. Defaults to 1.0. A value of 0.0 will make the interior invisible.
 
Property< PaintServer, PropertyCascade::PaintInheritstroke
 stroke property, which determines the color of the element's outline stroke. Defaults to none.
 
Property< double, PropertyCascade::InheritstrokeOpacity
 stroke-opacity property, which determines the opacity of the element's outline stroke. Defaults to 1.0. A value of 0.0 will make the outline invisible.
 
Property< Lengthd, PropertyCascade::InheritstrokeWidth
 stroke-width property, which determines the width of the element's outline stroke. Defaults to 1.0.
 
Property< StrokeLinecap, PropertyCascade::InheritstrokeLinecap
 stroke-linecap property, which determines the shape of the element's outline stroke at the ends of the path. Defaults to StrokeLinecap::Butt.
 
Property< StrokeLinejoin, PropertyCascade::InheritstrokeLinejoin
 stroke-linejoin property, which determines the shape of the element's outline stroke in between line segments. Defaults to StrokeLinejoin::Miter.
 
Property< double, PropertyCascade::InheritstrokeMiterlimit
 stroke-miterlimit property, which determines the limit of the ratio of the miter length to the stroke width. Defaults to 4.0.
 
Property< StrokeDasharray, PropertyCascade::InheritstrokeDasharray
 stroke-dasharray property, which determines the pattern of dashes and gaps used to stroke paths.
 
Property< Lengthd, PropertyCascade::InheritstrokeDashoffset
 stroke-dashoffset property, which determines the distance into the dash pattern to start the stroke.
 
Property< Reference, PropertyCascade::NoneclipPath
 clip-path property, which determines the shape of the element's clipping region. Defaults to none.
 
Property< ClipRule, PropertyCascade::InheritclipRule
 clip-rule property, which determines how the interior of the element is filled in the case of overlapping shapes. Defaults to ClipRule::NonZero.
 
Property< Reference, PropertyCascade::Nonemask
 mask property, which determines the shape of the element's clipping region. Defaults to none.
 
Property< FilterEffectfilter
 filter property, which determines the filter effect to apply to the element. Defaults to none.
 
Property< PointerEvents, PropertyCascade::InheritpointerEvents
 pointer-events property, which determines how the element responds to pointer events (such as clicks or hover). Defaults to PointerEvents::VisiblePainted.
 
Property< Reference, PropertyCascade::InheritmarkerStart
 marker-start property, which determines the marker to be drawn at the start of the path.
 
Property< Reference, PropertyCascade::InheritmarkerMid
 marker-mid property, which determines the marker to be drawn at the middle of the path.
 
Property< Reference, PropertyCascade::InheritmarkerEnd
 marker-end property, which determines the marker to be drawn at the end of the path.
 
std::map< RcString, parser::UnparsedPropertyunparsedProperties
 Properties which don't have specific listings above, which are stored as raw css declarations.
 

Friends

std::ostream & operator<< (std::ostream &os, const PropertyRegistry &registry)
 Ostream output operator, for debugging which outputs a human-readable representation of all of the properties.
 

Detailed Description

Holds CSS properties for a single element.

This class stores common properties which may be applied to any element, plus unparsedProperties which contains element-specific properties which are applied if the element matches.

For unparsedProperties, presentation attributes specified in CSS such as transform will be stored here until they can be applied to the element.

Supported properties

Property Member Default
color color black
display display inline
opacity opacity 1.0
visibility visibility visible
overflow overflow visible
fill fill black
fill-rule fillRule nonzero
fill-opacity fillOpacity 1.0
stroke stroke none
stroke-opacity strokeOpacity 1.0
stroke-width strokeWidth 1.0
stroke-linecap strokeLinecap butt
stroke-linejoin strokeLinejoin miter
stroke-miterlimit strokeMiterlimit 4.0
stroke-dasharray strokeDasharray none
stroke-dashoffset strokeDashoffset 0
clip-path clipPath none
clip-rule clipRule nonzero
mask mask none
filter filter none
pointer-events pointerEvents auto
marker-start markerStart none
marker-mid markerMid none
marker-end markerEnd none

Member Function Documentation

◆ allProperties()

auto donner::svg::PropertyRegistry::allProperties ( ) const
inline

Return a tuple of all properties within the PropertyRegistry.

To get the size of the tuple, use numProperties().

◆ allPropertiesMutable()

auto donner::svg::PropertyRegistry::allPropertiesMutable ( )
inline

Return a mutable tuple of all properties within the PropertyRegistry.

See also
allProperties()

◆ forEachProperty()

template<size_t Start, size_t End, class F >
static constexpr void donner::svg::PropertyRegistry::forEachProperty ( const F & f)
inlinestaticconstexpr

Calls a compile time functor for each property in the registry.

Example:

auto properties = allProperties();
forEachProperty<0, numProperties()>([&properties](auto i) {
auto& property = std::get<i>(properties);
}
auto allProperties() const
Return a tuple of all properties within the PropertyRegistry.
Definition PropertyRegistry.h:269
Template Parameters
StartIndex of the current property to call.
EndTotal number of properties in the registry.
FType of the functor object, with signature void(std::integral_constant<size_t>).
Parameters
fFunctor instance.

◆ inheritFrom()

PropertyRegistry donner::svg::PropertyRegistry::inheritFrom ( const PropertyRegistry & parent,
PropertyInheritOptions options = PropertyInheritOptions::All ) const

Inherit the value of each element in the stylesheet.

Parameters
parentPropertyRegistry from this element's direct parent, where properties will be inherited from.
optionsOptions for how to inherit properties, which can be used to skip inheritance for a category of properties.

◆ parsePresentationAttribute()

parser::ParseResult< bool > donner::svg::PropertyRegistry::parsePresentationAttribute ( std::string_view name,
std::string_view value,
std::optional< ElementType > type = std::nullopt,
EntityHandle handle = EntityHandle() )

Parse a presentation attribute, which can contain a CSS value.

See also
https://www.w3.org/TR/SVG2/styling.html#PresentationAttributes
Parameters
nameName of the attribute.
valueValue of the attribute, parsed as a CSS value.
typeIf set, parses additional presentation attributes for the given element type.
handleEntity handle to use for parsing additional attributes.
Returns
true if the element supports this attribute and it was parsed successfully, or a donner::base::parser::ParseError if parsing failed.

◆ parseProperty()

std::optional< parser::ParseError > donner::svg::PropertyRegistry::parseProperty ( const css::Declaration & declaration,
css::Specificity specificity )

Parse a single declaration, adding it to the property registry.

Parameters
declarationDeclaration to parse.
specificitySpecificity of the declaration.
Returns
Error if the declaration had errors parsing or the property is not supported.

◆ parseStyle()

void donner::svg::PropertyRegistry::parseStyle ( std::string_view str)

Parse a SVG style attribute, and set the parsed values on this PropertyRegistry.

Does not clear existing properties, new ones are applied additively.

Parses the string as a CSS "<declaration-list>", ignoring any parse errors or unsupported properties

Parameters
strInput string from a style attribute, e.g. "fill: red; stroke: blue".

Friends And Related Symbol Documentation

◆ operator<<

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

Ostream output operator, for debugging which outputs a human-readable representation of all of the properties.

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
Property< css::Color, PropertyCascade::Inherit > color
color property, which stores the context color of the element. For painting shapes,...
Definition PropertyRegistry.h:102
Parameters
osOutput stream.
registryPropertyRegistry to output.

Member Data Documentation

◆ clipPath

Property<Reference, PropertyCascade::None> donner::svg::PropertyRegistry::clipPath
Initial value:
{
"clip-path", []() -> std::optional<Reference> { return std::nullopt; }}

clip-path property, which determines the shape of the element's clipping region. Defaults to none.

◆ clipRule

Property<ClipRule, PropertyCascade::Inherit> donner::svg::PropertyRegistry::clipRule
Initial value:
{
"clip-rule", []() -> std::optional<ClipRule> { return ClipRule::NonZero; }}
@ NonZero
[DEFAULT] Determines "insideness" of a point by counting crossings of a ray drawn from that point to ...

clip-rule property, which determines how the interior of the element is filled in the case of overlapping shapes. Defaults to ClipRule::NonZero.

◆ color

Property<css::Color, PropertyCascade::Inherit> donner::svg::PropertyRegistry::color
Initial value:
{
"color", []() -> std::optional<css::Color> { return css::Color(css::RGBA(0, 0, 0, 0xFF)); }}

color property, which stores the context color of the element. For painting shapes, use stroke or fill instead.

◆ fill

Property<PaintServer, PropertyCascade::PaintInherit> donner::svg::PropertyRegistry::fill
Initial value:
{
"fill", []() -> std::optional<PaintServer> {
return PaintServer::Solid(css::Color(css::RGBA::RGB(0, 0, 0)));
}}
static constexpr RGBA RGB(uint8_t r, uint8_t g, uint8_t b)
Constructor, for RGB colors, which are fully opaque.
Definition Color.h:37

fill property, which determines the color of the element's interior. Defaults to black.

◆ fillOpacity

Property<double, PropertyCascade::Inherit> donner::svg::PropertyRegistry::fillOpacity
Initial value:
{
"fill-opacity", []() -> std::optional<double> { return 1.0; }}

fill-opacity property, which determines the opacity of the element's interior. Defaults to 1.0. A value of 0.0 will make the interior invisible.

◆ fillRule

Property<FillRule, PropertyCascade::Inherit> donner::svg::PropertyRegistry::fillRule
Initial value:
{
"fill-rule", []() -> std::optional<FillRule> { return FillRule::NonZero; }}
@ NonZero
[DEFAULT] Determines "insideness" of a point by counting crossings of a ray drawn from that point to ...

fill-rule property, which determines how the interior of the element is filled in the case of overlapping shapes. Defaults to FillRule::NonZero.

◆ filter

Property<FilterEffect> donner::svg::PropertyRegistry::filter
Initial value:
{
"filter", []() -> std::optional<FilterEffect> { return FilterEffect::None(); }}

filter property, which determines the filter effect to apply to the element. Defaults to none.

◆ markerEnd

Property<Reference, PropertyCascade::Inherit> donner::svg::PropertyRegistry::markerEnd
Initial value:
{
"marker-end", []() -> std::optional<Reference> { return std::nullopt; }}

marker-end property, which determines the marker to be drawn at the end of the path.

◆ markerMid

Property<Reference, PropertyCascade::Inherit> donner::svg::PropertyRegistry::markerMid
Initial value:
{
"marker-mid", []() -> std::optional<Reference> { return std::nullopt; }}

marker-mid property, which determines the marker to be drawn at the middle of the path.

◆ markerStart

Property<Reference, PropertyCascade::Inherit> donner::svg::PropertyRegistry::markerStart
Initial value:
{
"marker-start", []() -> std::optional<Reference> { return std::nullopt; }}

marker-start property, which determines the marker to be drawn at the start of the path.

◆ mask

Property<Reference, PropertyCascade::None> donner::svg::PropertyRegistry::mask
Initial value:
{
"mask", []() -> std::optional<Reference> { return std::nullopt; }}

mask property, which determines the shape of the element's clipping region. Defaults to none.

◆ overflow

Property<Overflow> donner::svg::PropertyRegistry::overflow
Initial value:
{"overflow",
[]() -> std::optional<Overflow> { return Overflow::Visible; }}
@ Visible
[DEFAULT] "visible": Content is not clipped, and may render outside the box.

overflow property, which determines how content that overflows the element's box is handled. Defaults to visible.

◆ pointerEvents

Property<PointerEvents, PropertyCascade::Inherit> donner::svg::PropertyRegistry::pointerEvents
Initial value:
{
"pointer-events",
[]() -> std::optional<PointerEvents> { return PointerEvents::VisiblePainted; }}
@ VisiblePainted
Responds to pointer events only if the element is visible and the pointer is over the painted area,...

pointer-events property, which determines how the element responds to pointer events (such as clicks or hover). Defaults to PointerEvents::VisiblePainted.

◆ stroke

Property<PaintServer, PropertyCascade::PaintInherit> donner::svg::PropertyRegistry::stroke
Initial value:
{
"stroke", []() -> std::optional<PaintServer> { return PaintServer::None(); }}

stroke property, which determines the color of the element's outline stroke. Defaults to none.

◆ strokeDasharray

Property<StrokeDasharray, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeDasharray
Initial value:
{
"stroke-dasharray", []() -> std::optional<StrokeDasharray> { return std::nullopt; }}

stroke-dasharray property, which determines the pattern of dashes and gaps used to stroke paths.

◆ strokeDashoffset

Property<Lengthd, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeDashoffset
Initial value:
{
"stroke-dashoffset",
[]() -> std::optional<Lengthd> { return Lengthd(0, Lengthd::Unit::None); }}
Length< double > Lengthd
Shorthand for Length<double>.
Definition Length.h:222

stroke-dashoffset property, which determines the distance into the dash pattern to start the stroke.

◆ strokeLinecap

Property<StrokeLinecap, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeLinecap
Initial value:
{
"stroke-linecap", []() -> std::optional<StrokeLinecap> { return StrokeLinecap::Butt; }}
@ Butt
[DEFAULT] The stroke is squared off at the endpoint of the path.

stroke-linecap property, which determines the shape of the element's outline stroke at the ends of the path. Defaults to StrokeLinecap::Butt.

◆ strokeLinejoin

Property<StrokeLinejoin, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeLinejoin
Initial value:
{
"stroke-linejoin", []() -> std::optional<StrokeLinejoin> { return StrokeLinejoin::Miter; }}
@ Miter
[DEFAULT] The outer edges of the strokes for the two segments are extended until they meet at an angl...

stroke-linejoin property, which determines the shape of the element's outline stroke in between line segments. Defaults to StrokeLinejoin::Miter.

◆ strokeMiterlimit

Property<double, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeMiterlimit
Initial value:
{
"stroke-miterlimit", []() -> std::optional<double> { return 4.0; }}

stroke-miterlimit property, which determines the limit of the ratio of the miter length to the stroke width. Defaults to 4.0.

◆ strokeOpacity

Property<double, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeOpacity
Initial value:
{
"stroke-opacity", []() -> std::optional<double> { return 1.0; }}

stroke-opacity property, which determines the opacity of the element's outline stroke. Defaults to 1.0. A value of 0.0 will make the outline invisible.

◆ strokeWidth

Property<Lengthd, PropertyCascade::Inherit> donner::svg::PropertyRegistry::strokeWidth
Initial value:
{
"stroke-width", []() -> std::optional<Lengthd> { return Lengthd(1, Lengthd::Unit::None); }}

stroke-width property, which determines the width of the element's outline stroke. Defaults to 1.0.

◆ visibility

Property<Visibility, PropertyCascade::Inherit> donner::svg::PropertyRegistry::visibility
Initial value:
{
"visibility", []() -> std::optional<Visibility> { return Visibility::Visible; }}
@ Visible
[DEFAULT] Visible is the default value.

visibility property, which determines whether the element is visible. Set to Visibility::Hidden to hide the element. Compared to display with Display::None, hiding the element will not remove it from the document, so it will still contribute to bounding boxes.


The documentation for this class was generated from the following files: