1. currentfont

Get current font dictionary from graphics state.

1.1. Syntax

- currentfont → font

1.2. Stack Effects

Before:

(empty)

After:

font

1.3. Description

currentfont returns the current font dictionary in the graphics state. Normally, this is the font most recently established by setfont or selectfont.

However, when executed inside a font’s BuildGlyph or BuildChar procedure or a procedure invoked by cshow, currentfont returns the currently selected base font (descendant of a composite font).

1.4. Returns

font (dictionary) : The current font dictionary from the graphics state

1.5. Examples

1.5.1. Querying Current Font

/Helvetica findfont 12 scalefont setfont
currentfont
% Returns the scaled Helvetica font dictionary

1.5.2. Saving and Restoring Font

% Save current font
currentfont /savedFont exch def

% Change font for temporary use
/Times-Roman findfont 10 scalefont setfont
100 100 moveto (Times text) show

% Restore original font
savedFont setfont
100 80 moveto (Original font) show

1.5.3. Font Information Inspection

currentfont
dup /FontName get == % Print font name
dup /FontMatrix get == % Print font matrix
dup /FontType get == % Print font type
pop

1.5.4. Conditional Font Checking

% Check if a specific font is current
currentfont /FontName get
/Helvetica eq {
  (Using Helvetica) =
} {
  (Using other font) =
} ifelse

1.6. Errors

stackoverflow : If the operand stack would overflow

1.7. Behavior with Composite Fonts

When currentfont is called during font construction:

In BuildGlyph/BuildChar procedures: : Returns the base font selected by the composite font machinery

In cshow procedure: : Returns the base font for the current character

Normal context: : Returns the top-level font set by setfont

To get the top-level composite font from within these procedures, use rootfont instead.

1.8. Font Dictionary Contents

The returned font dictionary typically contains:

% Example font dictionary structure
<<
  /FontType 1
  /FontName /Helvetica
  /FontMatrix [0.001 0 0 0.001 0 0]
  /FontBBox [-166 -225 1000 931]
  /Encoding StandardEncoding
  /PaintType 0
  /CharStrings <CharStrings dictionary>
  /FID <fontID>
>>

1.9. Use Cases

1.9.1. Dynamic Font Switching

% Switch between normal and bold
/toggleBold {
  currentfont /FontName get
  dup /Helvetica eq {
    pop /Helvetica-Bold
  } {
    /Helvetica-BoldOblique eq {
      /Helvetica-Oblique
    } {
      /Helvetica
    } ifelse
  } ifelse
  findfont 12 scalefont setfont
} def

1.9.2. Font Size Adjustment

% Scale current font by a factor
/scaleCurrent {  % factor scaleCurrent -
  currentfont
  exch scalefont
  setfont
} def

% Use it:
1.5 scaleCurrent  % Make current font 50% larger

1.10. See Also

  • setfont - Establish current font

  • findfont - Obtain font dictionary by name

  • scalefont - Scale font by uniform factor

  • makefont - Transform font by matrix

  • rootfont - Get root font of composite font

  • cshow - Show with procedure per character


Back to top

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