diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-02-13 14:48:14 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-02-13 14:48:14 +0000 |
| commit | e88644b0f3481c78a9563dbf9ee6b76ab6674583 (patch) | |
| tree | af55ee50eb2e0183baba5b3a9fad4a69d377ff50 /src | |
| parent | Misc. typos (diff) | |
| download | inkscape-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')
| -rw-r--r-- | src/attributes.cpp | 5 | ||||
| -rw-r--r-- | src/attributes.h | 13 | ||||
| -rw-r--r-- | src/object/sp-path.cpp | 79 | ||||
| -rw-r--r-- | src/object/sp-path.h | 20 | ||||
| -rw-r--r-- | src/style.cpp | 10 | ||||
| -rw-r--r-- | src/style.h | 5 |
6 files changed, 102 insertions, 30 deletions
diff --git a/src/attributes.cpp b/src/attributes.cpp index 6522563af..7a3916f6d 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -138,7 +138,6 @@ static SPStyleProp const props[] = { {SP_ATTR_X, "x"}, {SP_ATTR_Y, "y"}, /* SPPath */ - {SP_ATTR_D, "d"}, {SP_ATTR_INKSCAPE_ORIGINAL_D, "inkscape:original-d"}, /* (Note: XML representation of connectors may change in future.) */ {SP_ATTR_CONNECTOR_TYPE, "inkscape:connector-type"}, @@ -422,6 +421,9 @@ static SPStyleProp const props[] = { /* CSS & SVG Properites */ + /* SVG 2 Attributes promoted to properties */ + {SP_ATTR_D, "d"}, + /* Paint */ {SP_PROP_COLOR, "color"}, {SP_PROP_OPACITY, "opacity"}, @@ -552,6 +554,7 @@ static SPStyleProp const props[] = { /* LivePathEffect */ {SP_PROP_PATH_EFFECT, "effect"}, + }; #define n_attrs (sizeof(props) / sizeof(props[0])) diff --git a/src/attributes.h b/src/attributes.h index a2c1c30f5..cecf2673b 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -20,9 +20,9 @@ unsigned char const *sp_attribute_name(unsigned int id); /** * True iff k is a property in SVG, i.e. something that can be written either in a style attribute - * or as its own XML attribute. + * or as its own XML attribute. This must be kept in sync with SPAttributeEnum. */ -#define SP_ATTRIBUTE_IS_CSS(k) (((k) >= SP_PROP_INKSCAPE_FONT_SPEC) && ((k) <= SP_PROP_TEXT_RENDERING)) +#define SP_ATTRIBUTE_IS_CSS(k) (((k) >= SP_ATTR_D) && ((k) <= SP_PROP_PATH_EFFECT)) /* * Do not change order of attributes and properties. Attribute and @@ -146,7 +146,7 @@ enum SPAttributeEnum { SP_ATTR_X, SP_ATTR_Y, /* SPPath */ - SP_ATTR_D, + // SP_ATTR_D, Promoted to property in SVG 2 SP_ATTR_INKSCAPE_ORIGINAL_D, SP_ATTR_CONNECTOR_TYPE, SP_ATTR_CONNECTOR_CURVATURE, @@ -428,7 +428,12 @@ enum SPAttributeEnum { SP_ATTR_TEXT_EXCLUDE, SP_ATTR_LAYOUT_OPTIONS, - /* CSS & SVG Properties KEEP ORDER */ + /* CSS & SVG Properties KEEP ORDER! + * If first or last property changed, macro at top must be changed! + */ + + /* SVG 2 Attributes promoted to properties */ + SP_ATTR_D, /* Paint */ SP_PROP_COLOR, 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. diff --git a/src/object/sp-path.h b/src/object/sp-path.h index 572fd648d..0530a396a 100644 --- a/src/object/sp-path.h +++ b/src/object/sp-path.h @@ -18,6 +18,7 @@ #include "sp-shape.h" #include "sp-conn-end-pair.h" +#include "style-internal.h" // For SPStyleSrc class SPCurve; @@ -47,19 +48,22 @@ public: // should be made protected public: SPConnEndPair connEndPair; - virtual void build(SPDocument *document, Inkscape::XML::Node *repr); - virtual void release(); - virtual void update(SPCtx* ctx, unsigned int flags); + virtual void build(SPDocument *document, Inkscape::XML::Node *repr); + virtual void release(); + virtual void update(SPCtx* ctx, unsigned int flags); - virtual void set(unsigned int key, char const* value); - virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags); + virtual void set(unsigned int key, char const* value); + virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags); - virtual const char* displayName() const; - virtual char* description() const; - virtual Geom::Affine set_transform(Geom::Affine const &transform); + virtual const char* displayName() const; + virtual char* description() const; + virtual Geom::Affine set_transform(Geom::Affine const &transform); virtual void convert_to_guides() const; virtual void update_patheffect(bool write); + +private: + SPStyleSrc d_source; // Source of 'd' value, saved for output. }; #endif // SEEN_SP_PATH_H diff --git a/src/style.cpp b/src/style.cpp index 3298cb0c9..b3bbcbe45 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -97,6 +97,10 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // font-family // font-specification + + // SVG 2 attributes promoted to properties. (When geometry properties are added, move after font.) + d( "d" ), // SPIString Not inherited! + // Font related properties and 'font' shorthand font_style( "font-style", enum_font_style, SP_CSS_FONT_STYLE_NORMAL ), font_variant( "font-variant", enum_font_variant, SP_CSS_FONT_VARIANT_NORMAL ), @@ -282,6 +286,9 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // This might be too resource hungary... but for now it possible to loop over properties + // SVG 2: Attributes promoted to properties + _properties.push_back( &d ); + // 'color' must be before 'fill', 'stroke', 'text-decoration-color', ... _properties.push_back( &color ); @@ -702,6 +709,9 @@ SPStyle::readIfUnset( gint id, gchar const *val, SPStyleSrc const &source ) { g_return_if_fail(val != NULL); switch (id) { + case SP_ATTR_D: + d.readIfUnset( val, source ); + break; case SP_PROP_INKSCAPE_FONT_SPEC: font_specification.readIfUnset( val, source ); break; diff --git a/src/style.h b/src/style.h index 1b6ee2f47..2556ba2b1 100644 --- a/src/style.h +++ b/src/style.h @@ -91,6 +91,11 @@ public: /* ----------------------- THE PROPERTIES ------------------------- */ /* Match order in style.cpp. */ + /* SVG 2 attributes promoted to properties. */ + + /** Path data */ + SPIString d; + /* Font ---------------------------- */ /** Font style */ |
