diff -uNr poppler-0.26.5/poppler/PSOutputDev.cc poppler-0.26.5p/poppler/PSOutputDev.cc --- poppler-0.26.5/poppler/PSOutputDev.cc 2014-04-26 17:37:22.000000000 +0200 +++ poppler-0.26.5p/poppler/PSOutputDev.cc 2015-03-12 15:44:54.800581230 +0100 @@ -3664,41 +3664,28 @@ } } } - if (paperMatch) { - paperSize = (PSOutPaperSize *)paperSizes->get(pagePaperSize[pageNum]); - writePSFmt("%%PageMedia: {0:t}\n", paperSize->name); - } - if (rotate == 0 || rotate == 180) { - writePSFmt("%%PageBoundingBox: 0 0 {0:d} {1:d}\n", width, height); - } else { - writePSFmt("%%PageBoundingBox: 0 0 {0:d} {1:d}\n", height, width); - } - writePSFmt("%%PageOrientation: {0:s}\n", - landscape ? "Landscape" : "Portrait"); - writePS("%%BeginPageSetup\n"); - if (paperMatch) { - writePSFmt("{0:d} {1:d} pdfSetupPaper\n", imgURX, imgURY); - } - writePS("pdfStartPage\n"); - if (rotate == 0) { + + switch (rotate) { + case 0: imgWidth2 = imgWidth; imgHeight2 = imgHeight; - } else if (rotate == 90) { - writePS("90 rotate\n"); + break; + case 90: ty = -imgWidth; imgWidth2 = imgHeight; imgHeight2 = imgWidth; - } else if (rotate == 180) { - writePS("180 rotate\n"); + break; + case 180: imgWidth2 = imgWidth; imgHeight2 = imgHeight; tx = -imgWidth; ty = -imgHeight; - } else { // rotate == 270 - writePS("270 rotate\n"); + break; + default: // rotate == 270 tx = -imgHeight; imgWidth2 = imgHeight; imgHeight2 = imgWidth; + break; } // shrink or expand if (xScale0 > 0 && yScale0 > 0) { @@ -3739,6 +3726,65 @@ } tx += (rotate == 0 || rotate == 180) ? imgLLX : imgLLY; ty += (rotate == 0 || rotate == 180) ? imgLLY : -imgLLX; + + // Write results to PS + if (paperMatch) { + paperSize = (PSOutPaperSize *)paperSizes->get(pagePaperSize[pageNum]); + writePSFmt("%%PageMedia: {0:t}\n", paperSize->name); + } + + switch (rotate) { + case 0: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(tx), + int(ty), + int(width * xScale + tx + 0.5), + int(height * yScale + ty + 0.5)); + break; + case 180: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(imgWidth2 + tx), + int(imgHeight2 + ty), + int(imgWidth2 + tx + width * xScale + 0.5), + int(imgHeight2 + ty + height * yScale + 0.5)); + break; + case 90: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(imgHeight2 + ty), + int(tx), + int(imgHeight2 + ty + height * yScale + 0.5), + int(tx + width * xScale + 0.5)); + break; + case 270: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(ty), + int(imgWidth2 + tx), + int(ty + height * yScale + 0.5), + int(imgWidth2 + tx + width * xScale + 0.5)); + break; + } + writePSFmt("%%PageOrientation: {0:s}\n", + landscape ? "Landscape" : "Portrait"); + writePS("%%BeginPageSetup\n"); + if (paperMatch) { + writePSFmt("{0:d} {1:d} pdfSetupPaper\n", imgURX, imgURY); + } + writePS("pdfStartPage\n"); + + switch (rotate) { + case 0: + break; + case 90: + writePS("90 rotate\n"); + break; + case 180: + writePS("180 rotate\n"); + break; + default: // rotate == 270 + writePS("270 rotate\n"); + break; + } + if (tx != 0 || ty != 0) { writePSFmt("{0:.6g} {1:.6g} translate\n", tx, ty); }