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

/buff 256 string def

{%loop

%assumes no errors in the data...

currentfile buff readline not { exit } if (%%EOF) anchorsearch { exit } if

token pop exch token pop exch 3 1 roll moveto token pop exch token pop exch pop lineto

stroke } bind loop 96 17 20 30

15.5 75.25 120 145.789

30 89.75 168.5 76.5

80 40 60 140 %%EOF

Figure 11.1: Output of Example 11.10

output page

CONCLUDING THOUGHTS

In this chapter, you’ve seen how to construct arrays and strings and how to manipulate them with put and get. You have also seen how to

Chapter 11: CREATING AND MANIPULATING DATA

143

concatenate arrays and strings and how to do some simple and powerful manipulation of the data.

The PostScript language is not particularly strong in string-handling operations compared to some other languages, but it has all the necessary ingredients to do very respectable string manipulation when necessary.

When you work with arrays and strings, the most important thing to remember is that they are composite objects and work more like pointers than actual bodies of data. If you can keep track of when you need to copy the whole string or the whole array, you will have few problems with this kind of data manipulation.

In the next chapter you will see more in-depth treatment of the basics of data storage and retrieval and how to build data structures and use dictionaries creatively.

EXERCISES

1. What are the contents of the array constructed by the following code?

[ 0 0 moveto 100 100 lineto currentpoint ]

2.Show the PostScript code to create a two-dimensional array five elements wide and ten elements deep.

3.The filenameforall operator is very useful in obtaining a list of font files written to the disk on a printer. However, the file names that the operator returns are of the form (fonts/Palatino-Roman) rather than simply (Palatino-Roman). Write a procedure called extractfontname that will take a string like (fonts/Palatino-Roman) as input and strip off the (fonts/) part of the name, leaving just (Palatino-Ro- man).

144

Chapter 11: CREATING AND MANIPULATING DATA