From f730a1f8c23b11e89e665aba5f77e8dd979db795 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 4 Apr 2022 00:13:00 +0200 Subject: [PATCH] libcupsfilters: 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 --- cupsfilters/pdftopdf/pdftopdf_processor.cc | 4 ++-- cupsfilters/pdftopdf/pdftopdf_processor.h | 2 +- cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc | 11 ++++++++--- cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cupsfilters/pdftopdf/pdftopdf_processor.cc b/cupsfilters/pdftopdf/pdftopdf_processor.cc index fc432655b..dba97d5a1 100644 --- a/cupsfilters/pdftopdf/pdftopdf_processor.cc +++ b/cupsfilters/pdftopdf/pdftopdf_processor.cc @@ -301,8 +301,8 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters ¶m,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; diff --git a/cupsfilters/pdftopdf/pdftopdf_processor.h b/cupsfilters/pdftopdf/pdftopdf_processor.h index 92cd105c0..0b2c70bec 100644 --- a/cupsfilters/pdftopdf/pdftopdf_processor.h +++ b/cupsfilters/pdftopdf/pdftopdf_processor.h @@ -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 &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0; virtual void mirror() =0; diff --git a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc index 34b24334f..d3be13107 100644 --- a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc +++ b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.cc @@ -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); } diff --git a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h b/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h index 9e13348ab..732e7cbff 100644 --- a/cupsfilters/pdftopdf/qpdf_pdftopdf_processor.h +++ b/cupsfilters/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,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: -- 2.47.3