summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 16913de)
raw | patch | inline | side by side (parent: 16913de)
author | Jon A. Cruz <jon@joncruz.org> | |
Mon, 28 Jun 2010 03:16:09 +0000 (20:16 -0700) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Mon, 28 Jun 2010 03:16:09 +0000 (20:16 -0700) |
17 files changed:
diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp
index cf3c7243299f20fcb814acf9b089cec25058f92d..28d1db9a4abbe185a39f631eb27823cc381d266b 100644 (file)
@@ -1120,11 +1120,11 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain
SPLinearGradient *lg=SP_LINEARGRADIENT(paintserver);
- sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built
+ SP_GRADIENT(lg)->ensureVector(); // when exporting from commandline, vector is not built
Geom::Point p1 (lg->x1.computed, lg->y1.computed);
Geom::Point p2 (lg->x2.computed, lg->y2.computed);
- if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ if (pbox && SP_GRADIENT(lg)->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
// convert to userspace
Geom::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);
p1 *= bbox2user;
@@ -1144,12 +1144,12 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain
SPRadialGradient *rg=SP_RADIALGRADIENT(paintserver);
- sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built
+ SP_GRADIENT(rg)->ensureVector(); // when exporting from commandline, vector is not built
Geom::Point c (rg->cx.computed, rg->cy.computed);
Geom::Point f (rg->fx.computed, rg->fy.computed);
double r = rg->r.computed;
- if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX)
+ if (pbox && SP_GRADIENT(rg)->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX)
apply_bbox2user = true;
// create radial gradient pattern
@@ -1172,7 +1172,7 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain
SPGradient *g = SP_GRADIENT(paintserver);
// set extend type
- SPGradientSpread spread = sp_gradient_get_spread(g);
+ SPGradientSpread spread = g->fetchSpread();
switch (spread) {
case SP_GRADIENT_SPREAD_REPEAT: {
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
index c95c1b2c5228ec25da0311d503d0c2f826a70964..979b53f1b9a1babf0f434646b176587bf90b6c41 100644 (file)
}
/* First make sure we have vector directly defined (i.e. gr has its own stops) */
- if (!gr->has_stops) {
+ if ( !gr->hasStops() ) {
/* We do not have stops ourselves, so flatten stops as well */
- sp_gradient_ensure_vector(gr);
+ gr->ensureVector();
g_assert(gr->vector.built);
// this adds stops from gr->vector as children to gr
sp_gradient_repr_write_vector (gr);
g_return_val_if_fail(document != NULL, NULL);
g_return_val_if_fail(vector != NULL, NULL);
g_return_val_if_fail(SP_IS_GRADIENT(vector), NULL);
- g_return_val_if_fail(SP_GRADIENT_HAS_STOPS(vector), NULL);
+ g_return_val_if_fail(vector->hasStops(), NULL);
SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
// Orphaned gradient, no vector with stops at the end of the line; this used to be an assert
// but i think we should not abort on this - maybe just write a validity warning into some sort
// of log
- if (!vector || !SP_GRADIENT_HAS_STOPS(vector))
+ if ( !vector || !vector->hasStops() ) {
return (gr);
+ }
// user is the object that uses this gradient; normally it's item but for tspans, we
// check its ancestor text so that tspans don't get different gradients from their
SPDocument *doc = SP_OBJECT_DOCUMENT(gr);
SPObject *defs = SP_DOCUMENT_DEFS(doc);
- if ((gr->has_stops) ||
+ if ((gr->hasStops()) ||
(gr->state != SP_GRADIENT_STATE_UNKNOWN) ||
(SP_OBJECT_PARENT(gr) != SP_OBJECT(defs)) ||
(SP_OBJECT_HREFCOUNT(gr) > 1)) {
@@ -339,7 +340,7 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
gr = sp_gradient_fork_private_if_necessary(gr, gr->getVector(),
SP_IS_RADIALGRADIENT(gr) ? SP_GRADIENT_TYPE_RADIAL : SP_GRADIENT_TYPE_LINEAR, SP_OBJECT(item));
- if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
Inkscape::XML::Node *repr = SP_OBJECT_REPR(gr);
@@ -817,7 +818,7 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, Geom
// using X-coordinates only to determine the offset, assuming p has been snapped to the vector from begin to end.
double offset = get_offset_between_points (p, Geom::Point(lg->x1.computed, lg->y1.computed), Geom::Point(lg->x2.computed, lg->y2.computed));
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (lg, false);
- sp_gradient_ensure_vector(lg);
+ lg->ensureVector();
lg->vector.stops.at(point_i).offset = offset;
SPStop* stopi = sp_get_stop_i(vector, point_i);
stopi->offset = offset;
@@ -911,7 +912,7 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, Geom
Geom::Point end = Geom::Point (rg->cx.computed + rg->r.computed, rg->cy.computed);
double offset = get_offset_between_points (p, start, end);
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (rg, false);
- sp_gradient_ensure_vector(rg);
+ rg->ensureVector();
rg->vector.stops.at(point_i).offset = offset;
SPStop* stopi = sp_get_stop_i(vector, point_i);
stopi->offset = offset;
@@ -927,7 +928,7 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, Geom
Geom::Point end = Geom::Point (rg->cx.computed, rg->cy.computed - rg->r.computed);
double offset = get_offset_between_points (p, start, end);
SPGradient *vector = sp_gradient_get_forked_vector_if_necessary(rg, false);
- sp_gradient_ensure_vector(rg);
+ rg->ensureVector();
rg->vector.stops.at(point_i).offset = offset;
SPStop* stopi = sp_get_stop_i(vector, point_i);
stopi->offset = offset;
SPGradientSpread
sp_item_gradient_get_spread (SPItem *item, bool fill_or_stroke)
{
+ SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD;
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
- if (gradient)
- return sp_gradient_get_spread (gradient);
- return SP_GRADIENT_SPREAD_PAD;
+ if (gradient) {
+ spread = gradient->fetchSpread();
+ }
+ return spread;
}
@@ -1036,7 +1039,7 @@ sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool
}
}
- if (SP_GRADIENT(gradient)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ if (SP_GRADIENT(gradient)->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
Geom::OptRect bbox = item->getBounds(Geom::identity()); // we need "true" bbox without item_i2d_affine
if (bbox) {
index ddb153ffd927477a88fcb42505f8f362d18924f0..6d6ea87617f2780e36397b4ad776826ec498cd34 100644 (file)
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
if (SP_IS_GRADIENT (parent)) {
doc = SP_OBJECT_DOCUMENT (parent);
sp_vector_add_stop (SP_GRADIENT (parent), this_stop, next_stop, offset);
- sp_gradient_ensure_vector (SP_GRADIENT (parent));
+ SP_GRADIENT(parent)->ensureVector();
}
}
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index 11de93d680290f5fc9bc7a2cf3fc4c9443fc2a1e..227a5f0033cb4cacbceff49fa65d52c17e9064b3 100644 (file)
--- a/src/gradient-drag.cpp
+++ b/src/gradient-drag.cpp
SPStop *newstop = sp_vector_add_stop (vector, prev_stop, next_stop, offset);
- sp_gradient_ensure_vector (gradient);
+ gradient->ensureVector();
updateDraggers();
return newstop;
diff --git a/src/interface.cpp b/src/interface.cpp
index 47563238a50dde69c30937847ec8dd22cb252c67..b33443d1bd9e756cf1cb3a1869a39906c8eeca41 100644 (file)
--- a/src/interface.cpp
+++ b/src/interface.cpp
for (const GSList *item = gradients; item; item = item->next) {
SPGradient* grad = SP_GRADIENT(item->data);
if ( color.descr == grad->getId() ) {
- if ( grad->has_stops ) {
+ if ( grad->hasStops() ) {
matches = grad;
break;
}
diff --git a/src/sp-gradient-fns.h b/src/sp-gradient-fns.h
index dafa1646f4eeaad8e2d05d539cd4468dec41f2ad..aabc3eda7f487fb28ff38df02f73e173e10e5b53 100644 (file)
--- a/src/sp-gradient-fns.h
+++ b/src/sp-gradient-fns.h
class SPGradient;
-#define SP_GRADIENT_STATE_IS_SET(g) (SP_GRADIENT(g)->state != SP_GRADIENT_STATE_UNKNOWN)
-#define SP_GRADIENT_IS_VECTOR(g) (SP_GRADIENT(g)->state == SP_GRADIENT_STATE_VECTOR)
-#define SP_GRADIENT_IS_PRIVATE(g) (SP_GRADIENT(g)->state == SP_GRADIENT_STATE_PRIVATE)
-#define SP_GRADIENT_HAS_STOPS(g) (SP_GRADIENT(g)->has_stops)
-#define SP_GRADIENT_SPREAD(g) (SP_GRADIENT(g)->spread)
-#define SP_GRADIENT_UNITS(g) (SP_GRADIENT(g)->units)
-
-/** Forces vector to be built, if not present (i.e. changed) */
-void sp_gradient_ensure_vector(SPGradient *gradient);
-
-/** Ensures that color array is populated */
-void sp_gradient_ensure_colors(SPGradient *gradient);
-
-void sp_gradient_set_units(SPGradient *gr, SPGradientUnits units);
-void sp_gradient_set_spread(SPGradient *gr, SPGradientSpread spread);
-
SPGradientSpread sp_gradient_get_spread (SPGradient *gradient);
/* Gradient repr methods */
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 3d4d6967297de350fc3f5cb3d2925a182f5d522b..0c0c947840aa148f86a2c3049dbf83e13a48c56f 100644 (file)
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
-#define __SP_GRADIENT_C__
-
/** \file
* SPGradient, SPStop, SPLinearGradient, SPRadialGradient.
*/
#include "svg/css-ostringstream.h"
#include "attributes.h"
#include "document-private.h"
+#include "sp-gradient.h"
#include "gradient-chemistry.h"
#include "sp-gradient-reference.h"
#include "sp-linear-gradient.h"
static SPObjectClass *stop_parent_class;
+class SPGradientImpl
+{
+ friend class SPGradient;
+
+ static void classInit(SPGradientClass *klass);
+
+ static void init(SPGradient *gr);
+ static void build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
+ static void release(SPObject *object);
+ static void modified(SPObject *object, guint flags);
+ static Inkscape::XML::Node *write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
+
+ static void gradientRefModified(SPObject *href, guint flags, SPGradient *gradient);
+ static void gradientRefChanged(SPObject *old_ref, SPObject *ref, SPGradient *gr);
+
+ static void childAdded(SPObject *object,
+ Inkscape::XML::Node *child,
+ Inkscape::XML::Node *ref);
+ static void removeChild(SPObject *object, Inkscape::XML::Node *child);
+
+ static void setGradientAttr(SPObject *object, unsigned key, gchar const *value);
+};
+
/**
* Registers SPStop class and returns its type.
*/
@@ -240,6 +262,32 @@ sp_stop_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:
return repr;
}
+
+bool SPGradient::hasStops() const
+{
+ return has_stops;
+}
+
+bool SPGradient::isUnitsSet() const
+{
+ return units_set;
+}
+
+SPGradientUnits SPGradient::getUnits() const
+{
+ return units;
+}
+
+bool SPGradient::isSpreadSet() const
+{
+ return spread_set;
+}
+
+SPGradientSpread SPGradient::getSpread() const
+{
+ return spread;
+}
+
/**
* Return stop's color as 32bit value.
*/
* Gradient
*/
-static void sp_gradient_class_init(SPGradientClass *klass);
-static void sp_gradient_init(SPGradient *gr);
-
-static void sp_gradient_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
-static void sp_gradient_release(SPObject *object);
-static void sp_gradient_set(SPObject *object, unsigned key, gchar const *value);
-static void sp_gradient_child_added(SPObject *object,
- Inkscape::XML::Node *child,
- Inkscape::XML::Node *ref);
-static void sp_gradient_remove_child(SPObject *object, Inkscape::XML::Node *child);
-static void sp_gradient_modified(SPObject *object, guint flags);
-static Inkscape::XML::Node *sp_gradient_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr,
- guint flags);
-
-static void gradient_ref_modified(SPObject *href, guint flags, SPGradient *gradient);
-
-static bool sp_gradient_invalidate_vector(SPGradient *gr);
-static void sp_gradient_rebuild_vector(SPGradient *gr);
-
-static void gradient_ref_changed(SPObject *old_ref, SPObject *ref, SPGradient *gradient);
-
-SPGradientSpread sp_gradient_get_spread(SPGradient *gradient);
-SPGradientUnits sp_gradient_get_units(SPGradient *gradient);
-
static SPPaintServerClass *gradient_parent_class;
/**
* Registers SPGradient class and returns its type.
*/
-GType
-sp_gradient_get_type()
+GType SPGradient::getType()
{
static GType gradient_type = 0;
if (!gradient_type) {
GTypeInfo gradient_info = {
sizeof(SPGradientClass),
NULL, NULL,
- (GClassInitFunc) sp_gradient_class_init,
+ (GClassInitFunc) SPGradientImpl::classInit,
NULL, NULL,
sizeof(SPGradient),
16,
- (GInstanceInitFunc) sp_gradient_init,
+ (GInstanceInitFunc) SPGradientImpl::init,
NULL, /* value_table */
};
gradient_type = g_type_register_static(SP_TYPE_PAINT_SERVER, "SPGradient",
/**
* SPGradient vtable initialization.
*/
-static void
-sp_gradient_class_init(SPGradientClass *klass)
+void SPGradientImpl::classInit(SPGradientClass *klass)
{
SPObjectClass *sp_object_class = (SPObjectClass *) klass;
gradient_parent_class = (SPPaintServerClass *)g_type_class_ref(SP_TYPE_PAINT_SERVER);
- sp_object_class->build = sp_gradient_build;
- sp_object_class->release = sp_gradient_release;
- sp_object_class->set = sp_gradient_set;
- sp_object_class->child_added = sp_gradient_child_added;
- sp_object_class->remove_child = sp_gradient_remove_child;
- sp_object_class->modified = sp_gradient_modified;
- sp_object_class->write = sp_gradient_write;
+ sp_object_class->build = SPGradientImpl::build;
+ sp_object_class->release = SPGradientImpl::release;
+ sp_object_class->set = SPGradientImpl::setGradientAttr;
+ sp_object_class->child_added = SPGradientImpl::childAdded;
+ sp_object_class->remove_child = SPGradientImpl::removeChild;
+ sp_object_class->modified = SPGradientImpl::modified;
+ sp_object_class->write = SPGradientImpl::write;
}
/**
* Callback for SPGradient object initialization.
*/
-static void
-sp_gradient_init(SPGradient *gr)
+void SPGradientImpl::init(SPGradient *gr)
{
gr->ref = new SPGradientReference(SP_OBJECT(gr));
- gr->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(gradient_ref_changed), gr));
+ gr->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(SPGradientImpl::gradientRefChanged), gr));
/** \todo
* Fixme: reprs being rearranged (e.g. via the XML editor)
/**
* Virtual build: set gradient attributes from its associated repr.
*/
-static void
-sp_gradient_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
+void SPGradientImpl::build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
{
SPGradient *gradient = SP_GRADIENT(object);
@@ -425,8 +445,7 @@ sp_gradient_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *r
/**
* Virtual release of SPGradient members before destruction.
*/
-static void
-sp_gradient_release(SPObject *object)
+void SPGradientImpl::release(SPObject *object)
{
SPGradient *gradient = (SPGradient *) object;
/**
* Set gradient attribute to value.
*/
-static void
-sp_gradient_set(SPObject *object, unsigned key, gchar const *value)
+void SPGradientImpl::setGradientAttr(SPObject *object, unsigned key, gchar const *value)
{
SPGradient *gr = SP_GRADIENT(object);
/**
* Gets called when the gradient is (re)attached to another gradient.
*/
-static void
-gradient_ref_changed(SPObject *old_ref, SPObject *ref, SPGradient *gr)
+void SPGradientImpl::gradientRefChanged(SPObject *old_ref, SPObject *ref, SPGradient *gr)
{
if (old_ref) {
gr->modified_connection.disconnect();
if ( SP_IS_GRADIENT(ref)
&& ref != gr )
{
- gr->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&gradient_ref_modified), gr));
+ gr->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&SPGradientImpl::gradientRefModified), gr));
}
// Per SVG, all unset attributes must be inherited from linked gradient.
// So, as we're now (re)linked, we assign linkee's values to this gradient if they are not yet set -
// but without setting the _set flags.
// FIXME: do the same for gradientTransform too
- if (!gr->units_set)
- gr->units = sp_gradient_get_units (gr);
- if (!gr->spread_set)
- gr->spread = sp_gradient_get_spread (gr);
+ if (!gr->units_set) {
+ gr->units = gr->fetchUnits();
+ }
+ if (!gr->spread_set) {
+ gr->spread = gr->fetchSpread();
+ }
/// \todo Fixme: what should the flags (second) argument be? */
- gradient_ref_modified(ref, 0, gr);
+ gradientRefModified(ref, 0, gr);
}
/**
* Callback for child_added event.
*/
-static void
-sp_gradient_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
+void SPGradientImpl::childAdded(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
{
SPGradient *gr = SP_GRADIENT(object);
- sp_gradient_invalidate_vector(gr);
+ gr->invalidateVector();
if (((SPObjectClass *) gradient_parent_class)->child_added)
(* ((SPObjectClass *) gradient_parent_class)->child_added)(object, child, ref);
@@ -579,15 +597,15 @@ sp_gradient_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::
/**
* Callback for remove_child event.
*/
-static void
-sp_gradient_remove_child(SPObject *object, Inkscape::XML::Node *child)
+void SPGradientImpl::removeChild(SPObject *object, Inkscape::XML::Node *child)
{
SPGradient *gr = SP_GRADIENT(object);
- sp_gradient_invalidate_vector(gr);
+ gr->invalidateVector();
- if (((SPObjectClass *) gradient_parent_class)->remove_child)
+ if (((SPObjectClass *) gradient_parent_class)->remove_child) {
(* ((SPObjectClass *) gradient_parent_class)->remove_child)(object, child);
+ }
gr->has_stops = FALSE;
SPObject *ochild;
/**
* Callback for modified event.
*/
-static void
-sp_gradient_modified(SPObject *object, guint flags)
+void SPGradientImpl::modified(SPObject *object, guint flags)
{
SPGradient *gr = SP_GRADIENT(object);
if (flags & SP_OBJECT_CHILD_MODIFIED_FLAG) {
- sp_gradient_invalidate_vector(gr);
+ gr->invalidateVector();
}
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
- sp_gradient_ensure_colors(gr);
+ gr->ensureColors();
}
if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
/**
* Write gradient attributes to repr.
*/
-static Inkscape::XML::Node *
-sp_gradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
+Inkscape::XML::Node *SPGradientImpl::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
SPGradient *gr = SP_GRADIENT(object);
@@ -710,7 +726,7 @@ sp_gradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::
if ((flags & SP_OBJECT_WRITE_ALL) || gr->spread_set) {
/* FIXME: Ensure that gr->spread is the inherited value
- * if !gr->spread_set. Not currently happening: see sp_gradient_modified.
+ * if !gr->spread_set. Not currently happening: see SPGradient::modified.
*/
switch (gr->spread) {
case SP_GRADIENT_SPREAD_REFLECT:
@@ -733,40 +749,34 @@ sp_gradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::
*
* \pre SP_IS_GRADIENT(gradient).
*/
-void
-sp_gradient_ensure_vector(SPGradient *gradient)
+void SPGradient::ensureVector()
{
- g_return_if_fail(gradient != NULL);
- g_return_if_fail(SP_IS_GRADIENT(gradient));
-
- if (!gradient->vector.built) {
- sp_gradient_rebuild_vector(gradient);
+ if ( !vector.built ) {
+ rebuildVector();
}
}
/**
* Set units property of gradient and emit modified.
*/
-void
-sp_gradient_set_units(SPGradient *gr, SPGradientUnits units)
+void SPGradient::setUnits(SPGradientUnits units)
{
- if (units != gr->units) {
- gr->units = units;
- gr->units_set = TRUE;
- SP_OBJECT(gr)->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ if (units != this->units) {
+ this->units = units;
+ units_set = TRUE;
+ requestModified(SP_OBJECT_MODIFIED_FLAG);
}
}
/**
* Set spread property of gradient and emit modified.
*/
-void
-sp_gradient_set_spread(SPGradient *gr, SPGradientSpread spread)
+void SPGradient::setSpread(SPGradientSpread spread)
{
- if (spread != gr->spread) {
- gr->spread = spread;
- gr->spread_set = TRUE;
- SP_OBJECT(gr)->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ if (spread != this->spread) {
+ this->spread = spread;
+ spread_set = TRUE;
+ requestModified(SP_OBJECT_MODIFIED_FLAG);
}
}
*/
static bool has_stopsFN(SPGradient const *gr)
{
- return SP_GRADIENT_HAS_STOPS(gr);
+ return gr->hasStops();
}
/**
* True if gradient has spread set.
*/
-static bool
-has_spread_set(SPGradient const *gr)
+static bool has_spread_set(SPGradient const *gr)
{
- return gr->spread_set;
+ return gr->isSpreadSet();
}
/**
static bool
has_units_set(SPGradient const *gr)
{
- return gr->units_set;
+ return gr->isUnitsSet();
}
*
* \pre SP_IS_GRADIENT(gradient).
*/
-SPGradientSpread
-sp_gradient_get_spread(SPGradient *gradient)
+SPGradientSpread SPGradient::fetchSpread()
{
- g_return_val_if_fail(SP_IS_GRADIENT(gradient), SP_GRADIENT_SPREAD_PAD);
-
- SPGradient const *src = chase_hrefs(gradient, has_spread_set);
+ SPGradient const *src = chase_hrefs(this, has_spread_set);
return ( src
? src->spread
: SP_GRADIENT_SPREAD_PAD ); // pad is the default
*
* \pre SP_IS_GRADIENT(gradient).
*/
-SPGradientUnits
-sp_gradient_get_units(SPGradient *gradient)
+SPGradientUnits SPGradient::fetchUnits()
{
- g_return_val_if_fail(SP_IS_GRADIENT(gradient), SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX);
-
- SPGradient const *src = chase_hrefs(gradient, has_units_set);
+ SPGradient const *src = chase_hrefs(this, has_units_set);
return ( src
? src->units
: SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX ); // bbox is the default
}
-static void
-gradient_ref_modified(SPObject */*href*/, guint /*flags*/, SPGradient *gradient)
+void SPGradientImpl::gradientRefModified(SPObject */*href*/, guint /*flags*/, SPGradient *gradient)
{
- if (sp_gradient_invalidate_vector(gradient)) {
+ if ( gradient->invalidateVector() ) {
SP_OBJECT(gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG);
- /* Conditional to avoid causing infinite loop if there's a cycle in the href chain. */
+ // Conditional to avoid causing infinite loop if there's a cycle in the href chain.
}
}
-/** Return true iff change made. */
-static bool
-sp_gradient_invalidate_vector(SPGradient *gr)
+/** Return true if change made. */
+bool SPGradient::invalidateVector()
{
bool ret = false;
- if (gr->color != NULL) {
- g_free(gr->color);
- gr->color = NULL;
+ if (color != NULL) {
+ g_free(color);
+ color = NULL;
ret = true;
}
- if (gr->vector.built) {
- gr->vector.built = false;
- gr->vector.stops.clear();
+ if (vector.built) {
+ vector.built = false;
+ vector.stops.clear();
ret = true;
}
}
/** Creates normalized color vector */
-static void
-sp_gradient_rebuild_vector(SPGradient *gr)
+void SPGradient::rebuildVector()
{
gint len = 0;
- for ( SPObject *child = sp_object_first_child(SP_OBJECT(gr)) ;
+ for ( SPObject *child = sp_object_first_child(SP_OBJECT(this)) ;
child != NULL ;
child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_STOP(child)) {
}
}
- gr->has_stops = (len != 0);
+ has_stops = (len != 0);
- gr->vector.stops.clear();
+ vector.stops.clear();
- SPGradient *ref = gr->ref->getObject();
- if ( !gr->has_stops && ref ) {
+ SPGradient *reffed = ref->getObject();
+ if ( !hasStops() && reffed ) {
/* Copy vector from referenced gradient */
- gr->vector.built = true; // Prevent infinite recursion.
- sp_gradient_ensure_vector(ref);
- if (!ref->vector.stops.empty()) {
- gr->vector.built = ref->vector.built;
- gr->vector.stops.assign(ref->vector.stops.begin(), ref->vector.stops.end());
+ vector.built = true; // Prevent infinite recursion.
+ reffed->ensureVector();
+ if (!reffed->vector.stops.empty()) {
+ vector.built = reffed->vector.built;
+ vector.stops.assign(reffed->vector.stops.begin(), reffed->vector.stops.end());
return;
}
}
- for (SPObject *child = sp_object_first_child(SP_OBJECT(gr)) ;
+ for (SPObject *child = sp_object_first_child(SP_OBJECT(this)) ;
child != NULL;
child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_STOP(child)) {
SPStop *stop = SP_STOP(child);
SPGradientStop gstop;
- if (gr->vector.stops.size() > 0) {
+ if (vector.stops.size() > 0) {
// "Each gradient offset value is required to be equal to or greater than the
// previous gradient stop's offset value. If a given gradient stop's offset
// value is not equal to or greater than all previous offset values, then the
// offset value is adjusted to be equal to the largest of all previous offset
// values."
- gstop.offset = MAX(stop->offset, gr->vector.stops.back().offset);
+ gstop.offset = MAX(stop->offset, vector.stops.back().offset);
} else {
gstop.offset = stop->offset;
}
gstop.color = sp_stop_get_color(stop);
gstop.opacity = stop->opacity;
- gr->vector.stops.push_back(gstop);
+ vector.stops.push_back(gstop);
}
}
// Normalize per section 13.2.4 of SVG 1.1.
- if (gr->vector.stops.size() == 0) {
+ if (vector.stops.size() == 0) {
/* "If no stops are defined, then painting shall occur as if 'none' were specified as the
* paint style."
*/
gstop.offset = 0.0;
gstop.color.set( 0x00000000 );
gstop.opacity = 0.0;
- gr->vector.stops.push_back(gstop);
+ vector.stops.push_back(gstop);
}
{
SPGradientStop gstop;
gstop.offset = 1.0;
gstop.color.set( 0x00000000 );
gstop.opacity = 0.0;
- gr->vector.stops.push_back(gstop);
+ vector.stops.push_back(gstop);
}
} else {
/* "If one stop is defined, then paint with the solid color fill using the color defined
* for that gradient stop."
*/
- if (gr->vector.stops.front().offset > 0.0) {
+ if (vector.stops.front().offset > 0.0) {
// If the first one is not at 0, then insert a copy of the first at 0.
SPGradientStop gstop;
gstop.offset = 0.0;
- gstop.color = gr->vector.stops.front().color;
- gstop.opacity = gr->vector.stops.front().opacity;
- gr->vector.stops.insert(gr->vector.stops.begin(), gstop);
+ gstop.color = vector.stops.front().color;
+ gstop.opacity = vector.stops.front().opacity;
+ vector.stops.insert(vector.stops.begin(), gstop);
}
- if (gr->vector.stops.back().offset < 1.0) {
+ if (vector.stops.back().offset < 1.0) {
// If the last one is not at 1, then insert a copy of the last at 1.
SPGradientStop gstop;
gstop.offset = 1.0;
- gstop.color = gr->vector.stops.back().color;
- gstop.opacity = gr->vector.stops.back().opacity;
- gr->vector.stops.push_back(gstop);
+ gstop.color = vector.stops.back().color;
+ gstop.opacity = vector.stops.back().opacity;
+ vector.stops.push_back(gstop);
}
}
- gr->vector.built = true;
+ vector.built = true;
}
/**
* The gradient's color array is newly created and set up from vector.
*/
-void
-sp_gradient_ensure_colors(SPGradient *gr)
+void SPGradient::ensureColors()
{
- if (!gr->vector.built) {
- sp_gradient_rebuild_vector(gr);
+ if (!vector.built) {
+ rebuildVector();
}
- g_return_if_fail(!gr->vector.stops.empty());
+ g_return_if_fail(!vector.stops.empty());
/// \todo Where is the memory freed?
- if (!gr->color) {
- gr->color = g_new(guchar, 4 * NCOLORS);
+ if (!color) {
+ color = g_new(guchar, 4 * NCOLORS);
}
- // This assumes that gr->vector is a zero-order B-spline (box function) approximation of the "true" gradient.
+ // This assumes that vector is a zero-order B-spline (box function) approximation of the "true" gradient.
// This means that the "true" gradient must be prefiltered using a zero order B-spline and then sampled.
// Furthermore, the first element corresponds to offset="0" and the last element to offset="1".
double remainder[4] = {0,0,0,0};
double remainder_for_end[4] = {0,0,0,0}; // Used at the end
- switch(gr->spread) {
+ switch(spread) {
case SP_GRADIENT_SPREAD_PAD:
- remainder[0] = 0.5*gr->vector.stops[0].color.v.c[0]; // Half of the first cell uses the color of the first stop
- remainder[1] = 0.5*gr->vector.stops[0].color.v.c[1];
- remainder[2] = 0.5*gr->vector.stops[0].color.v.c[2];
- remainder[3] = 0.5*gr->vector.stops[0].opacity;
- remainder_for_end[0] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[0]; // Half of the first cell uses the color of the last stop
- remainder_for_end[1] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[1];
- remainder_for_end[2] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[2];
- remainder_for_end[3] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].opacity;
+ remainder[0] = 0.5*vector.stops[0].color.v.c[0]; // Half of the first cell uses the color of the first stop
+ remainder[1] = 0.5*vector.stops[0].color.v.c[1];
+ remainder[2] = 0.5*vector.stops[0].color.v.c[2];
+ remainder[3] = 0.5*vector.stops[0].opacity;
+ remainder_for_end[0] = 0.5*vector.stops[vector.stops.size() - 1].color.v.c[0]; // Half of the first cell uses the color of the last stop
+ remainder_for_end[1] = 0.5*vector.stops[vector.stops.size() - 1].color.v.c[1];
+ remainder_for_end[2] = 0.5*vector.stops[vector.stops.size() - 1].color.v.c[2];
+ remainder_for_end[3] = 0.5*vector.stops[vector.stops.size() - 1].opacity;
break;
case SP_GRADIENT_SPREAD_REFLECT:
case SP_GRADIENT_SPREAD_REPEAT:
default:
g_error("Spread type not supported!");
};
- for (unsigned int i = 0; i < gr->vector.stops.size() - 1; i++) {
- double r0 = gr->vector.stops[i].color.v.c[0];
- double g0 = gr->vector.stops[i].color.v.c[1];
- double b0 = gr->vector.stops[i].color.v.c[2];
- double a0 = gr->vector.stops[i].opacity;
- double r1 = gr->vector.stops[i+1].color.v.c[0];
- double g1 = gr->vector.stops[i+1].color.v.c[1];
- double b1 = gr->vector.stops[i+1].color.v.c[2];
- double a1 = gr->vector.stops[i+1].opacity;
- double o0 = gr->vector.stops[i].offset * (NCOLORS-1);
- double o1 = gr->vector.stops[i + 1].offset * (NCOLORS-1);
+ for (unsigned int i = 0; i < vector.stops.size() - 1; i++) {
+ double r0 = vector.stops[i].color.v.c[0];
+ double g0 = vector.stops[i].color.v.c[1];
+ double b0 = vector.stops[i].color.v.c[2];
+ double a0 = vector.stops[i].opacity;
+ double r1 = vector.stops[i+1].color.v.c[0];
+ double g1 = vector.stops[i+1].color.v.c[1];
+ double b1 = vector.stops[i+1].color.v.c[2];
+ double a1 = vector.stops[i+1].opacity;
+ double o0 = vector.stops[i].offset * (NCOLORS-1);
+ double o1 = vector.stops[i + 1].offset * (NCOLORS-1);
unsigned int ob = (unsigned int) floor(o0+.5); // These are the first and last element that might be affected by this interval.
unsigned int oe = (unsigned int) floor(o1+.5); // These need to be computed the same to ensure that ob will be covered by the next interval if oe==ob
double df = 1. / (o1-o0);
for (unsigned int j = ob+1; j < oe; j++) {
f += df;
- gr->color[4 * j + 0] = (unsigned char) floor(255*(r0 + f*(r1-r0)) + .5);
- gr->color[4 * j + 1] = (unsigned char) floor(255*(g0 + f*(g1-g0)) + .5);
- gr->color[4 * j + 2] = (unsigned char) floor(255*(b0 + f*(b1-b0)) + .5);
- gr->color[4 * j + 3] = (unsigned char) floor(255*(a0 + f*(a1-a0)) + .5);
+ color[4 * j + 0] = (unsigned char) floor(255*(r0 + f*(r1-r0)) + .5);
+ color[4 * j + 1] = (unsigned char) floor(255*(g0 + f*(g1-g0)) + .5);
+ color[4 * j + 2] = (unsigned char) floor(255*(b0 + f*(b1-b0)) + .5);
+ color[4 * j + 3] = (unsigned char) floor(255*(a0 + f*(a1-a0)) + .5);
}
// Now handle the beginning
// = (ob+.5-o0)*(c0+(ob+.5-o0)*df*(c1-c0)/2)
double dt = ob+.5-o0;
f = 0.5*dt*df;
- if (ob==0 && gr->spread==SP_GRADIENT_SPREAD_REFLECT) {
+ if (ob==0 && spread==SP_GRADIENT_SPREAD_REFLECT) {
// The first half of the first cell is just a mirror image of the second half, so simply multiply it by 2.
- gr->color[4 * ob + 0] = (unsigned char) floor(2*255*(remainder[0] + dt*(r0 + f*(r1-r0))) + .5);
- gr->color[4 * ob + 1] = (unsigned char) floor(2*255*(remainder[1] + dt*(g0 + f*(g1-g0))) + .5);
- gr->color[4 * ob + 2] = (unsigned char) floor(2*255*(remainder[2] + dt*(b0 + f*(b1-b0))) + .5);
- gr->color[4 * ob + 3] = (unsigned char) floor(2*255*(remainder[3] + dt*(a0 + f*(a1-a0))) + .5);
- } else if (ob==0 && gr->spread==SP_GRADIENT_SPREAD_REPEAT) {
+ color[4 * ob + 0] = (unsigned char) floor(2*255*(remainder[0] + dt*(r0 + f*(r1-r0))) + .5);
+ color[4 * ob + 1] = (unsigned char) floor(2*255*(remainder[1] + dt*(g0 + f*(g1-g0))) + .5);
+ color[4 * ob + 2] = (unsigned char) floor(2*255*(remainder[2] + dt*(b0 + f*(b1-b0))) + .5);
+ color[4 * ob + 3] = (unsigned char) floor(2*255*(remainder[3] + dt*(a0 + f*(a1-a0))) + .5);
+ } else if (ob==0 && spread==SP_GRADIENT_SPREAD_REPEAT) {
// The first cell is the same as the last cell, so save whatever is in the second half here and deal with the rest later.
remainder_for_end[0] = remainder[0] + dt*(r0 + f*(r1-r0));
remainder_for_end[1] = remainder[1] + dt*(g0 + f*(g1-g0));
remainder_for_end[3] = remainder[3] + dt*(a0 + f*(a1-a0));
} else {
// The first half of the cell was already in remainder.
- gr->color[4 * ob + 0] = (unsigned char) floor(255*(remainder[0] + dt*(r0 + f*(r1-r0))) + .5);
- gr->color[4 * ob + 1] = (unsigned char) floor(255*(remainder[1] + dt*(g0 + f*(g1-g0))) + .5);
- gr->color[4 * ob + 2] = (unsigned char) floor(255*(remainder[2] + dt*(b0 + f*(b1-b0))) + .5);
- gr->color[4 * ob + 3] = (unsigned char) floor(255*(remainder[3] + dt*(a0 + f*(a1-a0))) + .5);
+ color[4 * ob + 0] = (unsigned char) floor(255*(remainder[0] + dt*(r0 + f*(r1-r0))) + .5);
+ color[4 * ob + 1] = (unsigned char) floor(255*(remainder[1] + dt*(g0 + f*(g1-g0))) + .5);
+ color[4 * ob + 2] = (unsigned char) floor(255*(remainder[2] + dt*(b0 + f*(b1-b0))) + .5);
+ color[4 * ob + 3] = (unsigned char) floor(255*(remainder[3] + dt*(a0 + f*(a1-a0))) + .5);
}
// Now handle the end, which should end up in remainder
remainder[3] = dt*(a0 + f*(a1-a0));
}
}
- switch(gr->spread) {
+ switch(spread) {
case SP_GRADIENT_SPREAD_PAD:
- gr->color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(255*(remainder[0]+remainder_for_end[0]) + .5);
- gr->color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(255*(remainder[1]+remainder_for_end[1]) + .5);
- gr->color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(255*(remainder[2]+remainder_for_end[2]) + .5);
- gr->color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(255*(remainder[3]+remainder_for_end[3]) + .5);
+ color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(255*(remainder[0]+remainder_for_end[0]) + .5);
+ color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(255*(remainder[1]+remainder_for_end[1]) + .5);
+ color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(255*(remainder[2]+remainder_for_end[2]) + .5);
+ color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(255*(remainder[3]+remainder_for_end[3]) + .5);
break;
case SP_GRADIENT_SPREAD_REFLECT:
// The second half is the same as the first half, so multiply by 2.
- gr->color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(2*255*remainder[0] + .5);
- gr->color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(2*255*remainder[1] + .5);
- gr->color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(2*255*remainder[2] + .5);
- gr->color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(2*255*remainder[3] + .5);
+ color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(2*255*remainder[0] + .5);
+ color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(2*255*remainder[1] + .5);
+ color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(2*255*remainder[2] + .5);
+ color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(2*255*remainder[3] + .5);
break;
case SP_GRADIENT_SPREAD_REPEAT:
// The second half is the same as the second half of the first cell (which was saved in remainder_for_end).
- gr->color[0] = gr->color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(255*(remainder[0]+remainder_for_end[0]) + .5);
- gr->color[1] = gr->color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(255*(remainder[1]+remainder_for_end[1]) + .5);
- gr->color[2] = gr->color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(255*(remainder[2]+remainder_for_end[2]) + .5);
- gr->color[3] = gr->color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(255*(remainder[3]+remainder_for_end[3]) + .5);
+ color[0] = color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(255*(remainder[0]+remainder_for_end[0]) + .5);
+ color[1] = color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(255*(remainder[1]+remainder_for_end[1]) + .5);
+ color[2] = color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(255*(remainder[2]+remainder_for_end[2]) + .5);
+ color[3] = color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(255*(remainder[3]+remainder_for_end[3]) + .5);
break;
}
}
g_return_if_fail(span > 0);
if (!gradient->color) {
- sp_gradient_ensure_colors(gradient);
+ gradient->ensureColors();
}
gint idx = (pos * 1024 << 8) / span;
Geom::Matrix
sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Matrix const &ctm, Geom::Rect const &bbox)
{
- if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
return ( Geom::Scale(bbox.dimensions())
* Geom::Translate(bbox.min())
* Geom::Matrix(ctm) );
@@ -1371,7 +1370,7 @@ sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Matrix const &ctm, Geom::
Geom::Matrix
sp_gradient_get_gs2d_matrix(SPGradient const *gr, Geom::Matrix const &ctm, Geom::Rect const &bbox)
{
- if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
return ( gr->gradientTransform
* Geom::Scale(bbox.dimensions())
* Geom::Translate(bbox.min())
Geom::Rect const &bbox, Geom::Matrix const &gs2d)
{
gr->gradientTransform = gs2d * ctm.inverse();
- if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX ) {
+ if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX ) {
gr->gradientTransform = ( gr->gradientTransform
* Geom::Translate(-bbox.min())
* Geom::Scale(bbox.dimensions()).inverse() );
SPLinearGradient *lg;
NRLGradientRenderer lgr;
+
+ static SPPainter * painter_new(SPPaintServer *ps,
+ Geom::Matrix const &full_transform,
+ Geom::Matrix const &parent_transform,
+ NRRect const *bbox);
};
static void sp_lineargradient_class_init(SPLinearGradientClass *klass);
@@ -1420,10 +1424,6 @@ static void sp_lineargradient_set(SPObject *object, unsigned key, gchar const *v
static Inkscape::XML::Node *sp_lineargradient_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr,
guint flags);
-static SPPainter *sp_lineargradient_painter_new(SPPaintServer *ps,
- Geom::Matrix const &full_transform,
- Geom::Matrix const &parent_transform,
- NRRect const *bbox);
static void sp_lineargradient_painter_free(SPPaintServer *ps, SPPainter *painter);
static void sp_lg_fill(SPPainter *painter, NRPixBlock *pb);
sp_object_class->set = sp_lineargradient_set;
sp_object_class->write = sp_lineargradient_write;
- ps_class->painter_new = sp_lineargradient_painter_new;
+ ps_class->painter_new = SPLGPainter::painter_new;
ps_class->painter_free = sp_lineargradient_painter_free;
}
@@ -1573,16 +1573,17 @@ sp_lineargradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inks
* \todo (point 1 above) fixme: I do not know how to deal with start > 0
* and end < 1.
*/
-static SPPainter *
-sp_lineargradient_painter_new(SPPaintServer *ps,
- Geom::Matrix const &full_transform,
- Geom::Matrix const &/*parent_transform*/,
- NRRect const *bbox)
+SPPainter * SPLGPainter::painter_new(SPPaintServer *ps,
+ Geom::Matrix const &full_transform,
+ Geom::Matrix const &/*parent_transform*/,
+ NRRect const *bbox)
{
SPLinearGradient *lg = SP_LINEARGRADIENT(ps);
SPGradient *gr = SP_GRADIENT(ps);
- if (!gr->color) sp_gradient_ensure_colors(gr);
+ if (!gr->color) {
+ gr->ensureColors();
+ }
SPLGPainter *lgp = g_new(SPLGPainter, 1);
}
// TODO: remove color2px_nr after converting to 2geom
NR::Matrix color2px_nr = from_2geom(color2px);
- nr_lgradient_renderer_setup(&lgp->lgr, gr->color, sp_gradient_get_spread(gr), &color2px_nr,
+ nr_lgradient_renderer_setup(&lgp->lgr, gr->color, gr->fetchSpread(), &color2px_nr,
lg->x1.computed, lg->y1.computed,
lg->x2.computed, lg->y2.computed);
SPLGPainter *lgp = (SPLGPainter *) painter;
if (lgp->lg->color == NULL) {
- sp_gradient_ensure_colors (lgp->lg);
+ lgp->lg->ensureColors();
lgp->lgr.vector = lgp->lg->color;
}
SPPainter painter;
SPRadialGradient *rg;
NRRGradientRenderer rgr;
+
+ static SPPainter *painter_new(SPPaintServer *ps,
+ Geom::Matrix const &full_transform,
+ Geom::Matrix const &parent_transform,
+ NRRect const *bbox);
};
static void sp_radialgradient_class_init(SPRadialGradientClass *klass);
static void sp_radialgradient_set(SPObject *object, unsigned key, gchar const *value);
static Inkscape::XML::Node *sp_radialgradient_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr,
guint flags);
-
-static SPPainter *sp_radialgradient_painter_new(SPPaintServer *ps,
- Geom::Matrix const &full_transform,
- Geom::Matrix const &parent_transform,
- NRRect const *bbox);
static void sp_radialgradient_painter_free(SPPaintServer *ps, SPPainter *painter);
static void sp_rg_fill(SPPainter *painter, NRPixBlock *pb);
sp_object_class->set = sp_radialgradient_set;
sp_object_class->write = sp_radialgradient_write;
- ps_class->painter_new = sp_radialgradient_painter_new;
+ ps_class->painter_new = SPRGPainter::painter_new;
ps_class->painter_free = sp_radialgradient_painter_free;
}
@@ -1856,16 +1857,17 @@ sp_radialgradient_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inks
/**
* Create radial gradient context.
*/
-static SPPainter *
-sp_radialgradient_painter_new(SPPaintServer *ps,
- Geom::Matrix const &full_transform,
- Geom::Matrix const &/*parent_transform*/,
- NRRect const *bbox)
+SPPainter *SPRGPainter::painter_new(SPPaintServer *ps,
+ Geom::Matrix const &full_transform,
+ Geom::Matrix const &/*parent_transform*/,
+ NRRect const *bbox)
{
SPRadialGradient *rg = SP_RADIALGRADIENT(ps);
SPGradient *gr = SP_GRADIENT(ps);
- if (!gr->color) sp_gradient_ensure_colors(gr);
+ if (!gr->color) {
+ gr->ensureColors();
+ }
SPRGPainter *rgp = g_new(SPRGPainter, 1);
}
// TODO: remove gs2px_nr after converting to 2geom
NR::Matrix gs2px_nr = from_2geom(gs2px);
- nr_rgradient_renderer_setup(&rgp->rgr, gr->color, sp_gradient_get_spread(gr),
+ nr_rgradient_renderer_setup(&rgp->rgr, gr->color, gr->fetchSpread(),
&gs2px_nr,
rg->cx.computed, rg->cy.computed,
rg->fx.computed, rg->fy.computed,
SPRGPainter *rgp = (SPRGPainter *) painter;
if (rgp->rg->color == NULL) {
- sp_gradient_ensure_colors (rgp->rg);
+ rgp->rg->ensureColors();
rgp->rgr.vector = rgp->rg->color;
}
diff --git a/src/sp-gradient.h b/src/sp-gradient.h
index e7488673dddb9a40fd7de11ca4e9e19ca732dbf5..7e6afe0520a11094ed3595fffdf0d8bdb54137dd 100644 (file)
--- a/src/sp-gradient.h
+++ b/src/sp-gradient.h
struct SPGradientReference;
-#define SP_TYPE_GRADIENT (sp_gradient_get_type())
+#define SP_TYPE_GRADIENT (SPGradient::getType())
#define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient))
#define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass))
#define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT))
#define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT))
-GType sp_gradient_get_type();
-
typedef enum {
SP_GRADIENT_TYPE_UNKNOWN,
SP_GRADIENT_TYPE_LINEAR,
/** State in Inkscape gradient system */
guint state : 2;
+private:
/** gradientUnits attribute */
SPGradientUnits units;
guint units_set : 1;
+public:
/** gradientTransform attribute */
Geom::Matrix gradientTransform;
guint gradientTransform_set : 1;
+private:
/** spreadMethod attribute */
SPGradientSpread spread;
guint spread_set : 1;
/** Gradient stops */
guint has_stops : 1;
+public:
/** Composed vector */
SPGradientVector vector;
sigc::connection modified_connection;
+ bool hasStops() const;
SPStop* getFirstStop();
int getStopCount() const;
+
+ bool isUnitsSet() const;
+ SPGradientUnits getUnits() const;
+ void setUnits(SPGradientUnits units);
+
+
+ bool isSpreadSet() const;
+ SPGradientSpread getSpread() const;
+
/**
* Returns private vector of given gradient (the gradient at the end of the href chain which has
* stops), optionally normalizing it.
* \pre There exists a gradient in the chain that has stops.
*/
SPGradient *getVector(bool force_private = false);
+
+ static GType getType();
+
+ /** Forces vector to be built, if not present (i.e. changed) */
+ void ensureVector();
+
+ /** Ensures that color array is populated */
+ void ensureColors();
+
+ /**
+ * Set spread property of gradient and emit modified.
+ */
+ void setSpread(SPGradientSpread spread);
+
+ SPGradientSpread fetchSpread();
+ SPGradientUnits fetchUnits();
+
+private:
+ bool invalidateVector();
+ void rebuildVector();
+
+ friend class SPGradientImpl;
+ friend class SPLGPainter;
+ friend class SPRGPainter;
};
/**
index 258323a93d36399baffacada5af08aae80125106..5858f9a0e5c476106c234b06588837efb07322fc 100644 (file)
--- a/src/sp-paint-server.cpp
+++ b/src/sp-paint-server.cpp
bool swatch = false;
if (SP_IS_GRADIENT(this)) {
SPGradient *grad = SP_GRADIENT(this);
- if ( SP_GRADIENT_HAS_STOPS(grad) ) {
- gchar const * attr = repr->attribute("osb:paint");
- if (attr && !strcmp(attr, "solid")) {
- swatch = true;
- }
- }
+ swatch = grad->hasStops() && repr->attribute("osb:paint");
}
return swatch;
}
bool solid = false;
if (SP_IS_GRADIENT(this)) {
SPGradient *grad = SP_GRADIENT(this);
- if ( SP_GRADIENT_HAS_STOPS(grad) && (grad->getStopCount() == 0) ) {
+ if ( grad->hasStops() && (grad->getStopCount() == 0) ) {
gchar const * attr = repr->attribute("osb:paint");
if (attr && !strcmp(attr, "solid")) {
solid = true;
diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp
index 13299b5a4004fef123cb90f05cc659879cd7ca24..904d0cb231a73536d34526fa7ae5d32e969d0f25 100644 (file)
--- a/src/tweak-context.cpp
+++ b/src/tweak-context.cpp
// Normalize pos to 0..1, taking into accound gradient spread:
double pos_e = pos;
- if (gradient->spread == SP_GRADIENT_SPREAD_PAD) {
- if (pos > 1)
+ if (gradient->getSpread() == SP_GRADIENT_SPREAD_PAD) {
+ if (pos > 1) {
pos_e = 1;
- if (pos < 0)
+ }
+ if (pos < 0) {
pos_e = 0;
- } else if (gradient->spread == SP_GRADIENT_SPREAD_REPEAT) {
- if (pos > 1 || pos < 0)
+ }
+ } else if (gradient->getSpread() == SP_GRADIENT_SPREAD_REPEAT) {
+ if (pos > 1 || pos < 0) {
pos_e = pos - floor(pos);
- } else if (gradient->spread == SP_GRADIENT_SPREAD_REFLECT) {
+ }
+ } else if (gradient->getSpread() == SP_GRADIENT_SPREAD_REFLECT) {
if (pos > 1 || pos < 0) {
bool odd = ((int)(floor(pos)) % 2 == 1);
pos_e = pos - floor(pos);
- if (odd)
+ if (odd) {
pos_e = 1 - pos_e;
+ }
}
}
index b0d027ae9267c5aebf0dc0e8a04977b4acb33e21..90e9e5f7bcba5f414ab20358b068360d94407848 100644 (file)
@@ -182,12 +182,12 @@ void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer us
for (const GSList *item = gradients; item; item = item->next) {
SPGradient* grad = SP_GRADIENT(item->data);
if ( targetName == grad->getId() ) {
- grad->repr->setAttribute("osb:paint", "solid");
+ grad->repr->setAttribute("osb:paint", "solid"); // TODO make conditional
sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT,
_("Add gradient stop"));
- handleGradientsChange(doc); // work-around for signal not being emmitted
+ handleGradientsChange(doc); // work-around for signal not being emitted
break;
}
}
@@ -310,7 +310,7 @@ gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, g
gint index = 0;
for (const GSList *curr = gradients; curr; curr = curr->next) {
SPGradient* grad = SP_GRADIENT(curr->data);
- if (SP_GRADIENT_HAS_STOPS(grad) && !grad->isSwatch()) {
+ if ( grad->hasStops() && !grad->isSwatch() ) {
//gl = g_slist_prepend(gl, curr->data);
processed = true;
GtkWidget *child = gtk_menu_item_new_with_label(grad->getId());
for ( std::vector<SPGradient*>::iterator it = newList.begin(); it != newList.end(); ++it )
{
SPGradient* grad = *it;
- sp_gradient_ensure_vector( grad );
+ grad->ensureVector();
SPGradientStop first = grad->vector.stops[0];
SPColor color = first.color;
guint32 together = color.toRGBA32(first.opacity);
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
SPGradient* grad = SP_GRADIENT(server);
- if (grad->repr->attribute("osb:paint")) {
+
+ if ( grad->isSwatch() ) {
target = grad;
} else if ( grad->ref ) {
SPGradient *tmp = grad->ref->getObject();
- if ( tmp && tmp->repr->attribute("osb:paint") ) {
+ if ( tmp && tmp->isSwatch() ) {
target = tmp;
}
}
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
SPGradient* grad = SP_GRADIENT(server);
- if (grad->repr->attribute("osb:paint")) {
+ if ( grad->isSwatch() ) {
target = grad;
} else if ( grad->ref ) {
SPGradient *tmp = grad->ref->getObject();
- if ( tmp && tmp->repr->attribute("osb:paint") ) {
+ if ( tmp && tmp->isSwatch() ) {
target = tmp;
}
}
index 15d8b6cc27289bffc45b6b5e0acd2fbee46b7424..5a7256d8355a3584e71b98e7cf1f87bf9ed31048 100644 (file)
psel->setGradientLinear( vector );
SPLinearGradient *lg = SP_LINEARGRADIENT(server);
- psel->setGradientProperties( SP_GRADIENT_UNITS(lg),
- SP_GRADIENT_SPREAD(lg) );
+ psel->setGradientProperties( lg->getUnits(),
+ lg->getSpread() );
} else if (SP_IS_RADIALGRADIENT(server)) {
SPGradient *vector = SP_GRADIENT(server)->getVector();
psel->setGradientRadial( vector );
SPRadialGradient *rg = SP_RADIALGRADIENT(server);
- psel->setGradientProperties( SP_GRADIENT_UNITS(rg),
- SP_GRADIENT_SPREAD(rg) );
+ psel->setGradientProperties( rg->getUnits(),
+ rg->getSpread() );
} else if (SP_IS_PATTERN(server)) {
SPPattern *pat = pattern_getroot(SP_PATTERN(server));
psel->updatePatternList( pat );
index 9aa72164bc68ca04f145e0d49d6eff86f4e2149b..77defa5c9d4290b483924e648ea13189c85dd771 100644 (file)
g_return_if_fail(!vector || SP_IS_GRADIENT(vector));
g_return_if_fail(!vector || (SP_OBJECT_DOCUMENT(vector) == doc));
- if (vector && !SP_GRADIENT_HAS_STOPS(vector)) {
+ if (vector && !vector->hasStops()) {
return;
}
index 077e038e70ca8270686d3c391549f37772b358cf..1d3187985b8a0395a4b526da077dadfe56ed3608 100644 (file)
@@ -175,7 +175,7 @@ GtkWidget *gr_vector_list(SPDesktop *desktop, bool selection_empty, SPGradient *
const GSList *gradients = sp_document_get_resource_list (document, "gradient");
for (const GSList *i = gradients; i != NULL; i = i->next) {
SPGradient *grad = SP_GRADIENT(i->data);
- if (SP_GRADIENT_HAS_STOPS(grad) && !grad->isSolid()) {
+ if ( grad->hasStops() && !grad->isSolid() ) {
gl = g_slist_prepend (gl, i->data);
}
}
SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
if (SP_IS_GRADIENT(server)) {
SPGradient *gradient = SP_GRADIENT(server)->getVector();
- SPGradientSpread spread = sp_gradient_get_spread (SP_GRADIENT (server));
+ SPGradientSpread spread = SP_GRADIENT(server)->fetchSpread();
if (gradient && gradient->isSolid()) {
gradient = 0;
SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
if (SP_IS_GRADIENT(server)) {
SPGradient *gradient = SP_GRADIENT(server)->getVector();
- SPGradientSpread spread = sp_gradient_get_spread (SP_GRADIENT (server));
+ SPGradientSpread spread = SP_GRADIENT(server)->fetchSpread();
if (gradient && gradient->isSolid()) {
gradient = 0;
index 7bfe27310ddc74e008898718ca94f7d696065d7c..454c120015364949d684eade3245f17907b15d13 100644 (file)
@@ -181,7 +181,7 @@ void sp_gradient_vector_selector_set_gradient(SPGradientVectorSelector *gvs, SPD
g_return_if_fail(!gr || (doc != NULL));
g_return_if_fail(!gr || SP_IS_GRADIENT(gr));
g_return_if_fail(!gr || (SP_OBJECT_DOCUMENT(gr) == doc));
- g_return_if_fail(!gr || SP_GRADIENT_HAS_STOPS(gr));
+ g_return_if_fail(!gr || gr->hasStops());
if (doc != gvs->doc) {
/* Disconnect signals */
const GSList *gradients = sp_document_get_resource_list(SP_OBJECT_DOCUMENT(gvs->gr), "gradient");
for (const GSList *curr = gradients; curr; curr = curr->next) {
SPGradient* grad = SP_GRADIENT(curr->data);
- if (SP_GRADIENT_HAS_STOPS(grad) && (grad->isSwatch() == gvs->swatched)) {
+ if ( grad->hasStops() && (grad->isSwatch() == gvs->swatched) ) {
gl = g_slist_prepend(gl, curr->data);
}
}
@@ -535,7 +535,7 @@ static void update_stop_list( GtkWidget *mnu, SPGradient *gradient, SPStop *new_
GtkWidget *m = gtk_menu_new();
gtk_widget_show(m);
GSList *sl = NULL;
- if (gradient->has_stops) {
+ if ( gradient->hasStops() ) {
for ( SPObject *ochild = sp_object_first_child(SP_OBJECT(gradient)) ; ochild != NULL ; ochild = SP_OBJECT_NEXT(ochild) ) {
if (SP_IS_STOP(ochild)) {
sl = g_slist_append(sl, ochild);
@@ -1017,7 +1017,7 @@ static void sp_gradient_vector_widget_load_gradient(GtkWidget *widget, SPGradien
if (gradient) {
gtk_widget_set_sensitive(widget, TRUE);
- sp_gradient_ensure_vector(gradient);
+ gradient->ensureVector();
GtkOptionMenu *mnu = static_cast<GtkOptionMenu *>(g_object_get_data(G_OBJECT(widget), "stopmenu"));
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
@@ -1140,7 +1140,7 @@ static void sp_gradient_vector_color_dragged(SPColorSelector *csel, GtkObject *o
sp_gradient_vector_widget_load_gradient(GTK_WIDGET(object), ngr);
}
- sp_gradient_ensure_vector(ngr);
+ ngr->ensureVector();
GtkOptionMenu *mnu = static_cast<GtkOptionMenu *>(g_object_get_data(G_OBJECT(object), "stopmenu"));
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
@@ -1175,7 +1175,7 @@ static void sp_gradient_vector_color_changed(SPColorSelector *csel, GtkObject *o
sp_gradient_vector_widget_load_gradient(GTK_WIDGET(object), ngr);
}
- sp_gradient_ensure_vector(ngr);
+ ngr->ensureVector();
/* Set start parameters */
/* We rely on normalized vector, i.e. stops HAVE to exist */
index d3092669a92ea20d3e37255978b632af27be1492..8759854a02bc12696f45b5f0edcfd4be3af5ca6f 100644 (file)
SPGradientUnits units = SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX;
SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD;
getGradientProperties( units, spread );
- sp_gradient_set_units(gr, units);
- sp_gradient_set_spread(gr, spread);
+ gr->setUnits(units);
+ gr->setSpread(spread);
SP_OBJECT(gr)->updateRepr();
}
index a6f5133b799861adf64060caa61d5c9226c48358..ce0f8a810ae366f69ce3c3558b843fa4a1bd59e2 100644 (file)
// TODO replace with proper - sp_gradient_vector_widget_load_gradient(GTK_WIDGET(swsel->_gsel), ngr);
}
- sp_gradient_ensure_vector(ngr);
+ ngr->ensureVector();
SPStop* stop = ngr->getFirstStop();