summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9717f57)
raw | patch | inline | side by side (parent: 9717f57)
author | Jon A. Cruz <jon@joncruz.org> | |
Fri, 9 Jul 2010 05:02:03 +0000 (22:02 -0700) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Fri, 9 Jul 2010 05:02:03 +0000 (22:02 -0700) |
diff --git a/src/attributes.cpp b/src/attributes.cpp
index 3cfe04fab9b0bb25f9d7a65e795647bcac9ce36c..c44a7da4e5f19ed106f200a8e4b4b16ea46a0bae 100644 (file)
--- a/src/attributes.cpp
+++ b/src/attributes.cpp
{SP_ATTR_GRADIENTUNITS, "gradientUnits"},
{SP_ATTR_GRADIENTTRANSFORM, "gradientTransform"},
{SP_ATTR_SPREADMETHOD, "spreadMethod"},
+ {SP_ATTR_OSB_SWATCH, "osb:paint"},
/* SPRadialGradient */
{SP_ATTR_FX, "fx"},
{SP_ATTR_FY, "fy"},
diff --git a/src/attributes.h b/src/attributes.h
index c21087e3658e6d119f332f24610c013eb4d5b11f..aadb4d16519f86b957e9ac95934f0bef146228b2 100644 (file)
--- a/src/attributes.h
+++ b/src/attributes.h
SP_ATTR_GRADIENTUNITS,
SP_ATTR_GRADIENTTRANSFORM,
SP_ATTR_SPREADMETHOD,
+ SP_ATTR_OSB_SWATCH,
/* SPRadialGradient */
SP_ATTR_FX,
SP_ATTR_FY,
index 8a199d4a3940adcbbe360a75888346079b348665..974a13b5fe622b74f3626808b38e4acbeba41967 100644 (file)
@@ -1203,11 +1203,13 @@ SPGradient *sp_document_default_gradient_vector( SPDocument *document, SPColor c
Inkscape::XML::Node *repr = xml_doc->createElement("svg:linearGradient");
- repr->setAttribute("inkscape:collect", "always");
- // set here, but removed when it's edited in the gradient editor
- // to further reduce clutter, we could
- // (1) here, search gradients by color and return what is found without duplication
- // (2) in fill & stroke, show only one copy of each gradient in list
+ if ( !singleStop ) {
+ repr->setAttribute("inkscape:collect", "always");
+ // set here, but removed when it's edited in the gradient editor
+ // to further reduce clutter, we could
+ // (1) here, search gradients by color and return what is found without duplication
+ // (2) in fill & stroke, show only one copy of each gradient in list
+ }
Glib::ustring colorStr = color.toString();
addStop( repr, colorStr, 1, "0" );
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 2a3142b042d74255b1b5537bd2beadad568a1b0c..6650406168d35a08cf2094b68f2f55b5f8e327bd 100644 (file)
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
void SPGradient::setSwatch( bool swatch )
{
if ( swatch != isSwatch() ) {
- if ( swatch ) {
- if ( hasStops() && (getStopCount() == 0) ) {
- repr->setAttribute( "osb:paint", "solid" );
- } else {
- repr->setAttribute( "osb:paint", "gradient" );
- }
- } else {
- repr->setAttribute( "osb:paint", 0 );
- }
+ this->swatch = swatch; // to make isSolid() work, this happens first
+ gchar const* paintVal = swatch ? (isSolid() ? "solid" : "gradient") : 0;
+ sp_object_setAttribute( this, "osb:paint", paintVal, 0 );
+
requestModified( SP_OBJECT_MODIFIED_FLAG );
}
}
@@ -438,11 +433,16 @@ void SPGradientImpl::build(SPObject *object, SPDocument *document, Inkscape::XML
{
SPGradient *gradient = SP_GRADIENT(object);
- if (((SPObjectClass *) gradient_parent_class)->build)
+ // Work-around in case a swatch had been marked for immediate collection:
+ if ( repr->attribute("osb:paint") && repr->attribute("inkscape:collect") ) {
+ repr->setAttribute("inkscape:collect", 0);
+ }
+
+ if (((SPObjectClass *) gradient_parent_class)->build) {
(* ((SPObjectClass *) gradient_parent_class)->build)(object, document, repr);
+ }
- SPObject *ochild;
- for ( ochild = sp_object_first_child(object) ; ochild ; ochild = SP_OBJECT_NEXT(ochild) ) {
+ for ( SPObject *ochild = sp_object_first_child(object); ochild; ochild = ochild->next ) {
if (SP_IS_STOP(ochild)) {
gradient->has_stops = TRUE;
break;
@@ -453,6 +453,7 @@ void SPGradientImpl::build(SPObject *object, SPDocument *document, Inkscape::XML
sp_object_read_attr(object, "gradientTransform");
sp_object_read_attr(object, "spreadMethod");
sp_object_read_attr(object, "xlink:href");
+ sp_object_read_attr(object, "osb:paint");
/* Register ourselves */
sp_document_add_resource(document, "gradient", object);
@@ -553,9 +554,31 @@ void SPGradientImpl::setGradientAttr(SPObject *object, unsigned key, gchar const
gr->ref->detach();
}
break;
+ case SP_ATTR_OSB_SWATCH:
+ {
+ bool newVal = (value != 0);
+ bool modified = false;
+ if (newVal != gr->swatch) {
+ gr->swatch = newVal;
+ modified = true;
+ }
+ if (newVal) {
+ // Might need to flip solid/gradient
+ Glib::ustring paintVal = ( gr->hasStops() && (gr->getStopCount() == 0) ) ? "solid" : "gradient";
+ if ( paintVal != value ) {
+ sp_object_setAttribute( gr, "osb:paint", paintVal.c_str(), 0 );
+ modified = true;
+ }
+ }
+ if (modified) {
+ object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+ }
+ break;
default:
- if (((SPObjectClass *) gradient_parent_class)->set)
+ if (((SPObjectClass *) gradient_parent_class)->set) {
((SPObjectClass *) gradient_parent_class)->set(object, key, value);
+ }
break;
}
}
@@ -607,8 +630,8 @@ void SPGradientImpl::childAdded(SPObject *object, Inkscape::XML::Node *child, In
gr->has_stops = TRUE;
if ( gr->getStopCount() > 0 ) {
gchar const * attr = gr->repr->attribute("osb:paint");
- if ( attr && !strcmp(attr, "solid") ) {
- gr->repr->setAttribute("osb:paint", "gradient");
+ if ( attr && strcmp(attr, "gradient") ) {
+ sp_object_setAttribute( gr, "osb:paint", "gradient", 0 );
}
}
}
}
if ( gr->getStopCount() == 0 ) {
+ g_message("Check on remove");
gchar const * attr = gr->repr->attribute("osb:paint");
- if ( attr && !strcmp(attr, "gradient") ) {
- gr->repr->setAttribute("osb:paint", "solid");
+ if ( attr && strcmp(attr, "solid") ) {
+ sp_object_setAttribute( gr, "osb:paint", "solid", 0 );
}
}
@@ -714,15 +738,17 @@ Inkscape::XML::Node *SPGradientImpl::write(SPObject *object, Inkscape::XML::Docu
{
SPGradient *gr = SP_GRADIENT(object);
- if (((SPObjectClass *) gradient_parent_class)->write)
+ if (((SPObjectClass *) gradient_parent_class)->write) {
(* ((SPObjectClass *) gradient_parent_class)->write)(object, xml_doc, repr, flags);
+ }
if (flags & SP_OBJECT_WRITE_BUILD) {
GSList *l = NULL;
for (SPObject *child = sp_object_first_child(object); child; child = SP_OBJECT_NEXT(child)) {
- Inkscape::XML::Node *crepr;
- crepr = child->updateRepr(xml_doc, NULL, flags);
- if (crepr) l = g_slist_prepend(l, crepr);
+ Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags);
+ if (crepr) {
+ l = g_slist_prepend(l, crepr);
+ }
}
while (l) {
repr->addChild((Inkscape::XML::Node *) l->data, NULL);
@@ -771,6 +797,16 @@ Inkscape::XML::Node *SPGradientImpl::write(SPObject *object, Inkscape::XML::Docu
}
}
+ if ( (flags & SP_OBJECT_WRITE_EXT) && gr->isSwatch() ) {
+ if ( gr->isSolid() ) {
+ repr->setAttribute( "osb:paint", "solid" );
+ } else {
+ repr->setAttribute( "osb:paint", "gradient" );
+ }
+ } else {
+ repr->setAttribute( "osb:paint", 0 );
+ }
+
return repr;
}
index 5858f9a0e5c476106c234b06588837efb07322fc..4b5366a46f5749113af6f67668054cb580f33f4b 100644 (file)
--- a/src/sp-paint-server.cpp
+++ b/src/sp-paint-server.cpp
#include "xml/node.h"
static void sp_paint_server_class_init(SPPaintServerClass *psc);
-static void sp_paint_server_init(SPPaintServer *ps);
static void sp_paint_server_release(SPObject *object);
static SPObjectClass *parent_class;
static GSList *stale_painters = NULL;
-GType sp_paint_server_get_type (void)
+GType SPPaintServer::getType(void)
{
static GType type = 0;
if (!type) {
NULL, /* class_data */
sizeof(SPPaintServer),
16, /* n_preallocs */
- (GInstanceInitFunc) sp_paint_server_init,
+ (GInstanceInitFunc) SPPaintServer::init,
NULL, /* value_table */
};
type = g_type_register_static(SP_TYPE_OBJECT, "SPPaintServer", &info, (GTypeFlags) 0);
parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
}
-static void sp_paint_server_init(SPPaintServer *ps)
+void SPPaintServer::init(SPPaintServer *ps)
{
ps->painters = NULL;
+ ps->swatch = false;
}
static void sp_paint_server_release(SPObject *object)
bool SPPaintServer::isSwatch() const
{
- bool swatch = false;
- if (SP_IS_GRADIENT(this)) {
- SPGradient *grad = SP_GRADIENT(this);
- swatch = grad->hasStops() && repr->attribute("osb:paint");
- }
return swatch;
}
bool SPPaintServer::isSolid() const
{
bool solid = false;
- if (SP_IS_GRADIENT(this)) {
+ if (swatch && SP_IS_GRADIENT(this)) {
SPGradient *grad = SP_GRADIENT(this);
if ( grad->hasStops() && (grad->getStopCount() == 0) ) {
- gchar const * attr = repr->attribute("osb:paint");
- if (attr && !strcmp(attr, "solid")) {
- solid = true;
- }
+ solid = true;
}
}
return solid;
diff --git a/src/sp-paint-server.h b/src/sp-paint-server.h
index a76daf4d14643695fc990c7d8284a0dc14c9cf95..dc7bcc9c55e52e6bc93c66c73b88727aac2adabd 100644 (file)
--- a/src/sp-paint-server.h
+++ b/src/sp-paint-server.h
class SPPainter;
-#define SP_TYPE_PAINT_SERVER (sp_paint_server_get_type ())
+#define SP_TYPE_PAINT_SERVER (SPPaintServer::getType())
#define SP_PAINT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_PAINT_SERVER, SPPaintServer))
#define SP_PAINT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_PAINT_SERVER, SPPaintServerClass))
#define SP_IS_PAINT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_PAINT_SERVER))
/** List of paints */
SPPainter *painters;
+protected:
+ bool swatch;
+public:
+
+ static GType getType(void);
+
bool isSwatch() const;
bool isSolid() const;
+
+private:
+ static void init(SPPaintServer *ps);
};
struct SPPaintServerClass {
void (* painter_free) (SPPaintServer *ps, SPPainter *painter);
};
-GType sp_paint_server_get_type (void);
-
SPPainter *sp_paint_server_painter_new (SPPaintServer *ps, Geom::Matrix const &full_transform, Geom::Matrix const &parent_transform, const NRRect *bbox);
SPPainter *sp_painter_free (SPPainter *painter);