PostScript

A general Adobe Illustrator file - extension .ai - has three parts: a so-called h2, more or less lines of postscript, which describe the illustration, and a footer.

schematic structure of a postscript file
schematic structure of a postscript file

The h2 contains some information about the version, title, creator and so forth.
In this example, I use a h2, which indicates that the postscript file is suitable for Adobe Illustrator version 3.0. More recent versions demand much more lines of postscript, and Adobe Illustrator version 3.0 is good enough for this project.

The header

%!PS-Adobe-3.0
%%Creator:Adobe Illustrator(TM) 3.2
%%For: drububu.com
%%Title: h2
%%CreationDate: () ()
%%BoundingBox: -200 -200 200 200
%%DocumentProcessColors:
%%DocumentNeededResources: procset Adobe_packedarray 2.0 0
%%+ procset Adobe_cshow 1.1 0
%%+ procset Adobe_customcolor 1.0 0
%%+ procset Adobe_IllustratorA_AI3 1.0 1
%AI3_ColorUsage: Color
%%TemplateBox: -200 -200 200 200
%%TileBox: -200 -200 200 200
%AI3_DocumentPreview: None
%%PageOrigin:300 300
%%AI3_PaperRect:-12 730 583 -12
%%AI3_Margin:12 -12 -12 12
%AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9
%AI9_Flatten: 1
%%EndComments
%%BeginProlog
%%IncludeResource: procset Adobe_packedarray 2.0 0
Adobe_packedarray /initialize get exec
%%IncludeResource: procset Adobe_cshow 1.1 0
%%IncludeResource: procset Adobe_customcolor 1.0 0
%%IncludeResource: procset Adobe_IllustratorA_AI3 1.0 1
%%EndProlog
%%BeginSetup
Adobe_cshow /initialize get exec
Adobe_customcolor /initialize get exec
Adobe_IllustratorA_AI3 /initialize get exec
%%EndSetup
%%PageTrailer
gsave annotatepage grestore showpage
%%Trailer
Adobe_IllustratorA_AI3 /terminate get exec
Adobe_customcolor /terminate get exec
Adobe_cshow /terminate get exec
Adobe_packedarray /terminate get exec
%%%EOF

The postscript between the h2 and the footer describes the illustration.
Depending on the complexity of the illustration, the amount of lines in this part varies.

Bézier Curves

Images made in Adobe Illustrator are built on Bézier curves. A Bézier curve is the basic element in Adobe Illustrator, similar to what the pixel is in bitmap images.

A Bézier curve is described by a relatively simple mathematical formula, developed by the Pierre Bézier in the 1960's.
The Bézier curve is frequently used in computer graphics applications like Adobe Illustrator, Freehand, Maxxon's Cinema 4D, etc.

A Bézier curve consists of a starting point and an end point, also referred to as anchor points, and one or two control points, also referred to as handles, tangent points or nodes. The control points determine the curvature of the Bézier curve (see left image).

two flavors of bezier curves; quadratic bezier curves and cubic bezier curves
Two flavors of Bezier curves; quadratic Bezier curves and cubic Bezier curves

Within Adobe Illustrator, there are three possible types of Bézier Curves.
The first type is not a real Bézier curve but a straight line: it only has a starting point and an end point. The second and third types are curves with either one or two control points. A Bézier curve with only one control point is referred to as a quadratic bézier curve, whereas a Bézier curve with two control points is referred to as a cubic bézier curve (see right image).

Positions and Control Points

A Bézier curve is described by a series of numbers followed by a limited amount of characters (depending on the presence of control points).

A Bézier curve starts with two numbers followed by the character 'm' (for MoveTo).
The first number is the horizontal position (x), the second number the vertical position (y).


 41.106 41.422 m

Within Adobe Illustrator, a starting point or end point may be linked to another Bézier curve:
the end point of a Bézier curve is then the starting point of an adjacent Bézier curve. If you modify the control point, you will change the position of both Bézier curves.
If you were to save the starting point and end point of each Bézier curve separately, you would have to move the same position twice. This would make the use of Adobe Illustrator less efficient.

Certain number-character combinations are important; more precisely a combination of numbers followed by the characters c, C, l, L, m, M, v, V, y or Y. The amount of numbers that precedes the character depends on the specific character. Both capitals and lower-case characters are used in a postscript file.
In this tutorial, lower-case characters are used.

The list below includes some number-character combinations that are relevant for the Bézier curves.

First position Second position Third position Fourth position
first position (x y) l    
first position (x y) second position (x y) third position (x y) c
first position (x y) second position (x y) y  
first position (x y) second position (x y) v  


Character Description
m starting point
l end point of the straight line
c cubic Bézier curve (two control points)
y or v quadratic Bézier curve (one control point)

The next image explains the different possibilities.

line, cubic and quadratic bezier curve
Line, cubic and quadratic Bezier curve
Position Code
a -23.89 -40.64 m
b -23.89 -19.30 l
0 1 c -23.93 13.11 36.51 -55.48 45.82 -28.14 c
2 d 57.07 4.86 5.57 27.36 y
3 e -47.43 53.36 -47.43 32.61 v


The lines of postscript you will find in the Adobe Illustrator file:


 -23.89 -40.64 m
 -23.89 -19.30 l
 -23.93 13.11 36.51 -55.48 45.82 -28.14 c
  57.07 4.86 5.57 27.36 y
 -47.43 53.36 -47.43 32.61 v

The four possible Bézier curve options in the above image:

Line/Curve Description
a-b straight line, no control points
b-0-1-c cubic Bézier curve; two control points (0 and 1)
c-2-d quadratic Bézier curve; one control point (2)
d-3-e quadratic Bézier curve; one control point (3)

Shapes can be filled with colors as well, but this is beyond the scope of this tutorial.

Coordinate System

Like Adobe Flash, Adobe Illustrator has a coordinate system, which differs from the commonly used coordinate system.
In the commenly used Cartesian coordinate system, the horizontal x position increases when a point is moving to the right on the x-axis, and the vertical y position increases when a point is moving up to the y-axis (see left image). Inside Adobe Flash, the horizontal x position behaves 'normally'; the more to the right the higher the x value, the more to left the lower the x value.
The vertical y position behaves differently. The y position increases when moved downwards on the y-axis, and decreases when moved upwards on the y-axis (see right image).

the cartesian coordinate system and the coordinate system used by Adobe Illustrator
The Cartesian coordinate system and the coordinate system used by Adobe Illustrator

Basic postscript Examples

The next basic examples show a number of vector graphics and the postscript involved.

simple mathematical shape in postscript
Simple mathematical shape in postscript
%!PS-Adobe-3.0
%%Creator:Adobe Illustrator(TM) 3.2
%%For: drububu.com
%%Title: simple mathematical shape
%%CreationDate: () ()
%%BoundingBox: -200 -200 200 200
%%DocumentProcessColors:
%%DocumentNeededResources: procset Adobe_packedarray 2.0 0
%%+ procset Adobe_cshow 1.1 0
%%+ procset Adobe_customcolor 1.0 0
%%+ procset Adobe_IllustratorA_AI3 1.0 1
%AI3_ColorUsage: Color
%%TemplateBox: -200 -200 200 200
%%TileBox: -200 -200 200 200
%AI3_DocumentPreview: None
%%PageOrigin:300 300
%%AI3_PaperRect:-12 730 583 -12
%%AI3_Margin:12 -12 -12 12
%AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9
%AI9_Flatten: 1
%%EndComments
%%BeginProlog
%%IncludeResource: procset Adobe_packedarray 2.0 0
Adobe_packedarray /initialize get exec
%%IncludeResource: procset Adobe_cshow 1.1 0
%%IncludeResource: procset Adobe_customcolor 1.0 0
%%IncludeResource: procset Adobe_IllustratorA_AI3 1.0 1
%%EndProlog
%%BeginSetup
Adobe_cshow /initialize get exec
Adobe_customcolor /initialize get exec
Adobe_IllustratorA_AI3 /initialize get exec
%%EndSetup
0 A
0 R
0 0 0 1 K
0 J 0 j 2 w 4 M []0 d
240.0806 434.3184 m
254.5059 423.0063 L
251.9224 404.8584 L
234.9136 398.0195 L
220.4902 409.332 L
223.0732 427.4829 L
240.0806 434.3184 L
s
%%PageTrailer
gsave annotatepage grestore showpage
%%Trailer
Adobe_IllustratorA_AI3 /terminate get exec
Adobe_customcolor /terminate get exec
Adobe_cshow /terminate get exec
Adobe_packedarray /terminate get exec
%%%EOF
outline number eight in postscript
Outline number eight in postscript
%!PS-Adobe-3.0
%%Creator:Adobe Illustrator(TM) 3.2
%%For: drububu.com
%%Title: outline number eight
%%CreationDate: () ()
%%BoundingBox: -200 -200 200 200
%%DocumentProcessColors:
%%DocumentNeededResources: procset Adobe_packedarray 2.0 0
%%+ procset Adobe_cshow 1.1 0
%%+ procset Adobe_customcolor 1.0 0
%%+ procset Adobe_IllustratorA_AI3 1.0 1
%AI3_ColorUsage: Color
%%TemplateBox: -200 -200 200 200
%%TileBox: -200 -200 200 200
%AI3_DocumentPreview: None
%%PageOrigin:300 300
%%AI3_PaperRect:-12 730 583 -12
%%AI3_Margin:12 -12 -12 12
%AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9
%AI9_Flatten: 1
%%EndComments
%%BeginProlog
%%IncludeResource: procset Adobe_packedarray 2.0 0
Adobe_packedarray /initialize get exec
%%IncludeResource: procset Adobe_cshow 1.1 0
%%IncludeResource: procset Adobe_customcolor 1.0 0
%%IncludeResource: procset Adobe_IllustratorA_AI3 1.0 1
%%EndProlog
%%BeginSetup
Adobe_cshow /initialize get exec
Adobe_customcolor /initialize get exec
Adobe_IllustratorA_AI3 /initialize get exec
%%EndSetup
0 A
u
*u
0 R
0 0 0 1 K
0 J 0 j 1.5 w 4 M []0 d
148.1401 396.5576 m
148.1401 396.6499 L
145.0381 397.3896 143.3242 400.123 143.3242 403.2261 c
143.3242 409.6167 149.8999 412.1182 155.3198 412.1182 c
160.8311 412.1182 167.1753 409.6167 167.1753 403.1792 c
167.1753 400.2617 165.3696 397.2979 162.4063 396.6499 c
162.4063 396.5576 L
166.1104 395.8159 168.4722 392.9902 168.4722 388.916 c
168.4722 381.7822 161.6641 379.0049 155.2729 379.0049 c
148.9277 379.0049 141.9355 381.3652 141.9355 388.916 c
141.9355 392.666 144.4365 395.9082 148.1401 396.5576 c
s
1 D
149.8081 389.332 m
149.8081 386.1387 152.4482 384.793 155.2266 384.793 c
157.9126 384.793 160.5996 386.0439 160.5996 389.332 c
160.5996 392.2959 158.2383 393.9648 155.2729 393.9648 c
152.4482 393.9648 149.8081 392.4805 149.8081 389.332 c
s
150.3179 402.623 m
150.3179 399.7529 152.8184 398.8257 155.2266 398.8257 c
157.5425 398.8257 160.1821 399.8452 160.1821 402.623 c
160.1821 405.2637 157.7739 406.3291 155.2266 406.3291 c
152.6333 406.3291 150.3179 405.3101 150.3179 402.623 c
s
*U
U
%%PageTrailer
gsave annotatepage grestore showpage
%%Trailer
Adobe_IllustratorA_AI3 /terminate get exec
Adobe_customcolor /terminate get exec
Adobe_cshow /terminate get exec
Adobe_packedarray /terminate get exec
%%%EOF
1 2