0bb45677770704d3dbd9a8d61932f4ea96a6db4e
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 <2geom/forward.h>
22 #include <2geom/point.h>
24 #include "libnr/nr-forward.h"
25 #include "libnr/nr-rect.h"
27 #define SP_CURVE_LENSTEP 32
29 struct SPObject;
31 /// Wrapper around Geom::PathVector.
32 class SPCurve {
33 public:
34 /* Constructors */
35 SPCurve(guint length = SP_CURVE_LENSTEP);
36 SPCurve(Geom::PathVector const& pathv);
37 static SPCurve * new_from_bpath(NArtBpath *bpath);
38 static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath);
39 static SPCurve * new_from_rect(NR::Maybe<NR::Rect> const &rect);
41 virtual ~SPCurve();
43 void set_pathvector(Geom::PathVector const & new_pathv);
44 NArtBpath const * get_bpath() const;
45 Geom::PathVector const & get_pathvector() const;
47 guint get_length() const;
49 SPCurve * ref();
50 SPCurve * unref();
52 SPCurve * copy() const;
54 GSList * split() const;
55 void transform(Geom::Matrix const &m);
56 void transform(NR::Matrix const &);
57 void transform(NR::translate const &);
58 void stretch_endpoints(NR::Point const &, NR::Point const &);
59 void move_endpoints(NR::Point const &, NR::Point const &);
60 void last_point_additive_move(Geom::Point const & p);
62 void reset();
64 void moveto(Geom::Point const &p);
65 void moveto(NR::Point const &p);
66 void moveto(gdouble x, gdouble y);
67 void lineto(Geom::Point const &p);
68 void lineto(NR::Point const &p);
69 void lineto(gdouble x, gdouble y);
70 void curveto(Geom::Point const &p0, Geom::Point const &p1, Geom::Point const &p2);
71 void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
72 void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
73 void closepath();
74 void closepath_current();
76 SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance);
78 bool is_empty() const;
79 bool is_closed() const;
80 NArtBpath const * last_bpath() const;
81 Geom::Path const * last_path() const;
82 NArtBpath const * first_bpath() const;
83 Geom::Path const * first_path() const;
84 NR::Point first_point() const;
85 NR::Point last_point() const;
86 NR::Point second_point() const;
87 NR::Point penultimate_point() const;
88 guint nodes_in_path() const;
90 void append(SPCurve const *curve2, bool use_lineto);
91 SPCurve * create_reverse() const;
92 void backspace();
94 static SPCurve * concat(GSList const *list);
96 void ensure_space(guint space);
98 protected:
99 gint _refcount;
101 NArtBpath *_bpath;
102 Geom::PathVector _pathv;
104 /// Index in bpath[] of NR_END element.
105 guint _end;
107 /// Allocated size (i.e., capacity) of bpath[] array. Not to be confused
108 /// with the SP_CURVE_LENGTH macro, which returns the logical length of
109 /// the path (i.e., index of NR_END).
110 guint _length;
112 /// Index in bpath[] of the start (i.e., moveto element) of the last
113 /// subpath in this path.
114 guint _substart;
116 /// Previous moveto position.
117 /// \note This is used for coalescing moveto's, whereas if we're to
118 /// conform to the SVG spec then we mustn't coalesce movetos if we have
119 /// midpoint markers. Ref:
120 /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
121 /// (first subitem of the item about zero-length path segments)
122 NR::Point _movePos;
124 /// True iff current point is defined. Initially false for a new curve;
125 /// becomes true after moveto; becomes false on closepath. Curveto,
126 /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
127 bool _hascpt : 1;
129 /// True iff previous was moveto.
130 bool _posSet : 1;
132 /// True iff bpath end is moving.
133 bool _moving : 1;
135 /// True iff all subpaths are closed.
136 bool _closed : 1;
138 private:
139 // Don't implement these:
140 SPCurve(const SPCurve&);
141 SPCurve& operator=(const SPCurve&);
143 //friends:
144 friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
145 friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
146 template<class M> friend void tmpl_curve_transform(SPCurve *const curve, M const &m);
147 // this function is the only one who needs read access to _movePos and _posSet
148 friend void sp_polygon_set(SPObject *object, unsigned int key, const gchar *value);
150 static void debug_check( char const * text, SPCurve const * curve);
151 static void debug_check( char const * text, bool a);
152 };
154 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->get_length())
155 #define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->get_bpath())
156 #define SP_CURVE_SEGMENT(c,i) (((SPCurve const *)(c))->get_bpath() + (i))
158 #endif /* !SEEN_DISPLAY_CURVE_H */
160 /*
161 Local Variables:
162 mode:c++
163 c-file-style:"stroustrup"
164 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
165 indent-tabs-mode:nil
166 fill-column:99
167 End:
168 */
169 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :