X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=shell%2Fev-jobs.c;h=45728529c48fda033f3bb967170da2737454c322;hb=c5de241a3ab5fd9557326bd7135dfb550223f974;hp=8e140f8808f4126dcb1ae0a00e5d6cbfc559cfb9;hpb=85fa11d86616d3a9c5a5cfeba78dd7aa72e7997a;p=evince.git diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 8e140f88..45728529 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -4,16 +4,16 @@ #include "ev-document-links.h" #include "ev-document-images.h" #include "ev-document-forms.h" +#include "ev-file-exporter.h" #include "ev-document-factory.h" #include "ev-document-misc.h" #include "ev-file-helpers.h" #include "ev-document-fonts.h" -#include "ev-selection.h" #include "ev-async-renderer.h" -#include "ev-file-exporter.h" -#include "ev-window.h" +#include #include +#include #include #include #include @@ -29,6 +29,8 @@ static void ev_job_thumbnail_init (EvJobThumbnail *job); static void ev_job_thumbnail_class_init (EvJobThumbnailClass *class); static void ev_job_load_init (EvJobLoad *job); static void ev_job_load_class_init (EvJobLoadClass *class); +static void ev_job_save_init (EvJobSave *job); +static void ev_job_save_class_init (EvJobSaveClass *class); static void ev_job_print_init (EvJobPrint *job); static void ev_job_print_class_init (EvJobPrintClass *class); @@ -51,6 +53,7 @@ G_DEFINE_TYPE (EvJobRender, ev_job_render, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobThumbnail, ev_job_thumbnail, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobFonts, ev_job_fonts, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobLoad, ev_job_load, EV_TYPE_JOB) +G_DEFINE_TYPE (EvJobSave, ev_job_save, EV_TYPE_JOB) G_DEFINE_TYPE (EvJobPrint, ev_job_print, EV_TYPE_JOB) static void ev_job_init (EvJob *job) { /* Do Nothing */ } @@ -278,6 +281,7 @@ ev_job_render_new (EvDocument *document, gint width, gint height, EvRectangle *selection_points, + EvSelectionStyle selection_style, GdkColor *text, GdkColor *base, gboolean include_forms, @@ -298,6 +302,7 @@ ev_job_render_new (EvDocument *document, job->rc = g_object_ref (rc); job->target_width = width; job->target_height = height; + job->selection_style = selection_style; job->text = *text; job->base = *base; job->include_forms = include_forms; @@ -344,7 +349,10 @@ static void ev_job_render_page_ready (EvJobRender *job) { job->page_ready = TRUE; - g_idle_add ((GSourceFunc)notify_page_ready, job); + g_idle_add_full (G_PRIORITY_HIGH_IDLE, + (GSourceFunc)notify_page_ready, + g_object_ref (job), + (GDestroyNotify)g_object_unref); } void @@ -370,10 +378,12 @@ ev_job_render_run (EvJobRender *job) &(job->selection), &(job->selection_points), NULL, + job->selection_style, &(job->text), &(job->base)); job->selection_region = ev_selection_get_selection_region (EV_SELECTION (EV_JOB (job)->document), job->rc, + job->selection_style, &(job->selection_points)); } @@ -556,6 +566,143 @@ ev_job_load_run (EvJobLoad *job) EV_JOB (job)->finished = TRUE; } +static void ev_job_save_init (EvJobSave *job) { /* Do Nothing */ } + +static void +ev_job_save_dispose (GObject *object) +{ + EvJobSave *job = EV_JOB_SAVE (object); + + if (job->uri) { + g_free (job->uri); + job->uri = NULL; + } + + if (job->document_uri) { + g_free (job->document_uri); + job->document_uri = NULL; + } + + if (job->error) { + g_error_free (job->error); + job->error = NULL; + } + + (* G_OBJECT_CLASS (ev_job_save_parent_class)->dispose) (object); +} + +static void +ev_job_save_class_init (EvJobSaveClass *class) +{ + GObjectClass *oclass; + + oclass = G_OBJECT_CLASS (class); + + oclass->dispose = ev_job_save_dispose; +} + +EvJob * +ev_job_save_new (EvDocument *document, + const gchar *uri, + const gchar *document_uri) +{ + EvJobSave *job; + + job = g_object_new (EV_TYPE_JOB_SAVE, NULL); + + EV_JOB (job)->document = g_object_ref (document); + job->uri = g_strdup (uri); + job->document_uri = g_strdup (document_uri); + job->error = NULL; + + return EV_JOB (job); +} + +void +ev_job_save_run (EvJobSave *job) +{ + gint fd; + gchar *filename; + gchar *tmp_filename; + gchar *local_uri; + + filename = ev_tmp_filename ("saveacopy"); + tmp_filename = g_strdup_printf ("%s.XXXXXX", filename); + g_free (filename); + + fd = g_mkstemp (tmp_filename); + if (fd == -1) { + gchar *display_name; + gint save_errno = errno; + + display_name = g_filename_display_name (tmp_filename); + g_set_error (&(job->error), + G_FILE_ERROR, + g_file_error_from_errno (save_errno), + _("Failed to create file “%s”: %s"), + display_name, g_strerror (save_errno)); + g_free (display_name); + g_free (tmp_filename); + + return; + } + + ev_document_doc_mutex_lock (); + + /* Save document to temp filename */ + local_uri = g_filename_to_uri (tmp_filename, NULL, NULL); + ev_document_save (EV_JOB (job)->document, local_uri, &(job->error)); + close (fd); + + ev_document_doc_mutex_unlock (); + + if (job->error) { + g_free (local_uri); + return; + } + + /* If original document was compressed, + * compress it again before saving + */ + if (g_object_get_data (G_OBJECT (EV_JOB (job)->document), + "uri-uncompressed")) { + EvCompressionType ctype = EV_COMPRESSION_NONE; + const gchar *ext; + gchar *uri_comp; + + ext = g_strrstr (job->document_uri, ".gz"); + if (ext && g_ascii_strcasecmp (ext, ".gz") == 0) + ctype = EV_COMPRESSION_GZIP; + + ext = g_strrstr (job->document_uri, ".bz2"); + if (ext && g_ascii_strcasecmp (ext, ".bz2") == 0) + ctype = EV_COMPRESSION_BZIP2; + + uri_comp = ev_file_compress (local_uri, ctype, &(job->error)); + g_free (local_uri); + ev_tmp_filename_unlink (tmp_filename); + + if (!uri_comp || job->error) { + local_uri = NULL; + } else { + local_uri = uri_comp; + } + } + + g_free (tmp_filename); + + if (job->error) { + g_free (local_uri); + return; + } + + if (!local_uri) + return; + + ev_xfer_uri_simple (local_uri, job->uri, &(job->error)); + ev_tmp_uri_unlink (local_uri); +} + EvJob * ev_job_print_new (EvDocument *document, const gchar *format, @@ -665,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) { @@ -682,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; @@ -705,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); @@ -716,41 +924,24 @@ ev_job_print_run (EvJobPrint *job) fc.paper_width = job->width; fc.paper_height = job->height; fc.duplex = FALSE; - fc.pages_per_sheet = job->pages_per_sheet; + fc.pages_per_sheet = MAX (1, job->pages_per_sheet); 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; - - if (job->n_ranges > 0 && - !ev_print_job_print_page_in_range (job, page)) { - page += step; - continue; - } + page = job->reverse ? n_pages - 1 : 0; + n_copies = job->collate ? job->copies : 1; - 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; @@ -760,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;