1. scale

Changes the unit size of the coordinate system.

1.1. Syntax

sx sy scale → -
sx sy matrix scale → matrix

1.2. Stack Effects

Table 1. Before
Level Object

1

sy (number)

0

sx (number)

Table 2. After (first form)
Level Object

(empty)

No results

Table 3. After (second form)
Level Object

0

matrix (modified matrix)

1.3. Description

With no matrix operand, scale builds a temporary transformation matrix S and concatenates it with the current transformation matrix (CTM). Precisely, scale replaces the CTM by S × CTM.

The effect is to make the x and y units in the user coordinate system the size of sx and sy units in the former user coordinate system. The position of the user coordinate origin and the orientation of the axes are unchanged.

If the matrix operand is supplied, scale replaces the value of matrix by S and pushes the modified matrix back on the operand stack. In this case, scale does not affect the CTM.

The scaling matrix S has the form:

[sx 0 0 sy 0 0]

This transforms coordinates according to:

x' = sx × x
y' = sy × y

1.4. PostScript Level

Level 1 and later

1.5. Examples

Uniform scaling
2 2 scale         % Double size in both directions
0 0 50 50 rectfill % Draws 100x100 rectangle
Non-uniform scaling
2 1 scale         % Stretch horizontally
newpath
0 0 moveto
100 0 lineto
100 100 lineto
0 100 lineto
closepath
stroke            % Draws 200x100 rectangle
Scaling fonts
/Helvetica findfont
12 scalefont setfont  % Scale font to 12 points

% Equivalent using scale operator:
/Helvetica findfont
setfont
12 12 scale
(Text) show

1.6. Common Use Cases

1.6.1. Converting Units

% Convert to inches (72 points per inch)
72 72 scale
% Now coordinates are in inches
1 1 moveto        % 1 inch from origin
2 2 lineto        % To 2 inches from origin
stroke

1.6.2. Creating Aspect Ratios

% Create 16:9 aspect ratio in unit square
1 0.5625 scale    % 9/16 = 0.5625
0 0 1 1 rectfill  % Draws 16:9 rectangle

1.6.3. Mirror Effects

% Horizontal mirror (flip)
-1 1 scale
-100 0 translate  % Adjust position

% Vertical mirror
1 -1 scale
0 -100 translate

1.6.4. Coordinate System Setup

% Set up coordinate system: (0,0) at lower-left,
% (1,1) at upper-right of letter page
612 792 scale
% Now can use normalized coordinates 0-1

1.7. Common Pitfalls

Line Width Affected - Scaling affects line width. A 1-point line becomes thicker when scaled up.
1 setlinewidth
newpath
0 0 moveto
100 100 lineto
stroke            % 1-point line

2 2 scale
newpath
0 0 moveto
50 50 lineto
stroke            % 2-point line (appears thicker)
Dash Patterns Affected - Dash patterns are also scaled with the coordinate system.
[5 3] 0 setdash   % 5 on, 3 off
2 2 scale
% Dash pattern is now effectively [10 6] 0
Negative Scaling Reverses Direction - Negative scale values flip the coordinate system, which can reverse path direction.
-1 1 scale        % Horizontal flip
% Text and paths may appear reversed
Use setlinewidth After Scaling - Set line width after scaling for consistent appearance:
2 2 scale
1 setlinewidth    % Line appears as 2 points in original space
Preserve Aspect Ratio - For proportional scaling, use the same value for sx and sy:
2 2 scale         % Proportional
% Not: 2 3 scale (distorts aspect ratio)

1.8. Error Conditions

Error Condition

[rangecheck]

Resulting matrix values exceed implementation limits

[stackunderflow]

Fewer than 2 operands on stack (first form) or fewer than 3 (second form)

[typecheck]

Operands are not numbers, or matrix operand is not an array

1.9. Implementation Notes

  • Zero scale values create a degenerate transformation (not recommended)

  • Very small scale values may cause precision loss

  • Very large scale values may cause coordinates to exceed device limits

  • Scaling is applied during path construction

  • The flatness parameter for curves is in device space, so it’s unaffected by scaling

1.10. Matrix Mathematics

The scaling matrix for scale by (sx, sy) is:

S = [sx  0   0   sy  0  0]

Concatenating with the CTM:

CTM' = S × CTM
     = [sx  0   0   sy  0  0] × [a  b  c  d  e  f]
     = [sx×a  sx×b  sy×c  sy×d  e  f]

1.11. Graphics State Effects

Scaling affects several graphics state parameters when they are used:

  • Line width: Scaled by the transformation

  • Dash pattern: Dash lengths are scaled

  • Flatness: Remains in device space (not affected)

  • Path coordinates: Transformed by the scale

1.12. Performance Considerations

  • Scaling is a very efficient operation

  • No path recomputation is needed

  • Uniform scaling (sx = sy) may be slightly faster than non-uniform scaling

  • Extreme scale values can impact rendering performance

1.13. Relationship to Other Operators

% These are equivalent:
/Helvetica findfont 12 scalefont setfont
/Helvetica findfont setfont 12 12 scale

% Building a transformation:
gsave
  2 2 scale
  45 rotate
  100 100 translate
  % Draw content
grestore

1.14. See Also


Back to top

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