]> www.fi.muni.cz Git - evince.git/commitdiff
When printing multiple pages per sheet in reverse option, do not invert
authorCarlos Garcia Campos <carlosgc@gnome.org>
Thu, 11 Oct 2007 10:18:58 +0000 (10:18 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Thu, 11 Oct 2007 10:18:58 +0000 (10:18 +0000)
2007-10-11  Carlos Garcia Campos  <carlosgc@gnome.org>
* 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
backend/pdf/ev-poppler.cc
libdocument/ev-file-exporter.c
libdocument/ev-file-exporter.h
shell/ev-jobs.c

index 504749cb0e956ae890705e40100dda52ecb2d539..b01fdec0aacb9b0e21a09f6fef01cc75a1d7389c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-10-11  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * 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  <carlosgc@gnome.org>
 
        * shell/ev-jobs.c: (ev_job_print_get_page_list),
index 9ccfd22291411ec758843263d5fd8490d49136f1..4a783416e4a60ed5beaf743a56fe2c23025b3273 100644 (file)
@@ -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;
 }
index 1b942a25cad7f667366e305898fb5fa6db8d6a69..9b2bc6933ee732f2ce9d08051078fb8fb92e5ead 100644 (file)
@@ -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)
 {
index c05ea27d966e3edbdb38378899b750f28c23ce2b..6302cd20ac9292169396de1c57e0720c15334594 100644 (file)
@@ -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);
 
index 45728529c48fda033f3bb967170da2737454c322..84eb365cd17c290512f4320a73a8a92ea522b4c2 100644 (file)
@@ -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;
 }