SVG for C++
Loading...
Searching...
No Matches
SVG::Element Class Reference

Abstract base class for all SVG elements. More...

#include <svg.hpp>

Inherits SVG::AttributeMap.

Inherited by SVG::Defs, SVG::Group, SVG::Polygon, SVG::SVG::Style, SVG::Shape, SVG::Symbol, SVG::Text, and SVG::Title.

Classes

class  BoundingBox
 Represents the top left and bottom right corners of a bounding rectangle. More...
struct  TraversalOptions
class  DepthFirstIterator
class  ConstDepthFirstIterator
class  DepthFirstRange
class  ConstDepthFirstRange

Public Types

using ChildList = std::vector<Element*>
using ConstChildList = std::vector<const Element*>
using ChildMap = std::map<std::string, ChildList>
using ConstChildMap = std::map<std::string, ConstChildList>

Public Member Functions

 Element (const Element &other)
 Element (Element &&other) noexcept
Element & operator= (const Element &)=delete
Element & operator= (Element &&other) noexcept
 Element (const char *id)
 operator std::string () const
std::unique_ptr< Element > clone_element () const
template<typename T, typename... Args>
T * add_child (Args &&... args)
template<typename T>
Element & operator<< (T &&node)
template<typename T>
std::vector< T * > get_children ()
template<typename T>
std::vector< const T * > get_children () const
template<typename T>
std::vector< T * > get_immediate_children ()
template<typename T>
std::vector< const T * > get_immediate_children () const
Element * get_element_by_id (const std::string &id)
const Element * get_element_by_id (const std::string &id) const
std::vector< Element * > get_elements_by_class (const std::string &clsname)
std::vector< const Element * > get_elements_by_class (const std::string &clsname) const
const Element * parent () const
virtual ElementKind kind () const
Element & id (const std::string &value)
std::string id () const
void autoscale (const Margins &margins=DEFAULT_MARGINS)
void autoscale (const double margin)
void autoscale (const AutoscaleOptions &options)
void responsive_autoscale (const Margins &margins=DEFAULT_MARGINS)
void responsive_autoscale (const double margin)
void responsive_autoscale (const AutoscaleOptions &options)
Element & layout_bbox (const BoundingBox &bbox)
Element & bbox_padding (const Margins &padding)
Element & bbox_padding (double padding)
Element & clear_layout_bbox ()
bool has_layout_bbox () const
BoundingBox layout_bbox () const
Element & snap_to (const Element &target, RelativeAlignment relative, Point offset=Point(0, 0))
Element & snap_to (const Element &target, Alignment alignment, Point offset=Point(0, 0))
Element & align_to (const Element &target, Axis axis, Point offset=Point(0, 0))
Element & align_to (const Element &target, Axis axis, Anchor anchor, Point offset=Point(0, 0))
TransformList transform_list ()
TransformList transform_list () const
TransformList transform ()
TransformList transform () const
virtual BoundingBox get_bbox () const
ChildMap get_children ()
ConstChildMap get_children () const
DepthFirstIterator begin ()
ConstDepthFirstIterator begin () const
DepthFirstIterator end ()
ConstDepthFirstIterator end () const
DepthFirstRange depth_first ()
DepthFirstRange depth_first (TraversalOptions options)
ConstDepthFirstRange depth_first () const
ConstDepthFirstRange depth_first (TraversalOptions options) const
DepthFirstRange descendants ()
DepthFirstRange descendants (TraversalOptions options)
ConstDepthFirstRange descendants () const
ConstDepthFirstRange descendants (TraversalOptions options) const
template<>
Element::ChildList get_immediate_children ()
template<>
Element::ConstChildList get_immediate_children () const
 AttributeMap ()=default
 AttributeMap (SVGAttrib _attr)
Public Member Functions inherited from SVG::AttributeMap
 AttributeMap (SVGAttrib _attr)
const SVGAttrib & attrs () const
bool has_attr (const std::string &key) const
std::string get_attr (const std::string &key, const std::string &fallback="") const
template<typename T>
std::enable_if< detail::is_numeric_attr_type< T >::value, T >::type get_attr (const std::string &key, T fallback) const
template<typename T>
AttributeMap & set_attr (const std::string key, T value)
AttributeMap & set_attr (const std::string key, const Color &value)
AttributeMap & set_attrs (std::initializer_list< std::pair< std::string, std::string > > values)
AttributeMap & set_attrs (const SVGAttrib &values)
AttrSetter set_attr (const std::string key)
ClassList class_list ()
ClassList class_list () const
TransformList transform_list ()
TransformList transform_list () const
TransformList transform ()
TransformList transform () const
template<>
AttributeMap & set_attr (const std::string key, const double value)
template<>
AttributeMap & set_attr (const std::string key, const char *value)
template<>
AttributeMap & set_attr (const std::string key, const std::string value)

Protected Types

using ChildIterator = std::vector<std::unique_ptr<Element>>::iterator

Protected Member Functions

std::vector< Element * > get_children_helper ()
std::vector< const Element * > get_children_helper () const
BoundingBox get_autoscale_bbox () const
BoundingBox measured_layout_bbox () const
BoundingBox include_stroke_width (const BoundingBox &bbox) const
void autoscale_nested_svgs (const AutoscaleOptions &options, bool responsive)
void get_bbox (Element::BoundingBox &, bool visible_only=true) const
void set_viewbox_from_bbox (const BoundingBox &bbox, const Margins &margins)
virtual std::string svg_to_string (const size_t indent_level) const
virtual std::string tag ()
virtual std::string tag () const
virtual std::unique_ptr< Element > clone_element_impl () const
template<typename T>
std::unique_ptr< T > clone_as () const
void set_attr_value (const std::string &key, const std::string &value) override
AttrSetter make_attr_setter (const std::string &key) override
SVG * owner_svg ()
const SVG * owner_svg () const
void set_owner_svg (SVG *owner)
void register_subtree_ids ()
void unregister_subtree_ids ()
void register_own_id ()
void unregister_own_id ()
void clear_children ()
template<class T>
T * insert_new_child (std::unique_ptr< T > child, ChildIterator position)
Element * insert_child (std::unique_ptr< Element > child, ChildIterator position)
void reparent_children ()
double find_numeric (const std::string &key) const
Protected Member Functions inherited from SVG::AttributeMap
SVGAttrib & mutable_attrs ()

Static Protected Member Functions

static detail::AffineTransform transform_for (const Element *element, const detail::AffineTransform &parent_transform)

Protected Attributes

std::vector< std::unique_ptr< Element > > children

Detailed Description

Abstract base class for all SVG elements.

Member Typedef Documentation

◆ ChildIterator

using SVG::Element::ChildIterator = std::vector<std::unique_ptr<Element>>::iterator
protected

Smart pointers to child elements

Constructor & Destructor Documentation

◆ Element()

SVG::Element::Element ( const Element & other)
inline

Copy attributes and deep-copy children without carrying parent or owner indexes.

Member Function Documentation

◆ add_child()

template<typename T, typename... Args>
T * SVG::Element::add_child ( Args &&... args)
inline

Add an SVG element as a child and return a pointer to the element added

◆ align_to() [1/2]

Element & SVG::Element::align_to ( const Element & target,
Axis axis,
Anchor anchor,
Point offset = Point(0, 0) )
inline

Align this element to a target axis using the same anchor on both elements.

◆ align_to() [2/2]

Element & SVG::Element::align_to ( const Element & target,
Axis axis,
Point offset = Point(0, 0) )
inline

Align this element to a target axis, centered by default.

◆ autoscale() [1/2]

void SVG::Element::autoscale ( const AutoscaleOptions & options)
inline

Autoscale with explicit layout behavior options.

Automatically set the width, height, and viewBox attribute of this item so that it can contain all of its children without clipping

Parameters
[in]optionsMargins and nested SVG autoscale behavior

◆ autoscale() [2/2]

void SVG::Element::autoscale ( const double margin)
inline

Like other autoscale() but accepts margin as a percentage

◆ bbox_padding() [1/2]

Element & SVG::Element::bbox_padding ( const Margins & padding)
inline

Inflate measured autoscale/layout bounds; explicit layout_bbox() overrides this padding.

◆ bbox_padding() [2/2]

Element & SVG::Element::bbox_padding ( double padding)
inline

Inflate measured autoscale/layout bounds equally on every side.

◆ begin() [1/2]

Element::DepthFirstIterator SVG::Element::begin ( )
inline

Range-for iteration visits this element and descendants in depth-first document order.

◆ begin() [2/2]

Element::ConstDepthFirstIterator SVG::Element::begin ( ) const
inline

Range-for iteration visits this element and descendants in depth-first document order.

◆ clear_layout_bbox()

Element & SVG::Element::clear_layout_bbox ( )
inline

Remove an explicit autoscale/layout bound override.

◆ clone_element()

std::unique_ptr< Element > SVG::Element::clone_element ( ) const
inline

Return a type-preserving deep copy of this element subtree. Custom subclasses must override clone_element_impl(), usually by returning clone_as<Subclass>().

◆ depth_first() [1/4]

Element::DepthFirstRange SVG::Element::depth_first ( )
inline

Iterate through this element and its descendants in depth-first order.

◆ depth_first() [2/4]

Element::ConstDepthFirstRange SVG::Element::depth_first ( ) const
inline

Iterate through this element and its descendants in depth-first order.

◆ depth_first() [3/4]

Element::DepthFirstRange SVG::Element::depth_first ( TraversalOptions options)
inline

Iterate through this element and its descendants with traversal options.

◆ depth_first() [4/4]

Element::ConstDepthFirstRange SVG::Element::depth_first ( TraversalOptions options) const
inline

Iterate through this element and its descendants with traversal options.

◆ descendants() [1/4]

Element::DepthFirstRange SVG::Element::descendants ( )
inline

Iterate through descendants in depth-first order, excluding this element.

◆ descendants() [2/4]

Element::ConstDepthFirstRange SVG::Element::descendants ( ) const
inline

Iterate through descendants in depth-first order, excluding this element.

◆ descendants() [3/4]

Element::DepthFirstRange SVG::Element::descendants ( TraversalOptions options)
inline

Iterate through descendants in depth-first order with traversal options.

◆ descendants() [4/4]

Element::ConstDepthFirstRange SVG::Element::descendants ( TraversalOptions options) const
inline

Iterate through descendants in depth-first order with traversal options.

◆ find_numeric()

double SVG::Element::find_numeric ( const std::string & key) const
inlineprotected

Return the numeric attribute (if it exists) or NAN

Parameters
[in]keyName of the attribute

◆ get_bbox() [1/2]

Element::BoundingBox SVG::Element::get_bbox ( ) const
inlinevirtual

Compute the bounding box necessary to contain this element

Reimplemented in SVG::SVG, SVG::Symbol, SVG::Text, and SVG::Use.

◆ get_bbox() [2/2]

void SVG::Element::get_bbox ( Element::BoundingBox & box,
bool visible_only = true ) const
inlineprotected

Compute a transform-aware bounding box without recursive traversal.

◆ get_children() [1/4]

Element::ChildMap SVG::Element::get_children ( )
inline

Recursively compute all of the children of an SVG element

◆ get_children() [2/4]

template<typename T>
std::vector< T * > SVG::Element::get_children ( )
inline

Return all children of type T

◆ get_children() [3/4]

Element::ConstChildMap SVG::Element::get_children ( ) const
inline

Recursively compute all of the children of an SVG element

◆ get_children() [4/4]

template<typename T>
std::vector< const T * > SVG::Element::get_children ( ) const
inline

Return all children of type T

◆ get_children_helper() [1/2]

std::vector< Element * > SVG::Element::get_children_helper ( )
inlineprotected

Helper function which populates a std::deque with all of an Element's children

◆ get_children_helper() [2/2]

std::vector< const Element * > SVG::Element::get_children_helper ( ) const
inlineprotected

Helper function which populates a std::deque with all of an Element's children

◆ get_element_by_id() [1/2]

Element * SVG::Element::get_element_by_id ( const std::string & id)
inline

Return the SVG element that has a certain id

◆ get_element_by_id() [2/2]

const Element * SVG::Element::get_element_by_id ( const std::string & id) const
inline

Return the SVG element that has a certain id

◆ get_elements_by_class() [1/2]

std::vector< Element * > SVG::Element::get_elements_by_class ( const std::string & clsname)
inline

Return all SVG elements with a certain class name

◆ get_elements_by_class() [2/2]

std::vector< const Element * > SVG::Element::get_elements_by_class ( const std::string & clsname) const
inline

Return all SVG elements with a certain class name

◆ get_immediate_children() [1/4]

template<>
Element::ChildList SVG::Element::get_immediate_children ( )
inline

Return all immediate children, regardless of type, as Element pointers

◆ get_immediate_children() [2/4]

template<typename T>
std::vector< T * > SVG::Element::get_immediate_children ( )
inline

Return all immediate children of type T

◆ get_immediate_children() [3/4]

template<>
Element::ConstChildList SVG::Element::get_immediate_children ( ) const
inline

Return all immediate children, regardless of type, as Element pointers

◆ get_immediate_children() [4/4]

template<typename T>
std::vector< const T * > SVG::Element::get_immediate_children ( ) const
inline

Return all immediate children of type T

◆ has_layout_bbox()

bool SVG::Element::has_layout_bbox ( ) const
inline

Return true when autoscale/layout uses caller-provided bounds for this element.

◆ kind()

virtual ElementKind SVG::Element::kind ( ) const
inlinevirtual

Return the element category used by typed traversal; custom subclasses default to Custom.

Reimplemented in SVG::Circle, SVG::Defs, SVG::Group, SVG::Line, SVG::Path, SVG::Polygon, SVG::Rect, SVG::SVG, SVG::SVG::Style, SVG::Symbol, SVG::Text, SVG::Title, and SVG::Use.

◆ layout_bbox() [1/2]

Element::BoundingBox SVG::Element::layout_bbox ( ) const
inline

Return explicit autoscale/layout bounds, or this element's measured bounds when unset.

◆ layout_bbox() [2/2]

Element & SVG::Element::layout_bbox ( const BoundingBox & bbox)
inline

Provide explicit bounds for autoscale/layout when built-in measurement is insufficient.

◆ make_attr_setter()

AttributeMap::AttrSetter SVG::Element::make_attr_setter ( const std::string & key)
inlineoverrideprotectedvirtual

Reimplemented from SVG::AttributeMap.

◆ operator<<()

template<typename T>
Element & SVG::Element::operator<< ( T && node)
inline

Move an SVG element into this container

◆ responsive_autoscale() [1/3]

void SVG::Element::responsive_autoscale ( const AutoscaleOptions & options)
inline

Set only the viewBox using explicit layout behavior options.

◆ responsive_autoscale() [2/3]

void SVG::Element::responsive_autoscale ( const double margin)
inline

Set only the viewBox from content bounds and percentage margins.

◆ responsive_autoscale() [3/3]

void SVG::Element::responsive_autoscale ( const Margins & margins = DEFAULT_MARGINS)
inline

Set only the viewBox from content bounds, leaving width and height unchanged.

◆ set_attr_value()

void SVG::Element::set_attr_value ( const std::string & key,
const std::string & value )
inlineoverrideprotectedvirtual

Reimplemented from SVG::AttributeMap.

◆ snap_to() [1/2]

Element & SVG::Element::snap_to ( const Element & target,
Alignment alignment,
Point offset = Point(0, 0) )
inline

Snap this element using RelativeAlignment | Anchor.

◆ snap_to() [2/2]

Element & SVG::Element::snap_to ( const Element & target,
RelativeAlignment relative,
Point offset = Point(0, 0) )
inline

Snap this element to a target side, centered along the target edge by default.

◆ svg_to_string()

std::string SVG::Element::svg_to_string ( const size_t indent_level) const
inlineprotectedvirtual

Reimplemented in SVG::SVG::Style, and SVG::Title.

◆ tag() [1/2]

virtual std::string SVG::Element::tag ( )
inlineprotectedvirtual

SVG string corresponding to this element

◆ tag() [2/2]

virtual std::string SVG::Element::tag ( ) const
inlineprotectedvirtual

The SVG tag of this element Const rendering remains compatible with custom subclasses that still override only non-const tag().


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