1. show
Paint text string at current point.
1.3. Description
show paints the characters identified by the elements of string on the current page starting at the current point, using the font face, size, and orientation specified by the most recent setfont or selectfont.
The spacing from each character of the string to the next is determined by the character’s width, which is an (x, y) displacement that is part of the character’s definition. When it is finished, show adjusts the current point in the graphics state by the sum of the widths of all the characters shown.
show requires that the current point initially be defined (for example, by moveto); otherwise, it executes the error nocurrentpoint.
If a character code would index beyond the end of the font’s Encoding, or the character mapping algorithm goes out of bounds in other ways, a rangecheck error occurs.
1.5. Character Encoding
Characters are encoded as integers 0-255 in the string:
- Each byte indexes into the font’s Encoding array
- The Encoding maps character codes to character names
- Character names map to glyph descriptions in CharStrings
1.6. Examples
1.6.1. Basic Text Display
/Helvetica findfont 12 scalefont setfont
100 700 moveto
(Hello, World!) show
1.6.2. Multiple Lines of Text
/Helvetica findfont 12 scalefont setfont
100 700 moveto (Line 1) show
100 685 moveto (Line 2) show
100 670 moveto (Line 3) show
1.7. Errors
invalidaccess : Font or string has restricted access
invalidfont : Current font is not valid
nocurrentpoint : Current point is not defined
rangecheck : Character code exceeds encoding bounds
stackunderflow : No operand on stack
typecheck : Operand is not a string
1.8. Current Point Behavior
The current point is updated by the sum of all character widths:
100 100 moveto
currentpoint pop pop % x=100, y=100
(ABC) show
currentpoint pop pop % x=100+width(A)+width(B)+width(C), y=100
For most fonts, character widths move the current point horizontally. However, some fonts (particularly vertical writing fonts) may have vertical width components.
1.9. Character Width Vectors
Each character has a width vector (wx, wy):
width = (wx, wy)
After showing character c:
currentpoint' = currentpoint + width(c)
For a string "ABC":
currentpoint' = currentpoint + width(A) + width(B) + width(C)
1.10. Common Patterns
1.10.1. Right-Aligned Text
/rightShow { % string x y rightShow -
moveto
dup stringwidth pop neg 0 rmoveto
show
} def
(Right aligned) 500 700 rightShow
1.12. Comparison with Other Text Operators
| Operator | Purpose |
|---|---|
Basic text painting (fastest) |
|
Add uniform spacing to all characters |
|
Adjust width of specific character |
|
Execute procedure between characters (kerning) |
|
Execute procedure for each character (Level 2) |
|
Get character outlines as path |
1.13. See Also
-
ashow- Show with character spacing adjustment -
widthshow- Show with selective character width adjustment -
awidthshow- Combine ashow and widthshow -
kshow- Show with kerning procedure -
cshow- Show with procedure per character (Level 2) -
charpath- Get character outlines as path -
stringwidth- Calculate text width -
setfont- Establish current font -
moveto- Set current point