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;
137 #if GTK_CHECK_VERSION(3,4,0)
140 PangoFontDescription *font_desc;
142 dialog = gtk_font_chooser_dialog_new(data, GTK_WINDOW(gtk_widget_get_toplevel(widget)));
143 gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), option);
145 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL)
147 font_desc = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
148 font = pango_font_description_to_string(font_desc);
150 option = g_strdup(font);
154 gtk_widget_destroy(dialog);
158 font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
159 option = g_strdup(font);
163 static gint set_toggle(GSList *list, TextPosition pos)
165 GtkToggleButton *current_sel;
166 GtkToggleButton *new_sel;
169 current_sel = g_slist_nth(list, pos)->data;
170 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_sel)))
177 new_sel = g_slist_nth(list, new_pos)->data;
178 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(new_sel), TRUE);
183 static void image_text_position_h1_cb(GtkWidget *widget, gpointer data)
185 PrintWindow *pw = data;
188 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
190 new_set = set_toggle(pw->page_group, HEADER_1);
193 options->printer.page_text_position = new_set;
195 options->printer.image_text_position = HEADER_1;
199 static void image_text_position_h2_cb(GtkWidget *widget, gpointer data)
201 PrintWindow *pw = data;
204 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
206 new_set = set_toggle(pw->page_group, HEADER_2);
209 options->printer.page_text_position = new_set;
211 options->printer.image_text_position = HEADER_2;
215 static void image_text_position_f1_cb(GtkWidget *widget, gpointer data)
217 PrintWindow *pw = data;
220 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
222 new_set = set_toggle(pw->page_group, FOOTER_1);
225 options->printer.page_text_position = new_set;
227 options->printer.image_text_position = FOOTER_1;
231 static void image_text_position_f2_cb(GtkWidget *widget, gpointer data)
233 PrintWindow *pw = data;
236 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
238 new_set = set_toggle(pw->page_group, FOOTER_2);
241 options->printer.page_text_position = new_set;
243 options->printer.image_text_position = FOOTER_2;
247 static void page_text_position_h1_cb(GtkWidget *widget, gpointer data)
249 PrintWindow *pw = data;
252 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
254 new_set = set_toggle(pw->image_group, HEADER_1);
257 options->printer.image_text_position = new_set;
259 options->printer.page_text_position = HEADER_1;
263 static void page_text_position_h2_cb(GtkWidget *widget, gpointer data)
265 PrintWindow *pw = data;
268 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
270 new_set = set_toggle(pw->image_group, HEADER_2);
273 options->printer.image_text_position = new_set;
275 options->printer.page_text_position = HEADER_2;
279 static void page_text_position_f1_cb(GtkWidget *widget, gpointer data)
281 PrintWindow *pw = data;
284 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
286 new_set = set_toggle(pw->image_group, FOOTER_1);
289 options->printer.image_text_position = new_set;
291 options->printer.page_text_position = FOOTER_1;
295 static void page_text_position_f2_cb(GtkWidget *widget, gpointer data)
297 PrintWindow *pw = data;
300 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
302 new_set = set_toggle(pw->image_group, FOOTER_2);
305 options->printer.image_text_position = new_set;
307 options->printer.page_text_position = FOOTER_2;
311 static void set_print_image_text_string(gchar **template_string, const gchar *value)
313 g_assert(template_string);
315 g_free(*template_string);
316 *template_string = g_strdup(value);
319 static void image_text_template_view_changed_cb(GtkWidget *widget, gpointer data)
321 GtkWidget *pTextView;
322 GtkTextBuffer *pTextBuffer;
326 pTextView = GTK_WIDGET(data);
328 pTextBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pTextView));
329 gtk_text_buffer_get_start_iter(pTextBuffer, &iStart);
330 gtk_text_buffer_get_end_iter(pTextBuffer, &iEnd);
332 set_print_image_text_string(&options->printer.template_string,
333 gtk_text_buffer_get_text(pTextBuffer, &iStart, &iEnd, TRUE));
336 #define PRE_FORMATTED_COLUMNS 4
337 static void print_text_menu(GtkWidget *box, PrintWindow *pw)
344 GtkWidget *image_text_button;
345 GtkWidget *page_text_button;
347 GtkWidget *page_text_view;
348 GtkWidget *image_text_template_view;
350 GtkWidget *scrolled_pre_formatted;
351 GtkTextBuffer *buffer;
353 group = pref_group_new(box, FALSE, _("Image text"), GTK_ORIENTATION_VERTICAL);
355 image_text_button = pref_checkbox_new_int(group, _("Show image text"),
356 options->printer.show_image_text, &options->printer.show_image_text);
358 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
360 pref_checkbox_link_sensitivity(image_text_button, subgroup);
362 hbox = gtk_hbox_new(FALSE, 0);
363 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
365 /* order is important */
366 button1 = pref_radiobutton_new(hbox, NULL, "Header 1",
367 options->printer.image_text_position == HEADER_1,
368 G_CALLBACK(image_text_position_h1_cb), pw);
369 button1 = pref_radiobutton_new(hbox, button1, "Header 2",
370 options->printer.image_text_position == HEADER_2,
371 G_CALLBACK(image_text_position_h2_cb), pw);
372 button1 = pref_radiobutton_new(hbox, button1, "Footer 1",
373 options->printer.image_text_position == FOOTER_1,
374 G_CALLBACK(image_text_position_f1_cb), pw);
375 button1 = pref_radiobutton_new(hbox, button1, "Footer 2",
376 options->printer.image_text_position == FOOTER_2,
377 G_CALLBACK(image_text_position_f2_cb), pw);
378 gtk_widget_show(hbox);
379 pw->image_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button1)));
381 image_text_template_view = gtk_text_view_new();
383 scrolled_pre_formatted = osd_new(PRE_FORMATTED_COLUMNS, image_text_template_view);
384 gtk_box_pack_start(GTK_BOX(subgroup), scrolled_pre_formatted, FALSE, FALSE, 0);
385 gtk_widget_show(scrolled_pre_formatted);
386 gtk_widget_show(subgroup);
388 gtk_widget_set_tooltip_markup(image_text_template_view,
389 _("Extensive formatting options are shown in the Help file"));
391 scrolled = gtk_scrolled_window_new(NULL, NULL);
392 gtk_widget_set_size_request(scrolled, 200, 50);
393 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
394 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
395 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
396 gtk_box_pack_start(GTK_BOX(subgroup), scrolled, TRUE, TRUE, 5);
397 gtk_widget_show(scrolled);
399 gtk_container_add(GTK_CONTAINER(scrolled), image_text_template_view);
400 gtk_widget_show(image_text_template_view);
402 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(image_text_template_view));
403 if (options->printer.template_string) gtk_text_buffer_set_text(buffer, options->printer.template_string, -1);
404 g_signal_connect(G_OBJECT(buffer), "changed",
405 G_CALLBACK(image_text_template_view_changed_cb), image_text_template_view);
407 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
409 #if GTK_CHECK_VERSION(3,4,0)
410 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
411 G_CALLBACK(print_set_font_cb), "Image text font");
413 button = gtk_font_button_new();
414 gtk_font_button_set_title(GTK_FONT_BUTTON(button), "Image text Font");
415 gtk_font_button_set_font_name(GTK_FONT_BUTTON(button), options->printer.image_font);
416 g_signal_connect(G_OBJECT(button), "font-set",
417 G_CALLBACK(print_set_font_cb), "Image text font");
419 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
420 gtk_widget_show(button);
422 pref_spacer(group, PREF_PAD_GAP);
424 group = pref_group_new(box, FALSE, _("Page text"), GTK_ORIENTATION_VERTICAL);
426 page_text_button = pref_checkbox_new_int(group, _("Show page text"),
427 options->printer.show_page_text, &options->printer.show_page_text);
429 subgroup = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
430 pref_checkbox_link_sensitivity(page_text_button, subgroup);
432 hbox = gtk_hbox_new(FALSE, 0);
433 gtk_box_pack_start(GTK_BOX(subgroup), hbox, FALSE, FALSE, 0);
435 /* order is important */
436 button2 = pref_radiobutton_new(hbox, NULL, "Header 1",
437 options->printer.page_text_position == HEADER_1,
438 G_CALLBACK(page_text_position_h1_cb), pw);
439 button2 = pref_radiobutton_new(hbox, button2, "Header 2",
440 options->printer.page_text_position == HEADER_2,
441 G_CALLBACK(page_text_position_h2_cb), pw);
442 button2 = pref_radiobutton_new(hbox, button2, "Footer 1",
443 options->printer.page_text_position == FOOTER_1,
444 G_CALLBACK(page_text_position_f1_cb), pw);
445 button2 = pref_radiobutton_new(hbox, button2, "Footer 2",
446 options->printer.page_text_position == FOOTER_2,
447 G_CALLBACK(page_text_position_f2_cb), pw);
448 gtk_widget_show(hbox);
449 pw->page_group = (gtk_radio_button_get_group(GTK_RADIO_BUTTON(button2)));
451 scrolled = gtk_scrolled_window_new(NULL, NULL);
452 gtk_widget_set_size_request(scrolled, 50, 50);
453 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
454 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
455 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
456 gtk_box_pack_start(GTK_BOX(subgroup), scrolled, TRUE, TRUE, 5);
457 gtk_widget_show(scrolled);
459 page_text_view = gtk_text_view_new();
460 pw->page_text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page_text_view ));
461 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(pw->page_text), options->printer.page_text, -1);
462 g_object_ref(pw->page_text);
464 gtk_widget_set_tooltip_markup(page_text_view, (_("Text shown on each page of a single or multi-page print job")));
465 gtk_container_add(GTK_CONTAINER(scrolled), page_text_view);
466 gtk_widget_show(page_text_view);
468 hbox = pref_box_new(subgroup, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP);
470 #if GTK_CHECK_VERSION(3,4,0)
471 button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE,
472 G_CALLBACK(print_set_font_cb), "Page text font");
474 button = gtk_font_button_new();
475 gtk_font_button_set_title(GTK_FONT_BUTTON(button), "Page text Font");
476 gtk_font_button_set_font_name(GTK_FONT_BUTTON(button), options->printer.page_font);
477 g_signal_connect(G_OBJECT(button), "font-set",
478 G_CALLBACK(print_set_font_cb), "Page text font");
480 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
481 gtk_widget_show(button);
484 static gboolean paginate_cb(GtkPrintOperation *operation,
485 GtkPrintContext *context,
488 PrintWindow *pw = data;
490 if (pw->job_render_finished)
500 gchar *form_image_text(const gchar *template_string, FileData *fd, PrintWindow *pw, gint page_nr, gint total)
507 gchar *collection_name;
509 if (!fd) return NULL;
513 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
515 window_title = g_strdup(gtk_window_get_title(GTK_WINDOW(pw->parent)));
516 delimiter = g_strstr_len(window_title, -1, " - Collection - ");
519 collection_name = g_strndup(window_title, delimiter - window_title);
523 collection_name = NULL;
525 g_free(window_title);
529 osd_template_insert(vars, "collection", collection_name, OSDT_NONE);
532 osd_template_insert(vars, "number", g_strdup_printf("%d", page_nr + 1), OSDT_NO_DUP);
533 osd_template_insert(vars, "total", g_strdup_printf("%d", total), OSDT_NO_DUP);
534 osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
535 osd_template_insert(vars, "date", fd ? ((gchar *) text_from_time(fd->date)) : "", OSDT_NONE);
536 osd_template_insert(vars, "size", fd ? (text_from_size_abrev(fd->size)) : g_strdup(""), OSDT_FREE);
541 w = gdk_pixbuf_get_width(fd->pixbuf);
542 h = gdk_pixbuf_get_height(fd->pixbuf);
544 osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
545 osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
546 osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
550 osd_template_insert(vars, "width", NULL, OSDT_NONE);
551 osd_template_insert(vars, "height", NULL, OSDT_NONE);
552 osd_template_insert(vars, "res", NULL, OSDT_NONE);
555 text = image_osd_mkinfo(template_string, fd, vars);
556 g_hash_table_destroy(vars);
558 g_free(collection_name);
563 static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
564 gint page_nr, gpointer data)
566 PrintWindow *pw = data;
569 gdouble context_width, context_height;
570 gdouble pixbuf_image_width, pixbuf_image_height;
571 gdouble width_offset;
572 gdouble height_offset;
574 GdkPixbuf *rotated = NULL;
575 PangoLayout *layout_image = NULL;
576 PangoLayout *layout_page = NULL;
577 PangoFontDescription *desc;
578 GString *image_text = g_string_new(NULL);
579 GString *page_text = g_string_new(NULL);
580 PangoRectangle ink_rect, logical_rect;
582 gdouble image_text_width, image_text_height, page_text_width, page_text_height;
585 gdouble pango_height;
586 gdouble pango_image_height;
587 gdouble pango_page_height;
588 GtkTextIter start, end;
592 fd = g_list_nth_data(pw->source_selection, page_nr);
593 total = g_list_length(pw->source_selection);
595 pixbuf = g_list_nth_data(pw->print_pixbuf_queue, page_nr);
596 if (fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)
598 rotated = pixbuf_apply_orientation(pixbuf, fd->exif_orientation);
602 pixbuf_image_width = gdk_pixbuf_get_width(pixbuf);
603 pixbuf_image_height = gdk_pixbuf_get_height(pixbuf);
605 if (options->printer.show_image_text)
607 image_text = g_string_append(image_text, form_image_text(options->printer.template_string, fd, pw, page_nr, total));
610 if (options->printer.show_page_text)
612 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
614 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
615 page_text = g_string_append(page_text, tmp);
620 cr = gtk_print_context_get_cairo_context(context);
621 context_width = gtk_print_context_get_width(context);
622 context_height = gtk_print_context_get_height(context);
624 pango_image_height = 0;
625 pango_page_height = 0;
626 image_text_width = 0;
629 if (image_text->len > 0)
631 layout_image = pango_cairo_create_layout(cr);
633 pango_layout_set_text(layout_image, image_text->str, -1);
634 desc = pango_font_description_from_string(options->printer.image_font);
635 pango_layout_set_font_description(layout_image, desc);
637 pango_layout_get_extents(layout_image, &ink_rect, &logical_rect);
638 image_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
639 image_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
641 pango_layout_set_alignment(layout_image, PANGO_ALIGN_CENTER);
642 pango_layout_set_text(layout_image, image_text->str, -1);
644 pango_image_height = image_text_height + PRINT_TEXT_PADDING * 2;
646 pango_font_description_free(desc);
649 if (page_text->len > 0)
651 layout_page = pango_cairo_create_layout(cr);
653 pango_layout_set_text(layout_page, page_text->str, -1);
654 desc = pango_font_description_from_string(options->printer.page_font);
655 pango_layout_set_font_description(layout_page, desc);
657 pango_layout_get_extents(layout_page, &ink_rect, &logical_rect);
658 page_text_width = ((gdouble)logical_rect.width / PANGO_SCALE) ;
659 page_text_height = ((gdouble)logical_rect.height / PANGO_SCALE);
661 pango_layout_set_alignment(layout_page, PANGO_ALIGN_CENTER);
662 pango_layout_set_text(layout_page, page_text->str, -1);
664 pango_page_height = page_text_height + PRINT_TEXT_PADDING * 2;
666 pango_font_description_free(desc);
669 pango_height = pango_image_height + pango_page_height;
671 if ((context_width / pixbuf_image_width) < ((context_height - pango_height) / pixbuf_image_height))
674 scale = context_width / pixbuf_image_width;
675 h = pixbuf_image_height * scale;
676 height_offset = (context_height - (h + pango_height)) / 2;
681 h = context_height - pango_height ;
682 scale = (context_height - pango_height) / pixbuf_image_height;
683 w = pixbuf_image_width * scale;
685 width_offset = (context_width - (pixbuf_image_width * scale)) / 2;
688 incr_y = height_offset;
690 if (options->printer.page_text_position == HEADER_1 && page_text->len > 0)
692 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
693 pango_cairo_show_layout(cr, layout_page);
695 incr_y = incr_y + pango_page_height;
698 if (options->printer.image_text_position == HEADER_1 && image_text->len > 0)
700 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y + PRINT_TEXT_PADDING);
701 pango_cairo_show_layout(cr, layout_image);
703 incr_y = incr_y + pango_image_height;
706 if (options->printer.page_text_position == HEADER_2 && page_text->len > 0)
708 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
709 pango_cairo_show_layout(cr, layout_page);
711 incr_y = incr_y + pango_page_height;
714 if (options->printer.image_text_position == HEADER_2 && image_text->len > 0)
716 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
717 pango_cairo_show_layout(cr, layout_image);
719 incr_y = incr_y + pango_image_height;
725 if (options->printer.page_text_position == FOOTER_1 && page_text->len > 0)
727 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y + PRINT_TEXT_PADDING);
728 pango_cairo_show_layout(cr, layout_page);
730 incr_y = incr_y + pango_page_height;
733 if (options->printer.image_text_position == FOOTER_1 && image_text->len > 0)
735 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
736 pango_cairo_show_layout(cr, layout_image);
738 incr_y = incr_y + pango_image_height;
741 if (options->printer.page_text_position == FOOTER_2 && page_text->len > 0)
743 cairo_move_to(cr, (w / 2) - (page_text_width / 2) + width_offset, incr_y);
744 pango_cairo_show_layout(cr, layout_page);
746 incr_y = incr_y + pango_page_height;
749 if (options->printer.image_text_position == FOOTER_2 && image_text->len > 0)
751 cairo_move_to(cr, (w / 2) - (image_text_width / 2) + width_offset, incr_y);
752 pango_cairo_show_layout(cr, layout_image);
755 cairo_scale(cr, scale, scale);
757 cairo_rectangle(cr, width_offset * scale , image_y, pixbuf_image_width / scale, pixbuf_image_height / scale);
758 gdk_cairo_set_source_pixbuf(cr, pixbuf, width_offset / scale, image_y / scale);
761 if (image_text->len > 0)
763 g_object_unref(layout_image);
764 g_string_free(image_text, TRUE);
766 if (page_text->len > 0)
768 g_object_unref(layout_page);
769 g_string_free(page_text, TRUE);
772 if (rotated) g_object_unref(rotated);
777 static void begin_print(GtkPrintOperation *operation,
778 GtkPrintContext *context,
781 PrintWindow *pw = user_data;
784 page_count = print_layout_page_count(pw);
785 gtk_print_operation_set_n_pages (operation, page_count);
787 print_job_render_image(pw);
791 GObject *option_tab_cb(GtkPrintOperation *operation, gpointer user_data)
793 PrintWindow *pw = user_data;
795 return G_OBJECT(pw->vbox);
798 static void print_pref_store(PrintWindow *pw)
801 GtkTextIter start, end;
803 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(pw->page_text), &start, &end);
804 tmp = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(pw->page_text), &start, &end, FALSE);
805 g_free(options->printer.page_text);
806 options->printer.page_text = g_strdup(tmp);
810 static void end_print_cb(GtkPrintOperation *operation,
811 GtkPrintContext *context, gpointer data)
813 PrintWindow *pw = data;
817 GtkPrintSettings *print_settings;
818 GtkPageSetup *page_setup;
819 GError *error = NULL;
821 print_settings = gtk_print_operation_get_print_settings(operation);
822 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
824 gtk_print_settings_to_file(print_settings, path, &error);
827 log_printf("Error: Print settings save failed:\n%s", error->message);
832 g_object_unref(print_settings);
834 page_setup = gtk_print_operation_get_default_page_setup(operation);
835 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
837 gtk_page_setup_to_file(page_setup, path, &error);
840 log_printf("Error: Print page setup save failed:\n%s", error->message);
845 g_object_unref(page_setup);
847 print_pref_store(pw);
849 work = pw->print_pixbuf_queue;
855 g_object_unref(pixbuf);
859 g_list_free(pw->print_pixbuf_queue);
860 g_object_unref(pw->page_text);
864 void print_window_new(FileData *fd, GList *selection, GList *list, GtkWidget *parent)
868 GtkPrintOperation *operation;
869 GtkPageSetup *page_setup;
872 GError *error = NULL;
874 GtkPrintSettings *settings;
876 pw = g_new0(PrintWindow, 1);
878 pw->source_selection = file_data_process_groups_in_selection(selection, FALSE, NULL);
880 if (print_layout_page_count(pw) == 0)
887 vbox = gtk_vbox_new(FALSE, 0);
888 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
889 gtk_widget_show(vbox);
891 print_text_menu(vbox, pw);
894 pw->print_pixbuf_queue = NULL;
895 pw->job_render_finished = FALSE;
898 operation = gtk_print_operation_new();
899 settings = gtk_print_settings_new();
901 gtk_print_operation_set_custom_tab_label(operation, "Options");
902 gtk_print_operation_set_use_full_page(operation, TRUE);
903 gtk_print_operation_set_unit(operation, GTK_UNIT_POINTS);
904 gtk_print_operation_set_embed_page_setup(operation, TRUE);
905 gtk_print_operation_set_allow_async (operation, TRUE);
906 dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
909 dir = g_get_home_dir();
912 uri = g_build_filename("file:/", dir, "geeqie-file.pdf", NULL);
913 gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
916 path = g_build_filename(get_rc_dir(), PRINT_SETTINGS, NULL);
917 gtk_print_settings_load_file(settings, path, &error);
920 log_printf("Error: Printer settings load failed:\n%s", error->message);
924 gtk_print_operation_set_print_settings(operation, settings);
927 page_setup = gtk_page_setup_new();
928 path = g_build_filename(get_rc_dir(), PAGE_SETUP, NULL);
929 gtk_page_setup_load_file(page_setup, path, &error);
932 log_printf("Error: Print page setup load failed:\n%s", error->message);
936 gtk_print_operation_set_default_page_setup(operation, page_setup);
939 g_signal_connect (G_OBJECT (operation), "begin-print",
940 G_CALLBACK (begin_print), pw);
941 g_signal_connect (G_OBJECT (operation), "draw-page",
942 G_CALLBACK (draw_page), pw);
943 g_signal_connect (G_OBJECT (operation), "end-print",
944 G_CALLBACK (end_print_cb), pw);
945 g_signal_connect (G_OBJECT (operation), "create-custom-widget",
946 G_CALLBACK (option_tab_cb), pw);
947 g_signal_connect (G_OBJECT (operation), "paginate",
948 G_CALLBACK (paginate_cb), pw);
950 gtk_print_operation_set_n_pages(operation, print_layout_page_count(pw));
952 gtk_print_operation_run(operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
953 GTK_WINDOW (parent), &error);
959 dialog = gtk_message_dialog_new(GTK_WINDOW (parent),
960 GTK_DIALOG_DESTROY_WITH_PARENT,
963 "%s", error->message);
964 g_error_free (error);
966 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
968 gtk_widget_show (dialog);
971 g_object_unref(page_setup);
972 g_object_unref(settings);
974 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */