Trim trailing white spaces.
[geeqie.git] / src / print.c
index 9b93cb8..25eb5cc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -10,7 +10,6 @@
  * This software comes with no warranty of any kind, use at your own risk!
  */
 
-
 #include "main.h"
 #include "print.h"
 
 #include "ui_spinner.h"
 #include "ui_tabcomp.h"
 
-
 #include <locale.h>
 #include <signal.h>
-
+#include <glib/gprintf.h>
 
 #define PRINT_LPR_COMMAND "lpr"
 #define PRINT_LPR_CUSTOM  "lpr -P %s"
@@ -234,7 +232,7 @@ struct _PrintWindow
        gdouble layout_width;
        gdouble layout_height;
 
-       gint layout_idle_id;
+       guint layout_idle_id; /* event source id */
 
        gdouble image_scale;
 
@@ -321,9 +319,9 @@ static void print_window_close(PrintWindow *pw);
 
 /* misc utils */
 
-static gint clip_region(gdouble x1, gdouble y1, gdouble w1, gdouble h1,
-                       gdouble x2, gdouble y2, gdouble w2, gdouble h2,
-                       gdouble *rx, gdouble *ry, gdouble *rw, gdouble *rh)
+static gboolean clip_region(gdouble x1, gdouble y1, gdouble w1, gdouble h1,
+                           gdouble x2, gdouble y2, gdouble w2, gdouble h2,
+                           gdouble *rx, gdouble *ry, gdouble *rw, gdouble *rh)
 {
        if (x2 + w2 <= x1 || x2 >= x1 + w1 ||
            y2 + h2 <= y1 || y2 >= y1 + h1)
@@ -572,10 +570,10 @@ static void print_window_layout_status(PrintWindow *pw)
 
 static void print_window_layout_render_stop(PrintWindow *pw)
 {
-       if (pw->layout_idle_id != -1)
+       if (pw->layout_idle_id)
                {
                g_source_remove(pw->layout_idle_id);
-               pw->layout_idle_id = -1;
+               pw->layout_idle_id = 0;
                }
 }
 
@@ -586,7 +584,7 @@ static gboolean print_window_layout_render_idle(gpointer data)
        print_job_close(pw, FALSE);
        print_job_start(pw, RENDER_FORMAT_PREVIEW, 0);
 
-       pw->layout_idle_id = -1;
+       pw->layout_idle_id = 0;
        return FALSE;
 }
 
@@ -600,7 +598,7 @@ static void print_window_layout_render(PrintWindow *pw)
 
        print_window_layout_status(pw);
 
-       if (pw->layout_idle_id == -1)
+       if (!pw->layout_idle_id)
                {
                pw->layout_idle_id = g_idle_add(print_window_layout_render_idle, pw);
                }
@@ -752,7 +750,7 @@ static GtkWidget *print_window_layout_setup(PrintWindow *pw, GtkWidget *box)
        vbox = pref_box_new(box, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
        group = pref_frame_new(vbox, TRUE, _("Preview"), GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
 
-       pw->layout_idle_id = -1;
+       pw->layout_idle_id = 0;
 
        pw->layout_image = image_new(FALSE);
        gtk_widget_set_size_request(pw->layout_image->widget, PRINT_DLG_PREVIEW_WIDTH, PRINT_DLG_PREVIEW_HEIGHT);
@@ -1010,10 +1008,10 @@ static void pipe_handler_free(PipeError *pe)
        g_free(pe);
 }
 
-static gint pipe_handler_check(PipeError *pe)
+static gboolean pipe_handler_check(PipeError *pe)
 {
        if (!pe) return FALSE;
-       return *pe->error;
+       return !!(*pe->error);
 }
 
 static FILE *print_job_ps_fd(PrintWindow *pw)
@@ -1023,14 +1021,14 @@ static FILE *print_job_ps_fd(PrintWindow *pw)
        return NULL;
 }
 
-static gint print_job_ps_init(PrintWindow *pw)
+static gboolean print_job_ps_init(PrintWindow *pw)
 {
        FILE *f;
        PipeError *pe;
        const gchar *cmd = NULL;
        const gchar *path = NULL;
        gchar *lc_pointer;
-       gint ret;
+       gboolean ret;
 
        if (pw->job_file != NULL || pw->job_pipe != NULL) return FALSE;
 
@@ -1108,29 +1106,30 @@ static gint print_job_ps_init(PrintWindow *pw)
        pe = pipe_handler_new();
 
        /* comments, etc. */
-       fprintf(f, "%%!PS-Adobe-3.0\n");
-       fprintf(f, "%%%%Creator: %s Version %s\n", GQ_APPNAME, VERSION);
-       fprintf(f, "%%%%CreationDate: \n");
-       fprintf(f, "%%%%LanguageLevel 2\n");
-       fprintf(f, "%%%%DocumentMedia: \n");
-       fprintf(f, "%%%%Orientation: %s\n",
+       g_fprintf(f, "%%!PS-Adobe-3.0\n");
+       g_fprintf(f, "%%%%Creator: %s Version %s\n", GQ_APPNAME, VERSION);
+       g_fprintf(f, "%%%%CreationDate: \n");
+       g_fprintf(f, "%%%%LanguageLevel 2\n");
+       g_fprintf(f, "%%%%DocumentMedia: \n");
+       g_fprintf(f, "%%%%Orientation: %s\n",
                (pw->paper_orientation == PAPER_ORIENTATION_PORTRAIT) ? "Portrait" : "Landscape");
-       fprintf(f, "%%%%BoundingBox: %f %f %f %f\n",
+       g_fprintf(f, "%%%%BoundingBox: %f %f %f %f\n",
                0.0, 0.0, pw->paper_width, pw->paper_height);
-       fprintf(f, "%%%%Pages: %d\n", print_layout_page_count(pw));
-       fprintf(f, "%%%%PageOrder: Ascend\n");
-       fprintf(f, "%%%%Title:\n");
+       g_fprintf(f, "%%%%Pages: %d\n", print_layout_page_count(pw));
+       g_fprintf(f, "%%%%PageOrder: Ascend\n");
+       g_fprintf(f, "%%%%Title:\n");
 
        /* setup page size, coordinates (do we really need this?) */
-#if 0
-       fprintf(f, "<<\n");
-       fprintf(f, "/PageSize [%f %f]\n", pw->layout_width, pw->layout_height);
-       fprintf(f, "/ImagingBBox [%f %f %f %f]\n", /* l b r t */
+       /* enabled for 1.0beta2  https://bugzilla.redhat.com/222639 */
+#if 1
+       g_fprintf(f, "<<\n");
+       g_fprintf(f, "/PageSize [%f %f]\n", pw->layout_width, pw->layout_height);
+       g_fprintf(f, "/ImagingBBox [%f %f %f %f]\n", /* l b r t */
                pw->margin_left, pw->margin_bottom,
                pw->layout_width - pw->margin_right, pw->layout_height - pw->margin_top);
-       fprintf(f, "/Orientation %d\n",
+       g_fprintf(f, "/Orientation %d\n",
                (pw->paper_orientation == PAPER_ORIENTATION_PORTRAIT) ? 0 : 1);
-       fprintf(f, ">> setpagedevice\n");
+       g_fprintf(f, ">> setpagedevice\n");
 #endif
 
        ret = !pipe_handler_check(pe);
@@ -1147,12 +1146,12 @@ static gint print_job_ps_init(PrintWindow *pw)
        return ret;
 }
 
-static gint print_job_ps_page_new(PrintWindow *pw, gint page)
+static gboolean print_job_ps_page_new(PrintWindow *pw, gint page)
 {
        FILE *f;
        PipeError *pe;
        gchar *lc_pointer;
-       gint ret;
+       gboolean ret;
 
        f= print_job_ps_fd(pw);
        if (!f) return FALSE;
@@ -1162,12 +1161,12 @@ static gint print_job_ps_page_new(PrintWindow *pw, gint page)
 
        pe = pipe_handler_new();
 
-       fprintf(f, "%%%% page %d\n", page + 1);
+       g_fprintf(f, "%%%% page %d\n", page + 1);
 
        if (pw->paper_orientation == PAPER_ORIENTATION_LANDSCAPE)
                {
-               fprintf(f, "/pagelevel save def\n");
-               fprintf(f, "%d 0 translate 90 rotate\n", (gint)pw->layout_height);
+               g_fprintf(f, "/pagelevel save def\n");
+               g_fprintf(f, "%d 0 translate 90 rotate\n", (gint)pw->layout_height);
                }
 
        ret = !pipe_handler_check(pe);
@@ -1184,12 +1183,12 @@ static gint print_job_ps_page_new(PrintWindow *pw, gint page)
        return ret;
 }
 
-static gint print_job_ps_page_done(PrintWindow *pw)
+static gboolean print_job_ps_page_done(PrintWindow *pw)
 {
        FILE *f;
        PipeError *pe;
        gchar *lc_pointer;
-       gint ret;
+       gboolean ret;
 
        f = print_job_ps_fd(pw);
        if (!f) return FALSE;
@@ -1201,10 +1200,10 @@ static gint print_job_ps_page_done(PrintWindow *pw)
 
        if (pw->paper_orientation == PAPER_ORIENTATION_LANDSCAPE)
                {
-               fprintf(f, "pagelevel restore\n");
+               g_fprintf(f, "pagelevel restore\n");
                }
 
-       fprintf(f, "showpage\n");
+       g_fprintf(f, "showpage\n");
 
        ret = !pipe_handler_check(pe);
        pipe_handler_free(pe);
@@ -1233,11 +1232,11 @@ static void print_job_ps_page_image_pixel(FILE *f, guchar *pix)
                }
        text[6] = '\0';
 
-       fprintf(f, "%s", text);
+       g_fprintf(f, "%s", text);
 }
-static gint print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
-                                   gdouble x, gdouble y, gdouble w, gdouble h,
-                                   gdouble offx, gdouble offy)
+static gboolean print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
+                                       gdouble x, gdouble y, gdouble w, gdouble h,
+                                       gdouble offx, gdouble offy)
 {
        FILE *f;
        PipeError *pe;
@@ -1250,7 +1249,7 @@ static gint print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
        gint c;
        guchar *p;
        guchar bps_buf[3];
-       gint ret;
+       gboolean ret;
 
        if (!pixbuf) return TRUE;
 
@@ -1284,13 +1283,13 @@ static gint print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
 
        pe = pipe_handler_new();
 
-       fprintf(f, "gsave\n");
-       fprintf(f, "[%f 0 0 %f %f %f] concat\n", w, h, x, pw->layout_height - h - y);
-       fprintf(f, "/buf %d string def\n", sw * 3);
-       fprintf(f, "%d %d %d\n", sw, sh, 8);
-       fprintf(f, "[%d 0 0 -%d 0 %d]\n", sw, sh, sh);
-       fprintf(f, "{ currentfile buf readhexstring pop }\n");
-       fprintf(f, "false %d colorimage\n", 3);
+       g_fprintf(f, "gsave\n");
+       g_fprintf(f, "[%f 0 0 %f %f %f] concat\n", w, h, x, pw->layout_height - h - y);
+       g_fprintf(f, "/buf %d string def\n", sw * 3);
+       g_fprintf(f, "%d %d %d\n", sw, sh, 8);
+       g_fprintf(f, "[%d 0 0 -%d 0 %d]\n", sw, sh, sh);
+       g_fprintf(f, "{ currentfile buf readhexstring pop }\n");
+       g_fprintf(f, "false %d colorimage\n", 3);
 
        c = 0;
        for (j = 0; j < sh; j++)
@@ -1313,13 +1312,13 @@ static gint print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
                        c++;
                        if (c > 11)
                                {
-                               fprintf(f, "\n");
+                               g_fprintf(f, "\n");
                                c = 0;
                                }
                        }
                }
-       if (c > 0) fprintf(f, "\n");
-       fprintf(f, "grestore\n");
+       if (c > 0) g_fprintf(f, "\n");
+       g_fprintf(f, "grestore\n");
 
        ret = !pipe_handler_check(pe);
        pipe_handler_free(pe);
@@ -1337,103 +1336,54 @@ static gint print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
        return ret;
 }
 
-static const gchar *ps_text_to_hex_array(FILE *f, const gchar *text, gdouble x, gdouble y)
-{
-       static gchar hex_digits[] = "0123456789abcdef";
-       const gchar *p;
-
-       if (!text) return NULL;
-
-       fprintf(f, "%f %f moveto\n", x, y);
-       fprintf(f, "<");
-
-       /* fixme: convert utf8 to ascii or proper locale string.. */
-
-       p = text;
-       while (*p != '\0' && *p != '\n')
-               {
-               gchar text[3];
-
-               text[0] = hex_digits[*p >> 4];
-               text[1] = hex_digits[*p & 0xf];
-               text[2] = '\0';
-
-               fprintf(f, "%s", text);
-
-               p++;
-               }
-
-       fprintf(f, ">\n");
-       fprintf(f, "dup stringwidth pop 2 div neg 0 rmoveto show\n");
-
-       return p;
-}
-
-static void ps_text_parse(FILE *f, const gchar *text, gdouble x, gdouble y, gdouble point_size)
-{
-       const gchar *p;
-
-       if (!text) return;
-
-       fprintf(f, "newpath\n");
-
-       p = text;
-       while (p && *p != '\0')
-               {
-               p = ps_text_to_hex_array(f, p, x, y);
-               if (p && *p == '\n') p++;
-               y -= point_size;
-               }
-
-       fprintf(f, "closepath\n");
-}
+static gdouble convert_pango_dpi(gdouble points);
 
-static gint print_job_ps_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
-                                  gdouble x, gdouble y, gdouble width,
-                                  guint8 r, guint8 g, guint8 b)
+static gboolean print_job_ps_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
+                                      gdouble x, gdouble y, gdouble width,
+                                      guint8 r, guint8 g, guint8 b)
 {
-       FILE *f;
-       PipeError *pe;
-       gchar *lc_pointer;
-       gint ret;
-
-       if (!text) return TRUE;
-
-       f = print_job_ps_fd(pw);
-       if (!f) return FALSE;
+       PangoLayout *layout;
+       PangoFontDescription *desc;
+       GdkPixbuf *pixbuf;
+       gint lw, lh;
+       gboolean ret;
+       gdouble scale_to_max_dpi = (pw->max_dpi >= PRINT_PS_DPI_MIN) ? pw->max_dpi / 72.0 : 1200.0 / 72.0;
 
-       lc_pointer = g_strdup(setlocale(LC_NUMERIC, NULL));
-       setlocale(LC_NUMERIC, POSTSCRIPT_LOCALE);
+       layout = gtk_widget_create_pango_layout(pw->dialog->dialog, NULL);
 
-       pe = pipe_handler_new();
+       desc = pango_font_description_new();
+       pango_font_description_set_size(desc, convert_pango_dpi(point_size) * PANGO_SCALE * scale_to_max_dpi);
+       pango_layout_set_font_description(layout, desc);
+       pango_font_description_free(desc);
 
-       fprintf(f, "/Sans findfont\n");
-       fprintf(f, "%f scalefont\n", point_size);
-       fprintf(f, "setfont\n");
+       pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
+       pango_layout_set_text(layout, text, -1);
 
-       fprintf(f, "%f %f %f setrgbcolor\n", (gdouble)r / 255.0, (gdouble)g / 255.0, (gdouble)b / 255.0);
-       ps_text_parse(f, text, x, pw->layout_height - y - point_size, point_size);
+       pango_layout_get_pixel_size(layout, &lw, &lh);
+       x = x - (gdouble)lw / 2.0 / scale_to_max_dpi;
 
-       ret = !pipe_handler_check(pe);
-       pipe_handler_free(pe);
+       pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, lw, lh);
+       gdk_pixbuf_fill(pixbuf, 0xffffffff);
+       pixbuf_draw_layout(pixbuf, layout, pw->dialog->dialog, 0, 0, r, g, b, 255);
+       g_object_unref(G_OBJECT(layout));
 
-       if (lc_pointer)
-               {
-               setlocale(LC_NUMERIC, lc_pointer);
-               g_free(lc_pointer);
-               }
+       ret = print_job_ps_page_image(pw, pixbuf, x, y,
+                                      /* do not allow rescaling of the pixbuf due to rounding errors */
+                                     ((gdouble)lw + 0.01) / scale_to_max_dpi,
+                                     ((gdouble)lh + 0.01) / scale_to_max_dpi,
+                                     0, 0);
 
-       if (!ret) print_job_throw_error(pw, _("SIGPIPE error writing to printer."));
+       g_object_unref(G_OBJECT(pixbuf));
 
        return ret;
 }
 
-static gint print_job_ps_end(PrintWindow *pw)
+static gboolean print_job_ps_end(PrintWindow *pw)
 {
        FILE *f;
        PipeError *pe;
        gchar *lc_pointer;
-       gint ret;
+       gboolean ret;
 
        f = print_job_ps_fd(pw);
        if (!f) return FALSE;
@@ -1443,7 +1393,7 @@ static gint print_job_ps_end(PrintWindow *pw)
 
        pe = pipe_handler_new();
 
-       fprintf(f, "%%%%EOF\n");
+       g_fprintf(f, "%%%%EOF\n");
 
        ret = !pipe_handler_check(pe);
        pipe_handler_free(pe);
@@ -1465,7 +1415,7 @@ static gint print_job_ps_end(PrintWindow *pw)
  *-----------------------------------------------------------------------------
  */
 
-static gint print_job_rgb_page_new(PrintWindow *pw, gint page)
+static gboolean print_job_rgb_page_new(PrintWindow *pw, gint page)
 {
        gint total;
 
@@ -1524,10 +1474,10 @@ static gint print_job_rgb_page_new(PrintWindow *pw, gint page)
        return (pw->job_path != NULL);
 }
 
-static gint print_job_rgb_page_done(PrintWindow *pw)
+static gboolean print_job_rgb_page_done(PrintWindow *pw)
 {
        gchar *pathl;
-       gint ret = FALSE;
+       gboolean ret = FALSE;
 
        if (!pw->job_pixbuf) return FALSE;
 
@@ -1576,9 +1526,9 @@ static gint print_job_rgb_page_done(PrintWindow *pw)
        return ret;
 }
 
-static gint print_job_rgb_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
-                                    gdouble x, gdouble y, gdouble w, gdouble h,
-                                    gdouble offx, gdouble offy)
+static gboolean print_job_rgb_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
+                                        gdouble x, gdouble y, gdouble w, gdouble h,
+                                        gdouble offx, gdouble offy)
 {
        gdouble sw, sh;
        gdouble dw, dh;
@@ -1626,7 +1576,7 @@ static gdouble convert_pango_dpi(gdouble points)
 
                if (dpi < 25.0)
                        {
-                       static gint warned = FALSE;
+                       static gboolean warned = FALSE;
                        gdouble fallback_dpi = 96.0;
 
                        if (!warned)
@@ -1650,9 +1600,9 @@ static gdouble convert_pango_dpi(gdouble points)
        return points * 72.0 / dpi;
 }
 
-static gint print_job_rgb_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
-                                   gdouble x, gdouble y, gdouble width,
-                                   guint8 r, guint8 g, guint8 b)
+static gboolean print_job_rgb_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
+                                       gdouble x, gdouble y, gdouble width,
+                                       guint8 r, guint8 g, guint8 b)
 {
        PangoLayout *layout;
        PangoFontDescription *desc;
@@ -1679,7 +1629,7 @@ static gint print_job_rgb_page_text(PrintWindow *pw, const gchar *text, gdouble
        return TRUE;
 }
 
-static gint print_job_rgb_init(PrintWindow *pw)
+static gboolean print_job_rgb_init(PrintWindow *pw)
 {
        if (pw->job_pixbuf) g_object_unref(pw->job_pixbuf);
        pw->job_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
@@ -1694,7 +1644,7 @@ static gint print_job_rgb_init(PrintWindow *pw)
  *-----------------------------------------------------------------------------
  */
 
-static gint print_job_preview_page_new(PrintWindow *pw, gint page)
+static gboolean print_job_preview_page_new(PrintWindow *pw, gint page)
 {
        GdkPixbuf *pixbuf;
        gint w, h;
@@ -1782,14 +1732,14 @@ static gint print_job_preview_page_new(PrintWindow *pw, gint page)
        return TRUE;
 }
 
-static gint print_job_preview_page_done(PrintWindow *pw)
+static gboolean print_job_preview_page_done(PrintWindow *pw)
 {
        return TRUE;
 }
 
-static gint print_job_preview_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
-                                        gdouble x, gdouble y, gdouble w, gdouble h,
-                                        gdouble offx, gdouble offy)
+static gboolean print_job_preview_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
+                                            gdouble x, gdouble y, gdouble w, gdouble h,
+                                            gdouble offx, gdouble offy)
 {
        gdouble sw, sh;
        gdouble dw, dh;
@@ -1826,9 +1776,9 @@ static gint print_job_preview_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
        return TRUE;
 }
 
-static gint print_job_preview_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
-                                       gdouble x, gdouble y, gdouble width,
-                                       guint8 r, guint8 g, guint8 b)
+static gboolean print_job_preview_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
+                                           gdouble x, gdouble y, gdouble width,
+                                           guint8 r, guint8 g, guint8 b)
 {
        PangoLayout *layout;
        PangoFontDescription *desc;
@@ -1861,7 +1811,7 @@ static gint print_job_preview_page_text(PrintWindow *pw, const gchar *text, gdou
        return TRUE;
 }
 
-static gint print_job_preview_init(PrintWindow *pw)
+static gboolean print_job_preview_init(PrintWindow *pw)
 {
        if (pw->job_pixbuf) g_object_unref(pw->job_pixbuf);
        pw->job_pixbuf = image_get_pixbuf(pw->layout_image);
@@ -1877,7 +1827,7 @@ static gint print_job_preview_init(PrintWindow *pw)
  *-----------------------------------------------------------------------------
  */
 
-static gint print_job_page_new(PrintWindow *pw)
+static gboolean print_job_page_new(PrintWindow *pw)
 {
        switch (pw->job_format)
                {
@@ -1892,7 +1842,7 @@ static gint print_job_page_new(PrintWindow *pw)
        return FALSE;
 }
 
-static gint print_job_page_done(PrintWindow *pw)
+static gboolean print_job_page_done(PrintWindow *pw)
 {
        switch (pw->job_format)
                {
@@ -1907,11 +1857,11 @@ static gint print_job_page_done(PrintWindow *pw)
        return FALSE;
 }
 
-static gint print_job_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
-                                gdouble x, gdouble y, gdouble w, gdouble h,
-                                gdouble offx, gdouble offy)
+static gboolean print_job_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
+                                    gdouble x, gdouble y, gdouble w, gdouble h,
+                                    gdouble offx, gdouble offy)
 {
-       gint success = FALSE;
+       gboolean success = FALSE;
 
        if (w <= 0.0 || h <= 0.0) return TRUE;
 
@@ -1931,11 +1881,11 @@ static gint print_job_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
        return success;
 }
 
-static gint print_job_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
-                               gdouble x, gdouble y, gdouble width,
-                               guint8 r, guint8 g, guint8 b)
+static gboolean print_job_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
+                                   gdouble x, gdouble y, gdouble width,
+                                   guint8 r, guint8 g, guint8 b)
 {
-       gint success = TRUE;
+       gboolean success = TRUE;
 
        if (!text) return TRUE;
 
@@ -1961,8 +1911,8 @@ static gint print_job_page_text(PrintWindow *pw, const gchar *text, gdouble poin
  *-----------------------------------------------------------------------------
  */
 
-static gint print_job_render_image(PrintWindow *pw);
-static gint print_job_render_proof(PrintWindow *pw);
+static gboolean print_job_render_image(PrintWindow *pw);
+static gboolean print_job_render_proof(PrintWindow *pw);
 
 
 static void print_job_status(PrintWindow *pw)
@@ -2009,7 +1959,7 @@ static void print_job_throw_error(PrintWindow *pw, const gchar *message)
        GtkWidget *label;
        gchar *buf;
 
-       if (GTK_WIDGET_VISIBLE(pw->dialog->dialog)) parent = pw->dialog->dialog;
+       if (gtk_widget_get_visible(pw->dialog->dialog)) parent = pw->dialog->dialog;
 
        gd = generic_dialog_new(_("Printing error"), "print_warning",
                                parent, TRUE, NULL, NULL);
@@ -2031,14 +1981,14 @@ static void print_job_done(PrintWindow *pw)
        print_job_close(pw, FALSE);
 }
 
-static gint print_job_text_image(PrintWindow *pw, const gchar *path,
-                                gdouble x, gdouble y, gdouble width,
-                                gint sw, gint sh, gint proof)
+static gboolean print_job_text_image(PrintWindow *pw, const gchar *path,
+                                    gdouble x, gdouble y, gdouble width,
+                                    gint sw, gint sh, gint proof)
 {
        GString *string;
-       gint space = FALSE;
-       gint newline = FALSE;
-       gint ret;
+       gboolean space = FALSE;
+       gboolean newline = FALSE;
+       gboolean ret;
 
        if (pw->text_fields == 0) return TRUE;
 
@@ -2099,7 +2049,7 @@ static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
 {
        PrintWindow *pw = data;
        GdkPixbuf *pixbuf;
-       gint success = TRUE;
+       gboolean success = TRUE;
 
        pixbuf = image_loader_get_pixbuf(il);
        if (pixbuf)
@@ -2107,7 +2057,6 @@ static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
                gdouble sw, sh;
                gdouble dw, dh;
                gdouble x, y, w, h;
-               gdouble scale;
                gdouble offx, offy;
 
                sw = (gdouble)gdk_pixbuf_get_width(pixbuf);
@@ -2120,13 +2069,11 @@ static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
                        {
                        w = dw;
                        h = dw / sw * sh;
-                       scale = w / sw;
                        }
                else
                        {
                        h = dh;
                        w = dh / sh *sw;
-                       scale = h / sh;
                        }
 
                if (pw->image_scale >= 5.0)
@@ -2195,7 +2142,7 @@ static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
                }
 }
 
-static gint print_job_render_image(PrintWindow *pw)
+static gboolean print_job_render_image(PrintWindow *pw)
 {
        FileData *fd = NULL;
 
@@ -2219,7 +2166,7 @@ static gint print_job_render_image(PrintWindow *pw)
        if (!fd) return FALSE;
 
        pw->job_loader = image_loader_new(fd);
-       g_signal_connect (G_OBJECT(pw->job_loader), "done", (GCallback)print_job_render_image_loader_done, pw);
+       g_signal_connect(G_OBJECT(pw->job_loader), "done", (GCallback)print_job_render_image_loader_done, pw);
        if (!image_loader_start(pw->job_loader))
                {
                image_loader_free(pw->job_loader);
@@ -2237,8 +2184,7 @@ static void print_job_render_proof_loader_done(ImageLoader *il, gpointer data)
        gdouble w, h;
        gdouble proof_w, proof_h;
        gdouble icon_w, icon_h;
-       gdouble scale;
-       gint success = TRUE;
+       gboolean success = TRUE;
 
        if (pw->proof_columns < 1 || pw->proof_rows < 1)
                {
@@ -2252,6 +2198,10 @@ static void print_job_render_proof_loader_done(ImageLoader *il, gpointer data)
 
        pixbuf = image_loader_get_pixbuf(il);
 
+       if (options->image.exif_proof_rotate_enable == TRUE) {
+               pixbuf = pixbuf_apply_orientation(pixbuf, il->fd->exif_orientation);
+       }
+
        w = gdk_pixbuf_get_width(pixbuf);
        h = gdk_pixbuf_get_height(pixbuf);
 
@@ -2259,13 +2209,11 @@ static void print_job_render_proof_loader_done(ImageLoader *il, gpointer data)
                {
                icon_w = pw->proof_width;
                icon_h = pw->proof_width / w * h;
-               scale = icon_w / w;
                }
        else
                {
                icon_h = pw->proof_height;
                icon_w = pw->proof_height / h * w;
-               scale = icon_h / h;
                }
 
        y = pw->proof_position / pw->proof_columns;
@@ -2346,7 +2294,7 @@ static void print_job_render_proof_loader_done(ImageLoader *il, gpointer data)
                }
 }
 
-static gint print_job_render_proof(PrintWindow *pw)
+static gboolean print_job_render_proof(PrintWindow *pw)
 {
        FileData *fd = NULL;
 
@@ -2366,7 +2314,7 @@ static gint print_job_render_proof(PrintWindow *pw)
 
        image_loader_free(pw->job_loader);
        pw->job_loader = image_loader_new(fd);
-       g_signal_connect (G_OBJECT(pw->job_loader), "done", (GCallback)print_job_render_proof_loader_done, pw);
+       g_signal_connect(G_OBJECT(pw->job_loader), "done", (GCallback)print_job_render_proof_loader_done, pw);
        if (!image_loader_start(pw->job_loader))
                {
                image_loader_free(pw->job_loader);
@@ -2379,7 +2327,7 @@ static gint print_job_render_proof(PrintWindow *pw)
 static void print_job_render(PrintWindow *pw)
 {
        gdouble proof_w, proof_h;
-       gint finished;
+       gboolean finished;
 
        pw->proof_position = 0;
 
@@ -2436,9 +2384,9 @@ static void print_job_render(PrintWindow *pw)
        if (finished) print_job_done(pw);
 }
 
-static gint print_job_init(PrintWindow *pw)
+static gboolean print_job_init(PrintWindow *pw)
 {
-       gint success = FALSE;
+       gboolean success = FALSE;
 
        pw->job_page = 0;
 
@@ -2459,9 +2407,9 @@ static gint print_job_init(PrintWindow *pw)
        return success;
 }
 
-static gint print_job_finish(PrintWindow *pw)
+static gboolean print_job_finish(PrintWindow *pw)
 {
-       gint success = FALSE;
+       gboolean success = FALSE;
 
        switch (pw->job_format)
                {
@@ -2531,7 +2479,7 @@ static void print_job_close(PrintWindow *pw, gint error)
                pw->job_pixbuf = NULL;
                }
 
-       if (pw->dialog && !GTK_WIDGET_VISIBLE(pw->dialog->dialog))
+       if (pw->dialog && !gtk_widget_get_visible(pw->dialog->dialog))
                {
                g_idle_add_full(G_PRIORITY_HIGH_IDLE, print_job_close_finish_cb, pw, NULL);
                }
@@ -2609,7 +2557,7 @@ static void print_pref_store(PrintWindow *pw)
        pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_IMAGE_SCALE, pw->image_scale);
 }
 
-static gint print_job_start(PrintWindow *pw, RenderFormat format, PrintOutput output)
+static gboolean print_job_start(PrintWindow *pw, RenderFormat format, PrintOutput output)
 {
        GtkWidget *hbox;
        GtkWidget *spinner;
@@ -2681,7 +2629,7 @@ static void print_window_print_start(PrintWindow *pw)
 {
        RenderFormat format;
 
-       switch(pw->output)
+       switch (pw->output)
                {
                case PRINT_OUTPUT_RGB_FILE:
                        format = RENDER_FORMAT_RGB;
@@ -2710,11 +2658,11 @@ static GtkWidget *print_combo_menu(const gchar *text[], gint count, gint preferr
        GtkWidget *combo;
        gint i;
 
-       combo = gtk_combo_box_new_text();
+       combo = gtk_combo_box_text_new();
 
        for (i = 0 ; i < count; i++)
                {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(text[i]));
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _(text[i]));
                }
 
        if (preferred >= 0 && preferred < count)
@@ -2735,19 +2683,19 @@ static GtkWidget *print_combo_menu(const gchar *text[], gint count, gint preferr
  */
 
 static GtkWidget *print_paper_menu(GtkWidget *table, gint column, gint row,
-                                  gint preferred, GCallback func, gpointer data)
+                                  PaperOrientation preferred, GCallback func, gpointer data)
 {
        GtkWidget *combo;
        gint i;
 
        pref_table_label(table, column, row, (_("Format:")), 1.0);
 
-       combo = gtk_combo_box_new_text();
+       combo = gtk_combo_box_text_new();
 
        i = 0;
        while (print_paper_sizes[i].description)
                {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(print_paper_sizes[i].description));
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _(print_paper_sizes[i].description));
                i++;
                }
 
@@ -3023,7 +2971,7 @@ static void print_custom_entry_set(PrintWindow *pw, GtkWidget *combo)
                work = work->next;
 
                buf = g_strdup_printf(PRINT_LPR_CUSTOM, name);
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo), buf);
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), buf);
                g_free(buf);
                }
        string_list_free(list);
@@ -3048,9 +2996,9 @@ static void print_custom_entry_set(PrintWindow *pw, GtkWidget *combo)
 
 static void print_output_set(PrintWindow *pw, PrintOutput output)
 {
-       gint use_file = FALSE;
-       gint use_custom = FALSE;
-       gint use_format = FALSE;
+       gboolean use_file = FALSE;
+       gboolean use_custom = FALSE;
+       gboolean use_format = FALSE;
 
        pw->output = output;
 
@@ -3175,7 +3123,7 @@ static void print_output_dpi_cb(GtkWidget *combo, gpointer data)
        pw->max_dpi = (gdouble)n;
 }
 
-static void print_text_field_set(PrintWindow *pw, TextInfo field, gint active)
+static void print_text_field_set(PrintWindow *pw, TextInfo field, gboolean active)
 {
        if (active)
                {
@@ -3192,7 +3140,7 @@ static void print_text_field_set(PrintWindow *pw, TextInfo field, gint active)
 static void print_text_cb_name(GtkWidget *widget, gpointer data)
 {
        PrintWindow *pw = data;
-       gint active;
+       gboolean active;
 
        active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        print_text_field_set(pw, TEXT_INFO_FILENAME, active);
@@ -3201,7 +3149,7 @@ static void print_text_cb_name(GtkWidget *widget, gpointer data)
 static void print_text_cb_path(GtkWidget *widget, gpointer data)
 {
        PrintWindow *pw = data;
-       gint active;
+       gboolean active;
 
        active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        print_text_field_set(pw, TEXT_INFO_FILEPATH, active);
@@ -3210,7 +3158,7 @@ static void print_text_cb_path(GtkWidget *widget, gpointer data)
 static void print_text_cb_date(GtkWidget *widget, gpointer data)
 {
        PrintWindow *pw = data;
-       gint active;
+       gboolean active;
 
        active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        print_text_field_set(pw, TEXT_INFO_FILEDATE, active);
@@ -3219,7 +3167,7 @@ static void print_text_cb_date(GtkWidget *widget, gpointer data)
 static void print_text_cb_size(GtkWidget *widget, gpointer data)
 {
        PrintWindow *pw = data;
-       gint active;
+       gboolean active;
 
        active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        print_text_field_set(pw, TEXT_INFO_FILESIZE, active);
@@ -3228,7 +3176,7 @@ static void print_text_cb_size(GtkWidget *widget, gpointer data)
 static void print_text_cb_dims(GtkWidget *widget, gpointer data)
 {
        PrintWindow *pw = data;
-       gint active;
+       gboolean active;
 
        active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
        print_text_field_set(pw, TEXT_INFO_DIMENSIONS, active);
@@ -3264,12 +3212,6 @@ static void print_text_menu(GtkWidget *box, PrintWindow *pw)
        pref_spin_new(group, _("Size:"), _("points"),
                      8.0, 100.0, 1.0, 0, pw->text_points,
                      G_CALLBACK(print_text_cb_points), pw);
-
-#if 0
-       button = color_selection_new();
-       gtk_box_pack_start(GTK_BOX(group), button, FALSE, FALSE, 0);
-       gtk_widget_show(button);
-#endif
 }
 
 /*
@@ -3357,7 +3299,7 @@ void print_window_new(FileData *fd, GList *selection, GList *list, GtkWidget *pa
        pw = g_new0(PrintWindow, 1);
 
        pw->source_fd = file_data_ref(fd);
-       pw->source_selection = selection;
+       pw->source_selection = file_data_process_groups_in_selection(selection, FALSE, NULL);
        pw->source_list = list;
 
        pw->source = print_pref_int(PRINT_PREF_SOURCE, PRINT_SOURCE_SELECTION);