X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-print-operation.c;h=1821d4f96a94a2343a363ceb6b441748ce9c1e8e;hb=858d08e4a3794e93d7c6178099c78812f130161e;hp=fb3259b4b512b6d3192c8c8b7053312a6c5682ec;hpb=f9b57c7be5c8caaec5256804ad47d1dad069a993;p=evince.git diff --git a/shell/ev-print-operation.c b/shell/ev-print-operation.c index fb3259b4..1821d4f9 100644 --- a/shell/ev-print-operation.c +++ b/shell/ev-print-operation.c @@ -21,7 +21,9 @@ #include "ev-print-operation.h" +#if GTKUNIXPRINT_ENABLED #include +#endif #include #include #include @@ -297,6 +299,7 @@ ev_print_operation_get_progress (EvPrintOperation *op) return op->progress; } +#if GTK_CHECK_VERSION (2, 17, 1) | GTKUNIXPRINT_ENABLED static void ev_print_operation_update_status (EvPrintOperation *op, gint page, @@ -322,6 +325,9 @@ ev_print_operation_update_status (EvPrintOperation *op, g_signal_emit (op, signals[STATUS_CHANGED], 0); } +#endif + +#if GTKUNIXPRINT_ENABLED /* Export interface */ #define EV_TYPE_PRINT_OPERATION_EXPORT (ev_print_operation_export_get_type()) @@ -367,7 +373,7 @@ struct _EvPrintOperationExport { gint n_pages_to_print; gint uncollated_copies; gint collated_copies; - gint uncollated, collated, total; + gint uncollated, collated, total, blank; gint range, n_ranges; GtkPageRange *ranges; @@ -676,8 +682,8 @@ export_print_inc_page (EvPrintOperationExport *export) find_range (export); export->page = export->start; } - } while ((export->page_set == GTK_PAGE_SET_EVEN && export->page % 2 == 0) || - (export->page_set == GTK_PAGE_SET_ODD && export->page % 2 == 1)); + } while ((export->page_set == GTK_PAGE_SET_EVEN && (export->page / export->pages_per_sheet) % 2 == 0) || + (export->page_set == GTK_PAGE_SET_ODD && (export->page / export->pages_per_sheet) % 2 == 1)); return TRUE; } @@ -875,7 +881,7 @@ export_job_finished (EvJobExport *job, { EvPrintOperation *op = EV_PRINT_OPERATION (export); - if (export->pages_per_sheet == 1 || export->total % export->pages_per_sheet == 0) { + if (export->pages_per_sheet == 1 || (export->total + export->blank) % export->pages_per_sheet == 0 ) { ev_document_doc_mutex_lock (); ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document)); ev_document_doc_mutex_unlock (); @@ -948,28 +954,41 @@ export_print_page (EvPrintOperationExport *export) export->total++; export->collated++; + /* when printing multiple collated copies & multiple pages per sheet we want to + prevent the next copy bleeding into the last sheet of the previous one + we therefore check whether we've reached the last page in a document + if that is the case and the given sheet is not filled with pages, + we introduce a few blank pages to finish off the sheet + to make sure nothing goes wrong, the final condition ensures that + we're not at the end of a sheet, otherwise we'd introduce a blank sheet! */ + + if (export->collate == 1 && export->total > 1 && export->pages_per_sheet > 1 && + (export->page + 1) % export->n_pages == 0 && (export->total - 1 + export->blank) % export->pages_per_sheet != 0) { + ev_document_doc_mutex_lock (); + ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document)); + /* keep track of how many blank pages have been added */ + export->blank += export->pages_per_sheet - (export->total - 1 + export->blank) % export->pages_per_sheet; + ev_document_doc_mutex_unlock (); + } + + if (export->collated == export->collated_copies) { export->collated = 0; if (!export_print_inc_page (export)) { ev_document_doc_mutex_lock (); - if (export->pages_per_sheet > 1 && - export->total - 1 % export->pages_per_sheet == 0) - ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document)); ev_file_exporter_end (EV_FILE_EXPORTER (op->document)); ev_document_doc_mutex_unlock (); close (export->fd); export->fd = -1; - update_progress (export); - export_print_done (export); return FALSE; } } - if (export->pages_per_sheet == 1 || export->total % export->pages_per_sheet == 1) { + if (export->pages_per_sheet == 1 || (export->total + export->blank) % export->pages_per_sheet == 1) { ev_document_doc_mutex_lock (); ev_file_exporter_begin_page (EV_FILE_EXPORTER (op->document)); ev_document_doc_mutex_unlock (); @@ -1101,6 +1120,8 @@ ev_print_operation_export_print_dialog_response_cb (GtkDialog *dial export->ranges[i].end = export->n_pages - 1; } break; + default: + g_warning ("Unsupported print pages setting\n"); case GTK_PRINT_PAGES_ALL: export->ranges = &export->one_range; @@ -1110,6 +1131,7 @@ ev_print_operation_export_print_dialog_response_cb (GtkDialog *dial break; } + if (export->n_ranges < 1 || !clamp_ranges (export)) { GtkWidget *message_dialog; @@ -1359,6 +1381,8 @@ ev_print_operation_export_class_init (EvPrintOperationExportClass *klass) g_object_class->finalize = ev_print_operation_export_finalize; } +#endif /* GTKUNIXPRINT_ENABLED */ + #if GTK_CHECK_VERSION (2, 17, 1) /* Print to cairo interface */ #define EV_TYPE_PRINT_OPERATION_PRINT (ev_print_operation_print_get_type()) @@ -1533,6 +1557,8 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print, { EvPrintOperation *op = EV_PRINT_OPERATION (print); cairo_t *cr; + gdouble cr_width, cr_height; + gint width, height; gtk_print_operation_set_defer_drawing (print->op); @@ -1549,8 +1575,14 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print, ev_job_print_set_page (EV_JOB_PRINT (print->job_print), page); cr = gtk_print_context_get_cairo_context (context); - ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), cr); + cr_width = gtk_print_context_get_width (context); + cr_height = gtk_print_context_get_height (context); + ev_page_cache_get_size (ev_page_cache_get (op->document), + page, 0, 1.0, + &width, &height); + cairo_scale (cr, cr_width / (gdouble)width, cr_height / (gdouble)height); + ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), cr); ev_job_scheduler_push_job (print->job_print, EV_JOB_PRIORITY_NONE); } @@ -1622,11 +1654,30 @@ ev_print_operation_print_class_init (EvPrintOperationPrintClass *klass) } #endif /* GTK_CHECK_VERSION (2, 17, 1) */ +gboolean ev_print_operation_exists_for_document (EvDocument *document) +{ +#if GTKUNIXPRINT_ENABLED +#if GTK_CHECK_VERSION (2, 17, 1) + return (EV_IS_FILE_EXPORTER(document) || EV_IS_DOCUMENT_PRINT(document)); +#else + return EV_IS_FILE_EXPORTER(document); +#endif +#else /* ! GTKUNIXPRINT_ENABLED */ +#if GTK_CHECK_VERSION (2, 17, 1) + return EV_IS_DOCUMENT_PRINT(document); +#else + return FALSE; +#endif +#endif /* GTKUNIXPRINT_ENABLED */ +} + /* Factory method */ EvPrintOperation * ev_print_operation_new (EvDocument *document) { - EvPrintOperation *op; + EvPrintOperation *op = NULL; + + g_return_val_if_fail (ev_print_operation_exists_for_document (document), NULL); #if GTK_CHECK_VERSION (2, 17, 1) if (EV_IS_DOCUMENT_PRINT (document)) @@ -1634,8 +1685,9 @@ ev_print_operation_new (EvDocument *document) "document", document, NULL)); else #endif +#if GTKUNIXPRINT_ENABLED op = EV_PRINT_OPERATION (g_object_new (EV_TYPE_PRINT_OPERATION_EXPORT, "document", document, NULL)); - +#endif return op; }