Ok, I can not review my own code, but I will try to explain, what I changed.
The patch might look bigger than it actually is. This is because I had to
restructure the code a little bit, because in the original calculation of
bounding box and output to the postscript file is mixed. But to know the
PageBoundingBox you have to first transform the origincal bounding box of the
object to the output media coordinates. In the end my code only touches the
calculation of the PageBoundingBox. Nothing else is changed.
So lets start (o-prefix = original linenumbers, p-prefix = patched
linenummbers):
In line p3678 I introduced and initialized two variables pbbtx and pbbty to
save the page bounding box translation.
>From line o3765 - o3800 (p3772-p3793) I removed every writePS-command to do
that after calculation of page bounding box translation. I also changed the
chain of if-clauses into one switch statement.
Starting in line p3818 the the translation of page bounding box is calculated.
The result is stored in the new variables pbbtx and pbbty. In the original
code these values are immediately added to tx and ty. But we need these values
later on. So we store them and add them to tx and ty in line p3636 and p3637.
So after all the value of tx and ty are the same as before.
>From line p3839 the result is written to the PS file.
Hope this explanation helps a little bit to understand the code. The patch to
the newest version of poppler is added in the attachement.
Regards,
Martin Pahl
P.S. I used the old fashioned xfig to produce pdf files that show this bug,
because xfig produced pdf with a media size identical to the size of the
figure.
I can generate an example pdf and corresponding ps files next week.
Am Freitag, 23. Oktober 2015, 00:05:07 schrieb William Bader:
> I can look at the C++ code to check that the code does what it claims to do.
> I think that what it claims to do is correct, but I work mostly with single
> page documents, so someone who knows more about DSCs should look at that.
> Regards,William
>
> > From: [email protected]
> > To: [email protected]
> > Date: Fri, 23 Oct 2015 00:02:01 +0200
> > Subject: Re: [poppler] Printing of certain PDF files does not work
> > with "fit-to-page" because of wrong BoundingBox values in the
> > PostScript>
> > El Thursday 22 October 2015, a les 04:12:41, William Bader va escriure:
> > > Hi Stefan,
> > >
> > > I am a poppler user, not a popper maintainer. I can't push changes.
> > > Sorry.
> >
> > But you can review them. Pushing is very easy, it's the review part that
> > is
> > hard.
> >
> > Cheers,
> >
> > Albert
> >
> > > Regards,
> > > William
> > >
> > > From: [email protected]
> > > To: [email protected]; [email protected]
> > > Subject: Aw: RE: [poppler] Printing of certain PDF files does not work
> > > with
> > > "fit-to-page" because of wrong BoundingBox values in the PostScript
> > > Date:
> > > Thu, 22 Oct 2015 09:18:11 +0200
> > >
> > >
> > > This printing problem appear at pdf files which are coming from scanner.
> > >
> > > Since years there are reports of this problem:
> > >
> > > https://forum.kde.org/viewtopic.php?f=20&t=97572
> > >
> > > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=761487
> > >
> > > https://bugs.kde.org/show_bug.cgi?id=338456
> > >
> > > https://bugs.kde.org/show_bug.cgi?id=195719
> > >
> > >
> > >
> > >
> > > We now found the root cause and have a fix.
> > >
> > >
> > >
> > > So if Albert has no time at all I wonder if you (William) can take over
> > > this solution and push it.
> > >
> > > As Martin Pahl wrote he is willing to support and explain his code.
> > >
> > >
> > >
> > > Regards
> > >
> > > Stefan
> > >
> > >
> > >
> > >
> > > Gesendet: Mittwoch, 21. Oktober 2015 um 01:44 Uhr
> > >
> > > Von: "William Bader" <[email protected]>
> > >
> > > An: "Stefan Brandner" <[email protected]>,
> > > "[email protected]" <[email protected]>
> > >
> > > Betreff: RE: [poppler] Printing of certain PDF files does not work with
> > > "fit-to-page" because of wrong BoundingBox values in the PostScript
> > >
> > >
> > >
> > >
> > > The Adobe document 5001.DSC_Spec.pdf "PostScript Language Document
> > > Structuring Conventions Specification" Version 3.0, 25 September 1992,
> > > says
> > > on page 39 about the BoundingBox comment:
> > >
> > >
> > > "This comment specifies the bounding box that encloses all marks painted
> > > on
> > > all pages of a document. That is, it must be a “high water mark” in all
> > > directions for marks made on any page. The four arguments correspond to
> > > the
> > > lower left ( llx , lly ) and upper right corners ( urx , ury ) of the
> > > bounding box in the default user coordinate system (PostScript units)."
> > >
> > >
> > >
> > > and gives an example where the BoundingBox is the smallest rectangle
> > > that
> > > covers the PageBoundingBoxes of the pages in the document.
> > >
> > >
> > >
> > > If you are worried about breaking things that depend on the current
> > > behavior of pdftops, would it work to add a command line option?
> > > pdftops already has -origpagesize and -nocrop options.
> > >
> > >
> > >
> > > Regards,
> > >
> > > William
> > >
> > >
> > >
> > > To: [email protected]
> > >
> > > From: [email protected]
> > >
> > > Date: Tue, 20 Oct 2015 19:02:03 +0200
> > >
> > > Subject: [poppler] Printing of certain PDF files does not work with
> > > "fit-to-page" because of wrong BoundingBox values in the PostScript
> > >
> > >
> > >
> > > I am using the patch now for several month and I can prove it is working
> > > fine. So if the code quality is ok for you Albert why not pushing it?
> > >
> > > Regards
> > > Stefan Brandner
> > >
> > > El Dijous, 7 de maig de 2015, a les 09:34:09, Martin Pahl va escriure:
> > > > Hi,
> > > >
> > > > I sent patches to fix the bug:
> > > >
> > > > https://bugs.freedesktop.org/show_bug.cgi?id=87161
> > > >
> > > > Those patches were automatically sent to poppler-bugs mailing list.
> > > > But as
> > > > I see no reaction to my patch submission (poppler-bugs seems to be a
> > > > mailinglist without human interaction) I just want to ask, what is
> > > > the
> > > > right way to submit patches.
> > >
> > > It is.
> > >
> > > What we need is more people with time to review patches.
> > >
> > > Cheers,
> > >
> > > Albert
> > >
> > > > By the way this bug is really annoying as it makes all PDF viewers
> > > > using
> > > > poppler useless for printing documents that do not have the page size
> > > > of
> > > > the output device (e.g. printer). On the other hand acroread is not an
> > > > alternative anymore as Adobe has discontinued support for Linux.
> > > >
> > > > Regards,
> > > >
> > > > Martin Pahl
> > >
> > > _______________________________________________ poppler mailing list
> > > [email protected]
> > > http://lists.freedesktop.org/mailman/listinfo/poppler
> >
> > _______________________________________________
> > poppler mailing list
> > [email protected]
> > http://lists.freedesktop.org/mailman/listinfo/poppler
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 7b93e3b..18c132a 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -3675,9 +3675,14 @@ void PSOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) {
GooString *s;
PSOutPaperSize *paperSize;
+ // Page Boundingbox Translation
+ double pbbtx=0;
+ double pbbty=0;
+
if (!postInitDone) {
postInit();
}
+
xref = xrefA;
if (mode == psModePS) {
GooString pageLabel;
@@ -3762,41 +3767,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) {
@@ -3822,21 +3815,72 @@ 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:
+ case 180:
+ 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 90:
+ case 270:
+ writePSFmt("%%PageBoundingBox: {0:d} {1:d} {2:d} {3:d}\n",
+ int(pbbty),
+ int(pbbtx),
+ int(height * yScale + pbbty + 0.5),
+ int(width * xScale + pbbtx + 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);
}
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler