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.
25 #include "image-load.h"
27 #include "ui_fileops.h"
29 #define PRINT_SETTINGS "print_settings" // filename save printer settings
30 #define PAGE_SETUP "page_setup" // filename save page setup
32 /* padding between objects */
33 #define PRINT_TEXT_PADDING 3.0
35 /* method to use when scaling down image data */
36 #define PRINT_MAX_INTERP GDK_INTERP_HYPER
39 TEXT_INFO_FILENAME = 1 << 0,
40 TEXT_INFO_FILEDATE = 1 << 1,
41 TEXT_INFO_FILESIZE = 1 << 2,
42 TEXT_INFO_DIMENSIONS = 1 << 3,
43 TEXT_INFO_FILEPATH = 1 << 4
46 /* reverse order is important */
54 typedef struct _PrintWindow PrintWindow;
58 GList *source_selection;
62 GtkTextBuffer *page_text;
63 ImageLoader *job_loader;
65 GList *print_pixbuf_queue;
66 gboolean job_render_finished;
71 static gint print_layout_page_count(PrintWindow *pw)
75 images = g_list_length(pw->source_selection);
77 if (images < 1 ) return 0;
82 static gboolean print_job_render_image(PrintWindow *pw);
84 static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
86 PrintWindow *pw = data;
89 pixbuf = image_loader_get_pixbuf(il);
92 pw->print_pixbuf_queue = g_list_append(pw->print_pixbuf_queue, pixbuf);
94 image_loader_free(pw->job_loader);
95 pw->job_loader = NULL;
99 if (!print_job_render_image(pw))
101 pw->job_render_finished = TRUE;
105 static gboolean print_job_render_image(PrintWindow *pw)
109 fd = g_list_nth_data(pw->source_selection, pw->job_page);
110 if (!fd) return FALSE;
112 image_loader_free(pw->job_loader);
113 pw->job_loader = NULL;
115 pw->job_loader = image_loader_new(fd);
116 g_signal_connect(G_OBJECT(pw->job_loader), "done",
117 (GCallback)print_job_render_image_loader_done, pw);
119 if (!image_loader_start(pw->job_loader))
121 image_loader_free(pw->job_loader);
122 pw->job_loader= NULL;
128 static void print_text_field_set(PrintWindow *pw, TextInfo field, gboolean active)
132 pw->text_fields |= field;
136 pw->text_fields &= ~field;
140 static void print_text_cb_name(GtkWidget *widget, gpointer data)
142 PrintWindow *pw = data;
145 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
146 print_text_field_set(pw, TEXT_INFO_FILENAME, active);
149 static void print_text_cb_path(GtkWidget *widget, gpointer data)
151 PrintWindow *pw = data;
154 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
155 print_text_field_set(pw, TEXT_INFO_FILEPATH, active);
158 static void print_text_cb_date(GtkWidget *widget, gpointer data)
160 PrintWindow *pw = data;
163 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
164 print_text_field_set(pw, TEXT_INFO_FILEDATE, active);
167 static void print_text_cb_size(GtkWidget *widget, gpointer data)
169 PrintWindow *pw = data;
172 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
173 print_text_field_set(pw, TEXT_INFO_FILESIZE, active);
176 static void print_text_cb_dims(GtkWidget *widget, gpointer data)
178 PrintWindow *pw = data;
181 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
182 print_text_field_set(pw, TEXT_INFO_DIMENSIONS, active);
185 static void print_set_font_cb(GtkWidget *widget, gpointer data)
189 if (g_strcmp0(data, "Image text font") == 0)
191 option = options->printer.image_font;
195 option = options->printer.page_font;
198 #if GTK_CHECK_VERSION(3,4,0)
201 PangoFontDescription *font_desc;
203 dialog = gtk_font_chooser_dialog_new(data, GTK_WINDOW(gtk_widget_get_toplevel(widget)));
204 gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), option);
206 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL)
208 font_desc = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
209 font = pango_font_description_to_string(font_desc);
211 option = g_strdup(font);
215 gtk_widget_destroy(dialog);
219 font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
220 option = g_strdup(font);
224 static gint set_toggle(GSList *list, TextPosition pos)
226 GtkToggleButton *current_sel;
227 GtkToggleButton *new_sel;
230 current_sel = g_slist_nth(list, pos)->data;
231 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_sel)))
238 new_sel = g_slist_nth(list, new_pos)->data;
239 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(new_sel), TRUE);
244 static void image_text_position_h1_cb(GtkWidget *widget, gpointer data)
246 PrintWindow *pw = data;
249 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
251 new_set = set_toggle(pw->page_group, HEADER_1);
254 options->printer.page_text_position = new_set;
256 options->printer.image_text_position = HEADER_1;
260 static void image_text_position_h2_cb(GtkWidget *widget, gpointer data)
262 PrintWindow *pw = data;
265 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
267 new_set = set_toggle(pw->page_group, HEADER_2);
270 options->printer.page_text_position = new_set;
272 options->printer.image_text_position = HEADER_2;
276 static void image_text_position_f1_cb(GtkWidget *widget, gpointer data)
278 PrintWindow *pw = data;
281 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
283 new_set = set_toggle(pw->page_group, FOOTER_1);
286 options->printer.page_text_position = new_set;
288 options->printer.image_text_position = FOOTER_1;
292 static void image_text_position_f2_cb(GtkWidget *widget, gpointer data)
294 PrintWindow *pw = data;
297 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
299 new_set = set_toggle(pw->page_group, FOOTER_2);
302 options->printer.page_text_position = new_set;
304 options->printer.image_text_position = FOOTER_2;
308 static void page_text_position_h1_cb(GtkWidget *widget, gpointer data)
310 PrintWindow *pw = data;
313 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
315 new_set = set_toggle(pw->image_group, HEADER_1);
318 options->printer.image_text_position = new_set;
320 options->printer.page_text_position = HEADER_1;
324 static void page_text_position_h2_cb(GtkWidget *widget, gpointer data)
326 PrintWindow *pw = data;
329 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
331 new_set = set_toggle(pw->image_group, HEADER_2);
334 options->printer.image_text_position = new_set;
336 options->printer.page_text_position = HEADER_2;
340 static void page_text_position_f1_cb(GtkWidget *widget, gpointer data)
342 PrintWindow *pw = data;
345 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
347 new_set = set_toggle(pw->image_group, FOOTER_1);
350 options->printer.image_text_position = new_set;
352 options->printer.page_text_position = FOOTER_1;
356 static void page_text_position_f2_cb(GtkWidget *widget, gpointer data)
358 PrintWindow *pw = data;
361 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
363 new_set = set_toggle(pw->image_group, FOOTER_2);
366 options->printer.image_text_position = new_set;
368 options->printer.page_text_position = FOOTER_2;
372 static void print_text_menu(GtkWidget *box, PrintWindow *pw)
379 GtkWidget *image_text_button;
380 GtkWidget *page_text_button;
382 GtkWidget *page_text_view;
384 group = pref_group_new(box, FALSE, _("Image text"), GTK_ORIENTATION_VERTICAL);
386 image_text_button = pref_checkbox_new_int(group, _("Show image text"),
387 options->printer.show_image_text, &options->printer.show_image_text);
389 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
391 pref_checkbox_link_sensitivity(image_text_button, subgroup);
393 hbox = gtk_hbox_new(FALSE, 0);
394 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
396 /* order is important */
397 button1 = pref_radiobutton_new(hbox, NULL, "Header 1",
398 options->printer.image_text_position == HEADER_1,
399 G_CALLBACK(image_text_position_h1_cb), pw);
400 button1 = pref_radiobutton_new(hbox, button1, "Header 2",
401 options->printer.image_text_position == HEADER_2,
402 G_CALLBACK(image_text_position_h2_cb), pw);
403 button1 = pref_radiobutton_new(hbox, button1, "Footer 1",
404 options->printer.image_text_position == FOOTER_1,
405 G_CALLBACK(image_text_position_f1_cb), pw);
406 button1 = pref_radiobutton_new(hbox, button1, "Footer 2",
407 options->printer.image_text_position == FOOTER_2,
408 G_CALLBACK(image_text_position_f2_cb), pw);
409 gtk_widget_show(hbox);
410 pw->image_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button1)));
412 pref_checkbox_new(subgroup, _("Name"), (pw->text_fields & TEXT_INFO_FILENAME),
413 G_CALLBACK(print_text_cb_name), pw);
414 pref_checkbox_new(subgroup, _("Path"), (pw->text_fields & TEXT_INFO_FILEPATH),
415 G_CALLBACK(print_text_cb_path), pw);
416 pref_checkbox_new(subgroup, _("Date"), (pw->text_fields & TEXT_INFO_FILEDATE),
417 G_CALLBACK(print_text_cb_date), pw);
418 pref_checkbox_new(subgroup, _("Size"), (pw->text_fields & TEXT_INFO_FILESIZE),
419 G_CALLBACK(print_text_cb_size), pw);
420 pref_checkbox_new(subgroup, _("Dimensions"), (pw->text_fields & TEXT_INFO_DIMENSIONS),
421 G_CALLBACK(print_text_cb_dims), pw);
423 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
425 #if GTK_CHECK_VERSION(3,4,0)
426 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
427 G_CALLBACK(print_set_font_cb), "Image text font");
429 button = gtk_font_button_new();
430 gtk_font_button_set_title(GTK_FONT_BUTTON(button), "Image text Font");
431 gtk_font_button_set_font_name(GTK_FONT_BUTTON(button), options->printer.image_font);
432 g_signal_connect(G_OBJECT(button), "font-set",
433 G_CALLBACK(print_set_font_cb), "Image text font");
435 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
436 gtk_widget_show(button);
438 pref_spacer(group, PREF_PAD_GAP);
440 group = pref_group_new(box, FALSE, _("Page text"), GTK_ORIENTATION_VERTICAL);
442 page_text_button = pref_checkbox_new_int(group, _("Show page text"),
443 options->printer.show_page_text, &options->printer.show_page_text);
445 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
446 pref_checkbox_link_sensitivity(page_text_button, subgroup);
448 hbox = gtk_hbox_new(FALSE, 0);
449 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
451 /* order is important */
452 button2 = pref_radiobutton_new(hbox, NULL, "Header 1",
453 options->printer.page_text_position == HEADER_1,
454 G_CALLBACK(page_text_position_h1_cb), pw);
455 button2 = pref_radiobutton_new(hbox, button2, "Header 2",
456 options->printer.page_text_position == HEADER_2,
457 G_CALLBACK(page_text_position_h2_cb), pw);
458 button2 = pref_radiobutton_new(hbox, button2, "Footer 1",
459 options->printer.page_text_position == FOOTER_1,
460 G_CALLBACK(page_text_position_f1_cb), pw);
461 button2 = pref_radiobutton_new(hbox, button2, "Footer 2",
462 options->printer.page_text_position == FOOTER_2,
463 G_CALLBACK(page_text_position_f2_cb), pw);
464 gtk_widget_show(hbox);
465 pw->page_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button2)));
469 scrolled = gtk_scrolled_window_new(NULL, NULL);
470 gtk_widget_set_size_request(scrolled, 50, 50);
471 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
472 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
473 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
474 gtk_box_pack_start(GTK_BOX(subgroup), scrolled, TRUE, TRUE, 5);
475 gtk_widget_show(scrolled);
477 page_text_view = gtk_text_view_new();
478 pw->page_text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page_text_view ));
479 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(pw->page_text), options->printer.page_text, -1);
480 g_object_ref(pw->page_text);
482 gtk_widget_set_tooltip_markup(page_text_view, ("Text shown on each page of a single or multi-page print job"));
483 gtk_container_add(GTK_CONTAINER(scrolled), page_text_view);
484 gtk_widget_show(page_text_view);
486 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
488 #if GTK_CHECK_VERSION(3,4,0)
489 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
490 G_CALLBACK(print_set_font_cb), "Page text font");
492 button = gtk_font_button_new();
493 gtk_font_button_set_title(GTK_FONT_BUTTON(button), "Page text Font");
494 gtk_font_button_set_font_name(GTK_FONT_BUTTON(button), options->printer.page_font);
495 g_signal_connect(G_OBJECT(button), "font-set",
496 G_CALLBACK(print_set_font_cb), "Page text font");
498 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
499 gtk_widget_show(button);
502 static gboolean paginate_cb(GtkPrintOperation *operation,
503 GtkPrintContext *context,
506 PrintWindow *pw = data;
508 if (pw->job_render_finished)
518 static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
519 gint page_nr, gpointer data)
521 PrintWindow *pw = data;
524 gdouble context_width, context_height;
525 gdouble pixbuf_image_width, pixbuf_image_height;
526 gdouble width_offset;
527 gdouble height_offset;
529 GdkPixbuf *pixbuf_scaled;
530 PangoLayout *layout_image = NULL;
531 PangoLayout *layout_page = NULL;
532 PangoFontDescription *desc;
533 GString *image_text = g_string_new(NULL);
534 GString *page_text = g_string_new(NULL);
535 PangoRectangle ink_rect, logical_rect;
537 gdouble image_text_width, image_text_height, page_text_width, page_text_height;
540 gdouble pango_height;
541 gdouble pango_image_height;
542 gdouble pango_page_height;
543 GtkTextIter start, end;
546 pixbuf = g_list_nth_data(pw->print_pixbuf_queue, page_nr);
547 pixbuf_image_width = gdk_pixbuf_get_width(pixbuf);
548 pixbuf_image_height = gdk_pixbuf_get_height(pixbuf);
550 fd = g_list_nth_data(pw->source_selection, page_nr);
552 if (options->printer.show_image_text)
554 if (pw->text_fields & TEXT_INFO_FILENAME)
556 image_text = g_string_append(image_text, g_strdup(fd->name));
557 image_text = g_string_append(image_text, "\n");
559 if (pw->text_fields & TEXT_INFO_FILEDATE)
561 image_text = g_string_append(image_text, g_strdup(text_from_time(fd->date)));
562 image_text = g_string_append(image_text, "\n");
564 if (pw->text_fields & TEXT_INFO_FILESIZE)
566 image_text = g_string_append(image_text, g_strdup(text_from_size(fd->size)));
567 image_text = g_string_append(image_text, "\n");
569 if (pw->text_fields & TEXT_INFO_DIMENSIONS)
571 g_string_append_printf(image_text, "%d x %d", (gint)pixbuf_image_width,
572 (gint)pixbuf_image_height);
573 image_text = g_string_append(image_text, "\n");
575 if (pw->text_fields & TEXT_INFO_FILEPATH)
577 image_text = g_string_append(image_text, g_strdup(fd->path));
578 image_text = g_string_append(image_text, "\n");
580 if (image_text->len > 0)
582 image_text = g_string_truncate(image_text, image_text->len - 1);
586 if (options->printer.show_page_text)
588 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
590 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
591 page_text = g_string_append(page_text, tmp);
596 cr = gtk_print_context_get_cairo_context(context);
597 context_width = gtk_print_context_get_width(context);
598 context_height = gtk_print_context_get_height(context);
600 pango_image_height = 0;
601 pango_page_height = 0;
602 image_text_width = 0;
605 if (image_text->len > 0)
607 layout_image = pango_cairo_create_layout(cr);
609 pango_layout_set_text(layout_image, image_text->str, -1);
610 desc = pango_font_description_from_string(options->printer.image_font);
611 pango_layout_set_font_description(layout_image, desc);
613 pango_layout_get_extents(layout_image, &ink_rect, &logical_rect);
614 image_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
615 image_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
617 pango_layout_set_alignment(layout_image, PANGO_ALIGN_CENTER);
618 pango_layout_set_text(layout_image, image_text->str, -1);
620 pango_image_height = image_text_height + PRINT_TEXT_PADDING * 2;
622 pango_font_description_free(desc);
625 if (page_text->len > 0)
627 layout_page = pango_cairo_create_layout(cr);
629 pango_layout_set_text(layout_page, page_text->str, -1);
630 desc = pango_font_description_from_string(options->printer.page_font);
631 pango_layout_set_font_description(layout_page, desc);
633 pango_layout_get_extents(layout_page, &ink_rect, &logical_rect);
634 page_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
635 page_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
637 pango_layout_set_alignment(layout_page, PANGO_ALIGN_CENTER);
638 pango_layout_set_text(layout_page, page_text->str, -1);
640 pango_page_height = page_text_height + PRINT_TEXT_PADDING * 2;
642 pango_font_description_free(desc);
645 pango_height = pango_image_height + pango_page_height;
647 if ((context_width / pixbuf_image_width) < ((context_height - pango_height) / pixbuf_image_height))
650 scale = context_width / pixbuf_image_width;
651 h = pixbuf_image_height * scale;
652 height_offset = (context_height - (h + pango_height)) / 2;
657 h = context_height - pango_height ;
658 scale = (context_height - pango_height) / pixbuf_image_height;
659 w = pixbuf_image_width * scale;
661 width_offset = (context_width - (pixbuf_image_width * scale)) / 2;
664 incr_y = height_offset + PRINT_TEXT_PADDING;
666 if (options->printer.page_text_position == HEADER_1 && page_text->len > 0)
668 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
669 pango_cairo_show_layout(cr, layout_page);
671 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
674 if (options->printer.image_text_position == HEADER_1 && image_text->len > 0)
676 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
677 pango_cairo_show_layout(cr, layout_image);
679 incr_y = incr_y + PRINT_TEXT_PADDING + pango_image_height;
682 if (options->printer.page_text_position == HEADER_2 && page_text->len > 0)
684 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
685 pango_cairo_show_layout(cr, layout_page);
687 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
690 if (options->printer.image_text_position == HEADER_2 && image_text->len > 0)
692 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
693 pango_cairo_show_layout(cr, layout_image);
695 incr_y = incr_y + PRINT_TEXT_PADDING + pango_image_height;
699 incr_y = incr_y + h + PRINT_TEXT_PADDING;
701 if (options->printer.page_text_position == FOOTER_1 && page_text->len > 0)
703 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
704 pango_cairo_show_layout(cr, layout_page);
706 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
709 if (options->printer.image_text_position == FOOTER_1 && image_text->len > 0)
711 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
712 pango_cairo_show_layout(cr, layout_image);
714 incr_y = incr_y + PRINT_TEXT_PADDING + pango_image_height;
717 if (options->printer.page_text_position == FOOTER_2 && page_text->len > 0)
719 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
720 pango_cairo_show_layout(cr, layout_page);
722 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
725 if (options->printer.image_text_position == FOOTER_2 && image_text->len > 0)
727 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
728 pango_cairo_show_layout(cr, layout_image);
731 pixbuf_scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
732 gdk_pixbuf_scale(pixbuf, pixbuf_scaled, 0, 0, w, h, 0, 0, scale, scale, PRINT_MAX_INTERP);
734 cairo_rectangle(cr, width_offset, image_y, w, h);
736 gdk_cairo_set_source_pixbuf(cr, pixbuf_scaled, width_offset, image_y);
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 g_object_unref(pixbuf_scaled);
756 static void begin_print(GtkPrintOperation *operation,
757 GtkPrintContext *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 *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 options->printer.text_fields = pw->text_fields;
784 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
785 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
786 g_free(options->printer.page_text);
787 options->printer.page_text = g_strdup(tmp);
791 static void end_print_cb(GtkPrintOperation *operation,
792 GtkPrintContext *context, gpointer data)
794 PrintWindow *pw = data;
798 GtkPrintSettings *print_settings;
799 GtkPageSetup *page_setup;
800 GError *error = NULL;
802 print_settings = gtk_print_operation_get_print_settings(operation);
803 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
805 gtk_print_settings_to_file(print_settings, path, &error);
808 log_printf("Error: Print settings save failed:\n%s", error->message);
813 g_object_unref(print_settings);
815 page_setup = gtk_print_operation_get_default_page_setup(operation);
816 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
818 gtk_page_setup_to_file(page_setup, path, &error);
821 log_printf("Error: Print page setup save failed:\n%s", error->message);
826 g_object_unref(page_setup);
828 print_pref_store(pw);
830 work = pw->print_pixbuf_queue;
836 g_object_unref(pixbuf);
840 g_list_free(pw->print_pixbuf_queue);
841 g_object_unref(pw->page_text);
845 void print_window_new(FileData *fd, GList *selection, GList *list, GtkWidget *parent)
849 GtkPrintOperation *operation;
850 GtkPageSetup *page_setup;
853 GError *error = NULL;
855 GtkPrintSettings *settings;
857 pw = g_new0(PrintWindow, 1);
859 pw->source_selection = file_data_process_groups_in_selection(selection, FALSE, NULL);
860 pw->text_fields = options->printer.text_fields;
862 if (print_layout_page_count(pw) == 0)
867 vbox = gtk_vbox_new(FALSE, 0);
868 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
869 gtk_widget_show(vbox);
871 print_text_menu(vbox, pw);
874 pw->print_pixbuf_queue = NULL;
875 pw->job_render_finished = FALSE;
878 operation = gtk_print_operation_new();
879 settings = gtk_print_settings_new();
881 gtk_print_operation_set_custom_tab_label(operation, "Options");
882 gtk_print_operation_set_use_full_page(operation, TRUE);
883 gtk_print_operation_set_unit(operation, GTK_UNIT_POINTS);
884 gtk_print_operation_set_embed_page_setup(operation, TRUE);
885 gtk_print_operation_set_allow_async (operation, TRUE);
886 dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
889 dir = g_get_home_dir();
892 uri = g_build_filename("file:/", dir, "geeqie-file.pdf", NULL);
893 gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
896 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
897 gtk_print_settings_load_file(settings, path, &error);
900 log_printf("Error: Printer settings load failed:\n%s", error->message);
904 gtk_print_operation_set_print_settings(operation, settings);
907 page_setup = gtk_page_setup_new();
908 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
909 gtk_page_setup_load_file(page_setup, path, &error);
912 log_printf("Error: Print page setup load failed:\n%s", error->message);
916 gtk_print_operation_set_default_page_setup(operation, page_setup);
919 g_signal_connect (G_OBJECT (operation), "begin-print",
920 G_CALLBACK (begin_print), pw);
921 g_signal_connect (G_OBJECT (operation), "draw-page",
922 G_CALLBACK (draw_page), pw);
923 g_signal_connect (G_OBJECT (operation), "end-print",
924 G_CALLBACK (end_print_cb), pw);
925 g_signal_connect (G_OBJECT (operation), "create-custom-widget",
926 G_CALLBACK (option_tab_cb), pw);
927 g_signal_connect (G_OBJECT (operation), "paginate",
928 G_CALLBACK (paginate_cb), pw);
930 gtk_print_operation_set_n_pages(operation, print_layout_page_count(pw));
932 gtk_print_operation_run(operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
933 GTK_WINDOW (parent), &error);
939 dialog = gtk_message_dialog_new(GTK_WINDOW (parent),
940 GTK_DIALOG_DESTROY_WITH_PARENT,
943 "%s", error->message);
944 g_error_free (error);
946 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
948 gtk_widget_show (dialog);
951 g_object_unref(page_setup);
952 g_object_unref(settings);
954 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */