Code

Adding ICC Profiles in X support
[inkscape.git] / src / widgets / icon.cpp
index b170d69f815352add2d1ef364e853b849a11f76a..9be74a556f9151431dee10c24372351cd6702599 100644 (file)
@@ -35,8 +35,6 @@
 
 #include "icon.h"
 
-// JON: keeping legacy gboolean because of old code
-// TODO: replace gboolean with bool
 static gboolean icon_prerender_task(gpointer data);
 
 static void addPreRender( Inkscape::IconSize lsize, gchar const *name );
@@ -275,7 +273,7 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
     addPreRender( lsize, name );
 
     GtkStockItem stock;
-    bool tryLoad = gtk_stock_lookup( name, &stock );
+    gboolean tryLoad = gtk_stock_lookup( name, &stock );
     if ( !tryLoad && fallback ) {
         tryLoad |= strncmp("gtk-", name, 4 ) == 0;
     }
@@ -531,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);
+        }
     }
 }
 
@@ -611,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)->invokeBbox(i2doc);
+            NR::Maybe<NR::Rect> dbox = SP_ITEM(object)->getBounds(i2doc);
 
             if ( SP_OBJECT_PARENT(object) == NULL )
             {
@@ -620,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;
@@ -633,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 );
@@ -665,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 );
@@ -715,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);
 
@@ -835,8 +838,8 @@ static guchar *load_svg_pixels(gchar const *name,
 // returns true if icon needed preloading, false if nothing was done
 static bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize)
 {
-    Glib::ustring key=icon_cache_key(name, lsize, psize);
-    guchar *px=get_cached_pixels(key);
+    Glib::ustring key = icon_cache_key(name, lsize, psize);
+    guchar *px = get_cached_pixels(key);
     if (px) {
         return false;
     } else {
@@ -851,10 +854,10 @@ static bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize)
 static guchar *
 sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigned psize)
 {
-    Glib::ustring key=icon_cache_key(name, lsize, psize);
+    Glib::ustring key = icon_cache_key(name, lsize, psize);
 
     // did we already load this icon at this scale/size?
-    guchar *px=get_cached_pixels(key);
+    guchar *px = get_cached_pixels(key);
     if (!px) {
         px = load_svg_pixels(name, lsize, psize);
         if (px) {