displayTransform method
cm matrix that installs a local coordinate system aligned with the
display.
The origin of the local system sits at the lower-left corner of the given
visible rectangle, x grows to the right of the screen, y grows up
the screen and the unit is the display point. This is what allows
drawing a horizontal stamp even on a page with /Rotate 90: the content
is rotated in user space by exactly as much as the reader will rotate it
back.
Implementation
Matrix4 displayTransform(PdfTopLeftRect rect) {
final origin = pointFromTopLeft(rect.left, rect.bottom);
final scale = 1 / userUnit;
// The display rotates clockwise; for the content to appear upright, it has
// to rotate the same amount counter-clockwise in the user space.
final angle = rotationDegrees * math.pi / 180;
return Matrix4.identity()
..translateByDouble(origin.x, origin.y, 0, 1)
..rotateZ(angle)
..scaleByDouble(scale, scale, 1, 1);
}