summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2018-10-04 13:00:31 +0000
committerMartin Owens <doctormo@gmail.com>2018-10-05 22:03:39 +0000
commit93bd83b73e292ef37d8c4f03e5a9185f870bb0df (patch)
tree8ab42f5a785a01fbe4d700613f655372f26d10b6
parentfix 1795942 "object to path" uses outdated state (diff)
downloadinkscape-93bd83b73e292ef37d8c4f03e5a9185f870bb0df.tar.gz
inkscape-93bd83b73e292ef37d8c4f03e5a9185f870bb0df.zip
Removal of code but breaks gradients
-rw-r--r--src/gradient-drag.cpp7
-rw-r--r--src/object/sp-gradient.cpp8
-rw-r--r--src/object/sp-mesh-array.cpp6
-rw-r--r--src/object/sp-object.cpp49
-rw-r--r--src/object/sp-object.h30
-rw-r--r--src/object/sp-stop.cpp137
-rw-r--r--src/object/sp-stop.h15
-rw-r--r--src/style.cpp10
-rw-r--r--src/style.h4
-rw-r--r--src/ui/tools/tweak-tool.cpp10
-rw-r--r--src/widgets/gradient-vector.cpp10
-rw-r--r--src/widgets/paint-selector.cpp4
12 files changed, 50 insertions, 240 deletions
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index b0d330431..d2762f218 100644
--- a/src/gradient-drag.cpp
+++ b/src/gradient-drag.cpp
@@ -213,12 +213,7 @@ Glib::ustring GrDrag::makeStopSafeColor( gchar const *str, bool &isNull )
SPGradient *vect = grad->getVector();
SPStop *firstStop = (vect) ? vect->getFirstStop() : grad->getFirstStop();
if (firstStop) {
- Glib::ustring stopColorStr;
- if (firstStop->currentColor) {
- stopColorStr = firstStop->getStyleProperty("color", nullptr);
- } else {
- stopColorStr = firstStop->specified_color.toString();
- }
+ Glib::ustring stopColorStr = firstStop->getColor().toString();
if ( !stopColorStr.empty() ) {
colorStr = stopColorStr;
}
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:
diff --git a/src/style.cpp b/src/style.cpp
index 6d86e6a96..4ee979387 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -259,7 +259,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) :
// Unimplemented SVG 1.1: alignment-baseline, clip, clip-path, color-profile, cursor,
// dominant-baseline, flood-color, flood-opacity, font-size-adjust,
// glyph-orientation-horizontal, glyph-orientation-vertical, kerning, lighting-color,
- // pointer-events, stop-color, stop-opacity, unicode-bidi
+ // pointer-events, unicode-bidi
// For enums: property( name, enumeration, default value , inherits = true );
// For scale24: property( name, default value = 0, inherits = true );
@@ -384,7 +384,11 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) :
color_rendering( "color-rendering", enum_color_rendering, SP_CSS_COLOR_RENDERING_AUTO),
image_rendering( "image-rendering", enum_image_rendering, SP_CSS_IMAGE_RENDERING_AUTO),
shape_rendering( "shape-rendering", enum_shape_rendering, SP_CSS_SHAPE_RENDERING_AUTO),
- text_rendering( "text-rendering", enum_text_rendering, SP_CSS_TEXT_RENDERING_AUTO )
+ text_rendering( "text-rendering", enum_text_rendering, SP_CSS_TEXT_RENDERING_AUTO ),
+
+ // Stop color and opacity
+ stop_color("stop-color"),
+ stop_opacity("stop-opacity", SP_SCALE24_MAX)
{
// std::cout << "SPStyle::SPStyle( SPDocument ): Entrance: (" << _count << ")" << std::endl;
// std::cout << " Document: " << (document_in?"present":"null") << std::endl;
@@ -566,7 +570,7 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) {
// if( !(*temp == *this ) ) std::cout << "SPStyle::read: Need to clear" << std::endl;
// delete temp;
- clear(); // FIXME, If this isn't here, gradient editing stops working. Why?
+ clear(); // FIXME, If this isn't here, EVERYTHING stops working! Why?
if (object && object->cloned) {
cloned = true;
diff --git a/src/style.h b/src/style.h
index fd45e02ea..a70b82b26 100644
--- a/src/style.h
+++ b/src/style.h
@@ -268,6 +268,10 @@ public:
/** enable-background, used for defining where filter effects get their background image */
SPIEnum enable_background;
+ /** gradient-stop */
+ SPIColor stop_color;
+ SPIScale24 stop_opacity;
+
/* Rendering hints ----------------------- */
/** hints on how to render: e.g. speed vs. accuracy.
diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp
index 4a4bf6114..4f5834836 100644
--- a/src/ui/tools/tweak-tool.cpp
+++ b/src/ui/tools/tweak-tool.cpp
@@ -837,10 +837,10 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
// so it only affects the ends of this interstop;
// distribute the force between the two endstops so that they
// get all the painting even if they are not touched by the brush
- tweak_color (mode, stop->specified_color.v.c, rgb_goal,
+ tweak_color (mode, stop->getColor().v.c, rgb_goal,
force * (pos_e - offset_l) / (offset_h - offset_l),
do_h, do_s, do_l);
- tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
+ tweak_color(mode, prevStop->getColor().v.c, rgb_goal,
force * (offset_h - pos_e) / (offset_h - offset_l),
do_h, do_s, do_l);
stop->updateRepr();
@@ -850,14 +850,14 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
// wide brush, may affect more than 2 stops,
// paint each stop by the force from the profile curve
if (offset_l <= pos_e && offset_l > pos_e - r) {
- tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
+ tweak_color(mode, prevStop->getColor().v.c, rgb_goal,
force * tweak_profile (fabs (pos_e - offset_l), r),
do_h, do_s, do_l);
child_prev->updateRepr();
}
if (offset_h >= pos_e && offset_h < pos_e + r) {
- tweak_color (mode, stop->specified_color.v.c, rgb_goal,
+ tweak_color (mode, stop->getColor().v.c, rgb_goal,
force * tweak_profile (fabs (pos_e - offset_h), r),
do_h, do_s, do_l);
stop->updateRepr();
@@ -879,7 +879,7 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
for( unsigned j=0; j < array->nodes[i].size(); j+=3 ) {
SPStop *stop = array->nodes[i][j]->stop;
double distance = Geom::L2(Geom::Point(p - array->nodes[i][j]->p));
- tweak_color (mode, stop->specified_color.v.c, rgb_goal,
+ tweak_color (mode, stop->getColor().v.c, rgb_goal,
force * tweak_profile (distance, radius), do_h, do_s, do_l);
stop->updateRepr();
}
diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp
index 91f5ebc77..f748a9841 100644
--- a/src/widgets/gradient-vector.cpp
+++ b/src/widgets/gradient-vector.cpp
@@ -605,7 +605,7 @@ static void sp_grad_edit_combo_box_changed (GtkComboBox * /*widget*/, GtkWidget
SelectedColor *csel = static_cast<SelectedColor*>(g_object_get_data(G_OBJECT(tbl), "cselector"));
// set its color, from the stored array
g_object_set_data(G_OBJECT(tbl), "updating_color", reinterpret_cast<void*>(1));
- csel->setColorAlpha(stop->getEffectiveColor(), stop->opacity);
+ csel->setColorAlpha(stop->getColor(), stop->getOpacity());
g_object_set_data(G_OBJECT(tbl), "updating_color", reinterpret_cast<void*>(0));
GtkWidget *offspin = GTK_WIDGET(g_object_get_data(G_OBJECT(tbl), "offspn"));
GtkWidget *offslide =GTK_WIDGET(g_object_get_data(G_OBJECT(tbl), "offslide"));
@@ -1083,7 +1083,7 @@ static void sp_gradient_vector_widget_load_gradient(GtkWidget *widget, SPGradien
SelectedColor *csel = static_cast<SelectedColor*>(g_object_get_data(G_OBJECT(widget), "cselector"));
g_object_set_data(G_OBJECT(widget), "updating_color", reinterpret_cast<void*>(1));
- csel->setColorAlpha(stop->getEffectiveColor(), stop->opacity);
+ csel->setColorAlpha(stop->getColor(), stop->getOpacity());
g_object_set_data(G_OBJECT(widget), "updating_color", reinterpret_cast<void*>(0));
/* Fill preview */
@@ -1227,8 +1227,10 @@ static void sp_gradient_vector_color_dragged(Inkscape::UI::SelectedColor *select
return;
}
- selected_color->colorAlpha(stop->specified_color, stop->opacity);
- stop->currentColor = false;
+ SPColor color = stop->getColor();
+ gfloat opacity = stop->getOpacity();
+ selected_color->colorAlpha(color, opacity);
+ stop->style->stop_color.currentcolor = false;
blocked = FALSE;
}
diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp
index a3a24470e..f26ebe30f 100644
--- a/src/widgets/paint-selector.cpp
+++ b/src/widgets/paint-selector.cpp
@@ -670,8 +670,8 @@ static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelec
// Gradient can be null if object paint is changed externally (ie. with a color picker tool)
if (gradient)
{
- SPColor color = gradient->getFirstStop()->specified_color;
- float alpha = gradient->getFirstStop()->opacity;
+ SPColor color = gradient->getFirstStop()->getColor();
+ float alpha = gradient->getFirstStop()->getOpacity();
psel->selected_color->setColorAlpha(color, alpha, false);
}
}