Code

9cbb115292d2bb6dbef1f8a76b9fcd6464d6a486
[inkscape.git] / src / display / curve.h
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(gint 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     gint refcount;
38     NArtBpath *_bpath;
39     
40     /// Index in bpath[] of NR_END element.
41     gint 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     gint length;
48     /// Index in bpath[] of the start (i.e., moveto element) of the last 
49     /// subpath in this path.
50     gint 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;
64     
65     /// True iff previous was moveto.
66     bool posSet : 1;
68     /// True iff bpath end is moving.
69     bool moving : 1;
70     
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     NArtBpath * last_bpath() const;
101     NArtBpath * first_bpath() const;
102     NR::Point first_point() const;
103     NR::Point last_point() const;
104     NR::Point second_point() const;
105     NR::Point penultimate_point() const;
107     void append(SPCurve const *curve2, bool use_lineto);
108     SPCurve * reverse() const;
109     void backspace();
111     static SPCurve * concat(GSList const *list);
113 private:
114     // Don't implement these:
115     SPCurve(const SPCurve&);
116     SPCurve& operator=(const SPCurve&);
117 };
119 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->end)
120 #define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->_bpath)
121 #define SP_CURVE_SEGMENT(c,i) (((SPCurve const *)(c))->_bpath + (i))
123 #endif /* !SEEN_DISPLAY_CURVE_H */
125 /*
126   Local Variables:
127   mode:c++
128   c-file-style:"stroustrup"
129   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
130   indent-tabs-mode:nil
131   fill-column:99
132   End:
133 */
134 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :