Code

Fixing preview/swatch sizes.
[inkscape.git] / src / widgets / icon.cpp
index 264349bd17f50a7d898c7d8e86400d32e04a3de6..8c582da83ca4ef1e4befdcf8547d60ab4accb7db 100644 (file)
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#include "path-prefix.h"
-
-
 
+#include <cstring>
 #include <glib/gmem.h>
 #include <gtk/gtkiconfactory.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtkimage.h>
-
 #include <gtkmm/image.h>
 
+#include "path-prefix.h"
 #include "prefs-utils.h"
 #include "inkscape.h"
 #include "document.h"
@@ -61,8 +59,6 @@ static guchar *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigne
 
 static guchar *sp_icon_image_load(SPIcon *icon, gchar const *name);
 
-static int sp_icon_get_phys_size(int size);
-
 static void sp_icon_overlay_pixels( guchar *px, int width, int height, int stride,
                                     unsigned r, unsigned g, unsigned b );
 
@@ -399,7 +395,7 @@ static void injectCustomSize()
 
 }
 
-static int sp_icon_get_phys_size(int size)
+int sp_icon_get_phys_size(int size)
 {
     static bool init = false;
     static int lastSys[Inkscape::ICON_SIZE_DECORATION + 1];
@@ -529,17 +525,22 @@ 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);
+        }
     }
 }
 
 static guchar *
-sp_icon_image_load_pixmap(gchar const *name, unsigned lsize, unsigned psize)
+sp_icon_image_load_pixmap(gchar const *name, unsigned /*lsize*/, unsigned psize)
 {
     gchar *path;
     guchar *px;
@@ -609,7 +610,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 )
             {
@@ -618,7 +619,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 +632,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 +664,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 +714,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);
 
@@ -759,7 +760,7 @@ static guchar *get_cached_pixels(Glib::ustring const &key) {
 }
 
 static guchar *load_svg_pixels(gchar const *name,
-                               unsigned lsize, unsigned psize)
+                               unsigned /*lsize*/, unsigned psize)
 {
     SPDocument *doc = NULL;
     NRArenaItem *root = NULL;
@@ -833,8 +834,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 {
@@ -849,10 +850,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) {
@@ -946,7 +947,7 @@ static void addPreRender( Inkscape::IconSize lsize, gchar const *name )
     pendingRenders.push(preRenderItem(lsize, name));
 }
 
-gboolean icon_prerender_task(gpointer data) {
+gboolean icon_prerender_task(gpointer /*data*/) {
     if (!pendingRenders.empty()) {
         preRenderItem single=pendingRenders.front();
         pendingRenders.pop();