Debian Codegraph @

tests/svgpp_context.h

raw
1 #pragma once
2
3 #include <stdexcept>
4
5 #include <boost/range/any_range.hpp>
6 #include <boost/range/iterator_range_core.hpp>
7 #ifdef __GNUC__
8 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wdeprecated"
10 #endif
11 #include <svgpp/svgpp.hpp>
12 #ifdef __GNUC__
13 #pragma GCC diagnostic pop
14 #endif
15
16 class ISVGAnalyzer;
17
18 /**
19 * @brief The SvgppContext class provides a context containing SVG element
20 * callbacks for the SVG++ parser which is called from the SVG document
21 * traverser and forwards these callbacks to the SVG analyzer. It's separated
22 * from the SVG analyzer to avoid the very time consuming recompilation of the
23 * SVG document traverser when then SVG analyzer header is changed, which is
24 * expected to happen often as new functionality is added.
25 *
26 * Most of this is taken from
27 * http://svgpp.org/lesson01.html#handling-shapes-geometry.
28 */
29
30 class SvgppContext {
31 public:
32 SvgppContext(ISVGAnalyzer *svg_analyzer);
33 void on_enter_element(svgpp::tag::element::svg e);
34 void on_enter_element(svgpp::tag::element::g e);
35 void on_enter_element(svgpp::tag::element::circle e);
36 void on_enter_element(svgpp::tag::element::ellipse e);
37 void on_enter_element(svgpp::tag::element::line e);
38 void on_enter_element(svgpp::tag::element::path e);
39 void on_enter_element(svgpp::tag::element::polygon e);
40 void on_enter_element(svgpp::tag::element::polyline e);
41 void on_enter_element(svgpp::tag::element::rect e);
42 void on_enter_element(svgpp::tag::element::text e);
43 void on_enter_element(svgpp::tag::element::title e);
44 void on_exit_element();
45 void path_move_to(double x, double y, svgpp::tag::coordinate::absolute);
46 void path_line_to(double x, double y, svgpp::tag::coordinate::absolute);
47 void path_cubic_bezier_to(double x1, double y1, double x2, double y2,
48 double x, double y,
49 svgpp::tag::coordinate::absolute);
50 void path_quadratic_bezier_to(double x1, double y1, double x, double y,
51 svgpp::tag::coordinate::absolute);
52 void path_elliptical_arc_to(double rx, double ry, double x_axis_rotation,
53 bool large_arc_flag, bool sweep_flag, double x,
54 double y, svgpp::tag::coordinate::absolute);
55 void path_close_subpath();
56 void path_exit();
57 void set(svgpp::tag::attribute::cy cy, double v);
58 void set(svgpp::tag::attribute::cx cx, double v);
59
60 void set(svgpp::tag::attribute::fill, svgpp::tag::value::none);
61 void set(svgpp::tag::attribute::fill, svgpp::tag::value::currentColor);
62 using color_t = int;
63 void set(svgpp::tag::attribute::fill, color_t color,
64 svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color());
65 template <class IRI> void set(svgpp::tag::attribute::fill, IRI const &) {
66 throw std::runtime_error{
67 "this flavor of the 'fill' attribute is not yet implemented"};
68 };
69 template <class IRI>
70 void set(svgpp::tag::attribute::fill, svgpp::tag::iri_fragment, IRI const &) {
71 throw std::runtime_error{
72 "this flavor of the 'fill' attribute is not yet implemented"};
73 };
74 template <class IRI>
75 void set(svgpp::tag::attribute::fill, IRI const &, svgpp::tag::value::none) {
76 throw std::runtime_error{
77 "this flavor of the 'fill' attribute is not yet implemented"};
78 };
79 template <class IRI>
80 void set(svgpp::tag::attribute::fill, svgpp::tag::iri_fragment, IRI const &,
81 svgpp::tag::value::none) {
82 throw std::runtime_error{
83 "this flavor of the 'fill' attribute is not yet implemented"};
84 };
85 template <class IRI>
86 void set(svgpp::tag::attribute::fill, IRI const &,
87 svgpp::tag::value::currentColor) {
88 throw std::runtime_error{
89 "this flavor of the 'fill' attribute is not yet implemented"};
90 };
91 template <class IRI>
92 void set(svgpp::tag::attribute::fill, svgpp::tag::iri_fragment, IRI const &,
93 svgpp::tag::value::currentColor) {
94 throw std::runtime_error{
95 "this flavor of the 'fill' attribute is not yet implemented"};
96 };
97 template <class IRI>
98 void set(svgpp::tag::attribute::fill, IRI const &, color_t,
99 svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color()) {
100 throw std::runtime_error{
101 "this flavor of the 'fill' attribute is not yet implemented"};
102 };
103 template <class IRI>
104 void set(svgpp::tag::attribute::fill, svgpp::tag::iri_fragment, IRI const &,
105 color_t, svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color()) {
106 throw std::runtime_error{
107 "this flavor of the 'fill' attribute is not yet implemented"};
108 };
109
110 void set(svgpp::tag::attribute::fill_opacity, double v);
111 void set(svgpp::tag::attribute::stroke, svgpp::tag::value::none);
112 void set(svgpp::tag::attribute::stroke, svgpp::tag::value::currentColor);
113 void set(svgpp::tag::attribute::stroke, color_t color,
114 svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color());
115 template <class IRI> void set(svgpp::tag::attribute::stroke, IRI const &) {
116 throw std::runtime_error{
117 "this flavor of the 'stroke' attribute is not yet implemented"};
118 };
119 template <class IRI>
120 void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment,
121 IRI const &) {
122 throw std::runtime_error{
123 "this flavor of the 'stroke' attribute is not yet implemented"};
124 };
125 template <class IRI>
126 void set(svgpp::tag::attribute::stroke, IRI const &,
127 svgpp::tag::value::none) {
128 throw std::runtime_error{
129 "this flavor of the 'stroke' attribute is not yet implemented"};
130 };
131 template <class IRI>
132 void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment, IRI const &,
133 svgpp::tag::value::none) {
134 throw std::runtime_error{
135 "this flavor of the 'stroke' attribute is not yet implemented"};
136 };
137 template <class IRI>
138 void set(svgpp::tag::attribute::stroke, IRI const &,
139 svgpp::tag::value::currentColor) {
140 throw std::runtime_error{
141 "this flavor of the 'stroke' attribute is not yet implemented"};
142 };
143 template <class IRI>
144 void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment, IRI const &,
145 svgpp::tag::value::currentColor) {
146 throw std::runtime_error{
147 "this flavor of the 'stroke' attribute is not yet implemented"};
148 };
149 template <class IRI>
150 void set(svgpp::tag::attribute::stroke, IRI const &, color_t,
151 svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color()) {
152 throw std::runtime_error{
153 "this flavor of the 'stroke' attribute is not yet implemented"};
154 };
155 template <class IRI>
156 void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment, IRI const &,
157 color_t, svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color()) {
158 throw std::runtime_error{
159 "this flavor of the 'stroke' attribute is not yet implemented"};
160 };
161 void set(svgpp::tag::attribute::stroke_opacity, double v);
162 void set(svgpp::tag::attribute::stroke_width, double v);
163 void transform_matrix(const boost::array<double, 6> &matrix);
164 void set(svgpp::tag::attribute::r r, double v);
165 void set(svgpp::tag::attribute::rx rx, double v);
166 void set(svgpp::tag::attribute::ry ry, double v);
167 void set(svgpp::tag::attribute::x1 x1, double v);
168 void set(svgpp::tag::attribute::y1 y1, double v);
169 void set(svgpp::tag::attribute::x2 x2, double v);
170 void set(svgpp::tag::attribute::y2 y2, double v);
171 typedef boost::any_range<std::pair<double, double>,
172 boost::single_pass_traversal_tag,
173 const std::pair<double, double> &, std::ptrdiff_t>
174 PointsRange;
175 void set(svgpp::tag::attribute::points points, const PointsRange &range);
176 void set(svgpp::tag::attribute::x, double v);
177 typedef boost::any_range<double, boost::single_pass_traversal_tag, double,
178 std::ptrdiff_t>
179 NumbersRange;
180 void set(svgpp::tag::attribute::x, const NumbersRange &range);
181 void set(svgpp::tag::attribute::y, double v);
182 void set(svgpp::tag::attribute::y, const NumbersRange &range);
183 void set(svgpp::tag::attribute::width width, double v);
184 void set(svgpp::tag::attribute::height height, double v);
185 void set(svgpp::tag::attribute::id a, boost::iterator_range<const char *> v);
186 void set(svgpp::tag::attribute::class_ a,
187 boost::iterator_range<const char *> v);
188 void set(svgpp::tag::attribute::font_family a,
189 boost::iterator_range<const char *> v);
190 void set(svgpp::tag::attribute::font_size a, double v);
191 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::xx_small v);
192 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::x_small v);
193 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::smaller v);
194 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::small v);
195 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::medium v);
196 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::large v);
197 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::larger v);
198 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::x_large v);
199 void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::xx_large v);
200 void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::start v);
201 void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::middle v);
202 void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::end v);
203 void set(svgpp::tag::attribute::viewBox a, double v1, double v2, double v3,
204 double v4);
205 void set_text(boost::iterator_range<const char *> v);
206
207 private:
208 ISVGAnalyzer *m_svg_analyzer = nullptr;
209 };