+2007-10-11 Carlos Garcia Campos <carlosgc@gnome.org>
+
+ * backend/pdf/ev-poppler.cc:
+ (pdf_document_file_exporter_begin_page),
+ (pdf_document_file_exporter_do_page),
+ (pdf_document_file_exporter_end_page),
+ (pdf_document_file_exporter_iface_init):
+ * libdocument/ev-file-exporter.[ch]:
+ (ev_file_exporter_begin_page), (ev_file_exporter_end_page):
+ * shell/ev-jobs.c: (ev_job_print_get_page_list),
+ (ev_job_print_run):
+
+ When printing multiple pages per sheet in reverse option, do not
+ invert the order of the pages in every sheet, but the order of the
+ sheets. Do not print blank pages when page range is invalid. Fixes
+ bugs #484857 and #485521.
+
2007-10-10 Carlos Garcia Campos <carlosgc@gnome.org>
* shell/ev-jobs.c: (ev_job_print_get_page_list),
#endif
}
+static void
+pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
+ PdfPrintContext *ctx = pdf_document->print_ctx;
+
+ g_return_if_fail (pdf_document->print_ctx != NULL);
+
+ ctx->pages_printed = 0;
+
+ if (ctx->paper_width > ctx->paper_height) {
+ if (ctx->format == EV_FILE_FORMAT_PS) {
+ cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
+ ctx->paper_height,
+ ctx->paper_width);
+ } else if (ctx->format == EV_FILE_FORMAT_PDF) {
+ cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
+ ctx->paper_height,
+ ctx->paper_width);
+ }
+ }
+}
+
static void
pdf_document_file_exporter_do_page (EvFileExporter *exporter,
EvRenderContext *rc)
width = ctx->paper_height;
height = ctx->paper_width;
rotate = !rotate;
-
- cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
- width, height);
} else {
width = ctx->paper_width;
height = ctx->paper_height;
tmp2 = page_width;
page_width = page_height;
page_height = tmp2;
-
}
pwidth = width / ctx->pages_x;
ctx->pages_printed++;
- if (ctx->pages_printed % ctx->pages_per_sheet == 0) {
- cairo_show_page (ctx->cr);
- }
cairo_restore (ctx->cr);
#else /* HAVE_CAIRO_PRINT */
if (ctx->format == EV_FILE_FORMAT_PS)
g_object_unref (poppler_page);
}
+static void
+pdf_document_file_exporter_end_page (EvFileExporter *exporter)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
+ PdfPrintContext *ctx = pdf_document->print_ctx;
+
+ g_return_if_fail (pdf_document->print_ctx != NULL);
+
+ cairo_show_page (ctx->cr);
+}
+
static void
pdf_document_file_exporter_end (EvFileExporter *exporter)
{
pdf_document_file_exporter_iface_init (EvFileExporterIface *iface)
{
iface->begin = pdf_document_file_exporter_begin;
+ iface->begin_page = pdf_document_file_exporter_begin_page;
iface->do_page = pdf_document_file_exporter_do_page;
+ iface->end_page = pdf_document_file_exporter_end_page;
iface->end = pdf_document_file_exporter_end;
iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
}
iface->begin (exporter, fc);
}
+void
+ev_file_exporter_begin_page (EvFileExporter *exporter)
+{
+ EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter);
+
+ if (iface->begin_page)
+ iface->begin_page (exporter);
+}
+
void
ev_file_exporter_do_page (EvFileExporter *exporter,
EvRenderContext *rc)
iface->do_page (exporter, rc);
}
+void
+ev_file_exporter_end_page (EvFileExporter *exporter)
+{
+ EvFileExporterIface *iface = EV_FILE_EXPORTER_GET_IFACE (exporter);
+
+ if (iface->end_page)
+ iface->end_page (exporter);
+}
+
void
ev_file_exporter_end (EvFileExporter *exporter)
{
/* Methods */
void (* begin) (EvFileExporter *exporter,
EvFileExporterContext *fc);
+ void (* begin_page) (EvFileExporter *exporter);
void (* do_page) (EvFileExporter *exporter,
EvRenderContext *rc);
+ void (* end_page) (EvFileExporter *exporter);
void (* end) (EvFileExporter *exporter);
EvFileExporterCapabilities (* get_capabilities) (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_begin_page (EvFileExporter *exporter);
void ev_file_exporter_do_page (EvFileExporter *exporter,
EvRenderContext *rc);
+void ev_file_exporter_end_page (EvFileExporter *exporter);
void ev_file_exporter_end (EvFileExporter *exporter);
EvFileExporterCapabilities ev_file_exporter_get_capabilities (EvFileExporter *exporter);
return MIN (max_page, last_page);
}
-static gboolean
-ev_print_job_print_page_in_range (EvJobPrint *job,
- gint page)
-{
- gint i;
-
- for (i = 0; i < job->n_ranges; i++) {
- if (page >= job->ranges[i].start &&
- page <= job->ranges[i].end)
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean
ev_print_job_print_page_in_set (EvJobPrint *job,
gint page)
gint rsize;
gint start, end;
+ if (job->ranges[i].start > max_page)
+ continue;
+
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;
return page_list;
}
-static void
-ev_job_print_do_page (EvJobPrint *job, gint page)
-{
- EvDocument *document = EV_JOB (job)->document;
- EvRenderContext *rc;
-
- rc = ev_render_context_new (0, page, 1.0);
- ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc);
- g_object_unref (rc);
-}
-
void
ev_job_print_run (EvJobPrint *job)
{
EvDocument *document = EV_JOB (job)->document;
EvFileExporterContext fc;
+ EvRenderContext *rc;
gint fd;
gint *page_list;
gint n_pages;
gint last_page;
gint first_page;
- gint i;
+ gint i, j;
gchar *filename;
g_return_if_fail (EV_IS_JOB_PRINT (job));
fc.duplex = FALSE;
fc.pages_per_sheet = MAX (1, job->pages_per_sheet);
+ rc = ev_render_context_new (0, 0, 1.0);
+
ev_document_doc_mutex_lock ();
ev_file_exporter_begin (EV_FILE_EXPORTER (document), &fc);
gint page, step;
gint n_copies;
- step = job->reverse ? -1 : 1;
- page = job->reverse ? n_pages - 1 : 0;
+ step = job->reverse ? -1 * job->pages_per_sheet : job->pages_per_sheet;
+ page = job->reverse ? (n_pages / job->pages_per_sheet) * job->pages_per_sheet : 0;
n_copies = job->collate ? job->copies : 1;
while ((job->reverse && (page >= 0)) || (!job->reverse && (page < n_pages))) {
- gint j;
+ gint k;
+
+ ev_file_exporter_begin_page (EV_FILE_EXPORTER (document));
+
+ for (j = 0; j < job->pages_per_sheet; j++) {
+ gint p = page + j;
+
+ if (p < 0 || p >= n_pages)
+ break;
+
+ ev_render_context_set_page (rc, page_list[p]);
- for (j = 0; j < n_copies; j++) {
- ev_job_print_do_page (job, page_list[page]);
+ for (k = 0; k < n_copies; k++) {
+ ev_file_exporter_do_page (EV_FILE_EXPORTER (document), rc);
+ }
}
+ ev_file_exporter_end_page (EV_FILE_EXPORTER (document));
+
page += step;
}
g_free (page_list);
close (fd);
+ g_object_unref (rc);
EV_JOB (job)->finished = TRUE;
}