Transcript PostScript

Overview

    

What is PostScript?

Types Language Concepts Control Operators Examples

What is PostScript

 page description language :  PostScript is a programming language optimized for printing graphics and text  It was introduced by Adobe in 1985  The main purpose of PostScript was to provide a convenient language in which to describe images in a device independent manner. This device independence means that the image is described without reference to any specific device features ( e.g.

printer resolution)

Types

 String :  “This is a string” would be written as (This is a string).  Express a string as hexadecimal codes in angle brackets. “ABC” would be expressed as <414243>.  Boolean  Real  Array

Types

 Arrays:  One Dimensional  Object of different types in an array   /arrayName [ 12 (Twelve) True] def /arrayName [ 1 2 4 add] def   /arrayName 10 array Store and Fetch array elements: put, get    /anArray 10 array def anArray 8 (language) put anArray 8 get

Language Concepts

   Variable: /varName value def Path: A path is a collection of (possibly disjoint) line segments and curves arranged on the page.  newpath 144 72 moveto 144 432 linto stroke showpage Dictionary: is a table that associates pairs of objects   System Dictionary : operator , action User Dictionary : /var1Name Value def

Language Concepts

 Procedures:  /inch {72 mul} def  Stack:  Graphic Stack   Operand Stack (c lear, dup, pop, roll, pstack ) Dictionary Stack  Operator: Every command in PostScript is an operator: add, mul, findfont, moveto ...

Programming in PostScript

 Postfix Notation in PostScript : One must first place the operands on stack and then call the operator.

 5+27  5 27 add 8 –7 * 3 8 7 3 mul sub 7 3 mul 8 exch sub

Control Operators

 Conditional:  Comparisons:    Logical Operator:  And , or, not, xor bool { op } if bool {op1} {op2} ifelse

Control Operator

Loops:

  Repeat:  Iteration { loop_body_expression} repeat For:  Loop_counter_init_value increment_value {op} for   { op }loop : end with “exit” AnArray {op} forall

/Times-Italic findfont 30 scalefont setfont /printZip { 0 0 moveto (Zip) show} def 320 400 translate .95 -.05 0 % start incr. end {setgray printZip -1 .5 translate } for 1 setgray printZip showpage

/starside { 72 0 lineto currentpoint translate -144 rotate } def /star { moveto currentpoint translate 4 {starside} repeat closepath gsave .5 setgray fill grestore stroke } def 200 200 star %add line to path %move origin %rotate coord. sys.

%stack: x y

Refrences

 http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF

 http://www.tailrecursive.org/postscript/postscript.html