diff options
Diffstat (limited to 'src/svg/svg-path.cpp')
| -rw-r--r-- | src/svg/svg-path.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp index 9ba3c0ebd..ba9e11452 100644 --- a/src/svg/svg-path.cpp +++ b/src/svg/svg-path.cpp @@ -43,16 +43,15 @@ Geom::PathVector sp_svg_read_pathv(char const * str) if (!str) return pathv; // return empty pathvector when str == NULL - - typedef std::back_insert_iterator<Geom::PathVector> Inserter; - Inserter iter(pathv); - Geom::PathIteratorSink<Inserter> generator(iter); + Geom::PathBuilder builder(pathv); + Geom::SVGPathParser parser(builder); + parser.setZSnapThreshold(Geom::EPSILON); try { - Geom::parse_svg_path(str, generator); + parser.parse(str); } catch (Geom::SVGPathParseError &e) { - generator.flush(); + builder.flush(); // This warning is extremely annoying when testing //g_warning("Malformed SVG path, truncated path up to where error was found.\n Input path=\"%s\"\n Parsed path=\"%s\"", str, sp_svg_write_path(pathv)); } @@ -61,10 +60,17 @@ Geom::PathVector sp_svg_read_pathv(char const * str) } static void sp_svg_write_curve(Inkscape::SVG::PathString & str, Geom::Curve const * c) { + // TODO: this code needs to removed and replaced by appropriate path sink if(Geom::LineSegment const *line_segment = dynamic_cast<Geom::LineSegment const *>(c)) { // don't serialize stitch segments if (!dynamic_cast<Geom::Path::StitchSegment const *>(c)) { - str.lineTo( (*line_segment)[1][0], (*line_segment)[1][1] ); + if (line_segment->initialPoint()[Geom::X] == line_segment->finalPoint()[Geom::X]) { + str.verticalLineTo( line_segment->finalPoint()[Geom::Y] ); + } else if (line_segment->initialPoint()[Geom::Y] == line_segment->finalPoint()[Geom::Y]) { + str.horizontalLineTo( line_segment->finalPoint()[Geom::X] ); + } else { + str.lineTo( (*line_segment)[1][0], (*line_segment)[1][1] ); + } } } else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast<Geom::QuadraticBezier const *>(c)) { @@ -76,17 +82,11 @@ static void sp_svg_write_curve(Inkscape::SVG::PathString & str, Geom::Curve cons (*cubic_bezier)[2][0], (*cubic_bezier)[2][1], (*cubic_bezier)[3][0], (*cubic_bezier)[3][1] ); } - else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast<Geom::SVGEllipticalArc const *>(c)) { - str.arcTo( svg_elliptical_arc->ray(Geom::X), svg_elliptical_arc->ray(Geom::Y), - Geom::rad_to_deg(svg_elliptical_arc->rotationAngle()), - svg_elliptical_arc->largeArc(), svg_elliptical_arc->sweep(), - svg_elliptical_arc->finalPoint() ); - } - else if(Geom::HLineSegment const *hline_segment = dynamic_cast<Geom::HLineSegment const *>(c)) { - str.horizontalLineTo( hline_segment->finalPoint()[0] ); - } - else if(Geom::VLineSegment const *vline_segment = dynamic_cast<Geom::VLineSegment const *>(c)) { - str.verticalLineTo( vline_segment->finalPoint()[1] ); + else if(Geom::EllipticalArc const *elliptical_arc = dynamic_cast<Geom::EllipticalArc const *>(c)) { + str.arcTo( elliptical_arc->ray(Geom::X), elliptical_arc->ray(Geom::Y), + Geom::rad_to_deg(elliptical_arc->rotationAngle()), + elliptical_arc->largeArc(), elliptical_arc->sweep(), + elliptical_arc->finalPoint() ); } else { //this case handles sbasis as well as all other curve types Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c->toSBasis(), 0.1); |
