-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathsample01c.cpp
132 lines (111 loc) · 3.04 KB
/
sample01c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <rapidxml_ns/rapidxml_ns.hpp>
#include <svgpp/policy/xml/rapidxml_ns.hpp>
#include <svgpp/svgpp.hpp>
using namespace svgpp;
typedef rapidxml_ns::xml_node<> const * xml_element_t;
class Context
{
public:
void on_enter_element(tag::element::any)
{}
void on_exit_element()
{}
void transform_matrix(const boost::array<double, 6> & matrix)
{}
void set_viewport(double viewport_x, double viewport_y, double viewport_width, double viewport_height)
{}
void set_viewbox_size(double viewbox_width, double viewbox_height)
{}
void disable_rendering()
{}
void path_move_to(double x, double y, tag::coordinate::absolute)
{}
void path_line_to(double x, double y, tag::coordinate::absolute)
{}
void path_cubic_bezier_to(
double x1, double y1,
double x2, double y2,
double x, double y,
tag::coordinate::absolute)
{}
void path_quadratic_bezier_to(
double x1, double y1,
double x, double y,
tag::coordinate::absolute)
{}
void path_elliptical_arc_to(
double rx, double ry, double x_axis_rotation,
bool large_arc_flag, bool sweep_flag,
double x, double y,
tag::coordinate::absolute)
{}
void path_close_subpath()
{}
void path_exit()
{}
};
typedef
boost::mpl::set<
// SVG Structural Elements
tag::element::svg,
tag::element::g,
// SVG Shape Elements
tag::element::circle,
tag::element::ellipse,
tag::element::line,
tag::element::path,
tag::element::polygon,
tag::element::polyline,
tag::element::rect
>::type processed_elements_t;
// This cryptic code just merges predefined sequences traits::shapes_attributes_by_element
// and traits::viewport_attributes with tag::attribute::transform attribute into single MPL sequence
typedef
boost::mpl::fold<
boost::mpl::protect<
boost::mpl::joint_view<
traits::shapes_attributes_by_element,
traits::viewport_attributes
>
>,
boost::mpl::set<
tag::attribute::transform
>::type,
boost::mpl::insert<boost::mpl::_1, boost::mpl::_2>
>::type processed_attributes_t;
void loadSvg(xml_element_t xml_root_element)
{
Context context;
document_traversal<
processed_elements<processed_elements_t>,
processed_attributes<processed_attributes_t>,
viewport_policy<policy::viewport::as_transform>
>::load_document(xml_root_element, context);
}
int main()
{
#define TEXT(x) #x
char text[] =
TEXT(<svg xmlns="http://www.w3.org/2000/svg">)
TEXT( <g transform="translate(20,40)">)
TEXT( <svg preserveAspectRatio="xMinYMin meet" viewBox="0 0 30 40" width="50" height="30">)
TEXT( <rect x='.5' y='.5' width='29' height='39'/>)
TEXT( </svg>)
TEXT( </g>)
TEXT(</svg>);
rapidxml_ns::xml_document<> doc; // character type defaults to char
try
{
doc.parse<0>(text);
if (rapidxml_ns::xml_node<> * svg_element = doc.first_node("svg"))
{
loadSvg(svg_element);
}
}
catch (std::exception const & e)
{
std::cerr << "Error loading SVG: " << e.what() << std::endl;
return 1;
}
return 0;
}