From: johanengelen Date: Sat, 12 Jul 2008 16:04:51 +0000 (+0000) Subject: convert ps output to 2geom X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1e954d40bd974826c2af3e64e6debe9426eb9096;p=inkscape.git convert ps output to 2geom --- diff --git a/src/extension/internal/ps.cpp b/src/extension/internal/ps.cpp index 7670c3a86..aec3cf951 100644 --- a/src/extension/internal/ps.cpp +++ b/src/extension/internal/ps.cpp @@ -77,6 +77,8 @@ #include #include +#include <2geom/sbasis-to-bezier.h> + /* using std::atof; using std::ceil; @@ -830,9 +832,7 @@ PrintPS::fill(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, NR print_fill_style(os, style, pbox); - NArtBpath * bpath = BPath_from_2GeomPath(pathv); - print_bpath(os, bpath); - g_free(bpath); + print_pathvector(os, pathv); if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) { if (style->fill.isColor()) { @@ -893,9 +893,7 @@ PrintPS::stroke(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, print_stroke_style(os, style); - NArtBpath * bpath = BPath_from_2GeomPath(pathv); - print_bpath(os, bpath); - g_free(bpath); + print_pathvector(os, pathv); os << "stroke\n"; @@ -1439,44 +1437,57 @@ PrintPS::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p, /* PostScript helpers */ void -PrintPS::print_bpath(SVGOStringStream &os, NArtBpath const *bp) +PrintPS::print_pathvector(SVGOStringStream &os, Geom::PathVector const &pathv) { + if (pathv.empty()) + return; + os << "newpath\n"; - bool closed = false; - while (bp->code != NR_END) { - switch (bp->code) { - case NR_MOVETO: - if (closed) { - os << "closepath\n"; - } - closed = true; - os << bp->x3 << " " << bp->y3 << " moveto\n"; - break; - case NR_MOVETO_OPEN: - if (closed) { - os << "closepath\n"; - } - closed = false; - os << bp->x3 << " " << bp->y3 << " moveto\n"; - break; - case NR_LINETO: - os << bp->x3 << " " << bp->y3 << " lineto\n"; - break; - case NR_CURVETO: - os << bp->x1 << " " << bp->y1 << " " - << bp->x2 << " " << bp->y2 << " " - << bp->x3 << " " << bp->y3 << " curveto\n"; - break; - default: - break; + + for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { + + os << it->initialPoint()[Geom::X] << " " << it->initialPoint()[Geom::Y] << " moveto\n"; + + for(Geom::Path::const_iterator cit = it->begin(); cit != it->end_open(); ++cit) { + print_2geomcurve(os, *cit); + } + + if (it->closed()) { + os << "closepath\n"; } - bp += 1; + } - if (closed) { - os << "closepath\n"; +} + +void +PrintPS::print_2geomcurve(SVGOStringStream &os, Geom::Curve const & c ) +{ + using Geom::X; + using Geom::Y; + + if( dynamic_cast(&c) || + dynamic_cast(&c) || + dynamic_cast(&c) ) + { + os << c.finalPoint()[X] << " " << c.finalPoint()[Y] << " lineto\n"; + } + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(&c)) { + std::vector points = cubic_bezier->points(); + os << points[1][X] << " " << points[1][Y] << " " + << points[2][X] << " " << points[2][Y] << " " + << points[3][X] << " " << points[3][Y] << " curveto\n"; + } + else { + //this case handles sbasis as well as all other curve types + Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1); + + for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { + print_2geomcurve(os, *iter); + } } } + /* The following code is licensed under GNU GPL. ** The packbits, ascii85 and imaging printing code ** is from the gimp's postscript.c. diff --git a/src/extension/internal/ps.h b/src/extension/internal/ps.h index 407da88a3..179779e25 100644 --- a/src/extension/internal/ps.h +++ b/src/extension/internal/ps.h @@ -47,7 +47,8 @@ class PrintPS : public Inkscape::Extension::Implementation::Implementation { //map strings of font types to enumeration of int values std::map _fontTypesMap; - void print_bpath(SVGOStringStream &os, NArtBpath const *bp); + void print_2geomcurve(SVGOStringStream &os, Geom::Curve const & c ); + void print_pathvector(SVGOStringStream &os, Geom::PathVector const &pathv); void print_fill_style(SVGOStringStream &os, SPStyle const *style, NRRect const *pbox); void print_stroke_style(SVGOStringStream &os, SPStyle const *style);