=== modified file 'src/desktop-style.cpp' --- src/desktop-style.cpp 2012-10-04 01:45:44 +0000 +++ src/desktop-style.cpp 2012-10-07 11:58:10 +0000 @@ -34,6 +34,8 @@ #include "sp-flowdiv.h" #include "sp-linear-gradient.h" #include "sp-pattern.h" +#include "sp-gradient.h" +#include "sp-stop.h" #include "sp-radial-gradient.h" #include "sp-textpath.h" #include "sp-tref.h" @@ -42,6 +44,7 @@ #include "libnrtype/font-style-to-pos.h" #include "sp-path.h" #include "event-context.h" +#include "gradient-chemistry.h" #include "desktop-style.h" #include "svg/svg-icc-color.h" @@ -63,6 +66,41 @@ guint32 rgba = SP_RGBA32_F_COMPOSE(color[0], color[1], color[2], color[3]); gchar b[64]; sp_svg_write_color(b, sizeof(b), rgba); + + // Set swatch color + Inkscape::PaintTarget fill_or_stroke = fill ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; + gboolean isSwatch = false; + for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) { + SPItem *item = (SPItem *)i->data; + SPGradient *gradient = getGradient(item, fill_or_stroke); + + if (!gradient || !SP_IS_GRADIENT(gradient)) { + continue; + } + + SPGradient *vector = gradient->getVector(); + if (!vector->isSwatch()) { + continue; + } + + SPStop* stop = vector->getFirstStop(); + if (stop) { + // TODO replace with generic shared code that also handles icc-color + Inkscape::CSSOStringStream os; + gchar c[64]; + sp_svg_write_color(c, sizeof(c), rgba); + Inkscape::CSSOStringStream osalpha; + osalpha << color[3]; + os << "stop-color:" << c << ";stop-opacity:" << osalpha.str().c_str() <<";"; + stop->getRepr()->setAttribute("style", os.str().c_str()); + isSwatch = true; + } + } + + if (isSwatch) { + return; + } + SPCSSAttr *css = sp_repr_css_attr_new(); if (fill) { sp_repr_css_set_property(css, "fill", b);