From 848bab0c597980ec13b155f4e16820950e5ded61 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 26 Jun 2008 22:57:43 +0000 Subject: [PATCH] don't use splivarot to get livarot path, use livarot's LoadPathVector method instead --- src/livarot/Path.h | 1 + src/livarot/PathCutting.cpp | 7 +++ src/nodepath.cpp | 2 +- src/sp-offset.cpp | 90 ++++--------------------------------- 4 files changed, 18 insertions(+), 82 deletions(-) diff --git a/src/livarot/Path.h b/src/livarot/Path.h index d0bd2e9dd..adc26c169 100644 --- a/src/livarot/Path.h +++ b/src/livarot/Path.h @@ -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); diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp index c67fc9c97..2987536c3 100644 --- a/src/livarot/PathCutting.cpp +++ b/src/livarot/PathCutting.cpp @@ -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); diff --git a/src/nodepath.cpp b/src/nodepath.cpp index f4be1c30c..b712539ab 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -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); diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index c11324ec5..de4933821 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -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(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(); -- 2.30.2