Skip to content

Commit 27f9a1a

Browse files
committed
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 f730a1f)
1 parent 161b32b commit 27f9a1a

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ NEWS - OpenPrinting CUPS Filters v1.28.13 - 2022-03-27
33

44
CHANGES IN V1.28.14
55

6+
- pdftopdf: Correct the output when suppressing auto-rotation
7+
(option "nopdfAutoRotate"). Depending on the situation pages
8+
got cropped in the wrong orientation or de-centered.
69
- pdftopdf: Correct the output when the
710
"orientation-requested" or the "landscape" option is
811
supplied. Output could be de-centered (Issue #456),

filter/pdftopdf/pdftopdf_processor.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
264264
orientation = param.normal_landscape;
265265
else
266266
orientation = ROT_0;
267-
page->crop(param.page, orientation, param.xpos, param.ypos,
268-
!param.cropfit);
267+
page->crop(param.page, orientation, param.orientation,
268+
param.xpos, param.ypos,
269+
!param.cropfit, param.autoRotate);
269270
}
270271
if (param.fillprint)
271272
param.fitplot = true;

filter/pdftopdf/pdftopdf_processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class PDFTOPDF_PageHandle {
118118
// fscale: inverse_scale (from nup, fitplot)
119119
virtual void add_border_rect(const PageRect &rect,BorderType border,float fscale) =0;
120120
// TODO?! add standalone crop(...) method (not only for subpages)
121-
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale) =0;
121+
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate) =0;
122122
virtual bool is_landscape(Rotation orientation) =0 ;
123123
virtual void add_subpage(const std::shared_ptr<PDFTOPDF_PageHandle> &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0;
124124
virtual void mirror() =0;

filter/pdftopdf/qpdf_pdftopdf_processor.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void QPDF_PDFTOPDF_PageHandle::add_border_rect(const PageRect &_rect,BorderType
176176
* Trim Box is used for trimming the page in required size.
177177
* scale tells if we need to scale input file.
178178
*/
179-
Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale)
179+
Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate)
180180
{
181181
page.assertInitialized();
182182
Rotation save_rotate = getRotate(page);
@@ -193,8 +193,13 @@ Rotation QPDF_PDFTOPDF_PageHandle::crop(const PageRect &cropRect,Rotation orient
193193
double final_w,final_h; //Width and height of cropped image.
194194

195195
Rotation pageRot = getRotate(page);
196-
if (((pageRot == ROT_0 || pageRot == ROT_180) && pageWidth <= pageHeight) ||
197-
((pageRot == ROT_90 || pageRot == ROT_270) && pageWidth > pageHeight))
196+
if ((autorotate &&
197+
(((pageRot == ROT_0 || pageRot == ROT_180) &&
198+
pageWidth <= pageHeight) ||
199+
((pageRot == ROT_90 || pageRot == ROT_270) &&
200+
pageWidth > pageHeight))) ||
201+
(!autorotate &&
202+
(param_orientation == ROT_90 || param_orientation == ROT_270)))
198203
{
199204
std::swap(pageHeight,pageWidth);
200205
}

filter/pdftopdf/qpdf_pdftopdf_processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class QPDF_PDFTOPDF_PageHandle : public PDFTOPDF_PageHandle {
1212
virtual void mirror();
1313
virtual void rotate(Rotation rot);
1414
virtual void add_label(const PageRect &rect, const std::string label);
15-
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale);
15+
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Rotation param_orientation,Position xpos,Position ypos,bool scale,bool autorotate);
1616
virtual bool is_landscape(Rotation orientation);
1717
void debug(const PageRect &rect,float xpos,float ypos);
1818
private:

0 commit comments

Comments
 (0)