16#ifndef MiL_SVG_ELEMENTS_H
17#define MiL_SVG_ELEMENTS_H 1
75 _M_sstream <<
"url(#" <<
id <<
")" << k::quote;
83 _M_sstream <<
"url(#" <<
id <<
")" << k::quote;
103 _M_sstream << k::space <<
"transform=" << k::quote << s << k::quote;
157 _M_sstream <<
"<g id=" << k::quote << name << k::quote << k::space;
165 const style& sty = k::no_style)
167 _M_sstream <<
"<g id=" << k::quote << name << k::quote;
204 {
return "</defs>"; }
248 _M_sstream <<
"href=" << k::quote << url << k::quote;
258 add_data(
const string& url,
const string relt,
const string ast,
259 const string cors =
"anonymous")
261 _M_sstream <<
"rel=" << k::quote << relt << k::quote << k::space;
262 _M_sstream <<
"href=" << k::quote << url << k::quote << k::space;
263 _M_sstream <<
"as=" << k::quote << ast << k::quote << k::space;
264 _M_sstream <<
"crossorigin=" << k::quote << cors << k::quote << k::space;
265 _M_sstream <<
"referrerpolicy=" << k::quote <<
"no-referrer" << k::quote;
305 _M_sstream <<
"<filter id=" << k::quote <<
id << k::quote <<
">"
314 auto [ width, height ] = blur_area;
316 _M_sstream <<
"<filter id=" << k::quote <<
id << k::quote << k::space
317 <<
"x=" << k::quote << x << k::quote << k::space
318 <<
"y=" << k::quote << y << k::quote << k::space
319 <<
"width=" << k::quote << width << k::quote << k::space
320 <<
"height=" << k::quote << height << k::quote
340 stream <<
"<feGaussianBlur in=";
341 stream << k::quote <<
in << k::quote << k::space;
342 stream <<
"stdDeviation=" << k::quote << dev << k::quote << k::space;
388 stop(
const string off,
const color& klr,
const double opacity = 1.0)
390 _M_sstream <<
"<stop offset=" << k::quote << off << k::quote << k::space
391 <<
"stop-color=" << k::quote <<
to_string(klr) << k::quote;
395 <<
"stop-opacity=" << k::quote << opacity << k::quote;
405 const double ratio =
static_cast<double>(numer)/
static_cast<double>(denom);
407 return std::to_string(perc) +
"%";
424 _M_sstream <<
"<radialGradient id=" << k::quote <<
"default" << k::quote;
435 _M_sstream <<
"<radialGradient id=" << k::quote <<
id << k::quote;
438 _M_sstream << k::space <<
"r=" << k::quote << radius << k::quote;
439 _M_sstream << k::space <<
"cx=" << k::quote << cx << k::quote;
440 _M_sstream << k::space <<
"cy=" << k::quote << cy << k::quote;
454 _M_sstream <<
"<radialGradient id=" << k::quote <<
id << k::quote
455 << k::space <<
"r=" << k::quote << radius << k::quote;
456 _M_sstream << k::space <<
"cx=" << k::quote << cx << k::quote;
457 _M_sstream << k::space <<
"cy=" << k::quote << cy << k::quote;
460 _M_sstream << k::space <<
"fx=" << k::quote << fx << k::quote;
461 _M_sstream << k::space <<
"fy=" << k::quote << fy << k::quote;
462 _M_sstream << k::space <<
"fr=" << k::quote << fr << k::quote;
474 _M_sstream <<
"</radialGradient>" << k::newline;
487 _M_sstream <<
"<linearGradient id=" << k::quote <<
"default" << k::quote;
498 _M_sstream <<
"</linearGradient>" << k::newline;
526 _M_sstream <<
"<marker id=" << k::quote <<
id << k::quote << k::space
527 <<
"markerWidth=" << k::quote << w << k::quote << k::space
528 <<
"markerHeight=" << k::quote << h << k::quote << k::space
529 <<
"refX=" << k::quote << x << k::quote << k::space
530 <<
"refY=" << k::quote << y << k::quote <<
" >"
590 {
_M_sstream <<
"<desc>" << k::newline << dsc << k::newline; }
632 const string x(
"__x");
633 const string y(
"__y");
634 const string attr(
"__attr");
635 const string style(
"__style");
637 string strip = R
"_delimiter_(x="__x" y="__y" __attr __style)_delimiter_";
665 const string x(
"__x");
666 const string dys(
"__dy");
667 string strip = R
"_delimiter_(<tspan x="__x" dy="__dy">)_delimiter_";
683 const string x(
"__x");
684 const string dxs(
"__dx");
685 string strip = R
"_delimiter_(<tspan x="__x" dx="__dx">)_delimiter_";
697 {
return "</tspan>"; }
711 for (
uint i = 0; i < s.size(); ++i)
719 if (i < s.size() - 1)
757 const string x(
"__x");
758 const string y(
"__y");
759 const string w(
"__w");
760 const string h(
"__h");
762 string strip = R
"_delimiter_(x="__x" y="__y" width="__w" height="__h"
813 const string x(
"__x");
814 const string y(
"__y");
815 const string r(
"__r");
817 string strip = R
"_delimiter_(cx="__x" cy="__y" r="__r")_delimiter_";
864 const string x1(
"__x1");
865 const string x2(
"__x2");
866 const string y1(
"__y1");
867 const string y2(
"__y2");
868 const string dash(
"__darray");
870 const bool dashp = !dasharray.empty();
872 R
"_delimiter_(x1="__x1" y1="__y1" x2="__x2" y2="__y2")_delimiter_";
874 R
"_delimiter_(x1="__x1" y1="__y1" x2="__x2" y2="__y2" stroke-dasharray="__darray")_delimiter_";
876 string strip = dashp ? stript : stripf;
893 {
_M_sstream <<
"<line id=" << k::quote << name << k::quote << k::space; }
939 _M_sstream <<
"stroke-dasharray=" << k::quote;
944 _M_sstream <<
"stroke-dashoffset=" << k::quote;
961 _M_sstream <<
"marker-mid=" << mkr << k::space;
962 _M_sstream <<
"marker-end=" << mkr << k::space;
973 {
_M_sstream <<
"<polyline id=" << k::quote << name << k::quote << k::space; }
1009 const string pathd(
"__d");
1010 const string len(
"__l");
1012 string strip = R
"_delimiter_(d="__d")_delimiter_";
1025 {
_M_sstream <<
"<path id=" << k::quote << name << k::quote << k::space; }
1055 const string off =
"",
const string whichside =
"")
1063 << k::quote <<
'#' <<
path_name << k::quote;
1066 << k::quote <<
offset << k::quote;
1069 << k::quote <<
side << k::quote;
1105 const string simg =
"<image ";
1108 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1123 const string x(
"__x");
1124 const string y(
"__y");
1125 const string w(
"__w");
1126 const string h(
"__h");
1127 const string ref(
"__ref");
1129 string strip = R
"_delimiter_(href="__ref" x="__x" y="__y" width="__w" height="__h"
1148 _M_sstream <<
"visibility=" << k::quote << vattr << k::quote << k::space;
1149 _M_sstream <<
"crossorigin=" << k::quote << cors << k::quote << k::space;
1202 const auto [ scalex, scaley ] =
scale;
1203 const auto [ ox, oy ] = origin;
1205 const auto [ width, height ] = arect;
1209 const auto [ vwidth, vheight ] = av;
1225 string strip = R
"(<foreignObject x="XXX" y="YYY" width="WWW" height="HHH">)";
1239{
_M_sstream <<
" </foreignObject></g></g>" << k::newline; }
1253 const string svideo = R
"(<video xmlns="http://www.w3.org/1999/xhtml" )";
1256 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1276 const string attr = R
"(autoplay="true" loop="true" muted="true")")
1278 string strip = R
"(width="WWW" height="HHH" )";
1286 _M_sstream <<
"<source src=" << k::quote << src << k::quote << k::space;
1287 _M_sstream <<
"type=" << k::quote << mtype << k::quote;
1311 const string siframe = R
"(<iframe xmlns="http://www.w3.org/1999/xhtml" )";
1314 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1327 const string attr = R
"(sandbox="allow-scripts allow-same-origin")")
1329 string strip = R
"(width="WWW" height="HHH" )";
1339 _M_sstream <<
"<source src=" << k::quote << src << k::quote << k::space;
1340 _M_sstream <<
"type=" << k::quote << mtype << k::quote << k::space;
1365 const string sobject = R
"(<object xmlns="http://www.w3.org/1999/xhtml" )";
1368 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1382 const string attr = R
"(sandbox="allow-scripts allow-same-origin")")
1384 string strip = R
"(width="WWW" height="HHH" )";
1389 _M_sstream <<
"data=" << k::quote << src << k::quote << k::space;
1390 _M_sstream <<
"type=" << k::quote << mtype << k::quote << k::space;
1414 const string shead = R
"(<script type="text/javascript" crossorigin="anonymous")";
1417 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1427 static const string&
1430 static string js = R
"(
1431 function showTooltip(event, tooltipId) {
1432 const tooltipimg = document.getElementById(tooltipId);
1433 tooltipimg.setAttribute('x', event.pageX + 10);
1434 tooltipimg.setAttribute('y', event.pageY - 150);
1435 tooltipimg.setAttribute('visibility', 'visible');
1438 function hideTooltip(tooltipId) {
1439 const tooltipimg = document.getElementById(tooltipId);
1440 tooltipimg.setAttribute('visibility', 'hidden');
1449 const string toolr(
"__toolt");
1450 string strip1 = R
"_delimiter_(onmouseover="showTooltip(event, '__toolt')" )_delimiter_";
1451 string strip2 = R
"_delimiter_(onmouseout="hideTooltip('__toolt')" )_delimiter_";
1454 return k::space + strip1 + k::space + strip2;
1492 const bool lifetime =
true,
1503 const bool lifetime =
true)
1525 {
return _M_area.center_point(); }
1532 const style& sty = k::no_style);
void start_element(const string dsc)
static string start_tspan_x(uint xpos, uint dx)
void start_element(string name, const transform, const string ts, const style &sty=k::no_style)
void add_data(const string &url)
void add_data(const stroke_style &sstyl)
string gaussian_blur(string in, string dev)
static constexpr const char * pair_open_tag
void add_filter(const string id)
void start_element(const string id, const ssize_type radius=0, const ssize_type cx=0, const ssize_type cy=0)
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
virtual void add_text(string txt)
stream_type _M_sstream
Virtual, only one buffer.
void start_element(const string &id)
void start_element(const string id, const ssize_type radius, const ssize_type cx, const ssize_type cy, const ssize_type fr, const ssize_type fx, const ssize_type fy)
void add_style(const style &sty)
virtual void add_text(string txt)
void str(const string &s)
void start_element(const string id)
void add_data(const data &d, const string dasharray="")
svg_element(const string __title, const area &__cv, const bool lifetime=true, const unit u=svg::unit::pixel, const typography &__typo=k::smono_typo)
void add_data(const string fltr)
void add_data(const area<> a, const string src, const string mtype="image/jpeg", const string attr=R"(sandbox="allow-scripts allow-same-origin")")
iframe. a is width and height of video as embedded in page r is the foreign object,...
const string offset_percentage(const ssize_type numer, const ssize_type denom)
void start_element(const string id, const area<> blur_area, const point_2t p)
void add_desc(const string desc)
text_path_element(const string name, const string off="", const string whichside="")
void add_data(const area<> a, const string src, const string mtype="image/jpeg", const string attr=R"(sandbox="allow-scripts allow-same-origin")")
Add resource to object.
static string finish_tspan()
void start_element(const string &id)
void add_data(const data &d, string trans="")
void add_transform(const string s)
Common transforms include rotate(180)
void start_element(string name)
static string finish_defs()
static constexpr const char * pair_finish_tag
static string finish_group()
void add_data(const data &d, const string vattr, const string cors)
Visibility and other HTML/img attributes.
const point_2t center_point()
void add_data(const area<> a, const string src, const string mtype="video/mp4", const string attr=R"(autoplay="true" loop="true" muted="true")")
Video. a is width and height of video as embedded in page r is the foreign object,...
static constexpr const char * self_finish_tag
void add_data(const string scriptstr)
Add string with script source.
void add_title(const string &t)
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
void start_element(string name, const style &sty)
void start_element()
SVG element beginning boilerplate for outermost (containing) svg_element. Variable: unit,...
static const string & tooltip_script()
showTooltip(id) hideTooltip(id)
void stop(const string off, const color &klr, const double opacity=1.0)
static string start_defs()
string gaussian_blur(string dev)
static const string tooltip_attribute(const string &id)
void start_element(const point_2t p, const area destarea, const style &sty=k::no_style)
static constexpr const char * finish_tag
static string start_group(const string name="")
static string start_tspan_y(uint xpos, string dy)
For text list output, use tspan for line breaks. This span creates a new horizontal line for every ts...
void add_data(const data &d, const string trans="", const unit utype=svg::unit::point)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
static string start_tspan_y(uint xpos, uint dy)
static constexpr const char * pair_finish_tag
virtual void start_element()=0
void start_element(const string &id)
svg_element(const string __title, const string desc, const area &__cv, const bool lifetime=true)
void start_element(string name)
static string start_tspan_x(uint xpos, string dx)
For text list output, use tspan for line breaks. This span creates a new vertical line space for ever...
std::ostringstream stream_type
static constexpr const char * pair_finish_tag
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
void start_element(const string &id)
const typography & _M_typo
void add_raw(const string &raw)
void start_element(const string name)
virtual void finish_element()=0
bool empty()
Empty when the output buffer is.
void add_fill(const string id)
void start_element(const point_2t origin, const area<> av, const area<> arect, const point_2t scale=std::make_tuple(1.0, 1.0))
void start_element(const string id, const area<> a, const point_2t p)
void add_data(const string &url, const string relt, const string ast, const string cors="anonymous")
Overload for rel=x form. https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/p...
void start(const string &desc="")
void add_element(const element_base &e)
void start_element(const string t)
static constexpr const char * pair_open_tag
void start_element(const string &id)
static constexpr string finish_tag_hard
polyline_element(const vrange &points)
svg_element(const svg_element &other)
void start_element(string name)
For groups of elements that have the same name.
string make_tspan_y_from_string_by_token(string s, uint xpos, const char token=' ')
Make text span.
void store_element(const element_base &e)
Abstract base class for all SVG Elements.
iframe HTML object embedded in SVG container. NB: HTML elements video/audio/iframe/canvas can be used...
Linear gradients https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient.
HTML object embedded in SVG container. Unlike image_elements, object_elements are not locked down for...
Circular gradients https://developer.mozilla.org/en-US/docs/Web/SVG/Element/radialGradient.
video HTML object embedded in SVG container. NB: HTML elements video/audio/iframe/canvas can be used ...
color
Color enumerated as types.
unit
Measurement abstraction for absolute (not relative) measurements.
@ pt
Point where 1 pixel x 1/72 dpi x 96 PPI = .26 mm.
const string to_string(const unit e)
void string_replace(std::string &target, const std::string &match, const std::string &replace)
double space_type
Base floating point type.
std::vector< point_2t > vrange
std::tuple< space_type, space_type > point_2t
Point (x,y) in 2D space.
Color quantified as integral RGB components in the range [0,255]. aka like Scalar in OpenCV.
Additional path/line/polyline stroke styles.
Datum consolidating style preferences.
const std::string add_attribute(const svg::unit utype=svg::unit::pixel) const