[evince] [printing] Fix multipage even/odd printing issues



commit 776a6fe02961d8901d21e172633d3c8d1c85dc93
Author: Bartek Kostrzewa <zoombat runbox com>
Date:   Sat May 23 17:12:24 2009 +0200

    [printing] Fix multipage even/odd printing issues
    
    Fixes bugs bgo#583429 and bgo#583388.
---
 shell/ev-print-operation.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/shell/ev-print-operation.c b/shell/ev-print-operation.c
index fb3259b..9f34fd7 100644
--- a/shell/ev-print-operation.c
+++ b/shell/ev-print-operation.c
@@ -367,7 +367,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 +676,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 +875,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 +948,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 ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]