Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--backend/pdf/ev-poppler.cc145
-rw-r--r--libdocument/ev-file-exporter.h22
-rw-r--r--shell/ev-jobs.c4
-rw-r--r--shell/ev-jobs.h3
-rw-r--r--shell/ev-window.c13
6 files changed, 106 insertions, 92 deletions
diff --git a/ChangeLog b/ChangeLog
index 874e43a..8f0dad0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-09-01 Carlos Garcia Campos <carlosgc@gnome.org>
+
+ * backend/pdf/ev-poppler.cc: (pdf_document_file_exporter_begin),
+ (pdf_document_file_exporter_do_page):
+ * libdocument/ev-file-exporter.h:
+ * shell/ev-jobs.[ch]: (ev_job_print_new), (ev_job_print_run):
+ * shell/ev-window.c: (ev_window_print_dialog_response_cb):
+
+ Actually fix printing regressions. Remove orientation from
+ EvPrintContext since it's redundant.
+
2007-08-31 Carlos Garcia Campos <carlosgc@gnome.org>
* backend/dvi/dvi-document.c: (dvi_document_document_iface_init):
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 09edfb4..65c2884 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -68,15 +68,13 @@ typedef struct {
typedef struct {
EvFileExporterFormat format;
- gboolean landscape;
-
/* Pages per sheet */
gint pages_per_sheet;
gint pages_printed;
gint pages_x;
gint pages_y;
- gdouble page_width;
- gdouble page_height;
+ gdouble paper_width;
+ gdouble paper_height;
#ifdef HAVE_CAIRO_PRINT
cairo_t *cr;
@@ -1550,7 +1548,6 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
PdfPrintContext *ctx;
gdouble width, height;
- gboolean landscape, change_orient = FALSE;
#ifdef HAVE_CAIRO_PRINT
cairo_surface_t *surface = NULL;
#endif
@@ -1562,8 +1559,8 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
ctx->format = fc->format;
ctx->pages_per_sheet = fc->pages_per_sheet;
- landscape = (fc->orientation == EV_FILE_EXPORTER_LANDSCAPE);
- change_orient = landscape;
+ ctx->paper_width = fc->paper_width;
+ ctx->paper_height = fc->paper_height;
switch (fc->pages_per_sheet) {
default:
@@ -1572,7 +1569,6 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
ctx->pages_y = 1;
break;
case 2:
- landscape = !landscape;
ctx->pages_x = 1;
ctx->pages_y = 2;
break;
@@ -1581,7 +1577,6 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
ctx->pages_y = 2;
break;
case 6:
- landscape = !landscape;
ctx->pages_x = 2;
ctx->pages_y = 3;
break;
@@ -1595,36 +1590,12 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
break;
}
- ctx->landscape = landscape;
-
- if (change_orient) {
- width = fc->paper_height;
- height = fc->paper_width;
- } else {
- width = fc->paper_width;
- height = fc->paper_height;
- }
-
- if (landscape) {
- gint tmp;
-
- tmp = ctx->pages_x;
- ctx->pages_x = ctx->pages_y;
- ctx->pages_y = tmp;
-
- ctx->page_width = height / ctx->pages_x;
- ctx->page_height = width / ctx->pages_y;
- } else {
- ctx->page_width = width / ctx->pages_x;
- ctx->page_height = height / ctx->pages_y;
- }
-
ctx->pages_printed = 0;
switch (fc->format) {
case EV_FILE_FORMAT_PS:
#ifdef HAVE_CAIRO_PS
- surface = cairo_ps_surface_create (fc->filename, width, height);
+ surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
#else
ctx->ps_file = poppler_ps_file_new (pdf_document->document,
fc->filename, fc->first_page,
@@ -1635,7 +1606,7 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
break;
case EV_FILE_FORMAT_PDF:
#ifdef HAVE_CAIRO_PDF
- surface = cairo_pdf_surface_create (fc->filename, width, height);
+ surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
#endif
break;
default:
@@ -1644,16 +1615,6 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter,
#ifdef HAVE_CAIRO_PRINT
ctx->cr = cairo_create (surface);
- if (landscape) {
- cairo_matrix_t matrix;
-
- cairo_translate (ctx->cr, width, 0);
- cairo_matrix_init (&matrix,
- 0, 1,
- -1, 0,
- 0, 0);
- cairo_transform (ctx->cr, &matrix);
- }
cairo_surface_destroy (surface);
#endif
}
@@ -1666,8 +1627,12 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter,
PdfPrintContext *ctx = pdf_document->print_ctx;
PopplerPage *poppler_page;
#ifdef HAVE_CAIRO_PRINT
- gdouble page_width, page_height;
- gint x, y;
+ gdouble page_width, page_height;
+ gint x, y;
+ gboolean rotate, landscape;
+ gdouble width, height;
+ gdouble pwidth, pheight;
+ gdouble xscale, yscale;
#endif
g_return_if_fail (pdf_document->print_ctx != NULL);
@@ -1678,21 +1643,83 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter,
x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
poppler_page_get_size (poppler_page, &page_width, &page_height);
-
- cairo_save (ctx->cr);
- cairo_translate (ctx->cr,
- x * ctx->page_width,
- y * ctx->page_height);
- if (ctx->landscape) {
- cairo_scale (ctx->cr,
- ctx->page_height / page_height,
- ctx->page_height / page_height);
+
+ if (page_width > page_height && page_width > ctx->paper_width) {
+ rotate = TRUE;
+ } else {
+ rotate = FALSE;
+ }
+
+ landscape = (ctx->paper_width > ctx->paper_height);
+
+ /* Use always portrait mode and rotate when necessary */
+ if (ctx->paper_width > ctx->paper_height) {
+ width = ctx->paper_height;
+ height = ctx->paper_width;
+ rotate = !rotate;
+
+ cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
+ width, height);
} else {
- cairo_scale (ctx->cr,
- ctx->page_width / page_width,
- ctx->page_height / page_height);
+ width = ctx->paper_width;
+ height = ctx->paper_height;
}
+ if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
+ rotate = !rotate;
+ }
+
+ if (rotate) {
+ gint tmp1;
+ gdouble tmp2;
+
+ tmp1 = x;
+ x = y;
+ y = tmp1;
+
+ tmp2 = page_width;
+ page_width = page_height;
+ page_height = tmp2;
+
+ }
+
+ pwidth = width / ctx->pages_x;
+ pheight = height / ctx->pages_y;
+
+ if ((page_width > pwidth || page_height > pheight) ||
+ (page_width < pwidth && page_height < pheight)) {
+ xscale = pwidth / page_width;
+ yscale = pheight / page_height;
+
+ if (yscale < xscale) {
+ xscale = yscale;
+ } else {
+ yscale = xscale;
+ }
+
+ } else {
+ xscale = yscale = 1;
+ }
+
+ /* TODO: center */
+
+ cairo_save (ctx->cr);
+ if (rotate) {
+ cairo_matrix_t matrix;
+
+ cairo_translate (ctx->cr, width, 0);
+ cairo_matrix_init (&matrix,
+ 0, 1,
+ -1, 0,
+ 0, 0);
+ cairo_transform (ctx->cr, &matrix);
+ }
+
+ cairo_translate (ctx->cr,
+ x * (rotate ? pheight : pwidth),
+ y * (rotate ? pwidth : pheight));
+ cairo_scale (ctx->cr, xscale, yscale);
+
#ifdef HAVE_POPPLER_PAGE_RENDER
poppler_page_render (poppler_page, ctx->cr);
#endif
diff --git a/libdocument/ev-file-exporter.h b/libdocument/ev-file-exporter.h
index ab1daee..c05ea27 100644
--- a/libdocument/ev-file-exporter.h
+++ b/libdocument/ev-file-exporter.h
@@ -47,21 +47,15 @@ typedef enum {
EV_FILE_EXPORTER_CAN_NUMBER_UP = 1 << 8
} EvFileExporterCapabilities;
-typedef enum {
- EV_FILE_EXPORTER_PORTRAIT,
- EV_FILE_EXPORTER_LANDSCAPE
-} EvFileExporterOrientation;
-
typedef struct {
- EvFileExporterFormat format;
- const gchar *filename;
- gint first_page;
- gint last_page;
- gdouble paper_width;
- gdouble paper_height;
- EvFileExporterOrientation orientation;
- gboolean duplex;
- gint pages_per_sheet;
+ EvFileExporterFormat format;
+ const gchar *filename;
+ gint first_page;
+ gint last_page;
+ gdouble paper_width;
+ gdouble paper_height;
+ gboolean duplex;
+ gint pages_per_sheet;
} EvFileExporterContext;
#define EV_TYPE_FILE_EXPORTER (ev_file_exporter_get_type ())
diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c
index 99bfc87..acd4cb3 100644
--- a/shell/ev-jobs.c
+++ b/shell/ev-jobs.c
@@ -4,6 +4,7 @@
#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"
@@ -565,7 +566,6 @@ ev_job_print_new (EvDocument *document,
const gchar *format,
gdouble width,
gdouble height,
- EvFileExporterOrientation orientation,
EvPrintRange *ranges,
gint n_ranges,
EvPrintPageSet page_set,
@@ -587,7 +587,6 @@ ev_job_print_new (EvDocument *document,
job->width = width;
job->height = height;
- job->orientation = orientation;
job->ranges = ranges;
job->n_ranges = n_ranges;
@@ -721,7 +720,6 @@ ev_job_print_run (EvJobPrint *job)
fc.last_page = MAX (first_page, last_page);
fc.paper_width = job->width;
fc.paper_height = job->height;
- fc.orientation = job->orientation;
fc.duplex = FALSE;
fc.pages_per_sheet = MAX (1, job->pages_per_sheet);
diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h
index 6d7e95b..084ed6c 100644
--- a/shell/ev-jobs.h
+++ b/shell/ev-jobs.h
@@ -23,7 +23,6 @@
#include <gtk/gtk.h>
#include "ev-document.h"
#include "ev-window.h"
-#include "ev-file-exporter.h"
#include "ev-selection.h"
G_BEGIN_DECLS
@@ -207,7 +206,6 @@ struct _EvJobPrint
gboolean reverse;
gdouble width;
gdouble height;
- EvFileExporterOrientation orientation;
};
struct _EvJobPrintClass
@@ -267,7 +265,6 @@ EvJob *ev_job_print_new (EvDocument *document,
const gchar *format,
gdouble width,
gdouble height,
- EvFileExporterOrientation orientation,
EvPrintRange *ranges,
gint n_ranges,
EvPrintPageSet page_set,
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 81b303f..af2fb2a 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -2332,7 +2332,6 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
gdouble width;
gdouble height;
GtkPrintPages print_pages;
- EvFileExporterOrientation orientation = EV_FILE_EXPORTER_PORTRAIT;
const gchar *file_format;
if (response == GTK_RESPONSE_CANCEL) {
@@ -2412,17 +2411,6 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
height = gtk_page_setup_get_paper_height (window->priv->print_page_setup,
GTK_UNIT_PIXEL);
- switch (gtk_page_setup_get_orientation (window->priv->print_page_setup)) {
- case GTK_PAGE_ORIENTATION_PORTRAIT:
- case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
- orientation = EV_FILE_EXPORTER_PORTRAIT;
- break;
- case GTK_PAGE_ORIENTATION_LANDSCAPE:
- case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
- orientation = EV_FILE_EXPORTER_LANDSCAPE;
- break;
- }
-
if (scale != 1.0) {
width *= scale;
height *= scale;
@@ -2437,7 +2425,6 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog,
window->priv->print_job = ev_job_print_new (window->priv->document,
file_format ? file_format : "ps",
width, height,
- orientation,
ranges, n_ranges,
page_set,
pages_per_sheet,