paint method

void paint(
  1. Context context,
  2. PdfRect box, [
  3. PaintPhase phase = PaintPhase.all
])

Implementation

void paint(
  Context context,
  PdfRect box, [
  PaintPhase phase = PaintPhase.all,
]) {
  final resolvedBorderRadius =
      borderRadius?.resolve(Directionality.of(context));
  if (phase == PaintPhase.all || phase == PaintPhase.background) {
    if (color != null) {
      switch (shape) {
        case BoxShape.rectangle:
          if (resolvedBorderRadius == null) {
            if (boxShadow != null) {
              for (final s in boxShadow!) {
                final i = PdfRasterBase.shadowRect(box.width, box.height,
                    s.spreadRadius, s.blurRadius, s.color);
                final m = PdfImage.fromImage(context.document, image: i);
                context.canvas.drawImage(
                  m,
                  box.x + s.offset.x - s.spreadRadius,
                  box.y - s.offset.y - s.spreadRadius,
                );
              }
            }
            context.canvas.drawBox(box);
          } else {
            if (boxShadow != null) {
              for (final s in boxShadow!) {
                final i = PdfRasterBase.shadowRect(box.width, box.height,
                    s.spreadRadius, s.blurRadius, s.color);
                final m = PdfImage.fromImage(context.document, image: i);
                context.canvas.drawImage(
                  m,
                  box.x + s.offset.x - s.spreadRadius,
                  box.y - s.offset.y - s.spreadRadius,
                );
              }
            }
            resolvedBorderRadius.paint(context, box);
          }
          break;
        case BoxShape.circle:
          if (boxShadow != null && box.width == box.height) {
            for (final s in boxShadow!) {
              final i = PdfRasterBase.shadowEllipse(box.width, box.height,
                  s.spreadRadius, s.blurRadius, s.color);
              final m = PdfImage.fromImage(context.document, image: i);
              context.canvas.drawImage(
                m,
                box.x + s.offset.x - s.spreadRadius,
                box.y - s.offset.y - s.spreadRadius,
              );
            }
          }
          context.canvas.drawEllipse(box.x + box.width / 2.0,
              box.y + box.height / 2.0, box.width / 2.0, box.height / 2.0);
          break;
      }
      context.canvas
        ..setFillColor(color)
        ..fillPath();
    }

    if (gradient != null) {
      switch (shape) {
        case BoxShape.rectangle:
          if (resolvedBorderRadius == null) {
            context.canvas.drawBox(box);
          } else {
            resolvedBorderRadius.paint(context, box);
          }
          break;
        case BoxShape.circle:
          context.canvas.drawEllipse(box.x + box.width / 2.0,
              box.y + box.height / 2.0, box.width / 2.0, box.height / 2.0);
          break;
      }

      gradient!.paint(context, box);
    }

    if (image != null) {
      context.canvas.saveContext();
      switch (shape) {
        case BoxShape.circle:
          context.canvas
            ..drawEllipse(box.x + box.width / 2.0, box.y + box.height / 2.0,
                box.width / 2.0, box.height / 2.0)
            ..clipPath();

          break;
        case BoxShape.rectangle:
          if (resolvedBorderRadius != null) {
            resolvedBorderRadius.paint(context, box);
            context.canvas.clipPath();
          }
          break;
      }
      image!.paint(context, box);
      context.canvas.restoreContext();
    }
  }

  if (phase == PaintPhase.all || phase == PaintPhase.foreground) {
    if (border != null) {
      border!.paint(
        context,
        box,
        shape: shape,
        borderRadius: resolvedBorderRadius,
      );
    }
  }
}