Blob Blame History Raw
--- shell/ev-print-operation.c.aspect-ratio	2009-10-29 15:01:28.000000000 +0100
+++ shell/ev-print-operation.c	2009-10-29 15:01:40.000000000 +0100
@@ -1638,13 +1638,36 @@ print_job_cancelled (EvJobPrint         
 }
 
 static void
+ev_print_operation_print_request_page_setup (EvPrintOperationPrint *print,
+					     GtkPrintContext       *context,
+					     gint                   page_nr,
+					     GtkPageSetup          *setup)
+{
+	EvPrintOperation *op = EV_PRINT_OPERATION (print);
+	gdouble           width, height;
+	EvPage           *page;
+
+	page = ev_document_get_page (op->document, page_nr);
+
+	ev_document_get_page_size (op->document, page,
+				   &width, &height);
+
+	if (width > height)
+	        gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
+	else
+	        gtk_page_setup_set_orientation (setup, GTK_PAGE_ORIENTATION_PORTRAIT);
+
+	g_object_unref (page);
+}
+
+static void
 ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
 				    GtkPrintContext       *context,
 				    gint                   page)
 {
 	EvPrintOperation *op = EV_PRINT_OPERATION (print);
 	cairo_t          *cr;
-	gdouble           cr_width, cr_height;
+	gdouble           cr_width, cr_height, scale;
 	gint              width, height;
 
 	gtk_print_operation_set_defer_drawing (print->op);
@@ -1667,7 +1690,11 @@ ev_print_operation_print_draw_page (EvPr
 	ev_page_cache_get_size (ev_page_cache_get (op->document),
 				page, 0, 1.0,
 				&width, &height);
-	cairo_scale (cr, cr_width / (gdouble)width, cr_height / (gdouble)height);
+	if (cr_width / (gdouble)width < cr_height / (gdouble)height)
+	        scale = cr_width / (gdouble)width;
+	else
+	        scale = cr_height / (gdouble)height;
+	cairo_scale (cr, scale, scale);
 
 	ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), cr);
 	ev_job_scheduler_push_job (print->job_print, EV_JOB_PRIORITY_NONE);
@@ -1720,6 +1747,9 @@ ev_print_operation_print_init (EvPrintOp
 	g_signal_connect_swapped (print->op, "status_changed",
 				  G_CALLBACK (ev_print_operation_print_status_changed),
 				  print);
+	g_signal_connect_swapped (print->op, "request_page_setup",
+				  G_CALLBACK (ev_print_operation_print_request_page_setup),
+				  print);
 	gtk_print_operation_set_allow_async (print->op, TRUE);
 }