]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
Make pdftopdf also work correctly with auro-rotating off
authorTill Kamppeter <till.kamppeter@gmail.com>
Mon, 4 Apr 2022 08:36:58 +0000 (10:36 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Mon, 4 Apr 2022 08:36:58 +0000 (10:36 +0200)
If one turns off auto-rotating in the pdftopdf() filter function
(option "nopdfAutoRotate") the orientation of the input page on the
output sheet is manually controlled by the options
"orientation-requested" and "landscape".

The cropping of the pages (with "print-scaling=none") did not work
correctly with auto-rotating turned off. This commit fixes this.

Now all should work correctly as described here:

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

(manually backported from commit f730a1f8c23b11e89e665aba5f77e8dd979db795)

NEWS
filter/pdftopdf/pdftopdf_processor.cc
filter/pdftopdf/pdftopdf_processor.h
filter/pdftopdf/qpdf_pdftopdf_processor.cc
filter/pdftopdf/qpdf_pdftopdf_processor.h

diff --git a/NEWS b/NEWS
index 8b584d47f6c10ec0c0e27234c9b92347f46b32ff..70f6c3fd3b03544b9296af57e89d1ac646571020 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ NEWS - OpenPrinting CUPS Filters v1.28.13 - 2022-03-27
 
 CHANGES IN V1.28.14
 
+       - pdftopdf: Correct the output when suppressing auto-rotation
+         (option "nopdfAutoRotate"). Depending on the situation pages
+         got cropped in the wrong orientation or de-centered.
        - pdftopdf: Correct the output when the
          "orientation-requested" or the "landscape" option is
          supplied. Output could be de-centered (Issue #456),
index c6b2e720c070e124cd5bd53058a41e8911b2a0d9..9edb7fa08141f637cbaf1a85919c4a3564d4f724 100644 (file)
@@ -264,8 +264,9 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
        orientation = param.normal_landscape;
       else
        orientation = ROT_0;
-      page->crop(param.page, orientation, param.xpos, param.ypos,
-                !param.cropfit);
+      page->crop(param.page, orientation, param.orientation,
+                param.xpos, param.ypos,
+                !param.cropfit, param.autoRotate);
     }
     if (param.fillprint)
       param.fitplot = true;
index ec7b2997b24be3f67f37244623a7d98a50fc6214..3d64d1a4efcf592f6139405b1a07bf22a944ac06 100644 (file)
@@ -118,7 +118,7 @@ class PDFTOPDF_PageHandle {
   // fscale:  inverse_scale (from nup, fitplot)
   virtual void add_border_rect(const PageRect &rect,BorderType border,float fscale) =0;
   // TODO?! add standalone crop(...) method (not only for subpages)
-  virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale) =0;
+  virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate) =0;
   virtual bool is_landscape(Rotation orientation) =0 ;
   virtual void add_subpage(const std::shared_ptr<PDFTOPDF_PageHandle> &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0;
   virtual void mirror() =0;
index a330e825f40fd7e6e0915221da9b30c1901cc72e..2420e1f474f3eeca6bccd056582ef54c880a11c6 100644 (file)
@@ -176,7 +176,7 @@ void QPDF_PDFTOPDF_PageHandle::add_border_rect(const PageRect &_rect,BorderType
  *  Trim Box is used for trimming the page in required size.
  *  scale tells if we need to scale input file.
  */
-Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale)
+Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate)
 {
   page.assertInitialized();
   Rotation save_rotate = getRotate(page);
@@ -193,8 +193,13 @@ Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orient
   double final_w,final_h;   //Width and height of cropped image.
 
   Rotation pageRot = getRotate(page);
-  if (((pageRot == ROT_0 || pageRot == ROT_180) && pageWidth <= pageHeight) ||
-      ((pageRot == ROT_90 || pageRot == ROT_270) && pageWidth > pageHeight))
+  if ((autorotate &&
+       (((pageRot == ROT_0 || pageRot == ROT_180) &&
+        pageWidth <= pageHeight) ||
+       ((pageRot == ROT_90 || pageRot == ROT_270) &&
+        pageWidth > pageHeight))) ||
+      (!autorotate &&
+       (param_orientation == ROT_90 || param_orientation == ROT_270)))
   {
     std::swap(pageHeight,pageWidth);
   }
index f721d93909fb59cb8bc51ae52e15a102b13ed0b7..51e0d4f7a3031353da45758a40caabe884d8216a 100644 (file)
@@ -12,7 +12,7 @@ class QPDF_PDFTOPDF_PageHandle : public PDFTOPDF_PageHandle {
   virtual void mirror();
   virtual void rotate(Rotation rot);
   virtual void add_label(const PageRect &rect, const std::string label);
-  virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale);
+  virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate);
   virtual bool is_landscape(Rotation orientation);
   void debug(const PageRect &rect,float xpos,float ypos);
  private: