Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Layers in EPS

Status
Not open for further replies.

stongey

Technical User
May 7, 2004
4
CA
Adobe can preserve layers in EPS files.

Any ideas how I can do this in my code? I thought that using the Lb and LB tags would work (defined as empty functions so a PS interpreter won't trip on them), but I don't get layers in Illustrator.

Suggestions appreciated.


 
What does the term "Layers" mean to you? If you think that Adobe EPS files support, for example, alpha-channel opacity, they don't. PostScript doesn't. PDF files do.

What Illustrator (for example) may do, is write Illustrator "code" into a comment block that only it can read.

How can you support transparency in EPS files? The same way its always been done (and where the dots hit the film, still is): write complicated PostScript to draw the "flattened" optical illusion of transparency.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Thomas:

Thanks for the reply. I do actually mean Illustrator layers, not transparency or alpha channels.

The Lb and LB functions are Illustrator specific functions. Adobe has a way of making them be ignored by a standard PostScript interpreter, while still being valid to an Illustrator parser. I don't quite get how they do it and was looking for some ideas.


Marc
 
I just created an Illustrator file with Layers, and saved as an EPS. I don't see any "LB" or "Lb" procedures.

I'm still unclear what "preserving layers" would mean in the context of an EPS file.

Please give me some more detail. It sounds like you want to create an EPS "by hand" (programmatically) that, when opened in Illustrator, has Layers. Is that more or less correct?



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Yup, that's exactly right.

My employer's software deals with files that are inherently layered in the Illustrator sense of the word (it is map making software). I would like to develop an EPS exporter for standard PostScript exchange output, but many customers also like the ability to preserve separate layers of vector information. While we can write a separate Adobe Illustrator exporter, I noticed that Illustrator can preserve this information in an EPS. So I figured it might be interesting to only have one exporter that does both.

I exported a simple rectangle from Illustrator into EPS (ver 5.0/5.5) that gave this structure for the layer:

%AI5_BeginLayer
1 1 1 1 0 0 0 79 128 255 Lb
(Layer 1) Ln
0 A
300 Ar
0 R
0 0 0 1 K
1 J 1 j 0.96 w 3.85 M []0 d
66 66 m
66 726 l
546 726 l
546 66 l
66 66 l
S
LB
%AI5_EndLayer--

It doesn't work in my handcoded test EPS file, though...

Thanks for the replys, I appreciate your interest.

Marc
 
If it is, you're out of luck. Illustrator will open EPS files, yes... but it just interprets the PostScript in that case, and PostScript doesn't support layers. Nothing you put in an EPS can force Illustrator to create Illustrator features, such as a layer.

How does Illustrator do it, then, with EPS files it creates? By storing binary data in the file. Specifically, a big comment at the end that it calls a "PrivateData" dictionary. It's ASCII-85 encoded binary data.

When Illustrator opens an Illustrator EPS, it totally ignores the PostScript. It jumps right down to the private data, and uses it to create an Illustrator file.

You can even test this! Delete or alter the EPS code (if you know how). Swap it with another EPS file... when you open the altered file in Illustrator, none of your changes will be reflected, since Illustrator completely ignores the EPS code: it doesn't interpret anything except it's own "PrivateData".



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Ah... a much older Illustrator format. That might be interesting. Maybe the AI5 format was more primitive and thus more accesible to this kind of a "hack".

Can you send me a complete Illustrator test file?

My email address is on my website.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Nevermind. I have Illustrator. I've been able to write a file that creates Illustrator layers.

I've also been able to ADD layers to an existing Illustrator 5.0/5.5 EPS.

Currently they are empty layers, though. The next step is to add content. I imagine you'd have to use Illustrator's redefined operators.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Ok, this turns out to be fairly straightforward.

The trick is to use Illustrator's prolouge and definitions.

In other words, don't create "empty" LB and Lb etc procedures, but use Adobe's.

Lb begins a layer. LB ends a layer. Lb expects 6 numbers, all of which are eventually thrown away. One of them however, toggles (I think) text vs. path. It's 0 or 1. Step through the "6 1 roll" to see which number it us. The rest can be dummy numbers for what we need.

You can put your own PostScript code in the layer, just make sure to use Illustrator's redefined operators instead of the "real" operators. "m" instead of "moveto", "c" instead of "curveto", etc.

So code to add a rectangle in a new "3rd layer" in an existing two layer Illustrator EPS might be:

Code:
%AI5_BeginLayer
1 1 1 1 0 0 0 255 255 255 Lb
(Layer 3) Ln
123.8193 64.208 m
63.7358 64.208 L
63.7358 103.917 L
123.8193 103.917 L
123.8193 64.208 L
F
LB
%AI5_EndLayer--

This is just quick and dirty, you'd need to do a lot more research in how to do fills vs. strokes, what to do for colors, making sure that the file works as expected both in Illustrator and when interpreted/printed, and so on.

But it can be done! Let me know if you need any more help.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Thanks Thomas.

That's pretty much what I thought, I was just hoping there would be another path...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top