]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/pstops.c
Merge changes from CUPS 1.4svn-r7696.
[thirdparty/cups.git] / filter / pstops.c
index 77bc2df964d80d372a8859e4809a74b5ed098140..7517a4978ae1df69206189db27b5a676d40cf991 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: pstops.c 7006 2007-10-04 17:43:38Z mike $"
+ * "$Id: pstops.c 7689 2008-06-24 20:50:57Z mike $"
  *
  *   PostScript filter for the Common UNIX Printing System (CUPS).
  *
@@ -1259,6 +1259,7 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
   int          level;                  /* Embedded document level */
   pstops_page_t        *pageinfo;              /* Page information */
   int          first_page;             /* First page on N-up output? */
+  int          has_page_setup;         /* Does the page have %%Begin/EndPageSetup? */
   int          bounding_box[4];        /* PageBoundingBox */
 
 
@@ -1508,7 +1509,7 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
   if (first_page)
     doc_puts(doc, "%%BeginPageSetup\n");
 
-  if (!strncmp(line, "%%BeginPageSetup", 16))
+  if ((has_page_setup = !strncmp(line, "%%BeginPageSetup", 16)) != 0)
   {
     int        feature = 0;                    /* In a Begin/EndFeature block? */
 
@@ -1540,6 +1541,9 @@ copy_page(cups_file_t  *fp,               /* I - File to read from */
       else if (!strncmp(line, "%%Include", 9))
        continue;
 
+      if (line[0] != '%' && !feature)
+        break;
+
       if (!feature || (doc->number_up == 1 && !doc->fitplot))
        doc_write(doc, line, linelen);
     }
@@ -1548,8 +1552,11 @@ copy_page(cups_file_t  *fp,              /* I - File to read from */
     * Skip %%EndPageSetup...
     */
 
-    if (linelen > 0)
-      linelen = cupsFileGetLine(fp, line, linesize);
+    if (linelen > 0 && !strncmp(line, "%%EndPageSetup", 14))
+    {
+      linelen        = cupsFileGetLine(fp, line, linesize);
+      has_page_setup = 0;
+    }
   }
 
   if (first_page)
@@ -1629,6 +1636,45 @@ copy_page(cups_file_t  *fp,              /* I - File to read from */
   * Finish the PageSetup section as needed...
   */
 
+  if (has_page_setup)
+  {
+    int        feature = 0;                    /* In a Begin/EndFeature block? */
+
+    doc_write(doc, line, linelen);
+
+    while ((linelen = cupsFileGetLine(fp, line, linesize)) > 0)
+    {
+      if (!strncmp(line, "%%EndPageSetup", 14))
+       break;
+      else if (!strncmp(line, "%%BeginFeature:", 15))
+      {
+       feature = 1;
+
+       if (doc->number_up > 1 || doc->fitplot)
+         continue;
+      }
+      else if (!strncmp(line, "%%EndFeature", 12))
+      {
+       feature = 0;
+
+       if (doc->number_up > 1 || doc->fitplot)
+         continue;
+      }
+      else if (!strncmp(line, "%%Include", 9))
+       continue;
+
+      if (!feature || (doc->number_up == 1 && !doc->fitplot))
+       doc_write(doc, line, linelen);
+    }
+
+   /*
+    * Skip %%EndPageSetup...
+    */
+
+    if (linelen > 0 && !strncmp(line, "%%EndPageSetup", 14))
+      linelen = cupsFileGetLine(fp, line, linesize);
+  }
+
   if (first_page)
     doc_puts(doc, "%%EndPageSetup\n");
 
@@ -3369,5 +3415,5 @@ write_labels(pstops_doc_t *doc,           /* I - Document information */
 
 
 /*
- * End of "$Id: pstops.c 7006 2007-10-04 17:43:38Z mike $".
+ * End of "$Id: pstops.c 7689 2008-06-24 20:50:57Z mike $".
  */