For an very simple PS file (just the "test" word), applying "ps2epsi" and "gs -dEPSCrop -sDEVICE=pnggray" results in png file with some parts of letters chopped off (see croptest_epsi.png in attached archive). If instead of ps2epsi the outbut of "gs -sDEVICE=bbox" is inserted into the ps file (to make eps) - png comes out OK (croptest_eps.png). Both ways to make pdf file fail (croptest_eps.pdf and croptest_epsi.pdf). I have been told that the procedure also fails with both gs 8.53 and 7.07.1. PS file: %!PS-Adobe-3.0 /inch {72 mul} def /Times-Roman findfont 50 scalefont setfont 2.5 inch 5 inch moveto (test) show showpage Creating EPS, PNG and PDF: gs -dNOPAUSE -sDEVICE=bbox -- croptest.ps 2> croptest.bbox cp croptest.bbox croptest.bbx echo %%EndComments >> croptest.bbx cat croptest.ps | sed -e '/^%!PS-Adobe-3.0/s/$/ EPSF-3.0/' -e '/^%!PS-Adobe-3.0/rcroptest.bbx' > croptest.eps rm croptest.bbx gs -dEPSCrop -DNOPAUSE -sDEVICE=pdfwrite -sOutputFile=croptest_eps.pdf croptest.eps quit.ps gs -dEPSCrop -DNOPAUSE -sDEVICE=pnggray -r1200 -sOutputFile=croptest_eps.png croptest.eps quit.ps pdfinfo croptest_eps.pdf > croptest_eps.txt ps2epsi croptest.ps gs -dEPSCrop -DNOPAUSE -sDEVICE=pdfwrite -sOutputFile=croptest_epsi.pdf croptest.epsi quit.ps gs -dEPSCrop -DNOPAUSE -sDEVICE=pnggray -r1200 -sOutputFile=croptest_epsi.png croptest. epsi quit.ps pdfinfo croptest_epsi.pdf > croptest_epsi.txt Sincerely, Michail
Created attachment 1935 [details] testcase
With croptest.ps I confirm that the ps2epsi method of determining the bbox does not match the bbox device. Specifically, bbox gives: %%BoundingBox: 180 359 250 389 %%HiResBoundingBox: 180.646940 359.496903 249.497922 388.949894 but ps2epsi generated BoundingBox is: %%BoundingBox: 181 360 249 389 Since there is no real problem if the EPS BoundingBox is slightly larger than needed to contain the marked area, we should adjust the llx lly urx ury to expand the margin by one point (llx lly 1 smaller, urx, ury 1 bigger). This is somewhat expected because the low res image used for the EPS preview is used to derive the ps2epsi bbox values and this is imprecise.
Ken, I'd like you to maintain epswrite also.
Well, I have 2 variants on the same solution. This is because I'm unsure about the rules Ghostscript uses for rendering partially covered pixels. In simple cases if a pixel is more than half filled, then it is rendered, less then it is not, I'm assuming this is generally true for Ghostscript. If this is true we should be able to use Ray's suggestion, but instead of putting a full pixel (1 point) around the calculated bounding box a half pixel (half point) should be sufficient. This works for the test case, and makes for a closer tolerance of the bounding box than using a full point. The other variant, of course, is to use Ray's suggestion verbatim, which also works for the test case. Anyone like to enlighten me about filling rules ?
Fixed in revision 9619, patch here: http://ghostscript.com/pipermail/gs-cvs/2009-April/009194.html