1 /*
2 * Inkscape::SVG::PathString - builder for SVG path strings
3 *
4 * Copyright 2007 MenTaLguY <mental@rydia.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * See the file COPYING for details.
12 *
13 */
15 #ifndef SEEN_INKSCAPE_SVG_PATH_STRING_H
16 #define SEEN_INKSCAPE_SVG_PATH_STRING_H
18 #include <glibmm/ustring.h>
19 #include "libnr/nr-point.h"
20 #include "svg/stringstream.h"
22 namespace Inkscape {
24 namespace SVG {
26 class PathString {
27 public:
28 PathString() {}
30 // default copy
31 // default assign
33 Glib::ustring const &ustring() const {
34 return _str;
35 }
37 operator Glib::ustring const &() const {
38 return ustring();
39 }
41 char const *c_str() const {
42 return _str.c_str();
43 }
45 PathString &moveTo(NR::Coord x, NR::Coord y) {
46 return moveTo(NR::Point(x, y));
47 }
49 PathString &moveTo(NR::Point p) {
50 _appendOp('M');
51 _append(p);
52 return *this;
53 }
55 PathString &lineTo(NR::Coord x, NR::Coord y) {
56 return lineTo(NR::Point(x, y));
57 }
59 PathString &lineTo(NR::Point p) {
60 _appendOp('L');
61 _append(p);
62 return *this;
63 }
65 PathString &quadTo(NR::Coord cx, NR::Coord cy, NR::Coord x, NR::Coord y) {
66 return quadTo(NR::Point(cx, cy), NR::Point(x, y));
67 }
69 PathString &quadTo(NR::Point c, NR::Point p) {
70 _appendOp('Q');
71 _append(c);
72 _append(p);
73 return *this;
74 }
76 PathString &curveTo(NR::Coord x0, NR::Coord y0,
77 NR::Coord x1, NR::Coord y1,
78 NR::Coord x, NR::Coord y)
79 {
80 return curveTo(NR::Point(x0, y0), NR::Point(x1, y1), NR::Point(x, y));
81 }
84 PathString &curveTo(NR::Point c0, NR::Point c1, NR::Point p) {
85 _appendOp('C');
86 _append(c0);
87 _append(c1);
88 _append(p);
89 return *this;
90 }
92 PathString &arcTo(NR::Coord rx, NR::Coord ry, NR::Coord rot,
93 bool large_arc, bool sweep,
94 NR::Point p)
95 {
96 _appendOp('A');
97 _append(NR::Point(rx, ry));
98 _append(rot);
99 _append(large_arc);
100 _append(sweep);
101 _append(p);
102 return *this;
103 }
105 PathString &closePath() {
106 _appendOp('z');
107 return *this;
108 }
110 private:
111 void _appendOp(char op) {
112 if (!_str.empty()) {
113 _str.append(1, ' ');
114 }
115 _str.append(1, op);
116 }
118 void _append(bool flag) {
119 _str.append(1, ' ');
120 _str.append(1, ( flag ? '1' : '0' ));
121 }
123 void _append(NR::Coord v) {
124 SVGOStringStream os;
125 os << ' ' << v;
126 _str.append(os.str());
127 }
129 void _append(NR::Point p) {
130 SVGOStringStream os;
131 os << ' ' << p[NR::X] << ',' << p[NR::Y];
132 _str.append(os.str());
133 }
135 Glib::ustring _str;
136 };
138 }
140 }
142 #endif
143 /*
144 Local Variables:
145 mode:c++
146 c-file-style:"stroustrup"
147 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
148 indent-tabs-mode:nil
149 fill-column:99
150 End:
151 */
152 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :