diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-07-12 14:28:25 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-07-12 14:28:25 +0000 |
| commit | 790d58c716c76d5fdf2cbbba2ea5b10721d195f3 (patch) | |
| tree | 829e752bb4d6c0f88fdf59dc5c3fa0db0c22f401 | |
| parent | increase font size on kerning_preview and text_preview drawing areas (diff) | |
| download | inkscape-790d58c716c76d5fdf2cbbba2ea5b10721d195f3.tar.gz inkscape-790d58c716c76d5fdf2cbbba2ea5b10721d195f3.zip | |
Don't crash on path parse error. Truncate the path data up to where it is valid.
For now shows unsafe debug message about where the path was truncated.
(bzr r6272)
| -rw-r--r-- | src/svg/svg-path.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/svg/svg-path.cpp b/src/svg/svg-path.cpp index 1ab70d101..3deb6105c 100644 --- a/src/svg/svg-path.cpp +++ b/src/svg/svg-path.cpp @@ -36,6 +36,7 @@ #include "libnr/n-art-bpath.h" #include "gnome-canvas-bpath-util.h" +#include "svg/svg.h" #include "svg/path-string.h" #include <2geom/pathvector.h> @@ -674,20 +675,28 @@ NArtBpath *sp_svg_read_path(gchar const *str) return bpath; } +/* + * Parses the path in str. When an error is found in the pathstring, this method + * returns a truncated path up to where the error was found in the pathstring. + * Returns an empty PathVector when str==NULL + */ Geom::PathVector sp_svg_read_pathv(char const * str) { - std::vector<Geom::Path> pathv; + Geom::PathVector pathv; if (!str) return pathv; // return empty pathvector when str == NULL + + typedef std::back_insert_iterator<Geom::PathVector> Inserter; + Inserter iter(pathv); + Geom::SVGPathGenerator<Inserter> generator(iter); + try { - pathv = Geom::parse_svg_path(str); + Geom::parse_svg_path(str, generator); } catch (Geom::SVGPathParseError e) { - g_warning("SVGPathParseError: %s", e.what()); - g_warning("svgd str: %s", str); - throw Geom::SVGPathParseError(); // rethrow, maybe not necessary, can instead return empty path? - return std::vector<Geom::Path>(); + generator.finish(); + 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)); } return pathv; |
