2ab05c1
diff -up cups-1.4.1/filter/pstops.c.page-label cups-1.4.1/filter/pstops.c
2ab05c1
--- cups-1.4.1/filter/pstops.c.page-label	2009-10-02 12:33:33.410719651 +0100
2ab05c1
+++ cups-1.4.1/filter/pstops.c	2009-10-02 12:34:11.399594180 +0100
2ab05c1
@@ -108,6 +108,7 @@ typedef struct				/**** Document informa
2ab05c1
   int		num_options;		/* Number of document-wide options */
2ab05c1
   cups_option_t	*options;		/* Document-wide options */
2ab05c1
   int		normal_landscape,	/* Normal rotation for landscape? */
2ab05c1
+		orientation,		/* Original orientation of the document */
2ab05c1
 		saw_eof,		/* Saw the %%EOF comment? */
2ab05c1
 		slow_collate,		/* Collate copies by hand? */
2ab05c1
 		slow_duplex,		/* Duplex pages slowly? */
2ab05c1
@@ -2048,7 +2049,7 @@ do_setup(pstops_doc_t *doc,		/* I - Docu
2ab05c1
     * of the pages...
2ab05c1
     */
2ab05c1
 
2ab05c1
-    if (Orientation & 1)
2ab05c1
+    if (doc->orientation & 1)
2ab05c1
       write_label_prolog(doc, doc->page_label, PageBottom,
2ab05c1
                          PageWidth - PageLength + PageTop, PageLength);
2ab05c1
     else
2ab05c1
@@ -2056,7 +2057,30 @@ do_setup(pstops_doc_t *doc,		/* I - Docu
2ab05c1
                          PageLength);
2ab05c1
   }
2ab05c1
   else
2ab05c1
-    write_label_prolog(doc, doc->page_label, PageBottom, PageTop, PageWidth);
2ab05c1
+  {
2ab05c1
+    switch (doc->orientation)
2ab05c1
+    {
2ab05c1
+      case 0 :
2ab05c1
+	  write_label_prolog(doc, doc->page_label, PageBottom, PageTop, 
2ab05c1
+                             PageWidth);
2ab05c1
+          break;
2ab05c1
+
2ab05c1
+      case 1 :
2ab05c1
+	  write_label_prolog(doc, doc->page_label, PageLeft, PageRight, 
2ab05c1
+                             PageLength);
2ab05c1
+          break;
2ab05c1
+
2ab05c1
+      case 2 :
2ab05c1
+	  write_label_prolog(doc, doc->page_label, PageLength - PageTop, 
2ab05c1
+                             PageLength - PageBottom, PageWidth);
2ab05c1
+          break;
2ab05c1
+
2ab05c1
+      case 3 :
2ab05c1
+	  write_label_prolog(doc, doc->page_label, PageWidth - PageRight, 
2ab05c1
+                             PageWidth - PageLeft, PageLength);
2ab05c1
+          break;
2ab05c1
+    }
2ab05c1
+  }
2ab05c1
 }
2ab05c1
 
2ab05c1
 
2ab05c1
@@ -2141,7 +2165,7 @@ end_nup(pstops_doc_t *doc,		/* I - Docum
2ab05c1
     case 1 :
2ab05c1
 	if (doc->use_ESPshowpage)
2ab05c1
 	{
2ab05c1
-	  write_labels(doc, Orientation);
2ab05c1
+	  write_labels(doc, doc->orientation);
2ab05c1
           doc_puts(doc, "ESPshowpage\n");
2ab05c1
 	}
2ab05c1
 	break;
2ab05c1
@@ -2156,7 +2180,7 @@ end_nup(pstops_doc_t *doc,		/* I - Docum
2ab05c1
 	    * Rotate the labels back to portrait...
2ab05c1
 	    */
2ab05c1
 
2ab05c1
-	    write_labels(doc, Orientation - 1);
2ab05c1
+	    write_labels(doc, doc->orientation - 1);
2ab05c1
 	  }
2ab05c1
 	  else if (Orientation == 0)
2ab05c1
 	  {
2ab05c1
@@ -2182,7 +2206,7 @@ end_nup(pstops_doc_t *doc,		/* I - Docum
2ab05c1
     default :
2ab05c1
 	if (is_last_page(number) && doc->use_ESPshowpage)
2ab05c1
 	{
2ab05c1
-	  write_labels(doc, Orientation);
2ab05c1
+	  write_labels(doc, doc->orientation);
2ab05c1
           doc_puts(doc, "ESPshowpage\n");
2ab05c1
 	}
2ab05c1
         break;
2ab05c1
@@ -2385,6 +2409,12 @@ set_pstops_options(
2ab05c1
   doc->new_bounding_box[3] = INT_MIN;
2ab05c1
 
2ab05c1
  /*
2ab05c1
+  * Save original orientation of the document
2ab05c1
+  */
2ab05c1
+
2ab05c1
+  doc->orientation = Orientation;
2ab05c1
+
2ab05c1
+ /*
2ab05c1
   * AP_FIRSTPAGE_InputSlot
2ab05c1
   */
2ab05c1