]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Make pdftopdf() also work correctly with auro-rotating off
authorTill Kamppeter <till.kamppeter@gmail.com>
Sun, 3 Apr 2022 22:13:00 +0000 (00:13 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Sun, 3 Apr 2022 22:13:00 +0000 (00:13 +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

cupsfilters/pdftopdf/pdftopdf_processor.cc
cupsfilters/pdftopdf/pdftopdf_processor.h
cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc
cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h

index fc432655b9a35e0554517790d6f5511331874fcd..dba97d5a1f768e06b57029cb63a818ba69cb4413 100644 (file)
@@ -301,8 +301,8 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param,pdftop
        orientation = param.normal_landscape;
       else
        orientation = ROT_0;
-      page->crop(param.page, orientation, param.xpos, param.ypos,
-                !param.cropfit, doc);
+      page->crop(param.page, orientation, param.orientation, param.xpos, param.ypos,
+                !param.cropfit, param.autoRotate, doc);
     }
     if (param.fillprint)
       param.fitplot = true;
index 92cd105c09349c0ecfb3149ceee724179a319421..0b2c70becc0f8f6b5dc3624220b9871c1a4a9d1c 100644 (file)
@@ -123,7 +123,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,pdftopdf_doc_t *doc) =0;
+  virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc) =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 34b24334fd049b26fee90cedfb5a8f61d599486f..d3be131071186b95e19bbefb9b9a73ffad199381 100644 (file)
@@ -177,7 +177,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,pdftopdf_doc_t *doc)
+Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc)
 {
   page.assertInitialized();
   Rotation save_rotate = getRotate(page);
@@ -194,8 +194,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 9e13348ab20182e01b836509f25db028a889ca9b..732e7cbff5e4f9f5d2c84e6d72ea5ca96fd5c2f0 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,pdftopdf_doc_t *doc);
+  virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate,pdftopdf_doc_t *doc);
   virtual bool is_landscape(Rotation orientation);
   void debug(const PageRect &rect,float xpos,float ypos);
  private: