From 294d8e81765f1327f8507c57f3c80665909edbc4 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 18 Jul 2010 02:12:32 -0700 Subject: [PATCH] Follow-up to complete fix for gradient stops and icc. --- src/gradient-drag.cpp | 77 +++++++++++++++++++++++++++---------------- src/gradient-drag.h | 2 ++ src/sp-stop.cpp | 5 +-- src/style.cpp | 9 +++-- 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 25309dd61..0459cd145 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -176,6 +176,43 @@ gr_drag_style_query (SPStyle *style, int property, gpointer data) } } +Glib::ustring GrDrag::makeStopSafeColor( gchar const *str, bool &isNull ) +{ + Glib::ustring colorStr; + if ( str ) { + isNull = false; + colorStr = str; + Glib::ustring::size_type pos = colorStr.find("url(#"); + if ( pos != Glib::ustring::npos ) { + Glib::ustring targetName = colorStr.substr(pos + 5, colorStr.length() - 6); + const GSList *gradients = sp_document_get_resource_list(desktop->doc(), "gradient"); + for (const GSList *item = gradients; item; item = item->next) { + SPGradient* grad = SP_GRADIENT(item->data); + if ( targetName == grad->getId() ) { + SPGradient *vect = grad->getVector(); + SPStop *firstStop = (vect) ? vect->getFirstStop() : grad->getFirstStop(); + if (firstStop) { + Glib::ustring stopColorStr; + if (firstStop->currentColor) { + stopColorStr = sp_object_get_style_property(firstStop, "color", NULL); + } else { + stopColorStr = firstStop->specified_color.toString(); + } + if ( !stopColorStr.empty() ) { + colorStr = stopColorStr; + } + } + break; + } + } + } + } else { + isNull = true; + } + + return colorStr; +} + bool GrDrag::styleSet( const SPCSSAttr *css ) { if (!selected) { @@ -214,30 +251,10 @@ bool GrDrag::styleSet( const SPCSSAttr *css ) // Make sure the style is allowed for gradient stops. if ( !sp_repr_css_property_is_unset( stop, "stop-color") ) { - Glib::ustring tmp = sp_repr_css_property( stop, "stop-color", "" ); - Glib::ustring::size_type pos = tmp.find("url(#"); - if ( pos != Glib::ustring::npos ) { - Glib::ustring targetName = tmp.substr(pos + 5, tmp.length() - 6); - const GSList *gradients = sp_document_get_resource_list(desktop->doc(), "gradient"); - for (const GSList *item = gradients; item; item = item->next) { - SPGradient* grad = SP_GRADIENT(item->data); - if ( targetName == grad->getId() ) { - SPGradient *vect = grad->getVector(); - SPStop *firstStop = (vect) ? vect->getFirstStop() : grad->getFirstStop(); - if (firstStop) { - Glib::ustring stopColorStr; - if (firstStop->currentColor) { - stopColorStr = sp_object_get_style_property(firstStop, "color", NULL); - } else { - stopColorStr = firstStop->specified_color.toString(); - } - if ( !stopColorStr.empty() ) { - sp_repr_css_set_property( stop, "stop-color", stopColorStr.c_str() ); - } - } - break; - } - } + bool stopIsNull = false; + Glib::ustring tmp = makeStopSafeColor( sp_repr_css_property( stop, "stop-color", "" ), stopIsNull ); + if ( !stopIsNull && !tmp.empty() ) { + sp_repr_css_set_property( stop, "stop-color", tmp.c_str() ); } } @@ -393,14 +410,18 @@ GrDrag::addStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance) bool GrDrag::dropColor(SPItem */*item*/, gchar const *c, Geom::Point p) { + // Note: not sure if a null pointer can come in for the style, but handle that just in case + bool stopIsNull = false; + Glib::ustring toUse = makeStopSafeColor( c, stopIsNull ); + // first, see if we can drop onto one of the existing draggers for (GList *i = draggers; i != NULL; i = i->next) { // for all draggables of dragger GrDragger *d = (GrDragger *) i->data; if (Geom::L2(p - d->point)*desktop->current_zoom() < 5) { SPCSSAttr *stop = sp_repr_css_attr_new (); - sp_repr_css_set_property (stop, "stop-color", c); - sp_repr_css_set_property (stop, "stop-opacity", "1"); + sp_repr_css_set_property( stop, "stop-color", stopIsNull ? 0 : toUse.c_str() ); + sp_repr_css_set_property( stop, "stop-opacity", "1" ); for (GSList *j = d->draggables; j != NULL; j = j->next) { // for all draggables of dragger GrDraggable *draggable = (GrDraggable *) j->data; local_change = true; @@ -423,8 +444,8 @@ GrDrag::dropColor(SPItem */*item*/, gchar const *c, Geom::Point p) SPStop *stop = addStopNearPoint (line->item, p, 5/desktop->current_zoom()); if (stop) { SPCSSAttr *css = sp_repr_css_attr_new (); - sp_repr_css_set_property (css, "stop-color", c); - sp_repr_css_set_property (css, "stop-opacity", "1"); + sp_repr_css_set_property( css, "stop-color", stopIsNull ? 0 : toUse.c_str() ); + sp_repr_css_set_property( css, "stop-opacity", "1" ); sp_repr_css_change (SP_OBJECT_REPR (stop), css, "style"); return true; } diff --git a/src/gradient-drag.h b/src/gradient-drag.h index 22c0dbfb6..8cbe9f305 100644 --- a/src/gradient-drag.h +++ b/src/gradient-drag.h @@ -177,6 +177,8 @@ private: bool styleSet( const SPCSSAttr *css ); + Glib::ustring makeStopSafeColor( gchar const *str, bool &isNull ); + Inkscape::Selection *selection; sigc::connection sel_changed_connection; sigc::connection sel_modified_connection; diff --git a/src/sp-stop.cpp b/src/sp-stop.cpp index 031c6a3ea..71f937927 100644 --- a/src/sp-stop.cpp +++ b/src/sp-stop.cpp @@ -55,12 +55,13 @@ SPStop* SPStop::getPrevStop() SPColor SPStop::readStopColor( Glib::ustring const &styleStr, guint32 dfl ) { SPColor color(dfl); - SPStyle style; + SPStyle* style = sp_style_new(0); SPIPaint paint; - paint.read( styleStr.c_str(), style ); + paint.read( styleStr.c_str(), *style ); if ( paint.isColor() ) { color = paint.value.color; } + sp_style_unref(style); return color; } diff --git a/src/style.cpp b/src/style.cpp index 380decc48..a4094621f 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -1,5 +1,3 @@ -#define __SP_STYLE_C__ - /** @file * @brief SVG stylesheets implementation. */ @@ -487,11 +485,11 @@ sp_style_new_from_object(SPObject *object) g_return_val_if_fail(object != NULL, NULL); g_return_val_if_fail(SP_IS_OBJECT(object), NULL); - SPStyle *style = sp_style_new(SP_OBJECT_DOCUMENT(object)); + SPStyle *style = sp_style_new( object->document ); style->object = object; style->release_connection = object->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_style_object_release), style)); - if (object && SP_OBJECT_IS_CLONED(object)) { + if (object && object->cloned) { style->cloned = true; } @@ -573,7 +571,7 @@ sp_style_read(SPStyle *style, SPObject *object, Inkscape::XML::Node *repr) sp_style_clear(style); - if (object && SP_OBJECT_IS_CLONED(object)) { + if (object && object->cloned) { style->cloned = true; } @@ -4031,6 +4029,7 @@ SPIPaint::SPIPaint() : noneSet(0), value() { + value.color.set( 0 ); value.href = 0; } -- 2.30.2