diff options
| -rw-r--r-- | src/attributes.cpp | 2 | ||||
| -rw-r--r-- | src/attributes.h | 5 | ||||
| -rw-r--r-- | src/live_effects/lpe-copy_rotate.cpp | 3 | ||||
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.cpp | 3 | ||||
| -rw-r--r-- | src/style-internal.cpp | 34 | ||||
| -rw-r--r-- | src/style-internal.h | 58 | ||||
| -rw-r--r-- | src/style.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 6 |
8 files changed, 59 insertions, 54 deletions
diff --git a/src/attributes.cpp b/src/attributes.cpp index 49ec997ec..549dcf8ce 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -561,6 +561,8 @@ static SPStyleProp const props[] = { #define n_attrs (sizeof(props) / sizeof(props[0])) +static_assert(n_attrs == SPAttributeEnum_SIZE, ""); + /** * Inverse to the \c props array for lookup by name. */ diff --git a/src/attributes.h b/src/attributes.h index d1d4c5aa7..2ccbe470b 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -21,7 +21,7 @@ * 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. This must be kept in sync with SPAttributeEnum. */ -#define SP_ATTRIBUTE_IS_CSS(k) (((k) >= SP_ATTR_D) && ((k) <= SP_PROP_PATH_EFFECT)) +#define SP_ATTRIBUTE_IS_CSS(k) (((k) >= SP_ATTR_D) && ((k) < SP_PROP_SYSTEM_LANGUAGE)) /* * Do not change order of attributes and properties. Attribute and @@ -564,6 +564,9 @@ enum SPAttributeEnum : unsigned { /* LivePathEffect */ SP_PROP_PATH_EFFECT, + + // sentinel + SPAttributeEnum_SIZE }; /** diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 2a27eac0c..c9a88650c 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -191,7 +191,8 @@ void LPECopyRotate::cloneStyle(SPObject *orig, SPObject *dest) dest->getRepr()->setAttribute("style", orig->getRepr()->attribute("style")); for (auto iter : orig->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { - if (iter->name() != "font" && iter->name() != "d" && iter->name() != "marker") { + auto key = iter->id(); + if (key != SP_PROP_FONT && key != SP_ATTR_D && key != SP_PROP_MARKER) { const gchar *attr = orig->getRepr()->attribute(iter->name().c_str()); if (attr) { dest->getRepr()->setAttribute(iter->name(), attr); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 0cc749f2b..691cdc653 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -266,7 +266,8 @@ void LPEMirrorSymmetry::cloneStyle(SPObject *orig, SPObject *dest) dest->getRepr()->setAttribute("style", orig->getRepr()->attribute("style")); for (auto iter : orig->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { - if (iter->name() != "font" && iter->name() != "d" && iter->name() != "marker") { + auto key = iter->id(); + if (key != SP_PROP_FONT && key != SP_ATTR_D && key != SP_PROP_MARKER) { const gchar *attr = orig->getRepr()->attribute(iter->name().c_str()); if (attr) { dest->getRepr()->setAttribute(iter->name(), attr); diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 464369d28..5a36291bc 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -54,7 +54,16 @@ using Inkscape::CSSOStringStream; // SPIBase -------------------------------------------------------------- -Glib::ustring const &SPIBase::name() const { return _name; } +Glib::ustring const &SPIBase::name() const +{ + static Glib::ustring names[SPAttributeEnum_SIZE]; + auto &name = names[id()]; + if (name.empty()) { + auto const *namecstr = sp_attribute_name(id()); + name = namecstr ? namecstr : "anonymous"; + } + return name; +} // Standard criteria for writing a property // dfp == different from parent @@ -193,7 +202,7 @@ SPIScale24::merge( const SPIBase* const parent ) { } } else { // Needed only for 'opacity' and 'stop-opacity' which do not inherit. See comment at bottom of file. - if( name() != "opacity" && name() != "stop-opacity" ) + if (id() != SP_PROP_OPACITY && id() != SP_PROP_STOP_OPACITY) std::cerr << "SPIScale24::merge: unhandled property: " << name() << std::endl; if( !set || (!inherit && value == SP_SCALE24_MAX) ) { value = p->value; @@ -288,7 +297,7 @@ SPILength::read( gchar const *str ) { /* Percentage */ unit = SP_CSS_UNIT_PERCENT; value = value * 0.01; - if (name() == "line-height") { + if (id() == SP_PROP_LINE_HEIGHT) { // See: http://www.w3.org/TR/CSS2/visudet.html#propdef-line-height if( style ) { computed = value * style->font_size.computed; @@ -356,7 +365,7 @@ SPILength::cascade( const SPIBase* const parent ) { } else if (unit == SP_CSS_UNIT_EX) { // FIXME: Get x height from libnrtype or pango. computed = value * em * 0.5; - } else if (unit == SP_CSS_UNIT_PERCENT && name() == "line-height") { + } else if (unit == SP_CSS_UNIT_PERCENT && id() == SP_PROP_LINE_HEIGHT) { // Special case computed = value * em; } @@ -1088,13 +1097,13 @@ SPIString::read( gchar const *str ) { inherit = false; Glib::ustring str_temp(str); - if (name() == "d" && style_src == SP_STYLE_SRC_ATTRIBUTE) { + if (id() == SP_ATTR_D && style_src == SP_STYLE_SRC_ATTRIBUTE) { set = false; } - if (name() == "font-family") { + if (id() == SP_PROP_FONT_FAMILY) { // Family names may be quoted in CSS, internally we use unquoted names. css_font_family_unquote( str_temp ); - } else if (name() == "-inkscape-font-specification") { + } else if (id() == SP_PROP_INKSCAPE_FONT_SPEC) { css_unquote( str_temp ); } @@ -1107,11 +1116,11 @@ const Glib::ustring SPIString::get_value() const { if (this->inherit) return Glib::ustring("inherit"); if (!this->value) return Glib::ustring(""); - if (name() == "font-family") { + if (id() == SP_PROP_FONT_FAMILY) { Glib::ustring font_family( this->value ); css_font_family_quote( font_family ); return font_family; - } else if (name() == "-inkscape-font-specification") { + } else if (id() == SP_PROP_INKSCAPE_FONT_SPEC) { Glib::ustring font_spec( this->value ); css_quote( font_spec ); return font_spec; @@ -1244,7 +1253,7 @@ void SPIColor::read( gchar const *str ) { } else if ( !strcmp(str, "currentColor") ) { set = true; currentcolor = true; - if (name() == "color") { + if (id() == SP_PROP_COLOR) { inherit = true; // CSS3 } else { setColor( style->color.value.color ); @@ -1521,11 +1530,10 @@ SPIPaint::reset( bool init ) { } } if( init ) { - if (name() == "fill") { + if (id() == SP_PROP_FILL) { // 'black' is default for 'fill' setColor(0.0, 0.0, 0.0); - } - if (name() == "text-decoration-color") { + } else if (id() == SP_PROP_TEXT_DECORATION_COLOR) { // currentcolor = true; } } diff --git a/src/style-internal.h b/src/style-internal.h index 8975072cd..b8b493d0c 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -126,9 +126,8 @@ class SPIBase { public: - SPIBase( Glib::ustring name="anonymous", bool inherits = true ) - : _name(std::move(name)), - inherits(inherits), + SPIBase() + : inherits(true), set(false), inherit(false), important(false), @@ -136,6 +135,13 @@ public: style(nullptr) {} + // TODO remove name constructor + SPIBase(Glib::ustring const &, bool inherits_ = true) + : SPIBase() + { + inherits = inherits_; + } + virtual ~SPIBase() = default; @@ -201,7 +207,7 @@ public: // Check apples being compared to apples virtual bool operator==(const SPIBase& rhs) { - return (_name == rhs._name); + return id() == rhs.id(); } virtual bool operator!=(const SPIBase& rhs) { @@ -211,9 +217,6 @@ public: virtual SPAttributeEnum id() const { return SP_ATTR_INVALID; } Glib::ustring const &name() const; -private: - Glib::ustring _name; - // To do: make private public: bool inherits : 1; // Property inherits by default from parent. @@ -255,10 +258,7 @@ class SPIFloat : public SPIBase { public: - SPIFloat() - : SPIBase( "anonymous_float" ), - value(0.0) - {} + SPIFloat() = default; SPIFloat( Glib::ustring const &name, float value_default = 0.0 ) : SPIBase( name ), @@ -286,10 +286,10 @@ public: // To do: make private public: - float value; + float value = 0.0; private: - float value_default; + float value_default = 0.0; }; /* @@ -329,8 +329,7 @@ class SPIScale24 : public SPIBase public: SPIScale24() - : SPIBase( "anonymous_scale24" ), - value(0) + : value(0) {} SPIScale24( Glib::ustring const &name, unsigned value = 0, bool inherits = true ) @@ -391,8 +390,7 @@ class SPILength : public SPIBase public: SPILength() - : SPIBase( "anonymous_length" ), - unit(SP_CSS_UNIT_NONE), + : unit(SP_CSS_UNIT_NONE), value(0), computed(0) {} @@ -446,8 +444,7 @@ class SPILengthOrNormal : public SPILength public: SPILengthOrNormal() - : SPILength( "anonymous_length" ), - normal(true) + : normal(true) {} SPILengthOrNormal( Glib::ustring const &name, float value = 0 ) @@ -488,8 +485,7 @@ class SPIFontVariationSettings : public SPIBase public: SPIFontVariationSettings() - : SPIBase( "anonymous_fontvariationsettings" ), - normal(true) + : normal(true) {} SPIFontVariationSettings( Glib::ustring const &name ) @@ -602,10 +598,6 @@ class SPIEnumBits : public SPIEnum { public: - SPIEnumBits() : - SPIEnum( "anonymous_enumbits", nullptr ) - {} - SPIEnumBits( Glib::ustring const &name, SPStyleEnum const *enums, unsigned value = 0, bool inherits = true ) : SPIEnum( name, enums, value, inherits ) {} @@ -690,10 +682,7 @@ class SPIString : public SPIBase { public: - SPIString() - : SPIBase( "anonymous_string" ), - value(nullptr) - {} + SPIString() = default; // TODO probably want to avoid gchar* and c-style strings. SPIString( Glib::ustring const &name, gchar const* value_default_in = nullptr ) @@ -729,8 +718,8 @@ public: // To do: make private, convert value to Glib::ustring public: - gchar *value; - gchar *value_default; + gchar *value = nullptr; + gchar *value_default = nullptr; }; /// Shapes type internal to SPStyle. @@ -761,8 +750,8 @@ class SPIColor : public SPIBase public: SPIColor() - : SPIBase( "anonymous_color" ), - currentcolor(false) { + : currentcolor(false) + { value.color.set(0); } @@ -837,8 +826,7 @@ class SPIPaint : public SPIBase public: SPIPaint() - : SPIBase( "anonymous_paint" ), - paintOrigin( SP_CSS_PAINT_ORIGIN_NORMAL ), + : paintOrigin(SP_CSS_PAINT_ORIGIN_NORMAL), colorSet(false), noneSet(false) { value.href = nullptr; diff --git a/src/style.cpp b/src/style.cpp index 85371dae8..5bb0457fc 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -598,7 +598,7 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) { // font-variant are converted to shorthands in CSS 3 but can still be read as a // non-shorthand for compatibility with older renders, so they should not be in this list. // We could add a flag to SPIBase to avoid string comparison. - if (p->name() != "font" && p->name() != "marker") { + if (p->id() != SP_PROP_FONT && p->id() != SP_PROP_MARKER) { p->readAttribute( repr ); } } diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 99ada4381..048d75d0e 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -831,7 +831,8 @@ void StyleDialog::readStyleElement() if (obj) { for (auto iter : obj->style->properties()) { if (iter->style_src != SP_STYLE_SRC_UNSET) { - if (iter->name() != "font" && iter->name() != "d" && iter->name() != "marker") { + auto key = iter->id(); + if (key != SP_PROP_FONT && key != SP_ATTR_D && key != SP_PROP_MARKER) { const gchar *attr = obj->getRepr()->attribute(iter->name().c_str()); if (attr) { if (!hasattributes) { @@ -1114,7 +1115,8 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u _updating = false; } else if (selector == "attributes") { for (auto iter : obj->style->properties()) { - if (iter->name() != "font" && iter->name() != "d" && iter->name() != "marker") { + auto key = iter->id(); + if (key != SP_PROP_FONT && key != SP_ATTR_D && key != SP_PROP_MARKER) { const gchar *attr = obj->getRepr()->attribute(iter->name().c_str()); if (attr) { _updating = true; |
