Code

GSoC C++-ificiation merge and cleanup.
[inkscape.git] / src / livarot / path-description.h
1 #ifndef SEEN_INKSCAPE_LIVAROT_PATH_DESCRIPTION_H
2 #define SEEN_INKSCAPE_LIVAROT_PATH_DESCRIPTION_H
4 #include "svg/stringstream.h"
5 #include "libnr/nr-point.h"
7 // path description commands
8 /* FIXME: these should be unnecessary once the refactoring of the path
9 ** description stuff is finished.
10 */
11 enum
12 {
13   descr_moveto = 0,         // a moveto
14   descr_lineto = 1,         // a (guess what) lineto
15   descr_cubicto = 2,
16   descr_bezierto = 3,       // "beginning" of a quadratic bezier spline, will contain its endpoint (i know, it's bad...)
17   descr_arcto = 4,
18   descr_close = 5,
19   descr_interm_bezier = 6,  // control point of the bezier spline
20   descr_forced = 7,
22   descr_type_mask = 15      // the command no will be stored in a "flags" field, potentially with other info, so we need
23                             // a mask to AND the field and extract the command
24 };
26 struct PathDescr
27 {
28   PathDescr() : flags(0), associated(-1), tSt(0), tEn(1) {}
29   PathDescr(int f) : flags(f), associated(-1), tSt(0), tEn(1) {}
30   virtual ~PathDescr() {}
32   int getType() const { return flags & descr_type_mask; }
33   void setType(int t) {
34     flags &= ~descr_type_mask;
35     flags |= t;
36   }
38     virtual void dumpSVG(Inkscape::SVGOStringStream &/*s*/, Geom::Point const &/*last*/) const {}
39     virtual PathDescr *clone() const = 0;
40     virtual void transform(Geom::Matrix const &/*t*/) {}
41     virtual void dump(std::ostream &/*s*/) const {}
43   int    flags;         // most notably contains the path command no
44   int    associated;    // index in the polyline of the point that ends the path portion of this command
45   double tSt;
46   double tEn;
47 };
49 struct PathDescrMoveTo : public PathDescr
50 {
51   PathDescrMoveTo(Geom::Point const &pp)
52       : PathDescr(descr_moveto), p(pp) {}
54   void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const;
55   PathDescr *clone() const;
56   void transform(Geom::Matrix const &t);
57   void dump(std::ostream &s) const;
59   Geom::Point p;
60 };
62 struct PathDescrLineTo : public PathDescr
63 {
64   PathDescrLineTo(Geom::Point const &pp)
65     : PathDescr(descr_lineto), p(pp) {}
67   void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const;
68   PathDescr *clone() const;
69   void transform(Geom::Matrix const &t);
70   void dump(std::ostream &s) const;
72   Geom::Point p;
73 };
75 // quadratic bezier curves: a set of control points, and an endpoint
76 struct PathDescrBezierTo : public PathDescr
77 {
78   PathDescrBezierTo(Geom::Point const &pp, int n)
79     : PathDescr(descr_bezierto), p(pp), nb(n) {}
81   PathDescr *clone() const;
82   void transform(Geom::Matrix const &t);
83   void dump(std::ostream &s) const;
85   Geom::Point p;        // the endpoint's coordinates
86   int nb;             // number of control points, stored in the next path description commands
87 };
89 /* FIXME: I don't think this should be necessary */
90 struct PathDescrIntermBezierTo : public PathDescr
91 {
92   PathDescrIntermBezierTo()
93     : PathDescr(descr_interm_bezier) , p(0, 0) {}
94   PathDescrIntermBezierTo(Geom::Point const &pp)
95     : PathDescr(descr_interm_bezier), p(pp) {}
97   PathDescr *clone() const;
98   void transform(Geom::Matrix const &t);
99   void dump(std::ostream &s) const;
101   Geom::Point p;                  // control point coordinates
102 };
104 // cubic spline curve: 2 tangents and one endpoint
105 struct PathDescrCubicTo : public PathDescr
107   PathDescrCubicTo(Geom::Point const &pp, Geom::Point const &s, Geom::Point const& e)
108     : PathDescr(descr_cubicto), p(pp), start(s), end(e) {}
110   void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const;
111   PathDescr *clone() const;
112   void transform(Geom::Matrix const &t);
113   void dump(std::ostream &s) const;
115   Geom::Point p;
116   Geom::Point start;
117   Geom::Point end;
118 };
120 // arc: endpoint, 2 radii and one angle, plus 2 booleans to choose the arc (svg style)
121 struct PathDescrArcTo : public PathDescr
123   PathDescrArcTo(Geom::Point const &pp, double x, double y, double a, bool l, bool c)
124     : PathDescr(descr_arcto), p(pp), rx(x), ry(y), angle(a), large(l), clockwise(c) {}
126   void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const;
127   PathDescr *clone() const;
128   void transform(Geom::Matrix const &t);
129   void dump(std::ostream &s) const;
131   Geom::Point p;
132   double rx;
133   double ry;
134   double angle;
135   bool large;
136   bool clockwise;
137 };
139 struct PathDescrForced : public PathDescr
141   PathDescrForced() : PathDescr(descr_forced), p(0, 0) {}
143   PathDescr *clone() const;
145   /* FIXME: not sure whether _forced should have a point associated with it;
146   ** Path::ConvertForcedToMoveTo suggests that maybe it should.
147   */
148   Geom::Point p;
149 };
151 struct PathDescrClose : public PathDescr
153   PathDescrClose() : PathDescr(descr_close) {}
155   void dumpSVG(Inkscape::SVGOStringStream &s, Geom::Point const &last) const;
156   PathDescr *clone() const;
158   /* FIXME: not sure whether _forced should have a point associated with it;
159   ** Path::ConvertForcedToMoveTo suggests that maybe it should.
160   */
161   Geom::Point p;
162 };
164 #endif
167 /*
168   Local Variables:
169   mode:c++
170   c-file-style:"stroustrup"
171   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172   indent-tabs-mode:nil
173   fill-column:99
174   End:
175 */
176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :