1. setfont
Establish current font in graphics state.
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.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.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
-
currentfont- Get current font dictionary -
findfont- Obtain font dictionary by name -
scalefont- Scale font by uniform factor -
makefont- Transform font by matrix -
show- Paint text string at current point -
stringwidth- Calculate text width