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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* Inkscape::SVG::PathString - builder for SVG path strings
*
* Copyright 2007 MenTaLguY <mental@rydia.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* See the file COPYING for details.
*
*/
#ifndef SEEN_INKSCAPE_SVG_PATH_STRING_H
#define SEEN_INKSCAPE_SVG_PATH_STRING_H
#include <glibmm/ustring.h>
#include "libnr/nr-point.h"
#include "svg/stringstream.h"
namespace Inkscape {
namespace SVG {
class PathString {
public:
PathString() {}
// default copy
// default assign
Glib::ustring const &ustring() const {
return _str;
}
operator Glib::ustring const &() const {
return ustring();
}
char const *c_str() const {
return _str.c_str();
}
PathString &moveTo(NR::Coord x, NR::Coord y) {
return moveTo(NR::Point(x, y));
}
PathString &moveTo(NR::Point p) {
_appendOp('M');
_append(p);
return *this;
}
PathString &lineTo(NR::Coord x, NR::Coord y) {
return lineTo(NR::Point(x, y));
}
PathString &lineTo(NR::Point p) {
_appendOp('L');
_append(p);
return *this;
}
PathString &quadTo(NR::Coord cx, NR::Coord cy, NR::Coord x, NR::Coord y) {
return quadTo(NR::Point(cx, cy), NR::Point(x, y));
}
PathString &quadTo(NR::Point c, NR::Point p) {
_appendOp('Q');
_append(c);
_append(p);
return *this;
}
PathString &curveTo(NR::Coord x0, NR::Coord y0,
NR::Coord x1, NR::Coord y1,
NR::Coord x, NR::Coord y)
{
return curveTo(NR::Point(x0, y0), NR::Point(x1, y1), NR::Point(x, y));
}
PathString &curveTo(NR::Point c0, NR::Point c1, NR::Point p) {
_appendOp('C');
_append(c0);
_append(c1);
_append(p);
return *this;
}
PathString &arcTo(NR::Coord rx, NR::Coord ry, NR::Coord rot,
bool large_arc, bool sweep,
NR::Point p)
{
_appendOp('A');
_append(NR::Point(rx, ry));
_append(rot);
_append(large_arc);
_append(sweep);
_append(p);
return *this;
}
PathString &closePath() {
_appendOp('z');
return *this;
}
private:
void _appendOp(char op) {
if (!_str.empty()) {
_str.append(1, ' ');
}
_str.append(1, op);
}
void _append(bool flag) {
_str.append(1, ' ');
_str.append(1, ( flag ? '1' : '0' ));
}
void _append(NR::Coord v) {
SVGOStringStream os;
os << ' ' << v;
_str.append(os.str());
}
void _append(NR::Point p) {
SVGOStringStream os;
os << ' ' << p[NR::X] << ',' << p[NR::Y];
_str.append(os.str());
}
Glib::ustring _str;
};
}
}
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
|