diff options
author | Carlos Garcia Campos <carlosgc@gnome.org> | 2006-12-03 20:35:46 (GMT) |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@src.gnome.org> | 2006-12-03 20:35:46 (GMT) |
commit | 4094f85bec2a1f27274e42411555fc1ede846775 (patch) | |
tree | 462ac428e51cee3ac5c4a46f8ee7f1794285a9a7 /shell | |
parent | 592bc46cb8c4d56dd04c39ac87d287a0abcf6fa6 (diff) |
Allow printing to PDF when suppoted by the backend.
2006-12-03 Carlos Garcia Campos <carlosgc@gnome.org>
* configure.ac:
* backend/Makefile.am:
* backend/ev-file-exporter.[ch]:
* pdf/ev-poppler.cc: (pdf_document_file_exporter_*):
* ps/ps-document.c: (ps_document_file_exporter_*):
* tiff/tiff-document.c: (tiff_document_document_file_exporter_*):
* shell/ev-jobs.[ch]: (ev_job_print_new), (ev_job_print_run):
* shell/ev-window.c: (ev_window_setup_action_sensitivity),
(ev_window_print_dialog_response_cb), (ev_window_print_range):
Allow printing to PDF when suppoted by the backend.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ev-jobs.c | 33 | ||||
-rw-r--r-- | shell/ev-jobs.h | 2 | ||||
-rw-r--r-- | shell/ev-window.c | 39 |
3 files changed, 52 insertions, 22 deletions
diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 6749c66..3657f65 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -7,7 +7,7 @@ #include "ev-document-fonts.h" #include "ev-selection.h" #include "ev-async-renderer.h" -#include "ev-ps-exporter.h" +#include "ev-file-exporter.h" #include "ev-window.h" #include <glib/gstdio.h> @@ -528,6 +528,7 @@ ev_job_xfer_run (EvJobXfer *job) EvJob * ev_job_print_new (EvDocument *document, + const gchar *format, gdouble width, gdouble height, EvPrintRange *ranges, @@ -543,6 +544,8 @@ ev_job_print_new (EvDocument *document, EV_JOB (job)->document = g_object_ref (document); + job->format = format; + job->temp_file = NULL; job->error = NULL; @@ -636,7 +639,7 @@ ev_job_print_do_page (EvJobPrint *job, gint page) EvRenderContext *rc; rc = ev_render_context_new (0, page, 1.0); - ev_ps_exporter_do_page (EV_PS_EXPORTER (document), rc); + ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc); g_object_unref (rc); } @@ -648,6 +651,7 @@ ev_job_print_run (EvJobPrint *job) gint last_page; gint first_page; gint i; + gchar *filename; g_return_if_fail (EV_IS_JOB_PRINT (job)); @@ -658,8 +662,10 @@ ev_job_print_run (EvJobPrint *job) if (job->error) g_error_free (job->error); job->error = NULL; - - fd = g_file_open_tmp ("evince_print.ps.XXXXXX", &job->temp_file, &job->error); + + filename = g_strdup_printf ("evince_print.%s.XXXXXX", job->format); + fd = g_file_open_tmp (filename, &job->temp_file, &job->error); + g_free (filename); if (fd <= -1) { EV_JOB (job)->finished = TRUE; return; @@ -669,17 +675,21 @@ ev_job_print_run (EvJobPrint *job) last_page = ev_print_job_get_last_page (job); ev_document_doc_mutex_lock (); - ev_ps_exporter_begin (EV_PS_EXPORTER (document), - job->temp_file, - MIN (first_page, last_page), - MAX (first_page, last_page), - job->width, job->height, FALSE); + ev_file_exporter_begin (EV_FILE_EXPORTER (document), + g_ascii_strcasecmp (job->format, "pdf") == 0 ? + EV_FILE_FORMAT_PDF : EV_FILE_FORMAT_PS, + job->temp_file, + MIN (first_page, last_page), + MAX (first_page, last_page), + job->width, job->height, FALSE); + ev_document_doc_mutex_unlock (); for (i = 0; i < job->copies; i++) { gint page, step; 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; @@ -700,7 +710,9 @@ ev_job_print_run (EvJobPrint *job) n_pages = job->copies; for (j = 0; j < n_pages; j++) { + ev_document_doc_mutex_lock (); ev_job_print_do_page (job, page); + ev_document_doc_mutex_unlock (); } page += step; @@ -710,7 +722,8 @@ ev_job_print_run (EvJobPrint *job) break; } - ev_ps_exporter_end (EV_PS_EXPORTER (document)); + ev_document_doc_mutex_lock (); + ev_file_exporter_end (EV_FILE_EXPORTER (document)); ev_document_doc_mutex_unlock (); close (fd); diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h index b91d822..43f4496 100644 --- a/shell/ev-jobs.h +++ b/shell/ev-jobs.h @@ -188,6 +188,7 @@ struct _EvJobPrint EvJob parent; GError *error; + const gchar *format; gchar *temp_file; EvPrintRange *ranges; gint n_ranges; @@ -250,6 +251,7 @@ void ev_job_xfer_run (EvJobXfer *xfer); /* EvJobPrint */ GType ev_job_print_get_type (void) G_GNUC_CONST; EvJob *ev_job_print_new (EvDocument *document, + const gchar *format, gdouble width, gdouble height, EvPrintRange *ranges, diff --git a/shell/ev-window.c b/shell/ev-window.c index 03927ae..7ece884 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -40,7 +40,7 @@ #include "ev-password.h" #include "ev-password-view.h" #include "ev-properties-dialog.h" -#include "ev-ps-exporter.h" +#include "ev-file-exporter.h" #include "ev-document-thumbnails.h" #include "ev-document-links.h" #include "ev-document-fonts.h" @@ -328,7 +328,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window) ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY); } - if (has_document && !EV_IS_PS_EXPORTER(document)) + if (has_document && !EV_IS_FILE_EXPORTER(document)) ok_to_print = FALSE; @@ -1742,6 +1742,7 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog, gdouble width; gdouble height; GtkPrintPages print_pages; + const gchar *file_format; if (response != GTK_RESPONSE_OK) { gtk_widget_destroy (GTK_WIDGET (dialog)); @@ -1764,6 +1765,9 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog, window->priv->print_page_setup = g_object_ref ( gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dialog))); + file_format = gtk_print_settings_get (window->priv->print_settings, + GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); + if (!gtk_printer_accepts_ps (window->priv->printer)) { GtkWidget *msgdialog; @@ -1825,6 +1829,7 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog, reverse = gtk_print_settings_get_reverse (window->priv->print_settings); window->priv->print_job = ev_job_print_new (window->priv->document, + file_format ? file_format : "ps", width, height, ranges, n_ranges, page_set, @@ -1846,10 +1851,11 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog, void ev_window_print_range (EvWindow *ev_window, int first_page, int last_page) { - GtkWidget *dialog; - EvPageCache *page_cache; - gint current_page; - gint document_last_page; + GtkWidget *dialog; + EvPageCache *page_cache; + gint current_page; + gint document_last_page; + GtkPrintCapabilities capabilities; g_return_if_fail (EV_IS_WINDOW (ev_window)); g_return_if_fail (ev_window->priv->document != NULL); @@ -1881,13 +1887,22 @@ ev_window_print_range (EvWindow *ev_window, int first_page, int last_page) dialog = gtk_print_unix_dialog_new (_("Print"), GTK_WINDOW (ev_window)); ev_window->priv->print_dialog = dialog; + + capabilities = GTK_PRINT_CAPABILITY_PAGE_SET | + GTK_PRINT_CAPABILITY_COPIES | + GTK_PRINT_CAPABILITY_COLLATE | + GTK_PRINT_CAPABILITY_REVERSE | + GTK_PRINT_CAPABILITY_SCALE | + GTK_PRINT_CAPABILITY_GENERATE_PS; + + if (EV_IS_FILE_EXPORTER (ev_window->priv->document) && + ev_file_exporter_format_supported (EV_FILE_EXPORTER (ev_window->priv->document), + EV_FILE_FORMAT_PDF)) { + capabilities |= GTK_PRINT_CAPABILITY_GENERATE_PDF; + } + gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dialog), - GTK_PRINT_CAPABILITY_PAGE_SET | - GTK_PRINT_CAPABILITY_COPIES | - GTK_PRINT_CAPABILITY_COLLATE | - GTK_PRINT_CAPABILITY_REVERSE | - GTK_PRINT_CAPABILITY_SCALE | - GTK_PRINT_CAPABILITY_GENERATE_PS); + capabilities); gtk_print_unix_dialog_set_current_page (GTK_PRINT_UNIX_DIALOG (dialog), current_page); |