paint method

  1. @override
void paint(
  1. Context context,
  2. PdfRect box, {
  3. BoxShape shape = BoxShape.rectangle,
  4. BorderRadius? borderRadius,
})
override

Implementation

@override
void paint(
  Context context,
  PdfRect box, {
  BoxShape shape = BoxShape.rectangle,
  BorderRadius? borderRadius,
}) {
  if (isUniform) {
    if (top.style == BorderStyle.none) {
      return;
    }

    switch (shape) {
      case BoxShape.circle:
        assert(borderRadius == null,
            'A borderRadius can only be given for rectangular boxes.');
        BoxBorder._paintUniformBorderWithCircle(context, box, top);
        break;
      case BoxShape.rectangle:
        if (borderRadius != null) {
          BoxBorder._paintUniformBorderWithRadius(
              context, box, top, borderRadius);
          return;
        }
        BoxBorder._paintUniformBorderWithRectangle(context, box, top);
        break;
    }
    return;
  }

  assert(borderRadius == null,
      'A borderRadius can only be given for a uniform Border.');

  context.canvas
    ..setLineCap(PdfLineCap.square)
    ..setMiterLimit(4)
    ..setLineJoin(PdfLineJoin.miter);

  if (top.style.paint) {
    top.style.setStyle(context);
    context.canvas
      ..setStrokeColor(top.color)
      ..setLineWidth(top.width)
      ..drawLine(box.left, box.top, box.right, box.top)
      ..strokePath();
    top.style.unsetStyle(context);
  }

  if (right.style.paint) {
    right.style.setStyle(context);
    context.canvas
      ..setStrokeColor(right.color)
      ..setLineWidth(right.width)
      ..drawLine(box.right, box.top, box.right, box.bottom)
      ..strokePath();
    right.style.unsetStyle(context);
  }

  if (bottom.style.paint) {
    bottom.style.setStyle(context);
    context.canvas
      ..setStrokeColor(bottom.color)
      ..setLineWidth(bottom.width)
      ..drawLine(box.right, box.bottom, box.left, box.bottom)
      ..strokePath();
    bottom.style.unsetStyle(context);
  }

  if (left.style.paint) {
    left.style.setStyle(context);
    context.canvas
      ..setStrokeColor(left.color)
      ..setLineWidth(left.width)
      ..drawLine(box.left, box.top, box.left, box.bottom)
      ..strokePath();
    left.style.unsetStyle(context);
  }
}