1. undefinefont

Remove font from font directory (Level 2).

1.1. Syntax

key undefinefont → -

1.2. Stack Effects

Before:

key

After:

(empty)

1.3. PostScript Level

Level 2 and later

1.4. Description

undefinefont removes key and its associated value (a font dictionary) from the font directory, reversing the effect of a previous definefont. undefinefont is a special case of the undefineresource operator applied to the Font category.

If the specified key does not exist in the font directory, undefinefont does nothing—no error occurs.

1.5. Parameters

key (name or string) : The name of the font to remove from the font directory

1.6. VM Allocation Effects

Local and global resource definitions are maintained separately:

Local VM mode (false setglobal): - Removes local definition if one exists - Does not disturb global definition - If global definition exists, it reappears after local removal

Global VM mode (true setglobal): - Removes local definition - Removes global definition - Removes both if both exist

1.7. Examples

1.7.1. Basic Font Removal

% Define a custom font
/MyFont 10 dict dup begin
  /FontType 3 def
  /FontMatrix [0.001 0 0 0.001 0 0] def
  /FontBBox [0 0 1000 1000] def
  /Encoding StandardEncoding def
  /BuildChar { pop pop } def
currentdict end
/MyFont exch definefont pop

% Later, remove it
/MyFont undefinefont

1.7.2. Cleaning Up Temporary Fonts

% Create temporary scaled font
/Helvetica findfont 36 scalefont
/Helvetica-36 exch definefont
setfont

% Use the font
100 100 moveto (Large Text) show

% Clean up when done
/Helvetica-36 undefinefont

1.7.3. Replacing Font Definition

% Remove old definition before redefining
/CustomFont undefinefont

% Define new version
/CustomFont 10 dict dup begin
  % New font definition
  /FontType 3 def
  % ... other entries
currentdict end
/CustomFont exch definefont pop

1.7.4. VM-Aware Font Cleanup

% Clean up local and global definitions
false setglobal
/TempFont undefinefont    % Remove local definition

true setglobal
/TempFont undefinefont    % Remove global definition
false setglobal

1.8. Errors

stackunderflow : If no operand is on the stack

typecheck : If key is not a name or string

1.9. Behavior Notes

Font Still Usable: - The font dictionary itself is not destroyed - If stored elsewhere (e.g., in a variable), it remains valid - Font becomes eligible for garbage collection only when no longer accessible

Current Font: - If the removed font is currently set via setfont, it remains current - The current font in graphics state is unaffected - Only future findfont calls are affected

Restore Interaction: - Effect of undefinefont on local VM subject to restore - Removing local font can be undone by restore - Removing global font is permanent (until restored at job end)

1.10. Font Directory Structure

% Check if font is defined
FontDirectory /Helvetica known {
  (Helvetica is in FontDirectory) =
} if

% After undefinefont
/Helvetica undefinefont
FontDirectory /Helvetica known {
  (Still there) =
} {
  (Removed from FontDirectory) =
} ifelse

1.11. Use Cases

1.11.1. Memory Management

% Process many documents, clean up fonts between them
{
  % For each document:

  % Create custom fonts for this document
  /DocFont1 ... definefont pop
  /DocFont2 ... definefont pop

  % Process document
  % ...

  % Clean up to free memory
  /DocFont1 undefinefont
  /DocFont2 undefinefont
} forall

1.11.2. Font Versioning

% Replace font with updated version
/MyFont undefinefont

% Load new version from file or define inline
(myfontnew.pfa) run  % Loads and defines new version

1.11.3. Resource Management

% Remove all custom fonts with specific prefix
FontDirectory {
  pop  % Get key
  dup type /nametype eq {
    dup =string cvs (Custom) anchorsearch {
      pop pop  % Found custom font
      undefinefont
    } {
      pop pop  % Not custom
    } ifelse
  } {
    pop  % Not a name
  } ifelse
} forall

1.12. Relationship to Other Resource Operators

undefinefont is equivalent to:

key /Font undefineresource

For generic resource manipulation, use the resource operators: - undefineresource - Remove any resource type - findresource - Find any resource type - resourcestatus - Check resource status - resourceforall - Enumerate resources

1.13. See Also

  • definefont - Register font in font directory

  • findfont - Obtain font dictionary by name

  • undefineresource - Remove resource from category

  • FontDirectory - Dictionary of local fonts

  • GlobalFontDirectory - Dictionary of global fonts


Back to top

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