1. defaultmatrix

Gets the default transformation matrix for the current device.

1.1. Syntax

matrix defaultmatrix → matrix

1.2. Stack Effects

Table 1. Before
Level Object

0

matrix (array)

Table 2. After
Level Object

0

matrix (modified array)

1.3. Description

defaultmatrix replaces the value of matrix with the default transformation matrix for the current output device and pushes the modified matrix back on the operand stack.

The default matrix establishes the standard mapping from the default user coordinate system to device space for the current device. This matrix is device-dependent and defines the initial state before any transformations are applied.

For page-oriented devices, the default matrix is typically established by the page device setup. For display devices, it depends on the window system integration.

1.4. PostScript Level

Level 1 and later

1.5. Examples

Getting the default matrix
matrix defaultmatrix  % Get device default matrix
% → e.g., [1 0 0 -1 0 792] for letter page
Comparing with current matrix
matrix currentmatrix  % Get CTM
matrix defaultmatrix  % Get default
% Compare the two matrices
Resetting to default
matrix defaultmatrix setmatrix  % Reset to default
% Equivalent to: initmatrix

1.6. Common Use Cases

1.6.1. Understanding Device Coordinate System

% Examine default transformation
matrix defaultmatrix
% For letter page, might be:
% [72 0 0 -72 0 792]
% Meaning: 72dpi, y-axis inverted, origin at top-left

1.6.2. Saving Default State

% Save default for later restoration
/deviceDefault matrix defaultmatrix def

% After many transformations:
deviceDefault setmatrix  % Restore default

1.6.3. Computing Device Dimensions

% Get page dimensions in default user space
matrix defaultmatrix
% Extract translation components (tx, ty)
% to determine page size

1.7. Common Pitfalls

Device-Dependent - The default matrix varies by device and is not portable.
% These may differ on different devices:
matrix defaultmatrix  % On printer: [72 0 0 -72 0 792]
matrix defaultmatrix  % On display: [1 0 0 -1 0 1024]
Not Always Identity - The default matrix is rarely the identity matrix.
% Default matrix is usually NOT:
[1 0 0 1 0 0]

% It's typically something like:
[72 0 0 -72 0 792]  % Letter page at 72dpi
Use initmatrix Instead - For resetting CTM, use initmatrix:
% Less clear:
matrix defaultmatrix setmatrix

% Clearer:
initmatrix

1.8. Error Conditions

Error Condition

[rangecheck]

Array has fewer than 6 elements

[stackunderflow]

No operand on stack

[typecheck]

Operand is not an array

1.9. Implementation Notes

  • The default matrix is established during device initialization

  • For page devices, it’s set by the setpagedevice operator

  • The matrix defines the initial coordinate system mapping

  • The default matrix typically includes:

    • Scaling to convert from points to device pixels

    • Possible y-axis inversion

    • Translation to position the origin

1.10. Typical Default Matrices

1.10.1. Letter Page (8.5" × 11")

% 72 points per inch, y-axis inverted
[72 0 0 -72 0 792]

% Meaning:
% - 72 points = 1 inch
% - y increases downward in device space
% - Origin at top-left corner

1.10.2. A4 Page (210mm × 297mm)

% Similar to letter
[72 0 0 -72 0 842]

% 842 ≈ 297mm ÷ 25.4 × 72

1.10.3. Display Device

% Device-dependent, might be:
[1 0 0 -1 0 screenHeight]

% Or with DPI scaling:
[dpi/72 0 0 -dpi/72 0 height]

1.11. Matrix Components

For a typical page device:

[a b c d tx ty] = [72 0 0 -72 0 792]
  • a = 72: x-scale (points to device units)

  • b = 0: no rotation

  • c = 0: no shear

  • d = -72: y-scale (negative = inverted)

  • tx = 0: x origin

  • ty = 792: y origin (page height in points)

1.12. Relationship to initmatrix

% These are equivalent:
initmatrix

matrix defaultmatrix setmatrix

% initmatrix is just a convenience

1.13. See Also


Back to top

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