summaryrefslogtreecommitdiffstats
path: root/src/svg/svg-path.cpp
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-06-06 01:43:35 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-06-06 01:43:35 +0000
commit8a38c52bce619b07117cdd87a183eb05fb51e28e (patch)
tree39b9f2af1ce9df43884a3b33ca2445097fe8f5a5 /src/svg/svg-path.cpp
parentoops. sys/wait.h not on win32 (diff)
downloadinkscape-8a38c52bce619b07117cdd87a183eb05fb51e28e.tar.gz
inkscape-8a38c52bce619b07117cdd87a183eb05fb51e28e.zip
merge gsoc2008_johan_path2geom into trunk
(bzr r5823)
Diffstat (limited to 'src/svg/svg-path.cpp')
-rw-r--r--src/svg/svg-path.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp
index bd0d4a4f5..d610b9212 100644
--- a/src/svg/svg-path.cpp
+++ b/src/svg/svg-path.cpp
@@ -38,6 +38,11 @@
#include "gnome-canvas-bpath-util.h"
#include "svg/path-string.h"
+#include <2geom/pathvector.h>
+#include <2geom/path.h>
+#include <2geom/sbasis-to-bezier.h>
+#include <2geom/svg-path.h>
+#include <2geom/svg-path-parser.h>
/* This module parses an SVG path element into an RsvgBpathDef.
@@ -668,6 +673,21 @@ NArtBpath *sp_svg_read_path(gchar const *str)
return bpath;
}
+Geom::PathVector sp_svg_read_pathv(char const * str)
+{
+ std::vector<Geom::Path> pathv;
+
+ // TODO: enable this exception catching. don't catch now to better see when things go wrong
+// try {
+ pathv = Geom::parse_svg_path(str);
+// }
+// catch (std::runtime_error e) {
+// g_warning("SVGPathParseError: %s", e.what());
+// }
+
+ return pathv;
+}
+
gchar *sp_svg_write_path(NArtBpath const *bpath)
{
bool closed=false;
@@ -710,6 +730,53 @@ gchar *sp_svg_write_path(NArtBpath const *bpath)
return g_strdup(str.c_str());
}
+static void sp_svg_write_curve(Inkscape::SVG::PathString & str, Geom::Curve const * c) {
+ if(Geom::LineSegment const *line_segment = dynamic_cast<Geom::LineSegment const *>(c)) {
+ str.lineTo( (*line_segment)[1][0], (*line_segment)[1][1] );
+ }
+ else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast<Geom::QuadraticBezier const *>(c)) {
+ str.quadTo( (*quadratic_bezier)[1][0], (*quadratic_bezier)[1][0],
+ (*quadratic_bezier)[2][0], (*quadratic_bezier)[2][1] );
+ }
+ else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const *>(c)) {
+ str.curveTo( (*cubic_bezier)[1][0], (*cubic_bezier)[1][1],
+ (*cubic_bezier)[2][0], (*cubic_bezier)[2][1],
+ (*cubic_bezier)[3][0], (*cubic_bezier)[3][1] );
+ }
+ else if(Geom::EllipticalArc const *svg_elliptical_arc = dynamic_cast<Geom::EllipticalArc const *>(c)) {
+ str.arcTo( 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(),
+ svg_elliptical_arc->finalPoint() );
+ } 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) {
+ sp_svg_write_curve(str, &(*iter));
+ }
+ }
+}
+
+gchar * sp_svg_write_path(Geom::PathVector const &p) {
+ Inkscape::SVG::PathString str;
+
+ for(Geom::PathVector::const_iterator pit = p.begin(); pit != p.end(); pit++) {
+ str.moveTo( pit->initialPoint()[0], pit->initialPoint()[1] );
+
+ for(Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_open(); cit++) {
+ sp_svg_write_curve(str, &(*cit));
+ }
+
+ if (pit->closed()) {
+ str.closePath();
+ }
+ }
+
+ return g_strdup(str.c_str());
+}
+
/*
Local Variables:
mode:c++