From 2045bcb71b05b9882a6dcb31082acefac54f89a6 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Sat, 14 Dec 2013 16:05:09 +1030 Subject: [PATCH 1/3] pdftops: ensure paper size takes into account rotation Bug 72312 --- poppler/PSOutputDev.cc | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 623251f..32be0a3 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -1432,6 +1432,7 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage, switch (mode) { case psModePSOrigPageSizes: + paperMatch = gTrue; prevWidth = 0; prevHeight = 0; case psModePS: @@ -3550,34 +3551,6 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { switch (mode) { case psModePSOrigPageSizes: - x1 = (int)floor(state->getX1()); - y1 = (int)floor(state->getY1()); - x2 = (int)ceil(state->getX2()); - y2 = (int)ceil(state->getY2()); - width = x2 - x1; - height = y2 - y1; - if (width > height) { - landscape = gTrue; - } else { - landscape = gFalse; - } - writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", x1, y1, x2 - x1, y2 - y1); - writePS("%%BeginPageSetup\n"); - writePSFmt("%%PageOrientation: {0:s}\n", - landscape ? "Landscape" : "Portrait"); - if ((width != prevWidth) || (height != prevHeight)) { - // Set page size only when it actually changes, as otherwise Duplex - // printing does not work - writePSFmt("<> setpagedevice\n", width, height); - prevWidth = width; - prevHeight = height; - } - writePS("pdfStartPage\n"); - writePSFmt("{0:d} {1:d} {2:d} {3:d} re W\n", x1, y1, x2 - x1, y2 - y1); - writePS("%%EndPageSetup\n"); - ++seqPage; - break; - case psModePS: // rotate, translate, and scale page imgWidth = imgURX - imgLLX; @@ -3620,6 +3593,25 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { landscape ? "Landscape" : "Portrait"); if (paperMatch) { writePSFmt("{0:d} {1:d} pdfSetupPaper\n", imgURX, imgURY); + if (mode == psModePSOrigPageSizes) { + // Set page size only when it actually changes, as otherwise Duplex + // printing does not work + if (rotate == 0 || rotate == 180) { + if ((width != prevWidth) || (height != prevHeight)) { + writePSFmt("<> setpagedevice\n", + width, height); + prevWidth = width; + prevHeight = height; + } + } else { + if ((height != prevWidth) || (width != prevHeight)) { + writePSFmt("<> setpagedevice\n", + height, width); + prevWidth = height; + prevHeight = width; + } + } + } } writePS("pdfStartPage\n"); if (rotate == 0) { -- 1.8.3.2