From: johanengelen Date: Sun, 22 Jun 2008 21:56:33 +0000 (+0000) Subject: create method for Livarot paths to load PathVectors instead of NArtBpaths X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fbe6f6dcd9b1fedca68655ee24014d49290e18ec;p=inkscape.git create method for Livarot paths to load PathVectors instead of NArtBpaths --- diff --git a/src/livarot/Path.h b/src/livarot/Path.h index 2568f9ccc..4155bac31 100644 --- a/src/livarot/Path.h +++ b/src/livarot/Path.h @@ -14,6 +14,7 @@ #include "livarot/livarot-forward.h" #include "libnr/nr-point.h" #include +#include <2geom/forward.h> struct SPStyle; @@ -177,6 +178,8 @@ public: //utilitaire pour inkscape void LoadArtBPath(void const *iP,NR::Matrix const &tr,bool doTransformation); + 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* MakeArtBPath(); void Transform(const NR::Matrix &trans); @@ -381,6 +384,10 @@ public: bool ExtendFit(int off, int N, fitting_tables &data,double treshhold, PathDescrCubicTo & res,int &worstP); double RaffineTk (NR::Point pt, NR::Point p0, NR::Point p1, NR::Point p2, NR::Point p3, double it); void FlushPendingAddition(Path* dest,PathDescr *lastAddition,PathDescrCubicTo &lastCubic,int lastAD); + +private: + void AddCurve(Geom::Curve const *c); + }; #endif diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp index dddb7bdf4..872ae83e8 100644 --- a/src/livarot/PathCutting.cpp +++ b/src/livarot/PathCutting.cpp @@ -22,6 +22,10 @@ #include "livarot/path-description.h" #include "libnr/n-art-bpath.h" #include "libnr/nr-point-matrix-ops.h" +#include "libnr/nr-convert2geom.h" +#include <2geom/pathvector.h> +#include <2geom/matrix.h> +#include <2geom/sbasis-to-bezier.h> void Path::DashPolyline(float head,float tail,float body,int nbD,float *dashs,bool stPlain,float stOffset) { @@ -405,6 +409,71 @@ void* Path::MakeArtBPath(void) return bpath; } +void Path::AddCurve(Geom::Curve const *c) +{ + if(Geom::LineSegment const *line_segment = dynamic_cast(c)) { + LineTo( NR::Point((*line_segment)[1][0], (*line_segment)[1][1]) ); + } + /* + else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast(c)) { + ... + } + */ + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(c)) { + Geom::Point tmp = (*cubic_bezier)[3]; + Geom::Point tms = 3 * ((*cubic_bezier)[1] - (*cubic_bezier)[0]); + Geom::Point tme = 3 * ((*cubic_bezier)[3] - (*cubic_bezier)[2]); + CubicTo (from_2geom(tmp), from_2geom(tms), from_2geom(tme)); + } + else if(Geom::EllipticalArc const *svg_elliptical_arc = dynamic_cast(c)) { + ArcTo( from_2geom(svg_elliptical_arc->finalPoint()), + svg_elliptical_arc->ray(0), svg_elliptical_arc->ray(1), + svg_elliptical_arc->rotation_angle(), + svg_elliptical_arc->large_arc_flag(), svg_elliptical_arc->sweep_flag() ); + } else { + //this case handles sbasis as well as all other curve types + Geom::Path sbasis_path = Geom::path_from_sbasis(c->toSBasis(), 0.1); + + //recurse to convert the new path resulting from the sbasis to svgd + for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { + AddCurve(&*iter); + } + } +} + +/** append is false by default: it means that the path should be resetted. If it is true, the path is not resetted and Geom::Path will be appended as a new path + */ +void Path::LoadPath(Geom::Path const &path, Geom::Matrix const &tr, bool doTransformation, bool append) +{ + if (!append) { + SetBackData (false); + Reset(); + } + if (path.empty()) + return; + + Geom::Path const pathtr = doTransformation ? path * tr : path; + + MoveTo( from_2geom(pathtr.initialPoint()) ); + + for(Geom::Path::const_iterator cit = pathtr.begin(); cit != pathtr.end_open(); ++cit) { + AddCurve(&*cit); + } + + if (pathtr.closed()) { + Close(); + } +} + +void Path::LoadPathVector(Geom::PathVector const &pv, Geom::Matrix const &tr, bool doTransformation) +{ + SetBackData (false); + Reset(); + for(Geom::PathVector::const_iterator it = pv.begin(); it != pv.end(); ++it) { + LoadPath(*it, tr, doTransformation, true); + } +} + void Path::LoadArtBPath(void const *iV,NR::Matrix const &trans,bool doTransformation) { if ( iV == NULL ) return;