24 #if GTKUNIXPRINT_ENABLED
25 #include <gtk/gtkunixprint.h>
27 #include <glib/gi18n.h>
28 #include <glib/gstdio.h>
69 GtkPageSetup *page_setup);
72 const gchar *job_name);
85 GtkPrintOperationResult result);
98 g_object_unref (op->document);
107 (* G_OBJECT_CLASS (ev_print_operation_parent_class)->finalize) (
object);
120 op->document = g_value_dup_object (value);
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
135 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
140 g_object_class_install_property (g_object_class,
142 g_param_spec_object (
"document",
144 "The document to print",
147 G_PARAM_CONSTRUCT_ONLY |
148 G_PARAM_STATIC_STRINGS));
150 g_signal_new (
"done",
151 G_TYPE_FROM_CLASS (g_object_class),
155 g_cclosure_marshal_VOID__ENUM,
157 GTK_TYPE_PRINT_OPERATION_RESULT);
159 g_signal_new (
"begin_print",
160 G_TYPE_FROM_CLASS (g_object_class),
164 g_cclosure_marshal_VOID__VOID,
167 g_signal_new (
"status_changed",
168 G_TYPE_FROM_CLASS (g_object_class),
172 g_cclosure_marshal_VOID__VOID,
184 g_return_if_fail (current_page >= 0);
186 class->set_current_page (op, current_page);
196 g_return_if_fail (GTK_IS_PRINT_SETTINGS (print_settings));
198 class->set_print_settings (op, print_settings);
214 return class->get_print_settings (op);
219 GtkPageSetup *page_setup)
224 g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
226 class->set_default_page_setup (op, page_setup);
242 return class->get_default_page_setup (op);
247 const gchar *job_name)
252 g_return_if_fail (job_name != NULL);
254 class->set_job_name (op, job_name);
264 return class->get_job_name (op);
275 class->run (op, parent);
296 class->get_error (op, error);
307 class->set_embed_page_setup (op, embed);
317 return class->get_embed_page_setup (op);
325 return op->status ? op->status :
"";
342 if (op->status && op->progress == progress)
347 if (op->print_preview) {
350 op->status = g_strdup (
_(
"Preparing preview…"));
351 }
else if (page > n_pages) {
352 op->status = g_strdup (
_(
"Finishing…"));
354 op->status = g_strdup_printf (
_(
"Generating preview: page %d of %d"),
360 op->status = g_strdup (
_(
"Preparing to print…"));
361 }
else if (page > n_pages) {
362 op->status = g_strdup (
_(
"Finishing…"));
364 op->status = g_strdup_printf (
_(
"Printing page %d of %d…"),
369 op->progress = MIN (1.0, progress);
374 #if GTKUNIXPRINT_ENABLED
377 #define EV_TYPE_PRINT_OPERATION_EXPORT (ev_print_operation_export_get_type())
378 #define EV_PRINT_OPERATION_EXPORT(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PRINT_OPERATION_EXPORT, EvPrintOperationExport))
379 #define EV_PRINT_OPERATION_EXPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PRINT_OPERATION_EXPORT, EvPrintOperationExportClass))
380 #define EV_IS_PRINT_OPERATION_EXPORT(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PRINT_OPERATION_EXPORT))
382 typedef struct _EvPrintOperationExport EvPrintOperationExport;
383 typedef struct _EvPrintOperationExportClass EvPrintOperationExportClass;
385 static GType ev_print_operation_export_get_type (
void) G_GNUC_CONST;
387 static
void ev_print_operation_export_begin (EvPrintOperationExport *export);
388 static gboolean export_print_page (EvPrintOperationExport *export);
389 static
void export_cancel (EvPrintOperationExport *export);
391 struct _EvPrintOperationExport {
394 GtkWindow *parent_window;
401 GtkPageSetup *page_setup;
407 gint pages_per_sheet;
411 gboolean embed_page_setup;
417 gint n_pages_to_print;
418 gint uncollated_copies;
419 gint collated_copies;
420 gint uncollated, collated, total;
422 gint sheet, page_count;
424 gint range, n_ranges;
425 GtkPageRange *ranges;
426 GtkPageRange one_range;
428 gint page, start, end, inc;
431 struct _EvPrintOperationExportClass {
438 static GHashTable *print_queue = NULL;
441 queue_free (GQueue *queue)
443 g_queue_foreach (queue, (GFunc)g_object_unref, NULL);
444 g_queue_free (queue);
448 ev_print_queue_init (
void)
450 if (G_UNLIKELY (print_queue == NULL)) {
451 print_queue = g_hash_table_new_full (g_direct_hash,
454 (GDestroyNotify)queue_free);
459 remove_document_queue (gpointer data,
463 g_hash_table_remove (print_queue, document);
467 ev_print_queue_is_empty (
EvDocument *document)
471 queue = g_hash_table_lookup (print_queue, document);
472 return (!queue || g_queue_is_empty (queue));
480 queue = g_hash_table_lookup (print_queue, op->document);
482 queue = g_queue_new ();
483 g_hash_table_insert (print_queue,
486 g_object_weak_ref (G_OBJECT (op->document),
487 (GWeakNotify)remove_document_queue,
491 g_queue_push_head (queue, g_object_ref (op));
500 queue = g_hash_table_lookup (print_queue, document);
501 if (!queue || g_queue_is_empty (queue))
504 op = g_queue_pop_tail (queue);
515 queue = g_hash_table_lookup (print_queue, document);
516 if (!queue || g_queue_is_empty (queue))
519 return g_queue_peek_tail (queue);
526 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
528 g_return_if_fail (current_page < export->n_pages);
530 export->current_page = current_page;
537 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
539 if (print_settings == export->print_settings)
542 g_object_ref (print_settings);
543 if (export->print_settings)
544 g_object_unref (export->print_settings);
548 static GtkPrintSettings *
551 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
553 return export->print_settings;
558 GtkPageSetup *page_setup)
560 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
562 if (page_setup == export->page_setup)
565 g_object_ref (page_setup);
566 if (export->page_setup)
567 g_object_unref (export->page_setup);
568 export->page_setup = page_setup;
571 static GtkPageSetup *
574 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
576 return export->page_setup;
581 const gchar *job_name)
583 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
585 g_free (export->job_name);
586 export->job_name = g_strdup (job_name);
592 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
594 return export->job_name;
598 ev_print_operation_export_set_printer (EvPrintOperationExport *export,
601 if (printer == export->printer)
604 g_object_ref (printer);
606 g_object_unref (export->printer);
607 export->printer = printer;
611 find_range (EvPrintOperationExport *export)
615 range = &export->ranges[export->range];
617 if (export->inc < 0) {
618 export->start = range->end;
619 export->end = range->start - 1;
621 export->start = range->start;
622 export->end = range->end + 1;
627 clamp_ranges (EvPrintOperationExport *export)
629 gint num_of_correct_ranges = 0;
630 gint n_pages_to_print = 0;
632 gboolean null_flag =
FALSE;
634 for (i = 0; i < export->n_ranges; i++) {
637 if ((export->ranges[i].start >= 0) &&
638 (export->ranges[i].start < export->n_pages) &&
639 (export->ranges[i].end >= 0) &&
640 (export->ranges[i].end < export->n_pages)) {
641 export->ranges[num_of_correct_ranges] = export->ranges[i];
642 num_of_correct_ranges++;
643 }
else if ((export->ranges[i].start >= 0) &&
644 (export->ranges[i].start < export->n_pages) &&
645 (export->ranges[i].end >= export->n_pages)) {
646 export->ranges[i].end = export->n_pages - 1;
647 export->ranges[num_of_correct_ranges] = export->ranges[i];
648 num_of_correct_ranges++;
649 }
else if ((export->ranges[i].end >= 0) &&
650 (export->ranges[i].end < export->n_pages) &&
651 (export->ranges[i].start < 0)) {
652 export->ranges[i].start = 0;
653 export->ranges[num_of_correct_ranges] = export->ranges[i];
654 num_of_correct_ranges++;
657 n_pages = export->ranges[i].end - export->ranges[i].start + 1;
658 if (export->page_set == GTK_PAGE_SET_ALL) {
659 n_pages_to_print += n_pages;
660 }
else if (n_pages % 2 == 0) {
661 n_pages_to_print += n_pages / 2;
662 }
else if (export->page_set == GTK_PAGE_SET_EVEN) {
663 if (n_pages==1 && export->ranges[i].start % 2 == 0)
666 n_pages_to_print += export->ranges[i].start % 2 == 0 ?
667 n_pages / 2 : (n_pages / 2) + 1;
668 }
else if (export->page_set == GTK_PAGE_SET_ODD) {
669 if (n_pages==1 && export->ranges[i].start % 2 != 0)
672 n_pages_to_print += export->ranges[i].start % 2 == 0 ?
673 (n_pages / 2) + 1 : n_pages / 2;
677 if (null_flag && !n_pages_to_print) {
680 export->n_ranges = num_of_correct_ranges;
681 export->n_pages_to_print = n_pages_to_print;
687 get_first_and_last_page (EvPrintOperationExport *export,
692 gint first_page = G_MAXINT;
693 gint last_page = G_MININT;
694 gint max_page = export->n_pages - 1;
696 if (export->n_ranges == 0) {
703 for (i = 0; i < export->n_ranges; i++) {
704 if (export->ranges[i].start < first_page)
705 first_page = export->ranges[i].start;
706 if (export->ranges[i].end > last_page)
707 last_page = export->ranges[i].end;
710 *first = MAX (0, first_page);
711 *last = MIN (max_page, last_page);
715 export_print_inc_page (EvPrintOperationExport *export)
718 export->page += export->inc;
721 if (export->collate) {
722 export->page_count++;
723 export->sheet = 1 + (export->page_count - 1) / export->pages_per_sheet;
726 if (export->page == export->end) {
727 export->range += export->inc;
728 if (export->range == -1 || export->range == export->n_ranges) {
729 export->uncollated++;
734 if (export->pages_per_sheet > 1 && export->collate == 1 &&
735 (export->page_count - 1) % export->pages_per_sheet != 0) {
743 export->page_count += export->pages_per_sheet - (export->page_count - 1) % export->pages_per_sheet;
744 if (export->page_set == GTK_PAGE_SET_ALL ||
745 (export->page_set == GTK_PAGE_SET_EVEN && export->sheet % 2 == 0) ||
746 (export->page_set == GTK_PAGE_SET_ODD && export->sheet % 2 == 1) ) {
750 export->sheet = 1 + (export->page_count - 1) / export->pages_per_sheet;
753 if (export->uncollated == export->uncollated_copies)
756 export->range = export->inc < 0 ? export->n_ranges - 1 : 0;
759 export->page = export->start;
764 }
while ( export->collate == 1 &&
765 ((export->page_set == GTK_PAGE_SET_EVEN && export->sheet % 2 == 1) ||
766 (export->page_set == GTK_PAGE_SET_ODD && export->sheet % 2 == 0)));
772 ev_print_operation_export_clear_temp_file (EvPrintOperationExport *export)
774 if (!export->temp_file)
777 g_unlink (export->temp_file);
778 g_free (export->temp_file);
779 export->temp_file = NULL;
783 ev_print_operation_export_run_next (EvPrintOperationExport *export)
790 document = op->document;
791 ev_print_queue_pop (document);
793 next = ev_print_queue_peek (document);
795 ev_print_operation_export_begin (EV_PRINT_OPERATION_EXPORT (next));
799 gtk_print_job_finished (GtkPrintJob *print_job,
800 EvPrintOperationExport *export,
806 g_set_error_literal (&export->error,
808 GTK_PRINT_ERROR_GENERAL,
810 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_ERROR);
812 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_APPLY);
815 ev_print_operation_export_clear_temp_file (export);
816 g_object_unref (print_job);
818 ev_print_operation_export_run_next (export);
822 export_print_done (EvPrintOperationExport *export)
825 GtkPrintSettings *settings;
827 GError *error = NULL;
829 g_assert (export->temp_file != NULL);
837 settings = gtk_print_settings_copy (export->print_settings);
840 gtk_print_settings_set_page_ranges (settings, NULL, 0);
841 gtk_print_settings_set_print_pages (settings, GTK_PRINT_PAGES_ALL);
843 gtk_print_settings_set_n_copies (settings, 1);
845 gtk_print_settings_set_page_set (settings, GTK_PAGE_SET_ALL);
847 gtk_print_settings_set_scale (settings, 1.0);
849 gtk_print_settings_set_collate (settings,
FALSE);
851 gtk_print_settings_set_reverse (settings,
FALSE);
853 gtk_print_settings_set_number_up (settings, 1);
854 gtk_print_settings_set_int (settings,
"cups-"GTK_PRINT_SETTINGS_NUMBER_UP, 1);
857 if (op->print_preview) {
861 gchar *print_settings_file = NULL;
863 key_file = g_key_file_new ();
865 gtk_print_settings_to_key_file (settings, key_file, NULL);
866 gtk_page_setup_to_key_file (export->page_setup, key_file, NULL);
867 g_key_file_set_string (key_file,
"Print Job",
"title", export->job_name);
869 data = g_key_file_to_data (key_file, &data_len, &error);
873 fd = g_file_open_tmp (
"print-settingsXXXXXX", &print_settings_file, &error);
875 g_file_set_contents (print_settings_file, data, data_len, &error);
881 g_key_file_free (key_file);
885 gchar *quoted_filename;
886 gchar *quoted_settings_filename;
888 GdkAppLaunchContext *ctx;
890 quoted_filename = g_shell_quote (export->temp_file);
891 quoted_settings_filename = g_shell_quote (print_settings_file);
892 cmd = g_strdup_printf (
"evince-previewer --unlink-tempfile --print-settings %s %s",
893 quoted_settings_filename, quoted_filename);
895 g_free (quoted_filename);
896 g_free (quoted_settings_filename);
898 app = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
901 ctx = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (export->parent_window)));
902 gdk_app_launch_context_set_screen (ctx, gtk_window_get_screen (export->parent_window));
904 g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
906 g_object_unref (app);
907 g_object_unref (ctx);
914 if (print_settings_file)
915 g_unlink (print_settings_file);
916 g_free (print_settings_file);
918 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_APPLY);
921 ev_print_operation_export_run_next (export);
926 job = gtk_print_job_new (export->job_name,
930 gtk_print_job_set_source_file (job, export->temp_file, &error);
932 gtk_print_job_send (job,
933 (GtkPrintJobCompleteFunc)gtk_print_job_finished,
934 g_object_ref (export),
935 (GDestroyNotify)g_object_unref);
938 g_object_unref (settings);
941 g_set_error_literal (&export->error,
943 GTK_PRINT_ERROR_GENERAL,
945 g_error_free (error);
946 ev_print_operation_export_clear_temp_file (export);
947 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_ERROR);
949 ev_print_operation_export_run_next (export);
954 export_print_page_idle_finished (EvPrintOperationExport *export)
961 EvPrintOperationExport *export)
965 if (export->pages_per_sheet == 1 ||
966 ( export->page_count % export->pages_per_sheet == 0 &&
967 ( export->page_set == GTK_PAGE_SET_ALL ||
968 ( export->page_set == GTK_PAGE_SET_EVEN && export->sheet % 2 == 0 ) ||
969 ( export->page_set == GTK_PAGE_SET_ODD && export->sheet % 2 == 1 ) ) ) ) {
977 export->idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
978 (GSourceFunc)export_print_page,
980 (GDestroyNotify)export_print_page_idle_finished);
985 EvPrintOperationExport *export)
987 export_cancel (export);
991 export_cancel (EvPrintOperationExport *export)
995 if (export->idle_id > 0)
996 g_source_remove (export->idle_id);
999 if (export->job_export) {
1000 g_signal_handlers_disconnect_by_func (export->job_export,
1001 export_job_finished,
1003 g_signal_handlers_disconnect_by_func (export->job_export,
1004 export_job_cancelled,
1006 g_object_unref (export->job_export);
1007 export->job_export = NULL;
1010 if (export->fd != -1) {
1015 ev_print_operation_export_clear_temp_file (export);
1017 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_CANCEL);
1019 ev_print_operation_export_run_next (export);
1023 update_progress (EvPrintOperationExport *export)
1028 export->n_pages_to_print,
1029 export->total / (gdouble)export->n_pages_to_print);
1033 export_print_page (EvPrintOperationExport *export)
1037 if (!export->temp_file)
1044 if (!export->collate) {
1045 export->page_count++;
1046 export->sheet = 1 + (export->page_count - 1) / export->pages_per_sheet;
1049 if (export->collated == export->collated_copies) {
1050 export->collated = 0;
1051 if (!export_print_inc_page (export)) {
1058 update_progress (export);
1059 export_print_done (export);
1066 if (!export->collate &&
1067 ((export->page_set == GTK_PAGE_SET_EVEN && export->sheet % 2 != 0) ||
1068 (export->page_set == GTK_PAGE_SET_ODD && export->sheet % 2 != 1))) {
1071 export->page_count++;
1073 export->sheet = 1 + (export->page_count - 1) / export->pages_per_sheet;
1075 if (export->collated == export->collated_copies) {
1076 export->collated = 0;
1078 if (!export_print_inc_page (export)) {
1086 update_progress (export);
1088 export_print_done (export);
1093 }
while ((export->page_set == GTK_PAGE_SET_EVEN && export->sheet % 2 != 0) ||
1094 (export->page_set == GTK_PAGE_SET_ODD && export->sheet % 2 != 1));
1098 if (export->pages_per_sheet == 1 ||
1099 (export->page_count % export->pages_per_sheet == 1 &&
1100 (export->page_set == GTK_PAGE_SET_ALL ||
1101 (export->page_set == GTK_PAGE_SET_EVEN && export->sheet % 2 == 0) ||
1102 (export->page_set == GTK_PAGE_SET_ODD && export->sheet % 2 == 1)))) {
1108 if (!export->job_export) {
1110 g_signal_connect (export->job_export,
"finished",
1111 G_CALLBACK (export_job_finished),
1113 g_signal_connect (export->job_export,
"cancelled",
1114 G_CALLBACK (export_job_cancelled),
1121 update_progress (export);
1127 ev_print_operation_export_begin (EvPrintOperationExport *export)
1131 if (!export->temp_file)
1138 export->idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
1139 (GSourceFunc)export_print_page,
1141 (GDestroyNotify)export_print_page_idle_finished);
1146 GtkPrintSettings *print_settings)
1148 const gchar *file_format;
1151 file_format = gtk_print_settings_get (print_settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
1152 if (file_format != NULL) {
1153 format = g_ascii_strcasecmp (file_format,
"pdf") == 0 ?
1167 ev_print_operation_export_print_dialog_response_cb (GtkDialog *dialog,
1169 EvPrintOperationExport *export)
1171 GtkPrintPages print_pages;
1173 GtkPageSetup *page_setup;
1174 GtkPrinter *printer;
1181 GError *error = NULL;
1185 if (response != GTK_RESPONSE_OK &&
1186 response != GTK_RESPONSE_APPLY) {
1187 gtk_widget_destroy (GTK_WIDGET (dialog));
1188 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_CANCEL);
1193 op->print_preview = (response == GTK_RESPONSE_APPLY);
1195 printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dialog));
1196 ev_print_operation_export_set_printer (export, printer);
1198 print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dialog));
1199 ev_print_operation_export_set_print_settings (op, print_settings);
1201 page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dialog));
1202 ev_print_operation_export_set_default_page_setup (op, page_setup);
1207 if ((format ==
EV_FILE_FORMAT_PS && !gtk_printer_accepts_ps (export->printer)) ||
1209 gtk_widget_destroy (GTK_WIDGET (dialog));
1211 g_set_error_literal (&export->error,
1213 GTK_PRINT_ERROR_GENERAL,
1214 _(
"Requested format is not supported by this printer."));
1215 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_ERROR);
1220 filename = g_strdup_printf (
"evince_print.%s.XXXXXX", format ==
EV_FILE_FORMAT_PDF ?
"pdf" :
"ps");
1221 export->fd = g_file_open_tmp (filename, &export->temp_file, &error);
1223 if (export->fd <= -1) {
1224 gtk_widget_destroy (GTK_WIDGET (dialog));
1226 g_set_error_literal (&export->error,
1228 GTK_PRINT_ERROR_GENERAL,
1230 g_error_free (error);
1231 g_signal_emit (op,
signals[
DONE], 0, GTK_PRINT_OPERATION_RESULT_ERROR);
1236 export->current_page = gtk_print_unix_dialog_get_current_page (GTK_PRINT_UNIX_DIALOG (dialog));
1237 export->page_set = gtk_print_settings_get_page_set (print_settings);
1238 print_pages = gtk_print_settings_get_print_pages (print_settings);
1240 switch (print_pages) {
1241 case GTK_PRINT_PAGES_CURRENT:
1242 export->ranges = &export->one_range;
1244 export->ranges[0].start = export->current_page;
1245 export->ranges[0].end = export->current_page;
1246 export->n_ranges = 1;
1249 case GTK_PRINT_PAGES_RANGES: {
1252 export->ranges = gtk_print_settings_get_page_ranges (print_settings, &export->n_ranges);
1253 for (i = 0; i < export->n_ranges; i++)
1254 if (export->ranges[i].end == -1 || export->ranges[i].end >= export->n_pages)
1255 export->ranges[i].end = export->n_pages - 1;
1259 g_warning (
"Unsupported print pages setting\n");
1260 case GTK_PRINT_PAGES_ALL:
1261 export->ranges = &export->one_range;
1263 export->ranges[0].start = 0;
1264 export->ranges[0].end = export->n_pages - 1;
1265 export->n_ranges = 1;
1270 if (export->n_ranges < 1 || !clamp_ranges (export)) {
1271 GtkWidget *message_dialog;
1273 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
1275 GTK_MESSAGE_WARNING,
1277 "%s",
_(
"Invalid page selection"));
1278 gtk_window_set_title (GTK_WINDOW (message_dialog),
_(
"Warning"));
1279 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
1280 "%s",
_(
"Your print range selection does not include any pages"));
1281 g_signal_connect (message_dialog,
"response",
1282 G_CALLBACK (gtk_widget_destroy),
1284 gtk_widget_show (message_dialog);
1289 width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
1290 height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
1291 scale = gtk_print_settings_get_scale (print_settings) * 0.01;
1297 export->pages_per_sheet = MAX (1, gtk_print_settings_get_number_up (print_settings));
1299 export->copies = gtk_print_settings_get_n_copies (print_settings);
1300 export->collate = gtk_print_settings_get_collate (print_settings);
1301 export->reverse = gtk_print_settings_get_reverse (print_settings);
1303 if (export->collate) {
1304 export->uncollated_copies = export->copies;
1305 export->collated_copies = 1;
1307 export->uncollated_copies = 1;
1308 export->collated_copies = export->copies;
1311 if (export->reverse) {
1312 export->range = export->n_ranges - 1;
1318 find_range (export);
1320 export->page = export->start - export->inc;
1321 export->collated = export->collated_copies - 1;
1323 get_first_and_last_page (export, &first_page, &last_page);
1325 export->fc.format = format;
1326 export->fc.filename = export->temp_file;
1327 export->fc.first_page = MIN (first_page, last_page);
1328 export->fc.last_page = MAX (first_page, last_page);
1329 export->fc.paper_width = width;
1330 export->fc.paper_height = height;
1331 export->fc.duplex =
FALSE;
1332 export->fc.pages_per_sheet = export->pages_per_sheet;
1334 if (ev_print_queue_is_empty (op->document))
1335 ev_print_operation_export_begin (export);
1337 ev_print_queue_push (op);
1341 gtk_widget_destroy (GTK_WIDGET (dialog));
1348 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
1350 GtkPrintCapabilities capabilities;
1352 ev_print_queue_init ();
1354 export->parent_window = parent;
1355 export->error = NULL;
1358 dialog = gtk_print_unix_dialog_new (
_(
"Print"), parent);
1359 gtk_window_set_modal (GTK_WINDOW (dialog),
TRUE);
1361 capabilities = GTK_PRINT_CAPABILITY_PREVIEW |
1363 gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dialog),
1366 gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (dialog),
1367 export->embed_page_setup);
1369 gtk_print_unix_dialog_set_current_page (GTK_PRINT_UNIX_DIALOG (dialog),
1370 export->current_page);
1372 gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dialog),
1373 export->print_settings);
1375 if (export->page_setup)
1376 gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dialog),
1377 export->page_setup);
1379 g_signal_connect (dialog,
"response",
1380 G_CALLBACK (ev_print_operation_export_print_dialog_response_cb),
1383 gtk_window_present (GTK_WINDOW (dialog));
1389 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
1391 if (export->job_export &&
1395 export_cancel (export);
1403 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
1405 g_propagate_error (error, export->error);
1406 export->error = NULL;
1413 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
1415 export->embed_page_setup = embed;
1421 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
1423 return export->embed_page_setup;
1427 ev_print_operation_export_finalize (GObject *
object)
1429 EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (
object);
1431 if (export->idle_id > 0) {
1432 g_source_remove (export->idle_id);
1433 export->idle_id = 0;
1436 if (export->fd != -1) {
1441 if (export->ranges) {
1442 if (export->ranges != &export->one_range)
1443 g_free (export->ranges);
1444 export->ranges = NULL;
1445 export->n_ranges = 0;
1448 if (export->temp_file) {
1449 g_free (export->temp_file);
1450 export->temp_file = NULL;
1453 if (export->job_name) {
1454 g_free (export->job_name);
1455 export->job_name = NULL;
1458 if (export->job_export) {
1461 g_signal_handlers_disconnect_by_func (export->job_export,
1462 export_job_finished,
1464 g_signal_handlers_disconnect_by_func (export->job_export,
1465 export_job_cancelled,
1467 g_object_unref (export->job_export);
1468 export->job_export = NULL;
1471 if (export->error) {
1472 g_error_free (export->error);
1473 export->error = NULL;
1476 if (export->print_settings) {
1477 g_object_unref (export->print_settings);
1478 export->print_settings = NULL;
1481 if (export->page_setup) {
1482 g_object_unref (export->page_setup);
1483 export->page_setup = NULL;
1486 if (export->printer) {
1487 g_object_unref (export->printer);
1488 export->printer = NULL;
1491 (* G_OBJECT_CLASS (ev_print_operation_export_parent_class)->finalize) (
object);
1495 ev_print_operation_export_init (EvPrintOperationExport *export)
1502 ev_print_operation_export_constructor (GType type,
1503 guint n_construct_properties,
1504 GObjectConstructParam *construct_params)
1507 EvPrintOperationExport *export;
1510 object = G_OBJECT_CLASS (ev_print_operation_export_parent_class)->constructor (type,
1511 n_construct_properties,
1513 export = EV_PRINT_OPERATION_EXPORT (
object);
1521 ev_print_operation_export_class_init (EvPrintOperationExportClass *klass)
1523 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
1526 ev_print_op_class->
set_current_page = ev_print_operation_export_set_current_page;
1527 ev_print_op_class->
set_print_settings = ev_print_operation_export_set_print_settings;
1528 ev_print_op_class->
get_print_settings = ev_print_operation_export_get_print_settings;
1531 ev_print_op_class->
set_job_name = ev_print_operation_export_set_job_name;
1532 ev_print_op_class->
get_job_name = ev_print_operation_export_get_job_name;
1533 ev_print_op_class->
run = ev_print_operation_export_run;
1534 ev_print_op_class->
cancel = ev_print_operation_export_cancel;
1535 ev_print_op_class->
get_error = ev_print_operation_export_get_error;
1539 g_object_class->constructor = ev_print_operation_export_constructor;
1540 g_object_class->finalize = ev_print_operation_export_finalize;
1546 #define EV_TYPE_PRINT_OPERATION_PRINT (ev_print_operation_print_get_type())
1547 #define EV_PRINT_OPERATION_PRINT(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PRINT_OPERATION_PRINT, EvPrintOperationPrint))
1548 #define EV_PRINT_OPERATION_PRINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PRINT_OPERATION_PRINT, EvPrintOperationPrintClass))
1549 #define EV_IS_PRINT_OPERATION_PRINT(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PRINT_OPERATION_PRINT))
1558 EV_SCALE_SHRINK_TO_PRINTABLE_AREA,
1559 EV_SCALE_FIT_TO_PRINTABLE_AREA
1562 #define EV_PRINT_SETTING_PAGE_SCALE "evince-print-setting-page-scale"
1563 #define EV_PRINT_SETTING_AUTOROTATE "evince-print-setting-page-autorotate"
1564 #define EV_PRINT_SETTING_PAGE_SIZE "evince-print-setting-page-size"
1596 gtk_print_operation_set_current_page (print->
op, current_page);
1601 GtkPrintSettings *print_settings)
1605 gtk_print_operation_set_print_settings (print->
op, print_settings);
1608 static GtkPrintSettings *
1613 return gtk_print_operation_get_print_settings (print->
op);
1618 GtkPageSetup *page_setup)
1622 gtk_print_operation_set_default_page_setup (print->
op, page_setup);
1625 static GtkPageSetup *
1630 return gtk_print_operation_get_default_page_setup (print->
op);
1635 const gchar *job_name)
1640 print->
job_name = g_strdup (job_name);
1642 gtk_print_operation_set_job_name (print->
op, print->
job_name);
1645 static const gchar *
1653 g_object_get (print->
op,
"job_name", &name, NULL);
1666 gtk_print_operation_run (print->
op,
1667 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
1679 gtk_print_operation_cancel (print->
op);
1688 gtk_print_operation_get_error (print->
op, error);
1697 gtk_print_operation_set_embed_page_setup (print->
op, embed);
1705 return gtk_print_operation_get_embed_page_setup (print->
op);
1710 GtkPrintContext *context)
1716 gtk_print_operation_set_n_pages (print->
op, n_pages);
1724 GtkPrintOperationResult result)
1736 GtkPrintStatus status;
1738 status = gtk_print_operation_get_status (print->
op);
1739 if (status == GTK_PRINT_STATUS_GENERATING_DATA)
1749 gtk_print_operation_draw_page_finish (print->
op);
1764 gtk_print_operation_draw_page_finish (print->
op);
1781 gtk_print_operation_draw_page_finish (print->
op);
1786 GtkPrintContext *context,
1788 GtkPageSetup *setup)
1791 gdouble width, height;
1792 GtkPaperSize *paper_size;
1798 paper_size = gtk_paper_size_new_custom (
"custom",
"custom",
1799 width, height, GTK_UNIT_POINTS);
1800 gtk_page_setup_set_paper_size_and_default_margins (setup, paper_size);
1801 gtk_paper_size_free (paper_size);
1806 gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
1808 gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_PORTRAIT);
1819 if (!gtk_print_context_get_hard_margins (context, top, bottom, left, right)) {
1832 gdouble *manual_scale)
1834 GtkPrintSettings *settings;
1837 page, width, height);
1839 settings = gtk_print_operation_get_print_settings (print->
op);
1840 *manual_scale = gtk_print_settings_get_scale (settings) / 100.0;
1841 if (*manual_scale == 1.0)
1844 *width *= *manual_scale;
1845 *height *= *manual_scale;
1850 GtkPrintContext *context,
1855 gdouble cr_width, cr_height;
1856 gdouble width, height, manual_scale, scale;
1857 gdouble x_scale, y_scale;
1858 gdouble x_offset, y_offset;
1859 gdouble top, bottom, left, right;
1861 gtk_print_operation_set_defer_drawing (print->
op);
1865 g_signal_connect (G_OBJECT (print->
job_print),
"finished",
1868 g_signal_connect (G_OBJECT (print->job_print),
"cancelled",
1871 }
else if (g_cancellable_is_cancelled (print->
job_print->cancellable)) {
1872 gtk_print_operation_cancel (print->
op);
1879 cr = gtk_print_context_get_cairo_context (context);
1880 cr_width = gtk_print_context_get_width (context);
1881 cr_height = gtk_print_context_get_height (context);
1887 x_offset = (cr_width - width) / (2 * manual_scale);
1888 y_offset = (cr_height - height) / (2 * manual_scale);
1889 cairo_translate (cr, x_offset, y_offset);
1894 x_scale = (cr_width - left - right) / width;
1895 y_scale = (cr_height - top - bottom) / height;
1896 scale = MIN (x_scale, y_scale);
1899 if (scale > 1.0 && print->
page_scale == EV_SCALE_SHRINK_TO_PRINTABLE_AREA)
1903 x_offset = (cr_width - scale * width) / (2 * manual_scale);
1904 y_offset = (cr_height - scale * height) / (2 * manual_scale);
1905 cairo_translate (cr, x_offset, y_offset);
1912 if (x_offset < left)
1913 cairo_translate (cr, left - x_offset, 0);
1915 if (x_offset < right)
1916 cairo_translate (cr, -(right - x_offset), 0);
1919 cairo_translate (cr, 0, top - y_offset);
1921 if (y_offset < bottom)
1922 cairo_translate (cr, 0, -(bottom - y_offset));
1924 cairo_translate (cr, left, top);
1927 if (print->
page_scale == EV_SCALE_FIT_TO_PRINTABLE_AREA || scale < 1.0) {
1928 cairo_scale (cr, scale, scale);
1938 GtkPrintContext *context)
1940 GtkPrintSettings *settings;
1944 gboolean autorotate;
1945 gboolean use_source_size;
1947 settings = gtk_print_operation_get_print_settings (print->
op);
1954 grid = gtk_grid_new ();
1955 gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
1956 gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
1957 gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
1959 label = gtk_label_new (
_(
"Page Scaling:"));
1960 gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
1961 gtk_widget_show (label);
1965 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (print->
scale_combo),
_(
"None"));
1966 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (print->
scale_combo),
_(
"Shrink to Printable Area"));
1967 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (print->
scale_combo),
_(
"Fit to Printable Area"));
1968 gtk_combo_box_set_active (GTK_COMBO_BOX (print->
scale_combo), page_scale);
1970 _(
"Scale document pages to fit the selected printer page. Select from one of the following:\n"
1972 "• “None”: No page scaling is performed.\n"
1974 "• “Shrink to Printable Area”: Document pages larger than the printable area"
1975 " are reduced to fit the printable area of the printer page.\n"
1977 "• “Fit to Printable Area”: Document pages are enlarged or reduced as"
1978 " required to fit the printable area of the printer page.\n"));
1979 gtk_grid_attach (GTK_GRID (grid), print->
scale_combo, 1, 0, 1, 1);
1982 print->
autorotate_button = gtk_check_button_new_with_label (
_(
"Auto Rotate and Center"));
1983 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (print->
autorotate_button), autorotate);
1985 _(
"Rotate printer page orientation of each page to match orientation of each document page. "
1986 "Document pages will be centered within the printer page."));
1990 print->
source_button = gtk_check_button_new_with_label (
_(
"Select page size using document page size"));
1991 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (print->
source_button), use_source_size);
1992 gtk_widget_set_tooltip_text (print->
source_button,
_(
"When enabled, each page will be printed on "
1993 "the same size paper as the document page."));
1994 gtk_grid_attach (GTK_GRID (grid), print->
source_button, 0, 2, 2, 1);
1997 return G_OBJECT (grid);
2002 GtkPrintContext *context)
2004 GtkPrintSettings *settings;
2009 settings = gtk_print_operation_get_print_settings (print->
op);
2027 GApplication *application;
2030 g_object_unref (print->
op);
2042 g_signal_handlers_disconnect_by_func (print->
job_print,
2045 g_signal_handlers_disconnect_by_func (print->
job_print,
2052 (* G_OBJECT_CLASS (ev_print_operation_print_parent_class)->finalize) (
object);
2054 application = g_application_get_default ();
2056 g_application_release (application);
2062 GApplication *application;
2064 print->
op = gtk_print_operation_new ();
2065 g_signal_connect_swapped (print->
op,
"begin_print",
2068 g_signal_connect_swapped (print->
op,
"done",
2071 g_signal_connect_swapped (print->
op,
"draw_page",
2074 g_signal_connect_swapped (print->
op,
"status_changed",
2077 g_signal_connect_swapped (print->
op,
"request_page_setup",
2080 g_signal_connect_swapped (print->
op,
"create_custom_widget",
2083 g_signal_connect_swapped (print->
op,
"custom_widget_apply",
2086 g_signal_connect_swapped (print->
op,
"preview",
2089 gtk_print_operation_set_allow_async (print->
op,
TRUE);
2090 gtk_print_operation_set_use_full_page (print->
op,
TRUE);
2091 gtk_print_operation_set_unit (print->
op, GTK_UNIT_POINTS);
2092 gtk_print_operation_set_custom_tab_label (print->
op,
_(
"Page Handling"));
2094 application = g_application_get_default ();
2096 g_application_hold (application);
2102 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
2124 #if GTKUNIXPRINT_ENABLED
2141 "document", document, NULL));
2143 #if GTKUNIXPRINT_ENABLED
2145 "document", document, NULL));