index aa77ea0ade4bfd053cd22dff4ba37500e4b07555..fce26435c6b75a6037147b3dda2d888c35e98f8c 100644 (file)
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
*
+ * Copyright (C) 2007 Johan Engelen
* Copyright (C) 2001-2005 authors
* Copyright (C) 2001 Ximian, Inc.
*
#include "desktop-style.h"
#include "sp-gradient-reference.h"
+#include "sp-gradient-vector.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-stop.h"
#include <libnr/nr-matrix-fns.h>
#include "xml/repr.h"
#include "svg/svg.h"
+#include "svg/svg-color.h"
// Terminology:
// object. It is either linear or radial.
static void sp_gradient_repr_set_link(Inkscape::XML::Node *repr, SPGradient *gr);
-static void sp_item_repr_set_style_gradient(Inkscape::XML::Node *repr, gchar const *property,
- SPGradient *gr, bool recursive);
SPGradient *
sp_gradient_ensure_vector_normalized(SPGradient *gr)
@@ -93,12 +95,13 @@ sp_gradient_get_private_normalized(SPDocument *document, SPGradient *vector, SPG
SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
// create a new private gradient of the requested type
Inkscape::XML::Node *repr;
if (type == SP_GRADIENT_TYPE_LINEAR) {
- repr = sp_repr_new("svg:linearGradient");
+ repr = xml_doc->createElement("svg:linearGradient");
} else {
- repr = sp_repr_new("svg:radialGradient");
+ repr = xml_doc->createElement("svg:radialGradient");
}
// privates are garbage-collectable
sp_gradient_fork_vector_if_necessary (SPGradient *gr)
{
if (SP_OBJECT_HREFCOUNT(gr) > 1) {
- SPDocument *document = SP_OBJECT_DOCUMENT(gr);
+ SPDocument *doc = SP_OBJECT_DOCUMENT(gr);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
- Inkscape::XML::Node *repr = SP_OBJECT_REPR (gr)->duplicate();
- SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document))->addChild(repr, NULL);
- SPGradient *gr_new = (SPGradient *) document->getObjectByRepr(repr);
+ Inkscape::XML::Node *repr = SP_OBJECT_REPR (gr)->duplicate(xml_doc);
+ SP_OBJECT_REPR (SP_DOCUMENT_DEFS (doc))->addChild(repr, NULL);
+ SPGradient *gr_new = (SPGradient *) doc->getObjectByRepr(repr);
gr_new = sp_gradient_ensure_vector_normalized (gr_new);
Inkscape::GC::release(repr);
return gr_new;
return gr;
}
+/**
+ * Obtain the vector from the gradient. A forked vector will be created and linked to this gradient if another gradient uses it.
+ */
+SPGradient *
+sp_gradient_get_forked_vector_if_necessary(SPGradient *gradient, bool force_vector)
+{
+ SPGradient *vector = sp_gradient_get_vector (gradient, force_vector);
+ vector = sp_gradient_fork_vector_if_necessary (vector);
+ if ( gradient != vector && gradient->ref->getObject() != vector ) {
+ sp_gradient_repr_set_link(SP_OBJECT_REPR(gradient), vector);
+ }
+ return vector;
+}
+
+
/**
* Convert an item's gradient to userspace _without_ preserving coords, setting them to defaults
- * instead. No forking or reapplying is done because this is only called for newly created privates.
+ * instead. No forking or reapplying is done because this is only called for newly created privates.
* @return The new gradient.
*/
SPGradient *
// calculate the bbox of the item
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
- NR::Rect const bbox = item->invokeBbox(NR::identity()); // we need "true" bbox without item_i2d_affine
+ NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
+
+ if ( !bbox || bbox->isEmpty() )
+ return gr;
- NR::Coord const width = bbox.dimensions()[NR::X];
- NR::Coord const height = bbox.dimensions()[NR::Y];
- g_assert(width > 0 && height > 0);
+ NR::Coord const width = bbox->dimensions()[NR::X];
+ NR::Coord const height = bbox->dimensions()[NR::Y];
- NR::Point const center = bbox.midpoint();
+ NR::Point const center = bbox->midpoint();
if (SP_IS_RADIALGRADIENT(gr)) {
sp_repr_set_svg_double(repr, "cx", center[NR::X]);
sp_repr_set_svg_double(repr, "r", width/2);
// we want it to be elliptic, not circular
- NR::Matrix squeeze = NR::Matrix (NR::translate (-center)) *
- NR::Matrix (NR::scale(1, height/width)) *
+ NR::Matrix squeeze = NR::Matrix (NR::translate (-center)) *
+ NR::Matrix (NR::scale(1, height/width)) *
NR::Matrix (NR::translate (center));
gr->gradientTransform = squeeze;
{
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gr->gradientTransform)) {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
- } else {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gr->gradientTransform);
+ SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
+ g_free(c);
}
} else {
sp_repr_set_svg_double(repr, "x1", (center - NR::Point(width/2, 0))[NR::X]);
@@ -316,10 +334,16 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
// calculate the bbox of the item
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
- NR::Rect const bbox = item->invokeBbox(NR::identity()); // we need "true" bbox without item_i2d_affine
- NR::Matrix bbox2user(bbox.dimensions()[NR::X], 0,
- 0, bbox.dimensions()[NR::Y],
- bbox.min()[NR::X], bbox.min()[NR::Y]);
+ NR::Matrix bbox2user;
+ NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
+ if ( bbox && !bbox->isEmpty() ) {
+ bbox2user = NR::Matrix(bbox->dimensions()[NR::X], 0,
+ 0, bbox->dimensions()[NR::Y],
+ bbox->min()[NR::X], bbox->min()[NR::Y]);
+ } else {
+ // would be degenerate otherwise
+ bbox2user = NR::identity();
+ }
/* skew is the additional transform, defined by the proportions of the item, that we need
* to apply to the gradient in order to work around this weird bit from SVG 1.1
@@ -347,12 +371,9 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
// apply skew to the gradient
gr->gradientTransform = skew;
{
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gr->gradientTransform)) {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
- } else {
- SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gr->gradientTransform);
+ SP_OBJECT_REPR(gr)->setAttribute("gradientTransform", c);
+ g_free(c);
}
// Matrix to convert points to userspace coords; postmultiply by inverse of skew so
@@ -403,9 +424,9 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
// refer to one gradient, hence the recursive call for text (because we can't/don't
// want to access tspans and set gradients on them separately)
if (SP_IS_TEXT(item))
- sp_item_repr_set_style_gradient(SP_OBJECT_REPR(item), property, gr, true);
+ sp_style_set_property_url(SP_OBJECT(item), property, SP_OBJECT(gr), true);
else
- sp_item_repr_set_style_gradient(SP_OBJECT_REPR(item), property, gr, false);
+ sp_style_set_property_url(SP_OBJECT(item), property, SP_OBJECT(gr), false);
return gr;
}
@@ -420,12 +441,9 @@ sp_gradient_transform_multiply(SPGradient *gradient, NR::Matrix postmul, bool se
}
gradient->gradientTransform_set = TRUE;
- gchar c[256];
- if (sp_svg_transform_write(c, 256, gradient->gradientTransform)) {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", c);
- } else {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", NULL);
- }
+ gchar *c=sp_svg_transform_write(gradient->gradientTransform);
+ SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", c);
+ g_free(c);
}
SPGradient *
}
}
}
-
+
return gradient;
}
SPStop*
sp_prev_stop(SPStop *stop, SPGradient *gradient)
{
- if (sp_object_first_child(SP_OBJECT(gradient)) == SP_OBJECT(stop))
+ if (sp_object_first_child(SP_OBJECT(gradient)) == SP_OBJECT(stop))
return NULL;
SPObject *found = NULL;
for ( SPObject *ochild = sp_object_first_child(SP_OBJECT(gradient)) ; ochild != NULL ; ochild = SP_OBJECT_NEXT(ochild) ) {
return stop;
}
return NULL;
+}
+
+SPStop*
+sp_get_stop_i(SPGradient *gradient, guint stop_i)
+{
+ SPStop *stop = sp_first_stop (gradient);
+
+ for (guint i=0; i < stop_i; i++) {
+ if (!stop) return NULL;
+ stop = sp_next_stop (stop);
+ }
+
+ return stop;
}
void
-sp_item_gradient_edit_stop (SPItem *item, guint point_num, bool fill_or_stroke)
+sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
{
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
return;
SPGradient *vector = sp_gradient_get_vector (gradient, false);
- switch (point_num) {
- case POINT_LG_P1:
+ switch (point_type) {
+ case POINT_LG_BEGIN:
case POINT_RG_CENTER:
case POINT_RG_FOCUS:
{
}
break;
- case POINT_LG_P2:
+ case POINT_LG_END:
case POINT_RG_R1:
case POINT_RG_R2:
{
@@ -529,13 +560,22 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_num, bool fill_or_stroke)
gtk_widget_show (dialog);
}
break;
+
+ case POINT_LG_MID:
+ case POINT_RG_MID1:
+ case POINT_RG_MID2:
+ {
+ GtkWidget *dialog = sp_gradient_vector_editor_new (vector, sp_get_stop_i (vector, point_i));
+ gtk_widget_show (dialog);
+ }
+ break;
default:
break;
}
}
guint32
-sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_stroke)
+sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
{
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
@@ -547,8 +587,8 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s
if (!vector) // orphan!
return 0; // what else to do?
- switch (point_num) {
- case POINT_LG_P1:
+ switch (point_type) {
+ case POINT_LG_BEGIN:
case POINT_RG_CENTER:
case POINT_RG_FOCUS:
{
@@ -559,7 +599,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s
}
break;
- case POINT_LG_P2:
+ case POINT_LG_END:
case POINT_RG_R1:
case POINT_RG_R2:
{
@@ -569,6 +609,18 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s
}
}
break;
+
+ case POINT_LG_MID:
+ case POINT_RG_MID1:
+ case POINT_RG_MID2:
+ {
+ SPStop *stopi = sp_get_stop_i (vector, point_i);
+ if (stopi) {
+ return sp_stop_get_rgba32(stopi);
+ }
+ }
+ break;
+
default:
break;
}
@@ -576,7 +628,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s
}
void
-sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_stroke, SPCSSAttr *stop)
+sp_item_gradient_stop_set_style (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, SPCSSAttr *stop)
{
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
@@ -593,8 +645,8 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_str
sp_gradient_repr_set_link(SP_OBJECT_REPR(gradient), vector);
}
- switch (point_num) {
- case POINT_LG_P1:
+ switch (point_type) {
+ case POINT_LG_BEGIN:
case POINT_RG_CENTER:
case POINT_RG_FOCUS:
{
@@ -605,7 +657,7 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_str
}
break;
- case POINT_LG_P2:
+ case POINT_LG_END:
case POINT_RG_R1:
case POINT_RG_R2:
{
@@ -615,6 +667,18 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_str
}
}
break;
+
+ case POINT_LG_MID:
+ case POINT_RG_MID1:
+ case POINT_RG_MID2:
+ {
+ SPStop *stopi = sp_get_stop_i (vector, point_i);
+ if (stopi) {
+ sp_repr_css_change (SP_OBJECT_REPR (stopi), stop, "style");
+ }
+ }
+ break;
+
default:
break;
}
GSList *child_copies = NULL;
for (GSList *i = child_reprs; i != NULL; i = i->next) {
Inkscape::XML::Node *repr = (Inkscape::XML::Node *) i->data;
- child_copies = g_slist_append (child_copies, repr->duplicate());
+ Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(vector)->document();
+ child_copies = g_slist_append (child_copies, repr->duplicate(xml_doc));
}
}
+// FIXME: make general global function
+static double
+get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end)
+{
+ double length = NR::L2(end - begin);
+ NR::Point be = (end - begin) / length;
+ double r = NR::dot(p - begin, be);
+
+ if (r < 0.0) return 0.0;
+ if (r > length) return 1.0;
+
+ return (r / length);
+}
+
/**
-Set the position of point point_num of the gradient applied to item (either fill_or_stroke) to
+Set the position of point point_type of the gradient applied to item (either fill_or_stroke) to
p_w (in desktop coordinates). Write_repr if you want the change to become permanent.
*/
void
-sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool fill_or_stroke, bool write_repr, bool scale)
+sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::Point p_w, bool fill_or_stroke, bool write_repr, bool scale)
{
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
@@ -697,12 +776,12 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool
if (SP_IS_LINEARGRADIENT(gradient)) {
SPLinearGradient *lg = SP_LINEARGRADIENT(gradient);
- switch (point_num) {
- case POINT_LG_P1:
+ switch (point_type) {
+ case POINT_LG_BEGIN:
if (scale) {
lg->x2.computed += (lg->x1.computed - p[NR::X]);
lg->y2.computed += (lg->y1.computed - p[NR::Y]);
- }
+ }
lg->x1.computed = p[NR::X];
lg->y1.computed = p[NR::Y];
if (write_repr) {
@@ -716,11 +795,11 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool
SP_OBJECT (gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
break;
- case POINT_LG_P2:
+ case POINT_LG_END:
if (scale) {
lg->x1.computed += (lg->x2.computed - p[NR::X]);
lg->y1.computed += (lg->y2.computed - p[NR::Y]);
- }
+ }
lg->x2.computed = p[NR::X];
lg->y2.computed = p[NR::Y];
if (write_repr) {
@@ -734,22 +813,37 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool
SP_OBJECT (gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
break;
+ case POINT_LG_MID:
+ {
+ // 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, NR::Point(lg->x1.computed, lg->y1.computed), NR::Point(lg->x2.computed, lg->y2.computed));
+ SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (lg, false);
+ sp_gradient_ensure_vector(lg);
+ lg->vector.stops.at(point_i).offset = offset;
+ SPStop* stopi = sp_get_stop_i(vector, point_i);
+ stopi->offset = offset;
+ if (write_repr) {
+ sp_repr_set_css_double(SP_OBJECT_REPR(stopi), "offset", stopi->offset);
+ } else {
+ SP_OBJECT (stopi)->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+ }
+ }
+ break;
default:
break;
}
} else if (SP_IS_RADIALGRADIENT(gradient)) {
+ SPRadialGradient *rg = SP_RADIALGRADIENT(gradient);
+ NR::Point c (rg->cx.computed, rg->cy.computed);
+ NR::Point c_w = c * gradient->gradientTransform * i2d; // now in desktop coords
+ if ((point_type == POINT_RG_R1 || point_type == POINT_RG_R2) && NR::L2 (p_w - c_w) < 1e-3) {
+ // prevent setting a radius too close to the center
+ return;
+ }
+ NR::Matrix new_transform;
+ bool transform_set = false;
- SPRadialGradient *rg = SP_RADIALGRADIENT(gradient);
- NR::Point c (rg->cx.computed, rg->cy.computed);
- NR::Point c_w = c * gradient->gradientTransform * i2d; // now in desktop coords
- if ((point_num == POINT_RG_R1 || point_num == POINT_RG_R2) && NR::L2 (p_w - c_w) < 1e-3) {
- // prevent setting a radius too close to the center
- return;
- }
- NR::Matrix new_transform;
- bool transform_set = false;
-
- switch (point_num) {
+ switch (point_type) {
case POINT_RG_CENTER:
rg->fx.computed = p[NR::X] + (rg->fx.computed - rg->cx.computed);
rg->fy.computed = p[NR::Y] + (rg->fy.computed - rg->cy.computed);
@@ -776,19 +870,19 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool
break;
case POINT_RG_R1:
{
- NR::Point r1_w = (c + NR::Point(rg->r.computed, 0)) * gradient->gradientTransform * i2d;
+ NR::Point r1_w = (c + NR::Point(rg->r.computed, 0)) * gradient->gradientTransform * i2d;
double r1_angle = NR::atan2(r1_w - c_w);
double move_angle = NR::atan2(p_w - c_w) - r1_angle;
double move_stretch = NR::L2(p_w - c_w) / NR::L2(r1_w - c_w);
NR::Matrix move = NR::Matrix (NR::translate (-c_w)) *
- NR::Matrix (NR::rotate(-r1_angle)) *
+ NR::Matrix (NR::rotate(-r1_angle)) *
NR::Matrix (NR::scale(move_stretch, scale? move_stretch : 1)) *
- NR::Matrix (NR::rotate(r1_angle)) *
- NR::Matrix (NR::rotate(move_angle)) *
+ NR::Matrix (NR::rotate(r1_angle)) *
+ NR::Matrix (NR::rotate(move_angle)) *
NR::Matrix (NR::translate (c_w));
- new_transform = gradient->gradientTransform * i2d * move * i2d.inverse();
+ new_transform = gradient->gradientTransform * i2d * move * i2d.inverse();
transform_set = true;
break;
@@ -801,29 +895,57 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool
double move_stretch = NR::L2(p_w - c_w) / NR::L2(r2_w - c_w);
NR::Matrix move = NR::Matrix (NR::translate (-c_w)) *
- NR::Matrix (NR::rotate(-r2_angle)) *
+ NR::Matrix (NR::rotate(-r2_angle)) *
NR::Matrix (NR::scale(move_stretch, scale? move_stretch : 1)) *
- NR::Matrix (NR::rotate(r2_angle)) *
- NR::Matrix (NR::rotate(move_angle)) *
+ NR::Matrix (NR::rotate(r2_angle)) *
+ NR::Matrix (NR::rotate(move_angle)) *
NR::Matrix (NR::translate (c_w));
- new_transform = gradient->gradientTransform * i2d * move * i2d.inverse();
+ new_transform = gradient->gradientTransform * i2d * move * i2d.inverse();
transform_set = true;
- break;
- }
- }
-
+ break;
+ }
+ case POINT_RG_MID1:
+ {
+ NR::Point start = NR::Point (rg->cx.computed, rg->cy.computed);
+ NR::Point end = NR::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->vector.stops.at(point_i).offset = offset;
+ SPStop* stopi = sp_get_stop_i(vector, point_i);
+ stopi->offset = offset;
+ if (write_repr) {
+ sp_repr_set_css_double(SP_OBJECT_REPR(stopi), "offset", stopi->offset);
+ } else {
+ SP_OBJECT (stopi)->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+ }
+ break;
+ }
+ case POINT_RG_MID2:
+ NR::Point start = NR::Point (rg->cx.computed, rg->cy.computed);
+ NR::Point end = NR::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->vector.stops.at(point_i).offset = offset;
+ SPStop* stopi = sp_get_stop_i(vector, point_i);
+ stopi->offset = offset;
+ if (write_repr) {
+ sp_repr_set_css_double(SP_OBJECT_REPR(stopi), "offset", stopi->offset);
+ } else {
+ SP_OBJECT (stopi)->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+ }
+ break;
+ }
if (transform_set) {
- gradient->gradientTransform = new_transform;
+ gradient->gradientTransform = new_transform;
gradient->gradientTransform_set = TRUE;
if (write_repr) {
- gchar s[256];
- if (sp_svg_transform_write(s, 256, gradient->gradientTransform)) {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", s);
- } else {
- SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", NULL);
- }
+ gchar *s=sp_svg_transform_write(gradient->gradientTransform);
+ SP_OBJECT_REPR(gradient)->setAttribute("gradientTransform", s);
+ g_free(s);
} else {
SP_OBJECT (gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
return NULL;
}
-SPGradientSpread
+SPGradientSpread
sp_item_gradient_get_spread (SPItem *item, bool fill_or_stroke)
{
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
/**
-Returns the position of point point_num of the gradient applied to item (either fill_or_stroke),
+Returns the position of point point_type of the gradient applied to item (either fill_or_stroke),
in desktop coordinates.
*/
NR::Point
-sp_item_gradient_get_coords (SPItem *item, guint point_num, bool fill_or_stroke)
+sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke)
{
SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
@@ -869,17 +991,23 @@ sp_item_gradient_get_coords (SPItem *item, guint point_num, bool fill_or_stroke)
if (SP_IS_LINEARGRADIENT(gradient)) {
SPLinearGradient *lg = SP_LINEARGRADIENT(gradient);
- switch (point_num) {
- case POINT_LG_P1:
+ switch (point_type) {
+ case POINT_LG_BEGIN:
p = NR::Point (lg->x1.computed, lg->y1.computed);
break;
- case POINT_LG_P2:
+ case POINT_LG_END:
p = NR::Point (lg->x2.computed, lg->y2.computed);
break;
+ case POINT_LG_MID:
+ {
+ gdouble offset = lg->vector.stops.at(point_i).offset;
+ p = (1-offset) * NR::Point(lg->x1.computed, lg->y1.computed) + offset * NR::Point(lg->x2.computed, lg->y2.computed);
+ }
+ break;
}
} else if (SP_IS_RADIALGRADIENT(gradient)) {
SPRadialGradient *rg = SP_RADIALGRADIENT(gradient);
- switch (point_num) {
+ switch (point_type) {
case POINT_RG_CENTER:
p = NR::Point (rg->cx.computed, rg->cy.computed);
break;
@@ -892,15 +1020,29 @@ sp_item_gradient_get_coords (SPItem *item, guint point_num, bool fill_or_stroke)
case POINT_RG_R2:
p = NR::Point (rg->cx.computed, rg->cy.computed - rg->r.computed);
break;
+ case POINT_RG_MID1:
+ {
+ gdouble offset = rg->vector.stops.at(point_i).offset;
+ p = (1-offset) * NR::Point (rg->cx.computed, rg->cy.computed) + offset * NR::Point(rg->cx.computed + rg->r.computed, rg->cy.computed);
+ }
+ break;
+ case POINT_RG_MID2:
+ {
+ gdouble offset = rg->vector.stops.at(point_i).offset;
+ p = (1-offset) * NR::Point (rg->cx.computed, rg->cy.computed) + offset * NR::Point(rg->cx.computed, rg->cy.computed - rg->r.computed);
+ }
+ break;
}
}
if (SP_GRADIENT(gradient)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
- NR::Rect const bbox = item->invokeBbox(NR::identity()); // we need "true" bbox without item_i2d_affine
- p *= NR::Matrix(bbox.dimensions()[NR::X], 0,
- 0, bbox.dimensions()[NR::Y],
- bbox.min()[NR::X], bbox.min()[NR::Y]);
+ NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
+ if (bbox) {
+ p *= NR::Matrix(bbox->dimensions()[NR::X], 0,
+ 0, bbox->dimensions()[NR::Y],
+ bbox->min()[NR::X], bbox->min()[NR::Y]);
+ }
}
p *= NR::Matrix(gradient->gradientTransform) * sp_item_i2d_affine(item);
return p;
@@ -940,7 +1082,7 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_
//g_print("hrefcount %d count %d\n", SP_OBJECT_HREFCOUNT(ig), count_gradient_hrefs(SP_OBJECT(item), ig));
- if (SP_OBJECT_HREFCOUNT(current) == 1 ||
+ if (SP_OBJECT_HREFCOUNT(current) == 1 ||
SP_OBJECT_HREFCOUNT(current) == count_gradient_hrefs(SP_OBJECT(item), current)) {
// current is private and it's either used once, or all its uses are by children of item;
@@ -965,7 +1107,7 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_
/* We have to change object style here; recursive because this is used from
* fill&stroke and must work for groups etc. */
- sp_item_repr_set_style_gradient(SP_OBJECT_REPR(item), is_fill? "fill" : "stroke", normalized, true);
+ sp_style_set_property_url(SP_OBJECT(item), is_fill? "fill" : "stroke", SP_OBJECT(normalized), true);
}
SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
return normalized;
@@ -975,9 +1117,7 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_
/* Current fill style is not a gradient or wrong type, so construct everything */
SPGradient *constructed = sp_gradient_get_private_normalized(SP_OBJECT_DOCUMENT(item), gr, type);
constructed = sp_gradient_reset_to_userspace(constructed, item);
- sp_item_repr_set_style_gradient(SP_OBJECT_REPR(item),
- ( is_fill ? "fill" : "stroke" ),
- constructed, true);
+ sp_style_set_property_url(SP_OBJECT(item), ( is_fill ? "fill" : "stroke" ), SP_OBJECT(constructed), true);
SP_OBJECT(item)->requestDisplayUpdate(( SP_OBJECT_MODIFIED_FLAG |
SP_OBJECT_STYLE_MODIFIED_FLAG ));
return constructed;
repr->setAttribute("xlink:href", ref);
}
-static void
-sp_item_repr_set_style_gradient(Inkscape::XML::Node *repr, gchar const *property,
- SPGradient *gr, bool recursive)
-{
- g_return_if_fail(repr != NULL);
- g_return_if_fail(gr != NULL);
- g_return_if_fail(SP_IS_GRADIENT(gr));
-
- gchar *val = g_strdup_printf("url(#%s)", SP_OBJECT_ID(gr));
-
- SPCSSAttr *css = sp_repr_css_attr_new();
- sp_repr_css_set_property(css, property, val);
- g_free(val);
- if (recursive) {
- sp_repr_css_change_recursive(repr, css, "style");
- } else {
- sp_repr_css_change(repr, css, "style");
- }
- sp_repr_css_attr_unref(css);
-}
-
/*
* Get default normalized gradient vector of document, create if there is none
*/
sp_document_default_gradient_vector(SPDocument *document, guint32 color)
{
SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
- Inkscape::XML::Node *repr = sp_repr_new("svg:linearGradient");
+ 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
// (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
- Inkscape::XML::Node *stop = sp_repr_new("svg:stop");
+ Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop");
gchar b[64];
sp_svg_write_color(b, 64, color);
repr->appendChild(stop);
Inkscape::GC::release(stop);
- stop = sp_repr_new("svg:stop");
+ stop = xml_doc->createElement("svg:stop");
{
gchar *t = g_strdup_printf("stop-color:%s;stop-opacity:0;", b);
@@ -1121,6 +1241,7 @@ sp_gradient_vector_for_object(SPDocument *const doc, SPDesktop *const desktop,
return sp_document_default_gradient_vector(doc, rgba);
}
+
/*
Local Variables:
mode:c++