1. initmatrix

Resets the current transformation matrix to the device default.

1.1. Syntax

- initmatrix → -

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

No operands required

Table 2. After
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.4. PostScript Level

Level 1 and later

1.5. Examples

Resetting to default
% After many transformations
100 100 translate
2 2 scale
45 rotate

initmatrix  % Back to device default
Device setup
% In device initialization
initmatrix
72 72 scale  % Set up 1-inch units

1.6. Common Use Cases

1.6.1. Resetting Coordinate System

% Start fresh
initmatrix
% Now at device default transformation

1.6.2. Absolute Positioning

% Position independent of current transformation
gsave
  initmatrix
  300 400 moveto  % Absolute device coordinates
  (Text) show
grestore

1.6.3. Device Initialization

% Part of page setup
initmatrix
initgraphics  % Reset other graphics parameters too

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
Use gsave/grestore - For temporary transformations, use gsave/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)

initmatrix cannot fail

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):

  1. Device Setup: Initial coordinate system configuration

  2. Absolute Positioning: When you need device coordinates

  3. Error Recovery: Recovering from unknown transformation state

Invalid use cases (common mistakes):

  1. Normal Drawing: Use gsave/grestore instead

  2. Resetting After Transform: Use grestore instead

  3. Embedded Pages: Will break composition

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


Back to top

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