Table of Contents
1. grestore
Restores the graphics state from the top of the graphics state stack.
1.2. Stack Effects
| Level | Object |
|---|---|
(none) |
Graphics state stack decreased by one, current state restored |
1.3. Description
grestore resets the current graphics state from the one on top of the graphics state stack and pops that stack.
1.5. Examples
Basic restore
gsave
2 setlinewidth
0.5 setgray
% Draw something
grestore
% Line width and gray restored
Multiple levels
gsave
1 setlinewidth
gsave
5 setlinewidth
grestore % Back to 1
grestore % Back to original
After save
/mysave save def
gsave
% State changes
grestore % Doesn't pop (save intervened)
mysave restore % Restores including gsave level
1.6. Common Use Cases
1.7. Common Pitfalls
Must Have Matching gsave - Unmatched grestore doesn’t error but doesn’t pop stack.
|
grestore % No matching gsave
% State restored from top but stack not popped
save Intervenes - grestore after save doesn’t pop stack.
|
gsave
save
grestore % Doesn't pop due to save
restore % Pops graphics state stack
1.9. Implementation Notes
-
Restores all graphics state parameters atomically
-
Fast operation
-
Common pattern in PostScript programs
-
Stack-based state management
1.10. What Gets Restored
All parameters saved by gsave:
* CTM, path, current point
* Clipping path
* Color space and color
* Font
* All line parameters
* All device-dependent parameters
1.11. See Also
-
gsave- Save graphics state -
grestoreall- Restore all levels -
setgstate- Set from gstate object -
save,restore- VM and graphics state