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"
27 #include "pixbuf_util.h"
29 #include "ui_fileops.h"
31 #define PRINT_SETTINGS "print_settings" // filename save printer settings
32 #define PAGE_SETUP "page_setup" // filename save page setup
34 /* padding between objects */
35 #define PRINT_TEXT_PADDING 3.0
37 /* method to use when scaling down image data */
38 #define PRINT_MAX_INTERP GDK_INTERP_HYPER
41 TEXT_INFO_FILENAME = 1 << 0,
42 TEXT_INFO_FILEDATE = 1 << 1,
43 TEXT_INFO_FILESIZE = 1 << 2,
44 TEXT_INFO_DIMENSIONS = 1 << 3,
45 TEXT_INFO_FILEPATH = 1 << 4
48 /* reverse order is important */
56 typedef struct _PrintWindow PrintWindow;
60 GList *source_selection;
64 GtkTextBuffer *page_text;
65 ImageLoader *job_loader;
67 GList *print_pixbuf_queue;
68 gboolean job_render_finished;
73 static gint print_layout_page_count(PrintWindow *pw)
77 images = g_list_length(pw->source_selection);
79 if (images < 1 ) return 0;
84 static gboolean print_job_render_image(PrintWindow *pw);
86 static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
88 PrintWindow *pw = data;
91 pixbuf = image_loader_get_pixbuf(il);
94 pw->print_pixbuf_queue = g_list_append(pw->print_pixbuf_queue, pixbuf);
96 image_loader_free(pw->job_loader);
97 pw->job_loader = NULL;
101 if (!print_job_render_image(pw))
103 pw->job_render_finished = TRUE;
107 static gboolean print_job_render_image(PrintWindow *pw)
111 fd = g_list_nth_data(pw->source_selection, pw->job_page);
112 if (!fd) return FALSE;
114 image_loader_free(pw->job_loader);
115 pw->job_loader = NULL;
117 pw->job_loader = image_loader_new(fd);
118 g_signal_connect(G_OBJECT(pw->job_loader), "done",
119 (GCallback)print_job_render_image_loader_done, pw);
121 if (!image_loader_start(pw->job_loader))
123 image_loader_free(pw->job_loader);
124 pw->job_loader= NULL;
130 static void print_text_field_set(PrintWindow *pw, TextInfo field, gboolean active)
134 pw->text_fields |= field;
138 pw->text_fields &= ~field;
142 static void print_text_cb_name(GtkWidget *widget, gpointer data)
144 PrintWindow *pw = data;
147 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
148 print_text_field_set(pw, TEXT_INFO_FILENAME, active);
151 static void print_text_cb_path(GtkWidget *widget, gpointer data)
153 PrintWindow *pw = data;
156 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
157 print_text_field_set(pw, TEXT_INFO_FILEPATH, active);
160 static void print_text_cb_date(GtkWidget *widget, gpointer data)
162 PrintWindow *pw = data;
165 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
166 print_text_field_set(pw, TEXT_INFO_FILEDATE, active);
169 static void print_text_cb_size(GtkWidget *widget, gpointer data)
171 PrintWindow *pw = data;
174 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
175 print_text_field_set(pw, TEXT_INFO_FILESIZE, active);
178 static void print_text_cb_dims(GtkWidget *widget, gpointer data)
180 PrintWindow *pw = data;
183 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
184 print_text_field_set(pw, TEXT_INFO_DIMENSIONS, active);
187 static void print_set_font_cb(GtkWidget *widget, gpointer data)
191 if (g_strcmp0(data, "Image text font") == 0)
193 option = options->printer.image_font;
197 option = options->printer.page_font;
200 #if GTK_CHECK_VERSION(3,4,0)
203 PangoFontDescription *font_desc;
205 dialog = gtk_font_chooser_dialog_new(data, GTK_WINDOW(gtk_widget_get_toplevel(widget)));
206 gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), option);
208 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL)
210 font_desc = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
211 font = pango_font_description_to_string(font_desc);
213 option = g_strdup(font);
217 gtk_widget_destroy(dialog);
221 font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
222 option = g_strdup(font);
226 static gint set_toggle(GSList *list, TextPosition pos)
228 GtkToggleButton *current_sel;
229 GtkToggleButton *new_sel;
232 current_sel = g_slist_nth(list, pos)->data;
233 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_sel)))
240 new_sel = g_slist_nth(list, new_pos)->data;
241 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(new_sel), TRUE);
246 static void image_text_position_h1_cb(GtkWidget *widget, gpointer data)
248 PrintWindow *pw = data;
251 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
253 new_set = set_toggle(pw->page_group, HEADER_1);
256 options->printer.page_text_position = new_set;
258 options->printer.image_text_position = HEADER_1;
262 static void image_text_position_h2_cb(GtkWidget *widget, gpointer data)
264 PrintWindow *pw = data;
267 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
269 new_set = set_toggle(pw->page_group, HEADER_2);
272 options->printer.page_text_position = new_set;
274 options->printer.image_text_position = HEADER_2;
278 static void image_text_position_f1_cb(GtkWidget *widget, gpointer data)
280 PrintWindow *pw = data;
283 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
285 new_set = set_toggle(pw->page_group, FOOTER_1);
288 options->printer.page_text_position = new_set;
290 options->printer.image_text_position = FOOTER_1;
294 static void image_text_position_f2_cb(GtkWidget *widget, gpointer data)
296 PrintWindow *pw = data;
299 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
301 new_set = set_toggle(pw->page_group, FOOTER_2);
304 options->printer.page_text_position = new_set;
306 options->printer.image_text_position = FOOTER_2;
310 static void page_text_position_h1_cb(GtkWidget *widget, gpointer data)
312 PrintWindow *pw = data;
315 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
317 new_set = set_toggle(pw->image_group, HEADER_1);
320 options->printer.image_text_position = new_set;
322 options->printer.page_text_position = HEADER_1;
326 static void page_text_position_h2_cb(GtkWidget *widget, gpointer data)
328 PrintWindow *pw = data;
331 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
333 new_set = set_toggle(pw->image_group, HEADER_2);
336 options->printer.image_text_position = new_set;
338 options->printer.page_text_position = HEADER_2;
342 static void page_text_position_f1_cb(GtkWidget *widget, gpointer data)
344 PrintWindow *pw = data;
347 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
349 new_set = set_toggle(pw->image_group, FOOTER_1);
352 options->printer.image_text_position = new_set;
354 options->printer.page_text_position = FOOTER_1;
358 static void page_text_position_f2_cb(GtkWidget *widget, gpointer data)
360 PrintWindow *pw = data;
363 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
365 new_set = set_toggle(pw->image_group, FOOTER_2);
368 options->printer.image_text_position = new_set;
370 options->printer.page_text_position = FOOTER_2;
374 static void print_text_menu(GtkWidget *box, PrintWindow *pw)
381 GtkWidget *image_text_button;
382 GtkWidget *page_text_button;
384 GtkWidget *page_text_view;
386 group = pref_group_new(box, FALSE, _("Image text"), GTK_ORIENTATION_VERTICAL);
388 image_text_button = pref_checkbox_new_int(group, _("Show image text"),
389 options->printer.show_image_text, &options->printer.show_image_text);
391 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
393 pref_checkbox_link_sensitivity(image_text_button, subgroup);
395 hbox = gtk_hbox_new(FALSE, 0);
396 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
398 /* order is important */
399 button1 = pref_radiobutton_new(hbox, NULL, "Header 1",
400 options->printer.image_text_position == HEADER_1,
401 G_CALLBACK(image_text_position_h1_cb), pw);
402 button1 = pref_radiobutton_new(hbox, button1, "Header 2",
403 options->printer.image_text_position == HEADER_2,
404 G_CALLBACK(image_text_position_h2_cb), pw);
405 button1 = pref_radiobutton_new(hbox, button1, "Footer 1",
406 options->printer.image_text_position == FOOTER_1,
407 G_CALLBACK(image_text_position_f1_cb), pw);
408 button1 = pref_radiobutton_new(hbox, button1, "Footer 2",
409 options->printer.image_text_position == FOOTER_2,
410 G_CALLBACK(image_text_position_f2_cb), pw);
411 gtk_widget_show(hbox);
412 pw->image_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button1)));
414 pref_checkbox_new(subgroup, _("Name"), (pw->text_fields & TEXT_INFO_FILENAME),
415 G_CALLBACK(print_text_cb_name), pw);
416 pref_checkbox_new(subgroup, _("Path"), (pw->text_fields & TEXT_INFO_FILEPATH),
417 G_CALLBACK(print_text_cb_path), pw);
418 pref_checkbox_new(subgroup, _("Date"), (pw->text_fields & TEXT_INFO_FILEDATE),
419 G_CALLBACK(print_text_cb_date), pw);
420 pref_checkbox_new(subgroup, _("Size"), (pw->text_fields & TEXT_INFO_FILESIZE),
421 G_CALLBACK(print_text_cb_size), pw);
422 pref_checkbox_new(subgroup, _("Dimensions"), (pw->text_fields & TEXT_INFO_DIMENSIONS),
423 G_CALLBACK(print_text_cb_dims), pw);
425 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
427 #if GTK_CHECK_VERSION(3,4,0)
428 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
429 G_CALLBACK(print_set_font_cb), "Image text font");
431 button = gtk_font_button_new();
432 gtk_font_button_set_title(GTK_FONT_BUTTON(button), "Image text Font");
433 gtk_font_button_set_font_name(GTK_FONT_BUTTON(button), options->printer.image_font);
434 g_signal_connect(G_OBJECT(button), "font-set",
435 G_CALLBACK(print_set_font_cb), "Image text font");
437 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
438 gtk_widget_show(button);
440 pref_spacer(group, PREF_PAD_GAP);
442 group = pref_group_new(box, FALSE, _("Page text"), GTK_ORIENTATION_VERTICAL);
444 page_text_button = pref_checkbox_new_int(group, _("Show page text"),
445 options->printer.show_page_text, &options->printer.show_page_text);
447 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
448 pref_checkbox_link_sensitivity(page_text_button, subgroup);
450 hbox = gtk_hbox_new(FALSE, 0);
451 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
453 /* order is important */
454 button2 = pref_radiobutton_new(hbox, NULL, "Header 1",
455 options->printer.page_text_position == HEADER_1,
456 G_CALLBACK(page_text_position_h1_cb), pw);
457 button2 = pref_radiobutton_new(hbox, button2, "Header 2",
458 options->printer.page_text_position == HEADER_2,
459 G_CALLBACK(page_text_position_h2_cb), pw);
460 button2 = pref_radiobutton_new(hbox, button2, "Footer 1",
461 options->printer.page_text_position == FOOTER_1,
462 G_CALLBACK(page_text_position_f1_cb), pw);
463 button2 = pref_radiobutton_new(hbox, button2, "Footer 2",
464 options->printer.page_text_position == FOOTER_2,
465 G_CALLBACK(page_text_position_f2_cb), pw);
466 gtk_widget_show(hbox);
467 pw->page_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button2)));
471 scrolled = gtk_scrolled_window_new(NULL, NULL);
472 gtk_widget_set_size_request(scrolled, 50, 50);
473 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
474 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
475 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
476 gtk_box_pack_start(GTK_BOX(subgroup), scrolled, TRUE, TRUE, 5);
477 gtk_widget_show(scrolled);
479 page_text_view = gtk_text_view_new();
480 pw->page_text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page_text_view ));
481 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(pw->page_text), options->printer.page_text, -1);
482 g_object_ref(pw->page_text);
484 gtk_widget_set_tooltip_markup(page_text_view, ("Text shown on each page of a single or multi-page print job"));
485 gtk_container_add(GTK_CONTAINER(scrolled), page_text_view);
486 gtk_widget_show(page_text_view);
488 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
490 #if GTK_CHECK_VERSION(3,4,0)
491 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
492 G_CALLBACK(print_set_font_cb), "Page text font");
494 button = gtk_font_button_new();
495 gtk_font_button_set_title(GTK_FONT_BUTTON(button), "Page text Font");
496 gtk_font_button_set_font_name(GTK_FONT_BUTTON(button), options->printer.page_font);
497 g_signal_connect(G_OBJECT(button), "font-set",
498 G_CALLBACK(print_set_font_cb), "Page text font");
500 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
501 gtk_widget_show(button);
504 static gboolean paginate_cb(GtkPrintOperation *operation,
505 GtkPrintContext *context,
508 PrintWindow *pw = data;
510 if (pw->job_render_finished)
520 static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
521 gint page_nr, gpointer data)
523 PrintWindow *pw = data;
526 gdouble context_width, context_height;
527 gdouble pixbuf_image_width, pixbuf_image_height;
528 gdouble width_offset;
529 gdouble height_offset;
531 GdkPixbuf *pixbuf_scaled;
532 GdkPixbuf *rotated = NULL;
533 PangoLayout *layout_image = NULL;
534 PangoLayout *layout_page = NULL;
535 PangoFontDescription *desc;
536 GString *image_text = g_string_new(NULL);
537 GString *page_text = g_string_new(NULL);
538 PangoRectangle ink_rect, logical_rect;
540 gdouble image_text_width, image_text_height, page_text_width, page_text_height;
543 gdouble pango_height;
544 gdouble pango_image_height;
545 gdouble pango_page_height;
546 GtkTextIter start, end;
549 fd = g_list_nth_data(pw->source_selection, page_nr);
551 pixbuf = g_list_nth_data(pw->print_pixbuf_queue, page_nr);
552 if (fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)
554 rotated = pixbuf_apply_orientation(pixbuf, fd->exif_orientation);
558 pixbuf_image_width = gdk_pixbuf_get_width(pixbuf);
559 pixbuf_image_height = gdk_pixbuf_get_height(pixbuf);
561 if (options->printer.show_image_text)
563 if (pw->text_fields & TEXT_INFO_FILENAME)
565 image_text = g_string_append(image_text, g_strdup(fd->name));
566 image_text = g_string_append(image_text, "\n");
568 if (pw->text_fields & TEXT_INFO_FILEDATE)
570 image_text = g_string_append(image_text, g_strdup(text_from_time(fd->date)));
571 image_text = g_string_append(image_text, "\n");
573 if (pw->text_fields & TEXT_INFO_FILESIZE)
575 image_text = g_string_append(image_text, g_strdup(text_from_size(fd->size)));
576 image_text = g_string_append(image_text, "\n");
578 if (pw->text_fields & TEXT_INFO_DIMENSIONS)
580 g_string_append_printf(image_text, "%d x %d", (gint)pixbuf_image_width,
581 (gint)pixbuf_image_height);
582 image_text = g_string_append(image_text, "\n");
584 if (pw->text_fields & TEXT_INFO_FILEPATH)
586 image_text = g_string_append(image_text, g_strdup(fd->path));
587 image_text = g_string_append(image_text, "\n");
589 if (image_text->len > 0)
591 image_text = g_string_truncate(image_text, image_text->len - 1);
595 if (options->printer.show_page_text)
597 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
599 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
600 page_text = g_string_append(page_text, tmp);
605 cr = gtk_print_context_get_cairo_context(context);
606 context_width = gtk_print_context_get_width(context);
607 context_height = gtk_print_context_get_height(context);
609 pango_image_height = 0;
610 pango_page_height = 0;
611 image_text_width = 0;
614 if (image_text->len > 0)
616 layout_image = pango_cairo_create_layout(cr);
618 pango_layout_set_text(layout_image, image_text->str, -1);
619 desc = pango_font_description_from_string(options->printer.image_font);
620 pango_layout_set_font_description(layout_image, desc);
622 pango_layout_get_extents(layout_image, &ink_rect, &logical_rect);
623 image_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
624 image_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
626 pango_layout_set_alignment(layout_image, PANGO_ALIGN_CENTER);
627 pango_layout_set_text(layout_image, image_text->str, -1);
629 pango_image_height = image_text_height + PRINT_TEXT_PADDING * 2;
631 pango_font_description_free(desc);
634 if (page_text->len > 0)
636 layout_page = pango_cairo_create_layout(cr);
638 pango_layout_set_text(layout_page, page_text->str, -1);
639 desc = pango_font_description_from_string(options->printer.page_font);
640 pango_layout_set_font_description(layout_page, desc);
642 pango_layout_get_extents(layout_page, &ink_rect, &logical_rect);
643 page_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
644 page_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
646 pango_layout_set_alignment(layout_page, PANGO_ALIGN_CENTER);
647 pango_layout_set_text(layout_page, page_text->str, -1);
649 pango_page_height = page_text_height + PRINT_TEXT_PADDING * 2;
651 pango_font_description_free(desc);
654 pango_height = pango_image_height + pango_page_height;
656 if ((context_width / pixbuf_image_width) < ((context_height - pango_height) / pixbuf_image_height))
659 scale = context_width / pixbuf_image_width;
660 h = pixbuf_image_height * scale;
661 height_offset = (context_height - (h + pango_height)) / 2;
666 h = context_height - pango_height ;
667 scale = (context_height - pango_height) / pixbuf_image_height;
668 w = pixbuf_image_width * scale;
670 width_offset = (context_width - (pixbuf_image_width * scale)) / 2;
673 incr_y = height_offset + PRINT_TEXT_PADDING;
675 if (options->printer.page_text_position == HEADER_1 && page_text->len > 0)
677 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
678 pango_cairo_show_layout(cr, layout_page);
680 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
683 if (options->printer.image_text_position == HEADER_1 && image_text->len > 0)
685 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
686 pango_cairo_show_layout(cr, layout_image);
688 incr_y = incr_y + PRINT_TEXT_PADDING + pango_image_height;
691 if (options->printer.page_text_position == HEADER_2 && page_text->len > 0)
693 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
694 pango_cairo_show_layout(cr, layout_page);
696 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
699 if (options->printer.image_text_position == HEADER_2 && image_text->len > 0)
701 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
702 pango_cairo_show_layout(cr, layout_image);
704 incr_y = incr_y + PRINT_TEXT_PADDING + pango_image_height;
708 incr_y = incr_y + h + PRINT_TEXT_PADDING;
710 if (options->printer.page_text_position == FOOTER_1 && page_text->len > 0)
712 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
713 pango_cairo_show_layout(cr, layout_page);
715 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
718 if (options->printer.image_text_position == FOOTER_1 && image_text->len > 0)
720 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
721 pango_cairo_show_layout(cr, layout_image);
723 incr_y = incr_y + PRINT_TEXT_PADDING + pango_image_height;
726 if (options->printer.page_text_position == FOOTER_2 && page_text->len > 0)
728 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
729 pango_cairo_show_layout(cr, layout_page);
731 incr_y = incr_y + PRINT_TEXT_PADDING + pango_page_height;
734 if (options->printer.image_text_position == FOOTER_2 && image_text->len > 0)
736 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
737 pango_cairo_show_layout(cr, layout_image);
740 pixbuf_scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
741 gdk_pixbuf_scale(pixbuf, pixbuf_scaled, 0, 0, w, h, 0, 0, scale, scale, PRINT_MAX_INTERP);
743 cairo_rectangle(cr, width_offset, image_y, w, h);
745 gdk_cairo_set_source_pixbuf(cr, pixbuf_scaled, width_offset, image_y);
749 if (image_text->len > 0)
751 g_object_unref(layout_image);
752 g_string_free(image_text, TRUE);
754 if (page_text->len > 0)
756 g_object_unref(layout_page);
757 g_string_free(page_text, TRUE);
760 g_object_unref(pixbuf_scaled);
761 if (rotated) g_object_unref(rotated);
766 static void begin_print(GtkPrintOperation *operation,
767 GtkPrintContext *context,
770 PrintWindow *pw = user_data;
773 page_count = print_layout_page_count(pw);
774 gtk_print_operation_set_n_pages (operation, page_count);
776 print_job_render_image(pw);
780 GObject *option_tab_cb(GtkPrintOperation *operation, gpointer user_data)
782 PrintWindow *pw = user_data;
784 return G_OBJECT(pw->vbox);
787 static void print_pref_store(PrintWindow *pw)
790 GtkTextIter start, end;
792 options->printer.text_fields = pw->text_fields;
794 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
795 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
796 g_free(options->printer.page_text);
797 options->printer.page_text = g_strdup(tmp);
801 static void end_print_cb(GtkPrintOperation *operation,
802 GtkPrintContext *context, gpointer data)
804 PrintWindow *pw = data;
808 GtkPrintSettings *print_settings;
809 GtkPageSetup *page_setup;
810 GError *error = NULL;
812 print_settings = gtk_print_operation_get_print_settings(operation);
813 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
815 gtk_print_settings_to_file(print_settings, path, &error);
818 log_printf("Error: Print settings save failed:\n%s", error->message);
823 g_object_unref(print_settings);
825 page_setup = gtk_print_operation_get_default_page_setup(operation);
826 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
828 gtk_page_setup_to_file(page_setup, path, &error);
831 log_printf("Error: Print page setup save failed:\n%s", error->message);
836 g_object_unref(page_setup);
838 print_pref_store(pw);
840 work = pw->print_pixbuf_queue;
846 g_object_unref(pixbuf);
850 g_list_free(pw->print_pixbuf_queue);
851 g_object_unref(pw->page_text);
855 void print_window_new(FileData *fd, GList *selection, GList *list, GtkWidget *parent)
859 GtkPrintOperation *operation;
860 GtkPageSetup *page_setup;
863 GError *error = NULL;
865 GtkPrintSettings *settings;
867 pw = g_new0(PrintWindow, 1);
869 pw->source_selection = file_data_process_groups_in_selection(selection, FALSE, NULL);
870 pw->text_fields = options->printer.text_fields;
872 if (print_layout_page_count(pw) == 0)
877 vbox = gtk_vbox_new(FALSE, 0);
878 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
879 gtk_widget_show(vbox);
881 print_text_menu(vbox, pw);
884 pw->print_pixbuf_queue = NULL;
885 pw->job_render_finished = FALSE;
888 operation = gtk_print_operation_new();
889 settings = gtk_print_settings_new();
891 gtk_print_operation_set_custom_tab_label(operation, "Options");
892 gtk_print_operation_set_use_full_page(operation, TRUE);
893 gtk_print_operation_set_unit(operation, GTK_UNIT_POINTS);
894 gtk_print_operation_set_embed_page_setup(operation, TRUE);
895 gtk_print_operation_set_allow_async (operation, TRUE);
896 dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
899 dir = g_get_home_dir();
902 uri = g_build_filename("file:/", dir, "geeqie-file.pdf", NULL);
903 gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
906 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
907 gtk_print_settings_load_file(settings, path, &error);
910 log_printf("Error: Printer settings load failed:\n%s", error->message);
914 gtk_print_operation_set_print_settings(operation, settings);
917 page_setup = gtk_page_setup_new();
918 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
919 gtk_page_setup_load_file(page_setup, path, &error);
922 log_printf("Error: Print page setup load failed:\n%s", error->message);
926 gtk_print_operation_set_default_page_setup(operation, page_setup);
929 g_signal_connect (G_OBJECT (operation), "begin-print",
930 G_CALLBACK (begin_print), pw);
931 g_signal_connect (G_OBJECT (operation), "draw-page",
932 G_CALLBACK (draw_page), pw);
933 g_signal_connect (G_OBJECT (operation), "end-print",
934 G_CALLBACK (end_print_cb), pw);
935 g_signal_connect (G_OBJECT (operation), "create-custom-widget",
936 G_CALLBACK (option_tab_cb), pw);
937 g_signal_connect (G_OBJECT (operation), "paginate",
938 G_CALLBACK (paginate_cb), pw);
940 gtk_print_operation_set_n_pages(operation, print_layout_page_count(pw));
942 gtk_print_operation_run(operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
943 GTK_WINDOW (parent), &error);
949 dialog = gtk_message_dialog_new(GTK_WINDOW (parent),
950 GTK_DIALOG_DESTROY_WITH_PARENT,
953 "%s", error->message);
954 g_error_free (error);
956 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
958 gtk_widget_show (dialog);
961 g_object_unref(page_setup);
962 g_object_unref(settings);
964 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */