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

DOM object for a "<pattern>" element. More...

#include "donner/svg/SVGPatternElement.h"

Inheritance diagram for donner::svg::SVGPatternElement:
[legend]
Collaboration diagram for donner::svg::SVGPatternElement:
[legend]

Public Member Functions

std::optional< Boxdviewbox () const
 Get the parsed value of the viewBox attribute, if specified, which defines a rectangle in userspace that should be mapped to the SVG viewport bounds established by the pattern.
 
PreserveAspectRatio preserveAspectRatio () const
 The value of the preserveAspectRatio attribute, which defines how to scale the viewport to fit the content.
 
Lengthd x () const
 Get the value of the x attribute, which defines the top-left X coordinate of the rectangle indicating how pattern tiles are placed and spread.
 
Lengthd y () const
 Get the value of the y attribute, which defines the top-left Y coordinate of the rectangle indicating how pattern tiles are placed and spread.
 
std::optional< Lengthdwidth () const
 Get the value of the width attribute, if specified, which defines the width of the rectangle indicating how pattern tiles are placed and spread.
 
std::optional< Lengthdheight () const
 Get the value of the height attribute, if specified, which defines the height of the rectangle indicating how pattern tiles are placed and spread.
 
PatternUnits patternUnits () const
 Get the value of the patternUnits attribute, which defines the coordinate system for attributes x, y, width, and height.
 
PatternContentUnits patternContentUnits () const
 Get the value of the patternContentUnits attribute, which defines the coordinate system for the contents of the pattern.
 
Transformd patternTransform () const
 Get the value of the patternTransform attribute, which is an optional transformation from the pattern coordinate system onto the target coordinate system, allowing transformations such as skewing the pattern tiles.
 
std::optional< RcStringhref () const
 Get the value of the href attribute, if specified, which is a reference to another pattern element to use as a template.
 
void setViewbox (OptionalRef< Boxd > viewbox)
 Set the viewBox attribute, which defines a rectangle in userspace that should be mapped to the SVG viewport bounds established by the pattern.
 
void setPreserveAspectRatio (PreserveAspectRatio preserveAspectRatio)
 Set the preserveAspectRatio attribute, which defines how to scale the viewport to fit the content.
 
void setX (Lengthd value)
 Set the x attribute, which defines the top-left X coordinate of the rectangle indicating how pattern tiles are placed and spread.
 
void setY (Lengthd value)
 Set the y attribute, which defines the top-left Y coordinate of the rectangle indicating how pattern tiles are placed and spread.
 
void setWidth (OptionalRef< Lengthd > value)
 Set the width attribute, which defines the width of the rectangle indicating how pattern tiles are placed and spread.
 
void setHeight (OptionalRef< Lengthd > value)
 Set the height attribute, which defines the height of the rectangle indicating how pattern tiles are placed and spread.
 
void setPatternUnits (PatternUnits value)
 Set the patternUnits attribute, which defines the coordinate system for attributes x, y, width, and height.
 
void setPatternContentUnits (PatternContentUnits value)
 Set the patternContentUnits attribute, which defines the coordinate system for the contents of the pattern.
 
void setPatternTransform (Transformd transform)
 Set the patternTransform attribute, which is an optional transformation from the pattern coordinate system onto the target coordinate system.
 
void setHref (OptionalRef< RcStringOrRef > value)
 Set the href attribute, which is a reference to another pattern element to use as a template.
 
- Public Member Functions inherited from donner::svg::SVGElement
 SVGElement (const SVGElement &other)
 Create another reference to the same SVGElement.
 
 SVGElement (SVGElement &&other) noexcept
 Move constructor.
 
 ~SVGElement () noexcept=default
 Destructor.
 
SVGElementoperator= (const SVGElement &other)
 Create another reference to the same SVGElement.
 
SVGElementoperator= (SVGElement &&other) noexcept
 Move assignment operator.
 
ElementType type () const
 Get the ElementType for known XML element types.
 
XMLQualifiedNameRef tagName () const
 Get the XML tag name string for this element.
 
bool isKnownType () const
 Returns true if this is a known element type, returns false if this is an SVGUnknownElement.
 
Entity entity () const
 Get the underlying Entity, for advanced use-cases that require direct access to the ECS.
 
RcString id () const
 Get the element id, the value of the "id" attribute.
 
void setId (std::string_view id)
 Set the element id, the value of the "id" attribute.
 
RcString className () const
 Get the element class name, the value of the "class" attribute.
 
void setClassName (std::string_view name)
 Set the element class name, the value of the "class" attribute.
 
void setStyle (std::string_view style)
 Set the element style, the value of the "style" attribute.
 
base::parser::ParseResult< bool > trySetPresentationAttribute (std::string_view name, std::string_view value)
 Set the value of a presentation attribute, such as "fill" or "stroke".
 
bool hasAttribute (const XMLQualifiedNameRef &name) const
 Returns true if the element has an attribute with the given name.
 
std::optional< RcStringgetAttribute (const XMLQualifiedNameRef &name) const
 Get the value of an attribute, if it exists.
 
SmallVector< XMLQualifiedNameRef, 1 > findMatchingAttributes (const XMLQualifiedNameRef &matcher) const
 Find attributes matching the given name matcher.
 
void setAttribute (const XMLQualifiedNameRef &name, std::string_view value)
 Set the value of a generic XML attribute, which may be either a presentation attribute or custom user-provided attribute.
 
void removeAttribute (const XMLQualifiedNameRef &name)
 Remove an attribute, which may be either a presentation attribute or custom user-provided attribute.
 
SVGDocumentownerDocument ()
 Get the SVGDocument that holds this element.
 
std::optional< SVGElementparentElement () const
 Get this element's parent, if it exists.
 
std::optional< SVGElementfirstChild () const
 Get the first child of this element, if it exists.
 
std::optional< SVGElementlastChild () const
 Get the last child of this element, if it exists.
 
std::optional< SVGElementpreviousSibling () const
 Get the previous sibling of this element, if it exists.
 
std::optional< SVGElementnextSibling () const
 Get the next sibling of this element, if it exists.
 
SVGElement insertBefore (SVGElement newNode, std::optional< SVGElement > referenceNode)
 Insert newNode as a child, before referenceNode.
 
SVGElement appendChild (SVGElement child)
 Append child as a child of the current node.
 
SVGElement replaceChild (SVGElement newChild, SVGElement oldChild)
 Replace oldChild with newChild in the tree, removing oldChild and inserting newChild in its place.
 
SVGElement removeChild (SVGElement child)
 Remove child from this node.
 
void remove ()
 Remove this node from its parent, if it has one.
 
bool operator== (const SVGElement &other) const
 Returns true if the two SVGElement handles reference the same underlying document.
 
bool operator!= (const SVGElement &other) const
 Returns true if the two SVGElement handles reference the same underlying document.
 
template<typename Derived >
bool isa () const
 Return true if this element "is a" instance of type, if it be cast to a specific type with cast.
 
template<typename Derived >
Derived cast ()
 Cast this element to its derived type.
 
template<typename Derived >
Derived cast () const
 Cast this element to its derived type (const version).
 
template<typename Derived >
std::optional< Derived > tryCast ()
 Cast this element to its derived type, if possible.
 
template<typename Derived >
std::optional< const Derived > tryCast () const
 Cast this element to its derived type, if possible.
 
std::optional< SVGElementquerySelector (std::string_view selector)
 Find the first element in the tree that matches the given CSS selector.
 
const PropertyRegistrygetComputedStyle () const
 Get the computed CSS style of this element, after the CSS cascade.
 

Static Public Member Functions

static SVGPatternElement Create (SVGDocument &document)
 Create a new "<pattern>" element.
 

Static Public Attributes

static constexpr ElementType Type = ElementType::Pattern
 Element type.
 
static constexpr std::string_view Tag {"pattern"}
 XML tag name, "<pattern>".
 

Protected Member Functions

 SVGPatternElement (EntityHandle handle)
 Create an SVGPatternElement wrapper from an entity.
 
- Protected Member Functions inherited from donner::svg::SVGElement
 SVGElement (EntityHandle handle)
 Internal constructor to create an SVGElement from an EntityHandle.
 
Registryregistry () const
 Get the underlying ECS Registry, which holds all data for the document, for advanced use.
 
EntityHandle toHandle (Entity entity) const
 Convert an Entity to an EntityHandle, for advanced use.
 

Additional Inherited Members

- Static Protected Member Functions inherited from donner::svg::SVGElement
static EntityHandle CreateEntity (Registry &registry, const XMLQualifiedNameRef &tagName, ElementType Type)
 Create a new Entity of the given type.
 
- Protected Attributes inherited from donner::svg::SVGElement
EntityHandle handle_
 The underlying ECS Entity for this element, which holds all data.
 

Detailed Description

DOM object for a "<pattern>" element.

<pattern id="MyPattern" viewbox="0,0,10,10" width="15%" height="15%">
<circle cx="5" cy="5" r="5" fill="red" />
</pattern>

To reference it with a fill:

<rect fill="url(#MyPattern)" width="300" height="300" />

Attribute Default Description
viewBox (none) A list of four numbers (min-x, min-y, width, height) separated by whitespace and/or a comma, that specify a rectangle in userspace that should be mapped to the SVG viewport bounds established by the pattern.
preserveAspectRatio xMidYMid meet How to scale the viewport to fit the content. Only applies is viewBox is specified.
x 0 Defines the top-left X coordinate of a rectangle indicating how pattern tiles are placed and spread. The coordinate system is determined by the combination of the patternUnits and patternTransform attributes.
y 0 Defines the top-left Y coordinate of a rectangle indicating how pattern tiles are placed and spread. The coordinate system is determined by the combination of the patternUnits and patternTransform attributes.
width 0 Defines the width of a rectangle indicating how pattern tiles are placed and spread. The coordinate system is determined by the combination of the patternUnits and patternTransform attributes.
height 0 Defines the height of a rectangle indicating how pattern tiles are placed and spread. The coordinate system is determined by the combination of the patternUnits and patternTransform attributes.
patternUnits objectBoundingBox Defines the coordinate system for attributes x, y, width, and height.
patternContentUnits userSpaceOnUse Defines the coordinate system for the contents of the pattern. Note that this attribute has no effect if the viewBox attribute is specified.
patternTransform identity Optional transformation from the pattern coordinate system onto the target coordinate system, allowing things like skewing the pattern tiles.
href (none) Reference to another pattern element to use as a template.

Member Function Documentation

◆ Create()

SVGPatternElement donner::svg::SVGPatternElement::Create ( SVGDocument & document)
static

Create a new "<pattern>" element.

Parameters
documentContaining document.

◆ patternContentUnits()

PatternContentUnits donner::svg::SVGPatternElement::patternContentUnits ( ) const

Get the value of the patternContentUnits attribute, which defines the coordinate system for the contents of the pattern.

Note that this attribute has no effect if the viewBox attribute is specified.

◆ preserveAspectRatio()

PreserveAspectRatio donner::svg::SVGPatternElement::preserveAspectRatio ( ) const

The value of the preserveAspectRatio attribute, which defines how to scale the viewport to fit the content.

Only applies is viewBox is specified.

◆ setHeight()

void donner::svg::SVGPatternElement::setHeight ( OptionalRef< Lengthd > value)

Set the height attribute, which defines the height of the rectangle indicating how pattern tiles are placed and spread.

Parameters
valueThe height value to set.

◆ setHref()

void donner::svg::SVGPatternElement::setHref ( OptionalRef< RcStringOrRef > value)

Set the href attribute, which is a reference to another pattern element to use as a template.

Parameters
valueThe href value to set.

◆ setPatternContentUnits()

void donner::svg::SVGPatternElement::setPatternContentUnits ( PatternContentUnits value)

Set the patternContentUnits attribute, which defines the coordinate system for the contents of the pattern.

Parameters
valueThe patternContentUnits value to set.

◆ setPatternTransform()

void donner::svg::SVGPatternElement::setPatternTransform ( Transformd transform)

Set the patternTransform attribute, which is an optional transformation from the pattern coordinate system onto the target coordinate system.

Parameters
transformThe patternTransform value to set.

◆ setPatternUnits()

void donner::svg::SVGPatternElement::setPatternUnits ( PatternUnits value)

Set the patternUnits attribute, which defines the coordinate system for attributes x, y, width, and height.

Parameters
valueThe patternUnits value to set.

◆ setPreserveAspectRatio()

void donner::svg::SVGPatternElement::setPreserveAspectRatio ( PreserveAspectRatio preserveAspectRatio)

Set the preserveAspectRatio attribute, which defines how to scale the viewport to fit the content.

Only applies if viewBox is specified.

Parameters
preserveAspectRatioThe preserveAspectRatio value to set.

◆ setViewbox()

void donner::svg::SVGPatternElement::setViewbox ( OptionalRef< Boxd > viewbox)

Set the viewBox attribute, which defines a rectangle in userspace that should be mapped to the SVG viewport bounds established by the pattern.

Parameters
viewboxThe viewBox value to set.

◆ setWidth()

void donner::svg::SVGPatternElement::setWidth ( OptionalRef< Lengthd > value)

Set the width attribute, which defines the width of the rectangle indicating how pattern tiles are placed and spread.

Parameters
valueThe width value to set.

◆ setX()

void donner::svg::SVGPatternElement::setX ( Lengthd value)

Set the x attribute, which defines the top-left X coordinate of the rectangle indicating how pattern tiles are placed and spread.

Parameters
valueThe X coordinate value to set.

◆ setY()

void donner::svg::SVGPatternElement::setY ( Lengthd value)

Set the y attribute, which defines the top-left Y coordinate of the rectangle indicating how pattern tiles are placed and spread.

Parameters
valueThe Y coordinate value to set.

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