drawStamp method

void drawStamp(
  1. PdfStamp stamp
)

Applies stamp to the page, on the layer it declares.

Implementation

void drawStamp(PdfStamp stamp) {
  final size = stamp.measure(document);
  final rect = stamp.resolveRect(transformer, size);
  final matrix = transformer.displayTransform(rect);

  if (stamp.rotationDegrees != 0) {
    // Rotate around the center of the stamp, without moving the anchor.
    final cx = size.x / 2;
    final cy = size.y / 2;
    matrix
      ..translateByDouble(cx, cy, 0, 1)
      ..rotateZ(stamp.rotationDegrees * math.pi / 180)
      ..translateByDouble(-cx, -cy, 0, 1);
  }

  void build(PdfGraphics canvas) {
    canvas.setTransform(matrix);
    stamp.paint(canvas, size);
  }

  if (stamp.layer == PdfStampLayer.underlay) {
    drawUnderlay(build);
  } else {
    drawOverlay(build);
  }
}