index ab52ac280e851cde6c13e1b490faeb01711a3362..15b0bd8f40d95bc57e8a592c1fea40ec64df9d9f 100644 (file)
#include <signal.h>
#include <errno.h>
-#include <libnr/n-art-bpath.h>
#include <libnr/nr-matrix-fns.h>
#include <glib/gmem.h>
#include <cstdlib>
#include <cmath>
+#include <2geom/sbasis-to-bezier.h>
+#include <2geom/bezier-curve.h>
+#include <2geom/hvlinesegment.h>
+#include "helper/geom-curves.h"
+
/*
using std::atof;
using std::ceil;
unsigned int
-PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NR::Matrix const *ctm, SPStyle const *const style,
+PrintPS::fill(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, NR::Matrix const *ctm, SPStyle const *const style,
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
print_fill_style(os, style, pbox);
- print_bpath(os, bpath->path);
+ print_pathvector(os, pathv);
if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) {
if (style->fill.isColor()) {
unsigned int
-PrintPS::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NR::Matrix const *ctm, SPStyle const *style,
+PrintPS::stroke(Inkscape::Extension::Print *mod, Geom::PathVector const &pathv, NR::Matrix const *ctm, SPStyle const *style,
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
@@ -890,7 +894,7 @@ PrintPS::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NR::Matri
print_stroke_style(os, style);
- print_bpath(os, bpath->path);
+ print_pathvector(os, pathv);
os << "stroke\n";
@@ -1434,44 +1438,55 @@ 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( is_straight_curve(c) )
+ {
+ os << c.finalPoint()[X] << " " << c.finalPoint()[Y] << " lineto\n";
+ }
+ else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const*>(&c)) {
+ std::vector<Geom::Point> 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.