diff options
| author | Martin Owens <doctormo@gmail.com> | 2018-10-04 13:00:31 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2018-10-05 22:03:39 +0000 |
| commit | 93bd83b73e292ef37d8c4f03e5a9185f870bb0df (patch) | |
| tree | 8ab42f5a785a01fbe4d700613f655372f26d10b6 /src/object | |
| parent | fix 1795942 "object to path" uses outdated state (diff) | |
| download | inkscape-93bd83b73e292ef37d8c4f03e5a9185f870bb0df.tar.gz inkscape-93bd83b73e292ef37d8c4f03e5a9185f870bb0df.zip | |
Removal of code but breaks gradients
Diffstat (limited to 'src/object')
| -rw-r--r-- | src/object/sp-gradient.cpp | 8 | ||||
| -rw-r--r-- | src/object/sp-mesh-array.cpp | 6 | ||||
| -rw-r--r-- | src/object/sp-object.cpp | 49 | ||||
| -rw-r--r-- | src/object/sp-object.h | 30 | ||||
| -rw-r--r-- | src/object/sp-stop.cpp | 137 | ||||
| -rw-r--r-- | src/object/sp-stop.h | 15 |
6 files changed, 25 insertions, 220 deletions
diff --git a/src/object/sp-gradient.cpp b/src/object/sp-gradient.cpp index e36af38de..d0d50783f 100644 --- a/src/object/sp-gradient.cpp +++ b/src/object/sp-gradient.cpp @@ -128,8 +128,8 @@ bool SPGradient::isEquivalent(SPGradient *that) bool effective = true; while (effective && (as && bs)) { - if (!as->getEffectiveColor().isClose(bs->getEffectiveColor(), 0.001) || - as->offset != bs->offset || as->opacity != bs->opacity ) { + if (!as->getColor().isClose(bs->getColor(), 0.001) || + as->offset != bs->offset || as->getOpacity() != bs->getOpacity() ) { effective = false; break; } @@ -1003,8 +1003,8 @@ void SPGradient::rebuildVector() // down to 100%." gstop.offset = CLAMP(gstop.offset, 0, 1); - gstop.color = stop->getEffectiveColor(); - gstop.opacity = stop->opacity; + gstop.color = stop->getColor(); + gstop.opacity = stop->getOpacity(); vector.stops.push_back(gstop); } diff --git a/src/object/sp-mesh-array.cpp b/src/object/sp-mesh-array.cpp index 4815ec5c1..60bd11940 100644 --- a/src/object/sp-mesh-array.cpp +++ b/src/object/sp-mesh-array.cpp @@ -853,8 +853,8 @@ bool SPMeshNodeArray::read( SPMeshGradient *mg_in ) { if( (istop == 0 && irow == 0 && icolumn > 0) || (istop == 1 && irow > 0 ) ) { // skip } else { - SPColor color = stop->getEffectiveColor(); - double opacity = stop->opacity; + SPColor color = stop->getColor(); + double opacity = stop->getOpacity(); new_patch.setColor( istop, color ); new_patch.setOpacity( istop, opacity ); new_patch.setStopPtr( istop, stop ); @@ -1087,7 +1087,7 @@ static SPColor default_color( SPItem *item ) { if ( SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector() ) { SPStop *firstStop = SP_GRADIENT(server)->getVector()->getFirstStop(); if ( firstStop ) { - color = firstStop->getEffectiveColor(); + color = firstStop->getColor(); } } } diff --git a/src/object/sp-object.cpp b/src/object/sp-object.cpp index 0fc4f0d52..588bdacd0 100644 --- a/src/object/sp-object.cpp +++ b/src/object/sp-object.cpp @@ -1430,55 +1430,6 @@ sp_object_get_unique_id(SPObject *object, return buf; } -// Style - -gchar const * SPObject::getStyleProperty(gchar const *key, gchar const *def) const -{ - //g_return_val_if_fail(object != NULL, NULL); - //g_return_val_if_fail(SP_IS_OBJECT(object), NULL); - g_return_val_if_fail(key != nullptr, NULL); - - //XML Tree being used here. - gchar const *style = getRepr()->attribute("style"); - if (style) { - size_t const len = strlen(key); - char const *p; - while ( (p = strstr(style, key)) - != nullptr ) - { - p += len; - while ((*p <= ' ') && *p) { - p++; - } - if (*p++ != ':') { - break; - } - while ((*p <= ' ') && *p) { - p++; - } - size_t const inherit_len = sizeof("inherit") - 1; - if (*p - && !(strneq(p, "inherit", inherit_len) - && (p[inherit_len] == '\0' - || p[inherit_len] == ';' - || g_ascii_isspace(p[inherit_len])))) { - return p; - } - } - } - - //XML Tree being used here. - gchar const *val = getRepr()->attribute(key); - if (val && !streq(val, "inherit")) { - return val; - } - if (this->parent) { - return (this->parent)->getStyleProperty(key, def); - } - - return def; -} - void SPObject::_requireSVGVersion(Inkscape::Version version) { for ( SPObject::ParentIterator iter=this ; iter ; ++iter ) { SPObject *object = iter; diff --git a/src/object/sp-object.h b/src/object/sp-object.h index b5e59cec5..ca3ddaec5 100644 --- a/src/object/sp-object.h +++ b/src/object/sp-object.h @@ -720,36 +720,6 @@ public: void removeAttribute(char const *key, SPException *ex=nullptr); - /** - * Returns an object style property. - * - * \todo - * fixme: Use proper CSS parsing. The current version is buggy - * in a number of situations where key is a substring of the - * style string other than as a property name (including - * where key is a substring of a property name), and is also - * buggy in its handling of inheritance for properties that - * aren't inherited by default. It also doesn't allow for - * the case where the property is specified but with an invalid - * value (in which case I believe the CSS2 error-handling - * behaviour applies, viz. behave as if the property hadn't - * been specified). Also, the current code doesn't use CRSelEng - * stuff to take a value from stylesheets. Also, we aren't - * setting any hooks to force an update for changes in any of - * the inputs (i.e., in any of the elements that this function - * queries). - * - * \par - * Given that the default value for a property depends on what - * property it is (e.g., whether to inherit or not), and given - * the above comment about ignoring invalid values, and that the - * repr parent isn't necessarily the right element to inherit - * from (e.g., maybe we need to inherit from the referencing - * <use> element instead), we should probably make the caller - * responsible for ascending the repr tree as necessary. - */ - char const *getStyleProperty(char const *key, char const *def) const; - void setCSS(SPCSSAttr *css, char const *attr); void changeCSS(SPCSSAttr *css, char const *attr); diff --git a/src/object/sp-stop.cpp b/src/object/sp-stop.cpp index 197bc519f..c76524b95 100644 --- a/src/object/sp-stop.cpp +++ b/src/object/sp-stop.cpp @@ -24,12 +24,8 @@ #include "svg/css-ostringstream.h" SPStop::SPStop() : SPObject() { - this->path_string = nullptr; - + this->path_string = nullptr; this->offset = 0.0; - this->currentColor = false; - this->specified_color.set( 0x000000ff ); - this->opacity = 1.0; } SPStop::~SPStop() = default; @@ -38,10 +34,8 @@ void SPStop::build(SPDocument* doc, Inkscape::XML::Node* repr) { SPObject::build(doc, repr); this->readAttr( "offset" ); - this->readAttr( "stop-color" ); - this->readAttr( "stop-opacity" ); - this->readAttr( "style" ); this->readAttr( "path" ); // For mesh + SPObject::build(doc, repr); } /** @@ -50,55 +44,6 @@ void SPStop::build(SPDocument* doc, Inkscape::XML::Node* repr) { void SPStop::set(unsigned int key, const gchar* value) { switch (key) { - case SP_ATTR_STYLE: { - /** \todo - * fixme: We are reading simple values 3 times during build (Lauris). - * \par - * We need presentation attributes etc. - * \par - * remove the hackish "style reading" from here: see comments in - * sp_object_get_style_property about the bugs in our current - * approach. However, note that SPStyle doesn't currently have - * stop-color and stop-opacity properties. - */ - { - gchar const *p = this->getStyleProperty( "stop-color", "black"); - if (streq(p, "currentColor")) { - this->currentColor = true; - } else { - this->specified_color = SPStop::readStopColor( p ); - } - } - { - gchar const *p = this->getStyleProperty( "stop-opacity", "1"); - gdouble opacity = sp_svg_read_percentage(p, this->opacity); - this->opacity = opacity; - } - this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - break; - } - case SP_PROP_STOP_COLOR: { - { - gchar const *p = this->getStyleProperty( "stop-color", "black"); - if (streq(p, "currentColor")) { - this->currentColor = true; - } else { - this->currentColor = false; - this->specified_color = SPStop::readStopColor( p ); - } - } - this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - break; - } - case SP_PROP_STOP_OPACITY: { - { - gchar const *p = this->getStyleProperty( "stop-opacity", "1"); - gdouble opacity = sp_svg_read_percentage(p, this->opacity); - this->opacity = opacity; - } - this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); - break; - } case SP_ATTR_OFFSET: { this->offset = sp_svg_read_percentage(value, 0.0); this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); @@ -133,26 +78,7 @@ Inkscape::XML::Node* SPStop::write(Inkscape::XML::Document* xml_doc, Inkscape::X repr = xml_doc->createElement("svg:stop"); } - Glib::ustring colorStr = this->specified_color.toString(); - gfloat opacity = this->opacity; - SPObject::write(xml_doc, repr, flags); - - // Since we do a hackish style setting here (because SPStyle does not support stop-color and - // stop-opacity), we must do it AFTER calling the parent write method; otherwise - // sp_object_write would clear our style= attribute (bug 1695287) - - Inkscape::CSSOStringStream os; - os << "stop-color:"; - if (this->currentColor) { - os << "currentColor"; - } else { - os << colorStr; - } - os << ";stop-opacity:" << opacity; - repr->setAttribute("style", os.str().c_str()); - repr->setAttribute("stop-color", nullptr); - repr->setAttribute("stop-opacity", nullptr); sp_repr_set_css_double(repr, "offset", this->offset); /* strictly speaking, offset an SVG <number> rather than a CSS one, but exponents make no sense * for offset proportions. */ @@ -197,59 +123,28 @@ SPStop* SPStop::getPrevStop() { return result; } -SPColor SPStop::readStopColor(Glib::ustring const &styleStr, guint32 dfl) { - SPColor color(dfl); - SPIPaint paint; - - paint.read( styleStr.c_str() ); - - if ( paint.isColor() ) { - color = paint.value.color; +SPColor SPStop::getColor() const +{ + if (style->stop_color.currentcolor) { + return style->color.value.color; } - - return color; + Glib::ustring color = style->stop_color.value.color.toString(); + g_warning("Getting stop_color: %s", color.c_str()); + return style->stop_color.value.color; } -SPColor SPStop::getEffectiveColor() const { - SPColor ret; - - if (currentColor) { - char const *str = getStyleProperty("color", nullptr); - /* Default value: arbitrarily black. (SVG1.1 and CSS2 both say that the initial - * value depends on user agent, and don't give any further restrictions that I can - * see.) */ - ret = readStopColor( str, 0 ); - } else { - ret = specified_color; - } - - return ret; +gfloat SPStop::getOpacity() const +{ + return SP_SCALE24_TO_FLOAT(style->stop_opacity.value); } /** * Return stop's color as 32bit value. */ -guint32 SPStop::get_rgba32() const { - guint32 rgb0 = 0; - - /* Default value: arbitrarily black. (SVG1.1 and CSS2 both say that the initial - * value depends on user agent, and don't give any further restrictions that I can - * see.) */ - if (this->currentColor) { - char const *str = this->getStyleProperty("color", nullptr); - - if (str) { - rgb0 = sp_svg_read_color(str, rgb0); - } - - unsigned const alpha = static_cast<unsigned>(this->opacity * 0xff + 0.5); - - g_return_val_if_fail((alpha & ~0xff) == 0, rgb0 | 0xff); - - return rgb0 | alpha; - } else { - return this->specified_color.toRGBA32(this->opacity); - } +guint32 SPStop::get_rgba32() const +{ + g_warning("Asking for rgba32!"); + return getColor().toRGBA32(getOpacity()); } /* diff --git a/src/object/sp-stop.h b/src/object/sp-stop.h index a82775b6a..aef7bb180 100644 --- a/src/object/sp-stop.h +++ b/src/object/sp-stop.h @@ -31,25 +31,14 @@ public: bool currentColor; - /** \note - * N.B.\ Meaningless if currentColor is true. Use sp_stop_get_rgba32 or sp_stop_get_color - * (currently static in sp-gradient.cpp) if you want the effective color. - */ - SPColor specified_color; - - /// \todo fixme: Implement SPSVGNumber or something similar. - float opacity; - Glib::ustring * path_string; //SPCurve path; - static SPColor readStopColor( Glib::ustring const &styleStr, guint32 dfl = 0 ); - SPStop* getNextStop(); SPStop* getPrevStop(); - SPColor getEffectiveColor() const; - + SPColor getColor() const; + gfloat getOpacity() const; guint32 get_rgba32() const; protected: |
