Geometry
in package
Converts between a page as it is displayed and the PDF user space its content is drawn in.
Positions are given on the page as a viewer shows it: in points, from its top-left corner, after the
crop box and /Rotate are applied. The transform is the one pdf.js uses at scale 1, so a position picked
on a page rendered by pdf.js lands in the same place here.
Table of Contents
Methods
- displaySize() : array{float, float}
- The width and height of the displayed page.
- displayTransform() : array{float, float, float, float, float, float}
- The transform from user space to the displayed page, y downward: a b c d e f.
- placementMatrix() : array{float, float, float, float, float, float}
- The `cm` matrix that draws an image into a rectangle on the displayed page.
- toUser() : array{float, float}
- Converts a point on the displayed page to user space.
Methods
displaySize()
The width and height of the displayed page.
public
static displaySize(array{float, float, float, float} $viewBox, int $rotation) : array{float, float}
Parameters
- $viewBox : array{float, float, float, float}
-
The displayed box.
- $rotation : int
-
0, 90, 180 or 270.
Return values
array{float, float}displayTransform()
The transform from user space to the displayed page, y downward: a b c d e f.
public
static displayTransform(array{float, float, float, float} $viewBox, int $rotation) : array{float, float, float, float, float, float}
Parameters
- $viewBox : array{float, float, float, float}
-
The displayed box: lower-left x and y, upper-right x and y.
- $rotation : int
-
0, 90, 180 or 270.
Return values
array{float, float, float, float, float, float}placementMatrix()
The `cm` matrix that draws an image into a rectangle on the displayed page.
public
static placementMatrix(callable(float, float): array{float, float} $toUser, float $x, float $y, float $width, float $height) : array{float, float, float, float, float, float}
An image is drawn into the unit square, so the matrix maps its bottom-left, bottom-right and top-left corners onto the rectangle's. Converting the corners one by one accounts for rotation and a crop box away from the origin, and keeps the image upright on screen.
Parameters
- $toUser : callable(float, float): array{float, float}
-
Converts a displayed point to user space.
- $x : float
-
The rectangle's left edge on the displayed page.
- $y : float
-
Its top edge.
- $width : float
-
Its width.
- $height : float
-
Its height.
Return values
array{float, float, float, float, float, float}toUser()
Converts a point on the displayed page to user space.
public
static toUser(array{float, float, float, float, float, float} $transform, float $x, float $y) : array{float, float}
Parameters
- $transform : array{float, float, float, float, float, float}
-
- $x : float
-
From the displayed page's left edge.
- $y : float
-
From its top edge, downward.