PdfCoordinateTransformer class

Single conversion between "top-left" coordinates and the PDF user space.

The PDF space has its origin at the lower-left corner of the page box — which is not necessarily (0, 0) — with y growing upwards. Whoever uses the library almost always thinks in the opposite system: origin at the upper-left corner of what shows on screen, y downwards. This class is the only place that should know how to translate between the two, taking into account:

  • the box origin: /MediaBox [20 30 615 872] shifts everything by (20, 30);
  • the /CropBox, when present: it is the one, not the /MediaBox, that defines what the reader shows (the specification requires using the intersection of the two);
  • the /Rotate of 0, 90, 180 or 270 degrees, which rotates the page clockwise on display and swaps width for height at 90 and 270;
  • the /UserUnit, which scales the unit of the user space.

It replaces the two conversions the library used to carry — PdfDocument._rectFromTopLeft and PdfSignatureBounds.toPdfRect — which only did bottom = pageFormat.height - top - height. That is right only for an unrotated page, with a box starting at (0, 0), without a /CropBox and with /UserUnit equal to 1; both now delegate here (roadmap item D5).

Annotations
  • @immutable

Constructors

PdfCoordinateTransformer({required PdfBox box, PdfPageRotation rotation = PdfPageRotation.none, double userUnit = 1.0})
Creates the transformer for a box, a rotation and a /UserUnit.
PdfCoordinateTransformer.forPage(PdfPage page, {PdfBoxType reference = PdfBoxType.crop})
Creates the transformer of a page, new or loaded.
factory

Properties

box → PdfBox
The reference box, already normalized.
final
displayHeight → double
Height of the page as it appears, in display points.
no setter
displayWidth → double
Width of the page as it appears, in display points.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isQuarterTurned → bool
Whether the rotation swaps width for height.
no setter
rotation → PdfPageRotation
The display rotation of the page.
final
rotationDegrees → int
Rotation in degrees, clockwise on display.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
userUnit → double
The /UserUnit of the page: how many points one user unit is worth.
final

Methods

boxFromTopLeft({required double left, required double top, required double width, required double height}) → PdfBox
Converts a "top-left" box to a PdfBox in user space.
displayTransform(PdfTopLeftRect rect) → Matrix4
cm matrix that installs a local coordinate system aligned with the display.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pointFromTopLeft(double x, double y) → PdfPoint
Converts a "top-left" point to the user space.
pointToTopLeft(double x, double y) → PdfPoint
Converts a point from the user space to "top-left" coordinates.
rectFromTopLeft({required double left, required double top, required double width, required double height}) → PdfRect
Converts a "top-left" rectangle to a PdfRect in user space.
rectFromTopLeftRect(PdfTopLeftRect rect) → PdfRect
Version of rectFromTopLeft that takes the rectangle already built.
rectToTopLeft(PdfRect rect) → PdfTopLeftRect
Converts a rectangle from the user space to "top-left" coordinates.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

pageBox(PdfPage page, [PdfBoxType type = PdfBoxType.media]) → PdfBox
The type box of page, with the box inheritance rules applied.
pageUserUnit(PdfPage page) → double
The /UserUnit of page, or 1 when absent or invalid.