From d3b70fdd21b26ca93cba6fd50b65d3bf665ce0f5 Mon Sep 17 00:00:00 2001 From: mental Date: Sun, 4 Mar 2007 19:07:06 +0000 Subject: [PATCH] more NR::Maybe work --- src/gradient-chemistry.cpp | 70 ++++++++++++++++++-------------------- src/widgets/icon.cpp | 39 ++++++++++++--------- 2 files changed, 55 insertions(+), 54 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 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 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 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; diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 85666f76c..9be74a556 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -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(icon->psize) ); int const y1 = std::min(area->y + area->height, widget.allocation.y + pady + static_cast(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 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); -- 2.30.2