summaryrefslogtreecommitdiffstats
path: root/src/gradient-chemistry.cpp
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-03-04 19:07:06 +0000
committermental <mental@users.sourceforge.net>2007-03-04 19:07:06 +0000
commit2bc71af7910026787436a5013454a58b6bb3ec93 (patch)
tree0e6a25a344bcaaf31bc4138d099ba03d65519d44 /src/gradient-chemistry.cpp
parentreturn plain rect for union in all situations where a plain rect is given (diff)
downloadinkscape-2bc71af7910026787436a5013454a58b6bb3ec93.tar.gz
inkscape-2bc71af7910026787436a5013454a58b6bb3ec93.zip
more NR::Maybe<NR::Rect> work
(bzr r2543)
Diffstat (limited to 'src/gradient-chemistry.cpp')
-rw-r--r--src/gradient-chemistry.cpp70
1 files changed, 33 insertions, 37 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 1a161b201..c49eaab18 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -258,13 +258,13 @@ sp_gradient_reset_to_userspace (SPGradient *gr, SPItem *item)
// calculate the bbox of the item
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
- NR::Rect const bbox = item->getBounds(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
- NR::Coord const width = bbox.dimensions()[NR::X];
- NR::Coord const height = bbox.dimensions()[NR::Y];
- g_assert(width > 0 && height > 0);
+ g_assert( bbox && !bbox->isEmpty() );
+ 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]);
@@ -280,12 +280,9 @@ sp_gradient_reset_to_userspace (SPGradient *gr, SPItem *item)
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]);
@@ -319,10 +316,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->getBounds(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
@@ -350,12 +353,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
@@ -423,12 +423,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 *
@@ -925,12 +922,9 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::
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);
}
@@ -1022,10 +1016,12 @@ sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool
if (SP_GRADIENT(gradient)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
- NR::Rect const bbox = item->getBounds(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;