1. ashow
Show text with uniform character spacing adjustment.
1.3. Description
ashow paints the characters of string in a manner similar to show. But while doing so, ashow adjusts the width of each character shown by adding ax to the character’s x width and ay to its y width, thus modifying the spacing between characters.
The numbers ax and ay are x and y displacements in the user coordinate system, not in the character coordinate system. This operator enables a string of text to be fitted to a specific width by adjusting all the spaces between characters by a uniform amount.
1.4. Parameters
ax (number)
: Amount to add to each character’s x width
ay (number)
: Amount to add to each character’s y width
string (string)
: The text to display
1.5. Examples
1.5.1. Wide Character Spacing
/Helvetica findfont 12 scalefont setfont
14 61 moveto (Normal spacing) show
14 47 moveto 4 0 (Wide spacing) ashow
1.5.2. Tight Character Spacing
/Helvetica findfont 12 scalefont setfont
100 700 moveto (Normal) show
100 685 moveto -1 0 (Tight) ashow % Reduce spacing by 1 unit
1.5.3. Fitting Text to Width
/fitText { % string targetWidth fitText -
% Calculate adjustment needed
1 index stringwidth pop % Get current width
1 index exch sub % targetWidth - currentWidth
2 index length 1 sub % Number of spaces between chars
div % Adjustment per space
0 3 -1 roll ashow % Apply adjustment
} def
(Hello World) 200 fitText
1.6. Errors
invalidaccess : Font or string has restricted access
invalidfont : Current font is not valid
nocurrentpoint
: Current point is not defined before ashow
stackunderflow : Fewer than three operands on stack
typecheck
: ax or ay is not a number, or string is not a string
1.7. Width Calculation
For each character c in the string, the effective width becomes:
effectiveWidth(c) = characterWidth(c) + (ax, ay)
Total current point displacement:
totalDisplacement = Σ(characterWidth(c) + (ax, ay))
= Σ characterWidth(c) + n × (ax, ay)
where n is the string length.
1.8. Comparison with show
% These are equivalent:
100 100 moveto (ABC) show
100 100 moveto 0 0 (ABC) ashow % Zero adjustment
1.9. Use Cases
1.9.1. Justified Text
/justifyLine { % string lineWidth justifyLine -
exch dup stringwidth pop % Get current width
3 -1 roll exch sub % Calculate extra space
1 index length 1 sub div % Divide by num spaces
0 exch 3 -1 roll ashow % Apply uniform spacing
} def
(This text is justified) 400 justifyLine
1.12. See Also
-
show- Basic text painting -
widthshow- Adjust specific character width -
awidthshow- Combineashowandwidthshow -
kshow- Show with kerning procedure -
cshow- Show with procedure per character -
stringwidth- Calculate text width -
moveto- Set current point