From 27f9a1a26b407ea7a5d56e644c75dbc0e671b15f Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 4 Apr 2022 10:36:58 +0200 Subject: [PATCH] Make pdftopdf also work correctly with auro-rotating off 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 | 3 +++ filter/pdftopdf/pdftopdf_processor.cc | 5 +++-- filter/pdftopdf/pdftopdf_processor.h | 2 +- filter/pdftopdf/qpdf_pdftopdf_processor.cc | 11 ++++++++--- filter/pdftopdf/qpdf_pdftopdf_processor.h | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 8b584d47f..70f6c3fd3 100644 --- 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), diff --git a/filter/pdftopdf/pdftopdf_processor.cc b/filter/pdftopdf/pdftopdf_processor.cc index c6b2e720c..9edb7fa08 100644 --- a/filter/pdftopdf/pdftopdf_processor.cc +++ b/filter/pdftopdf/pdftopdf_processor.cc @@ -264,8 +264,9 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m) // {{ 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; diff --git a/filter/pdftopdf/pdftopdf_processor.h b/filter/pdftopdf/pdftopdf_processor.h index ec7b2997b..3d64d1a4e 100644 --- a/filter/pdftopdf/pdftopdf_processor.h +++ b/filter/pdftopdf/pdftopdf_processor.h @@ -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 &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0; virtual void mirror() =0; diff --git a/filter/pdftopdf/qpdf_pdftopdf_processor.cc b/filter/pdftopdf/qpdf_pdftopdf_processor.cc index a330e825f..2420e1f47 100644 --- a/filter/pdftopdf/qpdf_pdftopdf_processor.cc +++ b/filter/pdftopdf/qpdf_pdftopdf_processor.cc @@ -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); } diff --git a/filter/pdftopdf/qpdf_pdftopdf_processor.h b/filter/pdftopdf/qpdf_pdftopdf_processor.h index f721d9390..51e0d4f7a 100644 --- a/filter/pdftopdf/qpdf_pdftopdf_processor.h +++ b/filter/pdftopdf/qpdf_pdftopdf_processor.h @@ -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: -- 2.47.3