- 1. initmatrix
- 1.1. Syntax
- 1.2. Stack Effects
- 1.3. Description
- 1.4. PostScript Level
- 1.5. Examples
- 1.6. Common Use Cases
- 1.7. Common Pitfalls
- 1.8. Error Conditions
- 1.9. Implementation Notes
- 1.10. Default Matrix Characteristics
- 1.11. Relationship to Other Operators
- 1.12. When to Use initmatrix
- 1.13. Example of Proper Use
- 1.14. See Also
1. initmatrix
Resets the current transformation matrix to the device default.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
No operands required |
| Level | Object |
|---|---|
(empty) |
No results |
1.3. Description
initmatrix sets the current transformation matrix (CTM) to the default matrix for the current output device. This matrix transforms the default user coordinate system to device space.
For page-oriented devices, the default matrix is initially established by the setpagedevice operator.
This is equivalent to:
matrix defaultmatrix setmatrix
There are few situations in which a PostScript program should execute initmatrix explicitly. A page description that executes initmatrix usually produces incorrect results if embedded within another, composite page.
|
1.5. Examples
% After many transformations
100 100 translate
2 2 scale
45 rotate
initmatrix % Back to device default
% In device initialization
initmatrix
72 72 scale % Set up 1-inch units
1.6. Common Use Cases
1.7. Common Pitfalls
Breaks Nested Transformations - initmatrix ignores all previous transformations.
|
/drawBox {
newpath
0 0 100 100 rectfill
} def
100 100 translate
2 2 scale
initmatrix % Destroys the translate and scale!
drawBox % Box appears at device origin, normal size
Not for Typical Programs - Normal PostScript programs should not use initmatrix.
|
% Don't do this in normal programs:
initmatrix
% Use gsave/grestore instead:
gsave
% ... transformations ...
grestore
% Better than initmatrix:
gsave
100 100 translate
% ... draw content ...
grestore
% Original transformation restored
Part of initgraphics - initmatrix is one component of initgraphics:
|
% initgraphics is equivalent to:
initmatrix
newpath
initclip
1 setlinewidth
0 setlinecap
0 setlinejoin
[] 0 setdash
0 setgray
10 setmiterlimit
1.8. Error Conditions
| Error | Condition |
|---|---|
(none) |
|
1.9. Implementation Notes
-
The default matrix is device-dependent
-
For page devices, it’s established during page setup
-
The transformation is instantaneous
-
No previous CTM state is preserved (unlike
grestore)
1.10. Default Matrix Characteristics
For typical page-oriented devices:
[72 0 0 -72 0 height]
Where:
-
72 = points per inch (horizontal)
-
-72 = points per inch (vertical, inverted)
-
height = page height in points
This establishes:
-
1 unit = 1 point (1/72 inch)
-
Origin at top-left corner
-
Y-axis pointing down
-
X-axis pointing right
1.11. Relationship to Other Operators
% These are equivalent:
initmatrix
matrix defaultmatrix setmatrix
initmatrix is part of:
initgraphics % Calls initmatrix plus resets other parameters
1.12. When to Use initmatrix
Valid use cases (rare):
-
Device Setup: Initial coordinate system configuration
-
Absolute Positioning: When you need device coordinates
-
Error Recovery: Recovering from unknown transformation state
Invalid use cases (common mistakes):
1.13. Example of Proper Use
% Valid: Absolute positioning for debugging
/debugMark {
gsave
initmatrix % Work in device coordinates
72 72 translate % 1 inch from corner
newpath
0 0 5 0 360 arc
fill
grestore
} def
1.14. See Also
-
defaultmatrix- Get device default matrix -
currentmatrix- Get current CTM -
setmatrix- Set CTM explicitly -
gsave- Save graphics state -
grestore- Restore graphics state