summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-03-07 13:47:42 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-03-07 13:47:42 +0000
commit0326e4287a1f6a4f52d9a3998adf8670e25c85da (patch)
treec46729df7d9b1c42222ebda19f688d2aa691aea6 /src
parentRemove unused includes, etc. (diff)
downloadinkscape-0326e4287a1f6a4f52d9a3998adf8670e25c85da.tar.gz
inkscape-0326e4287a1f6a4f52d9a3998adf8670e25c85da.zip
Promote the path 'd' attribute to a property per SVG 2. Try 2.
See e88644b0 for first attempt and for comments.
Diffstat (limited to 'src')
-rw-r--r--src/attributes.cpp5
-rw-r--r--src/attributes.h13
-rw-r--r--src/object/sp-path.cpp36
-rw-r--r--src/object/sp-path.h20
-rw-r--r--src/splivarot.cpp15
-rw-r--r--src/style-internal.cpp4
-rw-r--r--src/style.cpp15
-rw-r--r--src/style.h5
8 files changed, 91 insertions, 22 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..bad843a05 100644
--- a/src/object/sp-path.cpp
+++ b/src/object/sp-path.cpp
@@ -279,6 +279,42 @@ void SPPath::update(SPCtx *ctx, guint flags) {
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 );
+
+ style->d.style_src = SP_STYLE_SRC_ATTRIBUTE;
+ } else {
+ // Do nothing... don't overwrite 'd' from attribute
+ }
+ }
+ }
+
SPShape::update(ctx, flags);
this->connEndPair.update();
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/splivarot.cpp b/src/splivarot.cpp
index cbb51f312..62d67469d 100644
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -1210,9 +1210,13 @@ sp_item_path_outline(SPItem *item, SPDesktop *desktop, bool legacy)
gchar const *opacity;
gchar const *filter;
+ // Copying stroke style to fill will fail for properties not defined by style attribute
+ // (i.e., properties defined in style sheet or by attributes).
+
+ // Stroke
SPCSSAttr *ncss = 0;
{
- ncss = sp_css_attr_from_style(i_style, SP_STYLE_FLAG_ALWAYS);
+ ncss = sp_css_attr_from_style(i_style, SP_STYLE_FLAG_ALWAYS | SP_STYLE_FLAG_IFSRC);
gchar const *s_val = sp_repr_css_property(ncss, "stroke", NULL);
gchar const *s_opac = sp_repr_css_property(ncss, "stroke-opacity", NULL);
opacity = sp_repr_css_property(ncss, "opacity", NULL);
@@ -1231,10 +1235,11 @@ sp_item_path_outline(SPItem *item, SPDesktop *desktop, bool legacy)
sp_repr_css_unset_property(ncss, "marker-mid");
sp_repr_css_unset_property(ncss, "marker-end");
}
- //fill
+
+ // Fill
SPCSSAttr *ncsf = 0;
{
- ncsf = sp_css_attr_from_style(i_style, SP_STYLE_FLAG_ALWAYS);
+ ncsf = sp_css_attr_from_style(i_style, SP_STYLE_FLAG_ALWAYS | SP_STYLE_FLAG_IFSRC);
sp_repr_css_set_property(ncsf, "stroke", "none");
sp_repr_css_set_property(ncsf, "stroke-opacity", "1.0");
sp_repr_css_set_property(ncsf, "filter", NULL);
@@ -1331,7 +1336,6 @@ sp_item_path_outline(SPItem *item, SPDesktop *desktop, bool legacy)
delete theRes;
} else {
-
orig->Outline(res, 0.5 * o_width, o_join, o_butt, 0.5 * o_miter);
orig->Coalesce(0.5 * o_width);
@@ -1520,6 +1524,7 @@ sp_item_path_outline(SPItem *item, SPDesktop *desktop, bool legacy)
markers->setAttribute("clip-path", clip_path);
}
}
+
gchar const *paint_order = sp_repr_css_property(ncss, "paint-order", NULL);
SPIPaintOrder temp;
temp.read( paint_order );
@@ -1622,10 +1627,12 @@ sp_item_path_outline(SPItem *item, SPDesktop *desktop, bool legacy)
} else if(did) {
out = g_repr;
}
+
SPCSSAttr *r_style = sp_repr_css_attr_new();
sp_repr_css_set_property(r_style, "opacity", opacity);
sp_repr_css_set_property(r_style, "filter", filter);
sp_repr_css_change(out, r_style, "style");
+
sp_repr_css_attr_unref(r_style);
if (unique) {
parent->appendChild(out);
diff --git a/src/style-internal.cpp b/src/style-internal.cpp
index ed1c79738..ed2937885 100644
--- a/src/style-internal.cpp
+++ b/src/style-internal.cpp
@@ -59,7 +59,7 @@ using Inkscape::CSSOStringStream;
inline bool should_write( guint const flags, bool set, bool dfp, bool src) {
bool should_write = false;
- if ( ((flags & SP_STYLE_FLAG_ALWAYS)) ||
+ if ( ((flags & SP_STYLE_FLAG_ALWAYS) && src) ||
((flags & SP_STYLE_FLAG_IFSET) && set && src) ||
((flags & SP_STYLE_FLAG_IFDIFF) && set && src && dfp)) {
should_write = true;
@@ -760,14 +760,12 @@ void
SPIEnumBits::read( gchar const *str ) {
if( !str ) return;
- std::cout << "SPIEnumBits: " << name << ": " << str << std::endl;
if( !strcmp(str, "inherit") ) {
set = true;
inherit = true;
} else {
for (unsigned i = 0; enums[i].key; i++) {
if (!strcmp(str, enums[i].key)) {
- std::cout << " found: " << enums[i].key << std::endl;
set = true;
inherit = false;
value += enums[i].value;
diff --git a/src/style.cpp b/src/style.cpp
index 3298cb0c9..8bc1307e3 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;
@@ -1782,13 +1792,14 @@ sp_style_unset_property_attrs(SPObject *o)
/**
* \pre style != NULL.
* \pre flags in {IFSET, ALWAYS}.
+ * Only used by sp_css_attr_from_object() and in splivarot.cpp - sp_item_path_outline().
*/
SPCSSAttr *
sp_css_attr_from_style(SPStyle const *const style, guint const flags)
{
g_return_val_if_fail(style != NULL, NULL);
- g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) ||
- (flags == SP_STYLE_FLAG_ALWAYS) ),
+ g_return_val_if_fail(((flags & SP_STYLE_FLAG_IFSET) ||
+ (flags & SP_STYLE_FLAG_ALWAYS)),
NULL);
Glib::ustring style_str = style->write(flags);
SPCSSAttr *css = sp_repr_css_attr_new();
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 */