diff -uNr poppler-0.26.5/poppler/PSOutputDev.cc poppler-0.26.5-tnt/poppler/PSOutputDev.cc --- poppler-0.26.5/poppler/PSOutputDev.cc 2014-04-26 17:37:22.000000000 +0200 +++ poppler-0.26.5-tnt/poppler/PSOutputDev.cc 2015-04-07 15:39:53.835252160 +0200 @@ -3580,6 +3580,10 @@ GooString *s; PSOutPaperSize *paperSize; + // Page Boundingbox Translation + double pbbtx=0; + double pbbty=0; + xref = xrefA; if (mode == psModePS) { GooString pageLabel; @@ -3664,41 +3668,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) { @@ -3724,21 +3715,85 @@ 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); }