Trim trailing white spaces.
[geeqie.git] / src / print.c
index a708255..25eb5cc 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
  *
@@ -1336,93 +1336,44 @@ static gboolean 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;
-
-       g_fprintf(f, "%f %f moveto\n", x, y);
-       g_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';
-
-               g_fprintf(f, "%s", text);
-
-               p++;
-               }
-
-       g_fprintf(f, ">\n");
-       g_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;
-
-       g_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;
-               }
-
-       g_fprintf(f, "closepath\n");
-}
+static gdouble convert_pango_dpi(gdouble points);
 
 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;
+       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;
 
-       if (!text) return TRUE;
-
-       f = print_job_ps_fd(pw);
-       if (!f) return FALSE;
-
-       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);
 
-       g_fprintf(f, "/Sans findfont\n");
-       g_fprintf(f, "%f scalefont\n", point_size);
-       g_fprintf(f, "setfont\n");
+       pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
+       pango_layout_set_text(layout, text, -1);
 
-       g_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;
 }
@@ -2008,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);
@@ -2106,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);
@@ -2119,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)
@@ -2236,7 +2184,6 @@ 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;
        gboolean success = TRUE;
 
        if (pw->proof_columns < 1 || pw->proof_rows < 1)
@@ -2251,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);
 
@@ -2258,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;
@@ -2530,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);
                }
@@ -2709,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)
@@ -2741,12 +2690,12 @@ static GtkWidget *print_paper_menu(GtkWidget *table, gint column, gint row,
 
        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++;
                }
 
@@ -3022,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);
@@ -3263,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
 }
 
 /*
@@ -3356,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);