paint method

  1. @override
void paint(
  1. Context context,
  2. PdfRect box
)
override

Implementation

@override
void paint(Context context, PdfRect box) {
  final _image = image.resolve(context, box.size, dpi: dpi);

  final imageSize =
      PdfPoint(_image.width.toDouble(), _image.height.toDouble());
  final sizes = applyBoxFit(fit, imageSize, box.size);
  final scaleX = sizes.destination!.x / sizes.source!.x;
  final scaleY = sizes.destination!.y / sizes.source!.y;
  final sourceRect = alignment.inscribe(
      sizes.source!, PdfRect.fromPoints(PdfPoint.zero, imageSize));
  final destinationRect = alignment.inscribe(sizes.destination!, box);
  final mat =
      Matrix4.translationValues(destinationRect.x, destinationRect.y, 0)
        ..scale(scaleX, scaleY, 1)
        ..translate(-sourceRect.x, -sourceRect.y);

  context.canvas
    ..saveContext()
    ..drawBox(box)
    ..clipPath()
    ..setTransform(mat)
    ..drawImage(_image, 0, 0, imageSize.x, imageSize.y)
    ..restoreContext();
}