commit 1c0f429bab65ebb47c8c07596203089b5cef412a Author: Martin Pahl Date: Fri Mar 13 09:43:40 2015 +0100 fix the calculation of the PageBoundingBox in DSC comment Signed-off-by: Martin Pahl diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 2502f5f..01cc25d 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -3680,41 +3680,29 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { } } } - 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) { @@ -3755,6 +3743,64 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { } 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); }