1 #ifndef SEEN_DISPLAY_CURVE_H
2 #define SEEN_DISPLAY_CURVE_H
4 /** \file
5 * Wrapper around an array of NArtBpath objects.
6 *
7 * Author:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 *
10 * Copyright (C) 2000 Lauris Kaplinski
11 * Copyright (C) 2000-2001 Ximian, Inc.
12 * Copyright (C) 2002 Lauris Kaplinski
13 * Copyright (C) 2008 Johan Engelen
14 *
15 * Released under GNU GPL
16 */
18 #include <glib/gtypes.h>
19 #include <glib/gslist.h>
21 #include "libnr/nr-forward.h"
22 #include "libnr/nr-rect.h"
24 #define SP_CURVE_LENSTEP 32
26 /// Wrapper around NArtBpath.
27 class SPCurve {
28 public:
29 /* Constructors */
30 SPCurve(guint length = SP_CURVE_LENSTEP);
31 static SPCurve * new_from_bpath(NArtBpath *bpath);
32 static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath);
33 static SPCurve * new_from_rect(NR::Maybe<NR::Rect> const &rect);
35 virtual ~SPCurve();
37 void set_bpath(NArtBpath * new_bpath);
38 NArtBpath const * get_bpath() const;
40 /// Index in bpath[] of NR_END element.
41 guint _end;
43 /// Allocated size (i.e., capacity) of bpath[] array. Not to be confused
44 /// with the SP_CURVE_LENGTH macro, which returns the logical length of
45 /// the path (i.e., index of NR_END).
46 guint _length;
48 /// Index in bpath[] of the start (i.e., moveto element) of the last
49 /// subpath in this path.
50 guint _substart;
52 /// Previous moveto position.
53 /// \note This is used for coalescing moveto's, whereas if we're to
54 /// conform to the SVG spec then we mustn't coalesce movetos if we have
55 /// midpoint markers. Ref:
56 /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
57 /// (first subitem of the item about zero-length path segments)
58 NR::Point _movePos;
60 /// True iff current point is defined. Initially false for a new curve;
61 /// becomes true after moveto; becomes false on closepath. Curveto,
62 /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
63 bool _hascpt : 1;
65 /// True iff previous was moveto.
66 bool _posSet : 1;
68 /// True iff bpath end is moving.
69 bool _moving : 1;
71 /// True iff all subpaths are closed.
72 bool _closed : 1;
74 SPCurve * ref();
75 SPCurve * unref();
77 SPCurve * copy() const;
79 GSList * split() const;
80 void transform(NR::Matrix const &);
81 void transform(NR::translate const &);
82 void stretch_endpoints(NR::Point const &, NR::Point const &);
83 void move_endpoints(NR::Point const &, NR::Point const &);
85 void reset();
87 void moveto(NR::Point const &p);
88 void moveto(gdouble x, gdouble y);
89 void lineto(NR::Point const &p);
90 void lineto(gdouble x, gdouble y);
91 void lineto_moving(gdouble x, gdouble y);
92 void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
93 void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
94 void closepath();
95 void closepath_current();
97 SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
99 bool is_empty() const;
100 bool is_closed() const;
101 NArtBpath * last_bpath() const;
102 NArtBpath * first_bpath() const;
103 NR::Point first_point() const;
104 NR::Point last_point() const;
105 NR::Point second_point() const;
106 NR::Point penultimate_point() const;
108 void append(SPCurve const *curve2, bool use_lineto);
109 SPCurve * create_reverse() const;
110 void backspace();
112 static SPCurve * concat(GSList const *list);
114 void ensure_space(guint space);
116 protected:
117 gint _refcount;
119 NArtBpath *_bpath;
121 private:
122 // Don't implement these:
123 SPCurve(const SPCurve&);
124 SPCurve& operator=(const SPCurve&);
126 friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
127 friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
128 template<class M> friend void tmpl_curve_transform(SPCurve *const curve, M const &m);
129 };
131 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->_end)
132 #define SP_CURVE_BPATH(c) ((c)->get_bpath())
133 #define SP_CURVE_SEGMENT(c,i) ((c)->get_bpath() + (i))
135 #endif /* !SEEN_DISPLAY_CURVE_H */
137 /*
138 Local Variables:
139 mode:c++
140 c-file-style:"stroustrup"
141 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
142 indent-tabs-mode:nil
143 fill-column:99
144 End:
145 */
146 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :