d509400
diff -up cups-1.4.4/filter/pstops.c.page-label cups-1.4.4/filter/pstops.c
d509400
--- cups-1.4.4/filter/pstops.c.page-label	2010-03-30 23:07:33.000000000 +0100
d509400
+++ cups-1.4.4/filter/pstops.c	2010-06-18 09:36:18.239126341 +0100
4a94f7b
@@ -108,6 +108,7 @@ typedef struct				/**** Document informa
4a94f7b
   int		num_options;		/* Number of document-wide options */
4a94f7b
   cups_option_t	*options;		/* Document-wide options */
4a94f7b
   int		normal_landscape,	/* Normal rotation for landscape? */
4a94f7b
+		orientation,		/* Original orientation of the document */
4a94f7b
 		saw_eof,		/* Saw the %%EOF comment? */
4a94f7b
 		slow_collate,		/* Collate copies by hand? */
4a94f7b
 		slow_duplex,		/* Duplex pages slowly? */
d509400
@@ -2083,7 +2084,7 @@ do_setup(pstops_doc_t *doc,		/* I - Docu
4a94f7b
     * of the pages...
4a94f7b
     */
4a94f7b
 
4a94f7b
-    if (Orientation & 1)
4a94f7b
+    if (doc->orientation & 1)
4a94f7b
       write_label_prolog(doc, doc->page_label, PageBottom,
4a94f7b
                          PageWidth - PageLength + PageTop, PageLength);
4a94f7b
     else
d509400
@@ -2091,7 +2092,30 @@ do_setup(pstops_doc_t *doc,		/* I - Docu
4a94f7b
                          PageLength);
4a94f7b
   }
4a94f7b
   else
4a94f7b
-    write_label_prolog(doc, doc->page_label, PageBottom, PageTop, PageWidth);
4a94f7b
+  {
4a94f7b
+    switch (doc->orientation)
4a94f7b
+    {
4a94f7b
+      case 0 :
4a94f7b
+	  write_label_prolog(doc, doc->page_label, PageBottom, PageTop, 
4a94f7b
+                             PageWidth);
4a94f7b
+          break;
4a94f7b
+
4a94f7b
+      case 1 :
4a94f7b
+	  write_label_prolog(doc, doc->page_label, PageLeft, PageRight, 
4a94f7b
+                             PageLength);
4a94f7b
+          break;
4a94f7b
+
4a94f7b
+      case 2 :
4a94f7b
+	  write_label_prolog(doc, doc->page_label, PageLength - PageTop, 
4a94f7b
+                             PageLength - PageBottom, PageWidth);
4a94f7b
+          break;
4a94f7b
+
4a94f7b
+      case 3 :
4a94f7b
+	  write_label_prolog(doc, doc->page_label, PageWidth - PageRight, 
4a94f7b
+                             PageWidth - PageLeft, PageLength);
4a94f7b
+          break;
4a94f7b
+    }
4a94f7b
+  }
4a94f7b
 }
4a94f7b
 
4a94f7b
 
d509400
@@ -2176,7 +2200,7 @@ end_nup(pstops_doc_t *doc,		/* I - Docum
4a94f7b
     case 1 :
4a94f7b
 	if (doc->use_ESPshowpage)
4a94f7b
 	{
4a94f7b
-	  write_labels(doc, Orientation);
4a94f7b
+	  write_labels(doc, doc->orientation);
4a94f7b
           doc_puts(doc, "ESPshowpage\n");
4a94f7b
 	}
4a94f7b
 	break;
d509400
@@ -2191,7 +2215,7 @@ end_nup(pstops_doc_t *doc,		/* I - Docum
4a94f7b
 	    * Rotate the labels back to portrait...
4a94f7b
 	    */
4a94f7b
 
4a94f7b
-	    write_labels(doc, Orientation - 1);
4a94f7b
+	    write_labels(doc, doc->orientation - 1);
4a94f7b
 	  }
4a94f7b
 	  else if (Orientation == 0)
4a94f7b
 	  {
d509400
@@ -2217,7 +2241,7 @@ end_nup(pstops_doc_t *doc,		/* I - Docum
4a94f7b
     default :
4a94f7b
 	if (is_last_page(number) && doc->use_ESPshowpage)
4a94f7b
 	{
4a94f7b
-	  write_labels(doc, Orientation);
4a94f7b
+	  write_labels(doc, doc->orientation);
4a94f7b
           doc_puts(doc, "ESPshowpage\n");
4a94f7b
 	}
4a94f7b
         break;
d509400
@@ -2420,6 +2444,12 @@ set_pstops_options(
4a94f7b
   doc->new_bounding_box[3] = INT_MIN;
4a94f7b
 
4a94f7b
  /*
4a94f7b
+  * Save original orientation of the document
4a94f7b
+  */
4a94f7b
+
4a94f7b
+  doc->orientation = Orientation;
4a94f7b
+
4a94f7b
+ /*
d509400
   * AP_FIRSTPAGE_* and the corresponding non-first-page options.
4a94f7b
   */
4a94f7b