Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Reid G.C.Thinking in PostScript.1990.pdf
Скачиваний:
17
Добавлен:
23.08.2013
Размер:
846.44 Кб
Скачать

PERSISTENTLY RESIDENT PROGRAMS

Yet another type of PostScript program is one that makes some persistent definitions that are visible to all subsequent programs. This provides a mechanism for redefining operators, making fonts semipermanent in the interpreter, or defining some procedure definitions once in such a way that they are usable to all subsequent programs.

On most printer implementations, this can be accomplished using the exitserver operator. This operator permits the program to exit the job server loop’s save/restore context, causing any definitions made to stay resident until the printer is rebooted. Example 4.6 shows the use of exitserver, in this case to make a font definition semipermanent.

Example 4.6: Sample Printer-Resident Program

%!PS-Adobe-2.0 ExitServer %%EndComments %%BeginExitServer: 0

serverdict begin 0 exitserver %%EndExitServer

%%BeginFont: UserFont 13 dict begin

/FontName /UserFont def /FontType 3 def /FontMatrix [ .001 0 0 .001 0 0 ] def /FontBoundingBox [ 0 0 1000 1000 ] def /Encoding /StandardEncoding load def

/BuildChar % fontdict charcode BuildChar - { %def

exch begin

Encoding exch get 500 0 setcharwidth CharDefs exch get exec

end } bind def

/CharDefs 256 dict def CharDefs begin Encoding { %forall

{ %def

4 { rand 1000 mod } repeat moveto lineto stroke

}def

}bind forall

end

currentdict end dup /FontName get exch definefont pop %%EndFont

%%EOF

46

Chapter 4: SOME TYPICAL PROGRAMS

In window system environments, the concept of a job server loop is often not present, since a windowed environment is usually not a batch system. With the Display PostScript System, there is a dictionary called shareddict, in which all entries are shared by all processes (and hence visible to all). Example 4.7 shows the same font definition made permanent or public in Display PostScript. Notice the use of the currentshared and setshared operators.

Example 4.7: Sample Display-Server-Resident Program

%!PS-Adobe-2.0 ExitServer %%EndComments %%BeginExitServer: 0

dup 0 eq { pop } if true setshared %%EndExitServer %%BeginFont: UserFont

13 dict begin

/FontName /UserFont def /FontType 3 def /FontMatrix [ .001 0 0 .001 0 0 ] def /FontBoundingBox [ 0 0 1000 1000 ] def /Encoding /StandardEncoding load def

/BuildChar % fontdict charcode BuildChar - { %def

exch begin

Encoding exch get 500 0 setcharwidth

CharDefs exch get exec

end } bind def

/CharDefs 256 dict def CharDefs begin Encoding { %forall

{ %def

4 { rand 1000 mod } repeat moveto lineto stroke

}def

}bind forall

end

currentdict end dup /FontName get exch definefont pop %%EndFont

%%EOF

Chapter 4: SOME TYPICAL PROGRAMS

47

TIP

 

The exitserver operator is not a standard part of the language. It is de-

 

 

fined in most printers, but is usually not implemented in display servers or

 

 

stand-alone interpreters. In general, use of exitserver is restricted to sys-

 

 

tem administrators. It should never be part of the output of a program, nor

 

 

should it be used routinely in any program.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 4.4: Shared Memory Configuration

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

shared virtual memory

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

shareddict

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

private

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

virtual

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

memory

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

process 1

 

 

 

 

 

 

 

 

 

 

 

 

 

process 3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

private

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

process 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

virtual

 

 

 

 

 

 

 

 

private

 

 

 

private

 

 

memory

 

 

 

 

 

 

 

 

 

 

 

stacks

 

 

 

stacks

 

 

 

 

 

 

 

 

 

 

 

 

 

private

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

private

 

virtual

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

memory

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

stacks

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 4.4 provides an illustration of the concept of shared virtual memory (often referred to as VM).

48

Chapter 4: SOME TYPICAL PROGRAMS