Code

Fixed icon loading, cacheing and fallback to use stock mechanisms.
[inkscape.git] / src / display / curve.h
index 28fce31323e030b6c6fe8d2910eb7fd1a161031d..6697987cafe9fd2cc48a7e41486f8a66cad05bf7 100644 (file)
 #include <glib/gtypes.h>
 #include <glib/gslist.h>
 
+#include <2geom/forward.h>
+
 #include "libnr/nr-forward.h"
 #include "libnr/nr-rect.h"
 
 #define SP_CURVE_LENSTEP 32
 
-/// Wrapper around NArtBpath.
+struct SPObject;
+
+/// Wrapper around Geom::PathVector.
 class SPCurve {
 public:
     /* Constructors */
     SPCurve(guint length = SP_CURVE_LENSTEP);
+    SPCurve(Geom::PathVector const& pathv);
     static SPCurve * new_from_bpath(NArtBpath *bpath);
     static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath);
-    static SPCurve * new_from_rect(NR::Maybe<NR::Rect> const &rect);
+    static SPCurve * new_from_rect(Geom::Rect const &rect);
 
     virtual ~SPCurve();
 
-    void set_bpath(NArtBpath * new_bpath);
+    void set_pathvector(Geom::PathVector const & new_pathv);
     NArtBpath const * get_bpath() const;
-    NArtBpath * get_bpath();
-
-    /// Index in bpath[] of NR_END element.
-    guint _end;
-
-    /// Allocated size (i.e., capacity) of bpath[] array.  Not to be confused 
-    /// with the SP_CURVE_LENGTH macro, which returns the logical length of 
-    /// the path (i.e., index of NR_END).
-    guint _length;
-
-    /// Index in bpath[] of the start (i.e., moveto element) of the last 
-    /// subpath in this path.
-    guint _substart;
+    Geom::PathVector const & get_pathvector() const;
 
-    /// Previous moveto position.
-    /// \note This is used for coalescing moveto's, whereas if we're to 
-    /// conform to the SVG spec then we mustn't coalesce movetos if we have 
-    /// midpoint markers.  Ref:
-    /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
-    /// (first subitem of the item about zero-length path segments)
-    NR::Point _movePos;
-
-    /// True iff current point is defined.  Initially false for a new curve; 
-    /// becomes true after moveto; becomes false on closepath.  Curveto, 
-    /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
-    bool _hascpt : 1;
-    
-    /// True iff previous was moveto.
-    bool _posSet : 1;
-
-    /// True iff bpath end is moving.
-    bool _moving : 1;
-    
-    /// True iff all subpaths are closed.
-    bool _closed : 1;
+    guint get_length() const;
+    guint get_segment_count() const;
 
     SPCurve * ref();
     SPCurve * unref();
@@ -78,18 +52,21 @@ public:
     SPCurve * copy() const;
 
     GSList * split() const;
-    void transform(NR::Matrix const &);
-    void transform(NR::translate const &);
+    void transform(NR::Matrix const &m);
+    void transform(Geom::Matrix const &m);
     void stretch_endpoints(NR::Point const &, NR::Point const &);
     void move_endpoints(NR::Point const &, NR::Point const &);
+    void last_point_additive_move(Geom::Point const & p);
 
     void reset();
 
+    void moveto(Geom::Point const &p);
     void moveto(NR::Point const &p);
     void moveto(gdouble x, gdouble y);
+    void lineto(Geom::Point const &p);
     void lineto(NR::Point const &p);
     void lineto(gdouble x, gdouble y);
-    void lineto_moving(gdouble x, gdouble y);
+    void curveto(Geom::Point const &p0, Geom::Point const &p1, Geom::Point const &p2);
     void curveto(NR::Point const &p0, NR::Point const &p1, NR::Point const &p2);
     void curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2);
     void closepath();
@@ -99,12 +76,16 @@ public:
 
     bool is_empty() const;
     bool is_closed() const;
-    NArtBpath * last_bpath() const;
-    NArtBpath * first_bpath() const;
+    NArtBpath const * last_bpath() const;
+    Geom::Curve const * last_segment() const;
+    Geom::Path const * last_path() const;
+    Geom::Curve const * first_segment() const;
+    Geom::Path const * first_path() const;
     NR::Point first_point() const;
     NR::Point last_point() const;
     NR::Point second_point() const;
     NR::Point penultimate_point() const;
+    guint nodes_in_path() const;
 
     void append(SPCurve const *curve2, bool use_lineto);
     SPCurve * create_reverse() const;
@@ -118,20 +99,56 @@ protected:
     gint _refcount;
 
     NArtBpath *_bpath;
+    Geom::PathVector _pathv;
+
+    /// Index in bpath[] of NR_END element.
+    guint _end;
+
+    /// Allocated size (i.e., capacity) of bpath[] array.  Not to be confused 
+    /// with the SP_CURVE_LENGTH macro, which returns the logical length of 
+    /// the path (i.e., index of NR_END).
+    guint _length;
+
+    /// Index in bpath[] of the start (i.e., moveto element) of the last 
+    /// subpath in this path.
+    guint _substart;
+
+    /// Previous moveto position.
+    /// \note This is used for coalescing moveto's, whereas if we're to 
+    /// conform to the SVG spec then we mustn't coalesce movetos if we have 
+    /// midpoint markers.  Ref:
+    /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
+    /// (first subitem of the item about zero-length path segments)
+    NR::Point _movePos;
+
+    /// True iff current point is defined.  Initially false for a new curve; 
+    /// becomes true after moveto; becomes false on closepath.  Curveto, 
+    /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
+    bool _hascpt : 1;
+    
+    /// True iff previous was moveto.
+    bool _posSet : 1;
+
+    /// True iff bpath end is moving.
+    bool _moving : 1;
+    
+    /// True iff all subpaths are closed.
+    bool _closed : 1;
 
 private:
     // Don't implement these:
     SPCurve(const SPCurve&);
     SPCurve& operator=(const SPCurve&);
 
+//friends:
     friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]);
     friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]);
-    template<class M> friend void tmpl_curve_transform(SPCurve *const curve, M const &m);
+    template<class M> friend void tmpl_curve_transform(SPCurve * curve, M const &m);
 };
 
-#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->_end)
-#define SP_CURVE_BPATH(c) ((c)->get_bpath())
-#define SP_CURVE_SEGMENT(c,i) ((c)->get_bpath() + (i))
+#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->get_length())
+#define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->get_bpath())
+
 
 #endif /* !SEEN_DISPLAY_CURVE_H */
 
@@ -144,4 +161,4 @@ private:
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :