]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Make pdftopdf() correctly working with "landscape" option
authorTill Kamppeter <till.kamppeter@gmail.com>
Sun, 3 Apr 2022 17:28:17 +0000 (19:28 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Sun, 3 Apr 2022 17:28:17 +0000 (19:28 +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
inbto cells happened in the wrong oriantation.

This commit fixes these issues.

cupsfilters/pdftopdf/pdftopdf_processor.cc

index 3553833d2049ef4a652542f459dae26be9dc6053..fc432655b9a35e0554517790d6f5511331874fcd 100644 (file)
@@ -177,7 +177,8 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param,pdftop
   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)
@@ -295,10 +296,11 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param,pdftop
     for (int i = 0; i < (int)input_page_range_list.size(); i ++)
     {
       std::shared_ptr<PDFTOPDF_PageHandle> page = input_page_range_list[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, doc);
     }
@@ -405,7 +407,8 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param,pdftop
       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;