-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg.cpp
85 lines (69 loc) · 1.72 KB
/
svg.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
#include "glsvg.hpp"
#include "pugixml/pugixml.hpp"
using pugi::xml_document;
glsvg::Elem::Elem(const weak_ptr<Elem> &parent)
:
mParent(parent)
{
}
// Compile this element to a display list
void glsvg::Elem::compile(const int listid)
{
}
// Dispatch to the correct element constructor, based on the node
unique_ptr<Elem> glsvg::Elem::construct(
const xml_node &rootnode,
const weak_ptr<Elem> &parent)
{
string nodetype(rootnode.name());
if(nodetype == "svg")
return shared_ptr<Elem>(new Svg(rootnode, parent));
else if(nodetype == "rect")
return shared_ptr<Elem>(new Rect(rootnode, parent));
else
throw SvgRuntimeError("Elem::construct() given invalid node type");
}
glsvg::Svg::Svg(const string &pathname)
:
Svg(path(pathname))
{
}
glsvg::Svg::Svg(const path &pathname)
:
Svg(istream(pathname))
{
}
glsvg::Svg::Svg(istream &inputstream)
{
xml_document svgdoc;
svgdoc.load(inputstream);
Svg(svgdoc, nullptr);
}
glsvg::Svg::Svg(const xml_node &rootnode, const weak_ptr &parent)
:
Elem(parent)
{
// Check that the node is an <svg> node
string nodetype(rootnode.name());
if(nodetype != "svg")
throw SvgRuntimeError("Svg::Svg() given invalid xml node type");
// Parse relevant attributes
// Generate this element's children
for(const xml_node &child: rootnode)
{
mChildren.emplace_back(Elem::construct(child, weak_ptr<Elem>(this)));
}
}
void glsvg::Svg::draw()
{
// The root svg type does no drawing of its own, only draws its children
for(const shared_ptr<Elem> &childptr: mChildren)
{
childptr->draw();
}
}
glsvg::SvgRuntimeError::SvgRuntimeError(string what)
:
runtime_error(what)
{
}