Taking Advantage of PostScript. John F. Sherman

Similar documents
Lecture 6: Coding theory

Factorising FACTORISING.

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Surds and Indices. Surds and Indices. Curriculum Ready ACMNA: 233,

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

CS 491G Combinatorial Optimization Lecture Notes

18.06 Problem Set 4 Due Wednesday, Oct. 11, 2006 at 4:00 p.m. in 2-106

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

2.4 Theoretical Foundations

I 3 2 = I I 4 = 2A

Numbers and indices. 1.1 Fractions. GCSE C Example 1. Handy hint. Key point

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

Lecture 2: Cayley Graphs

for all x in [a,b], then the area of the region bounded by the graphs of f and g and the vertical lines x = a and x = b is b [ ( ) ( )] A= f x g x dx

CARLETON UNIVERSITY. 1.0 Problems and Most Solutions, Sect B, 2005

GM1 Consolidation Worksheet

THE PYTHAGOREAN THEOREM

2.4 Linear Inequalities and Interval Notation

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

SIMPLE NONLINEAR GRAPHS

CS 573 Automata Theory and Formal Languages

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

PYTHAGORAS THEOREM WHAT S IN CHAPTER 1? IN THIS CHAPTER YOU WILL:

Let s divide up the interval [ ab, ] into n subintervals with the same length, so we have

Now we must transform the original model so we can use the new parameters. = S max. Recruits

Section 2.1 Special Right Triangles

Lesson 2: The Pythagorean Theorem and Similar Triangles. A Brief Review of the Pythagorean Theorem.

Equivalent fractions have the same value but they have different denominators. This means they have been divided into a different number of parts.

Total score: /100 points

Area and Perimeter. Area and Perimeter. Solutions. Curriculum Ready.

Probability The Language of Chance P(A) Mathletics Instant Workbooks. Copyright

Algorithm Design and Analysis

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

MCH T 111 Handout Triangle Review Page 1 of 3

Chapter 8 Roots and Radicals

Finite State Automata and Determinisation

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

6.5 Improper integrals

Nondeterministic Finite Automata

Momentum and Energy Review

CS 360 Exam 2 Fall 2014 Name

Improper Integrals. The First Fundamental Theorem of Calculus, as we ve discussed in class, goes as follows:

Spacetime and the Quantum World Questions Fall 2010

Grade 6. Mathematics. Student Booklet SPRING 2008 RELEASED ASSESSMENT QUESTIONS. Assessment of Reading,Writing and Mathematics, Junior Division

NON-DETERMINISTIC FSA

H SERIES. Algebra Basics. Algebra Basics. Solutions. Curriculum Ready.

Exam Review. John Knight Electronics Department, Carleton University March 2, 2009 ELEC 2607 A MIDTERM

WORKSHOP 7 PARASOLID SOLID EXAMPLE

Lesson 2.1 Inductive Reasoning

Lesson 2.1 Inductive Reasoning

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

4.5 THE FUNDAMENTAL THEOREM OF CALCULUS

Outline Data Structures and Algorithms. Data compression. Data compression. Lossy vs. Lossless. Data Compression

System Validation (IN4387) November 2, 2012, 14:00-17:00

] dx (3) = [15x] 2 0

Algorithm Design and Analysis

Basic Derivative Properties

Comparing the Pre-image and Image of a Dilation

Activities. 4.1 Pythagoras' Theorem 4.2 Spirals 4.3 Clinometers 4.4 Radar 4.5 Posting Parcels 4.6 Interlocking Pipes 4.7 Sine Rule Notes and Solutions

Eigenvectors and Eigenvalues

Proportions: A ratio is the quotient of two numbers. For example, 2 3

Automata and Regular Languages

INTRODUCTION TO AUTOMATA THEORY

Welcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz

Trigonometry Revision Sheet Q5 of Paper 2

Part I: Study the theorem statement.

Introduction to Olympiad Inequalities

CSC2542 State-Space Planning

For a, b, c, d positive if a b and. ac bd. Reciprocal relations for a and b positive. If a > b then a ab > b. then

Lecture 4: Graph Theory and the Four-Color Theorem

ILLUSTRATING THE EXTENSION OF A SPECIAL PROPERTY OF CUBIC POLYNOMIALS TO NTH DEGREE POLYNOMIALS

The DOACROSS statement

A Primer on Continuous-time Economic Dynamics

D. Harel, Statecharts: A visual formalism for complex systems, Science of Computer Programming 8, 1987, pp

Chapter 4 State-Space Planning

Digital Circuit Engineering

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

Lecture 8: Abstract Algebra

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

Mechanisms A Brief Introduction October, 2014

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

Identifying and Classifying 2-D Shapes

C (6) DOORS TYPICAL, ALL SAME SIZE ENCLOSURE, CUSTOM 6 DOOR REVISION HISTORY ZONE REV DESCRIPTION DATE APPROVED 0.01 RELEASE FOR QUOTE 11/16/12 PH

Logarithms LOGARITHMS.

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

5.3 The Fundamental Theorem of Calculus

Particle Physics. Michaelmas Term 2011 Prof Mark Thomson. Handout 3 : Interaction by Particle Exchange and QED. Recap

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Digital Circuit Engineering

INTEGRATION. 1 Integrals of Complex Valued functions of a REAL variable

Pythagoras Theorem. Pythagoras Theorem. Curriculum Ready ACMMG: 222, 245.

Linear Algebra Introduction

Proving the Pythagorean Theorem

Necessary and sucient conditions for some two. Abstract. Further we show that the necessary conditions for the existence of an OD(44 s 1 s 2 )

6. Suppose lim = constant> 0. Which of the following does not hold?

Typesetting Karnaugh Maps with L A TEX and TikZ

Transcription:

Tking Avntge of PostSript John F. Shermn

Tking Avntge of PostSript John F. Shermn University of Notre Dme Art, Art History & Design University of Notre Dme Notre Dme, IN 46556 5639 FRPEXX@IRISHMVS..n.eu

1 hpter Chpter 1 intro Designers fe new requirement: to quire n mster igitl rft. The tritionl rfts of olor theory, esign, typogrphy n rwing hve lwys een require for the esigner. All of these re importnt n I o not vote their ismissl. But the nee for igitl rft is eoming more pprent s the innovtions of tehnology rrive fster n fster. Designers, however, nnot fous on simply eing well-trine users of expensive piees of hrwre n softwre. By mstering the tehnology, they n reh point where innovtive new solutions to visul ommunition prolems n e isovere. The proess y whih n imge n e me hs hnge rmtilly. An imge n e onstrute y omintion of hn rwings, vieo pture, n omputer progrmming. The finishe imge provies solution y mens of fster investigtion, greter hoies, n new retive possiilities. Digitl rft entils lerning new lnguge visul lnguge. The greter the epth of unerstning n experiene in lnguge, the greter the vision of wht n exist in the min of the retor. Different lnguges llow ifferent relities to exist. Mny of the imges rete for this ook re visul ies tht hve een me into imges y writing them own. They n only e hieve y n intimte knowlege of the PostSript lnguge. I fin it exiting tht there re imges tht n only e rete y writing PostSript progrm. Unerstning PostSript is one mjor venue to mstering the tehnology of prouing grphis. 1.1 why lern PostSript? Why lern PostSript when there re so mny goo grphis progrms ville tht re muh esier to use thn progrmming? There re two nswers. First, knowing the PostSript Pge Desription Lnguge (PDL) gives the esigner n insight into grphis softwre se on the PostSript imge moe. The PostSript PDL hs strengths n weknesses. Hving this knowlege se uils onfiene euse it permits you to work with the strengths of softwre n not with flse expettions. When something oes not work s expete, you my e le to evise wy to work roun or ttk the prolem from nother iretion. Seon, the PostSript lnguge is riher grphis lnguge thn wht is me ville y menu seletions n ilog oxes in ll the grphis softwre pkges ville. There re visul opportunities ville to you tht re only ville y progrmming. A esign you write in PostSript might supplement pkge tehnique in softwre progrm or e written totlly in PostSript oe. intro 1

Tking Avntge of PostSript Either wy, you re in ontrol of the esign proess. 1.2 PostSript s kgroun PostSript is pge esription lnguge evelope y Aoe Systems Inorporte. PostSript resies within printer n ts s n interpreter for the t sent to it y either softwre progrm or n originl progrm written y progrmmer. A pge esription lnguge is the mens through whih printer prepres pge ontining text, line rt, n igitize imges. The pge is onstrute pixel y pixel (ot y ot). The size of ot will epen on the printer, n rnges from 300 to 2540 ots per inh (pi). A 300 pi printer will rw 1 inh squre 300 ots to sie, while 2540 pi printer will rw the squre 2540 ots per sie. Figures 1 1 n 1 2 re the sme shpe; they hve the sme esription. The otte line is the true shpe. Wht will e ifferent is the qulity of its presenttion through either printing or monitor s isply. The greter the resolution provie, the loser to the true esription the shpe will pper. figure 1 1 Figure 1 2 is the sme shpe with oule the resolution. figure 1 2 The most wiely known exmple of 300 pi printer is the Apple LserWriter. The Linotron L100 hs mximum resolution of 1270 pi n n e set to print t 600 n 300 pi. The Linotron L300 is lso ville with mximum printing resolution of 2540 pi. The vntge of using the inrese resolutions of these printers is tht greter numer of visully istint grys n e proue. The Linotron L100 n proue out one hunre visully seprte gry levels euse of its fine ot pttern. 2 intro

Chpter 1 The PostSript lnguge is printer inepenent, enling you to lternte from one rn of printer to nother without mking ny hnges to the originl oument. All the mjor originl equipment mnufturers of high resolution printers hve liense PostSript for their printers mking it the e fto inustry stnr. The esigner n use low ost lser printer for skething n then lter use the more ostly high resolution imgesetters when the esign is omplete. The ifferene in the resolution hnges the renering qulity n the numer of istint grys tht n e epite. Until reently, lser printer equippe with PostSript interpreter ws the only mens to see the esigns rete y writing PostSript progrms. Disply PostSript is n pttion of the PostSript PDL from Aoe Systems In. for use on omputer monitors, n the NeXT omputer is the only omputer tht uses it. Disply PostSript is to the grphi isply of omputer monitors s the PostSript PDL is to ifferent lser printers. It provies ommon imging moel for the grphi isply (sreen esription lnguge) n the lser printer. The Mintosh uses the QuikDrw lnguge for its sreen isply n file s t is onverte from QuikDrw to PostSript for printing. Beuse of this, the full rihness of the PostSript lnguge nnot e use n then viewe on the Mintosh sreen. Disply PostSript is monitor inepenent n utomtilly tkes vntge of the full pilities (gry levels or olor) of the omputer s monitor without hving to rewrite the prt of the softwre responsile for the grphi isply. Disply PostSript hs severl vntges. Most importntly, wht is seen on the sreen very losely mthes wht is printe. The only ifferene is the resolution of the imge on the monitor ompre to the resolution of the imge ultimtely printe on the lser printer. For exmple, in rwing 1 inh squre, the squre woul e rwn with ninety-two pixels per sie (resolution of the NeXT monitor) n the sme informtion woul e use gin n sent to the lser printer to rete the squre t 300 pi or more. 1.3 orgniztion of this ook Tking Avntge of PostSript is ivie into four mjor prts. Chpters 2 7 of this ook will introue some si PostSript onepts n rwing tehniques. Chpter 4 will show how these simple progrms n e sve s EPS files to e use within other progrms. Most of the simple eginning progrms re more esily rwn in vriety of grphis softwre progrms, ut they re the uiling loks to the more omplite progrmming tehniques tht ome in lter hpters. Chpters 8 17 will over vne PostSript tehniques tht unlesh the power of the PostSript Pge Desription Lnguge. Muh of wht is overe here nnot e omplishe in ville grphis softwre. Chpter 17 overs some vne progrmming tehniques n tkes severl esigns step y step n explins how n why they were written s they re. Chpter 18 will touh on some of the new fetures of PostSript Level 2. Chpters 19 n 20 of this ook re lirries of numerous exmples of PostSript progrms tht n e the strting point for new esigns. They generlly onentrte on one visul ie or progrmming tehnique. Chpter 21 is gllery of imges. The finl setion of the ook ontins severl referene ppenixes. intro 3

Tking Avntge of PostSript 1.4 lern PS 1 1 nimtion formts use in this ook The min nrrtive of this ook is in the font you re now reing. All PostSript progrm listings or the mention of PostSript opertor will e set in Courier Bol n look like this: PostSript oe % omment Notes or omments (expline in more etil in setion 2.5) will e set in regulr Courier to help set them off from the progrm. At times, when more lengthy nnottion is require, I ll rket the explntion like this for etter legiility n to sve spe: % -------------------------------------------------------- Extene omments; not prt of the progrm. % -------------------------------------------------------- When you see this symol in the mrgin, it mens tht the PostSript progrm is ville on isk for experimenttion within the ompnion LernPS tutoril. There will e version for oth Mintosh n NeXT omputers. The LernPS symol my lso inite tht the PostSript progrm for n illustrtion is ville or tht n nimtion emonstrting prtiulr point is ville. Use the numer or title elow the symol to help you lote the file in LernPS. Most of the PostSript exmples in this ook re written to pper on gri representing the ottom left orner of pge. A PostSript progrm will e liste elow the grphi it proues. In this wy, it will serve s title for the grphi. Otherwise, grphi title will e foun in the left mrgin. Eh hpter is ivie into setions. We re now in setion 1.4, mening hpter 1 setion 4. Often in this ook I ll refer to other setions using this system. 1.5 getting strte Writing simple originl PostSript progrm is firly esy tsk to omplish. You most likely lrey hve the tools neee if you hve Mintosh omputer n PostSript equippe printer. The progrm file n e written with ny wor proessing progrm tht n sve stnr ASCII text files. An ASCII text file is stnr form of sving text tht ll omputers unerstn. It nnot, however, ontin speilize formtting tht most pplitions provie, suh s vrile point sizes, font styles, or grphis. On the Mintosh you will nee: Softwre to write the progrm. Mirosoft Wor, MWrite, WriteNow n others will work fine. You my fin it onvenient to use text eitor esigne for working only with text files. A utility to sen the file to the PostSript printer. The most ommon is SenPS from Aoe. A PostSript equippe printer, to interpret your files. On the NeXT: The NeXT omputer omes with ll the softwre you ll nee to sen the file to 4 intro

Chpter 1 the printer or monitor. Chpter 2 overs getting strte in more etil. 1.6 options for ownloing files There re quite few utilities to sen or ownlo PostSript file to printer. On the Mintosh I hve use these, ut there re mny others: LserSttus DA from CE Softwre SenPS from Aoe Systems Downloer from Aoe Systems I hve two fvorite wys of working on the Mintosh. One option is to write the file using QUED (QUlity EDitor) from Promp. QUED is text eitor; it only opens n sves files s text. I then sen the PostSript file to the printer with LserSttus. Sine LserSttus is Desk Aessory, I n esily swith k n forth etween eitor n ownloer while eveloping esign. It looks like this elow: The seon metho is gin to use QUED to write the progrm, ut sen the file to the printer using either Aoe s SenPS or Downloer. The primry ifferene etween the two utilities is where the stnr output file is irete. This file my e n error messge or feek from the printer. With SenPS, the error messges n feek re sent to file on your omputer s isk. This is hny sine t times the messge n flsh y quikly or you my nee the informtion tht is sent k. The vntge of Downloer is tht those messges re sent to winow on the Mintosh sreen. The stnr output file will ome up numer times lter in setion 16.1 n the utilities ppenix. You will e le to sen PostSript files to your printer from within LernPS. intro 5

Tking Avntge of PostSript 6 overview of the sis

2 hpter Chpter 2 overview of the sis This setion is esigne to over the key points n terms use in PostSript progrmming. Even if PostSript is your first ttempt t writing omputer progrm, you shoul fin PostSript is not nerly s intimiting to lern s other progrmming lnguges. I elieve the reson for this is tht the gol is to get n imge on pper, whih is muh more interesting thn lulting some interest rte or personnel t se. Plus, the Hello Worl output, the lssi first gol in other progrmming tutorils, n now e in vriety of fonts n ple nywhere on the pge. 2.1 oorinte system The pge is oorinte system se on n x n y xis. The origin, the 0 0, is usully the ottom left orner of the pge. We ll see lter tht this n e hnge t ny time. y xis figure 2 1 0 0 x xis Distne is mesure in points with 72 points equling n inh. Eh squre ove in figure 2 1 represents 36 points. This is silly the sme unit of mesurement use y typesetters n printers in the grphi rts inustry. Tritionlly 72 points equls 0.918 of n inh. In PostSript, however, 72 points equls 1 inh extly. In some situtions this ifferene n use gret el of troule. If it is importnt tht you mth the tritionl mesurement sle, the oorinte overview of the sis 7

Tking Avntge of PostSript system n e hnge so tht 72 points oes equl 0.918 of n inh. This n e one with the sle opertor (see hpter 10). 2.2 the PostSript progrm must e text file The PostSript progrm must e text file, sometimes known s n ASCII file. A text file n e written y lmost every kin of wor proessor. A text file is n gree on stnr formt of sving wors tht ll omputers n ept n unerstn. Beuse it is onvenient mens to exhnge informtion etween vrious omputers, it nnot ontin speilize formtting tht is hnle ifferently from one wor proessing pplition to nother. A text file nnot ontin vrile font styles, point sizes, or ny grphis. It n ontin rrige returns, n ts re t fixe, regulr intervls. If you re using Mirosoft Wor on the Mintosh, text file woul e sve y first hoosing Sve or Sve As... (if lrey sve) from the File menu. Notie the File Formt... utton t the lower left orner. Choose it. A seon ilog ox will pper. Choose the Text Only option n then OK. The file will e sve s text. MWrite n other progrms hve similr options. You my try text eitor tht only sves n works with text files. Their vntge is they usully ome with fetures gere for esier progrmming. 2.3 PostSript is se sensitive The PostSript lnguge is se sensitive. Cse sensitive mens upperse hrters re seen s ifferent thn lowerse hrters. Tht is, wor is seen s ifferent wor thn WORD or Wor. In some other progrmming 8 overview of the sis

Chpter 2 lnguges this is not the se. 2.4 the progrm formt A PostSript progrm n e formtte in ny wy onvenient for legiility using ts, returns, or extr spes etween wors. These re seen s white spe n o not ffet the running of the progrm. For exmple, gsve 100 100 trnslte grestore is the sme s gsve 100 100 trnslte grestore whih is the sme s gsve 100 100 trnslte grestore 2.5 inserting omments Titles n referene omments n e inlue in PostSript progrm y entering them fter the speil hrter % (perent sign). Everything following % n efore the next return or line en is invisile to the PostSript interpreter. The % is lso use for heer informtion (the first lines of progrm) of file tht is written in stnr wy. This will e expline further in hpter 4, EPS Files. The spe etween the oe n the % n either e ts or ny numer of wor spes. It s goo hit to inlue omments in your progrms for future referene. A month from now, you won t rememer why you i wht you i. A few moments of your time now will py off lter when you nee the informtion. Exmples of inserting omments re % move origin one inh gsve 72 72 trnslte grestore The omment n lso e inserte in this wy, gsve % move origin one inh 72 72 trnslte grestore or in this wy gsve 72 72 trnslte % move origin one inh grestore overview of the sis 9

Tking Avntge of PostSript 2.6 the grphi stte Mny of the ommns in PostSript esrie some kin of grphi opertion or hnge in the grphi stte. The grphi stte is the set of givens or the environment grphi is rwn in. For exmple, it woul e sfe to ssume the following: The mesurement system equls 72 points to the inh. The origin is t the lower left orner of the pge. The efult olor is lk. The efult line weight is 1 point. There is no efult font. These re some of the efult vlues tht efine the grphi stte tht you egin with. There is possiility tht previous PostSript progrm my hve hnge ll this, ut normlly these efults re in effet. If you rw 72 point fille squre, it will e fille with lk n e 1 inh squre unless efine otherwise. There re severl more efult vlues to e wre of, ut these re enough to get strte with. The importnt onept here is tht s PostSript progrm is interprete y printer, urrent vlues for numer of things (olor, line weight, et.) n e hnge, n persist until nother hnge. These hnges re hnges in the grphi stte. 2.7 the urrent point & urrent pth Grphis n type re ple on the pge y estlishing urrent point. The urrent point is the urrent position of rwing tion. Estlishing urrent point n e thought of s the initil t of positioning penil on pper to egin rwing. The moveto opertor retes the lotion for hrter or the strting point for the rwing of grphi. This is mesure reltive to the origin or 0 0 (zero zero) of the oorinte system. For exmple, 144 216 moveto estlishes urrent point 2 inhes to the right n 3 inhes up from the lotion of the origin. There is nothing tht will print yet, it is only the strting point or lotion. More on moveto lter in setion 2.9. If line is rwn from this urrent point lote t 144 216, 144 216 moveto 288 288 lineto urrent pth is rete from the point 144 216 to the point 288 288. Agin, nothing will print yet euse it is only pth. The pth will nee to e pinte for something to print. The urrent pth n e pinte s stroke to give it the vlues of the urrent line weight n olor, or the pth my e fille with the urrent olor. As pth is rete, the urrent point is the most reent point on the pth. One 10 overview of the sis

Chpter 2 the pth is pinte, the pth is lere or initilize. These re importnt points to rememer. A typil sequene of events oul e: 1 No urrent point or urrent pth 2 Crete urrent point 3 Crete urrent pth 4 stroke or fill the urrent pth 5 Current pth is lere 2.8 the opern stk PostSript is stk se lnguge. An opern stk is like plte ispenser t feteri. The first plte in is the lst plte out n the lst plte in is first plte out. In PostSript, the stk is n re of memory tht vlues, opertors, n other items re pushe onto. The first item in line of PostSript oe will e the first item on the stk n the lst to e use. For exmple, moveto will nee two numers lrey on the stk. In the se of 144 216 moveto, 144 is on the ottom n 216 is next on top. moveto, the opertor, then omes long on top of the two numers n removes them to go off n mke urrent point. The lines of oe lern PS stk emo 144 216 moveto 288 288 lineto oul e seen entering the stk s in figure 2 2 elow. 216 144 moveto 288 288 lineto figure 2 2 Another wy of looking t 144 216 moveto 288 288 lineto woul e to hrt the stk s it hnges. In figure 2 3, eh white retngle represents the stk s vlues re pushe onto it n remove y opertors. overview of the sis 11

Tking Avntge of PostSript 216 144 moveto 216 144 empty stk 288 288 lineto 288 288 empty stk figure 2 3 The progrm oul lso e written like this: 288 288 144 216 moveto lineto It woul proue the sme results n the hrt woul look like figure 2 4. 216 144 288 moveto 216 144 lineto 288 288 empty stk 288 288 288 figure 2 4 This is not s onvenient wy to write progrm, ut it works. It n e esy to lose trk of whih vlues go with wht opertor. There re numer of PostSript opertors tht help mnipulte the orer of the stk. exh, for exmple, swithes the top two items on the stk. More on this in lter hpters. 2.9 reting urrent point As stte in setion 2.7, moveto is use to rete urrent point n expets two numers on the stk for its x n y lotion on the pge. The syntx for moveto is x y moveto The x n y n e ny two numers, positive or negtive. For exmple, the following n e use: 72 72 moveto 207.45 34.17 moveto -34 17 moveto Lter we ll lern to use vriles so we n write over up moveto x1 y2 moveto 12 overview of the sis

Chpter 2 1 inh 2 inh moveto or even x 12 y 12 moveto The moveto opertor expets to fin two numers witing for it on the stk. How they rrive there is of no onern to it. figure 2 5 The + s in the grphi in figure 2 5 mrk the lotion of the urrent points t 72 72 n 144 288 with 72 72 moveto n 216 288 moveto. A vrition of moveto is rmoveto or reltive moveto. rmoveto is use to mke rek in the urrent pth s it is eing onstrute. An exmple of its use will e foun t the en setion 2.11. 2.10 reting urrent pth To rete urrent pth, moveto is use to mke strting or urrent point. Then one of the PostSript pth onstrution opertors suh s lineto is use to ientify new point extening from tht point. overview of the sis 13

Tking Avntge of PostSript 144 216 288 216 figure 2 6 144 72 288 72 To rw 1 inh squre on the pge, we woul first nee to estlish urrent point n then urrent pth. See figure 2 6. The pth oul strt t 0.5 inh up n over 1 inh from the ottom left orner of the pge n move right 1 inh, up 1 inh, left 1 inh, n k own to the strting point. The pth oul lso e rwn in the lokwise iretion s well. The initil urrent oul hve een ny one of the orners. This esription of the squre is the urrent pth; nothing hs een pinte yet. It is the ro mp for pinting tht omes lter. The lineto opertor retes urrent pth to some new point from n existing urrent point. The new point eomes the new urrent point. The syntx for the lineto opertor is: x y lineto where x n y re oorintes on the pge. Also, lineto requires urrent point from either previous moveto or lineto. The PostSript progrm of our squre up to this point woul look like this: 144 72 moveto 288 72 lineto 288 216 lineto 144 216 lineto 144 72 lineto This PostSript progrm frgment retes urrent pth. If we were to print t this moment, we woul hve lnk pge. The next step of the progrm is to use the pth either to stroke line or s ontiner for fill. It is lso possile to use the pth s ounry or ookie utter for imges to pper within. This is one with lip, n will e expline in setion 9.4. 2.11 pinting the urrent pth One urrent pth hs een onstrute, you hve the hoie of either stroking it or filling it with the urrent olor. The two opertors re stroke n fill. These two opertors pint the urrent pth with the urrent line weight n urrent olor. In ition, the stroke n fill opertors onsume the urrent pth, mening one the pth is pinte, it will no longer exist. Exmples of stroke squre n fille squre with their PostSript progrms follow. 14 overview of the sis

Chpter 2 lern PS 2 1 72 72 moveto 144 72 lineto 144 144 lineto 72 144 lineto 72 72 lineto stroke lern PS 2 2 72 72 moveto 144 72 lineto 144 144 lineto 72 144 lineto 72 72 lineto fill As mentione in setion 1.4, if you wnt to experiment n print these first two progrms, fin exmples 2 1 n 2 2 in the ExmplePS setion of LernPS. Rememer, the reson these exmples look like this is euse the efult vlue for the urrent olor is lk n the urrent line weight is one point. Those vlues will remin until you hnge them. In the next hpter, we ll run this squre through ll sorts of vritions. The urrent pth oes not nee to e one ontinuous onnete pth. In this exmple, rmoveto is use twie to ontinue the pth fter rek. The rrow in the grphi shows the movement of the urrent point with rmoveto. The point of the rrow is lso rwn using rmoveto. 72 0 0 72 144 216 lern PS 2 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:twoLines.eps %%BouningBox:72 34 144 110 overview of the sis 15

Tking Avntge of PostSript 3 setlinewith % prllel lines 72 36 moveto 144 36 lineto -72 72 rmoveto 144 108 lineto % seon line stroke.25 setlinewith % rrow 138 42 moveto -60 60 rlineto 0-6 rmoveto 0 6 rlineto 6 0 rlineto stroke 16 overview of the sis

Chpter 2 overview of the sis 17

Tking Avntge of PostSript 16 rwing squre

Chpter 3 3 hpter rwing squre This hpter overs numer of ifferent methos tht n e use to rw squre. In oing so, vrious strtegies re overe in smll sle tht n e pplie to vriety of progrmming situtions. The PostSript lnguge provies more thn one wy to rete the sme result. The reson to use one over nother will epen on the sitution n your writing style. 3.1 finishing the finl orner of the squre In figure 3 1 elow, the lk line represents the pth for the wie gry line. Notie the line oes not exten eyon the pth. Beuse of this, squre stroke with thik outline woul hve notiele noth t the finl orner. figure 3 1 The preferre wy to write the PostSript progrm for the squre rwn in the lst hpter woul e to inlue the losepth opertor. losepth joins the urrent point on the pth to the first point me y moveto n finishes tht orner. Other exmples of its use will e seen in hpter 6. This exmple pints one squre on top of nother. The lk squre on top uses the losepth opertor to finish the orner t the lotion of the pth s eginning n ening. The PostSript progrm is liste elow. lern PS 3 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:losepth_1.eps %%BouningBox:0 0 84 84.5 setgry 12 setlinewith 6 6 moveto % gry thik line rwing squre 17

Tking Avntge of PostSript 72 0 rlineto 0 72 rlineto -72 0 rlineto 0-72 rlineto stroke % lk squre on top 0 setgry 4 setlinewith 6 6 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth stroke This PostSript progrm introues severl new opertors. First, n explntion of the first three lines lle the progrm heer. These three lines re not neessry to rete the tul grphi, ut they re very importnt if the grphi will e ple in nother oument. This will e expline in more etil in the next hpter on EPS files. The new PostSript opertors introue re: setgry hnges the urrent gry vlue. setlinewith hnges the urrent line weight. rlineto rws line reltive to the previous urrent point. setgry expets numer etween 0 n 1 where 0 is lk, 1 is white, n vrious grys re in etween. Therefore, 0.2 is 80% lk, 0.5 is 50%, n 0.9 is 10% lk. setgry hnges the urrent olor use y stroke n fill for pinting. setlinewith hnges the urrent line weight use y stroke n expets positive numer. It n e 0 n s high s 700 or higher. However, it is not visle to use zero. 0 setlinewith pints the line s fine s the printer is ple of prouing. On 300 pi tht woul e 0.24 inhes, whih n e seen esily. But on 2540 pi Linotron, however, it woul e 0.000393 inhes not visile. rlineto is n lterntive to lineto. lineto rws lines to points on the oorinte system reltive to the origin. rlineto rws its lines reltive to the previous urrent point. We hve two wys to rw the pth for squre. There is 72 72 moveto 144 72 lineto 144 144 lineto 72 144 lineto losepth stroke n 72 72 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth stroke Both of these progrm exmples proue the sme results. Lter, in hpter 18, two new opertors for rwing retngles in PostSript Level 2 will e expline. 18 rwing squre

Chpter 3 3.2 efining proeures A thir wy to rw the squre is to efine it s proeure. One efine, it n e use s often s neee. The efinition for squre oul look like this, /squre { 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth } ef n it oul e use like this 72 72 moveto squre stroke or 144 144 moveto squre fill The / (slsh) speil hrter ientifies the wor squre s nme. The speil hrters { n } ontin the efinition for the nme. The ef opertor ssoites the efinition with the nme. The proeure s nme or key is store in the PostSript interpreter s user itionry while the progrm is run. When PostSript interpreter enounters nme it oes not reognize, the interpreter sees if there is efinition for it in the user itionry. If there is none present, n error messge will e sent. The PostSript interpreter will ssume tht something ws misspelle. There will e more on user itionries in setions 17.1 3. A omplete progrm using the squre proeure n look like this: lern PS 3 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:squre_ef1.eps %%BouningBox:72 72 360 504 /squre { 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth } ef 72 72 moveto squre fill 72 288 moveto squre fill rwing squre 19

Tking Avntge of PostSript 216 144 moveto squre fill 288 432 moveto squre fill 3.3 stroking & filling the sme pth As stte in setion 2.11, the stroke n fill opertors onsume the urrent pth. However, there is wy to use the urrent pth for oth stroke n fill. The urrent pth n e opie to e use twie y sving or y tking snpshot of the grphi stte. The PostSript opertors gsve n grestore sve n restore the grphi stte. The sequene for grphisve n grphirestore woul e: 1 No urrent point or urrent pth 2 Crete urrent pth 3 Sve the urrent pth y sving the grphi stte n mking opy 4 fill the urrent pth 5 Restore the previously sve urrent pth 6 stroke the restore urrent pth 7 Current pth is lere The grphi stte ontins the urrent vlues for the urrent gry, line with, urrent point, urrent pth, lotion of the origin, n numer of other vlues not pplile here. Here s n exmple: 72 0 0 72 144 216 lern PS 3 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:gsve_1.eps %%BouningBox:36 36 144 108 72 36 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth gsve % sve pth, vlue lk 0.5 setgry fill % 50% lk & pth fille grestore % sve pth restore 20 rwing squre

Chpter 3 stroke % restore pth stroke The gsve sves the urrent pth n the efult vlue of lk. Next, 0.5 setgry fill hnges the urrent vlue to 50% lk n the urrent pth is fille with it. grestore restores the urrent gry k to 100% lk n the urrent pth. Finlly, stroke onsumes the sve opy of the urrent pth. The line weight of the stroke is the efult vlue of one point. 3.4 moving the origin The trnslte opertor moves the origin roun on the pge. For exmple, 72 72 trnslte moves the lotion of the origin from the lower left orner of the pge to 1 inh up n over. The vntge of moving the origin is tht it my mke it esier to ple numer of grphi ojets on the pge. In n erlier exmple, /squre ws efine to e: 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth It ws move roun the pge y estlishing urrent point t the esire lotion for the squre, then using the proeure. A seon metho of pling numer of squres on the pge is to hve the urrent point lwys t the origin within the efinition n move the origin roun. For exmple: /squre { 0 0 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill } ef 72 144 trnslte squre PS lern 3 4 Sine hnging the position of the origin is hnging the grphi stte, it will e helpful to rket the hnges with gsve n grestore. There n e some unexpete results if the origin is hnge within progrm. It is importnt to emphsize tht using the trnslte opertor oes not rete urrent point, ut trnsforms the oorinte system tht urrent points re me upon. The erlier exmple from setion 3.2, squre_ef1.eps, n e rewritten two wys to emonstrte the use of trnslte. The first rewrite oes not use gsve n grestore. The lotions of the vrious squres re not immeitely pprent n it gets rther iffiult to visulize where they re euse of the wy the origin is hnging its lotion. %!PS-Aoe-2.0 EPSF-1.2 %%Title:squre_ef2.eps %%BouningBox:72 72 360 504 /squre { 0 0 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill } ef 72 72 trnslte squre % 72 72 from 0 0 = 72 72 0 216 trnslte squre % 0 216 from 72 72 = 72 288 rwing squre 21

Tking Avntge of PostSript 144-144 trnslte squre % 144-144 from 72 288 = -72 144 72 288 trnslte squre % 72 288 from -72 144 = 0 144 The seon version ples the squres t the sme lotion on the pge ut the progrm is written ifferently this time y using gsve n grestore. Beuse of this, it is muh esier to keep trk of the lotion of the squres in this exmple. The lotion of the fourth squre t 288 432 is 288 432 from the lower left orner of the pge n not from n unknown point somewhere else on the pge euse of hnge in the previous line of oe. lern PS 3 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:squre_ef3.eps %%BouningBox:72 72 360 504 /squre { 0 0 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill } ef gsve % sve lotion of origin 72 72 trnslte squre % hnge lotion grestore % restore lotion of origin gsve 72 288 trnslte squre grestore gsve 216 144 trnslte squre grestore gsve 288 432 trnslte squre grestore 22 rwing squre

Chpter 3 Using gsve n grestore s flexiility to the progrm. Chnges to iniviul squres will not ripple throughout the rest of the progrm. Also, iniviul prts of progrm rkete y gsve n grestore n esily e opie n positione into other progrms. In the next exmple, hnges re me to the first n seon squres. The thir squre is stroke with the efult 1 point line weight n the fourth squre is fille with the efult olor lk. PS lern 3 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:squre_ef4.eps %%BouningBox:72 72 360 504 /squre { 0 0 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth } ef gsve % sve grphi stte / urrent olor & origin.5 setgry 72 72 trnslte squre fill grestore % restore grphi stte gsve % sve grphi stte 4 setlinewith 72 288 trnslte squre stroke grestore % restore grphi stte gsve % sves origin, uses efult olor 216 144 trnslte squre stroke grestore gsve 288 432 trnslte squre fill grestore rwing squre 23

Tking Avntge of PostSript 3.5 hnging the size The sle opertor mkes the oorinte system lrger or smller. For exmple, 2 2 sle oules the size of the grphi stte. There will lso e more etile isussion of the sle opertor in hpter 10. If the proeure for squre is efine to e 1x1 unit, sle oul e use to enlrge tht squre to whtever size is require. Note in the following exmple tht the squre is 1x1 n sle is use to rete three sizes of the squre. The iniviul squres re rkete y gsve n grestore so the sling will not multiply from squre to squre. PS lern 3 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:squre+sle_1.eps %%BouningBox:72 72 576 648 /squre { 0 0 moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto losepth } ef gsve.5 setgry 72 72 trnslte 72 72 sle squre fill grestore gsve 288 360 trnslte 288 288 sle squre fill grestore gsve.3 setgry 72 432 trnslte 24 rwing squre

Chpter 3 144 144 sle squre fill grestore The sequene of the PostSript opertors is very importnt. If you re not reful, you n get yourself some unexpete results. It n mke ifferene if sle is use efore or fter the retion of urrent pth. It will lso mke ifferene whether the pth is stroke or fille. Note where the 72 72 sle is use for eh squre in the following exmple. lern PS 3 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:squre+sle_2.eps %%BouningBox:72 72 432 504 /squre { 0 0 moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto losepth } ef gsve % smll gry squre.5 setgry 72 144 trnslte 72 72 sle % sle grphi worl 1 to 72 squre fill grestore gsve 2 setlinewith 288 144 trnslte 72 72 sle squre stroke grestore gsve % lower squre % upper squre rwing squre 25

Tking Avntge of PostSript 288 432 trnslte squre 72 72 sle stroke grestore 26 rwing squre

Chpter 3 rwing squre 27

Tking Avntge of PostSript 26 EPS files

4 hpter Chpter 4 EPS files There re two ifferent types of PostSript files: PostSript files tht re sent to the printer n PostSript files tht will e first inorporte into other ouments efore eing sent to the printer. A goo exmple of this is pge omposition softwre tht imports PostSript illustrtions. PostSript files intene to e inlue into nother oument re known s Enpsulte PostSript Files. The files re known s EPS files or EPSF files. These files my hve n.eps file extension, not require in the Mintosh environment ut use on the NeXT. 4.1.ps files The expettion with PostSript file or text file with.ps extension is tht it will print one or more pges of oument. It my ontin EPS files. It will ontin the showpge opertor. showpge is the PostSript print opertor. It is neessry when sening file to printer. In orer to sve spe, it is not use t the en of the PostSript exmples in this ook. If you use SenPS to ownlo your progrms, you n use the A showpge option uner the options menu to utomtilly showpge to your progrms. 4.2.eps files The expettion with n Enpsulte PostSript File or text file with n.eps extension is tht it is one pge n my ontin the showpge opertor n print preview. By efinition, n EPS file is single imge tht my e eventully ple in nother oument. It lso inlues informtion tht tells the importing softwre wht the imensions re n other informtion tht my e neee. This informtion is ontine in the file s heer or first lines of oe. More on this in the next setion. The showpge opertor is optionl n will use prolems if the importing oument is not set up to neutrlize it. If it s not, the pge will print premturely. This is hnle y temporrily reefining showpge to o nothing until the pge is rey to print. Renming PostSript opertors is overe in more etil in setion 17.2. Often print preview will e inlue with the Enpsulte PostSript File so it n e seen on the omputer s monitor. The si reson for this is the PostSript informtion use to rete the pge isn t omptile with how imges re forme EPS files 27

Tking Avntge of PostSript on omputer s monitor. The exeption is the NeXT omputer, on whih the sme informtion is sent to oth sreen n printer. There is no nee for preview version of the grphi. The Mintosh nees print preview of the PostSript file. On the Mintosh, wht is seen on the sreen is rwn y QuikDrw, Apple Computer s grphis lnguge. Files rete with QuikDrw re known s PICT files (short for PICTure). Even though PICT version is seen on the sreen, Aoe s PostSript version is wht is sent to the printer. Depening on the grphi, the overlp in the two grphi moels will proue rough or very urte QuikDrw preview. In ll ses, wht is seen on the Mintosh sreen is never wht is sent to the printer. The EPS options on the Mintosh re: PostSript informtion / no print preview PostSript informtion / 1 it PICT preview for si positioning PostSript informtion / olor or gry sle PICT preview On IBMs n omptiles, the sme sitution exists s with the Mintosh. Wht is seen on the sreen is ifferent thn wht is sent to the printer. All the EPS files we will write s prt of this ook n in the HyperCr version of the LernPS tutoril will not hve preview for the Mintosh sreen. 4.3 the progrm heer There re two lines tht must e present in PostSript file to mke it Enpsulte PostSript File. It is these lines tht mke n EPS file n EPS file. They re: %!PS-Aoe-2.0 EPSF-1.2 %%BouningBox:72 72 216 216 There re numer of onventions in writing the eginning of PostSript progrm. The following progrm, 2inSqure.eps, is n exmple using the most ommon omments. They re outline in more etil in Aoe s tehnil oument #PN LPS5002, Enpsulte PostSript Struturing Conventions. The two ove must e there, ut it is goo hit to provie s muh informtion s possile. These omment lines will e efine in setion 4.6. Notie tht ll of the first six lines egin with the % speil hrter. These lines re not re or use y the PostSript interpreter. They ontin informtion use y softwre tht inorporte the file into lrger oument. The softwre is esigne to re this informtion s the file is importe. The following PostSript progrm will look like this isplye on the NeXT or printe on PostSript lser printer. 28 EPS files

Chpter 4 EPS file lern PS 4 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:2inSqure.eps %%Cretor:John F Shermn %%CretionDte:June 1990 %%DoumentFonts:Times-Romn %%BouningBox:72 72 216 216 72 72 moveto 216 72 lineto 216 216 lineto 72 216 lineto losepth fill /Times-Romn finfont 36 slefont setfont 1 setgry 90 100 moveto (EPS file) show 2inSqure.eps n e ple in numer of Mintosh pplitions s is. Beuse it is only PostSript oe without QuikDrw preview, it will pper on the sreen s n outline ox. The size of this outline ox is tken from the %%BouningBox omment. 2inSqure.eps will print orretly, however, using the PostSript informtion. 4.4 pling EPS files into Mintosh ouments The file, 2inSqure.eps n e ple s is into n Illustrtor or PgeMker oument. In ft, every PostSript exmple in this ook n e ple into ouments in the sme wy. To ple n EPS file into n Illustrtor oument, first rete the text file with ny wor proessor. Its nme oesn t hve to hve the.eps file extension n its nme oesn t even hve to mth the %%Title: omment. When Ple uner the File menu in Aoe Illustrtor is hosen (see figure 4 1), ilog ox will pper to lote n EPS file. The ilog ox will isply TEXT n EPSF file types (more on file types in the next setion). EPS files 29

Tking Avntge of PostSript figure 4 1 When file is selete n opene, Illustrtor will hek the eginning of the file to see if the orret heer informtion is present. Speifilly, s mentione in the previous setion, these two lines: %!PS-Aoe-2.0 EPSF-1.2 %%BouningBox:72 72 216 216 One ple, the ontents of the file nnot e eite, ut it n e move to ny lotion on the pge. In ition, the sle, rotte, reflet, n skew trnsformtion tools of Illustrtor n e use on the file. figure 4 2 The ple 2inSqure.eps will pper like figure 4 2 in Aoe Illustrtor. When this file is printe, the PostSript informtion will e use. In Alus PgeMker, essentilly the sme steps re tken with the Ple menu foun uner the File menu. Selet the EPS file from within the ilog ox in the usul wy. The rrow ursor will eome PS ursor. Clik the PS ursor on the pge where you wnt the PostSript file to e lote (see figure 4 3). 30 EPS files

Chpter 4 figure 4 3 Agin, only gry ox will pper on the pge ut notie tht the title, retor, n retion te pper within the ox (see figure 4 4). This will e isplye if those lines re present in the heer of the progrm. figure 4 4 The gry ox for the EPS file n e move wherever it s neee one ple. 4.5 hnging TEXT to n EPSF file type Some Mintosh pplitions n only import EPS files if their file type hs een hnge from TEXT to EPSF. Their file ontents re not ny ifferent, just tg tht tells the importing softwre wht kin of file it is. figure 4 5 Every Mintosh file hs file type n retor ssoite with it. This informtion is use y the Finer to etermine wht ion to isply (file type) n wht pplition to lunh (file retor). In figure 4 5, Files A n B re me y Aoe Illustrtor n Files C n D re me y Mirosoft Wor (the retors). These two pplitions n mke the sme file type. Files A n D re TEXT. Mirosoft Wor (s n option) n Aoe Illustrtor (y efult) n sve their files s TEXT. File B is EPSF n File C is WDBN. This mens you oul open n Illustrtor file with MS Wor n look t the PostSript oe it hs written. It oesn t work the other EPS files 31

Tking Avntge of PostSript wy, however; Illustrtor n t open Mirosoft Wor s files. Illustrtor files re PostSript files. Illustrtor gives you the option to inlue preview to mke the file n Enpsulte PostSript File. When this is one, Illustrtor hnges the file type from TEXT to EPSF. Beuse of this, the file will hve ifferent ion. File A is TEXT file, File B is n EPSF. File C is Mirosoft Wor s efult file type WDBN n File D is TEXT file. Also, file types n retors re use in ilog oxes to filter wy file nmes of other progrms. In some other Mintosh pplitions, suh s Letrset s Rey, Set, Go, the file type of 2inSqure.eps will nee to e hnge from TEXT to EPSF. This n e one with numer of utilities, suh s CE s DeskTop or MTools. In Illustrtor n PgeMker, the Ple ilog ox isplys ll TEXT files, EPS formtte or not. In other softwre, the ilog ox isplys EPSF or other grphi file formts, ut not TEXT files. The steps involve in hnging file tht s TEXT file type to n EPSF file type n e one with severl utilities. I ll emonstrte how its one using DiskTop, esk essory from CE Softwre. The proess will e similr with other utilities, suh s MTools from Centrl Point Softwre. figure 4 6 After opening DiskTop, selet the file you wish to hnge. Notie tht in this se the file is of type TEXT n is rete y???? (see figure 4 6). It is???? euse the file ws not originlly written on Mintosh n the Mintosh therefore oesn t know who me it. Your file my show MSWD s the retor if the file ws me y Mirosoft Wor or MACA if it ws written y Clris MWrite. For our purposes, it oes not mtter wht the retor ID is. figure 4 7 Selet Get Info... from the DiskTop menu. In the upper right hn orner you will see two oxes to enter new Type n Cretor IDs (see figure 4 7). figure 4 8 Chnge TEXT to EPSF n sve the hnges (see figure 4 8). The file is now rey 32 EPS files

Chpter 4 to e use y progrms suh s Rey, Set, Go or DesignStuio tht look for the EPSF file type. Unfortuntely, you will nee to reverse the steps tken n hnge the file k to TEXT shoul you nee to eit the file. It s importnt to note tht just hnging the file type to EPSF from TEXT oesn t utomtilly mke file n Enpsulte PostSript File. The orret info must e present in the heer of the file. Also, not ll Mintosh softwre will e le to tke vntge of EPS files. Chek the mnul of the softwre in question. 4.6 the progrm heer, line y line Here is rief explntion of eh of the heer lines use in setion 4.3. All of these lines re seen s omments y the PostSript interpreter. They ren t use to mke mrk on the pge, ut to give informtion to either importing softwre or print servers. They o not hve to e in ertin orer exept the following shoul lwys e the first line: %!PS-Aoe-2.0 EPSF-1.2 This line ientifies tht the PostSript progrm onforms to the stnr Aoe struturing onventions. More often thn not, it must e present for the file to e properly use y n pplition. Some progrms will not e le to use the file if it isn t present. %%Title:2inSqure.eps This line is useful, s seen erlier in the PgeMker exmple (figure 4 4). There, the file nme is shown in the gry ox. In other pplitions, it my e liste when informtion is requeste. %%Cretor:John F Shermn This line might re %%Cretor:Aoe Illustrtor 88(TM) 1.6 if it ws rete y Aoe Illustrtor. %%CretionDte:June 1990 This is reor of when the file ws rete. %%DoumentFonts:Times-Romn This line n e very importnt in some print environments. This line my e use to let printer know it hs to get font from its hr isk or server. If more thn one font is eing use in file, it woul e written s follows: %%DoumentFonts:Times-Romn %%+ AvntGre-Demi %%+ Helveti EPS files 33

Tking Avntge of PostSript %%BouningBox:72 72 216 216 This is the most importnt line in the file heer euse it esries the smllest retngle tht the grphi woul fit in. This informtion is use for positioning the EPS file into other files. In the exmple elow, the shpe fits in retngle whose lower left is t x n y 36 36 n upper right is t 192 171. Its ouning ox woul therefore e: %%BouningBox:36 36 192 171 192 171 144 72 36 36 0 0 72 144 216 lern PS 4 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:BBox_1.eps %%CretionDte:June 1990 %%BouningBox:36 36 192 171 36 36 trnslte 12 90 moveto 36 131 65 149 91 115 urveto 113 85 71 89 62 71 urveto 53 53 71 25 97 38 urveto 123 51 114 90 140 78 urveto 171 63 148 31 116 16 urveto 84 1 40-5 21 18 urveto 2 41-6 59 12 90 urveto fill If BBox_1.eps were to e rought into TopDrw on the NeXT omputer, it woul pper s in figure 4 9. 34 EPS files

Chpter 4 figure 4 9 The eight little squres tht surroun the shpe pper when the ojet is selete for n eit in TopDrw. These re hnles tht n e use for strething n sling the piture n ly on the orer tht orrespons to the BouningBox. There is more informtion on the BouningBox in setion D.5. EPS files 35

Tking Avntge of PostSript 36 unerstning error messges

Chpter 5 5 hpter unerstning error messges As with ny progrmming lnguge, mistkes of ll kins n hppen. There n e misspellings, missing rguments, or opertors out of sequene. The PostSript interpreter provies feek to help the progrmmer lote the mistke. Depening on the mens you re using to ownlo the PostSript file, the error messge n e reeive in numer of ifferent wys. The error messge n e sent to text file on your isk rive or sent to winow on the omputer s monitor. An error messge will look like this: %%[Error: unefine; OffeningCommn: movto]%% It will pper on the Mintosh monitor like this when using SenPS: This messge my pper riefly on the monitor n then e sent to text file on isk uner the nme of the printer. It might e nme LserWriter Log n e foun in the sme foler s SenPS. Following re some of the most ommon error messges n where to look when they our. 5.1 unefine unefine is one of the most ommon error messges to reeive. lern PS 5 1 For exmple, with this PostSript progrm, %!PS %%Title:mistke1.ps 72 72 movto % moveto is misspelle unerstning error messges 37

Tking Avntge of PostSript 144 72 lineto 144 144 lineto 72 144 lineto 72 72 lineto fill lern PS 5 2 this error messge is sent k: %%[Error: unefine; OffeningCommn: movto]%% This messge oul e re s I nnot run this PostSript progrm euse I on t unerstn movto. In this se, it will e immeitely reognize tht we misspelle moveto. Another exmple is the following: %!PS %%Title:mistke2.ps /Box ox {72 72 moveto 144 72 lineto 144 144 lineto 72 144 lineto 72 72 lineto fill} ef % Box, not ox, is efine ove The progrm frgment proues this error messge: %%[Error: unefine; OffeningCommn: ox]%% This is sitution similr to the previous error. In oth exmples, when the PostSript interpreter enounters wor it oesn t unerstn, it serhes first the itionry of user efine proeures, n then the system itionry to see if the questionle wor is efine there. If not, the interpreter retes the unefine error. In the first exmple moveto ws misspelle; movto will not e foun in ny itionry. The seon exmple hs the sme si prolem: ox is not the sme s Box, n Box is wht is efine n lote in the user itionry. 5.2 lern PS 5 3 typehek Another ommon mistke is the se when n opertor isn t misspelle ut is missing from ertin PostSript opertor sequene. For exmple: %!PS %%Title:mistke3.ps /Helveti-Bol 100 slefont setfont % finfont is missing 36 36 moveto (Type) show lern PS 5 4 The progrm frgment proues this error messge: %%[Error: typehek; OffeningCommn: slefont]%% Here, finfont ws forgotten fter the /Helveti-Bol. slefont ws in error euse there wsn t nything to sle. Another exmple is this progrm tht retes pttern. %!PS %%Title:mistke4.ps /wor (LernPS) ef 20 20 1 [.1 0 0.1 0 0] {wor} imgemsk % oolen not 1 38 unerstning error messges

Chpter 5 The progrm frgment proues this error messge: %%[Error: typehek; OffeningCommn: imgemsk]%% The error here is not wht is missing, ut tht the 1 lote fter the 20 20 shoul e either true or flse. With the relte imge opertor, the 1 woul e orret in tht position. 5.3 lern PS 5 5 stkunerflow The stkunerflow error ours when n opertor oes not hve the expete numer of rguments on the stk. In the following line of PostSript, r nees five numers on the opern stk to o its work n there re only four present witing to e use. %!PS %%Title:mistke5.ps 72 36 0 270 r stroke % missing the vlue for rius The progrm frgment proues this error messge: %%[Error: stkunerflow; OffeningCommn: r]%% lern PS 5 6 In this next exmple, the height rgument is missing for the imge opertor. %!PS %%Title:mistke6.ps /pistr 2 string ef /Mikey {16 1 [.2 0 0.2 0 0] % missing height {urrentfile pistr rehexstring pop} imge} ef Mikey FE 0F FD B3 FD 7D F5 F8 F7 F8 F6 D3 80 D3 00 F7 00 CF 06 1F 04 0F 8C 0F FC 0F FC 0F FE 1F The progrm frgment proues this error messge: %%[Error: stkunerflow; OffeningCommn: imge]%% This messge sttes tht one of the rguments for the imge opertor is missing. H the mtrix rry or proeure een missing, the error woul hve een typehek error. 5.4 lern PS 5 7 rngehek The rngehek error is use when n expete vlue is outsie of the require rnge. In the exmple elow, the mtrix rry for the imge opertor is missing the lst zero in the rry, whih shoul re [.2 0 0.2 0 0]. %!PS %%Title:mistke7.ps /pistr 2 string ef unerstning error messges 39

Tking Avntge of PostSript /Mikey { 16 15 1 [.2 0 0.2 0] % rry missing lst 0 {urrentfile pistr rehexstring pop} imge} ef Mikey FE 0F FD B3 FD 7D F5 F8 F7 F8 F6 D3 80 D3 00 F7 00 CF 06 1F 04 0F 8C 0F FC 0F FC 0F FE 1F The progrm frgment proues this error messge: %%[Error: rngehek; OffeningCommn: imge]%% 5.5 limithek The most ommon reson for limithek error is tht urrent pth hs eome too omplex. For exmple, the mximum numer of points tht n e rete in urrent pth efore n error on the Apple LserWriter Plus is fifteen hunre. This numer will e ifferent epening on the printer. The resolution tht the printer is set to n lso hve ering on whether this error will our. lern PS 5 8 %!PS %%Title:mistke8.ps /Helveti-Bol finfont 100 slefont setfont /fountstring 256 string ef 0 1 255 { fountstring exh up put } for 36 36 trnslte 0 0 moveto (efghijklm) true hrpth lip 620 150 sle 255 1 8 [255 0 0 1 0 0] {fountstring} imge The progrm frgment proues this error messge: %%[Error: limithek; OffeningCommn: lip]%% Wht n e iffiult out this error is ntiipting when it will e me. A PostSript progrm might run error free on n Apple LserWriter ut fil on high resolution Linotron. The progrm mistke8.ps ove, for exmple, fils on n Apple LserWriter Plus ut runs without prolem on NeXT lser printer. There re two solutions when this error ours. In the exmple ove, the lip oul e one in severl prts, lipping first e, then the fghi, n then the jklm. This n e omplishe y using the stringwith opertor. The syntx for stringwith is: string stringwith returning xw yw where string is the string to e mesure, n xw is the returne with of string. The returne yw vlue is usully isre euse the vertil mesurement in romn fonts is lwys zero. 40 unerstning error messges

Chpter 5 efghijklm lern PS 5 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fix8.eps %%Dte:17 De 1990 %%DoumentFonts:Helveti-Bol %%BouningBox:0 0 355 70 0 0 355 70 retstroke /Helveti-Bol finfont 50 slefont setfont /fountstring 256 string ef 0 1 255 { fountstring exh up put } for /x1 (e) stringwith pop 12 ef /x2 (efghi) stringwith pop 12 ef gsve 12 24 moveto (efghijklm) true hrpth lip 350 70 sle 255 1 8 [255 0 0 1 0 0] {fountstring} imge grestore gsve x1 24 moveto (fghi) true hrpth lip 350 70 sle 255 1 8 [255 0 0 1 0 0] {fountstring} imge grestore gsve x2 24 moveto (jklm) true hrpth lip 350 70 sle 255 1 8 [255 0 0 1 0 0] {fountstring} imge grestore The seon wy is to use the setflt opertor. To get the progrm ove to work on the Apple LserWriter Plus, 9 setflt is e to the eginning of the progrm. setflt ontrols the ury of urve pths. The lrger the numer, the orser the urve. In mistke8.ps ove, the etter solution might e to ivie the lipping opertion euse the 9 setflt mkes the letterform s urves very rough. Following is n exmple of wht setion of the print woul look like with setflt use. unerstning error messges 41

Tking Avntge of PostSript efgh Another ommon reson for getting limithek error is using the utotre feture of Aoe Illustrtor on the wrong kin of templte. 5.6 lern PS 5 10 nourrentpoint The nourrentpoint error is sent when neee urrent point is missing. It is usully missing moveto. In this exmple, urveto nees n existing urrent point. Unlike r or rn, this line of PostSript must e preee y either moveto or the urrent point on pth eing me. %!PS %%Title:mistke9.ps 100 28 116 110 144 72 urveto stroke The progrm frgment proues this error messge: %%[Error: nourrentpoint; OffeningCommn: urveto]%% lern PS 5 11 Another exmple is type positione y moveto. %!PS %%Title:mistke10.ps /Helveti-Bol finfont 72 slefont setfont (Type) show The progrm frgment proues this error messge: %%[Error: nourrentpoint; OffeningCommn: show]%% lern PS 5 12 In this exmple, the lineto nees to egin with moveto. %!PS %%Title:mistke11.ps 144 72 lineto 144 144 lineto 72 144 lineto 72 72 lineto fill The progrm frgment proues this error messge: %%[Error: nourrentpoint; OffeningCommn: lineto]%% In eh se, lue is provie on where to fin the error. 42 unerstning error messges

Chpter 5 5.7 lern PS 5 13 syntxerror The typil reson for this error is tht the speil hrters (, [, {, n < re not pire with the orresponing ), ], }, n > in progrm. In this exmple, the losing prenthesis is missing from the string. %!PS %%Title:mistke12.ps /Helveti-Bol finfont 72 slefont setfont 36 36 moveto (Type show The progrm frgment proues this error messge: %%[Error: syntxerror; OffeningCommn: Type show H the first prenthesis een the one missing inste of the seon, the messge woul e this: %%[Error: syntxerror; OffeningCommn: Type]%% lern PS 5 14 In this exmple, the losing prenthesis is missing from the efinition. %!PS %%Title:mistke13.ps /wor (LernPS ef 20 20 2 [.1 0 0.1 0 0] {wor} imge The progrm frgment proues this error messge: %%[Error: syntxerror; OffeningCommn: LernPS ef unerstning error messges 43

Tking Avntge of PostSript 44 rwing sis

6 hpter Chpter 6 rwing sis Up to this point, we hve overe the sis of reting pth for lines n retngles using only the lineto n rlineto opertors. Oviously, there re numer of other pth onstrution opertors for mking other kins of pths. There re five PostSript opertors for mking irles, rs n urves. All of these opertors n e use in omintion with eh other to mke ny shpe possile. One me, the pth n e stroke, fille, or oth. 6.1 reting rs The r n rn opertors re use to rw rs n irles. Their syntx is: x y rius egin finish r x y rius egin finish rn Where: x is the enter of the r/irle on the x xis. y is the enter of the r/irle on the y xis. rius is the rius of the r/irle. egin is the eginning point of the pth. finish is the finishing point of the pth. The ifferene etween r n rn is the iretion of the rwing from egin to finish. See figure 6 1 elow. The irle is ivie into egree points in the ounterlokwise iretion from the three o lok position. The sme points re use y oth r n rn. With r, the iretion of egin to finish is in the ounterlokwise iretion, with rn it is lokwise. The 0 n 360 points shre the three o lok position. Therefore, oth 0 360 r n 0 360 rn oul e use to rw irle. Neither r nor rn nees n existing urrent me y moveto the wy lineto oes. However, they n tke vntge of moveto s will e shown lter in r_2.eps. If there is n existing urrent point, it will tth itself with stright line to the egin. To insure ginst n unwnte line, ler the urrent pth with the opertor newpth. rwing sis 45

Tking Avntge of PostSript 90 r rius x y 0 & 360 rn 270 figure 6 1 Here re three rs rwn with r. lern PS 6 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:r_1.eps %%BouningBox:34 34 256 110 3 setlinewith 72 72 36 0 270 r stroke 144 72 36 225 90 r stroke 216 72 36 0 135 r stroke Now, the sme progrm gin with the sme rguments use in r_1.eps, ut sustituting rn. The opposite portion of the r is rwn. 46 rwing sis

Chpter 6 lern PS 6 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rn_1.eps %%BouningBox:34 34 256 110 72 72 36 0 270 rn stroke 144 72 36 225 90 rn stroke 216 72 36 0 135 rn stroke The two previous r exmples were rwn without the ustomry estlishing of urrent point. If there is no existing urrent, one is rete t the lotion of egin, the strting point of the r. If there is n existing urrent point, line will e rwn to the point of egin. Notie the ifferene in the following two PostSript progrms when urrent point is me t the enter of the r n losepth is use. lern PS 6 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:r_2.eps %%BouningBox:34 34 256 110 72 72 moveto 72 72 36 0 270 r losepth stroke 144 72 moveto rwing sis 47

Tking Avntge of PostSript 144 72 36 225 90 r losepth stroke 216 72 moveto 216 72 36 0 135 r losepth stroke In ll the rs in the previous n next exmple, urrent point is first me t the enter of the r. egin onnets to tht urrent point n therefore rws line. After r, the urrent point will e t finish. Then, losepth rws line to the originl urrent point me with the erlier moveto. In this exmple, oth r n rn re use with fill. PS lern 6 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:r_3.eps %%BouningBox:34 34 256 110.5 setgry 72 72 moveto 72 72 36 0 270 r losepth fill.1 setgry 72 72 moveto 72 72 36 0 270 rn losepth fill.3 setgry 144 72 moveto 144 72 36 225 90 r losepth fill.8 setgry 144 72 moveto 144 72 36 225 90 rn losepth fill.5 setgry 216 72 moveto 216 72 36 0 135 r losepth fill.8 setgry 216 72 moveto 216 72 36 0 135 rn losepth fill 48 rwing sis

Chpter 6 6.2 mking pie hrt using r Using r to evelop pie hrt is goo exerise in lerning how to mke use of the opern stk n few of the PostSript mth opertors. The pie hrt elow is for the perentges of 43%, 25%, 17%, n 15%. This progrm exmple is written to hnle ny four perentges tht up to 100. The progrm for the fille version of the pie hrt n e foun in hpter 19. PS lern 6 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:pieChrt_1.eps %%Cretor:John F Shermn %%CretionDte:June 1990 %%BouningBox:10 10 154 154 2 setlinewith 10 10 trnslte 43 25 17 15 % the 4 perentges with spe etween /p1 exh 3.6 mul ef /p2 exh 3.6 mul p1 ef /p3 exh 3.6 mul p2 ef /p4 exh 3.6 mul p3 ef /x 72 ef /y 72 ef /r 72 ef /wege{r losepth stroke} ef x y moveto x y r 0 p1 wege x y moveto x y r p1 p2 wege x y moveto x y r p2 p3 wege x y moveto x y r p3 p4 wege Looking t the first prt of the progrm, 43 25 17 15 re the four perentges with wor spe seprting them. They n e ny four perentges s long s rwing sis 49

Tking Avntge of PostSript they up to 100. The four numers re entere onto the stk. /p1 exh 3.6 mul ef efines our first point on the r moving ounterlokwise from the 0 point. If we were to hrt the stk of these two lines of oe, it woul look like figure 6 2. exh 15 mul 54 ef 17 /p1 /p1 3.6 /p1 54 25 15 17 15 17 /p1 43 17 25 /p1 25 17 figure 6 2 25 43 43 17 25 43 43 25 43 In olumn one, the four numers, /p1, n exh re entere onto the stk. exh exhnges the top two items on the stk. Therefore, s we see in olumn two, /p1 n 15 hve swithe ples on the stk. p1 will eventully e the nme for our first point on the r. Next in olumn three, 3.6 n mul re e to the stk. mul multiplies the top two numers on the stk n pushes (puts) the prout onto the stk. We multiply y 3.6 euse our four numers re frtions of 100 n our pie weges will e frtions of 360. In olumn four, 54 is on top from the multiplying of 3.6 y 15. Next omes ef, whih ssoites /p1 with the vlue 54. The steps re then repete in the sme wy for points /p2, /p3, n /p4. However, with those points the new point will lso nee to hve the vlue of the previous point e to it. We o this euse we nee to mke our wy roun the irumferene of the pie. Note tht in efining the vrile p1 the { } re not use. They re only use when efining proeures. The next line of the progrm egins in the sme wy exept for the ition of ing the vlue of p1 to efinition of p2. Strting t where 17 times 3.6 equls 61.2 is pushe onto the stk, the stk woul ontinue s shown in figure 6 3. 61.2 115.2 ef 25 /p2 p1 (54) /p2 115.2 43 25 61.2 25 /p2 43 /p2 43 25 25 43 43 figure 6 3 p1 n re e to the stk. As you might guess, s the top two numers on the stk. We efine p1 in the previous line to e 54. So we then hve in olumn three p1 plus 61.2 equling 115.2 pushe onto the stk. It is then given the nme p2. Our stk now hs two numers left to proess s p3 n p4. They re one in the sme wy s p2. We now hve these points roun the pie (see figure 6 4). 50 rwing sis

Chpter 6 115.2 54.0 0 n 360.0 205.2 figure 6 4 The next prt of the progrm is: /x 72 ef /y 72 ef /r 72 ef /wege {r losepth stroke} ef x n y etermine the enter of the pie hrt. They will e use y oth the moveto n r opertors lter in the progrm. r is the rius of the pie hrt. Defining the x, y, n r vriles like this gives us flexiility. We nee to hnge only one numer, not mny, to mke hnge to the hrt. wege is the nme for the proeure {r losepth stroke}. This simplifies the progrm n helps it to e more rele. Next in the progrm omes the tul rwing of the pie hrt using the vlues n proeures efine erlier. x y moveto x y r 0 p1 wege These progrm lines rw the first wege, n so forth. To rewrite the progrm to work with five perentge numers, these lines: /p5 exh 3.6 mul p4 ef n x y moveto x y r p4 p5 wege Follow this sme pttern for eh wege tht will e neee for the hrt. Also, sine we know tht the lst point must e 360, we oul leve out the proess of efining the lst point n put in 360. 6.3 rwing urves Complex urves re rwn in PostSript with the urveto opertor, whih uses Beziér ui ontrol points. If you hve ever use Aoe Illustrtor, you my lrey hve eome quinte with them when rwing urves. Most omplex urves re iffiult to rw without the i of softwre pkge suh s Aoe Illustrtor, ut some si exmples n e emonstrte. rwing sis 51

Tking Avntge of PostSript The syntx of urveto is: 1x 1y 2x 2y x2 y2 urveto Where 1x 1y 2x 2y x2 y2 is the lotion of the first Beziér ontrol point. is the lotion of the seon Beziér ontrol point. is the en of the urve n new urrent point. urveto lso requires n existing urrent point, x1 y1, s strting point, unlike r n rn whih n get y without one. It is importnt to note tht the two points 1x 1y n 2x 2y re not points on the tul pth of the urve. Following is n exmple n igrm. x2 y2 eomes the new urrent point. 2x 2y 72 x1 y1 x2 y2 1x 1y 0 0 72 144 216 288 360 lern PS 6 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:urveto_1.eps %%BouningBox:72 55 144 88 3 setlinewith 72 72 moveto 100 28 116 110 144 72 urveto stroke lern PS urveto emo Beziér ui ontrol points rete urve y using the points x1 y1, 1x 1y, 2x 2y, n x2 y2 to mrk off frme s seen elow in the first frme of figure 6 5. Then eh line segment of the frme is repetely hlve until the urve is forme. Figures 6 5 n 6 6 illustrte this. 1x 1y 2x 2y x1 y1 x2 y2 figure 6 5 The urve of the lst frme is proue y 18 18 moveto 18 54 90 54 90 18 urveto stroke 52 rwing sis

Chpter 6 2x 2y 1x 1y x1 y1 x2 y2 figure 6 6 The urve of the lst frme is proue y 18 18 moveto 108 54 0 54 90 18 urveto stroke There is lso the relte rurveto, whih is muh like rlineto. 6.4 the rto opertor An lterntive wy of onstruting rs or urves is the rto opertor. rto rouns off orner me y two lines with n r of speifie rius. The syntx of rto is: x1 y1 x2 y2 rius rto Where: x1 y1 is the en point of the first line n mrks the orner. x2 y2 is the en point of the seon line. rius is the rius of the r rouning off the orner of the two lines. In ition, rto requires urrent point n pushes the new tngent points xt1 yt1 n xt2 yt2 onto the opern stk. In the mjority of ses, these four points re isre. xt2 yt2 eomes the new urrent point. See exmple elow. 36 180 moveto 144 xt1 yt1 enter of r 72 x1 y1 xt2 yt2 x2 y2 0 0 72 144 216 288 360 rwing sis 53

Tking Avntge of PostSript lern PS 6 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rto_1.eps %%CretionDte:June 1990 %%BouningBox:34 34 294 165 3 setlinewith 36 180 moveto 36 36 144 36 72 rto 360 36 180 180 36 rto stroke 8 {pop} repet lern PS rto emo In the exmple ove, urrent point is me t 36 180 n pth is rwn to x1 y1 n then ontinues to x2 y2. The orner of those two lines is then roune y n r with rius of 72. The two points where the r is tngent to the two lines rete the new points xt1 yt1 n xt2 yt2. The urrent point is now xt2 yt2 n the line will ontinue from there. x2 y2 will no longer exist. The reson for the 8 {pop} repet is to remove the tngent points left on the stk. The two sets of tngent points of xt1 yt1 n xt2 yt2 re y-prout of the two rtos n remin on the stk. This is totl of eight numers tht re not neee for nything t this time. In nother sitution, they my e tken vntge of. The opertor pop removes the top most item on the opern stk, n sine we hve eight numers to remove, 8 {pop} repet oes this. It s the sme s writing: pop pop pop pop pop pop pop pop The rto opertor n e use to mke retngles with roune orners. An exmple follows. 144 72 0 0 72 144 216 288 360 54 rwing sis

Chpter 6 lern PS 6 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:roune_ret.eps %%BouningBox:34 34 325 218 /rouneret { /rius exh ef /height exh ef /with exh ef with 2 iv 0 moveto % strt in the mile with 0 with height rius rto % 1st orner with height 0 height rius rto % 2n orner 0 height 0 0 rius rto % 3r orner 0 0 with 0 rius rto losepth % 4th orner 16 {pop} repet } ef % isr tngent points gsve 252 36 trnslte 2 setlinewith 72 180 12 rouneret % 72 wie, 180 high gsve.8 setgry fill grestore stroke grestore gsve 72 72 trnslte.5 setgry 216 72 18 rouneret fill grestore gsve 36 36 trnslte 3 setlinewith 144 144 36 rouneret stroke grestore lern PS roune ret The proeure rouneret is esigne to use three rguments to rw retngle with roune orners. The first two re the with n height of the retngle n the thir is the rius. It woul e use like this: 72 144 24 rouneret stroke The first line of rouneret is /rius exh ef /height exh ef /with exh ef This line is how the three rguments re psse on to the rest of rouneret proeure. 72, 144, n 24 re on the opern stk with 24 on top when rouneret rrives. All in one line it woul e 72 144 24 /rius exh ef /height exh ef /with exh ef The first exh woul swith 24 /rius. 72 144 /rius 24 ef /height exh ef /with exh ef /rius woul then e efine s 24. 72 144 /height exh ef /with exh ef The seon exh woul swith 144 /height n so on s efore. The rest of the proeure uses with n height in vrious omintions with 0 n rius s rguments for the rto opertor. rwing sis 55

Tking Avntge of PostSript 56 type sis

7 hpter Chpter 7 type sis Fonts re store s outlines either in printer s ROM, RAM, or n tthe hr isk. The vntge of outlines is tht the font n e sle to ny size without worry of rgge eges. The PostSript interpreter will fill in the pproprite numer of ots. A it-mp woul not provie the sme flexiility. Eh font is tully itionry of efinitions for eh letterform in the font. Erlier, in hpter 3, we efine the proeure squre to e series of rwing opertions tht rew squre. The proeure squre ws kept in user itionry in the PostSript interpreter while the progrm using it ws run on the printer. In muh the sme wy, eh hrter of the lphet hs series of rwing opertions ssoite with its nme in font itionry. For exmple, within every PostSript lser printer there is font itionry nme Times-Bol. In tht itionry, g woul e efine y series of rwing opertions tht woul rete its outline. 7.1 igrm of letterform In figure 7 1 elow, point mrks the lotion of the origin for Times-Bol g. Point represents oth the with of the letterform n the new urrent point. Point is the lotion of the origin of the next letterform to follow. It s very similr to the ie of mking urrent point, reting pth, n hving the new urrent point t the en of the pth. The lk ox ientifies the smllest retngle the g n fit gin. It is known s the letterform s ouning ox. The mount of spe letterform uses within line of type, the istne etween points n, is slightly more thn its visile with. type sis 57

Tking Avntge of PostSript figure 7 1 7.2 pling type on the pge Positioning type on the pge is omplishe in muh the sme wy s rwing tion is strte. A urrent point is first me using the moveto opertor. The ifferene, however, is tht the urrent point when me for type plement oes not represent n tul point on letterform, ut represents its origin on its seline. A letterform s origin is slightly left n on the seline of the hrter. See the g in figure 7 1. The following exmple prints g. The + mrks the lotion of 18 72 moveto, whih is the hrter s origin. lern PS 7 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type plement1.eps %%BouningBox:0 0 150 180 /Times-Bol finfont 200 slefont setfont 18 72 moveto (g) show Here s n explntion of the progrm: /Times-Bol finfont lotes the font itionry for Times-Bol. 200 slefont sles the font to 200 point. setfont mkes Times-Bol the urrent font. 18 72 moveto estlishes urrent point. This point will e the hrter s origin n will lso e on the seline. The hrters to e set re ientifie y eing ontine within prentheses. The ( n ) re speil hrters use to ientify wht is known s string or group of hrters to e use for some purpose. In this se, they will e pinte on pge. show pints the hrters hel within the ( n ) in the urrent font with 58 type sis

Chpter 7 the urrent olor. In this se, the urrent font is Times-Bol n the urrent olor is the gefult lk. In this exmple, the will e pinte with 70% gry. PS lern 7 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type plement2.eps %%BouningBox:0 0 150 180 /Times-Bol finfont 200 slefont setfont 18 72 moveto.3 setgry (g) show After show in oth preeing PostSript progrm exmples, the new urrent point is lote t the with of the hrter n on the seline. See point of figure 7 1. To illustrte this, notie how the line is rwn in the next exmple. The eginning of the line is the urrent point lote t the with of the hrter g n on the seline. 100 0 rlineto rws pth 100 points to the right of the urrent point. stroke then pints the pth n initilizes the urrent pth. type sis 59

Tking Avntge of PostSript g lern PS 7 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type plement3.eps %%BouningBox:0 0 225 180 /Times-Bol finfont 200 slefont setfont 18 72 moveto.3 setgry (g) show 0 setgry 2 setlinewith 100 0 rlineto stroke g When setting series of hrters to form wor, the hrter sping is se on the font s metri file. The font metri file ontins hrter withs. Eh hrter in line to e set referenes the previous hrter. figure 7 2 In figure 7 2 ove, point represents the first urrent point. Point is the new urrent fter the g is set. Point therefore eomes the lotion for the origin of the hrter. After is set, point eomes the new urrent point. 60 type sis

Chpter 7 7.3 vrious font strtegies Sine it is prole tht numer of ifferent fonts n sizes woul e use on pge, following re numer of ies for swithing from one urrent font to nother. The first metho woul e to sve the grphi stte using gsve n grestore. In this wy, there my e one font tht you will ontinully return to in PostSript progrm. An exmple woul e: BC A lern PS 7 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type plement4.eps %%BouningBox:0-4 346 126 /Helveti finfont 170 slefont setfont 0 0 moveto (A) show gsve /Times-Bol finfont 48 slefont setfont.3 setgry 10 10 moveto () show grestore (B) show % no moveto, urrent point from A still tive gsve /StoneSerif-Bol finfont 48 slefont setfont.5 setgry 10 40 moveto () show grestore (C) show % no moveto, urrent point from B still tive gsve /Helveti-Bol finfont 48 slefont setfont.8 setgry 10 80 moveto () show grestore type sis 61

Tking Avntge of PostSript The first gsve sves three key vlues. The urrent font me y /Helveti finfont 170 slefont setfont, the urrent efult vlue of lk, n the new urrent point me fter the (A) show. The urrent font is then hnge to /Helveti-Bol finfont 48 slefont setfont, the urrent vlue is hnge to 0.3 setgry (70%), n new urrent point is me with 10 10 moveto for the row of s. grestore restores the urrent font k to /Helveti finfont 170 slefont setfont, the urrent vlue k to lk, n the urrent point left fter the (A) show. The whole proess then gets repete for the rows of s n s. A seon strtegy is to give ifferent font settings nme. For exmple, /H18 {/Helveti finfont 18 slefont setfont} ef /H36 {/Helveti finfont 36 slefont setfont} ef /H72 {/Helveti finfont 72 slefont setfont} ef A thir option is to efine /f {finfont exh slefont setfont} ef n use it y writing this: 18 /Helveti f The thir metho is use in this exmple. Note how the plement of iniviul hrters is omplishe. PS lern 7 5 TYPE %!PS-Aoe-2.0 EPSF-1.2 %%Title:TYPE.eps %%BouningBox:0 0 190 50 /f {finfont exh slefont setfont} ef 68 /Helveti-Bol f 0 0 moveto (T) show 72 /StoneSerif-SemiolItli f (Y) show 74 /Times-Bol f 6 0 rmoveto (P) show % move urrent 6 points right 68 /Helveti-Olique f -8 0 rmoveto (E) show % move urrent -8 points left 62 type sis

Chpter 7 Notie how rmoveto is use to kern the type right n left to orret the lettersping. Kerning opertors re expline in more etil in hpter 11, vne type. 7.4 stroking & filling type Inste of using show to pint the type s in ll the previous exmples, the letterform s outline n e otine n me into the urrent pth. Then gsve n grestore n lso e use to sve the urrent pth to oth stroke n fill s ws previously one to the squre in setion 3.3. && lern PS 7 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:&&.eps %%BouningBox:0 0 350 170 /StoneSerif-Bol finfont 170 slefont setfont 6 setlinewith 18 36 moveto (&) true hrpth gsve.5 setgry fill grestore stroke 180 36 moveto (&) flse hrpth gsve stroke grestore.5 setgry fill Note the ifferene it mkes if the type is stroke seon or first. show is reple with true hrpth. true hrpth mkes the hrter s outline the urrent pth. hrpth is preee with either true or flse. Aoring to the PostSript Lnguge Referene (lso known s the Re Book), type sis 63

Tking Avntge of PostSript true hrpth is suitle for filling or lipping, ut not for stroking. The other hoie, flse hrpth, is suitle only for stroking. In the PostSript progrm exmple ove oth re use, oth seem to work orretly. Clipping is expline in setion 9.4. 7.5 font nmes If you re working on n Apple LserWriter Plus or the lter LserWriter NT or NTII, there re thirty-five ifferent font outlines tht n e esse in the printer s ROM. Following is list of their nmes written s they woul nee to e written for PostSript progrm. First, the si group of fonts tht re stnr on every PostSript evie: Courier Courier-Bol Courier-Olique Courier-BolOlique Times-Romn Times-Bol Times-Itli Times-BolItli Helveti Helveti-Bol Helveti-Olique Helveti-BolOlique Symol These itionl fonts re known s the Plus Set: AvntGre-Book AvntGre-BookOlique AvntGre-Demi AvntGre-DemiOlique Bookmn-Light Bookmn-LightItli Bookmn-Demi Bookmn-DemiItli Helveti-Nrrow Helveti-Nrrow-Olique Helveti-Nrrow-Bol Helveti-Nrrow-BolOlique NewCenturyShlk-Romn NewCenturyShlk-Itli NewCenturyShlk-Bol NewCenturyShlk-BolItli Pltino-Romn 64 type sis

Chpter 7 Pltino-Itli Pltino-Bol Pltino-BolItli ZpfChnery-MeiumItli ZpfDingts There re hunres of fonts ville from Aoe. A progrm to print most of the hrters of font (to see wht they look like) follows. Sustitute the font nme, efore the finfont opertor with the font nme to e set. lern PS 7 7 ABCDE FGHIJ KLMNO PQRST UVWXYZ efgh ijklmno pqrstuv wxyz 1234567890 %!PS-Aoe-2.0 EPSF-1.2 %%Title:quikLook.eps %%BouningBox:30 125 180 425 /Times-Bol finfont 24 slefont setfont /left 36 ef % left mrgin /newline {show urrentpoint exh pop 30 su left exh moveto} ef left 400 moveto (ABCDE) newline (FGHIJ) newline (KLMNO) newline % lotion of first line % newline ts like rrige % on typewriter type sis 65

Tking Avntge of PostSript (PQRST) newline (UVWXYZ) newline (efgh) newline (ijklmno) newline (pqrstuv) newline (wxyz) newline (1234567890) show.5 setgry 30 125 moveto 150 0 rlineto 0 300 rlineto -150 0 rlineto losepth stroke 66 type sis

Chpter 7 type sis 67

Tking Avntge of PostSript 66 the repet & for opertors

8 hpter Chpter 8 the repet & for opertors The repet opertor, s its nme implies, repets something speifie numer of times. The for opertor ounts y speifie inrement from given se numer to given limit. Both opertors n e use to rete similr results ut they work in entirely ifferent wys. 8.1 repet The syntx for repet is: numer proeure repet For exmple, 4 {line} repet is the sme s writing line line line line where line my e proeure efine erlier in the progrm to rw line. The proeure n lso e PostSript opertor. A ommon exmple is: 4 {pop} repet This woul remove the top four items on the opern stk. You hve seen this use efore with rto (setion 6.4) n you ll see it use lter with the kshow (setion 11.5) opertor. In the following exmple, repet is use to rw multiple lines. the repet & for opertors 67

Tking Avntge of PostSript 72 0 0 72 144 216 lern PS 8 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:repet_1.eps %%BouningBox:36 36 252 108 /vline {0 0 moveto 0 72 rlineto stroke} ef 36 36 trnslte 2 setlinewith 36 {6 0 trnslte vline} repet In the progrm ove, vline efines 72 point vertil line from the origin. The origin is then move 6 points right thirty-six times with the 6 0 trnslte efore eh use of the proeure line. It s the sme s writing 6 0 trnslte line thirty-six times. The next exmple is silly the sme thing ut moving up n rwing horizontl lines. 72 PS lern 8 2 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:repet_2.eps %%BouningBox:36 36 252 108 68 the repet & for opertors

Chpter 8 /hline { 0 0 moveto 216 0 rlineto stroke} ef 36 36 trnslte 2 setlinewith 12 {0 6 trnslte hline} repet To omine oth progrms to mke gri, t lest the first repet line shoul e within gsve n grestore so tht the seon repet strts t the proper lotion. Otherwise, the origin will e t 252 36 fter the first repet, throwing off the lotion of the seon set of lines. Here is how tht oul e written: lern PS 8 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:repet_1&2.eps %%BouningBox:36 36 252 108 /vline {0 0 moveto 0 72 rlineto stroke} ef /hline {0 0 moveto 216 0 rlineto stroke} ef 2 setlinewith 36 36 trnslte gsve vline 36 {6 0 trnslte vline} repet grestore gsve hline 12 {0 6 trnslte hline} repet grestore The repet n e use with the rotte opertor. See the next exmple. The origin is first move to 108 108 n then rotte thirty-six times t 10 intervls s eh line is rwn. Then the origin is move over 108 points n rotte ten times t 36 intervls s thiker line is rwn. More on rotte in setion 10.3. the repet & for opertors 69

Tking Avntge of PostSript 144 72 0 0 72 144 216 lern PS 8 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:repet_3.eps %%BouningBox:36 36 288 180 /line {0 0 moveto 0 72 rlineto stroke} ef 108 108 trnslte 36 {10 rotte line} repet 3 setlinewith 108 0 trnslte 10 {36 rotte line} repet 8.2 for The for opertor ounts up or own to speifie limit y speifie inrement from n initil numer. The syntx for for is: initil inrement limit proeure Where: initil inrement limit proeure is the first numer of the ount. is the inrement of the ount (it n e positive or negtive). is the lst numer of the ount. is the proeure exeute fter every ount. For exmple, 1 1 10 { } for is the sme s 1 2 3 4 5 6 7 8 9 10. Sine there is no proeure supplie etween the {}, nothing is exeute fter eh ount from 1 to 10. If proeure h een supplie, it woul e exeute fter eh ount. For exmple, 17 1 1 6 {} for woul e sme s writing: 17 1 2 3 4 5 6 70 the repet & for opertors

Chpter 8 These two lines of oe n e emonstrte further with the following progrm. Sine you n t see wht is hppening insie the PostSript interpreter, this progrm will print the result of the two lines of PostSript oe ove. Prts of this progrm will e expline in more etil in setion 8.3. 38 38 lern PS 8 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:for_test.eps %%BouningBox:36 36 108 72 /Times-Bol finfont 24 slefont setfont /str 4 string ef % ontiner for 4 hrters 36 36 moveto 17 1 1 6 {} for % ount from 1 to 6 ing eh to 17 str vs show % put nswer into str, onvert into % string n show /Times-Romn finfont 24 slefont setfont 72 36 moveto 17 1 2 3 4 5 6 str vs show The for opertor n e use to rw rows of prllel lines muh like the repet exmples isusse in the previous setion. However, it is omplishe y leving numers on the stk to e pike up lter y the moveto opertor. In the next exmple, the for opertor ounts y 6 up to 216. This puts or pushes 0, 6, 12, 18, 24,, 216 onto the opern stk efore the exeution of the proeure line, whih ws efine s {0 moveto 0 72 rlineto stroke}. Notie tht there is only one numer supplie for the moveto opertor within the proeure efinition. After eh ount of the for loop, there will e new numer on the stk to e use with 0 moveto. 72 lern PS8 6 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 the repet & for opertors 71

Tking Avntge of PostSript %%Title:for_1.eps %%BouningBox:36 36 252 108 /line {0 moveto 0 72 rlineto stroke} ef 36 36 trnslte 2 setlinewith 0 6 216 {line} for This woul e sme s writing: /line {0 moveto 0 72 rlineto stroke} ef 36 36 trnslte 2 setlinewith 0 6 216 { } for % ll x vlues re pushe onto the stk 0 line 6 line 12 line 18 line 24 line 30 line 36 line 42 line 48 line 54 line 60 line 66 line 72 line 78 line 84 line 90 line 96 line 102 line 108 line 114 line 120 line 126 line 132 line 138 line 144 line 150 line 156 line 162 line 168 line 174 line 180 line 186 line 192 line 198 line 204 line 210 line 216 line A similr tehnique n e use to rw series of horizontl lines. However, the for opertor will e use to supply the y vlue neee y moveto. The line proeure therefore is efine s {0 exh moveto 216 0 rlineto stroke}. exh swithes the top two items of the opern stk. Therefore, 0 tres ples with the new numer left on the stk. In this wy, 0 n lwys e the x vlue n the new numer is the y. 72 0 0 72 144 216 lern PS 8 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:for_2.eps %%BouningBox:36 36 252 108 /line {0 exh moveto 216 0 rlineto stroke} ef 36 36 trnslte 72 the repet & for opertors

Chpter 8 2 setlinewith 0 6 72 {line} for The following re two exmples where for is use to supply one of the numers for the sle opertor. Sine sle nees two vlues, for oth the x n y sling ftor, up is use to uplite the top item on the stk. In the next exmple, for ounts from 1 to 2.25 y inrements of 0.25. up uplites eh ount n pushes the opy onto the stk. Therefore, 1.25 2.25 {up sle irle} for is the sme s 1 1 sle irle 1.25 1.25 sle irle 1.5 1.5 sle irle 1.75 1.75 sle irle 2 2 sle irle 2.25 2.25 sle irle 144 72 0 0 72 144 216 lern PS 8 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:for_3.eps %%BouningBox:0 0 216 216 newpth /irle{0 0 6 0 360 r stroke} ef 108 108 trnslte 1.25 2.25 {up sle irle} for In the next version of the progrm, the irle proeure efinition inlues gsve n grestore n therefore hnges the rte of sle the irle reeives. the repet & for opertors 73

Tking Avntge of PostSript 144 72 0 0 72 144 216 lern PS 8 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:for_3.eps %%BouningBox:24 24 192 192 newpth /irle {0 0 9 0 360 r stroke} ef 108 108 trnslte 1 1.5 9 {gsve up sle irle grestore} for 8.3 using for & put with strings In the previous exmples, the for opertor ws use to proue results tht oul hve een written with the repet opertor. for hs other uses esies eing n lterntive to the repet opertor. for n lso e use with the put opertor to mnipulte strings n rrys. We will onentrte here on the mnipultion of strings. The tehnique will e seen gin lter when we isuss reting fountins with the imge opertor in hpter 13. Its use on rrys is essentilly the sme. In the following exmple, portion of the lphet is printe y ompletely ifferent tehnique thn expline in hpter 7. There, the string to e printe ws enlose within () for the show opertor to pint. Here, the hrters of the string will e rete y the for n put opertors. 74 the repet & for opertors

Chpter 8 72!"#$%& ()*+ 0 0 72 144 216 288 360 lern PS 8 10 %!PS-Aoe-2.0 EPSF-1.2 %%Title:for_4.eps %%BouningBox:36 36 378 60 /Times-Bol finfont 24 slefont setfont /str 44 string ef 0 1 43 {str exh up put} for 36 36 moveto str show 2 setlinewith 36 36 moveto 0 24 rlineto stroke Explining the progrm line y line, the first line mkes 24 point Times-Bol the urrent font. In the seon line, str is efine s n empty string with room for 44 hrters. 44 string oul e seen s (00000000000000000000000000000000000000000000) The 0s in this string re not the hrter zero, ut represent the ASCII eiml 0, the first entry of the 256 hrter ASCII hrt (see ppenix A). This entry oesn t hve visile hrter ssigne to it n is often referre to s null hrter. Down further on the hrt, you ll note tht eiml 33 is the! or exlmtion point. If str were printe now, the pge woul e lnk. PS lern for emo The thir line, 0 1 43 {str exh up put} for silly hnges str from (00000000000000000000000000000000000000000000) into (012345678910111213141516171819202122232425 40414243) It oes this y ounting from 0 to 43 n while oing so, repling str with the ount. The proeure reples the first 0 (null hrter) of str with 0, the seon 0 of str with 1, the thir 0 of str with 2, the fourth with 3 n so on until the 44th 0 is reple with 43. The ount is from 0 to 43. The string is 44 hrters in length. The first 0 is onsiere in position 0 n the lst 0 is in the 43r position. Looking t the syntx of put will explin this proeure in more etil. string inex integer put the repet & for opertors 75

Tking Avntge of PostSript Where: string inex is group of hrters. ientifies position within string; the first hrter is t inex. 0, the seon hrter, is t inex 1, n so on. integer is the integer to e put into position inex of string. In the previous exmple, 0 1 43 {str exh up put} for, fter the first ount of for you woul hve 0 str exh up put exh swithes the top two items on the stk, whih gives us str 0 up put up uplites 0, so we now hve str 0 0 put put now puts 0 in inex 0, or position 0 of str. The hnging string str woul look like this fter the first ount: (00000000000000000000000000000000000000000000) After the seon ount it woul e (01000000000000000000000000000000000000000000) n so on until it is fille: (012345678910111213141516171819202122232425 40414243) The next line, 36 36 moveto str show, pints the string str eginning t the lotion of 36 36. Nothing ppers till roun 36 234 euse there re no visile hrters ssigne to hrters 0 31 in the ASCII hrt n hrter 32 is the wor spe. The 33r hrter is the exlmtion point. See ppenix A. The lst two lines of the progrm rw vertil line mrking where the string egn t 36 36. In the next exmple, getintervl is use to get setion of string. In this se, it is use to otin only the visile portion of the string rete in the previous PostSript exmple. The syntx for getintervl is: string inex ount getintervl returning sustring Where: inex is the strting point into the string. ount is the numer of hrters strting t inex. For exmple, (efg) 2 3 getintervl returns (e) In this exmple, getintervl is efine s the setion of str strting t 33 plus the next 10 hrters ( totl of eleven hrters). 76 the repet & for opertors

Chpter 8 72!"#$%& ()*+ 0 0 72 144 216 288 360 lern PS 8 11 %!PS-Aoe-2.0 EPSF-1.2 %%Title:for_5.eps %%BouningBox:36 33 252 70 /Times-Bol finfont 36 slefont setfont /str 44 string ef 0 1 43 {str exh up put} for /piee {str 33 11 getintervl} ef 36 36 moveto piee show the repet & for opertors 77

Tking Avntge of PostSript 78 more on rwing

9 hpter Chpter 9 more on rwing There is more to o with urrent pths thn just stroke n fill them. The hrter of the stroke n fill n e hnge in vriety of wys. The pth n lso e use s kin of ookie utter or msk to hve imges pper only within its ounries. 9.1 line enings & orners There re three wys to en line. These re shown elow. In ll three, the lk line represents the pth n the gry is its with fter stroking. The first one is lle the utt p. Whtever the line s with, it oesn t ffet the line s length. The other two will inrese the line s length y the thikness. The utt p is the efult setting. 0 setlinep (the efult) 1 setlinep proues the roun p 2 setlinep proues the squre p There re lso three possile orners. 0 setlinejoin the miter join (the efult) 1 setlinejoin roun join 2 setlinejoin evel join Exmples of ll of this follows. Agin, the lk line represents the pth n the gry is its with fter stroking. more on rwing 79

Tking Avntge of PostSript 72 0 0 72 144 216 lern PS 9 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ps&joins.eps %%BouningBox:27 27 261 144 18 setlinewith 1 setlinejoin 1 setlinep % ottom.6 setgry 36 108 moveto 108 36 lineto 108 108 lineto 216 108 lineto stroke 2 setlinejoin 2 setlinep % mile.4 setgry 36 72 moveto 180 72 lineto 144 36 lineto 252 36 lineto stroke 0 setlinejoin 0 setlinep % top & k to efult.8 setgry 72 36 moveto 72 130 lineto 252 130 lineto 252 72 lineto stroke 9.2 she lines Dshe lines re rete y using the setsh opertor. The syntx is: rry offset setsh Where: rry is olletion of vlues tht lterntely speifies stroke segment n gp. There nnot e ny negtive vlues in the rry. offset shifts the line left or right. This n e seen in the following exmple. Eh line is 10 points wie n is the sme lternting sh of 20 point stroke n 10 point gp. Wht is ifferent out eh is the offset vlues of 0, 10, n -10 from top to ottom. There re itionl exmples in hpter 19, lirry of exmples. 80 more on rwing

Chpter 9 lern PS 9 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setsh_1.eps %%BouningBox:0 0 360 70 /vl {0 0 moveto 0 70 lineto} ef gsve.5 setgry 36 {10 0 trnslte vl} repet stroke grestore 10 setlinewith [20 10] 0 setsh % top 0 55 moveto 360 55 lineto stroke [20 10] 10 setsh % mile 0 35 moveto 360 35 lineto stroke [20 10] -10 setsh % ottom 0 15 moveto 360 15 lineto stroke 9.3 non-zero wining & the even/o rules The non-zero wining n the even/o rules etermine wht is fille or hollow within omplex pths. The most ovious pplition of the non-zero wining rule is in the rwing of letterforms tht hve holes (more preisely known s ounters) within them. Letterforms suh s A, e, n O re exmples. If the pths of the ounter re not rwn in the opposite iretion of the min letterform shpe, the ounter shpe will e fille. In the following exmple, oth irles were rwn with two pths. The intention is to mke one the outsie ege n the other the insie. In the first irle, oth the insie n the outsie pths re rwn in the sme iretion n fille. The pths were rwn gin in lk to show where they were rwn. Sine they were rwn in the sme iretion, oth irles fille. In the seon irle, the insie n outsie pths re rwn in opposite iretions. Sine this is the se, the smller insie pth eomes the insie ege of the irle. The retngle is nother exmple of the insie pth eing rwn in the opposite iretion of the outsie pth. The pths re use seon time n stroke to ientify the pths. A test for whether given point will e insie or outsie of fille re n e one y rwing line from tht point to the outsie. Strting with vlue of zero, when more on rwing 81

Tking Avntge of PostSript the line rosses lokwise pth one, n when the line rosses ounterlokwise pth sutrt one. If the result is zero, the point will e outsie the shpe, thus the nme non-zero wining rule. Notie the lines in the two irles in the exmple elow. On the left, the otte line represents the pth of oth irles. 144 0 1 2 0-10 72 0 0 72 144 216 288 360 lern PS 9 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:winingRule.eps %%BouningBox:16 34 364 182 % left irle; oth irles rwn in the sme iretion.7 setgry newpth 108 108 72 360 0 rn % lokwise 108 108 60 360 0 rn % lokwise fill % right irle; insie irle rwn in opposite iretion newpth 288 108 72 360 0 losepth rn % lokwise 288 108 60 0 360 losepth r % ounterlokwise fill % retngle ounterlokwise rwing.5 setgry 144 72 moveto 288 72 lineto 288 144 lineto 144 144 lineto losepth % lokwise rwing 150 78 moveto 150 138 lineto 282 138 lineto 282 78 lineto losepth fill The even-o rule is similr to the non-zero rule in tht it too helps to etermine wht prts re n re not fille within omplex pth. In figure 9 1, the letterform g is n exmple. The ounters of the first g re rwn in the opposite iretion of the outsie shpe. In the seon n thir g, the ounters re rwn in the sme 82 more on rwing

Chpter 9 lern PS 9 4 iretion. We get the expete results in the seon g, ut the thir ppers orret. The reson is the thir g is fille y using eofill, n lternte for fill. If eofill h een use on the first g, the results woul hve een the sme n een orret. 144 72 figure 9 1 0 0 72 144 216 The even-o rule uses the sme test line, rossing the pths s it leves the shpe. However, one is e every time pth is rosse. In the first n thir g ove, two pths re rosse, n even numer. It oesn t mtter wht iretion the pths re rwn in. In more omplex pths, the results re not s preitle s in figure 9 2. In figure 9 2, the first shpe is fille y fill, the seon y eofill. 72 figure 9 2 0 0 72 144 216 288 360 Other exmples of the non-zero wining n the even/o rules n e foun in hpter 19, lirry of exmples. 9.4 lipping Clipping fores ll susequent pinting to pper only within the ounries of more on rwing 83

Tking Avntge of PostSript pth. An exmple of lipping re re the mrgins tht form the printle re on lser printer s pge. If something is rwn eyon tht ounry, it s lippe or roppe. All the pth onstrution opertors suh s lineto, r n urveto n e use to rete lipping pth. The lipping tion shoul e ple etween gsve n grestore to prevent it from ffeting ll tht follows in the progrm. The gsve n grestore n e onsiere in sense n on/off swith for the lip. All grphis fter the lip n the next grestore will e roppe y the lippth. lip shoul lso e followe y the newpth opertor. Otherwise, the lipping pth my get stroke or fille. In the exmple elow, the first ox n zigzg re for referene. No lipping is tking ple. In the seon position, the ox lippth followe y newpth lips the zigzg. The thir prt shows wht hppens when newpth is left out. The lippth is lso stroke n hlf its with is lippe wy. newpth initilizes the lippth from pinting ut oes not ffet the lip. 72 0 0 72 144 216 288 360 lern PS 9 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:lip_3.eps %%BouningBox:12 30 326 115 /ox /zg {0 0 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth} ef {6 setlinewith.333 setgry 0 74 moveto 74-10 rlineto -74-10 rlineto 74-10 rlineto -74-10 rlineto 74-10 rlineto -74-10 rlineto 74-10 rlineto -74-10 rlineto} ef 36 36 trnslte ox stroke zg stroke 1 setlinewith 0 setgry gsve 108 0 trnslte ox lip newpth zg stroke grestore 84 more on rwing

Chpter 9 gsve 216 0 trnslte ox lip zg stroke grestore Other exmples of lipping n n exmple of the relte eolip n e foun in the lirry of exmples hpter. 9.5 setsreen Gry vlues re simulte on lser printers y rrnging the ots me y the printer into ptterns tht the eye sees s ifferent grys. The ots of the printer re groupe together to form ells. Within given re, if hlf the ots re use in eh ell, 50% gry is proue. The setsreen opertor ontrols the ot shpe of the ell n the frequeny (the numer of ells per inh) for the urrent olor. The efult for the NeXT lser printer, for exmple, is roun ot t 60 ells per inh t 0. The syntx for setsreen is: frequeny ngle proeure setsreen Where: frequeny is the numer of ells per inh. ngle is the ngle of the sreen in egrees. proeure ontrols the ot shpe of the ell. A numer of ifferent shpes re possile inluing squre, ovl n line ots. The size of the ot will epen on the vlue of the urrent olor. If the roun ot efult were hnge from 60 to 10 lines per inh n the ngle from 0 to 45, it woul e written s the following line of PostSript: 10 45 {up mul exh up mul 1.0 exh su} setsreen It woul look like figure 9 3. figure 9 3 The setsreen opertor ssigns priority vlue to eh pixel of eh ell of the hlftone. The priority etermines the rrngement of pixels for eh ell. The more on rwing 85

Tking Avntge of PostSript mount of pixels use will epen on the gry vlue neee. The rker the gry, the more pixels use. If 400 pi lser printer were set to hve 40 ells per inh, eh ell woul e 10x10 or ontin 100 pixels. If you oul see one of those ells n hrt it, it woul look like figure 9 4. The 100 pixels re ivie into n x y xis with its enter s the origin or 0 0. Eh pixel hs n x y vlue. The upper right is lwys 1 1, the lower left is lwys -1-1, n so on. If the ell were 20x20, the intermeite x y lotions woul just oringly. The setsreen proeure uses these x y lotions to etermine n ssign eh pixel s priority. -1 1 -.8 1 -.6 1 -.4 1 -.2 1.2 1.4 1.6 1.8 1 1 1-1.8 -.8.8 -.6.8 -.4.8 -.2.8.2.8.4.8.6.8.8.8 1.8-1.6 -.8.6 -.6.6 -.4.6 -.2.6.2.6.4.6.6.6.8.6 1.6-1.4 -.8.4 -.6.4 -.4.4 -.2.4.2.4.4.4.6.4.8.4 1.4-1.2 -.8.2 -.6.2 -.4.2 -.2.2.2.2.4.2.6.2.8.2 1.2-1 -.2 -.8 -.2 -.6 -.2 -.4 -.2 -.2 -.2.2 -.2.4 -.2.6 -.2.8 -.2 1 -.2-1 -.4 -.8 -.4 -.6 -.4 -.4 -.4 -.2 -.4.2 -.4.4 -.4.6 -.4.8 -.4 1 -.4-1 -.6 -.8 -.6 -.6 -.6 -.4 -.6 -.2 -.6.2 -.6.4 -.6.6 -.6.8 -.6 1 -.6-1 -.8 -.8 -.8 -.6 -.8 -.4 -.8 -.2 -.8.2 -.8.4 -.8.6 -.8.8 -.8 1 -.8 figure 9 4-1 -1 -.8-1 -.6-1 -.4-1 -.2-1.2-1.4-1.6-1.8-1 1-1 The esiest setsreen proeure to use s n exmple is {pop}. pop isrs the top numer on the stk. If the pir of numers is.2.4, the.4 woul e the one on top of the stk euse it woul e the lst numer reeive. pop woul isr it leving.2. Looking t the hrt of the ell, pop woul isr ll the y vlues, leving eh pixel s x s the pixel s priority numer. The left row therefore will ll e -1, the next row re ll -.8, n so on own eh row (see figure 9 5). -1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1-1 -.8 -.6 -.4 -.2.2.4.6.8 1 figure 9 5-1 -.8 -.6 -.4 -.2.2.4.6.8 1 86 more on rwing

Chpter 9 Using this priority system, ifferent gry vlues will fill s in figure 9 6. figure 9 6 10% 30% 50% 80% Atul size, it will look like this: Other proeures will luster the pixels in the enter s roun, ovl, or squre ot. There re numer of possile ptterns ville. In ition, the setsreen will ffet hlftone pitures. 9.6 setsreen with hlftones The setsreen opertor will ffet the imging of ll gry vlues, inluing snne gry sle pitures. setsreen oes not ffet 1-it pitures. The ot pttern in this se is lrey etermine. In the two exmples elow, squres pinte with 20%, 40%, 60%, n 80% lk re next to snne gry sle piture. Other setsreen exmples n e foun in hpter 19, lirry of exmples. more on rwing 87

Tking Avntge of PostSript 40 90 {pop} setsreen 144 72 0 0 72 144 216 288 360 40 45 {up mul exh up mul 1.0 exh su} setsreen 144 72 0 0 72 144 216 288 360 9.7 pthforll pthforll retrvels urrent pth n exeutes one of four proeures t eh instne of moveto, lineto, urveto, n losepth respetively. The syntx for pthforll is: movetopro linetopro urvetopro losepthpro pthforll Where: 88 more on rwing

Chpter 9 movetopro linetopro urvetopro losepthpro returns the x y lotion of the moveto then exeutes the movetopro proeure t every instne of moveto enountere. returns the x y lotion of the lineto then exeutes the linetopro proeure t every instne of lineto or rlineto enountere. returns the x y x 1 y 1 x 2 y 2 of the urveto n exeutes the urvetopro proeure t every instne of urveto or rurveto enountere. If the urve is me y the r, rn, or rto opertors, it will e onverte to the urveto equivlent. exeutes the losepthpro proeure t every instne of losepth. The x y oorintes returne re in user spe. The four proeures n perform ny opertion esire n n use the oorintes pushe on the stk. If the vlues re not use, they shoul e lere from the stk with the pop opertor. In the following exmple, I use pthforll to print the PostSript opertors use up to tht point. The lotion of eh lel is from the oorintes pushe onto the stk y pthforll. Note in the strt proeure the urrentpoint opertor. This pushes the x y oorintes of the urrent point fter the (moveto) show onto the stk to e use lter y the fin proeure. ontrol point 144 lineto urveto lineto 72 ontrol point lineto ontrol point moveto n losepth urveto ontrol point 0 0 72 144 216 288 360 lern PS 9 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:pthforll_1.eps %%BouningBox:34 34 360 220 /strt{moveto (moveto) show urrentpoint} ef /line {moveto (lineto) show} ef /urve{moveto (urveto) show /Times-Itli finfont 8 slefont setfont more on rwing 89

Tking Avntge of PostSript 90 more on rwing moveto (ontrol point) show moveto (ontrol point) show /Helveti-Bol finfont 10 slefont setfont} ef /fin {moveto( n losepth) show} ef /pth {36 36 moveto 36 144 lineto 216 72 144 216 252 144 urveto 72 0 rlineto 288 72 36 0 270 rn losepth} ef /Helveti-Bol finfont 10 slefont setfont 3 setlinewith 0.3 setgry pth stroke 0 setgry pth {strt} {line} {urve} {fin} pthforll newpth The following exmple uses pthforll in the sme wy s the esign Blst, foun in the eginning of hpter 2. All the musi notes re lote t the 3 pirs of x y for the urveto opertor generte y pthforll.

Chpter 9 lern PS 9 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:pthBlst.eps %%DoumentFonts:Sont %%BouningBox:0 0 310 310 0 0 moveto 310 0 lineto 310 310 lineto 0 310 lineto losepth stroke / {100 rn exh mo} ef / {100 rn exh mo} ef / {200 rn exh mo} ef / {200 rn exh mo} ef /e {300 rn exh mo} ef /f {300 rn exh mo} ef /note {moveto (q) show} ef.5 setlinewith 173417 srn /Sont finfont 10 slefont setfont 0 0 moveto 100 { e f urveto} repet {pop pop}{pop pop}{note note note}{} pthforll stroke more on rwing 91

Tking Avntge of PostSript 92 the CTM

10 hpter Chpter 10 the CTM CTM is the ronym for the Current Trnsformtion Mtrix. The CTM n e thought of s the oorinte system. A 1 inh squre n e efine n expete to print s 1 inh squre. It will print s 1 inh squre s long s the CTM hs not hnge. If the oorinte system or mtrix is oule in size, the squre will pper to e twie its intene size when use. The sle opertor is one of severl PostSript opertors use to trnsform the mtrix in some wy. The most ommon CTM opertors re: trnslte moves the lotion of the origin or 0 0. sle hnges the size of the oorinte system or mtrix. rotte rottes the oorinte system or mtrix. ont n perform the trnslte, sle, n rotte trnsformtions ll in one ommn. In prtiulr, unerstning the ont opertor will e neessry efore getting into hpters 11, 12, 13, n 14. The onepts overe here will esily pply to those four hpters. Lerning these vrious trnsformtions n provie numer of interesting visul opportunities. 10.1 trnsltion of the origin trnslte ws introue riefly in hpter 3, setion 3.4. There it ws use to position squre t ifferent lotions on the pge. Often, using trnslte to move roun the pge is the est wy to orgnize esign. Hving onsistent referene point to work from n e very hny. It filittes proeures eing use in one esign to e use in nother. It is importnt to rememer tht trnslte trnsforms the CTM, whih is prt of the grphi stte. Consier this exmple. Three squres re ple, the seon n thir using trnslte to move the origin to etermine their plement. Note tht gsve n grestore re not use to sve the grphi stte etween plement of squres. The white retngle represents the pge, the ifferent gri ptterns represent lotions of the CTM y using trnslte. As you n see, you oul hve n imge ple off the pge. When this progrm is printe, s fr s you know, the thir squre oesn t exist. the CTM 93

Tking Avntge of PostSript lern PS 10 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:trnslte_1.eps %%BouningBox:0 0 1098 1170 /squre { 0 0 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill} ef.5 setgry squre 360 432 trnslte squre 666 666 trnslte squre By using gsve n grestore to sve n restore the originl CTM etween 94 the CTM

Chpter 10 trnsformtions me y the trnslte opertor, grphis n more preitly e ple on the pge. 10.2 sle sle expets two rguments, n x n y vlue where 1 = the existing size, 0.5 = hlf the size, n 2 is twie the size. 0.5 2 sle woul therefore ompress the x xis y hlf n oule the y xis. sle ws introue riefly in setion 3.5. There the sle opertor ws use to mke squres of vrious sizes. As mentione there, you n get yourself into troule y not refully noting where sle is sequene with other opertors n otin unexpete results. Stuy the following exmple n note on whih line 1 8 sle is entere. 144 72 lern PS 10 2 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:sle_seq.eps %%BouningBox:30 30 330 288 /squre {0 0 moveto 72 0 lineto 72 72 lineto 0 72 lineto losepth } ef gsve % first 36 36 trnslte squre 1 8 sle % fter squre pth & trnslte stroke grestore gsve % seon 144 36 trnslte 1 8 sle % fter trnslte, efore squre pth squre the CTM 95

Tking Avntge of PostSript stroke grestore gsve % thir 1 8 sle % efore trnslte, squre pth, & stroke 252 4.5 trnslte % 8 x 4.5 = 36 squre stroke grestore 10.3 rotte As you might expet, rotte rottes the CTM. It expets one numer representing egree of rottion. A positive numer is ounterlokwise rottion n negtive numer is lokwise rottion. 0 is t the three o lok position. In the exmple elow, the first squre is norml, the seon is 45 rotte n the thir is -15 rotte. The rossing gry lines represent the hnge of lotion of the x y xis t the time the pth for squre is me n stroke. 144 72 PS lern 10 3 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rotte_1.eps %%Cretor:John F Shermn %%CretionDte:June 1990 %%BouningBox:34 70 360 180 /squre {0 0 moveto 72 0 lineto 72 72 lineto 0 72 lineto losepth stroke} ef 3 setlinewith gsve 36 72 trnslte squre grestore 96 the CTM

Chpter 10 gsve 144 72 trnslte 45 rotte squre grestore gsve 252 72 trnslte -15 rotte squre grestore As ws the se with sle, the sequene in whih rotte is use is very importnt. In the next exmple, rotte is use efore trnslte inste of fter. The sme egrees of rottion n trnsltion re use s in the previous exmple. Note the ifferene. Erlier we move the origin then rotte, now we rotte then move the origin. Agin the rossing gry lines represent the hnge of lotion of the x y xis. 144 72 0 0 72 144 216 288 360 PS lern 10 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rotte_2.eps %%BouningBox:0-12 360 270 /squre {0 0 moveto 72 0 lineto 72 72 lineto 0 72 lineto losepth stroke} ef 3 setlinewith gsve 36 72 trnslte the CTM 97

Tking Avntge of PostSript squre grestore gsve 45 rotte 144 72 trnslte squre grestore gsve -15 rotte 252 72 trnslte squre grestore It lso mkes ifferene whether the urrent point for grphi is me efore or fter the rottion. Note when rotte is use in the exmple elow. A urrent oes not move with the rottion of the CTM. 144 72 rotte1 rotte2 PS lern 10 5 0 0 72 144 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rotte_3.eps %%BouningBox:54 72 162 180 /Times-Bol finfont 24 slefont setfont 36 36 trnslte.5 setlinewith gsve % moveto fter rottion of CTM 45 rotte 72 36 moveto (rotte1) show grestore gsve % moveto efore rottion, ut (rotte2) show is fter 72 36 moveto 45 rotte (rotte2) show grestore 98 the CTM

Chpter 10 10.4 ont The mnipultion of the urrent trnsformtion mtrix using ont will lso e useful in unerstning the mkefont, imge, n imgemsk opertors expline in lter hpters. The mtrix n e thought of s n elsti gri tht sles ll grphis to the pge. If the CTM were oule, everything woul print twie the intene size. The trnslte, sle, n rotte opertors hnge the CTM, n their three omine opertions n e one t one with the ont opertor. ont is more powerful ut it s less intuitive thn the other three. In figure 10 1 elow, irle is rwn on gri representing the CTM. 0 1 1 1 0 1 1 1 figure 10 1 0 0 1 0 0 0 1 0 If tht gri ws sle to twie its norml size on the x xis, the with of the irle woul lso e twie its norml size. This oul hve een one with 2 1 sle ut it n lso e one with [2 0 0 1 0 0] ont The first numer of the rry sles the x xis n the fourth numer sles the y xis. If we wnte the height of the irle to e oule, the mtrix rry woul e [1 0 0 2 0 0]. Referring to the first n fourth numers, 1 is 100% or tul size,.5 is 50% n 3 is 300%. If there hs lrey een sle pplie to the CTM, the new trnsformtion will e in ition to the existing CTM. An exmple of the sle irle with ont follows: 72 0 0 72 144 216 the CTM 99

Tking Avntge of PostSript lern PS 10 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:irle y2.eps %%BouningBox:34 34 220 110.5 setgry 4 setlinewith newpth 72 72 36 0 360 r stroke 0 setgry [2 0 0 1 0 0] ont newpth 72 72 36 0 360 r stroke There re other trnsformtions possile with ont. The seon n thir numers skew the CTM up or own n left or right. Figure 10 2 is n exmple of skewing the x xis. The seon numer ontrols the ngle of the x xis n the thir ontrols the ngle of the y xis. Figure 10 2 is n exmple of [1 1 0 1 0 0] ont. The 1 in the seon position of the mtrix rry skews everything up 45. 1 1 0 1 1 0 figure 10 2 0 0 H the mtrix een [1-1 0 1 0 0] ont, the shift woul hve een own 45. Unfortuntely, s you n see, the egree of the esire shift is not wht is entere into the mtrix. There is lultion se on the esire ngle θ (egree) tht nees to e one for the seon n thir numers. The tngent of θ is wht is require for the seon n thir positions of the mtrix rry. Appenix B ontins tle of tngent vlues for eh egree for onvenient referene. To rotte the x xis ounterlokwise 30, tn30, whih equls 0.5774, is entere s the seon numer of the mtrix rry. In the following exmple, the squre is skewe 30 y the ont opertor. The lk line is rotte 30 y using rotte s referene. 100 the CTM

Chpter 10 144 72 0 0 72 144 216 PS lern 10 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ont_1.eps %%BouningBox:72 36 252 150 72 36 trnslte gsve % gry ox.5 setgry [1 0.5774 0 1 0 0] ont 0 0 moveto 0 72 lineto 72 72 lineto 72 0 lineto losepth fill grestore gsve % lk line 3 setlinewith 30 rotte 0 0 moveto 200 0 lineto stroke grestore If oth xes were skewe the sme egree n iretion, it woul pper tht we h me the equivlent of 30 rottion. Not quite, euse [1.5774 -.5774 1 0 0] ont is not the sme s 30 rotte Even though 30 rottion hs ourre, the squre is no longer the sme size. Note the ifferene in the with n height of the squre in ont_1.eps. The with is now greter thn the height. This is esily seen in the next exmple. The sme squre is oule skewe for 30 rottion n norml 30 rottion. the CTM 101

Tking Avntge of PostSript 144 72 0 0 72 144 216 PS lern 10 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ont_2.eps %%BouningBox:30 36 252 150 72 36 trnslte /squre {0 0 moveto 0 72 lineto 72 72 lineto 72 0 lineto losepth} ef gsve.5 setgry [1.5774 -.5774 1 0 0] ont squre fill grestore gsve 30 rotte squre stroke 3 setlinewith 0 0 moveto 200 0 lineto stroke grestore The proper metho of rottion with the ont opertor n e omplishe with this syntx: [osθ sinθ -sinθ osθ 0 0] ont whih is in this se [os30 sin30 -sin30 os30 0 0] ont The vlues use for this opertion n e foun in ppenix B. A rottion exmple follows: 102 the CTM

Chpter 10 72 0 0 72 144 216 PS lern 10 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ont&rotte.eps %%BouningBox:34 36 252 140 72 36 trnslte gsve % 30 egrees.5 setgry [.866.5 -.5.866 0 0] ont 0 0 moveto 0 72 lineto 72 72 lineto 72 0 lineto losepth fill grestore gsve 3 setlinewith 30 rotte 0 0 moveto 200 0 lineto stroke grestore A omine sle n rottion n e performe with the ont opertor in one mtrix rry. In the next exmple, the ox is rwn s 1 unit y 1 unit. Using ont, we n sle it to 72 y 72 n rotte it 30. The syntx for this mtrix is [s*osθ s*sinθ s*-sinθ s*osθ 0 0] ont where s is the sle ftor. Clulte, it will e: [62.352 36-36 62.352 0 0] ont An exmple follows: the CTM 103

Tking Avntge of PostSript 72 0 0 72 144 216 lern PS 10 10 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ont_r&s.eps %%BouningBox:34 36 252 140 72 36 trnslte gsve.5 setgry [62.352 36-36 62.352 0 0] ont 0 0 moveto 0 1 lineto 1 1 lineto 1 0 lineto losepth fill grestore gsve 3 setlinewith 30 rotte 0 0 moveto 200 0 lineto stroke grestore Finlly, the fifth n sixth numers of the mtrix rry perform trnsltion. In the next exmple, the 72 36 trnslte is use only y the rotte line. The squre is positione y the ont opertor. 72 0 0 72 144 216 104 the CTM

Chpter 10 PS lern 10 11 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ont_ll.eps %%BouningBox:34 36 252 140 gsve.5 setgry [62.352 36-36 62.352 72 36] ont 0 0 moveto 0 1 lineto 1 1 lineto 1 0 lineto losepth fill grestore gsve 72 36 trnslte 3 setlinewith 30 rotte 0 0 moveto 200 0 lineto stroke grestore the CTM 105

Tking Avntge of PostSript 106 vne type

11 hpter Chpter 11 vne type The previous hpter on type only overe the sis of working with type. There re numer of powerful PostSript opertors for moifying fonts n kerning fonts. Kerning is performing ustom hrter sping for etter legiility, form, or speil effet. For exmple, the lower se o is spe ifferently in the wors Do n To. Creful ttention to kerning woul tuk the o uner the T for proper lettersping. 11.1 moifying existing fonts As isusse in hpter 7, the outlines of fonts re store s 1 point outlines. To e more preise, they re store within mtrix tht sles it to 1 point squre. This mtrix is inepenent of the CTM, ut ts in muh the sme wy. In hpter 10, we mnipulte the CTM with the ont opertor. The font mtrix is mnipulte with the mkefont opertor. The next two PostSript frgments re equivlent: /Helveti-Bol finfont 100 slefont setfont /Helveti-Bol finfont [100 0 0 100 0 0] mkefont setfont The mkefont opertor expets mtrix rry tht ts in the sme wy s the mtrix rry use with ont. The first numer of the rry represents the x sle, the fourth numer represents the y sle. The other four remining numers lso t the sme s expline in setion 10.4. TTTT T PS lern 11 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:mkefont_1.eps %%BouningBox:0 0 340 75 /Helveti-Bol finfont [150 0 0 100 0 0] mkefont setfont vne type 107

Tking Avntge of PostSript 0 0 moveto (T) show /Helveti-Bol finfont [125 0 0 100 0 0] mkefont setfont 100 0 moveto (T) show /Helveti-Bol finfont 100 slefont setfont 188 0 moveto (T) show /Helveti-Bol finfont [75 0 0 100 0 0] mkefont setfont 255 0 moveto (T) show /Helveti-Bol finfont [50 0 0 100 0 0] mkefont setfont 308 0 moveto (T) show All the Ts ove re Helveti-Bol 100 point, t lest in height. The first is sle 150%, the seon 125%, the thir is norml, the fourth is onense 75%, n the fifth is onense 50%. The Helveti-Nrrow font on the LserWriter Plus is onense in this fshion (see setion 15.3). It is not seprte rwing of Helveti like Helveti Conense, ut mthemtilly onense version of the font. In the next exmple, the thir numer of the mtrix rry is given vlue n the first n fourth re set to 100. The thir numer of the mtrix skews the y xis left n right. The numer unfortuntely oes not represent the ngle tht the mtrix is skewe (see 10.4). It is the prout of this eqution: y tnθ See the preeing hpter for etile informtion on mtrix mnipultion. TTTTT lern PS 11 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:mkefont_2.eps %%BouningBox:0 0 360 75 /Helveti-Bol finfont % -45 [100 0-100 100 0 0] mkefont setfont 75 0 moveto (T) show /Helveti-Bol finfont % -20 [100 0-36.4 100 0 0] mkefont setfont 105 0 moveto (T) show /Helveti-Bol finfont 100 slefont setfont 108 vne type

Chpter 11 150 0 moveto (T) show % norml /Helveti-Bol finfont % 20 [100 0 36.4 100 0 0] mkefont setfont 195 0 moveto (T) show /Helveti-Bol finfont % 45 [100 0 100 100 0 0] mkefont setfont 225 0 moveto (T) show All the Ts ove re gin Helveti-Bol 100 point in size. The first T is olique 45, the seon is 20, the thir is norml, the fourth is t 20, n the fifth is t 45. In the next exmple, the letterforms get strethe more rmtilly when the x xis is skewe. Agin, the type is the equivlent of 100 point. Now the seon igit of the mtrix rry is hnge. The numer is rrive t in the sme wy s efore, exept the ngle movement will e up n own. This exmple is written ifferently to help keep trk of where the urrent point is lote for eh T. An X is rwn t eh T s origin for point of referene. Even though the origins of the Ts mke horizontl row, the selines of the Ts in effet rotte euse of the skewing of the x xis. All the Ts elow re gin Helveti-Bol 100 point. The first T is olique 45, the seon is 20, the thir is norml, the fourth is t 20, n the fifth is t 45. T TTTT lern PS 11 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:mkefont_3.eps %%BouningBox:0 0 360 195 /x {-6-6 moveto 6 6 lineto stroke -6 6 moveto 6-6 lineto stroke} ef.5 setgry % kgroun 0 0 moveto 360 0 lineto 360 195 lineto 0 195 lineto losepth fill vne type 109

Tking Avntge of PostSript 10 50 trnslte 1 setgry % seline 0 0 moveto 370 0 rlineto stroke 0 setgry.5 setlinewith /Helveti-Bol finfont % -45 [100-100 0 100 0 0] mkefont setfont x 0 0 moveto (T) show 70 0 trnslte /Helveti-Bol finfont % -20 [100-36.4 0 100 0 0] mkefont setfont x 0 0 moveto (T) show 70 0 trnslte % norml /Helveti-Bol finfont 100 slefont setfont x 0 0 moveto (T) show 70 0 trnslte /Helveti-Bol finfont % 20 [100 36.4 0 100 0 0] mkefont setfont x 0 0 moveto (T) show 70 0 trnslte /Helveti-Bol finfont % 45 [100 100 0 100 0 0] mkefont setfont x 0 0 moveto (T) show 11.2 lettersping with show The four PostSript kerning opertors re show, withshow, withshow, n kshow. Eh provies ifferent opportunities. In hpter 18 on PostSript Level 2, there re four itionl type opertors. show provies mens to or sutrt overll hrter sping oth vertilly n horizontlly. The syntx for show is: x y string show Where: x s or sutrts spe horizontlly in the string. y s or sutrts spe vertilly in the string. string is the hrters or wors ffete. In the following exmple, string is tightene, strethe, n shifte vertilly. The vertil justment is typilly use y non-romn fonts. 110 vne type

Chpter 11 144 s 72 spe sutrts spe steps up 0 0 72 144 216 lern PS 11 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:show_1.eps %%BouningBox:36 36 264 170 /Pltino-Romn finfont 36 slefont setfont 36 144 moveto 6 0 (s spe) show 36 108 moveto -6 0 (sutrts spe) show 72 36 moveto 0 6 (steps up) show 11.3 kerning with withshow withshow kerns single hrter within string. Its syntx is: x y hrter string withshow Where: x s or sutrts horizontl spe fter the hrter. y s or sutrts vertil spe fter the hrter. hrter is either ientifie y its eiml or otl hrter oe from the ASCII hrt. See ppenix A. In the next exmple, the spe is reue fter the W, whih therefore rings the A loser. The only ifferene etween the two WASHINGTONs is tht the top W is ientifie y the eiml 87 n the ottom W y the otl 127. The efult ientifition is eiml. If otl oe is use, it nees the 8# prefe s lel. vne type 111

Tking Avntge of PostSript 144 WASHINGTON 72 WASHINGTON 0 0 72 144 216 288 360 lern PS 11 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:withshow_1.eps %%BouningBox:36 36 360 144 /AvntGre-Demi finfont 48 slefont setfont 36 108 moveto % Deiml tle -6 0 087 (WASHINGTON) withshow 36 36 moveto % Otl tle -6 0 8#127 (WASHINGTON) withshow 11.4 kerning with withshow withshow is the omintion of show n withshow. It oth kerns single hrter within string n s or sutrts overll hrter sping oth vertilly n horizontlly. Its syntx is: x y hrter x s y s string withshow Where: x y s or sutrts horizontl spe fter the hrter. s or sutrts vertil spe fter the hrter. hrter is either the eiml or otl hrter oe for the hrter. x s y s s or sutrts horizontl spe in the string. s or sutrts vertil spe in the string. In the next exmple, the wor Typogrphy on top is set normlly with show. In the mile n ottom, the spe fter the T is reue to kern the y unerneth n overll hrter sping is tightene y 1 point. Agin, the hrter kerne is ientifie y its eiml or otl hrter oe. 112 vne type

Chpter 11 144Typogrphy Typogrphy 72 Typogrphy 0 0 72 144 216 lern PS 11 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:withshow 1.eps %%BouningBox:18 30 288 200 /AvntGre-Demi finfont 48 slefont setfont 18 158 moveto (Typogrphy) show % using Otl tle 18 97 moveto -3 0 8#124-1 0 (Typogrphy) withshow % using Deiml tle 18 36 moveto -3 0 084-1 0 (Typogrphy) withshow 11.5 kshow The kshow opertor hs muh ifferent strtegy for kerning thn the previous three PostSript opertors. Its syntx is: proeure string kshow The proeure is exeute fter the positioning of eh hrter. In the next exmple, two ifferent proeures re performe on the sme wor. In the top wor, the hrter sping of RAINBOW is omplishe y using the proeure -3 0 rmoveto. After R is positione, the new urrent point is move to the right of its hrter with. The proeure -3 0 rmoveto shifts the urrent point left 3 points. Other mnipultions esies the justment of the urrent point n our within vne type 113

Tking Avntge of PostSript the proeure. With the RAINBOW on the ottom, the proeure lso hnges the urrent gry etween eh hrter setting. Any numer of tions n e performe fter eh hrter. The intention of this opertor, however, is to give the opportunity to iniviully kern the hrters of string. Thus its nme, kernshow. To omplish this iniviul kerning fter eh hrter of the string (exept the lst), two numers re pushe onto the stk. In the se of RAINBOW, fter the R is set, the eiml oes for R n A re pushe onto the stk. They re 82 n 65. After the A is set, the eiml oes for A n I re pushe onto the stk. This ours fter eh hrter of the string exept for the lst. These numers n e use y the proeure to mke ustom sping eision se on whih two hrters re esie eh other. This omprison is not neee fter the lst hrter. If unuse, these numers re left on the stk: 82 65 65 73 73 78 78 66 66 79 79 87 Sine they re not use y the proeure in this exmple, we nee to isr them. This is one with the 12 {pop} repet. The numers n lso e isre within the kshow proeure. RAINBOW 144 72 RAINBOW PS lern 11 7 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:kshow_1.eps %%BouningBox:20 36 360 162 /AvntGre-Demi finfont 72 slefont setfont 18 108 moveto {-3 0 rmoveto} (RAINBOW) kshow 12 {pop} repet.9 setgry 18 36 moveto {urrentgry.12 su setgry pop pop} (RAINBOW) kshow Another exmple follows: 114 vne type

Chpter 11 72 M*A*S*H 0 0 72 144 216 288 360 PS lern 11 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:M*A*S*H.eps %%BouningBox:36 36 330 90 /Helveti-Bol finfont 72 slefont setfont % proeure lowers the sterisk & then returns to seline /putasterisk {0-14 rmoveto (*) show 0 14 rmoveto pop pop} ef 36 36 moveto {putasterisk} (MASH) kshow vne type 115

Tking Avntge of PostSript 116 the imge opertor / sn

12 hpter Chpter 12 the imge opertor / sn The imge opertor is use to ontrol pinting snne pitures. It n lso e use to rete vriety of ptterns n lens. Disussion of the imge opertor will e ivie over two hpters. This hpter onentrtes on snne pitures n hpter 13 will fous on reting ptterns n lens. In hpter 14, the imgemsk opertor, vrition of imge, will e expline. 12.1 introution The imge opertor n reeive the t for the piture it retes from numer of soures. The most ovious soure woul e the t from snner of some kin. In setions 12.3 n 12.4, the tritionl use of the imge opertor is expline with first very simple piture of shmrok n then snne piture. The other soure of t n e provie y the progrmmer. The provie t is usully some ritrry hrters tht n rete pttern or the mens to rete smooth len of olor. See hpter 13. In ll ses, either snne t for piture or ritrry hrters for pttern, t quisition proeure of some kin is neee. A t quisition proeure ontrols how the imge opertor reeives or retes the informtion neee to pint piture. The syntx of imge is: with height its mtrix pro imge Where: with is the with of the piture in ells or pixels. height is the height of the piture in ells or pixels. its is the numer of its of informtion per ell or pixel. It n e 1, 2, 4, or 8. mtrix is the piture s oorinte system. pro is the t quisition proeure tht otins or retes the piture t. imge is the PostSript opertor. the imge opertor / sn 117

Tking Avntge of PostSript 12.2 simple igitize pitures Snne pitures n e thought of s omplex pint y numer oloring projet iviing piture into little squres. Eh squre, or pixel, woul hve oe ssigne to it se on the vlue or the olor it represents. The pixels woul e rrnge into rows n olumns tht woul e use to esrie the piture s with n height. When the piture is pinte y the imge opertor, imge uses one of four oing shemes to pint the pixel prtiulr vlue. Depening how the piture ws originlly snne, the piture n e pinte s 1-it, 2-it, 4-it, or 8-it piture. This is the oing sheme for lk n white piture. Color pitures woul e multiples of this. The ifferene etween eh of these oing shemes is the numer of ifferent grys they n proue. The size of the file inreses s the numer of its inrese. These re the possile its n wht they n represent: 1-it 2 grys. Atully either lk or white. Vlue is either 0 or 1. 2-it 4 grys. Blk, white, n 2 intermeite grys. Vlue is either 0, 1, 10, or 11 (ounting from eiml 0 to 3 in inry). 4-it 64 grys. Blk, white, n 62 intermeite grys. 8-it 256 grys. Blk, white, n 254 intermeite grys. The its tht we re using to esrie vlue re inry its. Binry is numering system tht only uses 0 n 1. In 1-it oing, the vlue of the pixels will e either 0 or 1. 0 is the oe for lk, 1 the oe for white. We ll ome k to the other its lter. Looking further t 1-it piture, figure 12 1 represents piture ivie into 256 pixels. There re 16 rows n 16 olumns. figure 12 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 If you follow the oloring ssignments n pint the 0s lk n the 1s white, piture will emerge. See figure 12 2. 118 the imge opertor / sn

Chpter 12 figure 12 2 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 It s the jo of the snner to get ll this for you. Otherwise, it woul e mjor jo to onstrut piture. The snner uses the intensity of light reflete k from piture to ssign vlue to eh piture. The numer of its the snner s softwre is set for will etermine how the light is ivie. Appenix A is n ASCII tle of five ifferent oing shemes, eh ifferent wy of ounting from 0 to 255. In prtiulr, we re intereste in ASCII, hexeiml, n inry oe ssignments. The ASCII tle ontins our lphet within the 256 entries. Note tht there isn t visile hrter for ll 256. Hexeiml ounts from 0 to 256 using only the numers 0 9 n the hrters A F. The inry ounts from 0 to 255 in inry (using 0 n 1). The imge opertor uses the inry tle to give pixels vlue. It stores the pixel vlue s either ASCII or hexeiml t. As mentione efore, 0 n 1 re the two possile vlues for it. In the 1-it oing sheme, 0 n 1 represent lk n white. Eh entry of the inry tle of ppenix A ontins 8 its. Therefore, eh entry of the tle n represent 8 pixels of piture using the 1-it oing sheme. The first 8 pixels strting t the lower left of figure 12 2 hve the vlues 1 1 1 1 1 1 1 1. Consulting ppenix A, 11111111 will e foun t eiml 255. There isn t visile hrter in the ASCII tle n it s FF in hexeiml. Therefore, the first 8 pixels of figure 12 2 n e sve s either ASCII 255 or hexeiml FF. See figure 12 3 elow. This oing woul ontinue for every row of the piture. figure 12 3 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 This inry is represente y ASCII 31 or Hexeiml 1F This inry is represente y ASCII 255 or Hexeiml FF { {1 The ASCII tle ontins the hrters tht my e type from stnr omputer keyor plus mny other speil hrters whose lotion my vry from one system to nother suh s Ë or ß. There re totl of 256 possile hrters. The iffiulty in using the ASCII tle in esigning the shmrok_1.eps exmple ws hving visile ASCII hrter for mny of the prtiulr inry ptterns neee. Therefore, in the next exmple hexeiml ws the imge opertor / sn 119

Tking Avntge of PostSript use. However, mny snners sve their files using the ASCII tle euse the file will e hlf the size. At eiml 97, there is the ASCII hrter (1 yte of storge), n the hexeiml 61 (2 ytes of storge). The following is n exmple of how figure 12 2 woul e written s PostSript progrm. It is not snne piture, ut it is written in the sme wy snne piture woul e written, only on smller sle. Setion 12.3 will emonstrte how the sme tehnique is pplie to snne photogrph. lern PS 12 1 imge emo %!PS-Aoe-2.0 EPSF-1.2 %%Title:shmrok_1.eps %%BouningBox:0 0 160 160 /pistr 2 string ef /shmrok { 16 16 1 [.1 0 0.1 0 0] {urrentfile pistr rehexstring pop} imge } ef shmrok FF 1F FE 3F 9E 39 0E 70 06 60 02 40 00 00 00 00 00 00 04 20 08 19 90 0F F0 0F E0 07 E0 07 F0 0F % frme 0 0 moveto 160 0 lineto 160 160 lineto 0 160 lineto losepth stroke In shmrok_1.eps ove, the proeure /shmrok is efine y the imge opertor n its operns. Figure 12 4 lels the rguments (require informtion for n opertor) for the imge opertor. 120 the imge opertor / sn

Chpter 12 16 pixels wie 16 pixels high 1 it per pixel mtrix:.1 mkes eh pixel 10 points in size figure 12 4 16 16 1 [.1 0 0.1 0 0] {urrentfile pistr rehexstring pop} imge t quisition proeure PostSript opertor Let s look loser t eh rgument for imge: The with n height re the numer of ells wie n high for the piture. In the exmple ove, the piture's with n height is 16 y 16 pixels. The its vlue is 1 sine the piture is 1-it piture. Next is the mtrix rry whih etermines the size of the piture. This mtrix rry opertes ifferently with imge thn for ont (setion 10.4) n mkefont (setion 11.1). With ont n mkefont, if we wnte n ojet lrger, we woul hve use lrger numer in the first n fourth position of the rry. Here it is the opposite; smller numer is use. The lultion is ifferent with imge euse of ifferene in how it hnles pitures. It n e expline in this wy. H the mtrix rry een [1 0 0 1 0 0], the shmrok woul e s shown in figure 12 5. figure 12 5 Figure 12 5 is this size euse the 1 in the [1 0 0 1 0 0] mtrix rry mens eh pixel is tul size. The 16x16 pixel with n height will mesure 16x16 points. A 16x16 pixel with n height using [.1 0 0.1 0 0] mtrix is 160x160 points. This is rrive t y iviing 16 y.1 equling 160, n 160 ivie y 16 equls 10. With imension of 160x160, n the ells with n height eing 16x16, we then know the iniviul pixels will e 10 points squre. If the mtrix rry h een [.2 0 0.2 0 0] the pixels woul e 5 points squre. {urrentfile pistr rehexstring pop} is the t quisition proeure for the imge opertor. urrentfile ientifies tht the t for the piture will follow fter shmrok is use in the progrm. /pistr efines spe lrge enough for string two hrters long. pistr is temporry holing ple for the t for eh row of the piture. The first two hrters tht mke up the first row of the shmrok re the two hexeiml hrters FF n 1F. They represent the two sets of inry hrters 11111111 n 00011111. rehexstring ientifies tht the t is in hexeiml. pop lers the pistr so the proeure n e repete. The proeure is repete until the 16 rows of t in inrements of two re fille. Writing the progrm in this wy permits ll the t for the piture to follow the PostSript ommns tht ontrol its pinting. In most ses, snne pitures re very lrge files. Hving the t follow PostSript heer permits esier eiting of the progrm. the imge opertor / sn 121

Tking Avntge of PostSript 12.3 snne pitures This piture ws otine y using snner n sving the file in PostSript formt y its softwre. I hve eite the PostSript from its originl form supplie y the snning softwre. The originl file h efinitions to ommote numer of ifferent snning situtions n I wish to fous on the si similrity with the previous shmrok exmple. The progrm tht proue the piture follows, minus the piture t to sve spe. It woul hve tken up out eight pges. PS lern 12 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:relief.eps %%BouningBox:0 0 224 225 /height 225 ef /with 224 ef /nheight height neg ef /pistr 112 string ef /mkepiture { with height 4 [with 0 0 nheight 0 height] { urrentfile pistr restring pop } imge } ef gsve {1 exh su} settrnsfer with height sle mkepiture ˇˇˇˇˇ fl ªª ª ª ª πógfutvueddugfyzô flfl 25.6K of piture t, et Ì Ì ª ö óyxºããfiˇˇˇˇ à õœˇˇ ºÃÕà º Ôˇ grestore 122 the imge opertor / sn

Chpter 12 This progrm is silly the sme s shmrok_1.eps ut with few ifferenes. First, mny of the vlues hve een given nmes suh s height n with. This setion of the progrm is written y the snning softwre so the sme file eginning n e use for every file it retes. height efines the height of the piture to e 225. with efines the with of the piture to e 224. nheight efines height to hve negtive vlue. The reson for this is mny snners igitize from the top own s oppose to from the ottom up. Hving the trnsformtion mtrix e [with 0 0 nheight 0 height] justs for this y flopping the piture. pistr, s isusse t the en of setion 12.2, is holing spe for string. In this efinition, the holing ple is 112. This woul hol enough t for one row of the piture. mkepiture efines the imge opertion s shmrok i for the shmrok_1.eps exmple erlier. with height 4 [with 0 0 nheight 0 height] is the sme s 224 225 4 [224 0 0-255 0 255]. The piture is 4-it piture (64 grys) n the mtrix rry mps it, so it is very smll. To get it to the right size, with height sle sles the piture up to 224 225. {1 exh su} settrnsfer inverts the piture. Without this line, the piture woul pper s negtive. This ompenstes for the wy the snner sns the piture. 12.4 seon version of shmrok The previous exmple, relief.eps, is 4-it piture. To emonstrte how 4-it n 8-it pitures work with their t, the next exmple is version of shmrok written s 2-it piture. A 4-it n 8-it version woul e similr. the imge opertor / sn 123

Tking Avntge of PostSript lern PS 12 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shmrok_2.eps %%BouningBox:0 0 160 160 /pistr 4 string ef /shmrok {16 16 2 [.1 0 0.1 0 0] {urrentfile pistr rehexstring pop} imge} ef shmrok 55 40 55 55 6A A0 2A A9 42 A0 2A 81 00 A8 2A 00 00 28 28 00 00 08 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 08 00 42 80 02 00 6A 00 00 81 6A 00 00 A9 68 00 00 29 68 00 00 29 55 00 00 55 Figure 12 6 enlrges the first two rows of shmrok_2.eps for etter look t the it vlues. 10 is light gry, 01 is rk gry, 00 is lk, n if there h een 11 it woul e white. 01 10 10 10 10 10 00 00 00 10 10 10 10 10 10 01 figure 12 6 01 01 01 01 01 00 00 00 01 01 01 01 01 01 01 01 { { This inry is represente y ASCII 064 or Hexeiml 40 This inry is represente y ASCII 085 or Hexeiml 55 124 the imge opertor / sn

Chpter 12 In 1-it piture, 8 its is the t for 8 pixels. In 2-it piture, 8 its is the t for 4 pixels. With 4-it, it s 2 pixels n with 8-it, it s one pixel. This is overe more in the next hpter. When piture is snne, the tre-off will e the size of the file versus the qulity of the piture. Figure 12 7 is photogrph ivie into four vertil segments, 1-it, 2-it, 4-it, n 8-it in orer. The 1-it setion is out 4.5 K n the 8-it is just over 26K. figure 12 7 the imge opertor / sn 125

Tking Avntge of PostSript 126 the imge opertor / ptterns

Chpter 13 13 hpter the imge opertor / ptterns In this seon hpter on the imge opertor, it will e shown how imge n e retively use for mking ifferent kins of ptterns n for mking fountins, lso known s lens or rmps. See lso the next hpter on imgemsk whih n lso e use for mking ptterns. 13.1 reting ptterns with the imge opertor shmrok_2.eps oul e written in suh wy s to proue vrious ptterns. In shmrok_2.eps the t for shmrok ws only use one. However, if the height (or numer of rows) were to e oule n nme given to the t for shmrok, the piture oul e use twie to fill the spe. lern PS 13 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shmrokTwie_1.eps %%BouningBox:0 0 80 160 /shmrok <55 40 55 55 6A A0 2A A9 42 A0 2A 81 00 A8 2A 00 00 28 28 00 00 08 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 08 00 42 80 02 00 6A 00 00 81 6A 00 00 A9 68 00 00 29 68 00 00 29 55 00 00 55> ef 16 32 2 [.2 0 0.2 0 0] { shmrok } imge the imge opertor / ptterns 127

Tking Avntge of PostSript H the sme thing een one with shmrok_1.eps, isster woul strike. lern PS 13 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shmrokTwie_2.eps %%BouningBox:0 0 80 160 /pistr 2 string ef /shmrok { 16 32 1 [.2 0 0.2 0 0] {urrentfile pistr rehexstring pop} imge} ef shmrok FF 1F FE 3F 9E 39 0E 70 06 60 02 40 00 00 00 00 00 00 04 20 08 19 90 0F F0 0F E0 07 E0 07 F0 0F % frme 0 0 moveto 160 0 lineto 160 160 lineto 0 160 lineto losepth stroke It looks like this euse rehexstring will gole up everything fter shmrok is use, inluing the 0 0 moveto 160 0 lineto 160 160 lineto 0 160 lineto losepth stroke looking for piture t. An error will our euse the t ville n the efine piture size o not mth. 13.2 imgewor.eps Similr to shmroktwie_1.eps, the following is PostSript progrm using the imge opertor to mke pttern: 128 the imge opertor / ptterns

Chpter 13 lern PS 13 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:imgeWor.eps %%BouningBox:0 0 240 100 /wor (John) ef 24 10 2 [.1 0 0.1 0 0] { wor } imge In the piture ove, the inry for the wor John is repetely use until retngle 24 y 10 is forme s shown in figure 13 1. figure 13 1 { { { { J o h n { { The inry for the wor John is: 01001010 or J 01101111 or o (two gry then two white) 01101000 or h 01101110 or n The wor just one woul look like this: Looking t the progrm gin, the strip ove is use over n over gin until the piture retngle is omplete. If /wor ove were to e reefine to (John S), it woul look like figure 13 2. figure 13 2 the imge opertor / ptterns 129

Tking Avntge of PostSript It ppers stripe euse the 6 hrters of (John S) ivie evenly into the 24 pixel with of the piture. The previous exmples of imgewor.eps use the piture t to mke 2-it imge, mening every pixel of the piture hs 2 its of informtion, or four possile vlues. A pixel is n iniviul squre of vlue. For exmple, the inry for J is 01001010 n it will e ivie into four prts ontining 2 its eh s 01 00 10 10. The numer 01 represents rk gry, n 10 light gry, 00 represents lk, n 11 is white. A 2-it piture therefore n only hve 4 levels of gry: lk, white, n two grys. Shoul J e use in 1-it piture, J woul look like this: 01001010 s 1-it piture is lk, white, lk, lk, white, lk, white, lk. A 1-it piture hs 2 possile levels lk n white. The monitor of the Mintosh Plus n SE omputers is 1-it sreen. The pixels on the sreen re either lk or white. MPint retes 1-it pitures. A 4-it piture woul hve 64 gry levels. The inry for J in this se woul e the informtion for two pixels of piture. One woul e 0100 n the other woul e 1010, representing 2 grys out of possile 64. It woul look like this: An 8-it piture woul hve 256 gry levels. The entire 01001010 woul e use to represent single gry level. Blk is 00000000 n white is 11111111. In etween, there woul e 254 ifferent omintions of 0s n 1s for totl of 256 levels of gry. 13.3 lern PS 13 4 1248.eps The following re hrts for N, e, X, n T showing how the inry for eh hrter woul e pinte s 1, 2, 4, n 8-it piture. The vertil line mrks off the numer of times the letter is use. The PostSript progrm listing for 1248-132.eps n e foun t the en of ppenix A. 0 1 0 0 1 1 1 0 01 00 11 10 0100 1110 01001110 (N)<4E> 1 it 2 it 4 it 8 it 0 1 1 0 0 1 0 1 01 10 01 01 0110 0101 01100101 (e)<65> 1 it 2 it 4 it 8 it 130 the imge opertor / ptterns

Chpter 13 0 1 0 1 1 0 0 0 01 01 10 00 0101 1000 01011000 (X)<58> 1 it 2 it 4 it 8 it 0 1 0 1 0 1 0 0 01 01 01 00 0101 0100 01010100 (T)<54> 1 it 2 it 4 it 8 it 13.4 rnom ptterns Another exmple of t quisition proeure is the progrm tht retes rnom pttern within ertin rnge of grys. PS lern 13 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:pttern_1.eps %%Cretor:John F Shermn %%CretionDte:July 1989 %%BouningBox:0 0 200 200 /str 512 string ef /pttern {/light exh ef /rk exh ef /iff light rk su ef the imge opertor / ptterns 131

Tking Avntge of PostSript 20 20 8 [.1 0 0.1 0 0] {0 1 511 {str exh rn iff mo rk put} for str} in imge } ef 222 srn 0 255 pttern Next is version of the pttern proeure tht limits the vlues to etween 33 n 125. We ll next explin this exmple line y line. A review of the isussion of the for n put opertors in setion 8.3 might e helpful. PS lern 13 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:expttern1.eps %%BouningBox:0 0 200 40 /str 20 string ef /pttern {/light exh ef /rk exh ef /iff light rk su ef 20 4 8 [.1 0 0.1 0 0] {0 1 19 {str exh rn iff mo rk put} for str }imge} ef 178 srn 33 125 pttern This pttern is n 8-it, 20x4 piture. Sine it is n 8-it piture, eh row is rete y 20 hrters of t. A totl of 80 hrters will e neee for the entire piture. As expline in setion 12.2, eh hrter of the ASCII tle represents gry vlue somewhere etween 0 n 255. 0 is lk n 255 is white. Tht mens hrter 33 woul e the equivlent of.128 setgry or 87.2% lk n hrter 125 woul e 51.2% lk. The jo of the pttern t quisition proeure is to rnomly rete string of 20 hrters tht re lwys etween 33 n 125. I use this rnge euse it is portion of the ASCII tle with visile hrters. The first line /str 20 string ef efines string 20 hrters in length, initilly with the vlue of (00000000000000000000) Next egins the efinition for the pttern proeure. The first line of the proeure efinition is /light exh ef /rk exh ef whih efines the top two vlues on the opern stk to e light n rk. In this exmple, looking he to the lst line of the progrm, light will e efine s 125 n rk will e 33. 125 will e on top of the stk with 33 elow it. 132 the imge opertor / ptterns

Chpter 13 The seon line of the proeure efines iff s the sutrtion of rk from light, whih will in this se e 92. Next, 20 4 8 [.1 0 0.1 0 0] re the first rguments for the imge opertor, setting up the piture to e 20 y 4 pixels, with eh pixel to hve n 8-it vlue n the mtrix rry etermining the size of the piture. Next is the t quisition proeure: 0 1 19 {str exh rn iff mo rk put} for This line retes string 20 hrters in length, eh of whih is hrter tht flls etween 33 n 125 on the ASCII hrt. Breking this line own, fter the first ount of the for loop, 0 then str (whih is (00000000000000000000)) will e on top of the stk. exh will swith those positions so tht 0 is on top. Zero will e use lter s the inex for the put opertor. rn retes rnom numer, whih will e 2991646 on the first go roun. (Don t worry for now out how I know tht. See hpter 16.) The rnom numers proue here re reprouile sequene of numers se on the 178 srn it lter in the progrm. Tht is, the rnom sequene will lwys e the sme unless 178 is hnge (it my e ifferent repetle sequene on your mhine). Next, iff ws efine erlier to e 92. After tht is the opertor mo, whih returns to the stk the reminer of ivision. In this se, it is the ivision of 2991646 y 92, whih hs reminer of 82 (roune off). Then omes rk, efine erlier s 33 n whih s the 82 n 33 giving you 115. Cheking the ASCII tle, 115 is the hrter s. The str looks like this fter the first ount of for: (00000000000000000000) 0 115 put whih eomes (s0000000000000000000) This proess is repete until str is fille with 20 hrters. Then str is use s t for the first row of the piture y the imge opertor. Speifilly, the first 20 hrters in str woul e: sfy.+g=oqy,/xr4=4 lern PS 13 7 This ws rrive t y printing the string inste of using it s t for the imge opertor. %!PS-Aoe-2.0 EPSF-1.2 %%Title:seepttern1.eps %%BouningBox:0 0 180 30 /Times-Bol finfont 16 slefont setfont /str 20 string ef /pttern {/light exh ef /rk exh ef /iff light rk su ef 0 1 19 {str exh rn iff mo rk put} for} ef 178 srn 33 125 pttern % rete 20 etween 33 & 125 7 10 moveto str show the imge opertor / ptterns 133

Tking Avntge of PostSript.25 setlinewith %frme 0 0 moveto 180 0 lineto 180 30 lineto 0 30 lineto losepth stroke This progrm woul look like figure 13 3. figure 13 3 H only the one line, sfy.+g=oqy,/xr4=4, een use for the piture, repeting pttern woul emerge (figure 13 4) euse the sme string woul e use over n over until the with n height were stisfie. figure 13 4 However, the pttern t quisition proeure ontinully retes new 20 hrter string. The proeure h first rete: sfy.+g=oqy,/xr4=4 whih is use to pint 20 pixels in the first row. The proeure then retes: AMsD;,G=#_m`S_,IW-_@ for the 20 pixels of the seon row, looking like figure 13 5 t this point. figure 13 5 An so on until the piture is omplete. The next exmple shows how pttern n look t ifferent vlue rnges. lern PS 13 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:pttern_y4.eps %%Cretor:John F Shermn 1989 %%CretionDte:July 1989 %%BouningBox:0 0 310 70 /str 512 string ef /pttern {/light exh ef /rk exh ef /iff light rk su ef 7 7 8 [.1 0 0.1 0 0] 134 the imge opertor / ptterns

Chpter 13 {0 1 511 {str exh rn iff mo rk put} for str} in imge } ef 222 srn 0 75 pttern 80 0 trnslte 75 150 pttern 80 0 trnslte 150 225 pttern 80 0 trnslte 225 250 pttern 13.5 vritions on the ptterns Vritions of the pttern proeure n e hieve y hnging the it vlue for the imge opertor. The onfinement of the piture to e within ertin rnges of gry iminishes s the its level gets smller, ut ifferent textures re proue. Below, the first row of ptterns re 1-it, followe y 2, 4, n 8-it. lern PS 13 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ptternVr1.eps %%Cretor:John F Shermn %%BouningBox:0 0 400 400 the imge opertor / ptterns 135

Tking Avntge of PostSript /str 512 string ef /pttern {/light exh ef /rk exh ef /iff light rk su ef 7 7 its [.1 0 0.1 0 0] {0 1 511 {str exh rn iff mo rk put} for str} in imge} ef 17341734 srn /its 8 ef gsve % ottom row 0 75 pttern 80 0 trnslte 75 150 pttern 80 0 trnslte 150 225 pttern 80 0 trnslte 225 250 pttern grestore /its 4 ef gsve % seon row 0 80 trnslte 0 75 pttern 80 0 trnslte 75 150 pttern 80 0 trnslte 150 225 pttern 80 0 trnslte 225 250 pttern grestore /its 2 ef gsve % thir row 0 160 trnslte 0 75 pttern 80 0 trnslte 75 150 pttern 80 0 trnslte 150 225 pttern 80 0 trnslte 225 250 pttern grestore /its 1 ef gsve % top row 0 240 trnslte 0 75 pttern 80 0 trnslte 75 150 pttern 80 0 trnslte 150 225 pttern 80 0 trnslte 225 250 pttern grestore You n hnge the mtrix s expline erlier in setion 10.4. In the next exmple, hving the mtrix e [.1 0 -.1.1 0 0] skews the squre pttern 45 to the right. Then the skewe squre is use eight times s it is rotte in 45 inrements. 136 the imge opertor / ptterns

Chpter 13 lern PS 13 10 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ptternVr2.eps %%Cretor:John F Shermn %%BouningBox:0 0 300 300 /str 512 string ef /pttern {/light exh ef /rk exh ef /iff light rk su ef 7 7 8 [.1 0 -.1.1 0 0] {0 1 511 {str exh rn iff mo rk put} for str} in imge} ef 17341734 srn 0 0 300 300 retstroke 150 150 trnslte gsve 8 {45 rotte 0 255 pttern} repet grestore 13.6 fountins Fountins, lso known s rmps or lens, n e rete with the imge opertor. The t quisition proeure in this se retes single string orere from the the imge opertor / ptterns 137

Tking Avntge of PostSript ASCII hrt s eginning to en to rete trnsition of vlue. The first hrter of the hrt is lk, the lst is white. The t quisition proeure is onvenient mens to orer ll 256 hrters. We oul see tht string y printing it inste of using it s the t for the imge opertor. This is silly the sme progrm tht ws seen k in setion 8.3 when the for n put opertors were expline.!"#$%& ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ efghijklmnopqrstuvwxyz{ }~ ƒ ' «fifl» ` ˆ ˇ Æ ª ŁØŒº æ ı łøœß lern PS 13 11 %!PS-Aoe-2.0 EPSF-1.2 %%Title:seefountin_1.eps %%BouningBox:0 0 460 30.25 setlinewith 0 0 460 30 retstroke /Helveti-Conense finfont 4 slefont setfont /str 256 string ef 0 1 255 { str exh up put } for 5 10 moveto str show str stringwith pop 5 /strlength exh ef % mrk eginning 1 setlinewith 5 10 moveto 0 20 rlineto stroke strlength 10 moveto 0 20 rlineto stroke To show the omplete string in this exmple, it s set with 4 point type euse of its length. The vertil lines to the left n right mrk the eginning n en of the string. The! is the first visile hrter t the 33r position. The gps re hrters without rwing within the 256 hrter set. A fountin is silly 256x1 piture sle to whtever size is require. See figure 13 6. figure 13 6 The sling of the fountin is hnle y oth the imge opertor s mtrix rry n the sle opertor. In the following exmple of si fountin, first note the piture is 256 wie n 1 high. Seon, note the mtrix rry of [256 0 0 1 0 0]. We know from hpter 10 on the mtrix tht this rry will sle the piture y 256 in the x n y 1 in the y. The mtrix of [256 0 0 1 0 0] ompresses the 256x1 piture to 1 y 1 point squre. Without the 170 170 sle, we proly woul hve iffiult time 138 the imge opertor / ptterns

Chpter 13 seeing the fountin. The sle opertor sles the fountin to whtever size esire. Sine we re eginning with 1x1 point squre, the size of the fountin will lso e its sle ftor. Below, the 170 170 sle lso mens the fountin is 170x170 points in size. lern PS 13 12 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_1.eps %%Cretor:John F Shermn %%BouningBox:0 0 170 170 /str 256 string ef 0 1 255 { str exh up put } for 170 170 sle 256 1 8 [ 256 0 0 1 0 0 ] {str} imge 13.7 hnging the fountin s iretion The iretion of the fountin n e ontrolle y using either 1x256 or 256x1 piture n the mtrix rry use with the imge opertor. In the next exmple, note the hnges me to the [ 256 0 0 1 0 0 ] mtrix in the other three fountins. the imge opertor / ptterns 139

Tking Avntge of PostSript PS lern 13 13 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_x4.eps %%Cretor:John F Shermn %%BouningBox:0 0 200 200 100 100 sle /str 256 string ef 0 1 255 { str exh up put } for gsve % lower left 256 1 8 [ 256 0 0 1 0 0 ] { str } imge grestore gsve % lower right 1 0 trnslte % rememer 100 100 sle 1 256 8 [1 0 0 256 0 0 ] { str } imge % ifferent grestore gsve % upper left 0 1 trnslte 1 256 8 [ 1 0 0-256 0 256] { str } imge % ifferent grestore gsve % upper right 1 1 trnslte 256 1 8 [ -256 0 0 1 256 0 ] { str } imge % ifferent grestore 140 the imge opertor / ptterns

Chpter 13 13.8 other fountins There re severl tehniques in reting fountin to permit ifferent trnsitions of gry. Generlly the reson is to ompenste for ifferent printing situtions. lern PS 13 14 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_2.eps %%BouningBox:0 0 170 170 /str 256 string ef 0 1 255 {str exh up 255 iv sqrt 255 mul vi put} for /fountin { gsve /ury exh ef /urx exh ef /lly exh ef /llx exh ef llx lly ury trnslte urx llx su ury lly su sle 256 1 8 [ 256 0 0 1 0 1 ]{str} imge grestore } ef 0 0 170 170 fountin lern PS 13 15 Using vrition of seefountin_1.eps from the eginning of setion 13.6, the rte of hnge n e emonstrte y printing the string. fountin_1.eps is on the ottom for referene. It is lso roppe on the right so we n see the eginning more esily. The vertil lines mrk the eginning. # *-/2479;=?ACEGIJLNOQRTUWXZ[]^_fghiklmnoprstuvwxyz{ }~!"#$%& ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM the imge opertor / ptterns 141

Tking Avntge of PostSript lern PS 13 16 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_3-1.eps %%BouningBox:0 0 170 170 /str 256 string ef 0 1 255 { str exh up 255 iv 180 mul os neg 2 iv.5 255 mul vi put} for /fountin { /ury exh ef /urx exh ef /lly exh ef /llx exh ef gsve llx lly trnslte urx llx su ury lly su sle 256 1 8 [ 256 0 0 1 0 0 ] {str} imge grestore} ef 0 0 170 170 fountin lern PS 13 17 fountin_2.eps ws shift to the left. You n see elow tht fountin_3-1.eps is shift to the right ompre to fountin_1.eps.!"#$%& )*+,-.01235679:;=>?ABCEFH!"#$%& ()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM 142 the imge opertor / ptterns

Chpter 13 lern PS 13 18 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_3-2.eps %%BouningBox:0 0 170 170 /rte 720 ef /str 256 string ef 0 1 255 { str exh up 255 iv rte mul os neg 2 iv.5 255 mul vi put} for /fountin { /ury exh ef /urx exh ef /lly exh ef /llx exh ef gsve llx lly trnslte urx llx su ury lly su sle 255 1 8 [ 255 0 0 1 0 0 ] {str} imge grestore } ef 0 0 170 170 fountin lern PS 13 19 This is vrition of fountin_3-1.eps on the previous pge. Note the new vrile title rte use within the for proeure. In fountin_3-1.eps it ws 180. If rte is 360, the fountin woul e lk to white to lk. Below is portion of the string.!%*.39>ciou[gmsz «` Œ ıłøß œø æ ºŁ fi }vpj^xrlfa;61, # #,16;AFLRX^jpv} fi the imge opertor / ptterns 143

Tking Avntge of PostSript 144 retive uses of imgemsk

14 hpter Chpter 14 retive uses of imgemsk The imgemsk opertor is vrition of the imge opertor. It iffers in tht it n only e use to pint 1-it pitures, it n reverse the piture, n the piture is pinte with the urrent gry. Another feture of this opertor is tht the portion of the piture tht is not pinte is trnsprent. Otherwise it works muh in the sme wy s imge. imgemsk n e use to mke ptterns (see hpter 13). One of the suggeste uses of imgemsk is the retion of it-mp fonts. Sine the unpinte prt of the letterforms is trnsprent, they woul not interfere with imges unerneth them. 14.1 syntx The syntx of imgemsk is: with height invert mtrix pro imge Where: with height invert mtrix pro imgemsk is the with of the piture in ells or pixels. is the height of the piture in ells or pixels. if true, vlues of 1 re pinte with the urrent olor; if flse, vlues of 0 re pinte with the urrent olor. is the piture s oorinte system. is the t quisition proeure tht otins or retes the piture t. is the PostSript opertor. 14.2 shmrok revisite When the invert oolen is flse, the 0s re pinte with the urrent olor n the 1s re ler. A oolen is something tht is either true or flse. When the invert oolen is true, the opposite is the se. The 1s re pinte n the 0s re ler. See figure 14 1. retive uses of imgemsk 145

Tking Avntge of PostSript figure 14 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 Using the shmrok_1.eps exmple from hpter 12, the primry ifferenes of imgemsk n e emonstrte. In the next PostSript progrm exmple, the piture is ple on top of gry squre. H the imge opertor een use, tht gry squre woul hve een overe with opque white. lern PS 14 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shmrok_3.eps %%BouningBox:0 0 160 160 /S <FF 1F FE 3F 9E 39 0E 70 06 60 02 40 00 00 00 00 00 00 04 20 08 19 90 0F F0 0F E0 07 E0 07 F0 0F> ef.5 setgry 0 0 moveto 160 0 lineto 160 160 lineto 0 160 lineto losepth fill 0 setgry 16 16 flse [.1 0 0.1 0 0] {S} imgemsk H true een use in the imgemsk rgument, 16 16 true [.1 0 0.1 0 0] {S} imgemsk 146 retive uses of imgemsk

Chpter 14 the sme t woul look like figure 14 2. The gry shmrok is the gry showing through where the 0s re n the lk is the pinte 1s. figure 14 2 In the next exmple, ifferent olors re use for the piture. The kgroun squre is.666 setgry. The first shmrok is.333 setgry. For the shmrok to the right, the urrent olor is me to 1 0 1 0.3 setmykolor, rk green. lern PS 14 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shmrok_5&6.eps %%BouningBox:0 0 320 160 /S <FF 1F FE 3F 9E 39 0E 70 06 60 02 40 00 00 00 00 00 00 04 20 08 19 90 0F F0 0F E0 07 E0 07 F0 0F> ef.666 setgry % kgroun 0 0 moveto 320 0 lineto 320 160 lineto 0 160 lineto losepth fill.333 setgry 16 16 flse [.1 0 0.1 0 0] {S} imgemsk 160 0 trnslte 1 0 1.3 setmykolor 16 16 flse [.1 0 0.1 0 0] {S} imgemsk retive uses of imgemsk 147

Tking Avntge of PostSript 14.3 with fountin An interesting effet with imgemsk n e hieve with fountin (see previous hpter, setions 13.6 13.8) unerneth the piture. Following re two esigns set up silly the sme. Eh hs the sme fountin unerneth the piture of the violin pinte with imgemsk. In the first exmple, violinsq1.eps, the violin is pinte in the efult vlue of lk. PS lern 14 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:violinSq1.eps %%BouningBox: 0 0 300 300 gsve 300 300 sle /str 256 string ef 0 1 255 { str exh up put } for 256 1 8 [ -256 0 0 1 256 0 ] { str } imge grestore gsve 0 setgry /pistr1 38 string ef /ret {urrentfile exh rehexstring pop} ef /eginimge {{pistr1 ret} imgemsk} ef 300 300 sle 148 retive uses of imgemsk

Chpter 14 300 300 flse [300 0 0 300 neg 0 300] eginimge FFFFFFFFFFFFFFCFFFFFFFFFFFFFFFFFFFFEF69FEA800C00002000020000... PICTURE DATA... FFF7FFFFFFFFFFFFFFF7FFFAFBD54ED6AA52222004410000000363800000 grestore 0 0 300 300 retstroke In this seon exmple, two hnges hve een me to the file. First, true is use s the invert oolen for imgemsk, mking the opposite pixels e pinte 1s. Seon, the urrent gry is me white with 1 setgry. In this wy, whtever is unerneth will give the violin its olor. This retes the effet tht the violin is eing pinte s fountin. The white is msk overing the fountin elow it. PS lern 14 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:violinSq2.eps %%BouningBox: 0 0 300 300 gsve 300 300 sle /str 256 string ef 0 1 255 { str exh up put } for 256 1 8 [ -256 0 0 1 256 0 ] { str } imge grestore retive uses of imgemsk 149

Tking Avntge of PostSript gsve 1 setgry /pistr1 38 string ef /ret {urrentfile exh rehexstring pop} ef /eginimge {{pistr1 ret} imgemsk} ef 300 300 sle 300 300 true [300 0 0 300 neg 0 300] eginimge FFFFFFFFFFFFFFCFFFFFFFFFFFFFFFFFFFFEF69FEA800C00002000020000... PICTURE DATA... FFF7FFFFFFFFFFFFFFF7FFFAFBD54ED6AA52222004410000000363800000 grestore 0 0 300 300 retstroke 14.4 s pttern Rnom ptterns n e me with similr proeure use to mke ptterns in setion 13.4. 0 1 511 {str exh rn 255 mo put} for This proeure onverts str into string of 512 rnomly selete hrters. Three overlpping squres re me, eh ifferent vlue. 150 retive uses of imgemsk

Chpter 14 PS lern 14 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:imgemskPt_1.eps %%BouningBox:0 0 300 300 /str 512 string ef 0 1 511 {str exh rn 255 mo put} for 100 100 true [.5 0 0.5 0 0] {str} imgemsk 100 0 trnslte.333 setgry 100 100 true [.5 0 0.5 0 0] {str} imgemsk 0 100 trnslte.666 setgry 100 100 true [.5 0 0.5 0 0] {str} imgemsk retive uses of imgemsk 151

Tking Avntge of PostSript 152 reting font

15 hpter Chpter 15 reting font You n rete unique PostSript font n use it in your PostSript progrms. The PostSript exmples in this hpter will over how to moify n existing font, the retion of mono-spe font, n then vrile-spe font. We will e reting type 3 fonts. The retion of type 1 fonts, however, will not e overe. Type 1 fonts re Aoe s previously enrypte font formt tht ws reently pulishe. These fonts ontin proeures, ommonly known s hints, tht ensure high qulity output on ll resolutions of printers, espeilly smll type on low resolution evies. 15.1 ntomy of font progrm A PostSript font progrm is the retion of font itionry ontining the vlues for numer of font hrteristis, some of whih re ontine in their own itionry within the lrger font itionry. Erlier in hpter 3, you my rememer, we efine squre to e the nme of proeure tht rws squre. Within font itionry, / is the nme of proeure tht rws the hrter. There is more to it thn just this, ut essentilly font is itionry of rwings for eh hrter of the lphet. There re lso other ttriutes of the font efine in the file, suh s the FontType, FontMtrix, FontBBox, the hrter Enoing, n its font metri. The FontType tells the PostSript interpreter how the font ws me so it knows how to hnle the font. The ifferent font types re: 0 Knji or other very lrge font sets. 1 Aoe s enrypte n hinte fonts. 2 Osolete. 3 User efine fonts. 4 Crtrige n isk-se enrypte fonts. 5 ROM-se enrypte fonts. The FontMtrix is the oorinte system within whih the font ws esigne. Usully the font is esigne within 1000x1000 unit spe. It n e thought of s the pge the font ws esigne on. In figure 15 1, the hrters g n M re ple on wht oul e the 1000x1000 unit spe. Eh gri line represents 100 units. A mtrix rry of [.001 0 0.001 0 0] will reue the 1000x1000 unit spe to 1x1 unit squre. In other wors, wht ws rwn to e 100 is now.1 n wht ws 1000 is 1. Therefore, when 72 slefont is use with the font, the 1x1 unit squre is sle y ftor of 72. Figure 15 2 explins FontMtrix further. The first lrge squre gri represents reting font 153

Tking Avntge of PostSript the 1000x1000 unit spe (reue 10% to sve spe) on whih the font ws rwn. Next to it, lele with n A n with n rrow pointing t it (it s smll) is tht 1000x1000 unit spe reue to 1x1 unit spe y the pplition of the [.1 0 0.1 0 0] FontMtrix. B lels wht woul hppen with 72 slefont, C lels 300 slefont enlrgement for etter view. Mg BBox for g is: -4.24988-230.65 476.85 563.25 BBox for M is: -4.24988-230.65 854.25 563.25 BBox for the font is: -4.24988-230.65 854.25 563.25 figure 15 1 figure 15 2 The FontBBox is the smllest retngle into whih ll the hrters of the font will fit. This is epite y the gry retngle in figure 15 1. A B C The hrter Enoing etermines t wht eiml lotion the hrter nme will resie on the ASCII hrt. See ppenix A. PostSript hs stnr Enoing nme StnrEnoing tht lrey gives every entry of the rry nme. In it, /one is the nme for the numer 1 t eiml 49, / is the nme for the hrter t eiml 97, n so on. The StnrEnoing n e opie or you n rete your own sheme. In the next setion, the StnrEnoing is opie, sving the troule of hving to nme ll the hrter proeures. Lter, in setion 15.4, ustom nmes re given to severl of the hrters n the nme for null proeure (oesn t o nything) to the rest. The ChrPros is itionry ontining ll the proeure efinitions tht rw the iniviul hrters nme in the Enoing rry. Finlly, there is the BuilChr proeure tht uses the informtion previously liste in the progrm to tully rw the hrter. 154 reting font

Chpter 15 15.2 PS lern 15 1 font templte This next setion hs listing of font file to show how the ove informtion is orgnize into file. All tht is missing re your rwings for iniviul hrters n your hoie for font nme. Not ll 256 entries re inlue. The others n e foun in ppenix A. %!PS-Font %%Title:font_templte.ps /newfont 10 it ef newfont egin % rete itionry % egin filling itionry /FontType 3 ef % user efine font /FontMtrix [.001 0 0.001 0 0] ef /FontBBox [0 0 1000 1000] ef /Enoing 256 rry ef % opy stnr enoing StnrEnoing Enoing opy pop /ChrPros 20 it ef ChrPros egin % mth # with # of hr pro % itionry of hr proeures /spe { } ef % wor spe /mpersn { % hrter rwing for & } ef /sterisk { % hrter rwing for * } ef /zero /one /two /three /four { % hrter rwing for 0 } ef { % hrter rwing for 1 } ef { % hrter rwing for 2 } ef { % hrter rwing for 3 } ef { % hrter rwing for 4 } ef /A { % hrter rwing for A } ef /B { % hrter rwing for B } ef /C { % hrter rwing for C } ef /D { % hrter rwing for D } ef / { % hrter rwing for } ef / { % hrter rwing for } ef / { % hrter rwing for } ef / { % hrter rwing for } ef en /yen { % hrter rwing for } ef /prgrph { % hrter rwing for } ef /germnls { % hrter rwing for ß } ef /BuilChr % retes hr from info ove {1000 0 0 0 1000 1000 setheevie exh egin Enoing exh get ChrPros exh get exe en} ef reting font 155

Tking Avntge of PostSript en % give your font nme repling YourNme /YourNme newfont efinefont pop 15.3 moifying n existing font It s possile to moify n existing font y upliting its font itionry n then pling new entry in the opy. The most ommon hnge is to hnge the font s mtrix. By oing so, the entire font n e onense or expne. The font Helveti-Nrrow foun in mny lser printers is proue y mthemtilly onensing Helveti. Helveti Conense, on the other hn, is seprte rwing from Helveti. In this exmple, we will mke our own Pltino Bol Nrrow. The first setion of oe uplites the Pltino-Bol itionry n isrs the existing FID. A new one will e me with efinefont. While itcopy is on top of the itionry stk, the FontMtrix is reple with new rry. The next line efines Pltino-BNrrow s the font with efinefont. Pltino B 144 72 Pltino Bol Nrrow 0 0 72 144 216 288 360 lern PS 15 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:Pltino-BNrrow.eps %%BouningBox:18 36 373 156 /Pltino-Bol finfont up length it /itcopy exh ef {1 inex /FID ne {itcopy 3 1 roll put} {pop pop} ifelse }forll itcopy /FontMtrix [.0005 0 0.001 0 0] put /Pltino-BNrrow itcopy efinefont pop 156 reting font

Chpter 15 /Pltino-BNrrow finfont 70 slefont setfont 18 36 moveto (Pltino Bol Nrrow) show /Pltino-Bol finfont 70 slefont setfont 18 108 moveto (Pltino B) show 15.4 shpefont s mono-spe font To rete our own font from srth, we ll nee to set up ll the neessry informtion. A mono-spe font is simpler thn vrile-spe font euse every hrter uses the sme mount of spe. First, the font itionry is set up with /newfont 10 it ef. newfont is n ritrry nme; use whtever you wnt. It will lter e reple with the tul font nme. The newfont itionry must hve four entries: FontType, FontMtrix, FontBBox n Enoing. These shoul e unerstoo from setion 15.1. The Enoing this time will e nonstnr rry of 256 nmes. The line 0 1 255 {Enoing exh /.notef put} for reples eh position of the lnk Enoing me y the previous line /Enoing 256 rry ef with the key /.notef. This is quik wy to give eh entry of Enoing nme. We pln to nme only 5 of the 256 positions. If hrter without rwing is use, the.notef proeure (whih oes nothing) will e use to prevent n error. Next, the nmes for hrters we wnt in Enoing re put into the position we wnt tht orrespons to key of the keyor. Bsilly, ASCII 97 is the hrter in stnr font n is the hrter squre in shpefont. ChrPros is itionry tht mthes the nme in Enoing with proeure. The proeure efinitions shoul look fmilir to you. Note wht the proeure.notef is efine s. Finlly, there is the efinition for BuilChr. BuilChr is wht gets lle when hrter nees to e pinte. Font hing, performe y the setheevie opertor is use to gin effiieny in printing. When hrter is rwn y BuilChr, its imge is temporrily store in he. Shoul the hrter e use gin, it s there, rey to go. 72 0 0 72 144 216 288 360 PS lern15 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shpeFont.eps %%BouningBox:0 0 385 150 reting font 157

Tking Avntge of PostSript /newfont 10 it ef newfont egin /FontType 3 ef /FontMtrix [.001 0 0.001 0 0] ef /FontBBox [0 0 1000 1000] ef /Enoing 256 rry ef % give nme 0 1 255 {Enoing exh /.notef put} for Enoing 97 /squre put % keyor Enoing 98 /tringle put % keyor Enoing 99 /irle put % keyor Enoing 100 /imon put % keyor Enoing 101 /lines put % keyor e /ChrPros 6 it ef ChrPros egin % pro ef for nmes ove /.notef { } ef /squre {0 0 moveto 750 0 lineto 750 750 lineto 0 750 lineto losepth fill} ef /tringle {0 0 moveto 375 750 lineto 750 0 lineto losepth fill} ef /irle {375 375 375 0 360 r losepth fill} ef /imon {375 0 moveto 750 375 lineto 375 750 lineto 0 375 lineto losepth fill} ef /lines {150 setlinewith 0 75 moveto 750 0 rlineto stroke 0 375 moveto 750 0 rlineto stroke 0 675 moveto 750 0 rlineto stroke} ef en /BuilChr {1000 0 0 0 750 750 setheevie exh egin Enoing exh get ChrPros exh get exe en} ef en % en newfont /ShpeFont newfont efinefont pop /ShpeFont finfont 70 slefont setfont 36 36 moveto (e) show 158 reting font

Chpter 15 15.5 shpefont s vrile-spe font shpefont s vrile-spe font is written muh the sme s in the previous setion. In this version of the font, every hrter n hve its own unique with. The primry ifferene in this font file from the lst setion is the ition of the Metris n BBox itionries. These re use for hrter sping n setting the ounries of font hing respetively. These re use in the BuilChr proeure. If the vlues re hnge in the Metris itionry, the hrter sping of this font will e ifferent. The BBox itionry provies more preise informtion for font hing. 72 0 0 72 144 216 288 360 PS lern 15 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shpeFont2.eps %%BouningBox:0 0 385 150 /newfont 10 it ef newfont egin /FontType 3 ef /FontMtrix [.001 0 0.001 0 0] ef /FontBBox [0 0 750 750] ef /Enoing 256 rry ef 0 1 255 {Enoing exh /.notef put} for Enoing 97 /squre put % keyor Enoing 98 /tringle put % keyor Enoing 99 /irles put % keyor Enoing 100 /imon put % keyor Enoing 101 /lines put % keyor e /Metris 6 it ef Metris egin /.notef 0 ef /squre 800 ef /tringle 400 ef /irles 400 ef /imon 800 ef /lines 400 ef en /BBox 6 it ef reting font 159

Tking Avntge of PostSript BBox egin /.notef [0 0 0 0] ef /squre [0 0 750 750] ef /tringle [0 0 375 750] ef /irles [0 0 375 750] ef /imon [0 0 750 750] ef /lines [0 0 375 750] ef en /ChrPros 6 it ef ChrPros egin /.notef { } ef /squre {0 0 moveto 750 0 lineto 750 750 lineto 0 750 lineto losepth fill} ef /tringle {0 0 moveto 375 0 lineto 187.5 750 lineto losepth fill} ef /irles {187.5 562.5 187.5 0 360 r losepth fill 187.5 187.5 187.5 0 360 r losepth fill} ef /imon {375 0 moveto 750 375 lineto 375 750 lineto 0 375 lineto losepth fill} ef /lines {150 setlinewith 0 75 moveto 375 0 rlineto stroke 0 375 moveto 375 0 rlineto stroke 0 675 moveto 375 0 rlineto stroke} ef en /BuilChr {0 egin /hr exh ef /fontit exh ef /hrnme fontit /Enoing get hr get ef fontit egin Metris hrnme get 0 BBox hrnme get lo pop setheevie ChrPros hrnme get exe en en } ef /BuilChr lo 0 3 it put /UniqueID 1 ef en /ShpeFont2 newfont efinefont pop /ShpeFont2 finfont 70 slefont setfont 36 36 moveto (e) show 160 reting font

Chpter 15 15.6 the rbit-romn font The rbit-romn font is n exmple of how the PostSript font mhinery n e use to rete interesting ptterns. It is mono-spe font with no gp etween the hrters. 1CD ABCD lern PS 15 5 1234 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rBit_font.eps %%Cretor:John F Shermn %%CretionDte:April 1990 %%DoumentFonts:rBit-Romn %%BouningBox:0 0 400 400 /newfont 10 it ef newfont egin /FontType 3 ef reting font 161

Tking Avntge of PostSript /FontMtrix [.001 0 0.001 0 0] ef /FontBBox [0 0 1000 1000] ef /Enoing 256 rry ef StnrEnoing Enoing opy pop /ChrPros 30 it ef ChrPros egin /.notef { } ef /str 512 string ef /rbit { 0 1 511 {ChrPros /str get exe exh rn 255 mo put} for ChrPros /str get exe } ef /spe {0 0 moveto newpth} in ef /zero {48 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /one /two {49 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef {50 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /three{51 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /four {52 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /A {65 srn 10 10 true [.01 0 0.01 0 0] {ChrPros /rbit get exe}imgemsk} in ef /B {66 srn 10 10 true [.01 0 0.01 0 0] {ChrPros /rbit get exe}imgemsk} in ef /C {67 srn 10 10 true [.01 0 0.01 0 0] {ChrPros /rbit get exe}imgemsk} in ef /D {68 srn 10 10 true [.01 0 0.01 0 0] {ChrPros /rbit get exe}imgemsk} in ef 162 reting font

Chpter 15 / {97 srn 50 50 true [.05 0 0.05 0 0] {ChrPros /rbit get exe}imgemsk} in ef / {98 srn 50 50 true [.05 0 0.05 0 0] {ChrPros /rbit get exe}imgemsk} in ef / {99 srn 50 50 true [.05 0 0.05 0 0] {ChrPros /rbit get exe}imgemsk} in ef en / {100 srn 50 50 true [.05 0 0.05 0 0] {ChrPros /rbit get exe}imgemsk} in ef /BuilChr {1000 0 0 0 1000 1000 setheevie exh egin Enoing exh get ChrPros exh get exe en} ef en /rbit-romn newfont efinefont pop %% BEGIN DESIGN /rbit-romn finfont 100 slefont setfont gsve 0 0 moveto (1234) show 0 100 moveto (ABCD) show 0 200 moveto () show.5 setgry 0 300 moveto (1C) show.3 setgry (D) show grestore 15.7 how to use your font There re two wys you n use your font. The first wy is to inlue the efinition of the font in the eginning of your progrm. This hs een one in the previous exmples. The vntge of this is tht your progrm n esily e run on ny PostSript printer. Everything is there in the PostSript file rey to go. The seon wy to use your font is to use it only s font file n ownlo it to your lser printer s RAM. Therefter, your PostSript files tht use the font will not nee to ontin the efinition for the font. The min vntge to ownloing your font is tht you n simplify your PostSript files. The isvntges re tht you n lose trk of whih files use whih fonts n there isn t onvenient wy to let Mintosh pplitions use them. reting font 163

Tking Avntge of PostSript To e le to ownlo font, you nee to line of oe to the eginning of your font file: serverit egin 0 exitserver This line t the eginning of your file will let your font exist in your printer s RAM until it is turne off. Your file woul look like this. lern PS 15 6 %!PS-Font %%Title:ownlo_rFont.ps serverit egin 0 exitserver /newfont 10 it ef newfont egin /FontType 3 ef /FontMtrix [.001 0 0.001 0 0] ef /FontBBox [0 0 1000 1000] ef /Enoing 256 rry ef 0 1 255 {Enoing exh /.notef put} for Enoing 33 /33 put Enoing 65 /65 put Enoing 97 /97 put Enoing 122 /122 put /ChrPros 7 it ef ChrPros egin /.notef{ } ef /hr {10 setlinewith rn 1000 mo rn 1000 mo moveto rn 1000 mo rn 1000 mo lineto stroke} ef /33 {33 {ChrPros /hr get exe} repet} in ef /65 {65 {ChrPros /hr get exe} repet} in ef /97 {97 {ChrPros /hr get exe} repet} in ef /122 {122 {ChrPros /hr get exe} repet} in ef en /BuilChr {1000 0 0 0 1000 1000 setheevie exh egin Enoing exh get ChrPros exh get exe en} ef en /rfont newfont efinefont pop If the previous progrm hs een sent to the LserWriter, the following progrm 164 reting font

Chpter 15 n e sent to the printer n work orretly. zzzzz AAAAA!!!!! lern PS 15 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rFont.eps %%BouningBox:25 25 275 225 /rfont finfont 50 slefont setfont 25 25 moveto (!!!!!) show 25 75 moveto () show 25 125 moveto (AAAAA) show 25 175 moveto (zzzzz) show Generlly, you ll fin it esier to keep the font efinition within the PostSript file. reting font 165

Tking Avntge of PostSript 166 retive uses of rnom numers

16 hpter Chpter 16 retive uses of rnom numers The rnom numer genertion of PostSript hs numer of retive pplitions. Most ommon re rnom numers for n x y lotion for moveto or lineto opertor or to set gry vlue. The sequene of rnom numers n e repete if the see numer tht egins the sequene is the sme. 16.1 rn The simplest rnom numer progrm woul e rn = PS lern 16 1 rn retes n pushes rnom numer onto the opern stk. The equl sign (=) pops the numer off the stk n sens it the stnr output file. Depening on the pplition you re using t the time, the stnr output file will e ifferent. On the Mintosh, if you re using SenPS, the stnr output file will e text file on your hr isk nme fter your printer. If you re using Downloer, the output file is rief isply in winow on the monitor. On the NeXT, the stnr output file will e the Console winow foun in the Tools menu uner the min Workspe menu. By running the following, rn = rn = rn = rn = rn = rn = rn = you will sen seven numers to the stnr output file. 507111939 1815247477 1711656657 1717468248 1161144809 1176904574 1910786348 You won t get these numers. It will e ifferent set every time. Another wy to see the numer rete is to print it: retive uses of rnom numers 167

Tking Avntge of PostSript 72 1399702527 0 0 72 144 216 288 360 lern PS 16 2 %!PS-Aoe-2.0 EPSF-2.0 %%Title:seeRn1.eps %%DoumentFonts:Times-Bol %%BouningBox:36 36 288 72 /Times-Bol finfont 48 slefont setfont /str 10 string ef 36 36 moveto rn str vs show 16.2 srn In the previous exmple, every time the progrm is run, ifferent numer will e generte. By using the opertor srn, whih n e unerstoo s seernom numer, repetle series of numers n e rete. The syntx of srn is: integer srn lern PS 16 3 Where integer is the see numer. 1734 srn rn = rn = rn = rn = rn = rn = rn = Every time this is sent to the PostSript interpreter, the sme seven numers will e generte. Following is n expne version of seern1.eps. 72 29143338 185810250 471649012 29143338 185810250 471649012 0 0 72 144 216 288 360 168 retive uses of rnom numers

Chpter 16 lern PS 16 4 %!PS-Aoe-2.0 EPSF-2.0 %%Title:seeRn2.eps %%DoumentFonts:Times-Bol %%BouningBox:36 36 335 90 /Times-Bol finfont 18 slefont setfont /str 10 string ef 1734 srn 36 36 moveto rn str vs show 144 36 moveto rn str vs show 254 36 moveto rn str vs show 1734 srn 36 72 moveto rn str vs show 144 72 moveto rn str vs show 254 72 moveto rn str vs show 16.3 rnom x y plement The PostSript rnom numer genertor n e use to supply vlues for the moveto or lineto opertors. The rnom numer rete, however, nees to e onfine to ertin rnge so tht there is resonle expettion of where items will e lote. Otherwise, you ll e off the pge most of the time. Creting rnom numer tht is lwys within ertin rnge n e one with the mo opertor. mo ivies the top two integers on the stk n pushes the ivision s reminer onto the stk. For exmple, 77 10 mo woul return 7. No mtter wht the first integer is, the reminer will lwys e etween 0 n the ivier minus 1. In the following exmple, 10 rnom numers re generte etween 0 n 100. A ifferent set n e me if the srn vlue is hnge. 72 42 72 37 72 79 29 33 33 77 94 0 0 72 144 216 288 360 PS lern 16 5 %!PS-Aoe-2.0 EPSF-2.0 %%Title:seeRn3.eps %%DoumentFonts:Times-Bol %%BouningBox:36 36 362 100 /Times-Bol finfont 36 slefont setfont /str 20 string ef /rnge 100 ef /rnum {rn rnge mo} ef retive uses of rnom numers 169

Tking Avntge of PostSript 173468 srn 36 36 moveto rnum str vs show 108 36 moveto rnum str vs show 180 36 moveto rnum str vs show 254 36 moveto rnum str vs show 326 36 moveto rnum str vs show 36 72 moveto rnum str vs show 108 72 moveto rnum str vs show 180 72 moveto rnum str vs show 254 72 moveto rnum str vs show 326 72 moveto rnum str vs show To tke vntge of these numers to mke grphi, you n write: rnum rnum moveto rnum rnum lineto stroke This will rw line from rnom strt to rnom en. The eginning n the en will e within whtever rnge is eie. The next step is to repet the line so tht vrious ptterns or textures n e rete. In the following exmple, the first luster is n exmple of repeting the line of oe ove. The seon luster is n exmple of using the repetition twie with hnge in line weight n vlue. The thir luster of lines emonstrtes how y using srn with the sme see efore rwing the luster of lines, the sme pttern of lines n e me n overlppe. 72 0 0 72 144 216 288 360 PS lern 16 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnLines.eps %%BouningBox:36 36 324 108 /rnge72 ef /rnum {rn rnge mo} ef 36 36 trnslte % first luster 25 {rnum rnum moveto rnum rnum lineto stroke} repet 108 0 trnslte % seon luster.5 setgry 4 setlinewith 170 retive uses of rnom numers

Chpter 16 25 {rnum rnum moveto rnum rnum lineto stroke} repet 0 setgry 1 setlinewith 25 {rnum rnum moveto rnum rnum lineto stroke} repet 108 0 trnslte % thir luster 173468 srn.5 setgry 4 setlinewith 25 {rnum rnum moveto rnum rnum lineto stroke} repet 173468 srn 0 setgry 1 setlinewith 25 {rnum rnum moveto rnum rnum lineto stroke} repet Following is similr exmple using the urveto opertor. 72 0 0 72 144 216 288 360 lern PS 16 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnurves.eps %%BouningBox:36 24 362 140 /n {rn 72 mo} ef 36 36 trnslte % first srile n n moveto 25 {n n n n n n urveto} repet stroke 72 0 trnslte % seon srile.5 setgry 4 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke 0 setgry 1 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke 72 0 trnslte % thir srile retive uses of rnom numers 171

Tking Avntge of PostSript 172 retive uses of rnom numers 192837465 srn.5 setgry 4 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke 192837465 srn 0 setgry 1 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke 72 0 trnslte % fourth srile 1734173417 srn % ottom.8 setgry 10 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke 1734173417 srn % mile.5 setgry 5 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke 1734173417 srn % top 0 setgry.25 setlinewith n n moveto 25 {n n n n n n urveto} repet stroke rnom plement of type The rnom plement of type is essentilly omplishe in the sme wy s in the previous setion. Here we generte seprte x n y vlues. 16.4 0 0 72 144 216 288 72 144 e e e e e e e e e e e e e e e e e e e e e e e e e e e e ee e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g

Chpter 16 lern PS 16 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnAlph1.eps %%BouningBox:36 36 330 184 /x {rn 288 mo} ef % x will e etween 0 & 288 /y {rn 144 mo} ef % y will e etween 0 & 144 /Pltino-Romn finfont 10 slefont setfont 36 36 trnslte 100 {x y moveto () show} repet 100 {x y moveto () show} repet 100 {x y moveto () show} repet 100 {x y moveto () show} repet 100 {x y moveto (e) show} repet 100 {x y moveto (f) show} repet 100 {x y moveto (g) show} repet A seon exmple of rnomly pling type introues few helpful vritions of the rnom numer proeure. Hving the proeure /x {rn exh mo} ef use in this wy 100 x y moveto (A) show 200 x y moveto (B) show 300 x y moveto (C) show n give flexiility in the progrm to proue vrile rnges for the vlue of x. In the next exmple, this tehnique is use for the x vlue use y the moveto opertor. The ition of the 12 su to the /x n /y proeures elow shifts the vlues for x n y y 12 so tht the type will e roppe left n ottom. 144 72 EE EE E EEE E D E E E D E E E E D E E E E EE E E E D DD D CCB B C C C D D D CD D C E D CCC E E DD D D D E E D DD D C C A C C BB BB B AB BB CB C A C D E E 0 0 72 144 216 288 retive uses of rnom numers 173

Tking Avntge of PostSript lern PS 16 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnAlph2.eps %%BouningBox:0 0 366 224 /x {rn exh mo 12 su} ef /y {rn 130 mo 12 su} ef /AvntGre-Demi finfont 48 slefont setfont 36 36 trnslte 0 0 moveto 288 0 rlineto 0 144 rlineto -288 0 rlineto losepth lip newpth 933478383 srn.8 setgry 100 {290 x y moveto (E) show} repet.6 setgry 60 {200 x y moveto (D) show} repet.4 setgry 35 {150 x y moveto (C) show} repet.2 setgry 25 {100 x y moveto (B) show} repet 0 setgry 10 {40 x y moveto (A) show} repet 16.5 rnom gry vlues A rnomly generte numer n e use y the setgry opertor s well. In this se, we nee numer etween 0 n 1. To get the numer, numer etween 0 n 100 is generte with rn 100 mo n then this numer is multiplie y.01 to shift the eiml point. The following exmple is similr to seern2.eps seen erlier in setion 16.2. In this version, the generte numer is uplite so it n e use twie. The first is use y the setgry opertor, the opy is onverte to string n pinte. Therefore, the numer ppers in its gry vlue. 0.32 0.27 0.06 0.22 0.78 0.48 0.21 0.31 0.87 0.35 0 0 72 144 216 288 360 PS lern 16 10 %!PS-Aoe-2.0 EPSF-2.0 %%Title:seeRgry1.eps %%DoumentFonts:Times-Bol %%BouningBox:36 18 360 70 /Times-Bol finfont 18 slefont setfont /str 10 string ef 174 retive uses of rnom numers

Chpter 16 /rg {rn 100 mo.01 mul} ef 6234572 srn 36 18 moveto rg up setgry str vs show 108 18 moveto rg up setgry str vs show 180 18 moveto rg up setgry str vs show 254 18 moveto rg up setgry str vs show 326 18 moveto rg up setgry str vs show 36 48 moveto rg up setgry str vs show 108 48 moveto rg up setgry str vs show 180 48 moveto rg up setgry str vs show 254 48 moveto rg up setgry str vs show 326 48 moveto rg up setgry str vs show A vrition of this proeure is to onfine the gry vlues within n even tighter rnge y multiplying y.001 inste of.01 n then ing numer to fill the first eiml spe. The numer otine from the rnom genertion my e 0.027, for exmple. By ing 0.3, it will e 0.327. See exmple elow. By moving the eiml over three ples inste of two, the numer will lwys e 0.0xx. Whtever numer is then e etermines the nrrow rnge s long s it s etween 0.1 n 0.9. Or, nothing if you wnt to keep it in the 0.001 to 0.099 rnge. 0.332 0.327 0.306 0.322 0.378 0.348 0.321 0.331 0.387 0.335 0 0 72 144 216 288 360 PS lern 16 11 %!PS-Aoe-2.0 EPSF-2.0 %%Title:seeRgry2.eps %%DoumentFonts:Times-Bol %%BouningBox:36 18 370 70 /Times-Bol finfont 18 slefont setfont /str 10 string ef /rg {rn 100 mo.001 mul.3 } ef 6234572 srn 36 18 moveto rg up setgry str vs show 108 18 moveto rg up setgry str vs show 180 18 moveto rg up setgry str vs show 254 18 moveto rg up setgry str vs show 326 18 moveto rg up setgry str vs show 36 48 moveto rg up setgry str vs show 108 48 moveto rg up setgry str vs show 180 48 moveto rg up setgry str vs show 254 48 moveto rg up setgry str vs show 326 48 moveto rg up setgry str vs show retive uses of rnom numers 175

Tking Avntge of PostSript lern PS 16 12 Another exmple is the listing for the esign on the first pge of this hpter. %!PS-Aoe-2.0 EPSF-1.2 %%Title:qu_.eps %%BouningBox:0 0 360 360 /Helveti-Bol finfont 12 slefont setfont /n {rn exh mo} ef /nn {rn 200 mo} ef /g {rn 100 mo.01 mul} ef /ox {0 0 moveto 180 0 lineto 180 180 lineto 0 180 lineto losepth} ef 173417 srn 0 180 trnslte ox fill % upper left gsve ox lip newpth / {180 n nn moveto () show} ef / {144 n nn moveto () show} ef / {108 n nn moveto () show} ef / {72 n nn moveto () show} ef /e {36 n nn moveto () show} ef 25 {g setgry 25 {} repet} repet 20 {g setgry 25 {} repet} repet 15 {g setgry 25 {} repet} repet 10 {g setgry 25 {} repet} repet 10 {g setgry 25 {e} repet} repet grestore 0-180 trnslte ox.5 setgry fill gsve ox lip newpth / {nn 180 n moveto () show} ef / {nn 144 n moveto () show} ef / {nn 108 n moveto () show} ef / {nn 72 n moveto () show} ef /e {nn 36 n moveto () show} ef 25 {g setgry 25 {} repet} repet 20 {g setgry 25 {} repet} repet 15 {g setgry 25 {} repet} repet 10 {g setgry 25 {} repet} repet 10 {g setgry 25 {e} repet} repet grestore 180 180 trnslte ox.2 setgry fill 176 retive uses of rnom numers

Chpter 16 gsve ox lip newpth / {nn 180 n moveto () show} ef / {nn 144 n moveto () show} ef / {nn 108 n moveto () show} ef / {nn 72 n moveto () show} ef /e {nn 36 n moveto () show} ef 25 {g setgry 25 {} repet} repet 20 {g setgry 25 {} repet} repet 15 {g setgry 25 {} repet} repet 10 {g setgry 25 {} repet} repet 10 {g setgry 25 {e} repet} repet grestore 0-180 trnslte ox.9 setgry fill gsve ox lip newpth / {36 n nn moveto () show} ef / {72 n nn moveto () show} ef / {108 n nn moveto () show} ef / {144 n nn moveto () show} ef /e {180 n nn moveto () show} ef 25 {g setgry 25 {} repet} repet 20 {g setgry 25 {} repet} repet 15 {g setgry 25 {} repet} repet 10 {g setgry 25 {} repet} repet 10 {g setgry 25 {e} repet} repet grestore retive uses of rnom numers 177

Tking Avntge of PostSript 178 some vne progrmming ies

17 hpter Chpter 17 some vne progrmming ies There re numer of tehniques tht n e use to inrese the performne of your PostSript progrms. The tehniques involve new wys of efining the proeures you write, reefining PostSript opertors, n reting your own user itionry of proeures. After this isussion, I ll explin severl esigns in etil. 17.1 erly ining PostSript is n extensile lnguge, mening ox, s efine in this exmple, /ox { moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth } ef n e use like ny other PostSript opertor. You hve expne the voulry of the PostSript lnguge. Proeures tht you rete re lote in the userit itionry on itionry stk. PostSript opertors re foun in the systemit itionry elow userit on the stk. When nme or key is enountere, the userit is looke into first, the systemit seon, going own the stk. Every time ox is use, the PostSript interpreter looks first in the user itionry for the mening of ox. Wht is foun there is moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth. Next, the userit, then the systemit itionries re serhe for the vlue of moveto, rlineto, n losepth. Things oul e spe up if ll this lookup tivity oul e simplifie. This n e one with proess lle erly ining n it s one with the in opertor. All tht looking up proess esrie in the previous prgrph is lle lte ining. The ox proeure using in woul e written like this: /ox { moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth } in ef Now the lookup is performe when the proeure is first efine. When the key ox is now enountere in progrm, its vlue is exeute without ny lookup. In short progrm, the performne ifferene is negligile. Most of the progrm exmples in this ook woul not enefit from this. It is useful, however, in muh lrger progrms tht tke more time to proess. If proeure nme is use within the efinition of nother proeure, in is only neee in the seon proeure. There is no e enefit in ining oth proeures, nor is there penlty. For exmple, the in use in the R_ox proeure tht follows will lso pply to the ox proeure. some vne progrmming ies 179

Tking Avntge of PostSript /ox {0 0 moveto 8 0 rlineto 0 8 rlineto -8 0 rlineto losepth fill} ef /R_ox {100 {10 0 trnslte ox} repet} in ef 17.2 lo Another tehnique to inrese the effiieny of your progrm is to reue its size. Sometimes just the mount of informtion eing sent to the printer is tking up ll the time, not the PostSript interpreter proessing wht ws reeive. Agin, not muh gin is going to e ttine in short progrm. However, if PostSript progrm hs lrge numer of moveto s, lineto s, n stroke s for exmple, its size n e reue signifintly if they were reple with m, l, n s. The opertor lo n e use to renme PostSript opertors. Atully, lineto is the key to the vlue of PostSript opertor tht rws line. The key to this opertor vlue n e hnge. lo pushes the opertor vlue onto the opern stk n in n then e use to tightly ssoite new key or nme to the opertor. Following is n exmple using oth in n lo. 72 0 0 72 144 216 PS lern 17 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:3oxDesigns.eps %%BouningBox:36 36 252 108 / {in ef} in ef /l {lo ef} /lw /setlinewith l /g /setgry l /m /moveto l / /r l /rl /rlineto l /l /lineto l / /urveto l /p /losepth l /s /stroke l /f /fill l 180 some vne progrmming ies

Chpter 17 % first ox.5 g 36 36 m 108 36 l 108 108 l 36 108 l p f 0 g 2 lw 72 72 36 0 360 s % seon ox.2 g 4 lw 108 36 m 72 0 rl 0 72 rl -72 0 rl p f 1 g 108 72 m 144 108 144 36 180 72 s % thir ox.8 g 2 lw 180 36 m 72 0 rl 0 72 rl -72 0 rl p f 0 g 180 36 m 72 72 rl s 252 36 m -72 72 rl s 17.3 PS lern 17 2 mking user itionry The list of efinitions use in the eginning of 3oxDesigns.eps n e forme into user itionry. This is silly mking your own lser printer prep file. The Mintosh Lser Prep file is userit itionry nme m (proly for mintosh itionry). It nees to e in the LserWriter when printing euse Mintosh softwre uses the proeures efine in the m itionry when it sens file to the printer. The m itionry ontins 250 proeure efinitions. You n t open the Lser Prep file, ut it n e exmine in nother wy. Open ny file n selet Print from the File menu. Immeitely fter you lik on OK in the Print ilog ox, press ommn k on the keyor. A text file will e rete on your isk rive of the m itionry plus your file s it woul e sent to the printer. A vrition of this is pressing ommn f. This will rete the sme text file minus the m itionry. The files will e nme PostSript0, PostSript1, n so on up to PostSript9 n then strt over t PostSript0. This PostSript file, if sent to the lser printer, woul resie in the printer s RAM just s the Lser Prep file oes. Note tht this is silly the sme opertion s ownloing font to the printer. See setion 15.7. %!PS-Aoe-2.0 %%Title:Sherm_it.ps serverit egin 0 exitserver /Sherm 13 it ef Sherm egin % mke it with room for 13 ef % put it on top of it stk / {in ef} in ef /l {lo ef} /lw /setlinewith l /g /setgry l /m /moveto l / /r l /rl /rlineto l /l /lineto l / /urveto l /p /losepth l /s /stroke l /f /fill l some vne progrmming ies 181

Tking Avntge of PostSript en % remove s top itionry lern PS 17 3 This version of 3oxDesigns.eps oul then e sent: %!PS-Aoe-2.0 EPSF-1.2 %%Title:withoutDit.eps %%BouningBox:36 36 252 108 Sherm egin % put it on top of it stk % first ox.5 g 36 36 m 108 36 l 108 108 l 36 108 l p f 0 g 2 lw 72 72 36 0 360 s % seon ox.2 g 4 lw 108 36 m 72 0 rl 0 72 rl -72 0 rl p f 1 g 108 72 m 144 108 144 36 180 72 s % thir ox.8 g 2 lw 180 36 m 72 0 rl 0 72 rl -72 0 rl p f 0 g 180 36 m 72 72 rl s 252 36 m -72 72 rl s en % remove from top of it stk PS lern 17 4 However, tht wy of hnling your itionry n e inonvenient if you nee to print your files t numer of ifferent lotions. To inrese the portility of your files, your itionry n e inlue in the file. %!PS-Aoe-2.0 EPSF-1.2 %%Title:withDit.eps %%BouningBox:36 36 252 108 /Sherm 13 it ef Sherm egin / {in ef} in ef /l {lo ef} /lw /setlinewith l /g /setgry l /m /moveto l / /r l /rl /rlineto l /l /lineto l / /urveto l /p /losepth l /s /stroke l /f /fill l % first ox.5 g 36 36 m 108 36 l 108 108 l 36 108 l p f 0 g 2 lw 72 72 36 0 360 s % seon ox 182 some vne progrmming ies

Chpter 17.2 g 4 lw 108 36 m 72 0 rl 0 72 rl -72 0 rl p f 1 g 108 72 m 144 108 144 36 180 72 s % thir ox.8 g 2 lw 180 36 m 72 0 rl 0 72 rl -72 0 rl p f 0 g 180 36 m 72 72 rl s 252 36 m -72 72 rl s en 17.4 3 esigns expline, gdesign listing In this n the following two setions I ll explin three of my PostSript esigns in more etil n present my pproh to writing progrm. I generlly egin simply y eiing on formt n the germ of n ie. I lso like working on series, so one ie n fee into nother. I m lwys opying progrm frgments from other PostSript files to get things strte. With this in min, I generlly try to write in suh wy tht this n esily e one. This esign n e foun on the first pge of hpter 7, type sis. We ll strt with the stnr EPS heer info. The originl esign ws intene to e lrger. I egn with.5.5 sle to reue the esign y hlf. I lso reflete the reue size in the %%BouningBox: omment. It use to e 0 0 800 800. some vne progrmming ies 183

Tking Avntge of PostSript PS lern 17 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:gDesign.eps %%Cretor:John F Shermn %%CretionDte:8 Mrh 1989 %%DoumentFonts:Times-Bol %%BouningBox:0 0 400 400.5.5 sle % reue, originlly esigne for linotron % rememer to reflet hnge in BouningBox /Times-Bol finfont 800 slefont setfont % -------------------------------------------------------- This esign uses the pttern proeure (see hpter 13) written s 2-it piture pttern. As 2-it piture, the onfinement of vlue rnge is still there, ut there re lso other vlues thrown in tht give sprkle effet. I lso use n sx sy sle within the pttern efinition to etermine the pttern s size. sx n sy re efine n reefine four times efore pttern is use throughout the progrm. % -------------------------------------------------------- /str 512 string ef % use y pttern pro /pttern % ef for 200 200 rnom pttern {/light exh ef /rk exh ef /iff light rk su ef sx sy sle 200 200 2 [200 0 0 200 0 0] {0 1 511 {str exh rn iff mo rk put} for str} imge } in ef % kgroun seen on top n right sies 0 0 moveto 800 0 lineto 800 800 lineto 0 800 lineto losepth fill % 800 point Times-Bol g, outline with 50% gry 4 pt line 4 setlinewith.5 setgry 350 420 moveto (g) true hrpth stroke gsve % lrge pttern /sx 700 ef /sy 700 ef 0 50 pttern grestore gsve % 1 y 2 ner ottom /sx 100 ef /sy 200 ef 100 0 trnslte 25 50 pttern grestore 184 some vne progrmming ies

Chpter 17 gsve % 1 y 1 ner top /sx 100 ef /sy 100 ef 100 700 trnslte 0 255 pttern grestore gsve % pttern in g 300 250 moveto (g) true hrpth lip /sx 700 ef /sy 700 ef 150 250 pttern % pttern for lip grestore 1 setgry 2 setlinewith 420 336 moveto (g) true hrpth stroke /Times-Bol finfont 400 slefont setfont 0 setgry 160 400 moveto (G) show some vne progrmming ies 185

Tking Avntge of PostSript 17.5 PS lern 17 6 sontclef listing Here s the stnr EPS heer info: %!PS-Aoe-2.0 EPSF-2.0 %%Title:sontClef.eps %%CretionDte:9 July 1988 rev 7 August 1989 %%Cretor:John F Shermn %%DoumentFonts:Sont %%BouningBox:0 0 840 1850 186 some vne progrmming ies

Chpter 17 % -------------------------------------------------------- The lines of oe elow set the pge size for the Linotron. It is written in this wy so tht if it is printe on something other thn Linotron, suh s proof on n Apple LserWriter, the file oesn t fil. The sttusit is speil itionry tht ontins things suh s the printer s efult pge size, the printer s nme, whether or not the printer prints test pge, n numer of other persistent vlues. egin mkes sttusit the urrent itionry. /prout lo returns or gets the vlue of prout for the lser printer. In the se of n Apple LserWriter, /prout lo returns LserWriter; with Linotron L300, it returns Linotype. Therefore, epening on whih printer you re using, this line woul re LserWriter Linotype eq or re Linotype Linotype eq. eq looks to see if the top two items on the stk re equl n returns either true or flse (known s oolen). On the LserWriter we ll get flse, on the L300 we ll get true. In the next line, {840 1850 12 1 setpgeprms} if, etween the { } is proeure tht sets the pge size to 840 wie, 1850 high, n n offset of 12 points from the ege s vertil pge (0 is lnspe). if is ontrol opertor tht will exeute the pge size proeure if the oolen from the previous line is true. If it s flse, the pge size oesn t hnge. In short, if this file is eing printe on Linotron, use these pge prmeters. If not, isregr them. % -------------------------------------------------------- sttusit egin /prout lo (Linotype) eq {840 1850 12 1 setpgeprms} if en % -------------------------------------------------------- This next setion of the progrm is user itionry nme Sherms ontining opertor reefinitions n proeures. The purpose of Sherms is to hopefully gin some performne, ut mostly it is typing onveniene. It is esier to type m inste of moveto, l for lineto, n so on. If the files were very lrge, performne woul e more esily seen. See setion 17.3. % -------------------------------------------------------- /Sherms 35 it ef Sherms egin / {in ef} in ef /l {lo ef} /m /moveto l / /urveto l /rl /rlineto l /l /lineto l /s /show l /S /stroke l /r /repet l some vne progrmming ies 187

Tking Avntge of PostSript urx ury 0 0 moveto llx lly % -------------------------------------------------------- The purpose of the following lines of oe is to otin four numers. The four numers re the ouning ox of the lef hrter of the Sont font. The ouning ox is the x y lotions of the lower left n upper right orners. I nee these numers so I n utomtilly rete pttern the sme size s the lef hrter s ouning ox. One I get the four numers, I ll nee to just them euse the lower left orner will hve negtive y vlue. Note where the 0 0 moveto is lote in this rwing. I etermine the size of the lef y tril n error using seebbox1.ps foun in setion D.5. % -------------------------------------------------------- /Sont finfont [456.87 0 0 355 0 0] mkefont setfont 0 0 m (&) true hrpth % get hr pth flttenpth % reues urves to stright lines pthox % get BBox numers /ury exh ef /urx exh ef /lly exh ef /llx exh ef newpth % ler pth /str 512 string ef /y lly neg ury vi ef /x urx vi ef /pttern { /rk exh ef /lite exh ef /if rk lite su ef x y sle % x n y from ove, size of pttern x y 8 [ x 0 0 y 0 0 ] {0 1 511 {str exh rn if mo lite put} for str} imge} /n {rn exh mo vr} /gry {100 n.01 mul.1 } /r1 {800 n 1200 n m (e) s} % rnom notes /r2 {400 n 400 n m (e) s} /r3 {400 n 400 n m (h) s} /r4 {400 n 400 n m (w) s} % -------------------------------------------------------- newpth % frme 0 setgry 0 0 m 0 1850 l 840 1850 l 840 0 l losepth 6 setlinewith S 222 srn gsve % pttern ehin everything 3 3 sle 25 50 pttern 188 some vne progrmming ies

Chpter 17 grestore gsve 20 setflt % to prevent limithek error 3 3 sle llx lly s m % ple lef (&) true hrpth lip 50 100 pttern % pttern in lip lef grestore % rnom notes --------------------------------------------- /Sont finfont 18 slefont setfont 500000000 srn gsve 50 50 trnslte 20 {gry setgry 10 {r1} r } r 10 {gry setgry 10 {r3} r } r grestore gsve 200 200 trnslte 5 {gry setgry 10 {r2} r } r 5 {gry setgry 10 {r4} r } r grestore % stff ---------------------------------------------------- 40 setlinewith.5 setgry 600 1600 m 250 0 rl S 600 1400 m 250 0 rl S 600 1200 m 250 0 rl S 600 1000 m 250 0 rl S 600 800 m 250 0 rl S % urve ---------------------------------------------------- 2 setlinewith 1 setgry 0 700 m 250 700 l 280 700 318.4 710.1 316 740 313.6 769.5 271.6 784.6 246 770 218 754 228 708 194 708 175.1 708 158 728 166 748 177.1 775.9 206.8 758.9 226 776 252.2 799.4 239.4 833 264 858 305.7 900.3 357.2 903.2 414 886 480 866 484 798 554 778 596.4 765.9 632 792 644 848 654.7 898.2 626 902 616 880 S 0 625 m some vne progrmming ies 189

Tking Avntge of PostSript 400 625 l 470.2 625 514 666 578 652 611.9 644.6 627 633 650 598 S 0 550 m 500 0 rl S 0 475 m 500 0 rl S 0 400 m 500 0 rl S S % lrge note ----------------------------------------------- /Sont finfont 300 slefont setfont 300 625 m.9 setgry (e) s en % for sherms it showpge 190 some vne progrmming ies

Chpter 17 17.6 symphony, opus 1 listing This esign is the first pnel of triptyh entitle Symphony, opus 1. It egins with the efinition of rbit-romn, font expline in more etil in 15.6. This esign inlues two smll snne imges. These snne imges were rete using Ion on the NeXT for wnt of nything else t the time. If you re using the M, I use Aoe PhotoShop to mke your pitures. Also, I woul get goo text eitor (I use QUED) if you now use MSWor or MWrite to write your text files. Files with snne imges ten to e ig; MSWor n MWrite on t hnle lrge files very well. The size of your file my lso e limite y the mount of RAM you hve in your omputer. some vne progrmming ies 191

Tking Avntge of PostSript PS lern 17 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:symphony, opus 1.1 %%Cretor:John F Shermn University of Notre Dme %%CretionDte: opyright Jn 1990 %%DoumentFonts:Sont %%BouningBox:0 0 840 1850 sttusit % For Linotron printing egin /prout lo (Linotype) eq {840 1850 12 1 setpgeprms} if en /newfont 10 it ef newfont egin /FontType 3 ef /FontMtrix [.001 0 0.001 0 0] ef /FontBBox [0 0 1000 1000] ef /Enoing 256 rry ef StnrEnoing Enoing opy pop /ChrPros 30 it ef ChrPros egin /.notef{ } ef /str 512 string ef /rbit { 0 1 511{ChrPros /str get exe exh rn 255 mo put} for ChrPros /str get exe } ef /spe{0 0 moveto newpth} in ef /zero {48 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /one /two {49 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef {50 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /three{51 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /four {52 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef 192 some vne progrmming ies

Chpter 17 /five {53 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /six {54 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /seven{55 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /eight{56 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /nine {57 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /A {65 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /B {66 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /C {67 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /D {68 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /E {69 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /F {70 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef / {97 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef / {98 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef / {99 srn some vne progrmming ies 193

Tking Avntge of PostSript 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef / {100 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /e {101 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef /f {102 srn 100 100 true [.1 0 0.1 0 0] {ChrPros /rbit get exe}imgemsk} in ef en /BuilChr {1000 0 0 0 1000 1000 setheevie exh egin Enoing exh get ChrPros exh get exe en} ef en /rbit-romn newfont efinefont pop % PROCEDURES ---------------------------------------------- % These proeures re efine to simplify typing. / {in ef} in ef /l {lo ef} /m /moveto l /sg /setgry l /s /show l /fstr 256 string ef % BEGIN DESIGN ONE ----------------------------------------- Sine rbit-romn is mono-spe font, I n set up gri pttern se on its point size of 100. A hrter n spe re eh 100 points squre. Notie my m or moveto ommns re in 100 point intervls up the pge. Lter on you ll see spes use to rek up the pttern. % --------------------------------------------------------- /rbit-romn finfont 100 slefont setfont gsve 20 25 trnslte.9 sg 0 0 m (12312312) s 0 100 m (12312312) s 0 200 m (12312312) s 0 300 m (12312312) s 0 400 m (12312312) s 0 500 m (12312312) s 194 some vne progrmming ies

Chpter 17 0 600 m (12312312) s 0 700 m (12312312) s 0 800 m (12312312) s 0 900 m (12312312) s 0 1000 m (12312312) s 0 1100 m (12312312) s 0 1200 m (12312312) s 0 1300 m (12312312) s 0 1400 m (12312312) s 0 1500 m (12312312) s 0 1600 m (12312312) s 0 1700 m (12312312) s grestore gsve % fountin -21 rotte 255-1 0 { fstr exh up put } for 70 1900 sle 256 1 8 [ 256 0 0 1 0 0 ] { fstr} imge grestore % --------------------------------------------------------- This tringle shpe ws the prout of n ient. I ment to mke retngle. I entere the oorintes wrong, ut like the result. The tringle shpe is fille lk n is use s lipping pth for the reverse fountin n rbit-romn hrters. % --------------------------------------------------------- gsve % lrge tringle 0 sg 0 1600 moveto 820 1850 lineto 820 0 lineto losepth lip fill.1 sg 20 725 m ( ) s 20 825 m ( ) s 20 925 m ( ) s 20 1025 m ( ) s gsve {1 exh su} settrnsfer % reverses fountin -21 rotte 255-1 0 { fstr exh up put } for 70 1900 sle 256 1 8 [ 256 0 0 1 0 0 ] { fstr} imge grestore.2 sg 20 225 m ( ) s 20 325 m ( ) s 20 425 m ( ) s 20 525 m ( ) s grestore some vne progrmming ies 195

Tking Avntge of PostSript % --------------------------------------------------------- One of the hrteristis of rbit-romn is tht you n see through it. This is euse the imgemsk opertor is use inste of imge. This next setion rws the hlf irle tht lips the fountin with the rbit-romn hrters over it. % --------------------------------------------------------- gsve 420 225 trnslte 0 600 m 0 300 300 270 90 r losepth lip newpth gsve 255-1 0 { fstr exh up put } for 300 600 sle 256 1 8 [ 256 0 0 1 0 0 ] { fstr } imge grestore.2 sg 0 0 m () s 0 100 m () s 0 200 m () s 0 300 m () s 0 400 m () s 0 500 m () s grestore 20 225 m% 3.8 sg() s 20 325 m% 4 (A )s.7 sg (e) s 20 1325 m.2 sg (B ) s.5 sg (1) s.3 sg (1) s 320 1425 m.1 sg (1) s 0 sg % vio3 /pistr 25 string ef gsve 220 525 trnslte 100 100 sle 100 100 2 [100 0 0 100 neg 0 100] {urrentfile pistr rehexstring pop} imge AAAAAAAAAAAAAAAAAAAAA9020020056401690255AAAAAAAAAAAAAAAAAAA 196 some vne progrmming ies

Chpter 17 AAAAAAAA90200500194015501846AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4 06 5K of snne t AAAAAAAAA9A0034008008155555555555555AAAAAAAAAAAAAAAAAAAAAAA9 4008008155555555555555AAAAAAAAAAAAAAAAAAAAAAA9A003400800815 5grestore % vio1 /pistr 50 string ef gsve 620 625 trnslte 200 200 sle 200 200 2 [200 0 0 200 neg 0 200] {urrentfile pistr rehexstring pop} imge 5555555555555555555555555586BFBBA00FBBA4002D55101C000003000 00000000004000000000602AAAAAAAAAAAAAA5555555555555555555555 55 20K of snne t 55555555AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA A55555555555555555555555555555555555555555555AAAAAAAAAAAAAA AAgrestore showpge some vne progrmming ies 197

Tking Avntge of PostSript 198 PostSript Level 2

18 hpter Chpter 18 PostSript Level 2 The PostSript lnguge hs evolve from its first introution in 1985. When introue, it ws primrily oneive s pge esription lnguge for lk n white lser printers. Sine then, extensions hve een me for olor printers, omputer isplys n new tehnologies n fetures ville for iniviul lser printers. PostSript Level 2 rings ll these extensions n new imge opportunities into one unifie implementtion. This hpter will onentrte on some of the PostSript Level 2 opertors tht were originlly rete s extensions for Disply PostSript n olor printers. PostSript Level 2 is so new, not ll printers will e equippe with it, so you my not e le to experiment with some of the opertors presente in this hpter. If you hve ess to NeXT, ll the exmples in this hpter n e trie n experimente with. They will work on oth the lk n white n olor NeXT omputers. If you re Mintosh user, you will either nee Level 2 lser printer to use ll these exmples or olor printer for the olor exmples. If you only hve n Apple LserWriter, some of the olor exmples will work, some will not. For exmple, setrgolor will work on n Apple LserWriter, setmykolor will not. Some of the Disply PostSript opertors, suh s retfill n retstroke, n e simulte with Level 1 opertors. 18.1 retfill In PostSript Level 2, there re two new opertors for rwing squres or retngles. They re retfill n retstroke. They originte from the Disply PostSript extensions. retfill is the omintion of moveto, rlineto, n fill. Its syntx is: x y with height retfill where x y is the lotion of the lower left orner of the retngle on the pge reltive to the origin n with height is the istne from the x y to the upper right orner. x y n e thought of s the equivlent of the urrent point me y moveto when using n rlineto. Unlike rlineto, retfill oes not nee the estlishment of urrent point. In the next exmple, three squres re rwn n pinte. The first is rwn in the onventionl wy, the seon n thir re rwn using retfill. PostSript Level 2 199

Tking Avntge of PostSript 72 0 0 72 144 216 288 360 lern PS 18 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:retfill_1.eps %%BouningBox:36 36 324 108 36 36 moveto % first squre 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill 144 36 72 72 retfill % seon squre 252 36 trnslte % thir squre.5 setgry 0 0 72 72 retfill lern PS 18 2 As expline erlier, mny lser printers will not e le to unerstn retfill. If you re using suh printer, retfill_1.eps n e rewritten to work on Level 1 lser printer. %!PS-Aoe-2.0 EPSF-1.2 %%Title:retfill_2.eps %%BouningBox:36 36 324 108 % simulte retfill on Level 1 lser printer /retfill { /ury exh ef /urx exh ef /lly exh ef /llx exh ef llx lly moveto urx 0 rlineto 0 ury rlineto urx neg 0 rlineto losepth fill } ef 36 36 moveto % first squre 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill 144 36 72 72 retfill % seon squre 252 36 trnslte % thir squre.5 setgry 0 0 72 72 retfill 200 PostSript Level 2

Chpter 18 18.2 retstroke retstroke is the omintion of moveto, rlineto, n stroke. Its syntx is: x y with height retstroke where x y is the lotion of the lower left orner of the retngle on the pge reltive to the origin n with height is the istne from the x y to the upper right orner. Unlike retfill, n optionl mtrix n lso e supplie. x y with height mtrix retstroke mtrix will perform trnsformtion on the retngle s line weight, ut not on the pth itself. This is euse the trnsformtion ours fter the onstrution of the pth. retstroke is muh like retfill, s n e seen in the next exmple. This exmple is silly the sme progrm s retfill_1.eps. 72 0 0 72 144 216 288 360 lern PS 18 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:retstroke_1.eps %%BouningBox:34 34 326 110 % first squre 3 setlinewith 36 36 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth stroke % seon squre 144 36 72 72 retstroke % thir squre 252 36 trnslte 0 0 72 72 retstroke The following exmple is rewrite of retstroke_1.eps for Level 1 lser printer. It is essentilly simple vrition of retfill_2.eps from the previous pge. However, it is not omplete sustitute for retstroke. This simultion will not work for the lter exmples of retstroke tht inlue mtrix. A PostSript Level 2 201

Tking Avntge of PostSript lern PS 18 4 more etile explntion of the onsiertions involve in emulting Level 2 opertors n e foun in Appenix D: Comptiility Strtegies, in the PostSript Lnguge Referene Mnul, seon eition. %!PS-Aoe-2.0 EPSF-1.2 %%Title:retstroke_2.eps %%BouningBox:34 34 326 110 % simulte retstroke on Level 1 lser printer /retstroke { /ury exh ef /urx exh ef /lly exh ef /llx exh ef llx lly moveto urx 0 rlineto 0 ury rlineto urx neg 0 rlineto losepth stroke } ef % first squre 3 setlinewith 36 36 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth stroke % seon squre 144 36 72 72 retstroke % thir squre 252 36 trnslte 0 0 72 72 retstroke As outline in the eginning of this setion, mtrix n e inlue in the retstroke rguments. The trnsformtion ffets the line weight of the retngle. Following re some exmples of how this vrition of retstroke n e use. Note tht the trnsformtions o not hnge the grphi stte. 72 0 0 72 144 216 288 360 lern PS 18 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:retstroke_3.eps %%BouningBox:30 30 342 114 3 setlinewith 202 PostSript Level 2

Chpter 18 % first squre 36 36 72 72 [4 0 0 4 0 0] retstroke % seon squre 144 36 72 72 [1 0 0 1 0 0] retstroke % thir squre 252 36 72 72 [12 0 0 4 0 0] retstroke The result of using mtrix with retstroke n e simulte with Level 1 opertors. In this exmple, the seon n thir retngles omplish the sme result s with retstroke use for the first. 72 0 0 72 144 216 288 360 lern PS 18 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:retstroke_4.eps %%BouningBox:34 30 326 114 3 setlinewith % first squre 36 36 72 72 [1 0 0 4 0 0] retstroke gsve % seon squre 144 36 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth 1 4 sle stroke grestore gsve % thir squre 252 36 moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth [1 0 0 4 0 0] ont stroke grestore The oorintes of the retngles me y retfill n retstroke n e supplie s n rry. These two lines re the sme: PostSript Level 2 203

Tking Avntge of PostSript 36 36 72 72 retfill n [36 36 72 72] retfill The rry n e given nme so tht the sme imensions of retngle n e use severl times. 72 0 0 72 144 216 lern PS 18 7 %!PS-Aoe-2.0 EPSF-1.2 %%Title:othRet_1.eps %%BouningBox:34 30 222 114 /size [0 0 72 72] ef /m [4 0 0 4 0 0] ef 3 setlinewith % first squre gsve 36 36 trnslte.5 setgry size retfill 0 setgry size retstroke grestore % seon squre gsve 144 36 trnslte.5 setgry size retfill 0 setgry size m retstroke grestore 18.3 new type opertors There re severl new font n hrter opertors in PostSript Level 2 tht lso 204 PostSript Level 2

Chpter 18 originte from the Disply PostSript extensions. Some re for onveniene, others provie new typogrphi ontrol. The new opertors re: seletfont xshow yshow xyshow seletfont is onsiere onveniene opertor in tht it omines the funtions of the finfont, slefont, n setfont or the finfont, mkefont, n setfont opertors. Inste of writing, /Times-Bol finfont 42 slefont setfont this n e use: /Times-Bol 42 seletfont Inste of writing, /Times-Bol finfont [42 0 0 24 0 0] mkefont setfont this n e use: /Times-Bol 42 [42 0 0 24 0 0] seletfont Exmples of the uses of seletfont n e foun in the type exmples tht follow. xshow, yshow, n xyshow re new opertors tht provie new strtegies for ustom lettersping. xshow permits the iniviul sping of hrters in string long the x xis. yshow iniviully spes hrters long the y xis n xyshow is the omintion of xshow n yshow. Their syntx re: string spingarry xshow string spingarry yshow string spingarry xyshow where spingarry is n rry of numers tht is the sping for eh hrter. In the following exmple, the first rry, [30 34 37 0], is the sping vlues for T, y, p, n e respetively. If the with of T is hnge from 30 to 34, the ype woul shift to the right 4 points. The e ws given with of 0 only euse nothing is following. If no sping informtion is provie for the lst hrter, n error will our. 72 Type Type 0 0 72 144 216 PostSript Level 2 205

Tking Avntge of PostSript lern PS 18 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:xshow&.eps %%BouningBox:36 18 252 85 /Times-Bol 72 seletfont 36 36 moveto (Type) [30 34 37 0] xshow /Times-Bol [36 0 0 72 0 0] seletfont 180 36 moveto (Type) [17 17 20 0] xshow The following re exmples of xyshow. In this se, the rry is pir of numers for eh hrter s x n y sping within the string. 144 Type 72 Type 0 0 72 144 216 lern PS 18 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_xy1.eps %%BouningBox:36 18 198 164 /Helveti-Bol 70 seletfont 36 108 moveto (Type) show % Level 1 36 36 moveto (Type) [30 0 36 0 40 0 0 0] xyshow % Level 2 72 T y pe 0 0 72 144 216 206 PostSript Level 2

Chpter 18 PS lern18 10 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_xy2.eps %%BouningBox:36 12 156 90 /Helveti-Bol 70 seletfont 36 36 moveto (Type) [30 12 26-18 26 12 0 0] xyshow Following is n exmple using yshow. 144 72 E P T Y YPE T YP T YPE T E 0 0 72 144 216 PS lern 18 11 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_y1.eps %%BouningBox:0 0 294 186 /Helveti-Bol 72 seletfont 36 36 moveto (TYPE) [30 30 30 30] yshow 108 124 moveto (TYPE) [-30-30 -30-30] yshow /Helveti-Bol 36 seletfont 180 36 moveto (TYPE) [30 30 30 30] yshow 216 124 moveto (TYPE) [-30-30 -30-30] yshow Next is n exmple of using xyshow. Note tht the rry is roken over four lines, eh line for wor in the string. PostSript Level 2 207

Tking Avntge of PostSript 72 t h e w i n i s l o w i n g 0 0 72 144 216 lern PS 18 12 %!PS-Aoe-2.0 EPSF-1.2 %%Title:winy.eps %%BouningBox:0 0 294 114 /AvntGre-Demi 12 seletfont 36 72 moveto (the win is lowing) [10 2 10 4 10 6 10-2 14-4 10-6 10-8 10 0 10-14 8-2 10 2 10 2 12 2 10 2 12 2 14 2 10-2 10-2 0 0] xyshow 18.4 olor opertors There re three opertors use to speify olor. They re: hue sturtion rightness sethsolor Level 1 re green lue setrgolor Level 1 yn mgent yellow lk setmykolor Level 2 Where in eh se, the rguments re numers etween 0 n 1. Eh opertor is se on ifferent metho of ientifying olor. The first two ove re se on mixing light, the thir is se on mixing inks. In the following exmple, the sme olor is me using eh opertor. 72 0 0 72 144 216 288 208 PostSript Level 2

Chpter 18 PS lern18 13 %!PS-Aoe-2.0 EPSF-1.2 %%Title:smeColor.eps %%BouningBox:0 0 366 150 /squre {moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill} ef.02.66.61 setrgolor 36 36 squre.486979.969697.66 sethsolor 144 36 squre.95.31.36.03 setmykolor 252 36 squre setrgolor n sethsolor re oth se on itive olor mixing using light. Re, green, n lue light when mixe equl white. White on TV or white lous in the sky re the result of ll olors of light mixe together. Figure 18 1 shows n itive olor wheel. itive re green lue figure 18 1 PS lern olor emo setmykolor is se on sutrtive olor mixing using pint. Mgent, yn, n yellow pigment when mixe equl lk, t lest in theory. Blk is usully inlue in the mix euse goo totl lk is hr to get without help. Figure 18 2 shows sutrtive olor wheel. PostSript Level 2 209

Tking Avntge of PostSript sutrtive mgent yn yellow figure 18 2 Of the two methos, sutrtive olor mixing is the more intuitive wy of speifying olor. It mkes sense tht mixing yn n yellow pint will give green. It n e iffiult, though, to visulize tht re n green light will mke yellow. 18.5 olor pitures Color pitures re me y the olorimge opertor. Its syntx is: with height its mtrix s 0...s n s/ms omp olorimge where: with height its mtrix re the sme s with imge. s 0...s n re one or more t soures. All the olor omponents my e mixe together into one soure or seprte, for exmple, into iniviul re, green, n lue omponents. s/ms is oolen whether the t is from single soure (flse) or multiple soures (true). omp is numer representing the numer of t soures. The following exmple is simplifie version of file me y Aoe PhotoShop. 210 PostSript Level 2

Chpter 18 lern PS 18 14 %!PS-Aoe-2.0 EPSF-1.2 %%Title:Shmrok.eps %%BouningBox:0 0 160 160 /pistr1 16 string ef /pistr2 16 string ef /pistr3 16 string ef /pistr4 16 string ef /ret {urrentfile exh rehexstring pop} ef /shmrok{16 16 8 [.2 0 0.2 0 0] {pistr1 ret} {pistr2 ret} {pistr3 ret pistr4 ret pop} true 3 olorimge} ef gsve shmrok CCCCCCCCCC000000CCCCCCCCCCCCCCCC6633333333669966663333333333... olor t... 66666666003300330033003366666666666666663C423C603C423C60666 6grestore 18.6 overview of new opertors in Level 2 PostSript Level 2 offers numer of new fetures n visul opportunities. It will tke while for ll of these new opertors to mke their wy into printers n omputer isplys. Some things to look forwr to re: Ptterns PostSript Level 2 will hve new opertors to rete ptterns. These ptterns n then e use s the pint for fills n strokes. One pttern ptternnme is rete, it n e use y writing ptternnme setpttern within progrm. Forms Forms n e use to rete the repeting grphis on multiple pge oument or s the nme suggests, on form to e fille out. One the form formnme is efine, it n e use y writing formnme exeform within progrm. Snne pitures Snne pitures will e hnle more effiiently n fster. Snne pitures will e store in ompresse form n e pinte fster. Also, 12-it per pixel lk n white or 36-it olor pitures will e possile. A 12-it piture hs 4096 possile vlues. Color There will e expne support to insure requeste olors will remin onsistent from ifferent snners, to ifferent monitors, to vrious kins of print output. PostSript Level 2 211

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-2.0 %%Title:grss.eps %%BouningBox:0 0 300 300 / {rn 50 mo} ef % numer etween 0 & 50 / {rn 100 mo} ef % numer etween 0 & 100 / {rn 150 mo} ef % & so on / {rn 200 mo} ef % see hp 16 /e {rn 250 mo} ef /f {rn 300 mo} ef 17173434 srn % see rnom # to set sequene.8 setgry % 20% gry 0 0 300 300 retfill % retngle, Level 2 opertor 0 setgry % set olor to lk % rw 34 urve lines % eh ifferent euse of rn numer 34 {0 0 moveto e f urveto stroke} repet 212 lirry of exmples

19 hpter Chpter 19 lirry of exmples The purpose of this hpter is to provie itionl progrmming exmples. Some emonstrte ifferent visul ie thn presente in the text, others re exmples of opertors use in ifferent wy. &M1.eps 244 &M2.eps 245 &M3.eps 246 r&type_1.eps 227 r&type_2.eps 228 rto_2.eps 229 rto_3.eps 230 s-relief.eps 275 kgri.eps 253 ox ef1.eps 222 ox ef2.eps 223 ox ef4.eps 224 rnh2.eps 278 rnh3.eps 279 rnh4.eps 280 lip 1.eps 247 lip 2.eps 248 losepth_2.eps 220 ont_3.eps 225 urvetoloops.eps 270 urveto_2.eps 231 urveto_3.eps 232 shpttern1.eps 217 shpttern2.eps 218 shpttern3.eps 219 exite1.eps 262 exite2.eps 263 exploe.eps 264 flower.eps 265 fountin 3-3.eps 241 fountin_lsreen.eps 259 fountinline.eps 273 gesture.eps 261 grss.eps 212 grychrt.eps 271 grychrtrev.eps 272 linep.eps 215 line.eps 214 petl2.eps 266 pie_hrt2.eps 226 rnjzz.eps 260 repet_ox1.eps 234 repet_ox2.eps 235 rottefount.eps 242 rottefount2.eps 243 setsh2.eps 216 setflt.eps 233 setlinejoin2.eps 221 setsreen1-2.eps 255 setsreen3-4.eps 256 setsreen5-6.eps 257 setsreen7-8.eps 258 slinky.eps 281 slinky2.eps 282 str lip.eps 249 str eolip.eps 250 str eofill.eps 251 str fill.eps 252 str2.eps 274 stringwith.eps 240 TCpos&rev.eps 283 theres3.eps 254 3D-Line1.eps 267 3D-Line2.eps 268 3D-LineStr.eps 269 type_1.eps 236 type_2.eps 237 type_3.eps 238 type_4.eps 239 unenoing1.eps 276 unenoing2.eps 277 lirry of exmples 213

Tking Avntge of PostSript Here re two wys of rwing line: On top, the finish lotion is reltive to the strt lotion. Below, strt n finish lotions re reltive to the origin. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:line.eps %%BouningBox:36 30 252 75 6 setlinewith 36 36 moveto 216 36 lineto stroke 36 72 moveto 216 0 rlineto stroke 214 lirry of exmples

Chpter 19 The setlinep opertor is use to finish line enings. 0 setlinep is the efult. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:linep.eps %%BouningBox:32 32 220 112 12 setlinewith % ottom n efult 36 36 moveto 216 36 lineto stroke % mile 1 setlinep 36 72 moveto 216 72 lineto stroke % top 2 setlinep 36 108 moveto 216 108 lineto stroke lirry of exmples 215

Tking Avntge of PostSript The setsh opertor retes she line. 144 72 0 0 72 144 216 288 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setsh2.eps %%BouningBox:36 18 324 198 6 setlinewith 2 2 sle [1] 0 setsh 18 12 moveto 144 0 rlineto stroke [1] 2 setsh 18 24 moveto 144 0 rlineto stroke [2] 2 setsh 18 36 moveto 144 0 rlineto stroke [1 2] 2 setsh 18 48 moveto 144 0 rlineto stroke [1 2 3 4] 0 setsh 18 60 moveto 144 0 rlineto stroke [1 2 3 4] 2 setsh 18 72 moveto 144 0 rlineto stroke [4 3 2 1] 3 setsh 18 84 moveto 144 0 rlineto stroke [.4.7.5.3.8.2.9.1 1] 4 setsh 18 96 moveto 144 0 rlineto stroke 216 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shPttern1.eps %%BouningBox:0 0 360 100 /line {0.5 trnslte 0 0 moveto 36 0 rlineto stroke} ef /sh [.4.7.5.3.8.2.9.1 1] ef.5 setlinewith 0-2.5 trnslte 10 10 sle 0 setgry sh 0 setsh line.1 setgry sh 1 setsh line.2 setgry sh 2 setsh line.3 setgry sh 3 setsh line.4 setgry sh 4 setsh line.5 setgry sh 5 setsh line.6 setgry sh 6 setsh line.7 setgry sh 7 setsh line.8 setgry sh 8 setsh line.9 setgry sh 9 setsh line 0 setgry sh 10 setsh line.1 setgry sh 9 setsh line.2 setgry sh 8 setsh line.3 setgry sh 7 setsh line.4 setgry sh 6 setsh line.5 setgry sh 5 setsh line.6 setgry sh 4 setsh line.7 setgry sh 3 setsh line.8 setgry sh 2 setsh line.9 setgry sh 1 setsh line lirry of exmples 217

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:shPttern2.eps %%BouningBox:0 0 360 300 /line {0.5 trnslte 0 0 moveto 36 0 rlineto stroke} ef /sh [.4.7.5.3.8.2.9.1 1] ef /x -1 ef.5 setlinewith 0-2.5 trnslte 10 10 sle /pttern{ 0.1 1 {} for 10 {setgry sh x 1 up /x exh ef setsh line} repet 1 -.1 0 {} for 10 {setgry sh x 1 su up /x exh ef setsh line} repet } ef 3 {pttern} repet 218 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:shPttern3.eps %%BouningBox:0 0 200 200 /line {0 4 trnslte 0 0 moveto 40 0 rlineto stroke} ef /sha [.4.7.5.3.8.2.9.1 1] ef /shb [.6.3.5.7.2.8.1.9 1] ef 4 setlinewith 0-10 trnslte 5 5 sle gsve 1 -.1 0 {} for 10 {setgry shb 0 setsh line} repet grestore gsve 0.1 1 {} for 10 {setgry sha 0 setsh line} repet grestore lirry of exmples 219

Tking Avntge of PostSript The losepth opertor is use to finish off the finl orner of pth when the en of pth onnets with its eginning. The ifferene losepth mkes is espeilly notiele when the pths re stroke with thik line. Both squres elow hve een rwn the sme size, ut the first oes not use losepth n the seon oes. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:losepth_2.eps %%BouningBox:32 32 220 112 6 setlinewith 36 36 moveto 36 108 lineto 108 108 lineto 108 36 lineto 36 36 lineto stroke 144 36 moveto 216 36 lineto 216 108 lineto 144 108 lineto losepth stroke 220 lirry of exmples

Chpter 19 The setlinejoin opertor is use to finish orners. 0 setlinejoin is the efult. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setlinejoin2.eps %%BouningBox:27 27 261 117 /ret {54 0 rlineto 0 72 rlineto -54 0 rlineto losepth stroke} ef 18 setlinewith 1 setlinejoin % left, roune 36 36 moveto ret 2 setlinejoin % mile, evele 126 36 moveto ret 0 setlinejoin % right, miter 216 36 moveto ret lirry of exmples 221

Tking Avntge of PostSript Here s n exmple of efining proeure. The oxes elow re rwn with the rlineto opertor, or reltivelineto. Eh line is rwn se on the lotion of the previous urrent point. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ox ef1.eps %%BouningBox:34 34 218 146 /ox { moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth } ef 3 setlinewith 36 36 ox stroke 144 72 ox stroke 222 lirry of exmples

Chpter 19 This ox proeure is efine using the lineto opertor. Note tht the plement for the ox is ontrolle y moving the origin using the trnslte opertor. The gsve n grestore sve n restore the grphi stte. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ox ef2.eps %%BouningBox:34 34 218 146 /ox { 0 0 moveto 72 0 lineto 72 72 lineto 0 72 lineto losepth } ef 3 setlinewith gsve 36 36 trnslte ox stroke grestore gsve 144 72 trnslte ox stroke grestore lirry of exmples 223

Tking Avntge of PostSript The ox proeure is now fille with vlue. 0 equls lk (the efult) n 1 equls white. Note tht the seon ox is lk euse the efult is in fore. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ox ef4.eps %%BouningBox:36 36 288 144 /ox { 0 0 moveto 72 0 lineto 72 72 lineto 0 72 lineto losepth } ef 3 setlinewith gsve.3 setgry 36 36 trnslte ox fill grestore gsve 144 72 trnslte ox fill grestore gsve.8 setgry 216 36 trnslte ox fill grestore 224 lirry of exmples

Chpter 19 The ont opertor is use to skew the ox. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:ont_3.eps %%BouningBox:34 34 218 110 /ox {0 0 moveto 0 36 rlineto 36 0 rlineto 0-36 rlineto losepth stroke} ef 2 setlinewith 36 36 trnslte [1 0 1 1 0 0] ont ox 36 36 trnslte [1 0-1 1 0 0] ont ox 72-36 trnslte [1 0-1 1 0 0] ont ox lirry of exmples 225

Tking Avntge of PostSript The following is vrition of the pie hrt exmple from setion 6.2. 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:pieChrt_2.eps %%BouningBox:34 34 182 182 2 setlinewith 10 10 trnslte 43 25 17 15 % perentges with spe in etween /p1 exh 3.6 mul ef /p2 exh 3.6 mul p1 ef /p3 exh 3.6 mul p2 ef /p4 exh 3.6 mul p3 ef /x 72 ef /y 72 ef /r 72 ef /wege {setgry r losepth gsve fill grestore 0 setgry stroke} ef x y moveto x y r 0 p1.2 wege x y moveto x y r p1 p2.4 wege x y moveto x y r p2 p3.6 wege x y moveto x y r p3 p4.8 wege 226 lirry of exmples

Chpter 19 The show opertor oes not initilize the urrent point. Therefore, the r tthes itself y line to the urrent point fter the wor r. losepth returns the line. 72 r 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:r&type_1.eps %%BouningBox:36 34 180 110 3 setlinewith /Helveti-Bol finfont 24 slefont setfont 36 72 moveto (r) show 144 72 36 270 90 r losepth stroke lirry of exmples 227

Tking Avntge of PostSript newpth initilizes the urrent point left fter the wor r. The urrent point is then the eginning of the r. This is why losepth rws line from the eginning to the en of the r. 72 r 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:r&type_2.eps %%BouningBox:36 34 180 110 3 setlinewith /Helveti-Bol finfont 24 slefont setfont 36 72 moveto (r) show newpth 144 72 36 270 90 r losepth stroke 228 lirry of exmples

Chpter 19 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rto_2.eps %%BouningBox:40 34 250 190 3 setlinewith 144 36 moveto 288 36 144 216 36 rto 144 216 36 36 36 rto 0 36 108 36 36 rto losepth stroke 12 {pop} repet lirry of exmples 229

Tking Avntge of PostSript 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rto_3.eps %%BouningBox:38 36 252 180 3 setlinewith 72 180 moveto 0 0 288 216 36 rto 4 {pop} repet 252 36 lineto stroke 230 lirry of exmples

Chpter 19 In this exmple, the Beziér ontrol points re mrke to lel the urveto syntx elow: x1 y1 x2 y2 x2 y2 urveto urveto requires the existing urrent point x1 y1. x2 y2 72 x1 y1 x2 y2 x1 y1 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:urveto_2.eps %%BouningBox:72 60 216 96 3 setlinewith 72 72 moveto 108 36 144 144 216 72 urveto stroke lirry of exmples 231

Tking Avntge of PostSript This is nother, more involve urve, emonstrting how omplex pths n e rete. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:urveto_3.eps %%BouningBox:34 36 216 132 3 setlinewith 36 36 moveto 36 108 lineto 100 108 90 60 108 108 urveto 130 148 140 120 216 108 urveto stroke 232 lirry of exmples

Chpter 19 This progrm emonstrtes how the setflt opertor n ffet the ury of urve s rwing. The finl result will epen on the resolution of the printer euse this opertor is resolution epenent. 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setflt.eps %%BouningBox:72 40 250 198 /urve { 56 146 moveto 48 109 37 31 67 30 urveto 97 29 75 128 91 142 urveto 107 156 110 148 116 139 urveto 122 130 122 43 112 35 urveto 102 27 123 1 140 23 urveto 157 45 144 117 145 135 urveto 146 153 155 159 166 155 urveto 177 151 179 102 173 79 urveto 167 56 165 44 177 41 urveto 189 38 207 76 200 108 urveto } ef 36 36 trnslte gsve % thik gry line.6 setgry 12 setlinewith 90 setflt urve stroke grestore urve stroke % thin lk line lirry of exmples 233

Tking Avntge of PostSript The rotte opertor rottes the urrent trnsformtion mtrix or CTM. By repeting tht rottion, this esign n e me. 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:repet_ox1.eps %%BouningBox:36 0 252 288 /ox { 0 0 moveto 0 72 rlineto 72 0 rlineto 0-72 rlineto losepth stroke } ef 144 108 trnslte 2 setlinewith 10 { 36 rotte ox } repet 234 lirry of exmples

Chpter 19 This is vrition of the previous exmple using fille n stroke squre. 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:repet_ox2.eps %%BouningBox:36 0 252 288 /ox { 0 0 moveto 0 72 rlineto 72 0 rlineto 0-72 rlineto losepth gsve.5 setgry fill grestore stroke } ef 144 108 trnslte 2 setlinewith 10 { 36 rotte ox} repet lirry of exmples 235

Tking Avntge of PostSript The show opertor in the exmple elow pints string of hrters strting t urrent point, with the urrent font, in the urrent olor. moveto estlishes the urrent point, /fontnme finfont pointsize slefont setfont estlishes the urrent font, n vlue setgry estlishes the urrent olor. 144 typogrphy 72 Type 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_1.eps %%BouningBox:36 12 270 180 /Helveti-Bol finfont 100 slefont setfont 36 36 moveto (Type) show /Times-BolItli finfont 48 slefont setfont 36 144 moveto.5 setgry (typogrphy) show 236 lirry of exmples

Chpter 19 The show opertor oes not initilize the urrent point. In the exmple elow, rmoveto justs the hrter sping of the wor Type y moving the urrent point left fter the setting of the T. 72 Type 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_2.eps %%BouningBox:36 12 255 110 /Helveti-Bol finfont 100 slefont setfont 36 36 moveto (T) show -12 0 rmoveto (ype) show lirry of exmples 237

Tking Avntge of PostSript The progrm elow ontins exmples of the mkefont opertor. 144 Type 72 Type Type 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_3.eps %%BouningBox:36 12 288 168 % top /Helveti-Bol finfont [108 0 0 36 0 0] mkefont setfont 36 144 moveto (Type) show % ottom left /Helveti-Bol finfont [36 0 0 108 0 0] mkefont setfont 36 36 moveto (Type) show % ottom right norml /Helveti-Bol finfont [36 0 0 36 0 0] mkefont setfont 144 36 moveto (Type) show 238 lirry of exmples

Chpter 19 Here re more exmples of the mkefont opertor. 144 Type Type 72 Type 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:type_4.eps %%BouningBox:40 12 228 190 % top /Helveti-Bol finfont [36 0-36 108 0 0] mkefont setfont 144 108 moveto (Type) show % ottom left /Helveti-Bol finfont [36 0 36 108 0 0] mkefont setfont 36 36 moveto (Type) show % ottom right norml /Helveti-Bol finfont [36 0 0 36 0 0] mkefont setfont 144 36 moveto (Type) show lirry of exmples 239

Tking Avntge of PostSript The following is n exmple of the stringwith opertor. 72 this this lineupthis 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:stringwith.eps %%BouningBox:36 30 200 144 /Times-Bol finfont 36 slefont setfont /with 36 (lineup) stringwith pop ef.5 setgry 36 36 moveto (lineup) show 0 setgry (this) show with 72 moveto (this) show with 108 moveto (this) show 240 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_3-3.eps %%BouningBox:0 0 200 200 /fountin { /str 256 string ef 0 1 255 { str exh up 255 iv hnge mul os neg 2 iv.5 255 mul vi put } for /ury exh ef /urx exh ef /lly exh ef /llx exh ef gsve llx lly trnslte urx llx su ury lly su sle 1 256 8[1 0 0-256 0 256] {str} imge grestore } ef /hnge 720 ef 0 0 100 100 fountin /hnge 360 ef 100 100 200 200 fountin /hnge 180 ef 0 100 100 200 fountin /hnge 1440 ef 100 0 200 100 fountin lirry of exmples 241

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:rotteFount.eps %%Cretor:John F Shermn %%BouningBox:0 0 300 300 /str 256 string ef 0 1 255 { str exh up put } for 0 0 300 300 retstroke 150 150 trnslte gsve 8 {45 rotte gsve 100 100 sle 255 1 8 [255 0 0 1 0 0] {str} imge grestore} repet grestore 242 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rotteFount2.eps %%Cretor:John F Shermn %%BouningBox:0 0 300 300 /str 256 string ef 0 1 255 { str exh up put } for 0 0 300 300 retstroke 150 150 trnslte gsve 8 {45 rotte gsve 70 70 sle 255 1 8 [255 0-255 1 0 0] {str} imge grestore} repet grestore lirry of exmples 243

M Tking Avntge of PostSript The following is logo vrition emonstrting lipping with type. %!PS-Aoe-2.0 EPSF-1.2 %%Title:&M1.eps %%BouningBox:20 19 295 295 % is fille % M is fille /insie /Times-Bol finfont 525 slefont ef /outline /Helveti-Bol finfont 375 slefont ef 0 20 trnslte 0 0 moveto outline setfont (M) true hrpth lip.2 setgry fill.5 setgry 0 9 moveto insie setfont () show 244 lirry of exmples

Chpter 19 MM %!PS-Aoe-2.0 EPSF-1.2 %%Title:&M2.eps %%BouningBox:20 19 295 295 % oth letterforms re outline /insie /Times-Bol finfont 525 slefont ef /outline /Helveti-Bol finfont 375 slefont ef 0 20 trnslte 0 0 moveto outline setfont (M) true hrpth lip newpth 0 9 moveto insie setfont () true hrpth stroke 2 setlinewith 0 0 moveto outline setfont (M) true hrpth stroke lirry of exmples 245

Tking Avntge of PostSript MM %!PS-Aoe-2.0 EPSF-1.2 %%Title:&M3.eps %%BouningBox:20 19 295 295 % is fille % M is outline /insie /Times-Bol finfont 525 slefont ef /outline /Helveti-Bol finfont 375 slefont ef 0 20 trnslte 0 0 moveto outline setfont (M) true hrpth lip newpth.5 setgry 0 9 moveto insie setfont () show 0 setgry 2 setlinewith 0 0 moveto outline setfont (M) true hrpth stroke 246 lirry of exmples

Chpter 19 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:lip_1.eps %%BouningBox:72 36 216 180 72 36 moveto 0 144 rlineto 144 0 rlineto 0-144 rlineto losepth lip newpth 72 36 72 0 360 r.5 setgry fill 216 36 98 0 360 r.2 setgry fill 144 180 72 0 360 r.8 setgry fill lirry of exmples 247

Tking Avntge of PostSript 144 72 ND 0 0 72 144 216 288 %!PS-Aoe-2.0 EPSF-1.2 %%Title:lip_2.eps %%BouningBox:48 36 324 184 36 36 trnslte 0 0 moveto /Helveti-Bol finfont 200 slefont setfont (ND) true hrpth lip /str 256 string ef 0 1 255 { str exh up put } for 288 170 sle 255 1 8 [ 255 0 0 1 0 0 ] {str} imge 248 lirry of exmples

Chpter 19 144 72 rs rs rst StrStrStrStr StrStrStrStr rstrstrs StrStr rstrstr rst StrS rs rs 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:str lip.eps %%BouningBox:36 0 270 216 /str (StrStrStrStr) ef /leing { urrentpoint 22 exh pop 0 exh moveto } ef /kgroun { str show leing } ef /Helveti-Bol finfont 30 slefont setfont 36 0 trnslte % str 45 0 moveto 115 216 lineto 186 0 lineto 0 134 lineto 231 134 lineto 45 0 lineto losepth lip 0 0 moveto 10 {kgroun} repet lirry of exmples 249

Tking Avntge of PostSript The following is n exmple of eolip. 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:str eolip.eps %%BouningBox:36 0 270 216 /str (StrStrStrStr) ef /leing { urrentpoint 22 exh pop 0 exh moveto } ef /kgroun { str show leing } ef /Helveti-Bol finfont 30 slefont setfont 36 0 trnslte rs rs rst StrStrStrStr StrSt trstr rst rs St Str rstrstr rst StrS rs rs % str 45 0 moveto 115 216 lineto 186 0 lineto 0 134 lineto 231 134 lineto 45 0 lineto losepth eolip 0 0 moveto 10 {kgroun} repet 250 lirry of exmples

Chpter 19 The following is n exmple of eofill. 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:str eofill.eps %%BouningBox:36 0 270 216 36 0 trnslte % str 45 0 moveto 115 216 lineto 186 0 lineto 0 134 lineto 231 134 lineto 45 0 lineto losepth eofill lirry of exmples 251

Tking Avntge of PostSript 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:str fill.eps %%BouningBox:36 0 270 216 36 0 trnslte % str 45 0 moveto 115 216 lineto 186 0 lineto 0 134 lineto 231 134 lineto 45 0 lineto losepth fill 252 lirry of exmples

Chpter 19 This is the kgroun gri for mny of the exmples. 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:kGri.eps %%Cretor:John F Shermn %%BouningBox:0 0 294 150 /vline{0 0 moveto 0 144 lineto stroke} ef /hline{0 0 moveto 288 0 lineto stroke} ef.3 setgry 6 setlinewith 3 150 moveto 3 3 lineto 294 3 lineto stroke.5 setgry 1 setlinewith 6 6 trnslte gsve 7 {36 0 trnslte vline} repet grestore gsve 3 {0 36 trnslte hline} repet grestore 0 setgry /Helveti finfont 8 slefont setfont 2 2 moveto (0 0) show 75 2 moveto (72) show 146 2 moveto (144) show 220 2 moveto (216) show 2 75 moveto (72) show lirry of exmples 253

Tking Avntge of PostSript In this exmple, the setsreen is ommente out for omprison with the other setsreen exmples. Most of the snne imge is elete to sve spe. efult setsreen 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:theres3.eps %%BouningBox:36 36 360 198 /ox {moveto 72 0 rlineto 0 72 rlineto -72 0 rlineto losepth fill} ef /Helveti-Bol finfont 10 slefont setfont 36 185 moveto (efult setsreen) show.8 setgry 36 108 ox.6 setgry 108 108 ox.4 setgry 36 36 ox.2 setgry 108 36 ox % snne piture %%Title: Theres.eps... heer info... 72 65536 mul 4718592 iv up ols mul exh rows mul sle ols rows 8 [ols 0 0 rows neg 0 rows] eginimge 0B0A0D0A070E0F0B090D0D110F0E13161515151B17181A141D1A1916181 B1616.... t... 32130A0707050A31607E797B6D5B4D4A514E4C4B4D4E51564C525246434 74F51 565D5D616D6457514F3F352C2118121612161716 grestore en 254 lirry of exmples

Chpter 19 144 20 45 {exh pop} setsreen 20 45 {pop} setsreen 72 0 0 72 144 216 288 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setsreen1-2.eps %%BouningBox:36 36 306 198 /Helveti finfont 10 slefont setfont /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef 20 45 {exh pop} setsreen 36 128 moveto (20 45 {exh pop} setsreen) show.8 setgry 36 144 ox.6 setgry 108 144 ox.4 setgry 180 144 ox.2 setgry 252 144 ox 0 setgry 20 45 {pop} setsreen 36 92 moveto (20 45 {pop} setsreen) show.8 setgry 36 36 ox.6 setgry 108 36 ox.4 setgry 180 36 ox.2 setgry 252 36 ox lirry of exmples 255

Tking Avntge of PostSript 144 20 45 {mul.1 } setsreen 20 45 { 2 iv} setsreen 72 0 0 72 144 216 288 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setsreen3-4.eps %%BouningBox:36 36 306 198 /Helveti finfont 10 slefont setfont /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef 20 45 {mul.1 } setsreen 36 128 moveto (20 45 {mul.1 } setsreen) show.8 setgry 36 144 ox.6 setgry 108 144 ox.4 setgry 180 144 ox.2 setgry 252 144 ox 0 setgry 20 45 { 2 iv} setsreen 36 92 moveto (20 45 { 2 iv} setsreen) show.8 setgry 36 36 ox.6 setgry 108 36 ox.4 setgry 180 36 ox.2 setgry 252 36 ox 256 lirry of exmples

Chpter 19 144 20 45 {up mul exh up mul 2 iv 1 exh su sqrt 1 exh su} setsreen 20 45 {s exh s 2 opy gt {pop}{exh pop} ifelse 1 exh su} setsreen 72 0 0 72 144 216 288 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setsreen5-6.eps %%BouningBox:36 36 342 198 /Helveti finfont 9 slefont setfont /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef 20 45 {up mul exh up mul 2 iv 1 exh su sqrt 1 exh su} setsreen 36 128 moveto (20 45 {up mul exh up mul 2 iv 1 exh su sqrt 1 exh su} setsreen) show.8 setgry 36 144 ox.6 setgry 108 144 ox.4 setgry 180 144 ox.2 setgry 252 144 ox 0 setgry 20 45 {s exh s 2 opy gt {pop}{exh pop} ifelse 1 exh su} setsreen 36 92 moveto (20 45 {s exh s 2 opy gt {pop}{exh pop} ifelse 1 exh su} setsreen) show.8 setgry 36 36 ox.6 setgry 108 36 ox.4 setgry 180 36 ox.2 setgry 252 36 ox lirry of exmples 257

Tking Avntge of PostSript 144 20 45 {exh pop s 1 exh su} setsreen 20 45 { s 2 iv 1 exh su } setsreen 72 0 0 72 144 216 288 %!PS-Aoe-2.0 EPSF-1.2 %%Title:setsreen7-8.eps %%BouningBox:36 36 306 198 /Helveti finfont 10 slefont setfont /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef 20 45 {exh pop s 1 exh su} setsreen 36 128 moveto (20 45 {exh pop s 1 exh su} setsreen) show.8 setgry 36 144 ox.6 setgry 108 144 ox.4 setgry 180 144 ox.2 setgry 252 144 ox 0 setgry 20 45 { s 2 iv 1 exh su} setsreen 36 92 moveto (20 45 { s 2 iv 1 exh su} setsreen) show.8 setgry 36 36 ox.6 setgry 108 36 ox.4 setgry 180 36 ox.2 setgry 252 36 ox 258 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_LSreen.eps %%Cretor:John F Shermn %%BouningBox:0 0 170 170 /str 256 string ef 0 1 255 { str exh up put } for 20 90 {pop} setsreen 170 170 sle 255 1 8 [ 255 0 0 1 0 0 ] {str} imge lirry of exmples 259

Tking Avntge of PostSript 144 72 jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzzjzz jzz jzz jzz jzzjzz jzzjzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzzjzz jzz jzz jzz jzz jzz jzz jzz jzz jzz jzz 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnJzz.eps %%BouningBox:34 34 366 198 /n {rn exh mo} ef /gry {100 n.01 mul} ef 171717 srn 36 36 trnslte /Helveti finfont 18 slefont setfont 25 {gry setgry 25 {300 n 150 n moveto (jzz) show} repet} repet /Helveti finfont 36 slefont setfont 0 setgry 25 {250 n 125 n moveto (jzz) show} repet /Helveti finfont 72 slefont setfont 2 setlinewith 1 setgry 5 {250 n 100 n moveto (jzz) true hrpth stroke} repet 260 lirry of exmples

Chpter 19 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:gesture.eps %%BouningBox:36 36 378 170 /n 85 ef /nnn n 3 mul 1 su ef /x1 {rn 50 mo} in ef /x2 {rn 25 mo} in ef 36 36 trnslte.25 setlinewith x1 x1 moveto 0 1 nnn {} for n {x1 x1 x1 urveto} repet stroke 150 0 trnslte.25 setlinewith x2 x2 moveto 0 1 nnn {} for n {x2 x2 x2 urveto} repet stroke lirry of exmples 261

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:exite1.eps %%BouningBox:0 0 300 300 0 0 300 300 retstroke /x {rn 300 mo} in ef x x moveto 50 {x x x x x x urveto} repet stroke 262 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:exite2.eps %%BouningBox:0 0 300 300 0 0 300 300 retstroke /x {rn 300 mo} in ef /exit{ x x moveto 50 {x x x x x x urveto} repet stroke} ef 5 setlinewith.5 setgry exit 1 setlinewith 0 setgry exit lirry of exmples 263

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:exploe.eps %%BouningBox:0 0 360 360 / {50 rn exh mo} in ef / {100 rn exh mo} in ef / {200 rn exh mo} in ef / {300 rn exh mo} in ef /e {400 rn exh mo} in ef /f {500 rn exh mo} in ef 0 0 360 360 retlip.5 setgry 0 0 360 360 retfill.25 setlinewith 0 setgry 180 180 trnslte 8 {45 rotte 0 0 moveto 100 { e f urveto} repet stroke 0 0 600 600 retstroke } repet 264 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:flower.eps %%BouningBox:0 0 360 360 0 0 360 360 retlip.5 setgry 0 0 360 360 retfill 180 180 trnslte 1 setgry 10 { 36 rotte 0 0 moveto 252 253 253 0 0 0 urveto fill} repet 0 setgry.25 setlinewith 10 { 36 rotte 0 1 254 {} for 0 0 moveto 85 { 0 0 0 urveto} repet stroke } repet lirry of exmples 265

Tking Avntge of PostSript 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:petl2.eps %%BouningBox:0 0 385 186 36 36 trnslte.25 setlinewith 0 1 254 {} for 0 0 moveto 85 { 0 200 0 urveto} repet stroke 266 lirry of exmples

Chpter 19 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:3D-Line1.eps %%BouningBox:0 0 385 224 /line {25 0 rlineto} ef 30 rotte 1 setlinewith 0 0 moveto 16 {urrentlinewith 1 setlinewith line urrentpoint stroke moveto} repet lirry of exmples 267

Tking Avntge of PostSript 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:3D-Line2.eps %%BouningBox:0 0 385 224 /line {25 0 rlineto} ef 1 setlinewith 1 setlinep 1 setgry 0 0 moveto /L {/length exh ef gsve /setions {length 25 iv vi} ef /v 1 setions iv ef setions { urrentlinewith 1 setlinewith line urrentpoint stroke moveto urrentgry v su setgry} repet grestore} ef 20 rotte 200 L 10 rotte 400 L 10 rotte 250 L 268 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:3D-LineStr.eps %%BouningBox:0 0 360 250.5.5 sle.666 setgry 0 0 720 500 retlip 0 0 720 500 retfill /line {25 0 rlineto} ef 200 300 trnslte 10 rotte 1 setlinewith 1 setlinep 1 setgry 0 0 moveto /L { /length exh ef gsve /setions {length 25 iv vi} ef /v 1 setions iv ef setions {urrentlinewith 1 setlinewith line urrentpoint stroke moveto urrentgry v su setgry} repet grestore} ef 10 { 13 rotte 200 L 11 rotte 500 L 10 rotte 250 L 10 rotte 400 L 10 rotte 250 L 10 rotte 275 L} repet lirry of exmples 269

Tking Avntge of PostSript 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:urvetoLoops.eps %%BouningBox:34 34 290 120.5 setgry 6 setlinewith 36 36 moveto 288 144 36 144 288 36 urveto stroke 0 setgry 1 setlinewith 36 36 moveto 324 144 0 144 288 36 urveto stroke 36 36 moveto 396 144-72 144 288 36 urveto stroke 270 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:gryChrt.eps %%BouningBox:25 25 275 275 /ox /oxx {0 0 moveto 22 0 rlineto 0 22 rlineto -22 0 rlineto losepth fill} ef {10 {25 0 trnslte urrentgry.01 setgry ox} repet} ef 0 25 trnslte oxx 9 {-250 25 trnslte oxx} repet lirry of exmples 271

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:gryChrtRev.eps %%BouningBox:25 25 275 275 /ox /oxx {0 0 moveto 22 0 rlineto 0 22 rlineto -22 0 rlineto losepth fill} ef {10 {25 0 trnslte urrentgry.01 setgry ox} repet} ef {1 exh su} settrnsfer 0 25 trnslte oxx 9 {-250 25 trnslte oxx} repet 272 lirry of exmples

Chpter 19 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountinLine.eps %%BouningBox:36 36 324 185 /line {0 0 moveto 288 0 lineto stroke} ef 36 36 trnslte 99 {0.75 trnslte urrentgry.01 setgry line} repet 99 {0.75 trnslte urrentgry.01 su setgry line} repet lirry of exmples 273

Tking Avntge of PostSript 144 72 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:str2.eps %%BouningBox:36 30 252 210 /strsie {72 0 lineto urrentpoint trnslte -144 rotte} ef /str {moveto urrentpoint trnslte 4 {strsie} repet losepth gsve setgry fill grestore stroke} ef gsve.5 36 108 str grestore gsve.2 72 144 str grestore gsve.8 144 72 str grestore gsve.5 setgry.5 180 180 str grestore 274 lirry of exmples

Chpter 19 s-relief %!PS-Aoe-2.0 EPSF-1.2 %%Title:s-relief.eps %%BouningBox:0 0 360 130 0 0 360 130 retstroke /nme { 0 0 moveto (s-relief) show} ef /Helveti-Bol finfont 72 slefont setfont 36 36 trnslte 0.05.95 {setgry nme -1.5 trnslte} for 0 setgry nme lirry of exmples 275

Tking Avntge of PostSript 72 Vmos l ño? fçe 0 0 72 144 216 %!PS-Aoe-2.0 EPSF-1.2 %%Title:unenoing1.eps %%BouningBox:36 30 240 110 /BseFont /Times-Romn finfont ef /newfont BseFont length it ef newfont egin BseFont {1 inex up /FID ne exh /FID ne exh /Enoing ne n {ef}{pop pop} ifelse }in forll /Enoing 256 rry ef StnrEnoing Enoing opy pop Enoing 1 /ntile put Enoing 2 /eill put en /Times-RomnAent newfont efinefont pop /Times-RomnAent finfont 30 slefont setfont 36 90 moveto (\277Vmos l \1o?) show 36 36 moveto (f\2e) show 276 lirry of exmples

Chpter 19 0 1 0 0 1 1 1 0 01 00 11 10 0100 1110 01001110 (N)<4E> 1 it 2 it 4 it 8 it %!PS-Aoe-2.0 EPSF-1.2 %%Title:unenoing2.eps %%BouningBox:36 36 360 110 /BseFont /Pltino-Romn finfont ef /newfont BseFont length it ef newfont egin BseFont {1 inex up /FID ne exh /FID ne exh /Enoing ne n {ef}{pop pop} ifelse }in forll /Enoing 256 rry ef StnrEnoing Enoing opy pop Enoing 1 /opyright put Enoing 2 /registere put Enoing 3 /tremrk put en /Times-RomnAent newfont efinefont pop /Times-RomnAent finfont 30 slefont setfont 36 36 moveto (\0011989 Aoe) show 36 90 moveto (PostSript\2 Lnguge\3) show lirry of exmples 277

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnh2.eps %%BouningBox: 0 0 360 250 /epth 0 ef /mx 4 ef /own {/epth epth 1 ef} in ef /up {/epth epth 1 su ef} in ef /line % vertil line {0 100 rlineto urrentpoint stroke trnslte 0 0 moveto} in ef /rnh {gsve.7.7 sle own line epth mx 2 iv setgry epth mx le {60 rotte rnh -45 rotte rnh -30 rotte rnh -20 rotte -30 rotte rnh} if up grestore} in ef 0 0 360 250 retstroke 10 setlinewith 120 100 moveto rnh stroke 240 6 moveto rnh stroke 278 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnh3.eps %%BouningBox: 0 0 290 290 /epth 0 ef /mx 6 ef /own {/epth epth 1 ef} in ef /up {/epth epth 1 su ef} in ef /line {0 75 rlineto urrentpoint stroke trnslte 0 0 moveto} in ef /rnh {gsve.7.7 sle own line epth mx le {60 rotte rnh -150 rotte rnh} if up grestore} in ef 0 0 290 290 retstroke -25 145 trnslte 220 5 moveto rnh stroke [-1 0 0 1 0 0] ont -120 5 moveto rnh stroke [1 0 0-1 0 0] ont -120 5 moveto rnh stroke [-1 0 0 1 0 0] ont 220 5 moveto rnh stroke lirry of exmples 279

Tking Avntge of PostSript %!PS-Aoe-2.0 EPSF-1.2 %%Title:rnh4.eps %%BouningBox: 0 0 260 260 /epth 0 ef /mx 8 ef /own {/epth epth 1 ef} in ef /up {/epth epth 1 su ef} in ef /line % vertil line {0 100 rlineto urrentpoint stroke trnslte 0 0 moveto} in ef /rnh{gsve.7.7 sle own line epth mx le {45 rotte rnh -90 rotte rnh} if up grestore} in ef.8 setgry 0 0 260 260 retfill 0 setgry 130 60 moveto rnh 130 60 trnslte 180 rotte 0-130 moveto rnh stroke 280 lirry of exmples

Chpter 19 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:slinky.eps %%BouningBox:34 24 378 220 36 36 trnslte /slope.2 ef /irle {10 0 moveto 0 0 10 0 360 r stroke} ef gsve 0 1 40 {8 exh slope mul trnslte irle} for grestore /slope.5 ef gsve 0 1 23 {8 exh slope mul trnslte irle} for grestore /slope 1 ef gsve 0 1 18 {8 exh slope mul trnslte irle} for grestore /slope 3 ef gsve 0 1 10 {8 exh slope mul trnslte irle} for grestore /slope 8 ef gsve 0 1 5 {8 exh slope mul trnslte irle} for grestore lirry of exmples 281

Tking Avntge of PostSript 144 72 0 0 72 144 216 288 360 %!PS-Aoe-2.0 EPSF-1.2 %%Title:slinky2.eps %%BouningBox:38 30 378 216 36 36 trnslte /slope.2 ef /irle {0 0 moveto 18 18 18-18 36 0 urveto stroke} ef gsve 0 1 37 {8 exh slope mul trnslte irle} for grestore /slope.5 ef gsve 0 1 25 {8 exh slope mul trnslte irle} for grestore /slope 1 ef gsve 0 1 18 {8 exh slope mul trnslte irle} for grestore /slope 3 ef gsve 0 1 10 {8 exh slope mul trnslte irle} for grestore /slope 8 ef gsve 0 1 5 {8 exh slope mul trnslte irle} for grestore 282 lirry of exmples

Chpter 19 %!PS-Aoe-2.0 EPSF-1.2 %%Title:TCpos&rev.eps %%BouningBox: 0 0 288 144 gsve 0 setgry /rows 72 ef /ols 72 ef /pistr1 72 string ef /ret {urrentfile exh rehexstring pop} ef /eginimge {{pistr1 ret} imge} ef 72 65536 mul 2359296 iv up ols mul exh rows mul sle ols rows 8 [ols 0 0 rows neg 0 rows] eginimge 191F1F1E1F202429... piture t... 8147519C9A836D55 grestore gsve 144 0 trnslte {1 exh su} settrnsfer eginimge 191F1F1E1F202429... piture t... 8147519C9A836D55 grestore en lirry of exmples 283

Tking Avntge of PostSript 284 lirry of olor exmples

20 hpter Chpter 20 lirry of olor exmples Some of these progrms will work on lk n white printer. Some of the opertors use re prt of PostSript Level 2, whih mens you ll hve to try them on olor lser printer. The files rgboxes.eps n hsboxes.eps will work on n Apple LserWriter, the file mykboxes.eps will not. Pttern1.eps 291 fountin_1.eps 295 -imgewor1.eps 289 -imgewor2.eps 290 mykboxes.eps 288 olorrnotes.eps 292 RLines1.eps 293 RLines2.eps 294 hsboxes.eps 287 rgboxes.eps 286 lirry of olor exmples 285

Tking Avntge of PostSript 144.1.2.3 setrgolor.7.7.7.5.5.5.1.4.5 0 1.7 re green lue 0.4.7.8.4.7.8.6.4 72 0 0 72 144 216 288 lern PS 20 1 %!PS-Aoe-2.0 EPSF-1.2 %%Title:rgBoxes.eps %%BouningBox:36 36 306 198 /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef /lk {0 setgry} ef /Helveti-Olique finfont 10 slefont setfont 144 108 moveto (re green lue) show /Helveti-Bol finfont 10 slefont setfont 36 108 moveto (setrgolor) show 36 128 moveto (.1.2.3 ) show.1.2.3 setrgolor 36 144 ox lk 108 92 moveto (0.4.7) show 0.4.7 setrgolor 108 144 ox lk 180 92 moveto (.8.4.7) show.8.4.7 setrgolor 180 144 ox lk 252 92 moveto (.8.6.4) show.8.6.4 setrgolor 252 144 ox lk 36 92 moveto (.7.7.7) show.7.7.7 setrgolor 36 36 ox lk 108 128 moveto (.5.5.5) show.5.5.5 setrgolor 108 36 ox lk 180 128 moveto (.1.4.5) show.1.4.5 setrgolor 180 36 ox lk 252 128 moveto (0 1.7) show 0 1.7 setrgolor 252 36 ox 286 lirry of olor exmples

Chpter 20 144.1.2.3 sethsolor.7.7.7.5.5.5.1.4.5 0 1.7 hue sturtion rightness 0.4.7.8.4.7.8.6.4 72 0 0 72 144 216 288 PS lern 20 2 %!PS-Aoe-2.0 EPSF-1.2 %%Title:hsBoxes.eps %%BouningBox:36 36 306 198 /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef /lk {0 setgry} ef /Helveti-Olique finfont 10 slefont setfont 144 108 moveto (hue sturtion rightness) show /Helveti-Bol finfont 10 slefont setfont 36 108 moveto (sethsolor) show 36 128 moveto (.1.2.3 ) show.1.2.3 sethsolor 36 144 ox lk 108 92 moveto (0.4.7) show 0.4.7 sethsolor 108 144 ox lk 180 92 moveto (.8.4.7) show.8.4.7 sethsolor 180 144 ox lk 252 92 moveto (.8.6.4) show.8.6.4 sethsolor 252 144 ox lk 36 92 moveto (.7.7.7) show.7.7.7 sethsolor 36 36 ox lk 108 128 moveto (.5.5.5) show.5.5.5 sethsolor 108 36 ox lk 180 128 moveto (.1.4.5) show.1.4.5 sethsolor 180 36 ox lk 252 128 moveto (0 1.7) show 0 1.7 sethsolor 252 36 ox lirry of olor exmples 287

Tking Avntge of PostSript 144.1.2.3.4 setmykolor.7.7.7 0.5.5.5.5.1.4.5.9 0 1.7 0 yn mgent yellow lk 0.4.7 0.8.4.7 0.8.6.4.2 72 0 0 72 144 216 288 lern PS 20 3 %!PS-Aoe-2.0 EPSF-1.2 %%Title:mykBoxes.eps %%BouningBox:36 36 306 198 /ox {moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto losepth fill} ef /lk {0 setgry} ef /Helveti-Olique finfont 10 slefont setfont 144 108 moveto (yn mgent yellow lk) show /Helveti-Bol finfont 10 slefont setfont 36 108 moveto (setmykolor) show 36 128 moveto (.1.2.3.4) show.1.2.3.4 setmykolor 36 144 ox lk 108 92 moveto (0.4.7 0) show 0.4.7 0 setmykolor 108 144 ox lk 180 92 moveto (.8.4.7 0) show.8.4.7 0 setmykolor 180 144 ox lk 252 92 moveto (.8.6.4.2) show.8.6.4.2 setmykolor 252 144 ox lk 36 92 moveto (.7.7.7 0) show.7.7.7 0 setmykolor 36 36 ox lk 108 128 moveto (.5.5.5.5) show.5.5.5.5 setmykolor 108 36 ox lk 180 128 moveto (.1.4.5.9) show.1.4.5.9 setmykolor 180 36 ox lk 252 128 moveto (0 1.7 0) show 0 1.7 0 setmykolor 252 36 ox 288 lirry of olor exmples

Chpter 20 144 72 0 0 72 144 216 288 360 lern PS 20 4 %!PS-Aoe-2.0 EPSF-1.2 %%Title:-imgeWor1.eps %%Cretor:John F Shermn %%CretionDte:De 1990 %%BouningBox:36 36 356 186 /wor (John, Crolyn, Willim, Ptrik & Theres) ef 36 36 trnslte 15 15 4 [.1 0 0.1 0 0] {wor} true 1 olorimge 170 0 trnslte 15 15 4 [.1 0 0.1 0 0] {wor} flse 4 olorimge lirry of olor exmples 289

Tking Avntge of PostSript The ifferene etween this PostSript exmple n the exmple on the previous pge is tht these two squres re 8-it ptterns n the previous squres re 4-it. 144 72 0 0 72 144 216 288 360 PS lern 20 5 %!PS-Aoe-2.0 EPSF-1.2 %%Title:-imgeWor2.eps %%Cretor:John F Shermn %%CretionDte:De 1990 %%BouningBox:36 36 356 186 /wor (John, Crolyn, Willim, Ptrik & Theres) ef 36 36 trnslte 15 15 8 [.1 0 0.1 0 0] {wor} true 1 olorimge 170 0 trnslte 15 15 8 [.1 0 0.1 0 0] {wor} flse 4 olorimge 290 lirry of olor exmples

Chpter 20 144 72 0 0 72 144 216 288 360 PS lern 20 6 %!PS-Aoe-2.0 EPSF-1.2 %%Title:Pttern1.eps %%BouningBox:36 36 350 196 /str 512 string ef /it 4 ef /Pttern { / exh ef / exh ef /iff su ef 7 7 it [.1 0 0.1 0 0] {0 1 511 {str exh rn iff mo put} for str} flse 4 olorimge} ef 222 srn 36 36 trnslte 0 75 Pttern 80 0 trnslte 75 150 Pttern 80 0 trnslte 150 225 Pttern 80 0 trnslte 225 250 Pttern /it 8 ef -240 90 trnslte 0 75 Pttern 80 0 trnslte 75 150 Pttern 80 0 trnslte 150 225 Pttern 80 0 trnslte 225 250 Pttern lirry of olor exmples 291

Tking Avntge of PostSript 292 lirry of olor exmples %!PS-Aoe-2.0 EPSF-1.2 %%Title:olorRNotes.eps %%BouningBox:0 0 360 180 /Sont finfont 24 slefont setfont /n {rn exh mo 6 su} ef /g {rn 100 mo.01 mul} ef /lipbox {/ury exh ef /urx exh ef /lly exh ef /llx exh ef llx lly moveto urx lly lineto urx ury lineto llx ury lineto losepth lip} ef 173417 srn gsve 0 0 360 180 lipbox / {360 n 180 n moveto (&) show} ef / {250 n 180 n moveto (e) show} ef / {200 n 180 n moveto (e) show} ef / {150 n 180 n moveto (e) show} ef /e {100 n 180 n moveto (e) show} ef 10 {g g g 0 setmykolor 25 {} repet} repet 10 {g g g 0 setmykolor 25 {} repet} repet 10 {g g g 0 setmykolor 25 {} repet} repet 10 {g g g 0 setmykolor 25 {} repet} repet 10 {g g g 0 setmykolor 25 {e} repet} repet grestore 20 7 PS lern

Chpter 20 PS lern 20 8 %!PS-Aoe-2.0 EPSF-1.2 %%Title:RLines1.eps %%Cretor:John F Shermn %%CretionDte:De 1990 %%BouningBox:36 36 396 286 /n {rn exh mo} ef /g {rn 100 mo.01 mul} in ef 173417 srn 36 36 360 250 retlip gsve / {400 n 36 n moveto 38 300 rlineto stroke} ef / {300 n 36 n moveto 38 300 rlineto stroke} ef / {100 n 36 n moveto 38 300 rlineto stroke} ef 10 {g g g 0 setmykolor 7 {} repet} repet 10 {g g g 0 setmykolor 7 {} repet} repet 10 {g g g 0 setmykolor 7 {} repet} repet grestore lirry of olor exmples 293

Tking Avntge of PostSript PS lern 20 9 %!PS-Aoe-2.0 EPSF-1.2 %%Title:RLines2.eps %%BouningBox:0 0 330 120 /n {rn exh mo} in ef /g {rn 100 mo.01 mul} in ef 173417 srn.8 setgry 0 0 330 120 retfill gsve / {300 n 18 n moveto 32 100 rlineto stroke} ef / {200 n 18 n moveto 7 100 rlineto stroke} ef / {100 n 18 n moveto 7 100 rlineto stroke} ef 3 setlinewith 10 {g g g 0 setmykolor 7 {} repet} repet 1 setlinewith 10 {g g g 0 setmykolor 7 {} repet} repet 10 {g g g 0 setmykolor 7 {} repet} repet grestore 294 lirry of olor exmples

Chpter 20 PS lern 20 10 %!PS-Aoe-2.0 EPSF-1.2 %%Title:fountin_1.eps %%Cretor:John F Shermn %%BouningBox:0 0 200 200 /fountstring 256 string ef 0 1 255 { fountstring exh up put } for 200 200 sle 255 1 8 [ 255 0 0 1 0 0 ] { fountstring } flse 4 olorimge lirry of olor exmples 295

Tking Avntge of PostSript 296 gllery of esigns Mike s Romne

21 hpter Chpter 21 gllery of esigns This hpter ontins numer of exmples of esigns tht emonstrte the potentil of PostSript imge mking. gllery of esigns 297

Tking Avntge of PostSript fter the Romne 298 gllery of esigns

Chpter 21 AA 111111 A 111111 B 111111 AA 111111 1 B1 111111 B 111111 A B1 it o Romne gllery of esigns 299

Tking Avntge of PostSript 300 gllery of esigns violynn

Chpter 21 1111111111111111111111111111111 1111111111111111111111111111111111 A 11111111111111111111111111 11111 A A 1111111111111111111111111111111 11111111111111111111111111111 1 1 A A B A A A B A A A exite gllery of esigns 301

Tking Avntge of PostSript violin Swith 302 gllery of esigns

Chpter 21 rclef gllery of esigns 303