Bug 43634 - EPS output works poorly with dvips
Summary: EPS output works poorly with dvips
Alias: None
Product: cairo
Classification: Unclassified
Component: postscript backend (show other bugs)
Version: 1.10.3
Hardware: All All
: medium normal
Assignee: Adrian Johnson
QA Contact: cairo-bugs mailing list
Depends on:
Reported: 2011-12-08 08:20 UTC by tommie
Modified: 2011-12-09 06:16 UTC (History)
0 users

See Also:
i915 platform:
i915 features:

fix EPS (1.76 KB, patch)
2011-12-09 05:40 UTC, Adrian Johnson
Details | Splinter Review

Description tommie 2011-12-08 08:20:44 UTC
The PostScript surface pushes the userdict onto the dictionary stack in its setup code when in EPS mode. This (sometimes) causes problems when dvips includes the EPS image, due to the "showpage" command not being a no-op if it happens to be in userdict.

This is probably what causes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620146 as well.

The dvips decorations for EPSes essentially does

  /SDict 200 dict def
  SDict begin
  /showpage {} def
  [insert EPS]

However, the EPS generated by Cairo turns this into

  /SDict 200 dict def
  SDict begin
  /showpage {} def
  userdict begin
  [insert rest of EPS]

and if userdict happens to contain a non-nooped showpage, this will cause the showpage redefinition to be ignored.

The way I interpret the EPS 3 specification, section 2.4 is that you shouldn't use userdict:

  There are some PostScript language operators plus
  statusdict and userdict operators that are intended
  for system-level jobs or page descriptions that are
  not appropriate in an EPS file.

and 3.2 hints that you should create your own dictionary instead:

  [...] Ideally, the imported EPS file should create
  its own dictionary, but if it does not, [...]

I had a quick look at an Illustrator-generated EPS, and it creates a dict of 75 entries and uses that as the top-of-dictionary-stack, something like:

  /dict_count countdictstack def
  75 dict begin
  [insert rest of EPS]
  countdictstack dict_count sub {end} repeat
Comment 1 Adrian Johnson 2011-12-09 05:40:02 UTC
Created attachment 54266 [details] [review]
fix EPS

I'm not sure why I used that EPS prolog/trailer. Looking at the EPS spec it looks like I copied it from the example not realizing that code was meant for the application, not the EPS file.

The attached patch should fix the problem. Let me know if it works and I will commit it. The patch simplifies the EPS code to:

50 dict begin


Comment 2 tommie 2011-12-09 05:56:51 UTC
(In reply to comment #1)
> The attached patch should fix the problem. Let me know if it works and I will
> commit it. The patch simplifies the EPS code to:

The patch looks good. Tested it against 1.8.10 (Debian Squeeze, standard patch fuzz factor) with Inkscape. The raw output works in gs(1), and the generated dvips(1)-file looks good in Evince.

Thank you.
Comment 3 Adrian Johnson 2011-12-09 06:16:05 UTC
Fixed in http://cgit.freedesktop.org/cairo/commit

Thanks for the bug report and analysis.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.