summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-11-06 11:25:30 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-11-06 11:25:30 +0000
commitf74fd75f68147084cb9fbeac0573051e08605ac8 (patch)
tree4c5f6aba727efbd0cc9f15a4b64e23746ee87770 /src
parentfix memory leak in ClipboardManagerImpl (diff)
downloadinkscape-f74fd75f68147084cb9fbeac0573051e08605ac8.tar.gz
inkscape-f74fd75f68147084cb9fbeac0573051e08605ac8.zip
Update to latest syntax for 'd' as property.
Diffstat (limited to 'src')
-rw-r--r--src/object/sp-path.cpp50
1 files changed, 35 insertions, 15 deletions
diff --git a/src/object/sp-path.cpp b/src/object/sp-path.cpp
index 81149b13e..1da1ddc92 100644
--- a/src/object/sp-path.cpp
+++ b/src/object/sp-path.cpp
@@ -16,6 +16,7 @@
*/
#include <glibmm/i18n.h>
+#include <glibmm/regex.h>
#include "live_effects/effect.h"
#include "live_effects/lpeobject.h"
@@ -132,28 +133,47 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) {
(d_source == SP_STYLE_SRC_STYLE_PROP || d_source == SP_STYLE_SRC_STYLE_SHEET) ) {
if (style->d.value) {
- Geom::PathVector pv = sp_svg_read_pathv(style->d.value);
- SPCurve *curve = new SPCurve(pv);
- if (curve) {
+ // Chrome shipped with a different syntax for property vs attribute.
+ // The SVG Working group decided to follow the Chrome syntax (which may
+ // allow future extensions of the 'd' property). The property syntax
+ // wraps the path data with "path(...)". We must strip that!
+
+ // Must be Glib::ustring or we get conversion errors!
+ Glib::ustring input = style->d.value;
+ Glib::ustring expression = R"A(path\("(.*)"\))A";
+ Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create(expression);
+ Glib::MatchInfo matchInfo;
+ regex->match(input, matchInfo);
+
+ if (matchInfo.matches()) {
+ Glib::ustring value = matchInfo.fetch(1);
+ Geom::PathVector pv = sp_svg_read_pathv(value.c_str());
- // Update curve
- this->setCurveInsync(curve, TRUE);
- curve->unref();
+ SPCurve *curve = new SPCurve(pv);
+ if (curve) {
- // Convert from property to attribute (convert back on write)
- getRepr()->setAttribute("d", style->d.value);
+ // Update curve
+ this->setCurveInsync(curve, TRUE);
+ curve->unref();
- SPCSSAttr *css = sp_repr_css_attr( getRepr(), "style");
- sp_repr_css_unset_property ( css, "d");
- sp_repr_css_set ( getRepr(), css, "style" );
- sp_repr_css_attr_unref ( css );
+ // Convert from property to attribute (convert back on write)
+ getRepr()->setAttribute("d", value);
- style->d.style_src = SP_STYLE_SRC_ATTRIBUTE;
- } else {
- // Do nothing... don't overwrite 'd' from attribute
+ SPCSSAttr *css = sp_repr_css_attr( getRepr(), "style");
+ sp_repr_css_unset_property ( css, "d");
+ sp_repr_css_set ( getRepr(), css, "style" );
+ sp_repr_css_attr_unref ( css );
+
+ style->d.style_src = SP_STYLE_SRC_ATTRIBUTE;
+ } else {
+ std::cerr << "SPPath::build: Failed to create curve: " << input << std::endl;
+ }
}
}
+ // If any if statement is false, do nothing... don't overwrite 'd' from attribute
}
+
+
// this->readAttr( "inkscape:original-d" ); // bug #1299948
// Why we take the long way of doing this probably needs some explaining:
//