return *m_bbox;
}
+SVG::SVGElement &SVG::SVGElement::find_child(const SVG::SVGElementType type,
+ std::size_t index) {
+ std::size_t i = 0;
+ for (auto &child : children) {
+ if (child.type == type) {
+ if (i == index) {
+ return child;
+ }
+ ++i;
+ }
+ }
+ throw std::runtime_error(
+ fmt::format("SVG element only has {} \"{}\" children, index {} not found",
+ i, tag(type), index));
+}
+
SVG::SVGRect SVG::SVGElement::text_bbox() const {
assert(type == SVG::SVGElementType::Text && "Not a 'text' element");
/// throw an exception unless the `throw_if_bbox_not_defined` parameter is
/// `false`.
SVG::SVGRect bbox(bool throw_if_bbox_not_defined = true);
+ /// Return the element of the given type with the specified index found among
+ /// the element's children. Throwns an exception if there's no such element
+ /// with the specified index.
+ SVG::SVGElement &find_child(SVG::SVGElementType type, std::size_t index = 0);
bool is_closed_shape_element() const;
bool is_shape_element() const;
/// Return the outline bounding box of the element. The outline bounding box