]> www.fi.muni.cz Git - evince.git/commitdiff
Respect ranges order when printing more than one range in random order.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Thu, 11 Oct 2007 10:18:52 +0000 (10:18 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Thu, 11 Oct 2007 10:18:52 +0000 (10:18 +0000)
2007-10-10  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-jobs.c: (ev_job_print_get_page_list),
(ev_job_print_run):
* shell/ev-window.c: (ev_window_print_dialog_response_cb):
Respect ranges order when printing more than one range in random
order.

svn path=/trunk/; revision=2699

ChangeLog
shell/ev-jobs.c
shell/ev-window.c

index 25e69fafa23dd001c8aeff4dc78461b71ad0bde3..504749cb0e956ae890705e40100dda52ecb2d539 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-10-10  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-jobs.c: (ev_job_print_get_page_list),
+       (ev_job_print_run):
+       * shell/ev-window.c: (ev_window_print_dialog_response_cb):
+
+       Respect ranges order when printing more than one range in random
+       order.
+       
 2007-10-10  Martin Schanzenbach  <mschanzenbach@gmail.com>
 
        * shell/ev-window.c: (ev_window_refresh_window_thumbnail),
index c08fb0839ca72ea0f9ef7aa0224b789eaeae90c5..45728529c48fda033f3bb967170da2737454c322 100644 (file)
@@ -812,6 +812,58 @@ ev_print_job_print_page_in_set (EvJobPrint *job,
        return FALSE;
 }
 
+static gint *
+ev_job_print_get_page_list (EvJobPrint *job,
+                           gint       *n_pages)
+{
+       gint  i, j, page, max_page;
+       gint  pages = 0;
+       gint *page_list;
+
+       max_page = ev_document_get_n_pages (EV_JOB (job)->document) - 1;
+
+       for (i = 0; i < job->n_ranges; i++) {
+               gint rsize;
+               gint start, end;
+
+               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;
+
+               switch (job->page_set) {
+                       case EV_PRINT_PAGE_SET_EVEN:
+                               pages += start % 2 == 0 ? (rsize / 2) + (rsize % 2) : (rsize / 2);
+                               break;
+                       case EV_PRINT_PAGE_SET_ODD:
+                               pages += start % 2 != 0 ? (rsize / 2) + (rsize % 2) : (rsize / 2);
+                               break;
+                       default:
+                               pages += rsize;
+                               break;
+               }
+       }
+
+       *n_pages = pages;
+
+       if (pages == 0)
+               return NULL;
+
+       page_list = g_new (gint, pages);
+
+       page = 0;
+       for (i = 0; i < job->n_ranges; i++) {
+               for (j = job->ranges[i].start; j <= job->ranges[i].end; j++) {
+                       if (j > max_page)
+                               break;
+               
+                       if (ev_print_job_print_page_in_set (job, j + 1))
+                               page_list[page++] = j;
+               }
+       }
+
+       return page_list;
+}
+
 static void
 ev_job_print_do_page (EvJobPrint *job, gint page)
 {
@@ -829,6 +881,8 @@ ev_job_print_run (EvJobPrint *job)
        EvDocument            *document = EV_JOB (job)->document;
        EvFileExporterContext  fc;
        gint                   fd;
+       gint                  *page_list;
+       gint                   n_pages;
        gint                   last_page;
        gint                   first_page;
        gint                   i;
@@ -852,6 +906,13 @@ ev_job_print_run (EvJobPrint *job)
                return;
        }
 
+       page_list = ev_job_print_get_page_list (job, &n_pages);
+       if (n_pages == 0) {
+               close (fd);
+               EV_JOB (job)->finished = TRUE;
+               return;
+       }
+
        first_page = ev_print_job_get_first_page (job);
        last_page = ev_print_job_get_last_page (job);
 
@@ -867,37 +928,20 @@ ev_job_print_run (EvJobPrint *job)
 
        ev_document_doc_mutex_lock ();
        ev_file_exporter_begin (EV_FILE_EXPORTER (document), &fc);
-       ev_document_doc_mutex_unlock ();
 
        for (i = 0; i < job->copies; i++) {
                gint page, step;
+               gint n_copies;
                
                step = job->reverse ? -1 : 1;
-               page = job->reverse ? last_page : first_page;
-               
-               while ((job->reverse && (page >= first_page)) ||
-                      (!job->reverse && (page <= last_page))) {
-                       gint n_pages = 1;
-                       gint j;
+               page = job->reverse ? n_pages - 1 : 0;
+               n_copies = job->collate ? job->copies : 1;
 
-                       if (job->n_ranges > 0 &&
-                           !ev_print_job_print_page_in_range (job, page)) {
-                               page += step;
-                               continue;
-                       }
-
-                       if (!ev_print_job_print_page_in_set (job, page + 1)) {
-                               page += step;
-                               continue;
-                       }
-
-                       if (job->collate)
-                               n_pages = job->copies;
+               while ((job->reverse && (page >= 0)) || (!job->reverse && (page < n_pages))) {
+                       gint j;
 
-                       for (j = 0; j < n_pages; j++) {
-                               ev_document_doc_mutex_lock ();
-                               ev_job_print_do_page (job, page);
-                               ev_document_doc_mutex_unlock ();
+                       for (j = 0; j < n_copies; j++) {
+                               ev_job_print_do_page (job, page_list[page]);
                        }
 
                        page += step;
@@ -907,10 +951,10 @@ ev_job_print_run (EvJobPrint *job)
                        break;
        }
 
-       ev_document_doc_mutex_lock ();
        ev_file_exporter_end (EV_FILE_EXPORTER (document));
        ev_document_doc_mutex_unlock ();
-
+       
+       g_free (page_list);
        close (fd);
        
        EV_JOB (job)->finished = TRUE;
index 117ce944dadd4643aeeb13a6fb138b7eb6055184..1a20d23449d931f8459c1c20623e80b0b86091d6 100644 (file)
@@ -2360,7 +2360,17 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
                        ranges = g_memdup (page_range, n_ranges * sizeof (GtkPageRange));
        }
                break;
-       default:
+       case GTK_PRINT_PAGES_ALL: {
+               gint n_pages;
+
+               n_pages = ev_page_cache_get_n_pages (ev_page_cache_get (window->priv->document));
+               
+               ranges = g_new0 (EvPrintRange, 1);
+
+               ranges->start = 0;
+               ranges->end = n_pages - 1;
+               n_ranges = 1;
+       }
                break;
        }