1. ashow

Show text with uniform character spacing adjustment.

1.1. Syntax

ax ay string ashow → -

1.2. Stack Effects

Before:

ax ay string

After:

(empty)

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.5.4. Vertical Spacing Adjustment

% Add vertical spacing (unusual but possible)
/Helvetica findfont 12 scalefont setfont
100 700 moveto
0 -2 (Descending text) ashow
% Each character shifts down by 2 units

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.9.2. Letter Spacing Control

% Loose letter spacing for headings
/Heading {
  /Helvetica-Bold findfont 18 scalefont setfont
  2 0 3 -1 roll ashow
} def

100 700 moveto (WIDE HEADING) Heading

1.9.3. Compensating for Transformations

% When CTM is scaled, adjust spacing
gsave
  2 1 scale         % Different x and y scale
  /Helvetica findfont 12 scalefont setfont
  100 100 moveto
  1 0 (Adjusted) ashow  % Compensate for scaling
grestore

1.10. Performance Notes

  • ashow is slightly slower than show due to spacing calculations

  • Character caching still applies

  • For uniform spacing of all text, set once and use show

  • For spacing only specific characters, use widthshow instead

1.11. Advanced Usage

1.11.1. Dynamic Spacing Based on Content

/adaptiveShow {  % string adaptiveShow -
  dup length 10 lt {
    % Short strings: wide spacing
    3 0 3 -1 roll ashow
  } {
    % Long strings: normal spacing
    show
  } ifelse
} def

(Short) adaptiveShow
(This is a much longer string) adaptiveShow

1.12. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.