1. undefinefont
Remove font from font directory (Level 2).
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.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.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.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