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 *
14 * Released under GNU GPL
15 */
17 #include <glib/gtypes.h>
18 #include <glib/gslist.h>
20 #include "libnr/nr-forward.h"
21 #include "libnr/nr-point.h"
22 #include "libnr/nr-rect.h"
24 /// Wrapper around NArtBpath.
25 struct SPCurve {
26 gint refcount;
27 NArtBpath *_bpath;
29 /// Index in bpath[] of NR_END element.
30 gint end;
32 /// Allocated size (i.e., capacity) of bpath[] array. Not to be confused
33 /// with the SP_CURVE_LENGTH macro, which returns the logical length of
34 /// the path (i.e., index of NR_END).
35 gint length;
37 /// Index in bpath[] of the start (i.e., moveto element) of the last
38 /// subpath in this path.
39 gint substart;
41 /// Previous moveto position.
42 /// \note This is used for coalescing moveto's, whereas if we're to
43 /// conform to the SVG spec then we mustn't coalesce movetos if we have
44 /// midpoint markers. Ref:
45 /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
46 /// (first subitem of the item about zero-length path segments)
47 NR::Point movePos;
49 /// True iff current point is defined. Initially false for a new curve;
50 /// becomes true after moveto; becomes false on closepath. Curveto,
51 /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
52 bool hascpt : 1;
54 /// True iff previous was moveto.
55 bool posSet : 1;
57 /// True iff bpath end is moving.
58 bool moving : 1;
60 /// True iff all subpaths are closed.
61 bool closed : 1;
62 };
64 #define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->end)
65 #define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->_bpath)
66 #define SP_CURVE_SEGMENT(c,i) (((SPCurve const *)(c))->_bpath + (i))
68 /* Constructors */
70 SPCurve *sp_curve_new();
71 SPCurve *sp_curve_new_sized(gint length);
72 SPCurve *sp_curve_new_from_bpath(NArtBpath *bpath);
73 SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]);
74 SPCurve *sp_curve_new_from_rect(NR::Maybe<NR::Rect> const &rect);
76 SPCurve *sp_curve_ref(SPCurve *curve);
77 SPCurve *sp_curve_unref(SPCurve *curve);
79 SPCurve *sp_curve_copy(SPCurve *curve);
80 SPCurve *sp_curve_concat(GSList const *list);
81 GSList *sp_curve_split(SPCurve const *curve);
82 void sp_curve_transform(SPCurve *curve, NR::Matrix const &);
83 void sp_curve_transform(SPCurve *curve, NR::translate const &);
84 void sp_curve_stretch_endpoints(SPCurve *curve, NR::Point const &, NR::Point const &);
85 void sp_curve_move_endpoints(SPCurve *curve, NR::Point const &,
86 NR::Point const &);
88 /* Methods */
90 void sp_curve_reset(SPCurve *curve);
92 void sp_curve_moveto(SPCurve *curve, NR::Point const &p);
93 void sp_curve_moveto(SPCurve *curve, gdouble x, gdouble y);
94 void sp_curve_lineto(SPCurve *curve, NR::Point const &p);
95 void sp_curve_lineto(SPCurve *curve, gdouble x, gdouble y);
96 void sp_curve_lineto_moving(SPCurve *curve, gdouble x, gdouble y);
97 void sp_curve_curveto(SPCurve *curve, NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
98 void sp_curve_curveto(SPCurve *curve, gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
99 void sp_curve_closepath(SPCurve *curve);
100 void sp_curve_closepath_current(SPCurve *curve);
102 SPCurve *sp_curve_append_continuous(SPCurve *c0, SPCurve const *c1, gdouble tolerance);
104 #define sp_curve_is_empty sp_curve_empty
105 bool sp_curve_empty(SPCurve *curve);
106 NArtBpath *sp_curve_last_bpath(SPCurve const *curve);
107 NArtBpath *sp_curve_first_bpath(SPCurve const *curve);
108 NR::Point sp_curve_first_point(SPCurve const *curve);
109 NR::Point sp_curve_last_point(SPCurve const *curve);
110 NR::Point sp_curve_second_point(SPCurve const *curve);
111 NR::Point sp_curve_penultimate_point(SPCurve const *curve);
113 void sp_curve_append(SPCurve *curve, SPCurve const *curve2, bool use_lineto);
114 SPCurve *sp_curve_reverse(SPCurve const *curve);
115 void sp_curve_backspace(SPCurve *curve);
118 #endif /* !SEEN_DISPLAY_CURVE_H */
120 /*
121 Local Variables:
122 mode:c++
123 c-file-style:"stroustrup"
124 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
125 indent-tabs-mode:nil
126 fill-column:99
127 End:
128 */
129 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :