paintIntoCanvas method

  1. @override
void paintIntoCanvas(
  1. Canvas targetCanvas,
  2. DrawingParameters? parentDrawingParameters
)
override

Implementation

@override
void paintIntoCanvas(
    Canvas targetCanvas, DrawingParameters? parentDrawingParameters) {
  DrawingParameters usedDrawingParameters =
      mergeDrawingParameters(drawingParameters!, parentDrawingParameters);

  targetCanvas.save();
  if (drawingParameters!.transformMatrix != null) {
    targetCanvas.transform(drawingParameters!.transformMatrix!);
  }
  if (drawingParameters!.translate != null) {
    targetCanvas.translate(
        drawingParameters!.translate!.dx, drawingParameters!.translate!.dy);
  }

  var commonPath = new Path();
  pathElements.forEach((PathElement element) {
    element.addToPath(commonPath);
  });

  if (usedDrawingParameters.fillColor != null) {
    var fillPathPaint = new Paint()
      ..style = PaintingStyle.fill
      ..color = usedDrawingParameters.fillColor!;
    targetCanvas.drawPath(commonPath, fillPathPaint);
  }

  var strokePathPaint = new Paint()
    ..style = PaintingStyle.stroke
    ..color = usedDrawingParameters.strokeColor!
    ..strokeWidth = usedDrawingParameters.strokeWidth!;
  if (usedDrawingParameters.strokeLineCap != null) {
    strokePathPaint.strokeCap = usedDrawingParameters.strokeLineCap!;
  }
  if (usedDrawingParameters.strokeLineJoin != null) {
    strokePathPaint.strokeJoin = usedDrawingParameters.strokeLineJoin!;
  }
  if (usedDrawingParameters.strokeLineMiterLimit != null) {
    strokePathPaint.strokeMiterLimit =
        usedDrawingParameters.strokeLineMiterLimit!;
  }
  targetCanvas.drawPath(commonPath, strokePathPaint);

  targetCanvas.restore();
}