Trim trailing white spaces.
[geeqie.git] / src / pixbuf_util.c
index bdf5a98..6d4ad5b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -14,6 +14,7 @@
 #include "main.h"
 #include "pixbuf_util.h"
 #include "exif.h"
+#include "ui_fileops.h"
 
 #include "icons/icons_inline.h"
 
@@ -174,15 +175,34 @@ gboolean register_theme_icon_as_stock(const gchar *key, const gchar *icon)
                            64, /* size */
                            0,  /* flags */
                            &error);
-       if (!pixbuf) 
+       if (!pixbuf)
                {
                if (error)
                        {
-                       DEBUG_1("Couldn't load icon: %s", error->message);
+                       DEBUG_1("Couldn't load icon %s: %s", icon, error->message);
                        g_error_free(error);
+                       error = NULL;
+                       }
+                       
+               if (strchr(icon, '.'))
+                       {
+                       /* try again without extension */
+                       gchar *icon2 = remove_extension_from_path(icon);
+                       pixbuf = gtk_icon_theme_load_icon(icon_theme,
+                                          icon2, /* icon name */
+                                          64, /* size */
+                                          0,  /* flags */
+                                          &error);
+                       if (error)
+                               {
+                               DEBUG_1("Couldn't load icon %s: %s", icon2, error->message);
+                               g_error_free(error);
+                               }
+                       g_free(icon2);
                        }
-               return FALSE;
                }
+
+       if (!pixbuf) return FALSE;
        
        register_stock_icon(key, pixbuf);
        return TRUE;
@@ -329,10 +349,6 @@ GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gboolean counter_clockwise)
        gint dw, dh, drs;
        guchar *s_pix;
        guchar *d_pix;
-#if 0
-       guchar *sp;
-       guchar *dp;
-#endif
        gint i, j;
        gint a;
        GdkPixbuf *buffer;
@@ -760,32 +776,35 @@ void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *widge
                        gint x, gint y,
                        guint8 r, guint8 g, guint8 b, guint8 a)
 {
-       GdkPixmap *pixmap;
        GdkPixbuf *buffer;
        gint w, h;
-       GdkGC *gc;
        gint sx, sy;
        gint dw, dh;
-
-       if (!widget || !widget->window) return;
+       cairo_surface_t *source;
+       cairo_t *cr;
 
        pango_layout_get_pixel_size(layout, &w, &h);
        if (w < 1 || h < 1) return;
 
-       pixmap = gdk_pixmap_new(widget->window, w, h, -1);
-
-       gc = gdk_gc_new(widget->window);
-       gdk_gc_copy(gc, widget->style->black_gc);
-       gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, w, h);
-       gdk_gc_copy(gc, widget->style->white_gc);
-       gdk_draw_layout(pixmap, gc, 0, 0, layout);
-       g_object_unref(gc);
-
-       buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, w, h);
-       gdk_pixbuf_get_from_drawable(buffer, pixmap,
-                                    gdk_drawable_get_colormap(widget->window),
-                                    0, 0, 0, 0, w, h);
-       g_object_unref(pixmap);
+       source = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+
+       cr = cairo_create (source);
+       cairo_set_source_rgb(cr, 0, 0, 0);
+       cairo_rectangle (cr, 0, 0, w, h);
+       cairo_fill (cr);
+       cairo_set_source_rgb(cr, 1, 1, 1);
+       pango_cairo_show_layout (cr, layout);
+       cairo_destroy (cr);
+
+       buffer = gdk_pixbuf_new_from_data (cairo_image_surface_get_data (source),
+                                          GDK_COLORSPACE_RGB,
+                                          cairo_image_surface_get_format (source) == CAIRO_FORMAT_ARGB32,
+                                          8,
+                                          cairo_image_surface_get_width (source),
+                                          cairo_image_surface_get_height (source),
+                                          cairo_image_surface_get_stride (source),
+                                          NULL,
+                                          NULL);
 
        sx = 0;
        sy = 0;
@@ -814,6 +833,7 @@ void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *widge
                         r, g, b, a);
 
        g_object_unref(buffer);
+       cairo_surface_destroy(source);
 }
 
 /*
@@ -985,20 +1005,6 @@ static gboolean util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, g
                if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
                }
 
-#if 0
-       if (x1 >= clip_x && x2 <= clip_x + clip_w)
-               {
-               if (y1 < y2)
-                       {
-                       if (y1 >= clip_y && y2 <= clip_y + clip_h) return TRUE;
-                       }
-               else
-                       {
-                       if (y2 >= clip_y && y1 <= clip_y + clip_h) return TRUE;
-                       }
-               }
-#endif
-
        d = x2 - x1;
        if (d > 0.0)
                {