Code

don't use splivarot to get livarot path, use livarot's LoadPathVector method instead
authorjohanengelen <johanengelen@users.sourceforge.net>
Thu, 26 Jun 2008 22:57:43 +0000 (22:57 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Thu, 26 Jun 2008 22:57:43 +0000 (22:57 +0000)
src/livarot/Path.h
src/livarot/PathCutting.cpp
src/nodepath.cpp
src/sp-offset.cpp

index d0bd2e9dd06852437c72d82193bc8755d313fa1a..adc26c169e425447e7254b44229980fc43e19ec3 100644 (file)
@@ -179,6 +179,7 @@ public:
   //utilitaire pour inkscape
   void  LoadPath(Geom::Path const &path, Geom::Matrix const &tr, bool doTransformation, bool append = false);
   void  LoadPathVector(Geom::PathVector const &pv, Geom::Matrix const &tr, bool doTransformation);
+  void  LoadPathVector(Geom::PathVector const &pv);
        void* MakeArtBPath();
        
        void  Transform(const NR::Matrix &trans);
index c67fc9c97436752d98e72f51801ad239da272382..2987536c3e9ee1961146ec79b7ee9aa6eaac1d84 100644 (file)
@@ -452,6 +452,8 @@ void  Path::LoadPath(Geom::Path const &path, Geom::Matrix const &tr, bool doTran
     if (path.empty())
         return;
 
+    // TODO: this can be optimized by not generating a new path here, but doing the transform in AddCurve
+    //       directly on the curve parameters
     Geom::Path const pathtr = doTransformation ? path * tr : path;
 
     MoveTo( from_2geom(pathtr.initialPoint()) );
@@ -465,6 +467,11 @@ void  Path::LoadPath(Geom::Path const &path, Geom::Matrix const &tr, bool doTran
     }
 }
 
+void  Path::LoadPathVector(Geom::PathVector const &pv)
+{
+    LoadPathVector(pv, Geom::Matrix(), false);
+}
+
 void  Path::LoadPathVector(Geom::PathVector const &pv, Geom::Matrix const &tr, bool doTransformation)
 {
     SetBackData (false);
index f4be1c30c71dd7a9fcb2f738712e442374047613..b712539ab767f78f872a3fb550c54095ae7f1f9f 100644 (file)
@@ -342,7 +342,7 @@ void sp_nodepath_ensure_livarot_path(Inkscape::NodePath::Path *np)
     if (np && np->livarot_path == NULL) {
         SPCurve *curve = create_curve(np);
         np->livarot_path = new Path;
-        np->livarot_path->LoadPathVector(curve->get_pathvector(), Geom::Matrix(), false);
+        np->livarot_path->LoadPathVector(curve->get_pathvector());
 
         if (np->livarot_path)
             np->livarot_path->ConvertWithBackData(0.01);
index c11324ec5f9c23da60f0d18e3c579512acef9070..de4933821c3ed46f65e596b5da6950c24476cc92 100644 (file)
@@ -87,8 +87,6 @@ static gchar *sp_offset_description (SPItem * item);
 static void sp_offset_snappoints(SPItem const *item, SnapPointsIter p);
 static void sp_offset_set_shape (SPShape * shape);
 
-Path *bpath_to_liv_path (NArtBpath const * bpath);
-
 static void refresh_offset_source(SPOffset* offset);
 
 static void sp_offset_start_listening(SPOffset *offset,SPObject* to);
@@ -352,10 +350,8 @@ sp_offset_set(SPObject *object, unsigned key, gchar const *value)
                 offset->original = strdup (value);
 
                 Geom::PathVector pv = sp_svg_read_pathv(offset->original);
-                SPCurve *curve = new SPCurve(pv);         // fixme: translate this: curve se chargera de detruire bpath
-                g_assert (curve != NULL);
-                offset->originalPath = bpath_to_liv_path (SP_CURVE_BPATH(curve));
-                curve->unref();
+                offset->originalPath = new Path;
+                reinterpret_cast<Path *>(offset->originalPath)->LoadPathVector(pv);
 
                 offset->knotSet = false;
                 if ( offset->isUpdating == false ) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
@@ -437,75 +433,6 @@ sp_offset_description(SPItem *item)
     }
 }
 
-/**
- * Converts an NArtBpath (like the one stored in a SPCurve) into a
- * livarot Path. Duplicate of splivarot.
- */
-Path *
-bpath_to_liv_path(NArtBpath const *bpath)
-{
-    if (bpath == NULL)
-        return NULL;
-
-    Path *dest = new Path;
-    dest->SetBackData (false);
-    {
-        int i;
-        bool closed = false;
-        float lastX = 0.0;
-        float lastY = 0.0;
-
-        for (i = 0; bpath[i].code != NR_END; i++)
-        {
-            switch (bpath[i].code)
-            {
-                case NR_LINETO:
-                    lastX = bpath[i].x3;
-                    lastY = bpath[i].y3;
-                    {
-                        NR::Point  tmp(lastX,lastY);
-                        dest->LineTo (tmp);
-                    }
-                    break;
-
-                case NR_CURVETO:
-                {
-                    NR::Point  tmp(bpath[i].x3, bpath[i].y3);
-                    NR::Point  tms;
-                    tms[0]=3 * (bpath[i].x1 - lastX);
-                    tms[1]=3 * (bpath[i].y1 - lastY);
-                    NR::Point  tme;
-                    tme[0]=3 * (bpath[i].x3 - bpath[i].x2);
-                    tme[1]= 3 * (bpath[i].y3 - bpath[i].y2);
-                    dest->CubicTo (tmp,tms,tme);
-                }
-                lastX = bpath[i].x3;
-                lastY = bpath[i].y3;
-                break;
-
-                case NR_MOVETO_OPEN:
-                case NR_MOVETO:
-                    if (closed)
-                        dest->Close ();
-                    closed = (bpath[i].code == NR_MOVETO);
-                    lastX = bpath[i].x3;
-                    lastY = bpath[i].y3;
-                    {
-                        NR::Point tmp(lastX,lastY);
-                        dest->MoveTo(tmp);
-                    }
-                    break;
-                default:
-                    break;
-            }
-        }
-        if (closed)
-            dest->Close ();
-    }
-
-    return dest;
-}
-
 /**
  * Compute and set shape's offset.
  */
@@ -1030,14 +957,15 @@ sp_offset_top_point (SPOffset * offset, NR::Point *px)
         if (curve == NULL)
             return;
     }
-
-    Path *finalPath = bpath_to_liv_path (SP_CURVE_BPATH(curve));
-    if (finalPath == NULL)
+    if (curve->is_empty())
     {
         curve->unref();
         return;
     }
 
+    Path *finalPath = new Path;
+    finalPath->LoadPathVector(curve->get_pathvector());
+
     Shape *theShape = new Shape;
 
     finalPath->Convert (1.0);
@@ -1155,7 +1083,6 @@ refresh_offset_source(SPOffset* offset)
 {
     if ( offset == NULL ) return;
     offset->sourceDirty=false;
-    Path *orig = NULL;
 
     // le mauvais cas: pas d'attribut d => il faut verifier que c'est une SPShape puis prendre le contour
     // The bad case: no d attribute.  Must check that it's an SPShape and then take the outline.
@@ -1173,9 +1100,10 @@ refresh_offset_source(SPOffset* offset)
     if (SP_IS_TEXT (item)) {
         curve = SP_TEXT (item)->getNormalizedBpath ();
         if (curve == NULL)
-           return;
+        return;
     }
-    orig = bpath_to_liv_path (SP_CURVE_BPATH(curve));
+    Path *orig = new Path;
+    orig->LoadPathVector(curve->get_pathvector());
     curve->unref();