Don't rotate pdf landscape output

This commit is contained in:
Adrian Johnson 2012-09-12 11:34:09 +02:00 committed by Marek Kasik
parent 2971446d58
commit dd7e8e9414
5 changed files with 58 additions and 12 deletions

View File

@ -285,6 +285,36 @@ _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
}
}
void
_gtk_print_context_reverse_according_to_orientation (GtkPrintContext *context)
{
cairo_t *cr = context->cr;
cairo_matrix_t matrix;
gdouble width, height;
width = gtk_page_setup_get_paper_width (context->page_setup, GTK_UNIT_INCH);
width = width * context->surface_dpi_x / context->pixels_per_unit_x;
height = gtk_page_setup_get_paper_height (context->page_setup, GTK_UNIT_INCH);
height = height * context->surface_dpi_y / context->pixels_per_unit_y;
switch (gtk_page_setup_get_orientation (context->page_setup))
{
default:
case GTK_PAGE_ORIENTATION_PORTRAIT:
case GTK_PAGE_ORIENTATION_LANDSCAPE:
break;
case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
cairo_translate (cr, width, height);
cairo_matrix_init (&matrix,
-1, 0,
0, -1,
0, 0);
cairo_transform (cr, &matrix);
break;
}
}
void
_gtk_print_context_translate_into_margin (GtkPrintContext *context)
{

View File

@ -138,6 +138,7 @@ void _gtk_print_context_set_page_setup (GtkPrintCon
GtkPageSetup *page_setup);
void _gtk_print_context_translate_into_margin (GtkPrintContext *context);
void _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context);
void _gtk_print_context_reverse_according_to_orientation (GtkPrintContext *context);
void _gtk_print_context_set_hard_margins (GtkPrintContext *context,
gdouble top,
gdouble bottom,

View File

@ -106,6 +106,11 @@ unix_start_page (GtkPrintOperation *op,
}
else if (type == CAIRO_SURFACE_TYPE_PDF)
{
if (!op->priv->manual_orientation)
{
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
}
cairo_pdf_surface_set_size (op_unix->surface, w, h);
}
}
@ -829,12 +834,10 @@ _gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation
GtkPageSetup *page_setup,
cairo_surface_t *surface)
{
GtkPaperSize *paper_size;
gdouble w, h;
paper_size = gtk_page_setup_get_paper_size (page_setup);
w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
cairo_pdf_surface_set_size (surface, w, h);
}

View File

@ -2050,14 +2050,11 @@ pdf_start_page (GtkPrintOperation *op,
GtkPrintContext *print_context,
GtkPageSetup *page_setup)
{
GtkPaperSize *paper_size;
cairo_surface_t *surface = op->priv->platform_data;
gdouble w, h;
paper_size = gtk_page_setup_get_paper_size (page_setup);
w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
cairo_pdf_surface_set_size (surface, w, h);
}
@ -2146,7 +2143,7 @@ run_pdf (GtkPrintOperation *op,
priv->manual_reverse = FALSE;
priv->manual_page_set = GTK_PAGE_SET_ALL;
priv->manual_scale = 1.0;
priv->manual_orientation = TRUE;
priv->manual_orientation = FALSE;
priv->manual_number_up = 1;
priv->manual_number_up_layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
@ -2498,6 +2495,8 @@ common_render_page (GtkPrintOperation *op,
if (priv->manual_orientation)
_gtk_print_context_rotate_according_to_orientation (print_context);
else
_gtk_print_context_reverse_according_to_orientation (print_context);
if (priv->manual_number_up > 1)
{
@ -3048,7 +3047,7 @@ print_pages (GtkPrintOperation *op,
priv->manual_reverse = gtk_print_settings_get_reverse (priv->print_settings);
priv->manual_page_set = gtk_print_settings_get_page_set (priv->print_settings);
priv->manual_scale = gtk_print_settings_get_scale (priv->print_settings) / 100.0;
priv->manual_orientation = TRUE;
priv->manual_orientation = FALSE;
priv->manual_number_up = gtk_print_settings_get_number_up (priv->print_settings);
priv->manual_number_up_layout = gtk_print_settings_get_number_up_layout (priv->print_settings);
}

View File

@ -783,6 +783,7 @@ file_printer_prepare_for_print (GtkPrinter *printer,
GtkPrintPages pages;
GtkPageRange *ranges;
gint n_ranges;
OutputFormat format;
pages = gtk_print_settings_get_print_pages (settings);
gtk_print_job_set_pages (print_job, pages);
@ -807,7 +808,19 @@ file_printer_prepare_for_print (GtkPrinter *printer,
gtk_print_job_set_scale (print_job, scale / 100.0);
gtk_print_job_set_page_set (print_job, gtk_print_settings_get_page_set (settings));
gtk_print_job_set_rotate (print_job, TRUE);
format = format_from_settings (settings);
switch (format)
{
case FORMAT_PDF:
gtk_print_job_set_rotate (print_job, FALSE);
break;
default:
case FORMAT_PS:
case FORMAT_SVG:
gtk_print_job_set_rotate (print_job, TRUE);
break;
}
}
static GList *