Code

more NR::Maybe<NR::Rect> work
authormental <mental@users.sourceforge.net>
Sun, 4 Mar 2007 19:07:06 +0000 (19:07 +0000)
committermental <mental@users.sourceforge.net>
Sun, 4 Mar 2007 19:07:06 +0000 (19:07 +0000)
src/gradient-chemistry.cpp
src/widgets/icon.cpp

index 1a161b2010047b8d69c4bcb4e69db3388539da7e..c49eaab18ff7ec8902631487e14eb274cffd64f7 100644 (file)
@@ -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;
index 85666f76c5b04f3eb733b278b9f3b69936957e15..9be74a556f9151431dee10c24372351cd6702599 100644 (file)
@@ -529,12 +529,17 @@ static void sp_icon_paint(SPIcon *icon, GdkRectangle const *area)
         int const x1 = std::min(area->x + area->width,  widget.allocation.x + padx + static_cast<int>(icon->psize) );
         int const y1 = std::min(area->y + area->height, widget.allocation.y + pady + static_cast<int>(icon->psize) );
 
-        gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), NULL, image,
-                        x0 - widget.allocation.x - padx,
-                        y0 - widget.allocation.y - pady,
-                        x0, y0,
-                        x1 - x0, y1 - y0,
-                        GDK_RGB_DITHER_NORMAL, x0, y0);
+        int width = x1 - x0;
+        int height = y1 - y0;
+        // Limit drawing to when we actually have something. Avoids some crashes.
+        if ( (width > 0) && (height > 0) ) {
+            gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), NULL, image,
+                            x0 - widget.allocation.x - padx,
+                            y0 - widget.allocation.y - pady,
+                            x0, y0,
+                            width, height,
+                            GDK_RGB_DITHER_NORMAL, x0, y0);
+        }
     }
 }
 
@@ -609,7 +614,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
         if (object && SP_IS_ITEM(object)) {
             /* Find bbox in document */
             NR::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
-            NR::Rect dbox = SP_ITEM(object)->getBounds(i2doc);
+            NR::Maybe<NR::Rect> dbox = SP_ITEM(object)->getBounds(i2doc);
 
             if ( SP_OBJECT_PARENT(object) == NULL )
             {
@@ -618,7 +623,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
             }
 
             /* This is in document coordinates, i.e. pixels */
-            if (dbox.isEmpty() == false) {
+            if ( dbox && !dbox->isEmpty() ) {
                 NRGC gc(NULL);
                 /* Update to renderable state */
                 double sf = 1.0;
@@ -631,10 +636,10 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                                              NR_ARENA_ITEM_STATE_NONE );
                 /* Item integer bbox in points */
                 NRRectL ibox;
-                ibox.x0 = (int) floor(sf * dbox.min()[NR::X] + 0.5);
-                ibox.y0 = (int) floor(sf * dbox.min()[NR::Y] + 0.5);
-                ibox.x1 = (int) floor(sf * dbox.max()[NR::X] + 0.5);
-                ibox.y1 = (int) floor(sf * dbox.max()[NR::Y] + 0.5);
+                ibox.x0 = (int) floor(sf * dbox->min()[NR::X] + 0.5);
+                ibox.y0 = (int) floor(sf * dbox->min()[NR::Y] + 0.5);
+                ibox.x1 = (int) floor(sf * dbox->max()[NR::X] + 0.5);
+                ibox.y1 = (int) floor(sf * dbox->max()[NR::Y] + 0.5);
 
                 if ( dump ) {
                     g_message( "   box    --'%s'  (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 );
@@ -663,10 +668,10 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                                                      NR_ARENA_ITEM_STATE_ALL,
                                                      NR_ARENA_ITEM_STATE_NONE );
                         /* Item integer bbox in points */
-                        ibox.x0 = (int) floor(sf * dbox.min()[NR::X] + 0.5);
-                        ibox.y0 = (int) floor(sf * dbox.min()[NR::Y] + 0.5);
-                        ibox.x1 = (int) floor(sf * dbox.max()[NR::X] + 0.5);
-                        ibox.y1 = (int) floor(sf * dbox.max()[NR::Y] + 0.5);
+                        ibox.x0 = (int) floor(sf * dbox->min()[NR::X] + 0.5);
+                        ibox.y0 = (int) floor(sf * dbox->min()[NR::Y] + 0.5);
+                        ibox.x1 = (int) floor(sf * dbox->max()[NR::X] + 0.5);
+                        ibox.y1 = (int) floor(sf * dbox->max()[NR::Y] + 0.5);
 
                         if ( dump ) {
                             g_message( "   box2   --'%s'  (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 );
@@ -713,7 +718,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                                           px + 4 * psize * (ua.y0 - area.y0) +
                                           4 * (ua.x0 - area.x0),
                                           4 * psize, FALSE, FALSE );
-                nr_arena_item_invoke_render( root, &ua, &B,
+                nr_arena_item_invoke_render(NULL, root, &ua, &B,
                                              NR_ARENA_ITEM_RENDER_NO_CACHE );
                 nr_pixblock_release(&B);