From: Carlos Garcia Campos Date: Mon, 27 Aug 2007 18:11:30 +0000 (+0000) Subject: Create always a portrait cairo surface and rotate when needed for X-Git-Tag: EVINCE_2_19_4~3 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=bc50ee241e2267cc7cc34b3598b047f335995662;p=evince.git Create always a portrait cairo surface and rotate when needed for 2007-08-27 Carlos Garcia Campos * backend/pdf/ev-poppler.cc: (pdf_print_context_free), (pdf_document_file_exporter_begin), (pdf_document_file_exporter_do_page): * shell/ev-jobs.c: (ev_job_print_run): * shell/ev-window.c: (ev_window_print_dialog_response_cb): Create always a portrait cairo surface and rotate when needed for landscape. It fixes printing problems in real printers. svn path=/trunk/; revision=2643 --- diff --git a/ChangeLog b/ChangeLog index d95b6e17..da4744d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-08-27 Carlos Garcia Campos + + * backend/pdf/ev-poppler.cc: (pdf_print_context_free), + (pdf_document_file_exporter_begin), + (pdf_document_file_exporter_do_page): + * shell/ev-jobs.c: (ev_job_print_run): + * shell/ev-window.c: (ev_window_print_dialog_response_cb): + + Create always a portrait cairo surface and rotate when needed for + landscape. It fixes printing problems in real printers. + 2007-08-25 Carlos Garcia Campos * backend/pdf/ev-poppler.cc: (pdf_document_file_exporter_begin): diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index cc6137b1..815862cb 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -67,8 +67,9 @@ typedef struct { typedef struct { EvFileExporterFormat format; - PopplerPSFile *ps_file; + gboolean landscape; + /* Pages per sheet */ gint pages_per_sheet; gint pages_printed; @@ -79,6 +80,8 @@ typedef struct { #ifdef HAVE_CAIRO_PRINT cairo_t *cr; +#else + PopplerPSFile *ps_file; #endif } PdfPrintContext; @@ -1559,15 +1562,16 @@ pdf_print_context_free (PdfPrintContext *ctx) if (!ctx) return; - if (ctx->ps_file) { - poppler_ps_file_free (ctx->ps_file); - ctx->ps_file = NULL; - } #ifdef HAVE_CAIRO_PRINT if (ctx->cr) { cairo_destroy (ctx->cr); ctx->cr = NULL; } +#else + if (ctx->ps_file) { + poppler_ps_file_free (ctx->ps_file); + ctx->ps_file = NULL; + } #endif g_free (ctx); } @@ -1592,6 +1596,7 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, ctx->pages_per_sheet = fc->pages_per_sheet; landscape = (fc->orientation == EV_FILE_EXPORTER_LANDSCAPE); + change_orient = landscape; switch (fc->pages_per_sheet) { default: @@ -1600,7 +1605,6 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, ctx->pages_y = 1; break; case 2: - change_orient = TRUE; landscape = !landscape; ctx->pages_x = 1; ctx->pages_y = 2; @@ -1610,7 +1614,6 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, ctx->pages_y = 2; break; case 6: - change_orient = TRUE; landscape = !landscape; ctx->pages_x = 2; ctx->pages_y = 3; @@ -1625,6 +1628,8 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, break; } + ctx->landscape = landscape; + if (change_orient) { width = fc->paper_height; height = fc->paper_width; @@ -1632,17 +1637,20 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, 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->page_width = width / ctx->pages_x; - ctx->page_height = height / ctx->pages_y; ctx->pages_printed = 0; @@ -1669,6 +1677,16 @@ 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 } @@ -1698,9 +1716,15 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, cairo_translate (ctx->cr, x * ctx->page_width, y * ctx->page_height); - cairo_scale (ctx->cr, - ctx->page_width / page_width, - ctx->page_height / page_height); + if (ctx->landscape) { + cairo_scale (ctx->cr, + ctx->page_height / page_height, + ctx->page_height / page_height); + } else { + cairo_scale (ctx->cr, + ctx->page_width / page_width, + ctx->page_height / page_height); + } #ifdef HAVE_POPPLER_PAGE_RENDER poppler_page_render (poppler_page, ctx->cr); diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index c78b28cb..6934f60f 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -720,7 +720,7 @@ ev_job_print_run (EvJobPrint *job) fc.paper_height = job->height; fc.orientation = job->orientation; fc.duplex = FALSE; - fc.pages_per_sheet = job->pages_per_sheet; + fc.pages_per_sheet = MAX (1, job->pages_per_sheet); ev_document_doc_mutex_lock (); ev_file_exporter_begin (EV_FILE_EXPORTER (document), &fc); diff --git a/shell/ev-window.c b/shell/ev-window.c index 97007467..32d52fda 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -2332,7 +2332,7 @@ ev_window_print_dialog_response_cb (GtkDialog *dialog, gdouble width; gdouble height; GtkPrintPages print_pages; - EvFileExporterOrientation orientation; + EvFileExporterOrientation orientation = EV_FILE_EXPORTER_PORTRAIT; const gchar *file_format; if (response == GTK_RESPONSE_CANCEL) {