# EPS

EPS, or Encapsulated PostScript is the programming language designed for the description of the graphical information and bidimensional objects; usually it refers to some pattern (text, pictures) printed on a paper or shown at the screen of the monitor or projector.

The program, written at EPS is called "EPS document". Usually, the file name of such a document finishes with string ".eps" or ".EPS" .

Some commands of the Postscript are specified in the Tutorial [1].

## Structure of the EPS documents

At the head, the EPS document specifies the paper size in the following way:

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 $A$ $B$


where $A$ and $B$ should be substituted to the numbers represented in the standard decimal positional system. The standard paper sizes have names, but in the EPS document, the paper size is specified in points. Usually, the first number $A$ refers to the width of a document, and $B$ refers to its height (for example, at the screen). In the most of cases, the scaling of the resulting image is assumed, so, the units of length do not have their usual sense, as they have in physics.

The EPS document usually contains some drawing, paintings, texts and so on. The special commands are used to describe them.

The EPS document finishes with lines

showpage
%%Trailer


No any text is expected after these lines. Even word %%Trailer happen to be not necessary; it does not affect the view of the image, nor on the conversion into the PDF file.

## EPS commands

The EPS commands are basically the same as in the PostScript; some of them are mentioned below. The EPS command either define some object (used in other commands), or draw some lines, of fill some places with certain colors, or put some texts, or put some paintings.

### Line commands

The basic line commands are moveto, lineto and stroke. The arguments of the moveto and lineto are specified before the command, they should be numbers. The command stroke draws the lines defined previously with moveto and lineto.

In TORI, for the graphics, the EPS file is often written in C++; and the beginning, header of the EPS file is written with the routine ado(FILE*, int, int) stored at ado.cin . In that header, the short abbreviations are defined for commands moveto, lineto and stroke, namely,

/M {moveto} bind def
/L {lineto} bind def
/S {stroke} bind def


After such definitions, letter "M" (separated with spacebars or carriage returns) does the same as moveto. In the similar way, letter "L" does the same as lineto, and "S" does the same as stroke.

## Roster graphics

The black and white roster graphics in EPS document can be realized with the command image.

Let the roster is stored in the bi-dimensional array $a$ of sizes $M$, $N$. Then, this roster can be placed at the page in the following way:

gsave
$M$ $N$ scale
$M$ $N$ 4 [$M$ 0 0 -$N$ 0 $N$]
<
$a$
>
image
grestore


where $a$ should be represented in the hexagonal form.

Such a code paints the matrix of squares of gray level, specified with values of array $a$. The size of each square is unity. (By default this corresponds to size one pt at the printing or the displaying). The coordinates of the left down corner of the matrix are (0,0). Such a convention allows to reduce the number of parameters at the calling. However, the position and the scale of the resulting matrix can be changed (customized) with commands translate and scale.

The example of the EPS program with the roster graphic is suggested below; its result result is shown at right.

#### Code, Roster case

Example of the EPS roster graphics
Example of the EPS vector graphics

%%BoundingBox: 0 0 322 222

/RGB {setrgbcolor} bind def
/W {setlinewidth} bind def
/M {moveto} bind def
/L {lineto} bind def
/S {stroke} bind def
1 1 translate
10 10 scale
gsave
32 22 scale
32 22 4 [32 0 0 -22 0 22]
<
fffffffffffd73100137dfffffffffff
fffffffffe500000000005efffffffff
ffffffffc20026acca62002cffffffff
fffffffc1018effffffe8101cfffffff
ffffffe202cffffffffffc202effffff
ffffff501cffffffffffffc105ffffff
fffffd008ffffffffffffff800dfffff
fffff702effffffffffffffe207fffff
fffff306ffffffffffffffff603fffff
fffff10affffffffffffffffa01fffff
ffffe00cffffffffffffffffc00effff
ffffe00cffffffffffffffffc00effff
fffff10affffffffffffffffa01fffff
fffff306ffffffffffffffff603fffff
fffff702effffffffffffffe207fffff
fffffd008ffffffffffffff800dfffff
ffffff501cffffffffffffc105ffffff
ffffffe202cffffffffffc202effffff
fffffffc1018effffffe8101cfffffff
ffffffffc20026acca62002cffffffff
fffffffffe500000000005efffffffff
fffffffffffd73100137dfffffffffff
>
image
grestore
16.000 -1.000 M
16.000 23.000 L
-1.000 11.000 M
33.000 11.000 L
1 0 0 RGB .3 W S
showpage


%%Trailer

The empty lines and the spacebar at the beginning of lines are introduced to improve the formatting at TORI and simplify the loading, they do not affect the view and conversion of this file to other formats.

It worth to compare the roster graphics to the vector graphics of a similar picture; such a vector graphics is suggesed at the second figure, produced with the code below.

#### Code, Vector case

%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 322 222
/RGB {setrgbcolor} bind def
/W {setlinewidth} bind def
/M {moveto} bind def
/L {lineto} bind def
/C {closepath} bind def
/S {stroke} bind def
1 1 translate
10 10 scale
16.000 11.000 10 0 360 arc C 2 W S
16.000 -1.000 M
16.000 23.000 L
-1.000 11.000 M
33.000 11.000 L
1 0 0 RGB .3 W S
showpage


The examples shows, that EPS allow to combine both, roster and vector graphics at the same page. However, for the addition of formulas, the more suitable is to combine various EPS pictures in the latex document.

While the EPS graphics are not supported at TORI, both examples above are converted to the JPG format. For this reason, at the strong zooming-in, the "vector" graphics also shows some defects of the circuar shape of the ring painted. However, the original eps documents above, being displayed, show no defects, even at very strong zooming-in. The same refers to the PDF versions of the files, made of these EPS.

## Text commands

In principle, any text can be defined using the EPS syntax. However, the programming and debugging of such document may be boring. For this reason, in TORI, the labels at the pictures are drawn using the latex language.

However, few graphical commands are still useful.

The string

/times-Roman findfont $p$ scalefont setfont


determines the Roman font of size $p$ for the placing text in the resulting picture. as usually, the default unit of length is pt.

The text can be placed with command

$x$ $y$ moveto ($s$) show


where $x$ and $y$ are coordinates of the left down cornet of the text, and $s$ is the ascii string.

Some extensions allow to put also the non–ascii characters, but the result depends on the implementation of the EPS interpreter. Especially difficult is representation of the Russian characters. During the USSR, the soviet veterans used to suppress various branches of science; in particular, they fought against cybernetics. (The official Soviet doctrine qualified the Cybernetics as pseudo-science; then, the prohibition of the Russian characters in computers was used to fight the computer–supported samizdat.) As the result, no unique system for encoding of the Russian characters (analogy of the English ascii) has been established, and the Russian texts prepared at some computer may be, by default, unreadable on another computer; in many cases, the special recoding is necessary [2]. For this reason, the English is strongly recommended for any strings introduced from PostSctipt. The complicated strings should be added with latex.

## Gallery

The EPS format is efficient tool for Reproduction of some famous paintings; in particular, those by Kazimir Malevic. Three examples are suggested below.

$~$ $~$ $~$

## References

1. http://paulbourke.net/dataformats/postscript/ Paul Bourke. PostScript Tutorial. (1990 - 1998)
2. http://www.rcom.ru/new/coders.htm Существующие кодировки русских букв. In Russian, cited for the state for year 2011: .. русскому языку не повезло - существует множество используемых в настоящее время различных кодовых таблиц для русских символов:. .. Существуют программы, которые сами пытаются подобрать вариант последовательного перекодирования, автоматически анализирую степень читабельности полученного сообщения. Но это у них не всегда получается.