From 0c13cd8bc2121c9e2e1850899d4bda2cd85840ca Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 22 Mar 2010 23:35:55 -0700 Subject: [PATCH] Update to reflect "swatch" gradients as being assumed to be shared. --- src/gradient-chemistry.cpp | 9 +++++---- src/widgets/fill-style.cpp | 18 ++++++++++++++---- src/widgets/paint-selector.cpp | 28 ++++++++++++++-------------- src/widgets/paint-selector.h | 3 +-- src/widgets/stroke-style.cpp | 2 +- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index b2e68c345..c95c1b2c5 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -190,7 +190,7 @@ sp_gradient_fork_private_if_necessary(SPGradient *gr, SPGradient *vector, // Check the number of uses of the gradient within this object; // if we are private and there are no other users, - if (SP_OBJECT_HREFCOUNT(gr) <= count_gradient_hrefs(user, gr)) { + if (!vector->isSwatch() && (SP_OBJECT_HREFCOUNT(gr) <= count_gradient_hrefs(user, gr))) { // check vector if ( gr != vector && gr->ref->getObject() != vector ) { /* our href is not the vector, and vector is different from gr; relink */ @@ -1080,10 +1080,11 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_ /* Current fill style is the gradient of the required type */ SPGradient *current = SP_GRADIENT(ps); - //g_print("hrefcount %d count %d\n", SP_OBJECT_HREFCOUNT(ig), count_gradient_hrefs(SP_OBJECT(item), ig)); + //g_message("hrefcount %d count %d\n", SP_OBJECT_HREFCOUNT(current), count_gradient_hrefs(SP_OBJECT(item), current)); - if (SP_OBJECT_HREFCOUNT(current) == 1 || - SP_OBJECT_HREFCOUNT(current) == count_gradient_hrefs(SP_OBJECT(item), current)) { + if (!current->isSwatch() + && (SP_OBJECT_HREFCOUNT(current) == 1 || + SP_OBJECT_HREFCOUNT(current) == count_gradient_hrefs(SP_OBJECT(item), current))) { // current is private and it's either used once, or all its uses are by children of item; // so just change its href to vector diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 57fa22976..3f2018b91 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -124,8 +124,8 @@ static void sp_fill_style_widget_construct( SPWidget *spw, SPPaintSelector */*psel*/ ) { #ifdef SP_FS_VERBOSE - g_print ( "Fill style widget constructed: inkscape %p repr %p\n", - spw->inkscape, spw->repr ); + g_print ( "Fill style widget constructed: inkscape %p\n", + spw->inkscape ); #endif if (spw->inkscape) { sp_fill_style_widget_update (spw); @@ -143,6 +143,9 @@ sp_fill_style_widget_modify_selection( SPWidget *spw, SP_OBJECT_PARENT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG) ) { +#ifdef SP_FS_VERBOSE + g_message("sp_fill_style_widget_modify_selection()"); +#endif sp_fill_style_widget_update (spw); } } @@ -198,7 +201,7 @@ sp_fill_style_widget_update (SPWidget *spw) case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector case QUERY_STYLE_MULTIPLE_SAME: { - SPPaintSelector::Mode pselmode = sp_style_determine_paint_selector_mode(query, true); + SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, true); psel->setMode(pselmode); psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? @@ -208,7 +211,7 @@ sp_fill_style_widget_update (SPWidget *spw) psel->setColorAlpha(query->fill.value.color, SP_SCALE24_TO_FLOAT(query->fill_opacity.value)); } else if (query->fill.set && query->fill.isPaintserver()) { - SPPaintServer *server = SP_STYLE_FILL_SERVER (query); + SPPaintServer *server = query->getFillPaintServer(); if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { SPGradient *vector = SP_GRADIENT(server)->getVector(); @@ -257,6 +260,10 @@ sp_fill_style_widget_paint_mode_changed( SPPaintSelector *psel, if (g_object_get_data (G_OBJECT (spw), "update")) return; +#ifdef SP_FS_VERBOSE + g_message("sp_fill_style_widget_paint_mode_changed(psel:%p, mode, spw:%p)", psel, spw); +#endif + /* TODO: Does this work? */ /* TODO: Not really, here we have to get old color back from object */ /* Instead of relying on paint widget having meaningful colors set */ @@ -346,6 +353,9 @@ static void sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, SPWidget *spw ) { +#ifdef SP_FS_VERBOSE + g_message("sp_fill_style_widget_paint_changed(psel:%p, spw:%p)", psel, spw); +#endif if (g_object_get_data (G_OBJECT (spw), "update")) { return; } diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 6f3fd823e..288764177 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -1137,42 +1137,42 @@ void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_prope sp_repr_css_attr_unref(css); } -SPPaintSelector::Mode sp_style_determine_paint_selector_mode(SPStyle *style, bool isfill) +SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, bool isfill) { - SPPaintSelector::Mode mode = SPPaintSelector::MODE_UNSET; - SPIPaint& target = isfill ? style->fill : style->stroke; + Mode mode = MODE_UNSET; + SPIPaint const & target = isfill ? style.fill : style.stroke; if ( !target.set ) { - mode = SPPaintSelector::MODE_UNSET; + mode = MODE_UNSET; } else if ( target.isPaintserver() ) { - SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style); - + SPPaintServer const *server = isfill ? style.getFillPaintServer() : style.getStrokePaintServer(); #ifdef SP_PS_VERBOSE + g_message("SPPaintSelector::getModeForStyle(%p, %d)", &style, isfill); g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n")); #endif // SP_PS_VERBOSE if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { - mode = SPPaintSelector::MODE_SWATCH; + mode = MODE_SWATCH; } else if (SP_IS_LINEARGRADIENT(server)) { - mode = SPPaintSelector::MODE_GRADIENT_LINEAR; + mode = MODE_GRADIENT_LINEAR; } else if (SP_IS_RADIALGRADIENT(server)) { - mode = SPPaintSelector::MODE_GRADIENT_RADIAL; + mode = MODE_GRADIENT_RADIAL; } else if (SP_IS_PATTERN(server)) { - mode = SPPaintSelector::MODE_PATTERN; + mode = MODE_PATTERN; } else { g_warning( "file %s: line %d: Unknown paintserver", __FILE__, __LINE__ ); - mode = SPPaintSelector::MODE_NONE; + mode = MODE_NONE; } } else if ( target.isColor() ) { // TODO this is no longer a valid assertion: - mode = SPPaintSelector::MODE_COLOR_RGB; // so far only rgb can be read from svg + mode = MODE_COLOR_RGB; // so far only rgb can be read from svg } else if ( target.isNone() ) { - mode = SPPaintSelector::MODE_NONE; + mode = MODE_NONE; } else { g_warning( "file %s: line %d: Unknown paint type", __FILE__, __LINE__ ); - mode = SPPaintSelector::MODE_NONE; + mode = MODE_NONE; } return mode; diff --git a/src/widgets/paint-selector.h b/src/widgets/paint-selector.h index 63b8f733e..a3c4cb973 100644 --- a/src/widgets/paint-selector.h +++ b/src/widgets/paint-selector.h @@ -75,6 +75,7 @@ struct SPPaintSelector { SPColor color; float alpha; + static Mode getModeForStyle(SPStyle const & style, bool isfill); void setMode( Mode mode ); void setFillrule( FillRule fillrule ); @@ -117,8 +118,6 @@ GtkWidget *sp_paint_selector_new (bool is_fill); -SPPaintSelector::Mode sp_style_determine_paint_selector_mode(SPStyle *style, bool isfill); - #endif // SEEN_SP_PAINT_SELECTOR_H /* diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index edf42f30b..ddd1c92d3 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -197,7 +197,7 @@ sp_stroke_style_paint_update (SPWidget *spw) case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector case QUERY_STYLE_MULTIPLE_SAME: { - SPPaintSelector::Mode pselmode = sp_style_determine_paint_selector_mode (query, false); + SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, false); psel->setMode(pselmode); if (query->stroke.set && query->stroke.isPaintserver()) { -- 2.30.2