Precision Graphics Markup Language
PGML is Adobe's expansion of the PostScript/PDF format. Put very simply, PGML translates PostScript commands into XML elements and attributes.
| Many people are aware that PostScript is a page description language-a formal description of the layout of ink on a page. When you print a PostScript document, you send a series of PostScript commands in which your data is embedded to a dedicated processor in the printer. The processor then interprets and executes the commands. |
To demonstrate, Listing 21.7 shows the PostScript code taken from a small test file that prints out the characters in a font in various sizes. The resulting display is shown in Figure 21.5.
|
Listing 21.7 A Typical PostScript File
|
1: % Check for command line parameters:
2: % Name, FirstSize, Ratio, NumSizes, UseOutline.
3:
4: /FontName where { pop } { /FontName (Palatino-Italic) def } ifelse
5: /FirstSize where { pop } { /FirstSize 15 def } ifelse
6: /Ratio where { pop } { /Ratio 1.6 def } ifelse
7: /NumSizes where { pop } { /NumSizes 3 def } ifelse
8: /UseOutline where { pop } { /UseOutline false def } ifelse
9:
10: /Strings FirstSize 20 gt
11: { [
12: (ABCDEFGHIJ) (KLMNOPQR) (STUVWXYZ)
13: (abcdefghijklm) (nopqrstuvwxyz)
14: (0123456789<=>) (:;?@ !"#$%&')
15: (\(\)*+,-./[\\]^_) ('{|}~)
16: ] }
17: { [
18: (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
19: (abcdefghijklmnopqrstuvwxyz)
20: (0123456789<=>:;?@ !"#$%&')
21: (\(\)*+,-./ [\\]^_ '{|}~)
22: ] }
23: ifelse def
24:
25: /sshow
26: { gsave UseOutline
27: { { gsave ( ) dup 0 4 -1 roll put
28: false charpath pathbbox 0 setlinewidth stroke grestore
29: pop 8 add currentpoint exch pop moveto pop
30: } forall
31: }
32: { 2 0 3 -1 roll ashow }
33: ifelse grestore
34: } def
35:
36: FontName findfont FirstSize scalefont setfont
37:
38: clippath pathbbox /top exch def pop pop pop newpath
39: 10 10 moveto
40: NumSizes
41: { gsave nulldevice (Q) false charpath pathbbox grestore
42: exch pop exch sub exch pop 1.25 mul /height exch def
43: Strings
44: { currentpoint exch pop top height 3 mul sub gt
45: { showpage 10 10 height sub moveto
46: }
47: if
48: dup sshow
49: UseOutline not
50: { 0 height rmoveto gsave 0.01 rotate sshow grestore }
51: if
52: 0 height rmoveto
53: } forall
54: Ratio dup scale
55: } repeat
56: showpage
Figure 21.5 The PostScript code from Listing 21.7 looks like this when displayed as an Adobe Acrobat (PDF) File.
| As you can see from Listing 21.7, there are quite clearly commands being sent. Indeed, although Adobe's PDF format is a binary format, if you filter out the binary codes you can still detect some of the remnants of the original PostScript commands, as shown in Listing 21.8. |
|
Listing 21.8 A Fragment of PostScript File of Listing 21.7 After Conversion into Adobe Acrobat (PDF) Format
|
1: << 2: /ProcSet [/PDF /Text ] 3: /Font << 4: /F2 4 0 R 5: >> 6: /ExtGState << 7: /GS1 5 0 R 8: >> 9: >>10: endobj 11: 7 0 obj 12: << 13: /Type /Halftone 14: /HalftoneType 1 15: /HalftoneName (Default) 16: /Frequency 60 17: /Angle 45 18: /SpotFunction /Round 19: >> 20: endobj 21: 5 0 obj 22: << 23: /Type /ExtGState 24: /SA false 25: /OP false 26: /HT /Default 27: >> 28: endobj 29: 8 0 obj 30: << 31: /Type /FontDescriptor 32: /Ascent 733 33: /CapHeight 692 34: /Descent -276 35: /Flags 98 36: /FontBBox [-170 -276 1010 918] 37: /FontName /Palatino-Italic 38: /ItalicAngle -10 39: /StemV 84 40: /XHeight 482 41: >> 42: endobj
I won't go into the technical details of PostScript here, but it's enough to say that it uses a very few basic commands consisting of path instructions (such as moveto, lineto, and curveto) and attributes (such as height, linewidth, and rgbcolor). These instructions are actually quite simple to translate into XML elements and attributes. Listing 21.9 shows a very simple PGML file.
|
Listing 21.9 A Sample PGML File
|
1: <?XML version="1.0"?> 2: <!DOCTYPE PGML SYSTEM "pgml1.0.dtd"> 3: <pgml boundingbox="0 0 300 300"> 4: <path fill="1" fillcolor="100 0 0"> 5: <moveto x="100" y="100"/> 6: <lineto x="150"/> 7: <lineto y="150"/> 8: <lineto x="100"/> 9: <lineto y="100"/> 10: </path> 11: </pgml>
| The PGML code shown in Listing 21.9 produces a small, solid red box: boundingbox declares the x and y coordinates of the area in which the drawing will be done (0,0-the bottom left-hand corner, to 300,300). The fillcolor instructions sets the Red, Green, and Blue color values (100,0,0) of the color that will be used to fill the object, and moveto sets the starting point to (100,100). Finally, the four lineto instructions draw the sides; the corners are at (100,100), (150,100), (150,150), and (100,150). |
Adobe has been extremely adventurous and, as an outsider, I'd say that they'd decided that if they were going to do it all then they decided they were going to do it right. PSGML doesn't stop with just converting PostScript into XML; it takes the development several exciting steps further. It allows you to:
- • Name objects and groups of objects so that they can easily be found by software for applying links or searching
- • Embed XML links inside objects
- • Embed scripting into the PSGML file so a browser will behave just as if the scripting commands had been placed in the enveloping HTML file
- • Embed event handling (based on the Document Object Model that you learned about on Day 16, "Programming with the Document Object Model") to enable interaction and animation
There are as yet no software packages that support the creation of PGML code, and there is no way to display or use the code once it has been written. Indeed, less than half of the PGML specification has been written. However, every indication is that Adobe takes it very seriously and it cannot be too long before the first packages appear.