Bug 43634

Summary: EPS output works poorly with dvips
Product: cairo Reporter: tommie
Component: postscript backendAssignee: Adrian Johnson <ajohnson>
Status: RESOLVED FIXED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium    
Version: 1.10.3   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: fix EPS

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]
  end

However, the EPS generated by Cairo turns this into

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

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:

save
50 dict begin

.....

end
restore
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
/?id=c7ea92907a7eaaf62136755d0b6c60da913d1057

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.