X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-print-job.c;h=d042ab680214ce67824d87ecf30d45e3f15b1bee;hb=ff9cbcf0866ce9afae0176b03d44fbb2da780a8c;hp=e7c1ce1b431d065a349d4f4aab539c98810656c1;hpb=3f3b7a054f3b5d704fc1389b4551a4bed49e63bc;p=evince.git diff --git a/shell/ev-print-job.c b/shell/ev-print-job.c index e7c1ce1b..d042ab68 100644 --- a/shell/ev-print-job.c +++ b/shell/ev-print-job.c @@ -32,8 +32,9 @@ #define GNOME_PRINT_UNSTABLE_API #include -#include "ev-ps-exporter.h" +#include "ev-file-exporter.h" #include "ev-print-job.h" +#include "ev-page-cache.h" #define EV_PRINT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_PRINT_JOB, EvPrintJobClass)) #define EV_IS_PRINT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_PRINT_JOB)) @@ -44,21 +45,17 @@ struct _EvPrintJob { EvDocument *document; GnomePrintJob *gnome_print_job; - double width; /* FIXME unused */ - double height; /* FIXME unused */ - gboolean duplex; /* FIXME unused */ - int copies; /* FIXME unused */ - int collate; /* FIXME unsued */ - - /* range printing */ - int first_page; - int last_page; + EvFileExporterContext fc; + int copies; + int collate; int fd; char *temp_file; guint idle_id; gboolean printing; int next_page; + int copies_done; + int shift; }; struct _EvPrintJobClass { @@ -219,7 +216,8 @@ void ev_print_job_use_print_dialog_settings (EvPrintJob *job, GnomePrintDialog *dialog) { GnomePrintConfig *print_config; - EvPageCache *page_cache = ev_document_get_page_cache (job->document); + EvPageCache *page_cache = ev_page_cache_get (job->document); + gint first_page, last_page; g_return_if_fail (EV_IS_PRINT_JOB (job)); g_return_if_fail (GNOME_IS_PRINT_DIALOG (dialog)); @@ -227,28 +225,31 @@ ev_print_job_use_print_dialog_settings (EvPrintJob *job, GnomePrintDialog *dialo print_config = gnome_print_dialog_get_config (dialog); gnome_print_dialog_get_copies (dialog, &job->copies, &job->collate); gnome_print_config_get_page_size (print_config, - &job->width, &job->height); + &job->fc.paper_width, &job->fc.paper_height); gnome_print_config_get_boolean (print_config, - (guchar *)GNOME_PRINT_KEY_DUPLEX, &job->duplex); + (guchar *)GNOME_PRINT_KEY_DUPLEX, &job->fc.duplex); - page_cache = ev_document_get_page_cache (job->document); + page_cache = ev_page_cache_get (job->document); /* get the printing ranges */ switch (gnome_print_dialog_get_range (dialog)) { case GNOME_PRINT_RANGE_ALL: - job->first_page = 0; - job->last_page = ev_page_cache_get_n_pages (page_cache) - 1; + first_page = 0; + last_page = ev_page_cache_get_n_pages (page_cache) - 1; break; case GNOME_PRINT_RANGE_RANGE: - gnome_print_dialog_get_range_page (dialog, &job->first_page, &job->last_page); + gnome_print_dialog_get_range_page (dialog, &first_page, &last_page); /* convert 1-based user interface to 0-based internal numbers */ - job->first_page--; - job->last_page--; + first_page--; + last_page--; break; default: g_assert_not_reached (); } + job->fc.first_page = MIN (first_page, last_page); + job->fc.last_page = MAX (first_page, last_page); + gnome_print_config_unref (print_config); } @@ -257,28 +258,49 @@ idle_print_handler (EvPrintJob *job) { if (!job->printing) { ev_document_doc_mutex_lock (); - ev_ps_exporter_begin (EV_PS_EXPORTER (job->document), - job->temp_file, job->first_page, - job->last_page); + ev_file_exporter_begin (EV_FILE_EXPORTER (job->document), + &(job->fc)); ev_document_doc_mutex_unlock (); - job->next_page = job->first_page; + job->next_page = job->fc.first_page; + job->shift = (job->fc.first_page > job->fc.last_page) ? -1 : 1; job->printing = TRUE; return TRUE; } - - if (job->next_page <= job->last_page) { + + if ((job->next_page - job->fc.last_page) * job->shift <= 0) { + EvRenderContext *rc; #if 0 g_printerr ("Printing page %d\n", job->next_page); #endif + rc = ev_render_context_new (0, job->next_page, 1.0); + ev_document_doc_mutex_lock (); - ev_ps_exporter_do_page (EV_PS_EXPORTER (job->document), - job->next_page); + ev_file_exporter_do_page (EV_FILE_EXPORTER (job->document), rc); ev_document_doc_mutex_unlock (); - job->next_page++; + + g_object_unref (rc); + + if (job->collate) { + /* collate must repeat the same page */ + job->copies_done++; + if(job->copies == job->copies_done) { + job->next_page += job->shift; + job->copies_done = 0; + } + } else { + job->next_page += job->shift; + if ((job->next_page - job->fc.last_page) * job->shift > 0){ + job->copies_done++; + if(job->copies_done < job->copies) { + /* more copies to go, restart to the first page */ + job->next_page = job->fc.first_page; + } + } + } return TRUE; - } else { /* no more pages */ + } else { /* no more pages or copies */ ev_document_doc_mutex_lock (); - ev_ps_exporter_end (EV_PS_EXPORTER (job->document)); + ev_file_exporter_end (EV_FILE_EXPORTER (job->document)); ev_document_doc_mutex_unlock (); close (job->fd); @@ -312,7 +334,7 @@ ev_print_job_print (EvPrintJob *job, GtkWindow *parent) g_return_if_fail (EV_IS_PRINT_JOB (job)); g_return_if_fail (job->document != NULL); - g_return_if_fail (EV_IS_PS_EXPORTER (job->document)); + g_return_if_fail (EV_IS_FILE_EXPORTER (job->document)); #if 0 g_printerr ("Printing...\n"); #endif @@ -321,6 +343,8 @@ ev_print_job_print (EvPrintJob *job, GtkWindow *parent) if (job->fd <= -1) return; /* FIXME use GError */ + job->fc.format = EV_FILE_FORMAT_PS; + job->fc.filename = job->temp_file; gnome_print_job_set_file (job->gnome_print_job, job->temp_file); g_object_ref (job);