summaryrefslogtreecommitdiffstats
path: root/src/object/sp-path.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-02-13 14:48:14 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-02-13 14:48:14 +0000
commite88644b0f3481c78a9563dbf9ee6b76ab6674583 (patch)
treeaf55ee50eb2e0183baba5b3a9fad4a69d377ff50 /src/object/sp-path.cpp
parentMisc. typos (diff)
downloadinkscape-e88644b0f3481c78a9563dbf9ee6b76ab6674583.tar.gz
inkscape-e88644b0f3481c78a9563dbf9ee6b76ab6674583.zip
Promote the path 'd' attribute to a property per SVG 2.
This allows 'd' to be animated via CSS animations. Due to the interactions of 'd' with LPE's, 'd' as a property is converted to 'd' as an attribute in SPPath::update. This changes the XML which causes update() to be called again (and triggers a warning). Fixing this is left to a future patch as is converting the 'd' back to a property on output.
Diffstat (limited to 'src/object/sp-path.cpp')
-rw-r--r--src/object/sp-path.cpp79
1 files changed, 62 insertions, 17 deletions
diff --git a/src/object/sp-path.cpp b/src/object/sp-path.cpp
index a0c7f098d..b4e9f7559 100644
--- a/src/object/sp-path.cpp
+++ b/src/object/sp-path.cpp
@@ -21,29 +21,32 @@
#include <glibmm/i18n.h>
-#include "live_effects/effect.h"
-#include "live_effects/lpeobject.h"
-#include "live_effects/lpeobject-reference.h"
-#include "sp-lpe-item.h"
+#include <2geom/curves.h>
+#include "attributes.h"
+#include "desktop-style.h"
+#include "desktop.h"
#include "display/curve.h"
-#include <2geom/curves.h>
+#include "document.h"
+#include "inkscape.h"
+#include "style.h"
+
#include "helper/geom-curves.h"
-#include "svg/svg.h"
-#include "xml/repr.h"
-#include "attributes.h"
+#include "live_effects/effect.h"
+#include "live_effects/lpeobject-reference.h"
+#include "live_effects/lpeobject.h"
-#include "sp-path.h"
#include "sp-guide.h"
+#include "sp-lpe-item.h"
+#include "sp-path.h"
-#include "document.h"
-#include "desktop.h"
+#include "svg/svg.h"
-#include "desktop-style.h"
#include "ui/tools/tool-base.h"
-#include "inkscape.h"
-#include "style.h"
+
+#include "xml/repr.h"
+#include "xml/sp-css-attr.h"
#define noPATH_VERBOSE
@@ -109,13 +112,18 @@ void SPPath::convert_to_guides() const {
sp_guide_pt_pairs_to_guides(this->document, pts);
}
-SPPath::SPPath() : SPShape(), connEndPair(this) {
+SPPath::SPPath()
+ : SPShape()
+ , connEndPair(this)
+ , d_source( SP_STYLE_SRC_UNSET )
+{
}
SPPath::~SPPath() {
}
void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) {
+
/* Are these calls actually necessary? */
this->readAttr( "marker" );
this->readAttr( "marker-start" );
@@ -164,7 +172,6 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) {
/* d is a required attribute */
char const *d = this->getAttribute("d", NULL);
-
if (d == NULL) {
// First see if calculating the path effect will generate "d":
this->update_patheffect(true);
@@ -173,8 +180,11 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) {
// I guess that didn't work, now we have nothing useful to write ("")
if (d == NULL) {
this->setKeyValue( sp_attribute_lookup("d"), "");
+ } else {
+ d_source = SP_STYLE_SRC_ATTRIBUTE;
}
}
+
}
void SPPath::release() {
@@ -275,10 +285,46 @@ g_message("sp_path_write writes 'd' attribute");
}
void SPPath::update(SPCtx *ctx, guint flags) {
+
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore
}
+ // Our code depends on 'd' being an attribute (LPE's, etc.). To support 'd' as a property, we
+ // check it here (after the style property has been evaluated, this allows us to properly
+ // handled precedence of property vs attribute). If we read in a 'd' set by styling, convert it
+ // to an attribute. We'll convert it back on output.
+
+ d_source = style->d.style_src;
+
+ if (style->d.set &&
+
+ (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) {
+
+ // Update curve
+ this->setCurveInsync(curve, TRUE);
+ curve->unref();
+
+ // Convert from property to attribute (convert back on write)
+ getRepr()->setAttribute("d", style->d.value);
+
+ 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 );
+
+ } else {
+ // Do nothing... don't overwrite 'd' from attribute
+ }
+ }
+ }
+
SPShape::update(ctx, flags);
this->connEndPair.update();
@@ -371,7 +417,6 @@ g_message("sp_path_update_patheffect writes 'd' attribute");
}
}
-
/**
* Adds a original_curve to the path. If owner is specified, a reference
* will be made, otherwise the curve will be copied into the path.