2 * Copyright (C) 2018 The Geeqie Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "image-load.h"
28 #include "pixbuf-util.h"
30 #include "ui-fileops.h"
32 #define PRINT_SETTINGS "print_settings" // filename save printer settings
33 #define PAGE_SETUP "page_setup" // filename save page setup
35 /* padding between objects */
36 #define PRINT_TEXT_PADDING 3.0
38 /* method to use when scaling down image data */
39 #define PRINT_MAX_INTERP GDK_INTERP_BILINEAR
41 /* reverse order is important */
49 typedef struct _PrintWindow PrintWindow;
53 GList *source_selection;
56 GtkTextBuffer *page_text;
57 gchar *template_string;
59 ImageLoader *job_loader;
61 GList *print_pixbuf_queue;
62 gboolean job_render_finished;
67 static gint print_layout_page_count(PrintWindow *pw)
71 images = g_list_length(pw->source_selection);
73 if (images < 1 ) return 0;
78 static gboolean print_job_render_image(PrintWindow *pw);
80 static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
82 PrintWindow *pw = data;
85 pixbuf = image_loader_get_pixbuf(il);
88 pw->print_pixbuf_queue = g_list_append(pw->print_pixbuf_queue, pixbuf);
90 image_loader_free(pw->job_loader);
91 pw->job_loader = NULL;
95 if (!print_job_render_image(pw))
97 pw->job_render_finished = TRUE;
101 static gboolean print_job_render_image(PrintWindow *pw)
105 fd = g_list_nth_data(pw->source_selection, pw->job_page);
106 if (!fd) return FALSE;
108 image_loader_free(pw->job_loader);
109 pw->job_loader = NULL;
111 pw->job_loader = image_loader_new(fd);
112 g_signal_connect(G_OBJECT(pw->job_loader), "done",
113 (GCallback)print_job_render_image_loader_done, pw);
115 if (!image_loader_start(pw->job_loader))
117 image_loader_free(pw->job_loader);
118 pw->job_loader= NULL;
124 static void print_set_font_cb(GtkWidget *widget, gpointer data)
128 if (g_strcmp0(data, "Image text font") == 0)
130 option = options->printer.image_font;
134 option = options->printer.page_font;
139 PangoFontDescription *font_desc;
141 dialog = gtk_font_chooser_dialog_new(data, GTK_WINDOW(gtk_widget_get_toplevel(widget)));
142 gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), option);
144 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL)
146 font_desc = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
147 font = pango_font_description_to_string(font_desc);
149 option = g_strdup(font);
153 gtk_widget_destroy(dialog);
156 static gint set_toggle(GSList *list, TextPosition pos)
158 GtkToggleButton *current_sel;
159 GtkToggleButton *new_sel;
162 current_sel = g_slist_nth(list, pos)->data;
163 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_sel)))
170 new_sel = g_slist_nth(list, new_pos)->data;
171 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(new_sel), TRUE);
176 static void image_text_position_h1_cb(GtkWidget *widget, gpointer data)
178 PrintWindow *pw = data;
181 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
183 new_set = set_toggle(pw->page_group, HEADER_1);
186 options->printer.page_text_position = new_set;
188 options->printer.image_text_position = HEADER_1;
192 static void image_text_position_h2_cb(GtkWidget *widget, gpointer data)
194 PrintWindow *pw = data;
197 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
199 new_set = set_toggle(pw->page_group, HEADER_2);
202 options->printer.page_text_position = new_set;
204 options->printer.image_text_position = HEADER_2;
208 static void image_text_position_f1_cb(GtkWidget *widget, gpointer data)
210 PrintWindow *pw = data;
213 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
215 new_set = set_toggle(pw->page_group, FOOTER_1);
218 options->printer.page_text_position = new_set;
220 options->printer.image_text_position = FOOTER_1;
224 static void image_text_position_f2_cb(GtkWidget *widget, gpointer data)
226 PrintWindow *pw = data;
229 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
231 new_set = set_toggle(pw->page_group, FOOTER_2);
234 options->printer.page_text_position = new_set;
236 options->printer.image_text_position = FOOTER_2;
240 static void page_text_position_h1_cb(GtkWidget *widget, gpointer data)
242 PrintWindow *pw = data;
245 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
247 new_set = set_toggle(pw->image_group, HEADER_1);
250 options->printer.image_text_position = new_set;
252 options->printer.page_text_position = HEADER_1;
256 static void page_text_position_h2_cb(GtkWidget *widget, gpointer data)
258 PrintWindow *pw = data;
261 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
263 new_set = set_toggle(pw->image_group, HEADER_2);
266 options->printer.image_text_position = new_set;
268 options->printer.page_text_position = HEADER_2;
272 static void page_text_position_f1_cb(GtkWidget *widget, gpointer data)
274 PrintWindow *pw = data;
277 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
279 new_set = set_toggle(pw->image_group, FOOTER_1);
282 options->printer.image_text_position = new_set;
284 options->printer.page_text_position = FOOTER_1;
288 static void page_text_position_f2_cb(GtkWidget *widget, gpointer data)
290 PrintWindow *pw = data;
293 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
295 new_set = set_toggle(pw->image_group, FOOTER_2);
298 options->printer.image_text_position = new_set;
300 options->printer.page_text_position = FOOTER_2;
304 static void set_print_image_text_string(gchar **template_string, const gchar *value)
306 g_assert(template_string);
308 g_free(*template_string);
309 *template_string = g_strdup(value);
312 static void image_text_template_view_changed_cb(GtkWidget *UNUSED(widget), gpointer data)
314 GtkWidget *pTextView;
315 GtkTextBuffer *pTextBuffer;
319 pTextView = GTK_WIDGET(data);
321 pTextBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pTextView));
322 gtk_text_buffer_get_start_iter(pTextBuffer, &iStart);
323 gtk_text_buffer_get_end_iter(pTextBuffer, &iEnd);
325 set_print_image_text_string(&options->printer.template_string,
326 gtk_text_buffer_get_text(pTextBuffer, &iStart, &iEnd, TRUE));
329 #define PRE_FORMATTED_COLUMNS 4
330 static void print_text_menu(GtkWidget *box, PrintWindow *pw)
337 GtkWidget *image_text_button;
338 GtkWidget *page_text_button;
340 GtkWidget *page_text_view;
341 GtkWidget *image_text_template_view;
343 GtkWidget *scrolled_pre_formatted;
344 GtkTextBuffer *buffer;
346 group = pref_group_new(box, FALSE, _("Image text"), GTK_ORIENTATION_VERTICAL);
348 image_text_button = pref_checkbox_new_int(group, _("Show image text"),
349 options->printer.show_image_text, &options->printer.show_image_text);
351 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
353 pref_checkbox_link_sensitivity(image_text_button, subgroup);
355 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
356 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
358 /* order is important */
359 button1 = pref_radiobutton_new(hbox, NULL, "Header 1",
360 options->printer.image_text_position == HEADER_1,
361 G_CALLBACK(image_text_position_h1_cb), pw);
362 button1 = pref_radiobutton_new(hbox, button1, "Header 2",
363 options->printer.image_text_position == HEADER_2,
364 G_CALLBACK(image_text_position_h2_cb), pw);
365 button1 = pref_radiobutton_new(hbox, button1, "Footer 1",
366 options->printer.image_text_position == FOOTER_1,
367 G_CALLBACK(image_text_position_f1_cb), pw);
368 button1 = pref_radiobutton_new(hbox, button1, "Footer 2",
369 options->printer.image_text_position == FOOTER_2,
370 G_CALLBACK(image_text_position_f2_cb), pw);
371 gtk_widget_show(hbox);
372 pw->image_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button1)));
374 image_text_template_view = gtk_text_view_new();
376 scrolled_pre_formatted = osd_new(PRE_FORMATTED_COLUMNS, image_text_template_view);
377 gtk_box_pack_start(GTK_BOX(subgroup), scrolled_pre_formatted, FALSE, FALSE, 0);
378 gtk_widget_show(scrolled_pre_formatted);
379 gtk_widget_show(subgroup);
381 gtk_widget_set_tooltip_markup(image_text_template_view,
382 _("Extensive formatting options are shown in the Help file"));
384 scrolled = gtk_scrolled_window_new(NULL, NULL);
385 gtk_widget_set_size_request(scrolled, 200, 50);
386 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
387 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
388 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
389 gtk_box_pack_start(GTK_BOX(subgroup), scrolled, TRUE, TRUE, 5);
390 gtk_widget_show(scrolled);
392 gtk_container_add(GTK_CONTAINER(scrolled), image_text_template_view);
393 gtk_widget_show(image_text_template_view);
395 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(image_text_template_view));
396 if (options->printer.template_string) gtk_text_buffer_set_text(buffer, options->printer.template_string, -1);
397 g_signal_connect(G_OBJECT(buffer), "changed",
398 G_CALLBACK(image_text_template_view_changed_cb), image_text_template_view);
400 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
402 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
403 G_CALLBACK(print_set_font_cb), "Image text font");
405 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
406 gtk_widget_show(button);
408 pref_spacer(group, PREF_PAD_GAP);
410 group = pref_group_new(box, FALSE, _("Page text"), GTK_ORIENTATION_VERTICAL);
412 page_text_button = pref_checkbox_new_int(group, _("Show page text"),
413 options->printer.show_page_text, &options->printer.show_page_text);
415 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
416 pref_checkbox_link_sensitivity(page_text_button, subgroup);
418 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
419 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
421 /* order is important */
422 button2 = pref_radiobutton_new(hbox, NULL, "Header 1",
423 options->printer.page_text_position == HEADER_1,
424 G_CALLBACK(page_text_position_h1_cb), pw);
425 button2 = pref_radiobutton_new(hbox, button2, "Header 2",
426 options->printer.page_text_position == HEADER_2,
427 G_CALLBACK(page_text_position_h2_cb), pw);
428 button2 = pref_radiobutton_new(hbox, button2, "Footer 1",
429 options->printer.page_text_position == FOOTER_1,
430 G_CALLBACK(page_text_position_f1_cb), pw);
431 button2 = pref_radiobutton_new(hbox, button2, "Footer 2",
432 options->printer.page_text_position == FOOTER_2,
433 G_CALLBACK(page_text_position_f2_cb), pw);
434 gtk_widget_show(hbox);
435 pw->page_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button2)));
437 scrolled = gtk_scrolled_window_new(NULL, NULL);
438 gtk_widget_set_size_request(scrolled, 50, 50);
439 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
440 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
441 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
442 gtk_box_pack_start(GTK_BOX(subgroup), scrolled, TRUE, TRUE, 5);
443 gtk_widget_show(scrolled);
445 page_text_view = gtk_text_view_new();
446 pw->page_text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page_text_view ));
447 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(pw->page_text), options->printer.page_text, -1);
448 g_object_ref(pw->page_text);
450 gtk_widget_set_tooltip_markup(page_text_view, (_("Text shown on each page of a single or multi-page print job")));
451 gtk_container_add(GTK_CONTAINER(scrolled), page_text_view);
452 gtk_widget_show(page_text_view);
454 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
456 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
457 G_CALLBACK(print_set_font_cb), "Page text font");
459 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
460 gtk_widget_show(button);
463 static gboolean paginate_cb(GtkPrintOperation *UNUSED(operation),
464 GtkPrintContext *UNUSED(context),
467 PrintWindow *pw = data;
469 if (pw->job_render_finished)
479 gchar *form_image_text(const gchar *template_string, FileData *fd, PrintWindow *pw, gint page_nr, gint total)
486 gchar *collection_name;
488 if (!fd) return NULL;
492 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
494 window_title = g_strdup(gtk_window_get_title(GTK_WINDOW(pw->parent)));
495 delimiter = g_strstr_len(window_title, -1, " - Collection - ");
498 collection_name = g_strndup(window_title, delimiter - window_title);
502 collection_name = NULL;
504 g_free(window_title);
508 osd_template_insert(vars, "collection", collection_name, OSDT_NONE);
511 osd_template_insert(vars, "number", g_strdup_printf("%d", page_nr + 1), OSDT_NO_DUP);
512 osd_template_insert(vars, "total", g_strdup_printf("%d", total), OSDT_NO_DUP);
513 osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
514 osd_template_insert(vars, "date", fd ? ((gchar *) text_from_time(fd->date)) : "", OSDT_NONE);
515 osd_template_insert(vars, "size", fd ? (text_from_size_abrev(fd->size)) : g_strdup(""), OSDT_FREE);
520 w = gdk_pixbuf_get_width(fd->pixbuf);
521 h = gdk_pixbuf_get_height(fd->pixbuf);
523 osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
524 osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
525 osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
529 osd_template_insert(vars, "width", NULL, OSDT_NONE);
530 osd_template_insert(vars, "height", NULL, OSDT_NONE);
531 osd_template_insert(vars, "res", NULL, OSDT_NONE);
534 text = image_osd_mkinfo(template_string, fd, vars);
535 g_hash_table_destroy(vars);
537 g_free(collection_name);
542 static void draw_page(GtkPrintOperation *UNUSED(operation), GtkPrintContext *context,
543 gint page_nr, gpointer data)
545 PrintWindow *pw = data;
548 gdouble context_width, context_height;
549 gdouble pixbuf_image_width, pixbuf_image_height;
550 gdouble width_offset;
551 gdouble height_offset;
553 GdkPixbuf *rotated = NULL;
554 PangoLayout *layout_image = NULL;
555 PangoLayout *layout_page = NULL;
556 PangoFontDescription *desc;
557 GString *image_text = g_string_new(NULL);
558 GString *page_text = g_string_new(NULL);
559 PangoRectangle ink_rect, logical_rect;
561 gdouble image_text_width, image_text_height, page_text_width, page_text_height;
564 gdouble pango_height;
565 gdouble pango_image_height;
566 gdouble pango_page_height;
567 GtkTextIter start, end;
571 fd = g_list_nth_data(pw->source_selection, page_nr);
572 total = g_list_length(pw->source_selection);
574 pixbuf = g_list_nth_data(pw->print_pixbuf_queue, page_nr);
575 if (fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)
577 rotated = pixbuf_apply_orientation(pixbuf, fd->exif_orientation);
581 pixbuf_image_width = gdk_pixbuf_get_width(pixbuf);
582 pixbuf_image_height = gdk_pixbuf_get_height(pixbuf);
584 if (options->printer.show_image_text)
586 image_text = g_string_append(image_text, form_image_text(options->printer.template_string, fd, pw, page_nr, total));
589 if (options->printer.show_page_text)
591 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
593 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
594 page_text = g_string_append(page_text, tmp);
599 cr = gtk_print_context_get_cairo_context(context);
600 context_width = gtk_print_context_get_width(context);
601 context_height = gtk_print_context_get_height(context);
603 pango_image_height = 0;
604 pango_page_height = 0;
605 image_text_width = 0;
608 if (image_text->len > 0)
610 layout_image = pango_cairo_create_layout(cr);
612 pango_layout_set_text(layout_image, image_text->str, -1);
613 desc = pango_font_description_from_string(options->printer.image_font);
614 pango_layout_set_font_description(layout_image, desc);
616 pango_layout_get_extents(layout_image, &ink_rect, &logical_rect);
617 image_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
618 image_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
620 pango_layout_set_alignment(layout_image, PANGO_ALIGN_CENTER);
621 pango_layout_set_text(layout_image, image_text->str, -1);
623 pango_image_height = image_text_height + PRINT_TEXT_PADDING * 2;
625 pango_font_description_free(desc);
628 if (page_text->len > 0)
630 layout_page = pango_cairo_create_layout(cr);
632 pango_layout_set_text(layout_page, page_text->str, -1);
633 desc = pango_font_description_from_string(options->printer.page_font);
634 pango_layout_set_font_description(layout_page, desc);
636 pango_layout_get_extents(layout_page, &ink_rect, &logical_rect);
637 page_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
638 page_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
640 pango_layout_set_alignment(layout_page, PANGO_ALIGN_CENTER);
641 pango_layout_set_text(layout_page, page_text->str, -1);
643 pango_page_height = page_text_height + PRINT_TEXT_PADDING * 2;
645 pango_font_description_free(desc);
648 pango_height = pango_image_height + pango_page_height;
650 if ((context_width / pixbuf_image_width) < ((context_height - pango_height) / pixbuf_image_height))
653 scale = context_width / pixbuf_image_width;
654 h = pixbuf_image_height * scale;
655 height_offset = (context_height - (h + pango_height)) / 2;
660 h = context_height - pango_height ;
661 scale = (context_height - pango_height) / pixbuf_image_height;
662 w = pixbuf_image_width * scale;
664 width_offset = (context_width - (pixbuf_image_width * scale)) / 2;
667 incr_y = height_offset;
669 if (options->printer.page_text_position == HEADER_1 && page_text->len > 0)
671 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
672 pango_cairo_show_layout(cr, layout_page);
674 incr_y = incr_y + pango_page_height;
677 if (options->printer.image_text_position == HEADER_1 && image_text->len > 0)
679 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y + PRINT_TEXT_PADDING);
680 pango_cairo_show_layout(cr, layout_image);
682 incr_y = incr_y + pango_image_height;
685 if (options->printer.page_text_position == HEADER_2 && page_text->len > 0)
687 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
688 pango_cairo_show_layout(cr, layout_page);
690 incr_y = incr_y + pango_page_height;
693 if (options->printer.image_text_position == HEADER_2 && image_text->len > 0)
695 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
696 pango_cairo_show_layout(cr, layout_image);
698 incr_y = incr_y + pango_image_height;
704 if (options->printer.page_text_position == FOOTER_1 && page_text->len > 0)
706 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y + PRINT_TEXT_PADDING);
707 pango_cairo_show_layout(cr, layout_page);
709 incr_y = incr_y + pango_page_height;
712 if (options->printer.image_text_position == FOOTER_1 && image_text->len > 0)
714 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
715 pango_cairo_show_layout(cr, layout_image);
717 incr_y = incr_y + pango_image_height;
720 if (options->printer.page_text_position == FOOTER_2 && page_text->len > 0)
722 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
723 pango_cairo_show_layout(cr, layout_page);
725 incr_y = incr_y + pango_page_height;
728 if (options->printer.image_text_position == FOOTER_2 && image_text->len > 0)
730 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
731 pango_cairo_show_layout(cr, layout_image);
734 cairo_scale(cr, scale, scale);
736 cairo_rectangle(cr, width_offset * scale , image_y, pixbuf_image_width / scale, pixbuf_image_height / scale);
737 gdk_cairo_set_source_pixbuf(cr, pixbuf, width_offset / scale, image_y / scale);
740 if (image_text->len > 0)
742 g_object_unref(layout_image);
743 g_string_free(image_text, TRUE);
745 if (page_text->len > 0)
747 g_object_unref(layout_page);
748 g_string_free(page_text, TRUE);
751 if (rotated) g_object_unref(rotated);
756 static void begin_print(GtkPrintOperation *operation,
757 GtkPrintContext *UNUSED(context),
760 PrintWindow *pw = user_data;
763 page_count = print_layout_page_count(pw);
764 gtk_print_operation_set_n_pages (operation, page_count);
766 print_job_render_image(pw);
770 GObject *option_tab_cb(GtkPrintOperation *UNUSED(operation), gpointer user_data)
772 PrintWindow *pw = user_data;
774 return G_OBJECT(pw->vbox);
777 static void print_pref_store(PrintWindow *pw)
780 GtkTextIter start, end;
782 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
783 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
784 g_free(options->printer.page_text);
785 options->printer.page_text = g_strdup(tmp);
789 static void end_print_cb(GtkPrintOperation *operation,
790 GtkPrintContext *UNUSED(context), gpointer data)
792 PrintWindow *pw = data;
796 GtkPrintSettings *print_settings;
797 GtkPageSetup *page_setup;
798 GError *error = NULL;
800 print_settings = gtk_print_operation_get_print_settings(operation);
801 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
803 gtk_print_settings_to_file(print_settings, path, &error);
806 log_printf("Error: Print settings save failed:\n%s", error->message);
811 g_object_unref(print_settings);
813 page_setup = gtk_print_operation_get_default_page_setup(operation);
814 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
816 gtk_page_setup_to_file(page_setup, path, &error);
819 log_printf("Error: Print page setup save failed:\n%s", error->message);
824 g_object_unref(page_setup);
826 print_pref_store(pw);
828 work = pw->print_pixbuf_queue;
834 g_object_unref(pixbuf);
838 g_list_free(pw->print_pixbuf_queue);
839 g_object_unref(pw->page_text);
843 void print_window_new(FileData *UNUSED(fd), GList *selection, GList *UNUSED(list), GtkWidget *parent)
847 GtkPrintOperation *operation;
848 GtkPageSetup *page_setup;
851 GError *error = NULL;
853 GtkPrintSettings *settings;
855 pw = g_new0(PrintWindow, 1);
857 pw->source_selection = file_data_process_groups_in_selection(selection, FALSE, NULL);
859 if (print_layout_page_count(pw) == 0)
866 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
867 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
868 gtk_widget_show(vbox);
870 print_text_menu(vbox, pw);
873 pw->print_pixbuf_queue = NULL;
874 pw->job_render_finished = FALSE;
877 operation = gtk_print_operation_new();
878 settings = gtk_print_settings_new();
880 gtk_print_operation_set_custom_tab_label(operation, "Options");
881 gtk_print_operation_set_use_full_page(operation, TRUE);
882 gtk_print_operation_set_unit(operation, GTK_UNIT_POINTS);
883 gtk_print_operation_set_embed_page_setup(operation, TRUE);
884 gtk_print_operation_set_allow_async (operation, TRUE);
885 dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
888 dir = g_get_home_dir();
891 uri = g_build_filename("file:/", dir, "geeqie-file.pdf", NULL);
892 gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
895 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
896 gtk_print_settings_load_file(settings, path, &error);
899 log_printf("Error: Printer settings load failed:\n%s", error->message);
903 gtk_print_operation_set_print_settings(operation, settings);
906 page_setup = gtk_page_setup_new();
907 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
908 gtk_page_setup_load_file(page_setup, path, &error);
911 log_printf("Error: Print page setup load failed:\n%s", error->message);
915 gtk_print_operation_set_default_page_setup(operation, page_setup);
918 g_signal_connect (G_OBJECT (operation), "begin-print",
919 G_CALLBACK (begin_print), pw);
920 g_signal_connect (G_OBJECT (operation), "draw-page",
921 G_CALLBACK (draw_page), pw);
922 g_signal_connect (G_OBJECT (operation), "end-print",
923 G_CALLBACK (end_print_cb), pw);
924 g_signal_connect (G_OBJECT (operation), "create-custom-widget",
925 G_CALLBACK (option_tab_cb), pw);
926 g_signal_connect (G_OBJECT (operation), "paginate",
927 G_CALLBACK (paginate_cb), pw);
929 gtk_print_operation_set_n_pages(operation, print_layout_page_count(pw));
931 gtk_print_operation_run(operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
932 GTK_WINDOW (parent), &error);
938 dialog = gtk_message_dialog_new(GTK_WINDOW (parent),
939 GTK_DIALOG_DESTROY_WITH_PARENT,
942 "%s", error->message);
943 g_error_free (error);
945 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
947 gtk_widget_show (dialog);
950 g_object_unref(page_setup);
951 g_object_unref(settings);
953 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */