28fce31323e030b6c6fe8d2910eb7fd1a161031d
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;
39 NArtBpath * get_bpath();
41 /// Index in bpath[] of NR_END element.
42 guint _end;
44 /// Allocated size (i.e., capacity) of bpath[] array. Not to be confused
45 /// with the SP_CURVE_LENGTH macro, which returns the logical length of
46 /// the path (i.e., index of NR_END).
47 guint _length;
49 /// Index in bpath[] of the start (i.e., moveto element) of the last
50 /// subpath in this path.
51 guint _substart;
53 /// Previous moveto position.
54 /// \note This is used for coalescing moveto's, whereas if we're to
55 /// conform to the SVG spec then we mustn't coalesce movetos if we have
56 /// midpoint markers. Ref:
57 /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
58 /// (first subitem of the item about zero-length path segments)
59 NR::Point _movePos;
61 /// True iff current point is defined. Initially false for a new curve;
62 /// becomes true after moveto; becomes false on closepath. Curveto,
63 /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
64 bool _hascpt : 1;
66 /// True iff previous was moveto.
67 bool _posSet : 1;
69 /// True iff bpath end is moving.
70 bool _moving : 1;
72 /// True iff all subpaths are closed.
73 bool _closed : 1;
75 SPCurve * ref();
76 SPCurve * unref();
78 SPCurve * copy() const;
80 GSList * split() const;
81 void transform(NR::Matrix const &);
82 void transform(NR::translate const &);
83 void stretch_endpoints(NR::Point const &, NR::Point const &);
84 void move_endpoints(NR::Point const &, NR::Point const &);
86 void reset();
88 void moveto(NR::Point const &p);
89 void moveto(gdouble x, gdouble y);
90 void lineto(NR::Point const &p);
91 void lineto(gdouble x, gdouble y);
92 void lineto_moving(gdouble x, gdouble y);
93 void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
94 void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
95 void closepath();
96 void closepath_current();
98 SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
100 bool is_empty() const;
101 bool is_closed() const;
102 NArtBpath * last_bpath() const;
103 NArtBpath * first_bpath() const;
104 NR::Point first_point() const;
105 NR::Point last_point() const;
106 NR::Point second_point() const;
107 NR::Point penultimate_point() const;
109 void append(SPCurve const *curve2, bool use_lineto);
110 SPCurve * create_reverse() const;
111 void backspace();
113 static SPCurve * concat(GSList const *list);
115 void ensure_space(guint space);
117 protected:
118 gint _refcount;
120 NArtBpath *_bpath;
122 private:
123 // Don't implement these:
124 SPCurve(const SPCurve&);
125 SPCurve& operator=(const SPCurve&);
127 friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
128 friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
129 template<class M> friend void tmpl_curve_transform(SPCurve *const curve, M const &m);
130 };
132 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->_end)
133 #define SP_CURVE_BPATH(c) ((c)->get_bpath())
134 #define SP_CURVE_SEGMENT(c,i) ((c)->get_bpath() + (i))
136 #endif /* !SEEN_DISPLAY_CURVE_H */
138 /*
139 Local Variables:
140 mode:c++
141 c-file-style:"stroustrup"
142 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
143 indent-tabs-mode:nil
144 fill-column:99
145 End:
146 */
147 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :