...master 2026-11-10 (4e7201cfc+unstaged)

Matrix

A Matrix is used to compute transformations of points and graphics objects.

3-by-3 matrices of this form can perform 2-dimensional transformations such as translations, rotations, scaling, and skewing:

/ a b 0 \
| c d 0 |
\ e f 1 /

Because of the fixes values in the right-most column, such a matrix is represented in Javascript as an array of six numbers:

[a, b, c, d, e, f]

In TypeScript the Matrix type is defined as follows:

type Matrix = [number, number, number, number, number, number]

Constructors

class Matrix()

This is an interface, not a concrete class!

Matrices are not represented by a class; they are just plain arrays of six numbers.

Static properties

Matrix.identity

The identity matrix, short hand for [1, 0, 0, 1, 0, 0].

var m = mupdf.Matrix.identity

Static methods

Matrix.scale(sx, sy)

Returns a scaling matrix, short hand for [sx, 0, 0, sy, 0, 0].

var m = mupdf.Matrix.scale(2, 2)

Matrix.translate(tx, ty)

Return a translation matrix, short hand for [1, 0, 0, 1, tx, ty].

var m = mupdf.Matrix.translate(2, 2)

Matrix.rotate(theta)

Return a rotation matrix, short hand for [cos(theta), sin(theta), -sin(theta), cos(theta), 0, 0].

var m = mupdf.Matrix.rotate(90)

Matrix.concat(a, b)

Concatenate matrices a and b. Bear in mind that matrix multiplication is not commutative.

var m = mupdf.Matrix.concat([1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2])
// expected result [4, 4, 4, 4, 6, 6]

Matrix.invert(matrix)

Inverts the supplied matrix and returns the result.

var m = mupdf.Matrix.invert([1, 0.5, 1, 1, 1, 1])