diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 2a3142b042d74255b1b5537bd2beadad568a1b0c..1b8f9a11137a0e1e311200c2c00ca7ad97a81145 100644 (file)
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
#include "streq.h"
#include "uri.h"
#include "xml/repr.h"
+#include "style.h"
#define SP_MACROS_SILENT
#include "macros.h"
@@ -141,10 +144,10 @@ static void sp_stop_build(SPObject *object, SPDocument *document, Inkscape::XML:
if (((SPObjectClass *) stop_parent_class)->build)
(* ((SPObjectClass *) stop_parent_class)->build)(object, document, repr);
- sp_object_read_attr(object, "offset");
- sp_object_read_attr(object, "stop-color");
- sp_object_read_attr(object, "stop-opacity");
- sp_object_read_attr(object, "style");
+ object->readAttr( "offset" );
+ object->readAttr( "stop-color" );
+ object->readAttr( "stop-opacity" );
+ object->readAttr( "style" );
}
/**
* stop-color and stop-opacity properties.
*/
{
- gchar const *p = sp_object_get_style_property(object, "stop-color", "black");
+ gchar const *p = object->getStyleProperty( "stop-color", "black");
if (streq(p, "currentColor")) {
stop->currentColor = true;
} else {
- guint32 const color = sp_svg_read_color(p, 0);
- stop->specified_color.set( color );
+ stop->specified_color = SPStop::readStopColor( p );
}
}
{
- gchar const *p = sp_object_get_style_property(object, "stop-opacity", "1");
+ gchar const *p = object->getStyleProperty( "stop-opacity", "1");
gdouble opacity = sp_svg_read_percentage(p, stop->opacity);
stop->opacity = opacity;
}
}
case SP_PROP_STOP_COLOR: {
{
- gchar const *p = sp_object_get_style_property(object, "stop-color", "black");
+ gchar const *p = object->getStyleProperty( "stop-color", "black");
if (streq(p, "currentColor")) {
stop->currentColor = true;
} else {
stop->currentColor = false;
- guint32 const color = sp_svg_read_color(p, 0);
- stop->specified_color.set( color );
+ stop->specified_color = SPStop::readStopColor( p );
}
}
object->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
}
case SP_PROP_STOP_OPACITY: {
{
- gchar const *p = sp_object_get_style_property(object, "stop-opacity", "1");
+ gchar const *p = object->getStyleProperty( "stop-opacity", "1");
gdouble opacity = sp_svg_read_percentage(p, stop->opacity);
stop->opacity = opacity;
}
@@ -232,11 +233,12 @@ sp_stop_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:
repr = xml_doc->createElement("svg:stop");
}
- guint32 specifiedcolor = stop->specified_color.toRGBA32( 255 );
+ Glib::ustring colorStr = stop->specified_color.toString();
gfloat opacity = stop->opacity;
- if (((SPObjectClass *) stop_parent_class)->write)
+ if (((SPObjectClass *) stop_parent_class)->write) {
(* ((SPObjectClass *) stop_parent_class)->write)(object, xml_doc, repr, flags);
+ }
// Since we do a hackish style setting here (because SPStyle does not support stop-color and
// stop-opacity), we must do it AFTER calling the parent write method; otherwise
@@ -247,9 +249,7 @@ sp_stop_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:
if (stop->currentColor) {
os << "currentColor";
} else {
- gchar c[64];
- sp_svg_write_color(c, sizeof(c), specifiedcolor);
- os << c;
+ os << colorStr;
}
os << ";stop-opacity:" << opacity;
repr->setAttribute("style", os.str().c_str());
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;
+ setAttribute( "osb:paint", paintVal, 0 );
+
requestModified( SP_OBJECT_MODIFIED_FLAG );
}
}
* value depends on user agent, and don't give any further restrictions that I can
* see.) */
if (stop->currentColor) {
- char const *str = sp_object_get_style_property(stop, "color", NULL);
+ char const *str = stop->getStyleProperty( "color", NULL);
if (str) {
rgb0 = sp_svg_read_color(str, rgb0);
}
}
}
-/**
- * Return stop's color as SPColor.
- */
-static SPColor
-sp_stop_get_color(SPStop const *const stop)
-{
- if (stop->currentColor) {
- char const *str = sp_object_get_style_property(stop, "color", NULL);
- guint32 const dfl = 0;
- /* Default value: arbitrarily black. (SVG1.1 and CSS2 both say that the initial
- * value depends on user agent, and don't give any further restrictions that I can
- * see.) */
- guint32 color = dfl;
- if (str) {
- color = sp_svg_read_color(str, dfl);
- }
- SPColor ret( color );
- return ret;
- } else {
- return stop->specified_color;
- }
-}
-
/*
* Gradient
*/
@@ -438,24 +410,30 @@ 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 = object->firstChild() ; ochild ; ochild = ochild->getNext() ) {
if (SP_IS_STOP(ochild)) {
gradient->has_stops = TRUE;
break;
}
}
- sp_object_read_attr(object, "gradientUnits");
- sp_object_read_attr(object, "gradientTransform");
- sp_object_read_attr(object, "spreadMethod");
- sp_object_read_attr(object, "xlink:href");
+ object->readAttr( "gradientUnits" );
+ object->readAttr( "gradientTransform" );
+ object->readAttr( "spreadMethod" );
+ object->readAttr( "xlink:href" );
+ object->readAttr( "osb:paint" );
- /* Register ourselves */
- sp_document_add_resource(document, "gradient", object);
+ // Register ourselves
+ document->addResource("gradient", object);
}
/**
SPGradient *gradient = (SPGradient *) object;
#ifdef SP_GRADIENT_VERBOSE
- g_print("Releasing gradient %s\n", SP_OBJECT_ID(object));
+ g_print("Releasing gradient %s\n", object->getId());
#endif
if (SP_OBJECT_DOCUMENT(object)) {
/* Unregister ourselves */
- sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "gradient", SP_OBJECT(object));
+ SP_OBJECT_DOCUMENT(object)->removeResource("gradient", SP_OBJECT(object));
}
if (gradient->ref) {
@@ -553,9 +531,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 ) {
+ gr->setAttribute( "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;
}
}
@@ -602,13 +602,13 @@ void SPGradientImpl::childAdded(SPObject *object, Inkscape::XML::Node *child, In
(* ((SPObjectClass *) gradient_parent_class)->child_added)(object, child, ref);
}
- SPObject *ochild = sp_object_get_child_by_repr(object, child);
+ SPObject *ochild = object->get_child_by_repr(child);
if ( ochild && SP_IS_STOP(ochild) ) {
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");
+ gchar const * attr = gr->getAttribute("osb:paint");
+ if ( attr && strcmp(attr, "gradient") ) {
+ gr->setAttribute( "osb:paint", "gradient", 0 );
}
}
}
}
gr->has_stops = FALSE;
- SPObject *ochild;
- for ( ochild = sp_object_first_child(object) ; ochild ; ochild = SP_OBJECT_NEXT(ochild) ) {
+ for ( SPObject *ochild = object->firstChild() ; ochild ; ochild = ochild->getNext() ) {
if (SP_IS_STOP(ochild)) {
gr->has_stops = TRUE;
break;
}
if ( gr->getStopCount() == 0 ) {
- gchar const * attr = gr->repr->attribute("osb:paint");
- if ( attr && !strcmp(attr, "gradient") ) {
- gr->repr->setAttribute("osb:paint", "solid");
+ gchar const * attr = gr->getAttribute("osb:paint");
+ if ( attr && strcmp(attr, "solid") ) {
+ gr->setAttribute( "osb:paint", "solid", 0 );
}
}
// FIXME: climb up the ladder of hrefs
GSList *l = NULL;
- for (SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ for (SPObject *child = object->firstChild() ; child; child = child->getNext() ) {
g_object_ref(G_OBJECT(child));
l = g_slist_prepend(l, child);
}
SPStop* SPGradient::getFirstStop()
{
SPStop* first = 0;
- for (SPObject *ochild = sp_object_first_child(this); ochild && !first; ochild = SP_OBJECT_NEXT(ochild)) {
+ for (SPObject *ochild = firstChild(); ochild && !first; ochild = ochild->getNext()) {
if (SP_IS_STOP(ochild)) {
first = SP_STOP(ochild);
}
@@ -714,15 +713,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);
+ for (SPObject *child = object->firstChild(); child; child = child->getNext()) {
+ 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 +772,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;
}
g_return_if_fail(gr != NULL);
g_return_if_fail(SP_IS_GRADIENT(gr));
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(gr));
+ Inkscape::XML::Document *xml_doc = SP_OBJECT_DOCUMENT(gr)->getReprDoc();
Inkscape::XML::Node *repr = SP_OBJECT_REPR(gr);
/* We have to be careful, as vector may be our own, so construct repr list at first */
sp_repr_set_css_double(child, "offset", gr->vector.stops[i].offset);
/* strictly speaking, offset an SVG <number> rather than a CSS one, but exponents make no
* sense for offset proportions. */
- gchar c[64];
- sp_svg_write_color(c, sizeof(c), gr->vector.stops[i].color.toRGBA32( 0x00 ));
- os << "stop-color:" << c << ";stop-opacity:" << gr->vector.stops[i].opacity;
+ os << "stop-color:" << gr->vector.stops[i].color.toString() << ";stop-opacity:" << gr->vector.stops[i].opacity;
child->setAttribute("style", os.str().c_str());
/* Order will be reversed here */
cl = g_slist_prepend(cl, child);
void SPGradient::rebuildVector()
{
gint len = 0;
- for ( SPObject *child = sp_object_first_child(SP_OBJECT(this)) ;
- child != NULL ;
- child = SP_OBJECT_NEXT(child) ) {
+ for ( SPObject *child = firstChild() ; child ; child = child->getNext() ) {
if (SP_IS_STOP(child)) {
len ++;
}
}
}
- for (SPObject *child = sp_object_first_child(SP_OBJECT(this)) ;
- child != NULL;
- child = SP_OBJECT_NEXT(child) ) {
+ for ( SPObject *child = firstChild(); child; child = child->getNext() ) {
if (SP_IS_STOP(child)) {
SPStop *stop = SP_STOP(child);
// down to 100%."
gstop.offset = CLAMP(gstop.offset, 0, 1);
- gstop.color = sp_stop_get_color(stop);
+ gstop.color = stop->getEffectiveColor();
gstop.opacity = stop->opacity;
vector.stops.push_back(gstop);
if (((SPObjectClass *) lg_parent_class)->build)
(* ((SPObjectClass *) lg_parent_class)->build)(object, document, repr);
- sp_object_read_attr(object, "x1");
- sp_object_read_attr(object, "y1");
- sp_object_read_attr(object, "x2");
- sp_object_read_attr(object, "y2");
+ object->readAttr( "x1" );
+ object->readAttr( "y1" );
+ object->readAttr( "x2" );
+ object->readAttr( "y2" );
}
/**
@@ -1799,11 +1804,11 @@ sp_radialgradient_build(SPObject *object, SPDocument *document, Inkscape::XML::N
if (((SPObjectClass *) rg_parent_class)->build)
(* ((SPObjectClass *) rg_parent_class)->build)(object, document, repr);
- sp_object_read_attr(object, "cx");
- sp_object_read_attr(object, "cy");
- sp_object_read_attr(object, "r");
- sp_object_read_attr(object, "fx");
- sp_object_read_attr(object, "fy");
+ object->readAttr( "cx" );
+ object->readAttr( "cy" );
+ object->readAttr( "r" );
+ object->readAttr( "fx" );
+ object->readAttr( "fy" );
}
/**
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :