Bug 688500 - ps2epsi produces too-narrow bounding box (2)
Summary: ps2epsi produces too-narrow bounding box (2)
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 8.51
Hardware: Macintosh MacOS X
: P4 normal
Assignee: Ken Sharp
URL:
Keywords: bountiable
Depends on:
Blocks:
 
Reported: 2006-01-19 01:55 UTC by Michail Vidiassov
Modified: 2009-04-07 03:21 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
testcase (15.16 KB, application/octet-stream)
2006-01-19 01:56 UTC, Michail Vidiassov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michail Vidiassov 2006-01-19 01:55:26 UTC
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
Comment 1 Michail Vidiassov 2006-01-19 01:56:40 UTC
Created attachment 1935 [details]
testcase
Comment 2 Ray Johnston 2006-01-25 23:44:05 UTC
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.

Comment 3 leonardo 2008-01-31 04:04:02 UTC
Ken, I'd like you to maintain epswrite also.
Comment 4 Ken Sharp 2008-02-05 07:06:34 UTC
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 ?

Comment 5 Ken Sharp 2009-04-07 03:21:01 UTC
Fixed in revision 9619, patch here:

http://ghostscript.com/pipermail/gs-cvs/2009-April/009194.html