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

Base class for elements that support rendering child text content. More...

#include "donner/svg/SVGTextContentElement.h"

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

Public Member Functions

std::optional< LengthdtextLength () const
 Returns the textLength attribute (the author's intended length for the text).
 
void setTextLength (std::optional< Lengthd > value)
 Sets the textLength attribute, which indicates the author-computed total length for the text layout.
 
LengthAdjust lengthAdjust () const
 Returns the lengthAdjust attribute, which controls how the text is stretched or spaced to fit the textLength.
 
void setLengthAdjust (LengthAdjust value)
 Controls how the text is stretched or spaced to fit the textLength.
 
long getNumberOfChars () const
 Returns the total number of addressable characters in the element.
 
double getComputedTextLength () const
 Computes the total advance distance for all glyphs.
 
double getSubStringLength (std::size_t charnum, std::size_t nchars) const
 Computes the advance distance for a substring of text.
 
Vector2d getStartPositionOfChar (std::size_t charnum) const
 Returns the start position (in user space) of the glyphs corresponding to the given character index.
 
Vector2d getEndPositionOfChar (std::size_t charnum) const
 Returns the end position (in user space) of the glyphs corresponding to the given character index.
 
Boxd getExtentOfChar (std::size_t charnum) const
 Returns the bounding box of the glyph cell for the specified character, in the element's coordinate space.
 
double getRotationOfChar (std::size_t charnum) const
 Returns the rotation applied to the glyphs corresponding to the given character index, in degrees.
 
long getCharNumAtPosition (const Vector2d &point) const
 Given a point in the element's coordinate space, returns which character is rendered at that point.
 
void selectSubString (std::size_t charnum, std::size_t nchars)
 Select a substring of characters for user operations (e.g.
 
void appendText (std::string_view text)
 Append text content from text or CDATA nodes.
 
RcString textContent () const
 Get the raw text content concatenated from all child text nodes.
 
- Public Member Functions inherited from donner::svg::SVGGraphicsElement
Transformd transform () const
 Get the 2d transformation for this element, element-from-parent.
 
void setTransform (const Transformd &transform)
 Set the 2d transformation for this element, element-from-parent. This is a no-op if the transform is identity.
 
Transformd elementFromWorld () const
 Get the absolute element-from-world transform for this element.
 
- 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.
 
xml::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.
 
EntityHandle entityHandle () const
 Get the underlying EntityHandle, 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.
 
void updateStyle (std::string_view style)
 Update the element style, adding new attributes or overridding existing ones (without removing them).
 
ParseResult< booltrySetPresentationAttribute (std::string_view name, std::string_view value)
 Set the value of a presentation attribute, such as "fill" or "stroke".
 
bool hasAttribute (const xml::XMLQualifiedNameRef &name) const
 Returns true if the element has an attribute with the given name.
 
std::optional< RcStringgetAttribute (const xml::XMLQualifiedNameRef &name) const
 Get the value of an attribute, if it exists.
 
SmallVector< xml::XMLQualifiedNameRef, 1 > findMatchingAttributes (const xml::XMLQualifiedNameRef &matcher) const
 Find attributes matching the given name matcher.
 
void setAttribute (const xml::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 xml::XMLQualifiedNameRef &name)
 Remove an attribute, which may be either a presentation attribute or custom user-provided attribute.
 
SVGDocument ownerDocument ()
 Get an owning reference to the SVGDocument containing 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.
 
void insertBefore (const SVGElement &newNode, std::optional< SVGElement > referenceNode)
 Insert newNode as a child, before referenceNode.
 
void appendChild (const SVGElement &child)
 Append child as a child of the current node.
 
void replaceChild (const SVGElement &newChild, const SVGElement &oldChild)
 Replace oldChild with newChild in the tree, removing oldChild and inserting newChild in its place.
 
void removeChild (const 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< DerivedtryCast ()
 Cast this element to its derived type, if possible.
 
template<typename Derived >
std::optional< const DerivedtryCast () 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 constexpr bool IsBaseOf (ElementType type)
 Returns true if the given element type can be cast to SVGTextContentElement.
 
- Static Public Member Functions inherited from donner::svg::SVGGraphicsElement
static constexpr bool IsBaseOf (ElementType type)
 Returns true if the given element type can be cast to SVGTextContentElement.
 

Protected Member Functions

 SVGTextContentElement (EntityHandle handle)
 Inheriting constructor to be called by derived classes.
 
- Protected Member Functions inherited from donner::svg::SVGGraphicsElement
 SVGGraphicsElement (EntityHandle handle)
 Inheriting constructor to be called by derived classes. SVGGraphicsElement cannot be instantiated directly.
 
- 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.
 

Friends

class parser::SVGParserImpl
 

Additional Inherited Members

- Static Protected Member Functions inherited from donner::svg::SVGElement
static EntityHandle CreateEmptyEntity (SVGDocument &document)
 Create a new Entity within the document ECS, and return a handle to it.
 
static void CreateEntityOn (EntityHandle handle, const xml::XMLQualifiedNameRef &tagName, ElementType Type)
 Create a new SVG element instance on a given Entity.
 
- Protected Attributes inherited from donner::svg::SVGElement
EntityHandle handle_
 The underlying ECS Entity for this element, which holds all data.
 

Detailed Description

Base class for elements that support rendering child text content.

This class matches the behavior of the IDL interface SVGTextContentElement. It inherits from SVGGraphicsElement, but is not directly instantiable.

See also
https://www.w3.org/TR/SVG2/text.html#InterfaceSVGTextContentElement

Constructor & Destructor Documentation

◆ SVGTextContentElement()

donner::svg::SVGTextContentElement::SVGTextContentElement ( EntityHandle handle)
explicitprotected

Inheriting constructor to be called by derived classes.

SVGTextContentElement cannot be instantiated directly.

Parameters
handleThe handle to the underlying entity.

Member Function Documentation

◆ appendText()

void donner::svg::SVGTextContentElement::appendText ( std::string_view text)

Append text content from text or CDATA nodes.

Parameters
textText content to append.

◆ getCharNumAtPosition()

long donner::svg::SVGTextContentElement::getCharNumAtPosition ( const Vector2d & point) const

Given a point in the element's coordinate space, returns which character is rendered at that point.

Returns -1 if none.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getCharNumAtPosition

◆ getComputedTextLength()

double donner::svg::SVGTextContentElement::getComputedTextLength ( ) const

Computes the total advance distance for all glyphs.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getComputedTextLength

◆ getEndPositionOfChar()

Vector2d donner::svg::SVGTextContentElement::getEndPositionOfChar ( std::size_t charnum) const

Returns the end position (in user space) of the glyphs corresponding to the given character index.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getEndPositionOfChar

◆ getExtentOfChar()

Boxd donner::svg::SVGTextContentElement::getExtentOfChar ( std::size_t charnum) const

Returns the bounding box of the glyph cell for the specified character, in the element's coordinate space.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getExtentOfChar

◆ getNumberOfChars()

long donner::svg::SVGTextContentElement::getNumberOfChars ( ) const

Returns the total number of addressable characters in the element.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getNumberOfChars

◆ getRotationOfChar()

double donner::svg::SVGTextContentElement::getRotationOfChar ( std::size_t charnum) const

Returns the rotation applied to the glyphs corresponding to the given character index, in degrees.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getRotationOfChar

◆ getStartPositionOfChar()

Vector2d donner::svg::SVGTextContentElement::getStartPositionOfChar ( std::size_t charnum) const

Returns the start position (in user space) of the glyphs corresponding to the given character index.

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getStartPositionOfChar

◆ getSubStringLength()

double donner::svg::SVGTextContentElement::getSubStringLength ( std::size_t charnum,
std::size_t nchars ) const

Computes the advance distance for a substring of text.

The substring is defined by the character positions [charnum, charnum + nchars).

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__getSubStringLength

◆ lengthAdjust()

LengthAdjust donner::svg::SVGTextContentElement::lengthAdjust ( ) const

Returns the lengthAdjust attribute, which controls how the text is stretched or spaced to fit the textLength.

See also
https://www.w3.org/TR/SVG2/text.html#TextElementLengthAdjustAttribute

◆ selectSubString()

void donner::svg::SVGTextContentElement::selectSubString ( std::size_t charnum,
std::size_t nchars )

Select a substring of characters for user operations (e.g.

text highlight).

See also
https://www.w3.org/TR/SVG2/text.html#__svg__SVGTextContentElement__selectSubString

◆ setLengthAdjust()

void donner::svg::SVGTextContentElement::setLengthAdjust ( LengthAdjust value)

Controls how the text is stretched or spaced to fit the textLength.

Parameters
valueAdjustment mode, defaults to LengthAdjust::Spacing.

◆ setTextLength()

void donner::svg::SVGTextContentElement::setTextLength ( std::optional< Lengthd > value)

Sets the textLength attribute, which indicates the author-computed total length for the text layout.

Parameters
valueLength value.

◆ textContent()

RcString donner::svg::SVGTextContentElement::textContent ( ) const

Get the raw text content concatenated from all child text nodes.

Returns
Text content string.

◆ textLength()

std::optional< Lengthd > donner::svg::SVGTextContentElement::textLength ( ) const

Returns the textLength attribute (the author's intended length for the text).

See also
https://www.w3.org/TR/SVG2/text.html#TextElementTextLengthAttribute

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