}
}
+void SVGAnalyzer::set_text_anchor(std::string_view text_anchor) {
+ current_element().attributes.text_anchor = text_anchor;
+}
+
void SVGAnalyzer::set_width(double width) {
current_element().attributes.width = width;
}
void set_stroke(std::string_view stroke) override;
void set_point(std::pair<double, double> point) override;
void set_text(std::string_view text) override;
+ void set_text_anchor(std::string_view text_anchor) override;
void set_transform(double a, double b, double c, double d, double e,
double f) override;
void set_viewBox(double x, double y, double width, double height) override;
virtual void set_point(std::pair<double, double> point) = 0;
virtual void set_stroke(std::string_view stroke) = 0;
virtual void set_text(std::string_view text) = 0;
+ virtual void set_text_anchor(std::string_view text_anchor) = 0;
virtual void set_transform(double a, double b, double c, double d, double e,
double f) = 0;
virtual void set_viewBox(double x, double y, double width, double height) = 0;
attributes.viewBox.height);
break;
case SVG::SVGElementType::Text:
- // ignore for now
+ attributes_str +=
+ fmt::format(R"(text-anchor="{}")", attributes.text_anchor);
break;
case SVG::SVGElementType::Title:
// Graphviz doesn't generate attributes on 'title' elements
double rx;
double ry;
std::string stroke;
+ std::string text_anchor;
std::optional<SVGMatrix> transform;
SVGRect viewBox;
double width;
m_svgAnalyzer->set_class({v.begin(), v.end()});
}
+void SvgppContext::set(svgpp::tag::attribute::text_anchor,
+ svgpp::tag::value::start) {
+ m_svgAnalyzer->set_text_anchor("start");
+}
+
+void SvgppContext::set(svgpp::tag::attribute::text_anchor,
+ svgpp::tag::value::middle) {
+ m_svgAnalyzer->set_text_anchor("middle");
+}
+
+void SvgppContext::set(svgpp::tag::attribute::text_anchor,
+ svgpp::tag::value::end) {
+ m_svgAnalyzer->set_text_anchor("end");
+}
+
void SvgppContext::set(svgpp::tag::attribute::viewBox, const double v1,
const double v2, const double v3, const double v4) {
m_svgAnalyzer->set_viewBox(v1, v2, v3, v4);
void set(svgpp::tag::attribute::id a, boost::iterator_range<const char *> v);
void set(svgpp::tag::attribute::class_ a,
boost::iterator_range<const char *> v);
+ void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::start v);
+ void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::middle v);
+ void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::end v);
void set(svgpp::tag::attribute::viewBox a, double v1, double v2, double v3,
double v4);
void set_text(boost::iterator_range<const char *> v);
using processed_attributes_t =
boost::mpl::set<svgpp::traits::shapes_attributes_by_element,
- svgpp::tag::attribute::class_, //
- svgpp::tag::attribute::cx, //
- svgpp::tag::attribute::cy, //
- svgpp::tag::attribute::fill, //
- svgpp::tag::attribute::height, //
- svgpp::tag::attribute::id, //
- svgpp::tag::attribute::points, //
- svgpp::tag::attribute::rx, //
- svgpp::tag::attribute::ry, //
- svgpp::tag::attribute::stroke, //
- svgpp::tag::attribute::transform, //
- svgpp::tag::attribute::viewBox, //
- svgpp::tag::attribute::width //
+ svgpp::tag::attribute::class_, //
+ svgpp::tag::attribute::cx, //
+ svgpp::tag::attribute::cy, //
+ svgpp::tag::attribute::fill, //
+ svgpp::tag::attribute::height, //
+ svgpp::tag::attribute::id, //
+ svgpp::tag::attribute::points, //
+ svgpp::tag::attribute::rx, //
+ svgpp::tag::attribute::ry, //
+ svgpp::tag::attribute::stroke, //
+ svgpp::tag::attribute::text_anchor, //
+ svgpp::tag::attribute::transform, //
+ svgpp::tag::attribute::viewBox, //
+ svgpp::tag::attribute::width //
>::type;
svgpp::document_traversal<
// yet handle all attributes on the 'path' element
break;
}
- if (recreated_svg_lines[i] == "<text>a</text>") {
- // stop comparison here for polygon based shapes since we do not yet
- // handle all attributes on the 'text' element
+ if (recreated_svg_lines[i] == "<text text-anchor=\"middle\">a</text>") {
+ // stop comparison here since we do not yet handle all attributes on the
+ // 'text' element
break;
}
REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);
CHECK(recreated_svg.find("<title>a</title>") != std::string::npos);
CHECK(recreated_svg.find("<title>b</title>") != std::string::npos);
if (shape != "point") {
- CHECK(recreated_svg.find("<text>a</text>") != std::string::npos);
- CHECK(recreated_svg.find("<text>b</text>") != std::string::npos);
+ CHECK(recreated_svg.find("<text text-anchor=\"middle\">a</text>") !=
+ std::string::npos);
+ CHECK(recreated_svg.find("<text text-anchor=\"middle\">b</text>") !=
+ std::string::npos);
}
CHECK(recreated_svg.find("<path fill=\"none\" stroke=\"black\"/>") !=
std::string::npos);