izzi
SVG SUBSET C++ API
Loading...
Searching...
No Matches
a60-svg-markers.h
Go to the documentation of this file.
1// svg path/line markers points -*- mode: C++ -*-
2
3// alpha60
4// bittorrent x scrape x data + analytics
5
6// Copyright (c) 2025, Benjamin De Kosnik <b.dekosnik@gmail.com>
7
8// This file is part of the alpha60 library. This library is free
9// software; you can redistribute it and/or modify it under the terms
10// of the GNU General Public License as published by the Free Software
11// Foundation; either version 3, or (at your option) any later
12// version.
13
14// This library is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// General Public License for more details.
18
19#ifndef MiL_SVG_MARKERS_H
20#define MiL_SVG_MARKERS_H 1
21
22
23namespace svg {
24
25/**
26 Marker styles, ways to make line start, mid points, and enpoints look distinct.
27
28 https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/
29
30 stroke_dash_array
31 Attribute/stroke-dasharray
32
33 polyline marker-mid
34 Attribute/marker-mid
35*/
36
37/// Base function for generating SVG markers in a defs section.
39make_marker_element(const std::string id,
40 const area<> ma, const point_2t mcp,
41 const std::string raw)
42{
44 mkr.start_element(id, ma, mcp);
45 mkr.add_raw(raw.c_str());
46 mkr.finish_element();
47 return mkr;
48}
49
50marker_element
51make_marker_circle(const std::string id,
52 const area<> ma, const point_2t mcp,
53 const uint radius, const style styl)
54{
55 circle_element c = make_circle(mcp, styl, radius);
56 return make_marker_element(id, ma, mcp, c.str());
57}
58
59marker_element
60make_marker_triangle(const std::string id,
61 const area<> ma, const point_2t mcp,
62 const uint radius, const style styl)
63{
64 path_element p = make_path_triangle(mcp, styl, radius);
65 return make_marker_element(id, ma, mcp, p.str());
66}
67
68marker_element
69make_marker_x(const std::string id,
70 const area<> ma, const point_2t mcp,
71 const uint radius, const style styl)
72{
73 path_element cm = make_path_center_mark(mcp, styl, radius, radius / 2);
74 return make_marker_element(id, ma, mcp, cm.str());
75}
76
77marker_element
78make_marker_rect(const std::string id,
79 const area<> ma, const point_2t mcp,
80 const style styl)
81{
82 rect_element p = make_rect_centered(mcp, styl, ma);
83 return make_marker_element(id, ma, mcp, p.str());
84}
85
86
87/// Create a set of markers bounded by a rectangle of size n.
88string
89make_marker_set_n(const double i)
90{
91 // 4 / 2, etc.
92 const double h(i/2);
93 const string si = std::to_string(static_cast<uint>(i));
94 auto m1 = make_marker_circle("c" + si + "red", {i, i}, {h, h}, h, k::r_style);
95 auto m2 = make_marker_circle("c" + si + "wcaglg", {i, i}, {h, h}, h, k::wcaglg_style);
96 auto m3 = make_marker_circle("c" + si + "wcagdg", {i, i}, {h, h}, h, k::wcagdg_style);
97 auto m4 = make_marker_circle("c" + si + "black", {i, i}, {h, h}, h, k::b_style);
98 auto m5 = make_marker_triangle("t" + si + "black", {i, i}, {h, h}, h, k::b_style);
99 auto m6 = make_marker_triangle("t" + si + "wcagg", {i, i}, {h, h}, h, k::wcagg_style);
100 auto m7 = make_marker_x("x" + si + "wcagg", {i, i}, {h, h}, h, k::wcaglg_style);
101 auto m8 = make_marker_rect("r" + si + "wcaglg", {i, i}, {h, h}, k::wcaglg_style);
102 auto m9 = make_marker_rect("r" + si + "wcagdg", {i, i}, {h, h}, k::wcagdg_style);
103
104 std::ostringstream oss;
105 oss << m1.str() << m2.str() << m3.str() << m4.str()
106 << m5.str() << m6.str() << m7.str() << m8.str() << m9.str();
107 return oss.str();
108}
109
110
111/// Make black/white/wcag markers with sizes 4x4 and 2x2.
112void
114{
115
116 defs_element def;
117 def.start_element();
118
119 string m2 = make_marker_set_n(2);
120 def.add_raw(m2);
121
122 string m4 = make_marker_set_n(4);
123 def.add_raw(m4);
124
125 def.finish_element();
126 obj.add_element(def);
127};
128
129} // namespace svg
130
131#endif
void add_raw(const string &raw)
string str() const
void add_element(const element_base &e)
circle_element make_circle(const point_2t origin, style s, const space_type r=4, const string xform="")
Make circle element.
@ cm
Centimeter.
path_element make_path_center_mark(const point_2t &origin, const style styl, const int len, const int width)
Plus or x tilt mark as closed path that can be filled.
string make_marker_set_n(const double i)
Create a set of markers bounded by a rectangle of size n.
marker_element make_marker_element(const std::string id, const area<> ma, const point_2t mcp, const std::string raw)
Base function for generating SVG markers in a defs section.
path_element make_path_triangle(const point_2t origin, const style styl, const double r=4, const double angle=120, const bool selfclosingtagp=true)
Center a triangle at this point.
marker_element make_marker_rect(const std::string id, const area<> ma, const point_2t mcp, const style styl)
marker_element make_marker_circle(const std::string id, const area<> ma, const point_2t mcp, const uint radius, const style styl)
rect_element make_rect_centered(const point_2t origin, const style s, const area<> a, const string filterstr="")
Create rect_element centered at origin.
marker_element make_marker_x(const std::string id, const area<> ma, const point_2t mcp, const uint radius, const style styl)
void make_markers(svg_element &obj)
Make black/white/wcag markers with sizes 4x4 and 2x2.
unsigned int uint
Definition a60-svg.h:57
std::tuple< space_type, space_type > point_2t
Point (x,y) in 2D space.
Definition a60-svg.h:65
marker_element make_marker_triangle(const std::string id, const area<> ma, const point_2t mcp, const uint radius, const style styl)
Datum consolidating style preferences.