]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Make pdftopdf() correctly working with "landscape" option
authorTill Kamppeter <till.kamppeter@gmail.com>
Mon, 4 Apr 2022 08:14:28 +0000 (10:14 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Mon, 4 Apr 2022 08:14:28 +0000 (10:14 +0200)
The "landscape" option rotates the input pages by 90 degrees, in the
direction given by the "*LandscapeOrientation" in the PPD file.

The "orientation-requested" option/IPP attribute rotates the page
according to its value: 3: No rotation; 4: 90 degrees anticlockwise;
5: 90 dgrees clockwise; 6: 180 degrees (upside-down).

After that, at least when not suppressed via "nopdfAutoRotate"
("pdfAutoRotate=false") option, auto-rotation kicks in, rotating the
page by 90 degrees (direction according to "*LandscapeOrientation" in
the PPD file) if the orientations of the input page and the output
page mis-match.

See also:

https://openprinting.github.io/cups/doc/options.html
https://wiki.debian.org/CUPSPdfToPdf

When applying the "landscape" or "orientation-requested" option the
following bugs occured:

1. The page image did not only get rotated but also de-centered. See
issue #456.

2. When cropping ("print-scaling=none" or "print-scaling=fill")
portrait-oriented pages got wrongly cropped.

3. When using N-up ("number-up" option) division of the output page
into cells happened in the wrong oriantation.

This commit fixes these issues.

(manually backported from commit 9b86754edb4362c0765469eac1c315904cc295d9)

NEWS
filter/pdftopdf/pdftopdf_processor.cc

diff --git a/NEWS b/NEWS
index ca704590f6fd98d36c99bcd1da6bfa2a7f32d5ea..8b584d47f6c10ec0c0e27234c9b92347f46b32ff 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,12 @@ NEWS - OpenPrinting CUPS Filters v1.28.13 - 2022-03-27
 
 CHANGES IN V1.28.14
 
+       - pdftopdf: Correct the output when the
+         "orientation-requested" or the "landscape" option is
+         supplied. Output could be de-centered (Issue #456),
+         portrait-oriented pages be wrongly cropped and division of
+         the output page into cells for N-up done in the wrong
+         orientation.
        - rastertopdf: In PCLm output mode the filter failed to
          generate PCLm if the printer has no
          "pclm-source-resolution-default" IPP attribute.
index 30158b04f55a29b862f6231ad32b9de2575a21e3..c6b2e720c070e124cd5bd53058a41e8911b2a0d9 100644 (file)
@@ -152,7 +152,8 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
   const bool dst_lscape =
     (param.paper_is_landscape ==
      ((param.orientation == ROT_0) || (param.orientation == ROT_180)));
-  if (dst_lscape)
+
+  if (param.paper_is_landscape)
     std::swap(param.nup.nupX, param.nup.nupY);
 
   if (param.autoRotate)
@@ -258,10 +259,11 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
     for(int i=0;i<(int)pages.size();i++)
     {
       std::shared_ptr<PDFTOPDF_PageHandle> page = pages[i];
-      Rotation orientation = param.orientation;
-      if (param.noOrientation &&
-         page->is_landscape(param.orientation))
+      Rotation orientation;
+      if (page->is_landscape(param.orientation))
        orientation = param.normal_landscape;
+      else
+       orientation = ROT_0;
       page->crop(param.page, orientation, param.xpos, param.ypos,
                 !param.cropfit);
     }
@@ -365,7 +367,8 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
       if ((param.nup.nupX == 1) && (param.nup.nupY == 1))
       {
        double xpos2, ypos2;
-       if (param.orientation == ROT_270 || param.orientation == ROT_90)
+       if ((param.page.height - param.page.width) *
+           (page->getRect().height - page->getRect().width) < 0)
        {
          xpos2 = (param.page.width - (page->getRect().height)) / 2;
          ypos2 = (param.page.height - (page->getRect().width)) / 2;