summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7739223)
raw | patch | inline | side by side (parent: 7739223)
author | Jon A. Cruz <jon@joncruz.org> | |
Sun, 18 Jul 2010 09:12:32 +0000 (02:12 -0700) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Sun, 18 Jul 2010 09:12:32 +0000 (02:12 -0700) |
src/gradient-drag.cpp | patch | blob | history | |
src/gradient-drag.h | patch | blob | history | |
src/sp-stop.cpp | patch | blob | history | |
src/style.cpp | patch | blob | history |
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index 25309dd614f650d5aa94b129eb623412db25e782..0459cd1451b1998097edce64901907e734888032 100644 (file)
--- a/src/gradient-drag.cpp
+++ b/src/gradient-drag.cpp
}
}
+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) {
// 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;
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 22c0dbfb69cb58db91e5d7feba3872905ee32ca6..8cbe9f3052f51e7e58f96211149f1f81e1631e70 100644 (file)
--- a/src/gradient-drag.h
+++ b/src/gradient-drag.h
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 031c6a3ea8f00060f855c6c928de6ee031fd4061..71f937927b2a3b62c6531b8fd3ea5eb39943abe6 100644 (file)
--- a/src/sp-stop.cpp
+++ b/src/sp-stop.cpp
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 380decc48776b4b3611a19f40b8ae748f83c1226..a4094621f8d9712abc32bf5f7d551f0513b27ee6 100644 (file)
--- a/src/style.cpp
+++ b/src/style.cpp
-#define __SP_STYLE_C__
-
/** @file
* @brief SVG stylesheets implementation.
*/
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;
}
sp_style_clear(style);
- if (object && SP_OBJECT_IS_CLONED(object)) {
+ if (object && object->cloned) {
style->cloned = true;
}
noneSet(0),
value()
{
+ value.color.set( 0 );
value.href = 0;
}