Description: Improve printing.
 Detect the orientation of the pages and set it accordingly. Also indicate that
 we're printing full pages without margin.
Origin:
 http://git.pwmt.org/?p=zathura.git;a=commit;h=508f8dad,
 http://git.pwmt.org/?p=zathura.git;a=commit;h=7a123151,
 http://git.pwmt.org/?p=zathura.git;a=commit;h=4e98fb3d
Last-Update: 2012-06-12

Index: zathura/print.c
===================================================================
--- zathura.orig/print.c	2012-06-11 23:36:10.000000000 +0200
+++ zathura/print.c	2012-06-11 23:37:48.337030484 +0200
@@ -7,6 +7,10 @@
 #include <girara/utils.h>
 #include <girara/statusbar.h>
 
+static void cb_print_request_page_setup(GtkPrintOperation* print_operation,
+    GtkPrintContext* context, gint page_number, GtkPageSetup* setup,
+    zathura_t* zathura);
+
 void
 print(zathura_t* zathura)
 {
@@ -27,10 +31,12 @@
   gtk_print_operation_set_allow_async(print_operation, TRUE);
   gtk_print_operation_set_n_pages(print_operation, zathura->document->number_of_pages);
   gtk_print_operation_set_current_page(print_operation, zathura->document->current_page_number);
+  gtk_print_operation_set_use_full_page(print_operation, TRUE);
 
   /* print operation signals */
   g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura);
   g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end),       zathura);
+  g_signal_connect(print_operation, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura);
 
   /* print */
   GtkPrintOperationResult result = gtk_print_operation_run(print_operation,
@@ -93,3 +99,23 @@
   zathura_page_render(page, cairo, true);
   render_unlock(zathura->sync.render_thread);
 }
+
+static void
+cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation),
+    GtkPrintContext* UNUSED(context), gint page_number, GtkPageSetup* setup,
+    zathura_t* zathura)
+{
+  if (zathura == NULL || zathura->document == NULL) {
+    return;
+  }
+
+  zathura_page_t* page = zathura->document->pages[page_number];
+  double width  = page->width;
+  double height = page->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);
+  }
+}
