From 459160ed87739fa5bba5e96d0b53c6fd3bbce6b7 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Thu, 11 Oct 2007 10:18:58 +0000 Subject: [PATCH] When printing multiple pages per sheet in reverse option, do not invert 2007-10-11 Carlos Garcia Campos * backend/pdf/ev-poppler.cc: (pdf_document_file_exporter_begin_page), (pdf_document_file_exporter_do_page), (pdf_document_file_exporter_end_page), (pdf_document_file_exporter_iface_init): * libdocument/ev-file-exporter.[ch]: (ev_file_exporter_begin_page), (ev_file_exporter_end_page): * shell/ev-jobs.c: (ev_job_print_get_page_list), (ev_job_print_run): When printing multiple pages per sheet in reverse option, do not invert the order of the pages in every sheet, but the order of the sheets. Do not print blank pages when page range is invalid. Fixes bugs #484857 and #485521. svn path=/trunk/; revision=2700 --- ChangeLog | 17 ++++++++++ backend/pdf/ev-poppler.cc | 43 +++++++++++++++++++++---- libdocument/ev-file-exporter.c | 18 +++++++++++ libdocument/ev-file-exporter.h | 4 +++ shell/ev-jobs.c | 58 +++++++++++++++------------------- 5 files changed, 101 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 504749cb..b01fdec0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-10-11 Carlos Garcia Campos + + * backend/pdf/ev-poppler.cc: + (pdf_document_file_exporter_begin_page), + (pdf_document_file_exporter_do_page), + (pdf_document_file_exporter_end_page), + (pdf_document_file_exporter_iface_init): + * libdocument/ev-file-exporter.[ch]: + (ev_file_exporter_begin_page), (ev_file_exporter_end_page): + * shell/ev-jobs.c: (ev_job_print_get_page_list), + (ev_job_print_run): + + When printing multiple pages per sheet in reverse option, do not + invert the order of the pages in every sheet, but the order of the + sheets. Do not print blank pages when page range is invalid. Fixes + bugs #484857 and #485521. + 2007-10-10 Carlos Garcia Campos * shell/ev-jobs.c: (ev_job_print_get_page_list), diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 9ccfd222..4a783416 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -1592,6 +1592,29 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, #endif } +static void +pdf_document_file_exporter_begin_page (EvFileExporter *exporter) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (exporter); + PdfPrintContext *ctx = pdf_document->print_ctx; + + g_return_if_fail (pdf_document->print_ctx != NULL); + + ctx->pages_printed = 0; + + if (ctx->paper_width > ctx->paper_height) { + if (ctx->format == EV_FILE_FORMAT_PS) { + cairo_ps_surface_set_size (cairo_get_target (ctx->cr), + ctx->paper_height, + ctx->paper_width); + } else if (ctx->format == EV_FILE_FORMAT_PDF) { + cairo_pdf_surface_set_size (cairo_get_target (ctx->cr), + ctx->paper_height, + ctx->paper_width); + } + } +} + static void pdf_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) @@ -1630,9 +1653,6 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, width = ctx->paper_height; height = ctx->paper_width; rotate = !rotate; - - cairo_ps_surface_set_size (cairo_get_target (ctx->cr), - width, height); } else { width = ctx->paper_width; height = ctx->paper_height; @@ -1653,7 +1673,6 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, tmp2 = page_width; page_width = page_height; page_height = tmp2; - } pwidth = width / ctx->pages_x; @@ -1703,9 +1722,6 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, ctx->pages_printed++; - if (ctx->pages_printed % ctx->pages_per_sheet == 0) { - cairo_show_page (ctx->cr); - } cairo_restore (ctx->cr); #else /* HAVE_CAIRO_PRINT */ if (ctx->format == EV_FILE_FORMAT_PS) @@ -1715,6 +1731,17 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, g_object_unref (poppler_page); } +static void +pdf_document_file_exporter_end_page (EvFileExporter *exporter) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (exporter); + PdfPrintContext *ctx = pdf_document->print_ctx; + + g_return_if_fail (pdf_document->print_ctx != NULL); + + cairo_show_page (ctx->cr); +} + static void pdf_document_file_exporter_end (EvFileExporter *exporter) { @@ -1753,7 +1780,9 @@ static void pdf_document_file_exporter_iface_init (EvFileExporterIface *iface) { iface->begin = pdf_document_file_exporter_begin; + iface->begin_page = pdf_document_file_exporter_begin_page; iface->do_page = pdf_document_file_exporter_do_page; + iface->end_page = pdf_document_file_exporter_end_page; iface->end = pdf_document_file_exporter_end; iface->get_capabilities = pdf_document_file_exporter_get_capabilities; } diff --git a/libdocument/ev-file-exporter.c b/libdocument/ev-file-exporter.c index 1b942a25..9b2bc693 100644 --- a/libdocument/ev-file-exporter.c +++ b/libdocument/ev-file-exporter.c @@ -52,6 +52,15 @@ ev_file_exporter_begin (EvFileExporter *exporter, iface->begin (exporter, fc); } +void +ev_file_exporter_begin_page (EvFileExporter *exporter) +{ + EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter); + + if (iface->begin_page) + iface->begin_page (exporter); +} + void ev_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) @@ -61,6 +70,15 @@ ev_file_exporter_do_page (EvFileExporter *exporter, iface->do_page (exporter, rc); } +void +ev_file_exporter_end_page (EvFileExporter *exporter) +{ + EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter); + + if (iface->end_page) + iface->end_page (exporter); +} + void ev_file_exporter_end (EvFileExporter *exporter) { diff --git a/libdocument/ev-file-exporter.h b/libdocument/ev-file-exporter.h index c05ea27d..6302cd20 100644 --- a/libdocument/ev-file-exporter.h +++ b/libdocument/ev-file-exporter.h @@ -74,8 +74,10 @@ struct _EvFileExporterIface { /* Methods */ void (* begin) (EvFileExporter *exporter, EvFileExporterContext *fc); + void (* begin_page) (EvFileExporter *exporter); void (* do_page) (EvFileExporter *exporter, EvRenderContext *rc); + void (* end_page) (EvFileExporter *exporter); void (* end) (EvFileExporter *exporter); EvFileExporterCapabilities (* get_capabilities) (EvFileExporter *exporter); }; @@ -83,8 +85,10 @@ struct _EvFileExporterIface { GType ev_file_exporter_get_type (void) G_GNUC_CONST; void ev_file_exporter_begin (EvFileExporter *exporter, EvFileExporterContext *fc); +void ev_file_exporter_begin_page (EvFileExporter *exporter); void ev_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc); +void ev_file_exporter_end_page (EvFileExporter *exporter); void ev_file_exporter_end (EvFileExporter *exporter); EvFileExporterCapabilities ev_file_exporter_get_capabilities (EvFileExporter *exporter); diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 45728529..84eb365c 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -781,21 +781,6 @@ ev_print_job_get_last_page (EvJobPrint *job) return MIN (max_page, last_page); } -static gboolean -ev_print_job_print_page_in_range (EvJobPrint *job, - gint page) -{ - gint i; - - for (i = 0; i < job->n_ranges; i++) { - if (page >= job->ranges[i].start && - page <= job->ranges[i].end) - return TRUE; - } - - return FALSE; -} - static gboolean ev_print_job_print_page_in_set (EvJobPrint *job, gint page) @@ -826,6 +811,9 @@ ev_job_print_get_page_list (EvJobPrint *job, gint rsize; gint start, end; + if (job->ranges[i].start > max_page) + continue; + start = job->ranges[i].start + 1; end = job->ranges[i].end <= max_page ? job->ranges[i].end + 1 : max_page + 1; rsize = end - start + 1; @@ -864,28 +852,18 @@ ev_job_print_get_page_list (EvJobPrint *job, return page_list; } -static void -ev_job_print_do_page (EvJobPrint *job, gint page) -{ - EvDocument *document = EV_JOB (job)->document; - EvRenderContext *rc; - - rc = ev_render_context_new (0, page, 1.0); - ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc); - g_object_unref (rc); -} - void ev_job_print_run (EvJobPrint *job) { EvDocument *document = EV_JOB (job)->document; EvFileExporterContext fc; + EvRenderContext *rc; gint fd; gint *page_list; gint n_pages; gint last_page; gint first_page; - gint i; + gint i, j; gchar *filename; g_return_if_fail (EV_IS_JOB_PRINT (job)); @@ -926,6 +904,8 @@ ev_job_print_run (EvJobPrint *job) fc.duplex = FALSE; fc.pages_per_sheet = MAX (1, job->pages_per_sheet); + rc = ev_render_context_new (0, 0, 1.0); + ev_document_doc_mutex_lock (); ev_file_exporter_begin (EV_FILE_EXPORTER (document), &fc); @@ -933,17 +913,30 @@ ev_job_print_run (EvJobPrint *job) gint page, step; gint n_copies; - step = job->reverse ? -1 : 1; - page = job->reverse ? n_pages - 1 : 0; + step = job->reverse ? -1 * job->pages_per_sheet : job->pages_per_sheet; + page = job->reverse ? (n_pages / job->pages_per_sheet) * job->pages_per_sheet : 0; n_copies = job->collate ? job->copies : 1; while ((job->reverse && (page >= 0)) || (!job->reverse && (page < n_pages))) { - gint j; + gint k; + + ev_file_exporter_begin_page (EV_FILE_EXPORTER (document)); + + for (j = 0; j < job->pages_per_sheet; j++) { + gint p = page + j; + + if (p < 0 || p >= n_pages) + break; + + ev_render_context_set_page (rc, page_list[p]); - for (j = 0; j < n_copies; j++) { - ev_job_print_do_page (job, page_list[page]); + for (k = 0; k < n_copies; k++) { + ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc); + } } + ev_file_exporter_end_page (EV_FILE_EXPORTER (document)); + page += step; } @@ -956,6 +949,7 @@ ev_job_print_run (EvJobPrint *job) g_free (page_list); close (fd); + g_object_unref (rc); EV_JOB (job)->finished = TRUE; } -- 2.43.5