From: Carlos Garcia Campos Date: Thu, 26 Jul 2007 14:53:17 +0000 (+0000) Subject: Use capabilities to know which options should be offered by the print X-Git-Tag: EVINCE_0_9_3~21 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=e70119b293ab8a26bdea4a56407bb0f41f1e43aa;p=evince.git Use capabilities to know which options should be offered by the print 2007-07-26 Carlos Garcia Campos * backend/dvi/dvi-document.c: (dvi_document_file_exporter_begin), (dvi_document_file_exporter_do_page), (dvi_document_file_exporter_get_capabilities), (dvi_document_file_exporter_iface_init): * backend/ps/ps-document.c: (ps_document_file_exporter_begin), (ps_document_file_exporter_do_page), (ps_document_file_exporter_get_capabilities), (ps_document_file_exporter_iface_init): * backend/djvu/djvu-document.c: (djvu_document_file_exporter_begin), (djvu_document_file_exporter_end), (djvu_document_file_exporter_get_capabilities), (djvu_document_file_exporter_iface_init): * backend/tiff/tiff-document.c: (tiff_document_file_exporter_begin), (tiff_document_file_exporter_get_capabilities), (tiff_document_document_file_exporter_iface_init): * backend/pdf/ev-poppler.cc: (pdf_document_file_exporter_begin), (pdf_document_file_exporter_do_page), (pdf_document_file_exporter_get_capabilities), (pdf_document_file_exporter_iface_init): * libdocument/ev-file-exporter.[ch]: (ev_file_exporter_begin), (ev_file_exporter_get_capabilities): * shell/ev-print-job.c: (ev_print_job_use_print_dialog_settings), (idle_print_handler), (ev_print_job_print): * shell/ev-jobs.c: (ev_job_print_run): * shell/ev-window.c: (ev_window_print_send), (ev_window_print_range): Use capabilities to know which options should be offered by the print dialog depending on the document backend. svn path=/trunk/; revision=2580 --- diff --git a/ChangeLog b/ChangeLog index 4c32b376..648b16ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2007-07-26 Carlos Garcia Campos + + * backend/dvi/dvi-document.c: (dvi_document_file_exporter_begin), + (dvi_document_file_exporter_do_page), + (dvi_document_file_exporter_get_capabilities), + (dvi_document_file_exporter_iface_init): + * backend/ps/ps-document.c: (ps_document_file_exporter_begin), + (ps_document_file_exporter_do_page), + (ps_document_file_exporter_get_capabilities), + (ps_document_file_exporter_iface_init): + * backend/djvu/djvu-document.c: + (djvu_document_file_exporter_begin), + (djvu_document_file_exporter_end), + (djvu_document_file_exporter_get_capabilities), + (djvu_document_file_exporter_iface_init): + * backend/tiff/tiff-document.c: + (tiff_document_file_exporter_begin), + (tiff_document_file_exporter_get_capabilities), + (tiff_document_document_file_exporter_iface_init): + * backend/pdf/ev-poppler.cc: (pdf_document_file_exporter_begin), + (pdf_document_file_exporter_do_page), + (pdf_document_file_exporter_get_capabilities), + (pdf_document_file_exporter_iface_init): + * libdocument/ev-file-exporter.[ch]: (ev_file_exporter_begin), + (ev_file_exporter_get_capabilities): + * shell/ev-print-job.c: (ev_print_job_use_print_dialog_settings), + (idle_print_handler), (ev_print_job_print): + * shell/ev-jobs.c: (ev_job_print_run): + * shell/ev-window.c: (ev_window_print_send), + (ev_window_print_range): + + Use capabilities to know which options should be offered by the + print dialog depending on the document backend. + 2007-07-25 Carlos Garcia Campos * shell/ev-view.c: (ev_view_handle_cursor_over_xy): diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index 88c6bc85..9b4ba825 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -441,30 +441,17 @@ djvu_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface) } /* EvFileExporterIface */ -static gboolean -djvu_document_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format) -{ - return (format == EV_FILE_FORMAT_PS); // only exporting to PS is implemented. -} - static void -djvu_document_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const char *filename, /* for storing the temp ps file */ - int first_page, - int last_page, - double width, - double height, - gboolean duplex) +djvu_document_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc) { DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter); if (djvu_document->ps_filename) g_free (djvu_document->ps_filename); - djvu_document->ps_filename = g_strdup(filename); + djvu_document->ps_filename = g_strdup (fc->filename); - g_string_assign(djvu_document->opts, "-page="); + g_string_assign (djvu_document->opts, "-page="); } static void @@ -473,7 +460,7 @@ djvu_document_file_exporter_do_page (EvFileExporter *exporter, { DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter); - g_string_append_printf(djvu_document->opts, "%d,", (rc->page) + 1); + g_string_append_printf (djvu_document->opts, "%d,", (rc->page) + 1); } static void @@ -484,29 +471,39 @@ djvu_document_file_exporter_end (EvFileExporter *exporter) DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter); - FILE *fn = fopen(djvu_document->ps_filename, "w"); + FILE *fn = fopen (djvu_document->ps_filename, "w"); if (fn == NULL) { - g_warning(_("Cannot open file “%s”."), djvu_document->ps_filename); + g_warning ("Cannot open file “%s”.", djvu_document->ps_filename); return; } d_optv[0] = djvu_document->opts->str; ddjvu_job_t * job = ddjvu_document_print(djvu_document->d_document, fn, d_optc, d_optv); - while (!ddjvu_job_done(job) ) { + while (!ddjvu_job_done(job)) { djvu_handle_events (djvu_document, TRUE); } fclose(fn); } +static EvFileExporterCapabilities +djvu_document_file_exporter_get_capabilities (EvFileExporter *exporter) +{ + return EV_FILE_EXPORTER_CAN_PAGE_SET | + EV_FILE_EXPORTER_CAN_COPIES | + EV_FILE_EXPORTER_CAN_COLLATE | + EV_FILE_EXPORTER_CAN_REVERSE | + EV_FILE_EXPORTER_CAN_GENERATE_PS; +} + static void djvu_document_file_exporter_iface_init (EvFileExporterIface *iface) { - iface->format_supported = djvu_document_file_exporter_format_supported; iface->begin = djvu_document_file_exporter_begin; iface->do_page = djvu_document_file_exporter_do_page; iface->end = djvu_document_file_exporter_end; + iface->get_capabilities = djvu_document_file_exporter_get_capabilities; } static void diff --git a/backend/dvi/dvi-document.c b/backend/dvi/dvi-document.c index c85e4f5a..b6f83258 100644 --- a/backend/dvi/dvi-document.c +++ b/backend/dvi/dvi-document.c @@ -362,28 +362,15 @@ dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface) } /* EvFileExporterIface */ -static gboolean -dvi_document_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format) -{ - return (format == EV_FILE_FORMAT_PDF); /* only exporting to PDF is implemented. */ -} - static void -dvi_document_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const char *filename, /* for storing the temp pdf file */ - int first_page, - int last_page, - double width, - double height, - gboolean duplex) +dvi_document_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc) { DviDocument *dvi_document = DVI_DOCUMENT(exporter); if (dvi_document->exporter_filename) g_free (dvi_document->exporter_filename); - dvi_document->exporter_filename = g_strdup(filename); + dvi_document->exporter_filename = g_strdup(fc->filename); if (dvi_document->exporter_opts) { g_string_free (dvi_document->exporter_opts, TRUE); @@ -392,7 +379,8 @@ dvi_document_file_exporter_begin (EvFileExporter *exporter, } static void -dvi_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) +dvi_document_file_exporter_do_page (EvFileExporter *exporter, + EvRenderContext *rc) { DviDocument *dvi_document = DVI_DOCUMENT(exporter); @@ -423,22 +411,32 @@ dvi_document_file_exporter_end (EvFileExporter *exporter) g_free(command_line); if (success == FALSE) { - g_warning (_("Error: %s"), err->message); + g_warning ("Error: %s", err->message); } else if (exit_stat != 0) { - g_warning (_("Error: dvipdfm exited with non-zero status.")); + g_warning ("Error: dvipdfm exited with non-zero status."); } if (err) g_error_free(err); } +static EvFileExporterCapabilities +dvi_document_file_exporter_get_capabilities (EvFileExporter *exporter) +{ + return EV_FILE_EXPORTER_CAN_PAGE_SET | + EV_FILE_EXPORTER_CAN_COPIES | + EV_FILE_EXPORTER_CAN_COLLATE | + EV_FILE_EXPORTER_CAN_REVERSE | + EV_FILE_EXPORTER_CAN_GENERATE_PDF; +} + static void dvi_document_file_exporter_iface_init (EvFileExporterIface *iface) { - iface->format_supported = dvi_document_file_exporter_format_supported; iface->begin = dvi_document_file_exporter_begin; iface->do_page = dvi_document_file_exporter_do_page; iface->end = dvi_document_file_exporter_end; + iface->get_capabilities = dvi_document_file_exporter_get_capabilities; } #define RGB2ULONG(r,g,b) ((0xFF<<24)|(r<<16)|(g<<8)|(b)) diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index f96fdd42..4b6b114e 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -1506,17 +1506,6 @@ pdf_document_find_iface_init (EvDocumentFindIface *iface) iface->cancel = pdf_document_find_cancel; } -static const gboolean supported_formats[] = { - TRUE, /* EV_FILE_FORMAT_PS */ -#ifdef HAVE_CAIRO_PDF -#ifdef HAVE_POPPLER_PAGE_RENDER - TRUE, /* EV_FILE_FORMAT_PDF */ -#else - FALSE, /* EV_FILE_FORMAT_PDF */ -#endif -#endif -}; - static void pdf_print_context_free (PdfPrintContext *ctx) { @@ -1536,22 +1525,9 @@ pdf_print_context_free (PdfPrintContext *ctx) g_free (ctx); } -static gboolean -pdf_document_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format) -{ - return supported_formats[format]; -} - static void -pdf_document_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const char *filename, - int first_page, - int last_page, - double width, - double height, - gboolean duplex) +pdf_document_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc) { PdfDocument *pdf_document = PDF_DOCUMENT (exporter); PdfPrintContext *ctx; @@ -1560,22 +1536,22 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, pdf_print_context_free (pdf_document->print_ctx); pdf_document->print_ctx = g_new0 (PdfPrintContext, 1); ctx = pdf_document->print_ctx; - ctx->format = format; + ctx->format = fc->format; - switch (format) { + switch (fc->format) { case EV_FILE_FORMAT_PS: ctx->ps_file = poppler_ps_file_new (pdf_document->document, - filename, first_page, - last_page - first_page + 1); - poppler_ps_file_set_paper_size (ctx->ps_file, width, height); - poppler_ps_file_set_duplex (ctx->ps_file, duplex); + fc->filename, fc->first_page, + fc->last_page - fc->first_page + 1); + poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height); + poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex); break; case EV_FILE_FORMAT_PDF: { #ifdef HAVE_CAIRO_PDF cairo_surface_t *surface; - surface = cairo_pdf_surface_create (filename, width, height); + surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height); ctx->pdf_cairo = cairo_create (surface); cairo_surface_destroy (surface); #endif @@ -1587,7 +1563,8 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, } static void -pdf_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) +pdf_document_file_exporter_do_page (EvFileExporter *exporter, + EvRenderContext *rc) { PdfDocument *pdf_document = PDF_DOCUMENT (exporter); PdfPrintContext *ctx = pdf_document->print_ctx; @@ -1629,13 +1606,30 @@ pdf_document_file_exporter_end (EvFileExporter *exporter) pdf_document->print_ctx = NULL; } +static EvFileExporterCapabilities +pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter) +{ + return (EvFileExporterCapabilities) ( + EV_FILE_EXPORTER_CAN_PAGE_SET | + EV_FILE_EXPORTER_CAN_COPIES | + EV_FILE_EXPORTER_CAN_COLLATE | + EV_FILE_EXPORTER_CAN_REVERSE | + EV_FILE_EXPORTER_CAN_SCALE | +#ifdef HAVE_CAIRO_PDF +#ifdef HAVE_POPPLER_PAGE_RENDER + EV_FILE_EXPORTER_CAN_GENERATE_PDF | +#endif +#endif + EV_FILE_EXPORTER_CAN_GENERATE_PS); +} + static void pdf_document_file_exporter_iface_init (EvFileExporterIface *iface) { - iface->format_supported = pdf_document_file_exporter_format_supported; iface->begin = pdf_document_file_exporter_begin; iface->do_page = pdf_document_file_exporter_do_page; iface->end = pdf_document_file_exporter_end; + iface->get_capabilities = pdf_document_file_exporter_get_capabilities; } static void diff --git a/backend/ps/ps-document.c b/backend/ps/ps-document.c index 0931fb91..5e636871 100644 --- a/backend/ps/ps-document.c +++ b/backend/ps/ps-document.c @@ -598,22 +598,9 @@ ps_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface) } /* EvFileExporterIface */ -static gboolean -ps_document_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format) -{ - return (format == EV_FILE_FORMAT_PS); -} - static void -ps_document_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const char *filename, - int first_page, - int last_page, - double width, - double height, - gboolean duplex) +ps_document_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc) { PSDocument *document = PS_DOCUMENT (exporter); @@ -623,11 +610,12 @@ ps_document_file_exporter_begin (EvFileExporter *exporter, document->ps_export_pagelist = g_new0 (int, document->doc->numpages); } - document->ps_export_filename = g_strdup (filename); + document->ps_export_filename = g_strdup (fc->filename); } static void -ps_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) +ps_document_file_exporter_do_page (EvFileExporter *exporter, + EvRenderContext *rc) { PSDocument *document = PS_DOCUMENT (exporter); @@ -653,11 +641,18 @@ ps_document_file_exporter_end (EvFileExporter *exporter) } } +static EvFileExporterCapabilities +ps_document_file_exporter_get_capabilities (EvFileExporter *exporter) +{ + return EV_FILE_EXPORTER_CAN_PAGE_SET | + EV_FILE_EXPORTER_CAN_GENERATE_PS; +} + static void ps_document_file_exporter_iface_init (EvFileExporterIface *iface) { - iface->format_supported = ps_document_file_exporter_format_supported; iface->begin = ps_document_file_exporter_begin; iface->do_page = ps_document_file_exporter_do_page; iface->end = ps_document_file_exporter_end; + iface->get_capabilities = ps_document_file_exporter_get_capabilities; } diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 8247c2a2..59748d72 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -450,27 +450,13 @@ tiff_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface) } /* postscript exporter implementation */ - -static gboolean -tiff_document_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format) -{ - return (format == EV_FILE_FORMAT_PS); -} - static void -tiff_document_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const char *filename, - int first_page, - int last_page, - double width, - double height, - gboolean duplex) +tiff_document_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc) { TiffDocument *document = TIFF_DOCUMENT (exporter); - document->ps_export_ctx = tiff2ps_context_new(filename); + document->ps_export_ctx = tiff2ps_context_new(fc->filename); } static void @@ -496,13 +482,23 @@ tiff_document_file_exporter_end (EvFileExporter *exporter) tiff2ps_context_finalize(document->ps_export_ctx); } +static EvFileExporterCapabilities +tiff_document_file_exporter_get_capabilities (EvFileExporter *exporter) +{ + return EV_FILE_EXPORTER_CAN_PAGE_SET | + EV_FILE_EXPORTER_CAN_COPIES | + EV_FILE_EXPORTER_CAN_COLLATE | + EV_FILE_EXPORTER_CAN_REVERSE | + EV_FILE_EXPORTER_CAN_GENERATE_PS; +} + static void tiff_document_document_file_exporter_iface_init (EvFileExporterIface *iface) { - iface->format_supported = tiff_document_file_exporter_format_supported; iface->begin = tiff_document_file_exporter_begin; iface->do_page = tiff_document_file_exporter_do_page; iface->end = tiff_document_file_exporter_end; + iface->get_capabilities = tiff_document_file_exporter_get_capabilities; } static void diff --git a/libdocument/ev-file-exporter.c b/libdocument/ev-file-exporter.c index 7a4e9021..d65abec1 100644 --- a/libdocument/ev-file-exporter.c +++ b/libdocument/ev-file-exporter.c @@ -43,39 +43,18 @@ ev_file_exporter_get_type (void) return type; } -gboolean -ev_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format) -{ - EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter); - - if (format < EV_FILE_FORMAT_PS || - format > EV_FILE_FORMAT_PDF) - return FALSE; - - return iface->format_supported (exporter, format); -} - void -ev_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const gchar *filename, - gint first_page, - gint last_page, - gdouble paper_width, - gdouble paper_height, - gboolean duplex) +ev_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc) { EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter); - g_return_if_fail (ev_file_exporter_format_supported (exporter, format)); - - iface->begin (exporter, format, filename, first_page, last_page, - paper_width, paper_height, duplex); + iface->begin (exporter, fc); } void -ev_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc) +ev_file_exporter_do_page (EvFileExporter *exporter, + EvRenderContext *rc) { EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter); @@ -89,3 +68,11 @@ ev_file_exporter_end (EvFileExporter *exporter) iface->end (exporter); } + +EvFileExporterCapabilities +ev_file_exporter_get_capabilities (EvFileExporter *exporter) +{ + EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter); + + iface->get_capabilities (exporter); +} diff --git a/libdocument/ev-file-exporter.h b/libdocument/ev-file-exporter.h index f0e517c8..7fadb1ae 100644 --- a/libdocument/ev-file-exporter.h +++ b/libdocument/ev-file-exporter.h @@ -30,11 +30,33 @@ G_BEGIN_DECLS typedef enum { - EV_FILE_FORMAT_PS, - EV_FILE_FORMAT_PDF, - EV_FILE_FORMAT_UNKNOWN + EV_FILE_FORMAT_UNKNOWN, + EV_FILE_FORMAT_PS, + EV_FILE_FORMAT_PDF } EvFileExporterFormat; +typedef enum { + EV_FILE_EXPORTER_CAN_PAGE_SET = 1 << 0, + EV_FILE_EXPORTER_CAN_COPIES = 1 << 1, + EV_FILE_EXPORTER_CAN_COLLATE = 1 << 2, + EV_FILE_EXPORTER_CAN_REVERSE = 1 << 3, + EV_FILE_EXPORTER_CAN_SCALE = 1 << 4, + EV_FILE_EXPORTER_CAN_GENERATE_PDF = 1 << 5, + EV_FILE_EXPORTER_CAN_GENERATE_PS = 1 << 6, + EV_FILE_EXPORTER_CAN_PREVIEW = 1 << 7, + EV_FILE_EXPORTER_CAN_NUMBER_UP = 1 << 8 +} EvFileExporterCapabilities; + +typedef struct { + EvFileExporterFormat format; + const gchar *filename; + gint first_page; + gint last_page; + gdouble paper_width; + gdouble paper_height; + gboolean duplex; +} EvFileExporterContext; + #define EV_TYPE_FILE_EXPORTER (ev_file_exporter_get_type ()) #define EV_FILE_EXPORTER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_FILE_EXPORTER, EvFileExporter)) #define EV_FILE_EXPORTER_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_FILE_EXPORTER, EvFileExporterIface)) @@ -42,42 +64,28 @@ typedef enum { #define EV_IS_FILE_EXPORTER_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_FILE_EXPORTER)) #define EV_FILE_EXPORTER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_FILE_EXPORTER, EvFileExporterIface)) -typedef struct _EvFileExporter EvFileExporter; +typedef struct _EvFileExporter EvFileExporter; typedef struct _EvFileExporterIface EvFileExporterIface; struct _EvFileExporterIface { GTypeInterface base_iface; /* Methods */ - gboolean (* format_supported) (EvFileExporter *exporter, - EvFileExporterFormat format); - void (* begin) (EvFileExporter *exporter, - EvFileExporterFormat format, - const gchar *filename, - gint first_page, - gint last_page, - gdouble paper_width, - gdouble paper_height, - gboolean duplex); - void (* do_page) (EvFileExporter *exporter, - EvRenderContext *rc); - void (* end) (EvFileExporter *exporter); + void (* begin) (EvFileExporter *exporter, + EvFileExporterContext *fc); + void (* do_page) (EvFileExporter *exporter, + EvRenderContext *rc); + void (* end) (EvFileExporter *exporter); + EvFileExporterCapabilities (* get_capabilities) (EvFileExporter *exporter); }; -GType ev_file_exporter_get_type (void) G_GNUC_CONST; -gboolean ev_file_exporter_format_supported (EvFileExporter *exporter, - EvFileExporterFormat format); -void ev_file_exporter_begin (EvFileExporter *exporter, - EvFileExporterFormat format, - const gchar *filename, - gint first_page, - gint last_page, - gdouble paper_width, - gdouble paper_height, - gboolean duplex); -void ev_file_exporter_do_page (EvFileExporter *exporter, - EvRenderContext *rc); -void ev_file_exporter_end (EvFileExporter *exporter); +GType ev_file_exporter_get_type (void) G_GNUC_CONST; +void ev_file_exporter_begin (EvFileExporter *exporter, + EvFileExporterContext *fc); +void ev_file_exporter_do_page (EvFileExporter *exporter, + EvRenderContext *rc); +void ev_file_exporter_end (EvFileExporter *exporter); +EvFileExporterCapabilities ev_file_exporter_get_capabilities (EvFileExporter *exporter); G_END_DECLS diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 0f0a0daf..d61185c0 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -643,12 +643,13 @@ ev_job_print_do_page (EvJobPrint *job, gint page) void ev_job_print_run (EvJobPrint *job) { - EvDocument *document = EV_JOB (job)->document; - gint fd; - gint last_page; - gint first_page; - gint i; - gchar *filename; + EvDocument *document = EV_JOB (job)->document; + EvFileExporterContext fc; + gint fd; + gint last_page; + gint first_page; + gint i; + gchar *filename; g_return_if_fail (EV_IS_JOB_PRINT (job)); @@ -671,14 +672,17 @@ ev_job_print_run (EvJobPrint *job) first_page = ev_print_job_get_first_page (job); last_page = ev_print_job_get_last_page (job); + fc.format = g_ascii_strcasecmp (job->format, "pdf") == 0 ? + EV_FILE_FORMAT_PDF : EV_FILE_FORMAT_PS; + fc.filename = job->temp_file; + fc.first_page = MIN (first_page, last_page); + fc.last_page = MAX (first_page, last_page); + fc.paper_width = job->width; + fc.paper_height = job->height; + fc.duplex = FALSE; + ev_document_doc_mutex_lock (); - 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_file_exporter_begin (EV_FILE_EXPORTER (document), &fc); ev_document_doc_mutex_unlock (); for (i = 0; i < job->copies; i++) { diff --git a/shell/ev-print-job.c b/shell/ev-print-job.c index 79076f90..d042ab68 100644 --- a/shell/ev-print-job.c +++ b/shell/ev-print-job.c @@ -45,16 +45,10 @@ struct _EvPrintJob { EvDocument *document; GnomePrintJob *gnome_print_job; - double width; /* FIXME unused */ - double height; /* FIXME unused */ - gboolean duplex; /* FIXME unused */ + EvFileExporterContext fc; int copies; int collate; - /* range printing */ - int first_page; - int last_page; - int fd; char *temp_file; guint idle_id; @@ -223,6 +217,7 @@ ev_print_job_use_print_dialog_settings (EvPrintJob *job, GnomePrintDialog *dialo { GnomePrintConfig *print_config; 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)); @@ -230,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_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); } @@ -260,21 +258,16 @@ idle_print_handler (EvPrintJob *job) { if (!job->printing) { ev_document_doc_mutex_lock (); - ev_file_exporter_begin ( - EV_FILE_EXPORTER (job->document), - EV_FILE_FORMAT_PS, - job->temp_file, - MIN (job->first_page, job->last_page), - MAX (job->first_page, job->last_page), - job->width, job->height, job->duplex); + ev_file_exporter_begin (EV_FILE_EXPORTER (job->document), + &(job->fc)); ev_document_doc_mutex_unlock (); - job->next_page = job->first_page; - job->shift = (job->first_page > job->last_page) ? -1 : 1; + 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) * job->shift <= 0) { + if ((job->next_page - job->fc.last_page) * job->shift <= 0) { EvRenderContext *rc; #if 0 g_printerr ("Printing page %d\n", job->next_page); @@ -296,11 +289,11 @@ idle_print_handler (EvPrintJob *job) } } else { job->next_page += job->shift; - if ((job->next_page - job->last_page) * job->shift > 0){ + 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->first_page; + job->next_page = job->fc.first_page; } } } @@ -350,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); diff --git a/shell/ev-window.c b/shell/ev-window.c index 9f6f0828..41b68364 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -2211,6 +2211,7 @@ ev_window_print_send (EvWindow *window, const gchar *filename) { GtkPrintSettings *settings; + EvFileExporterCapabilities capabilities; /* Some printers take into account some print settings, * and others don't. However we have exported the document @@ -2219,14 +2220,21 @@ ev_window_print_send (EvWindow *window, * settings set to default values. */ settings = gtk_print_settings_copy (window->priv->print_settings); - gtk_print_settings_set_n_copies (settings, 1); + capabilities = ev_file_exporter_get_capabilities (EV_FILE_EXPORTER (window->priv->document)); + gtk_print_settings_set_page_ranges (settings, NULL, 0); - gtk_print_settings_set_page_set (settings, GTK_PAGE_SET_ALL); gtk_print_settings_set_print_pages (settings, GTK_PRINT_PAGES_ALL); - gtk_print_settings_set_scale (settings, 1.0); - gtk_print_settings_set_collate (settings, FALSE); - gtk_print_settings_set_reverse (settings, FALSE); - + if (capabilities & EV_FILE_EXPORTER_CAN_COPIES) + gtk_print_settings_set_n_copies (settings, 1); + if (capabilities & EV_FILE_EXPORTER_CAN_PAGE_SET) + gtk_print_settings_set_page_set (settings, GTK_PAGE_SET_ALL); + if (capabilities & EV_FILE_EXPORTER_CAN_SCALE) + gtk_print_settings_set_scale (settings, 1.0); + if (capabilities & EV_FILE_EXPORTER_CAN_COLLATE) + gtk_print_settings_set_collate (settings, FALSE); + if (capabilities & EV_FILE_EXPORTER_CAN_REVERSE) + gtk_print_settings_set_reverse (settings, FALSE); + if (window->priv->print_preview) { gchar *uri; gchar *print_settings_file = NULL; @@ -2457,20 +2465,8 @@ 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 | - GTK_PRINT_CAPABILITY_PREVIEW; - - 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; - } - + capabilities = GTK_PRINT_CAPABILITY_PREVIEW | + ev_file_exporter_get_capabilities (EV_FILE_EXPORTER (ev_window->priv->document)); gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dialog), capabilities); @@ -3441,7 +3437,7 @@ ev_window_cmd_preview_print (GtkAction *action, EvWindow *window) gtk_enumerate_printers ((GtkPrinterFunc) lookup_printer_from_name, window, NULL, TRUE); - g_assert (GTK_IS_PRINTER (window->priv->printer)); + g_assert (GTK_IS_PRINTER (window->priv->printer)); page_setup = gtk_page_setup_new ();