rectFromTopLeft method

PdfRect rectFromTopLeft({
  1. required double left,
  2. required double top,
  3. required double width,
  4. required double height,
})

Converts a "top-left" rectangle to a PdfRect in user space.

Since the rotations are multiples of 90 degrees, the rectangle stays axis-aligned; at 90 and 270 degrees width and height swap places, which is exactly what the two current converters get wrong.

Implementation

PdfRect rectFromTopLeft({
  required double left,
  required double top,
  required double width,
  required double height,
}) {
  final a = pointFromTopLeft(left, top);
  final b = pointFromTopLeft(left + width, top + height);
  return PdfRect.fromLBRT(
    math.min(a.x, b.x),
    math.min(a.y, b.y),
    math.max(a.x, b.x),
    math.max(a.y, b.y),
  );
}