1. setfont

Establish current font in graphics state.

1.1. Syntax

font setfont → -

1.2. Stack Effects

Before:

font

After:

(empty)

1.3. Description

setfont establishes the font dictionary parameter in the graphics state. This specifies the font to be used by subsequent character operators, such as show and stringwidth. The font must be a valid font dictionary previously returned by findfont, scalefont, or makefont.

The font remains current until changed by another setfont or selectfont operation, or until the graphics state is restored by grestore or grestoreall.

1.4. Parameters

font (dictionary) : A valid font dictionary to establish as the current font

1.5. Examples

1.5.1. Basic Font Setup

/Helvetica findfont    % Obtain prototype Helvetica font
10 scalefont           % Scale it to 10-unit size
setfont                % Establish it as current font

1.5.2. Multiple Font Changes

% Set up multiple fonts
/Helvetica findfont 12 scalefont /H12 exch def
/Times-Roman findfont 10 scalefont /T10 exch def

% Use Helvetica for heading
H12 setfont
100 700 moveto (Heading) show

% Use Times for body
T10 setfont
100 680 moveto (Body text) show

1.5.3. Font with Graphics State Save/Restore

/Helvetica findfont 12 scalefont setfont

gsave
  /Times-Roman findfont 10 scalefont setfont
  100 100 moveto (Times Roman text) show
grestore

% Helvetica is restored as current font
100 80 moveto (Back to Helvetica) show

1.6. Errors

invalidfont : If font is not a well-formed font dictionary

stackunderflow : If no operand is on the stack

typecheck : If the operand is not a dictionary

1.7. Font Dictionary Requirements

A valid font dictionary must contain at least:

  • FontType - Integer identifying the font type (1, 3, etc.)

  • FontMatrix - Transformation matrix from character space to user space

  • Encoding - Array mapping character codes to names

  • FID - Font identifier (inserted by definefont)

For Type 1 fonts: - CharStrings - Dictionary of character programs - PaintType - Integer (0 or 2) - FontInfo - Dictionary of font information (optional but common)

For Type 3 fonts: - BuildChar or BuildGlyph - Character construction procedure - FontBBox - Bounding box for all characters

1.8. Graphics State Impact

setfont only modifies the font parameter of the graphics state. It does not affect:

  • Current transformation matrix

  • Current path

  • Current point

  • Current color

  • Any other graphics state parameters

1.9. Interaction with Other Operators

% Font is part of graphics state
gsave
  /Times-Roman findfont 12 scalefont setfont
  % Do some text operations
grestore
% Previous font is restored

% Font persists across most operations
newpath
/Helvetica findfont 10 scalefont setfont
100 100 moveto (Text) show
% Font is still Helvetica

1.10. See Also


Back to top

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