• No results found

The Application Programmer Perspective

In document dtj v02 03 1990 pdf (Page 73-75)

For the application programmer,

XDPS

supplies a library laye::red on top of the protocol . The library provides mechanisms for creating, destroying, and manipulating contexts. The:: l ibrary is re::sponsible for folding extension events into the normal X event stream.

I n addition, a utility, pswrap, allows program­ mers to define C interfaces to arbitrary PostScript language routines. Such an interface is called a wrap. We also provide wraps for all the PostScript operators.

Figure 5 is a simple example of a working applica­ tion using

XOI'S.

The applicat ion opens the display, creates a window, creates a PostScript context, associates the context with the window, executes PostScript code in the context, and manipulates the resulting ourpul.

(Note Figure 5 is a complete working program, not a pseudo-code example. As such, some derails are important to its execution but not to the discus­ sion at hand . Also, the program is an example of several bad progranuning practices: it ignores possi-

Digital Tecbnicaljou•·nal Vi>l. l No. 3 Sll/11111er 1990

ble errors and is not event driven. Again, these details are not relevant to this discussion and are therefore ignored. )

This program builds a simple animation. I t creates 3 6 frames, each o f which contains the string "Display PostScript" in a different size, orientation, and color. Each of these frames is rendered with PostScript operators and saved in a n X pixmap. After all the rendering is complete, the program loops through the 36 frames and copies them to the screen without any delay between frames.

The program begins by opening the display, cre­ ati ng a simple window, and causing t he:: window to appear on the screen. The program then creates a

DPS

context; it does not associate the output with any drawable. Then the program begins the loop to create frames.

Each time through the loop, the program creates a p ixmap and attaches the output of the context to the pixmap, with the user coordinate system origin at the center of the pixmap. The program then chooses and scales the Helvetica-bold font , clears the pixmap to white, sets the drawing color, and paints the text. Finally, when all the frames have been created, the program goes into a tight display loop.

The performance of this example program is not greatly improved by t he combination of

X

Copy Area( ) and PostScript wraps. The same effect could have been ach ieved by writing a simple PostScript program and downloading it into the server. A PostScript program can draw text in

XDPS

relatively quickly. Most notable here is that t he loop that created the frames could have executed any PostScript program - even one read from a file. The final rate of display would be the same no matter which PostScript program were used; only the delay between program execution and the display of the first frame ·vould vary. A programmer work­ ing only with X cou ld not draw rotated text ; and a programmer using

OPS

could not write flip-book­ style animation. The extension combine::s these capabilities so the be-. features of each system can be used.

Summary

It has been said that X is a window system, not a graphics syste::m. The

XDPS

extension for the DEC windows program provides applications with a rich graphical model that can be freely intermixed with the core protocol .

XDPS

provides all the mech­ anisms available in the Display PostScript System, without imposing constraints on their use.

DEC windows Program # i n c l ud e <X 11 I X 1 i b . h > # i n c l ud e <DPS i dp s X c l i e n t . h> # i n c l ude <s t d i o . # d e f i n e S I Z E # d e f i n e S T E P # d e f i n e N S T E P ma i n ( a r g c , a rg v l c h a r • • a r gv ; D i sp l a y W i n d ow D P SC o n t e x t h> 4 0 0 1 0 360 1 S T E P * d p y ; w ; c t x ; I * had b e t t e r d i v i d e 360 even J y l * I

P i xmap maps f N S T E P l , * pMap ,

i n t i j GC g c ; d p y X O p e n D i sp l ay ( " " l ; w ; X C r e a t e S i mp l eW i n d o w ( dpy , R o o t W i n d ow ( d p y , O l , 0 , 0 , S I Z E , S I Z E , 1 , B l a c k P i x e l ( d py , O l , Wh i t eP i x e l ( d py , O l l ; X MapW i n d o w ( d p y , w l ; g c ; De f a u l tG C ( dp y , O l ; X S e t G r a ph i c s E x p o s u r e s ( dp y , g c , F a l s e ) ; c t x ; X D PS C r e a t e S i m p l e C o n t e x t C d py , N U L L , NULL , 0 , 0 , DPSSe t C o n t e x t C c t x l ; f o r ( i ; 0 ; i < N S T E P ; i • + l { pMap ; &maps [ i l ;

NULL , DPSDe f a u l t E r r o r P r o c , NUL L ) ;

* pMap ; X C r e a t e P i x m ap C d py , w , S I Z E , S I Z E , X D e f a u l t De p t h ( d py , O l l P S s e t X g c d r awab l e < X G C o n t e x t F r omGC < g c l , * pMap , S I Z E / 2 , S I Z E / 2 ) ; P S s e l e c t f o n t ( " H e l ve t i ca - Bo l d " , 1 2 . 0 + ( i • 0 . 5 ) ) ; P S e r a s e p ag e < l , P S s e t r g b c o l o r ( 1 . 0 - i * S T E P 1 3 60 . 0 , 0 . , i ' S T E P 1 360 . 0 l ; P S r o t a t e ( ( f l oa t l S T E P • i l ; PSmove t o ( O . O , O . O l ; P S s ho w ( " D i s p l a y Po s t S c r i p t " ) ; DPSWa i t C o n t e x t ( c t x l ; f o r ( i ; 0 ; ; ) { X C o p yA r e a ( d py , map s f i l , w , g c , 0 , 0 , S I Z E , S I Z E , 0 , O J ; i + .. j i 7. : N S TE P ; X F l u s h C d py l ;

Figure

5 A

Simple Program Using Core Graphics Requests

XDPS: A Display PostScript System Extension for DECwindows

Acknowledgments

X D PS is t he result of work by many people. The original protocol definition is the work of Susan Angebranndt, Phil Karlton, and Terry Weissman of Digital, and Ramin Behtash, lvor Durham, and Jim Sandman of Adobe. Perry Caro and joe Pasqua of Adobe have done further work w ith Burns Fisher, Terry Weissman, and the author to nail down the final protocol . All of us at Digital have had a hand in the implementation. Erik Fortune added t he font support we needed to the server.

References

1 . Adobe Systems Inc . , PostScript Language

Reference Manual (Reading: Addison-Wesley

Publishing Company, Inc . , 1985).

2. PostScript Language Extensions for the Display PostScrzpt System (Mountain View, CA: Adobe Systems, Inc . , 1988, 1989).

3. PostScript

Language Color Extensions (Mountain View, CA : Adobe Systems, Inc . , 1988, 1989).

4 .

B. Fisher, Xll Server Extensions Engineering Specification XJJ

R3

edition (Cambridge:

Digital Tecbnicaljournal

Vol.

2 No. 3 Summer 1990

Massachusetts Institute of Technology, 1987). 5. R. Scheitler, ). Gettys, and R. Newman,

X Window System C Library and Protocn/ Reference (Bedford: Digital Press, 1988).

6. R. Ulichney, Digital Ha(ftoning (Cambridge: The

MIT

Press, 1987).

In document dtj v02 03 1990 pdf (Page 73-75)