9#include "abg-internal.h"
11ABG_BEGIN_EXPORT_DECLARATIONS
15ABG_END_EXPORT_DECLARATIONS
26 std::string filename(_M_title +
".svg");
27 std::ofstream f(filename);
28 if (!f.is_open() || !f.good())
29 throw std::runtime_error(
"abigail::svg::write fail");
31 f << _M_sstream.str() << std::endl;
33 catch(std::exception& e)
44 const std::string start = R
"_delimiter_(<?xml version="1.0" encoding="utf-8"?>
45<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
47 id="svg2" xml:space="preserve"
48 xmlns:dc="http://purl.org/dc/elements/1.1/"
49 xmlns:cc="http://creativecommons.org/ns#"
50 xmlns:svg="http://www.w3.org/2000/svg"
51 xmlns="http://www.w3.org/2000/svg"
52 xmlns:xlink="http://www.w3.org/1999/xlink"
55 const std::string
units(
"__units");
56 const std::string width(
"__width");
57 const std::string height(
"__height");
59 std::string strip = R
"_delimiter_(x="0__units" y="0__units"
60width="__width__units" height="__height__units"
61viewBox="0 0 __width __height" enable-background="new 0 0 __width __height">
66 string_replace(strip, height, std::to_string(_M_canvas._M_height));
69 _M_sstream << strip << std::endl;
76 _M_sstream <<
"</svg>" << std::endl;
82 _M_sstream <<
"<title>" << _M_title <<
"</title>" << std::endl;
90 unsigned int xcur = 0;
91 const unsigned int padding = 10;
92 const std::string x(
"__x");
93 const std::string y(
"__y");
94 const std::string label(
"__label");
95 const std::string style(
"__style");
96 const std::string offset(
"OFFSET");
97 const std::string size(
"SIZE");
98 const std::string align(
"ALIGN");
101 std::string text_strip = R
"_delimiter_(<text x="__x" y="__y" transform="rotate(270 __x __y)" __style>__label</text>
105 string_replace(text_strip, y, std::to_string(_M_y_origin - padding));
106 string_replace(text_strip, style, _M_typo.to_attribute(typography::start));
109 xcur = _M_x_origin + (.5 * _M_x_space);
110 std::string offset_strip = text_strip;
115 std::string size_strip = text_strip;
120 std::string align_strip = text_strip;
124 _M_sstream <<
"<g><!-- vertical labels -->" << std::endl;
125 _M_sstream << offset_strip;
126 _M_sstream << size_strip;
127 _M_sstream << align_strip;
128 _M_sstream <<
"</g>" << std::endl;
136 unsigned int xcur = 0;
137 const unsigned int yend = _M_y_origin + _M_y_size * _M_y_space;
138 const std::string x(
"__x");
139 const std::string y1(
"__y1");
140 const std::string y2(
"__y2");
142 std::string strip = R
"_delimiter_(<path stroke="black" stroke-width="1" d="M __x __y1 L __x __y2"/>
146 string_replace(strip, y1, std::to_string(_M_y_origin - _M_y_space));
150 std::string strip_1 = strip;
154 std::string strip_2 = strip;
158 std::string strip_3 = strip;
162 std::string strip_4 = strip;
166 _M_sstream <<
"<g><!-- vertical lines -->" << std::endl;
167 _M_sstream << strip_1;
168 _M_sstream << strip_2;
169 _M_sstream << strip_3;
170 _M_sstream << strip_4;
171 _M_sstream <<
"</g>" << std::endl;
178svg::add_y_row(
const row& __r)
182 unsigned int xcur = 0;
184 const unsigned int ycur = _M_y_origin + (_M_y_size * _M_y_space) + (.5 * _M_y_space);
185 const std::string x(
"__x");
186 const std::string y(
"__y");
187 const std::string name(
"__name");
188 const std::string style(
"__style");
189 const std::string
color(
"__color");
190 const std::string width(
"__width");
191 const std::string height(
"__height");
192 const std::string val(
"__val");
194 std::string rect_strip = R
"_delimiter_(<rect x="__x" y="__y" fill="__color" stroke="__color" stroke-width="1" width="__width" height="__height"/>
197 xcur = _M_x_origin + _M_x_space;
198 chroma = color_to_string(__r._M_style._M_fill_color);
200 string_replace(rect_strip, y, std::to_string(ycur - (.5 * _M_y_space)));
201 string_replace(rect_strip, width, std::to_string(_M_x_space * 2));
207 std::string text_strip = R
"_delimiter_(<text x="__x" y="__y" fill="__color" __style>__val</text>
212 std::string offset_strip(text_strip);
213 xcur = _M_x_origin + (.5 * _M_x_space);
214 chroma = color_to_string(abigail::color::black);
218 string_replace(offset_strip, style, _M_typo.to_attribute(typography::middle));
223 std::string size_strip(text_strip);
225 chroma = color_to_string(__r._M_style._M_text_color);
229 string_replace(size_strip, style, _M_typo.to_attribute(typography::middle));
234 std::string align_strip(text_strip);
239 string_replace(align_strip, style, _M_typo.to_attribute(typography::middle));
244 const unsigned int padding = 10;
245 std::string name_strip(text_strip);
246 xcur = _M_x_origin + (_M_x_size * _M_x_space) + padding;
247 chroma = color_to_string(abigail::color::black);
251 string_replace(name_strip, style, _M_typo.to_attribute(typography::start));
256 _M_sstream <<
"<g><!-- row " << _M_y_size <<
" -->" << std::endl;
257 _M_sstream << rect_strip;
258 _M_sstream << offset_strip;
259 _M_sstream << size_strip;
260 _M_sstream << align_strip;
261 _M_sstream << name_strip;
262 _M_sstream <<
"</g>" << std::endl;
Toplevel namespace for libabigail.
units
Measurement abstraction type, conversion function.
color
Color, conversion function.
void string_replace(std::string &target, const std::string &match, const std::string &replace)
Utility function, like regex_replace.