diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 2502f5f..4bf4f06 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -3596,6 +3596,10 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { GooString *s; PSOutPaperSize *paperSize; + // Page Boundingbox Translation + double pbbtx=0; + double pbbty=0; + xref = xrefA; if (mode == psModePS) { GooString pageLabel; @@ -3680,41 +3684,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) { @@ -3740,21 +3732,84 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { tx -= xScale * x1; ty -= yScale * y1; } + // center if (tx0 >= 0 && ty0 >= 0) { - tx += (rotate == 0 || rotate == 180) ? tx0 : ty0; - ty += (rotate == 0 || rotate == 180) ? ty0 : -tx0; + pbbtx = (rotate == 0 || rotate == 180) ? tx0 : ty0; + pbbty = (rotate == 0 || rotate == 180) ? ty0 : -tx0; } else if (globalParams->getPSCenter()) { if (clipLLX0 < clipURX0 && clipLLY0 < clipURY0) { - tx += (imgWidth2 - xScale * (clipURX0 - clipLLX0)) / 2; - ty += (imgHeight2 - yScale * (clipURY0 - clipLLY0)) / 2; + pbbtx = (imgWidth2 - xScale * (clipURX0 - clipLLX0)) / 2; + pbbty = (imgHeight2 - yScale * (clipURY0 - clipLLY0)) / 2; } else { - tx += (imgWidth2 - xScale * width) / 2; - ty += (imgHeight2 - yScale * height) / 2; + pbbtx = (imgWidth2 - xScale * width) / 2; + pbbty = (imgHeight2 - yScale * height) / 2; } } - tx += (rotate == 0 || rotate == 180) ? imgLLX : imgLLY; - ty += (rotate == 0 || rotate == 180) ? imgLLY : -imgLLX; + + pbbtx += (rotate == 0 || rotate == 180) ? imgLLX : imgLLY; + pbbty += (rotate == 0 || rotate == 180) ? imgLLY : -imgLLX; + + tx += pbbtx; + ty += pbbty; + + // 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(pbbtx), + int(pbbty), + int(width * xScale + pbbtx + 0.5), + int(height * yScale + pbbty + 0.5)); + break; + case 180: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(imgWidth2 + pbbtx), + int(imgHeight2 + pbbty), + int(imgWidth2 + pbbtx + width * xScale + 0.5), + int(imgHeight2 + pbbty + height * yScale + 0.5)); + break; + case 90: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(imgHeight2 + pbbty), + int(pbbtx), + int(imgHeight2 + pbbty + height * yScale + 0.5), + int(pbbtx + width * xScale + 0.5)); + break; + case 270: + writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n", + int(pbbty), + int(imgWidth2 + pbbtx), + int(pbbty + height * yScale + 0.5), + int(imgWidth2 + pbbtx + 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); }