]> www.fi.muni.cz Git - evince.git/commitdiff
Actually fix printing regressions. Remove orientation from EvPrintContext
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sat, 1 Sep 2007 17:35:44 +0000 (17:35 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sat, 1 Sep 2007 17:35:44 +0000 (17:35 +0000)
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.

svn path=/trunk/; revision=2649

ChangeLog
backend/pdf/ev-poppler.cc
libdocument/ev-file-exporter.h
shell/ev-jobs.c
shell/ev-jobs.h
shell/ev-window.c

index 874e43a2e2f2c4a68d049dc9a4f134046c5faed4..8f0dad0e4f2602d1e2baa963a7e1aa243b284ef0 100644 (file)
--- 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):
index 09edfb4165ea8067817d2fdce9ef4d87df0d3e9f..65c2884fa5d0c2c85d0b5fa347a4d402b7bf6db6 100644 (file)
@@ -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
index ab1daee416cfc822243640dd5486ed49d8306ef8..c05ea27d966e3edbdb38378899b750f28c23ce2b 100644 (file)
@@ -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 ())
index 99bfc87a2fb5e77d6eb84e8370ee57a900916543..acd4cb3a59e8081b4202ce0aa0280bb64bc9c0e8 100644 (file)
@@ -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);
 
index 6d7e95bf4a5d68e7abd7482ee8baa3bf096844b6..084ed6c0e109ada7740156c61944d9e4fae24f11 100644 (file)
@@ -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,
index 81b303f39d634d9c1435bd4cb7227c2417db50fa..af2fb2a35d2264a877c7e2c04ef10d0c6b79beb1 100644 (file)
@@ -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,