From: joncruz Date: Wed, 18 Mar 2009 09:56:47 +0000 (+0000) Subject: Rough code to preserve drag-n-drop of solid gradients. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c3ab7c5b5bbd9557e3b5325104294f16ea87b591;p=inkscape.git Rough code to preserve drag-n-drop of solid gradients. --- diff --git a/src/interface.cpp b/src/interface.cpp index 164b66f33..c162ea6d6 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -40,6 +40,8 @@ #include "widgets/desktop-widget.h" #include "sp-item-group.h" #include "sp-text.h" +#include "sp-gradient-fns.h" +#include "sp-gradient.h" #include "sp-flowtext.h" #include "sp-namedview.h" #include "ui/view/view.h" @@ -1252,9 +1254,30 @@ sp_ui_drag_data_received(GtkWidget *widget, } else if ( color.getType() == eek::ColorDef::NONE ) { colorspec = "none"; } else { - gchar* tmp = g_strdup_printf("#%02x%02x%02x", color.getR(), color.getG(), color.getB()); - colorspec = tmp; - g_free(tmp); + unsigned int r = color.getR(); + unsigned int g = color.getG(); + unsigned int b = color.getB(); + + SPGradient* matches = 0; + const GSList *gradients = sp_document_get_resource_list(doc, "gradient"); + for (const GSList *item = gradients; item; item = item->next) { + SPGradient* grad = SP_GRADIENT(item->data); + if ( color.descr == grad->id ) { + if ( grad->has_stops ) { + matches = grad; + break; + } + } + } + if (matches) { + colorspec = "url(#"; + colorspec += matches->id; + colorspec += ")"; + } else { + gchar* tmp = g_strdup_printf("#%02x%02x%02x", r, g, b); + colorspec = tmp; + g_free(tmp); + } } } } diff --git a/src/widgets/eek-color-def.cpp b/src/widgets/eek-color-def.cpp index fb0eeeb5e..8542e5593 100644 --- a/src/widgets/eek-color-def.cpp +++ b/src/widgets/eek-color-def.cpp @@ -248,6 +248,19 @@ bool ColorDef::fromMIMEData(std::string const & type, char const * data, int len double dbl = strtod(srgb.c_str() + numPos + 3, &endPtr); this->b = static_cast(255 * dbl); } + + size_t pos = xml.find("", pos); + std::string colorTag = xml.substr(pos, endPos); + + size_t namePos = colorTag.find("name="); + if (namePos != std::string::npos) { + char quote = colorTag[namePos + 5]; + endPos = colorTag.find(quote, namePos + 6); + descr = colorTag.substr(namePos + 6, endPos - (namePos + 6)); + } + } changed = true; worked = true; }