1. Advanced Usage
Advanced PostScript programming techniques for professional document production.
2. Font and Text
2.1. Font Selection
/Helvetica findfont 12 scalefont setfont
/Times-Roman findfont 14 scalefont setfont
/Helvetica findfont
[10 0 0 12 0 0] makefont % Condensed
setfont
2.3. Text Measurement
(Sample Text) stringwidth pop % Get width
3. Color Spaces
3.1. Device Colors
% Grayscale
0.5 setgray
% RGB
1 0 0 setrgbcolor
% CMYK (Level 2)
0 1 1 0 setcmykcolor
3.2. CIE Color (Level 2)
Calibrated color for color management:
[/CIEBasedABC <<
/RangeABC [0 1 0 1 0 1]
/DecodeABC [{exp} bind {exp} bind {exp} bind]
/MatrixABC [0.4124 0.2126 0.0193
0.3576 0.7152 0.1192
0.1805 0.0722 0.9505]
/WhitePoint [0.9505 1.0000 1.0890]
>>] setcolorspace
4. Patterns
Create repeating patterns for fills:
<<
/PatternType 1
/PaintType 1
/TilingType 1
/BBox [0 0 10 10]
/XStep 10
/YStep 10
/PaintProc { pop
newpath
5 5 3 0 360 arc
fill
}
>> matrix makepattern setpattern
Cache complex graphics for reuse:
/myform <<
/FormType 1
/BBox [0 0 100 100]
/Matrix [1 0 0 1 0 0]
/PaintProc { pop
% Complex graphics here
0 0 100 100 rectfill
}
>> def
myform execform
6. Image Handling
6.1. Monochrome Image
100 100 translate
100 100 scale
8 8 1 [8 0 0 -8 0 8]
{ <FF00 0000 00FF 00FF
00FF FF00 0000 FF00> }
image
6.2. Color Image (Level 2)
/DeviceRGB setcolorspace
100 100 translate
100 100 scale
8 8 8 [8 0 0 -8 0 8]
currentfile /ASCIIHexDecode filter
image
FF0000 00FF00 0000FF ...
7. Error Handling
7.1. Try-Catch Pattern
{
% Risky operation
riskyCode
} stopped {
% Error handler
(Error occurred) print
handleError
} if
7.2. Custom Error Handler
errordict /myerror {
(Custom error handler) print
stop
} put
8. Resource Management
8.1. Memory Conservation
save
% Temporary allocations
complexOperations
restore % Free everything
8.2. Efficient Dictionaries
% Estimate size correctly
100 dict begin % Not 5 if you need 100!
definitions
end
Table of contents