clip method

void clip(
  1. Canvas canvas
)

Implementation

void clip(ui.Canvas canvas) {
  for (final List<ClipShape> clips in clipShapes) {
    for (final ClipShape clipShape in clips) {
      var shape = clipShape.shape;
      if (shape.renderCollapsed) {
        continue;
      }
      if (clipShape.intersect) {
        canvas.clipPath((shape as FlutterActorShape).path);
      } else {
        var artboardRect = Rect.fromLTWH(
            artboard.origin[0] * artboard.width,
            artboard.origin[1] * artboard.height,
            artboard.width,
            artboard.height);

        if (shape.fill != null && shape.fill!.fillRule == FillRule.evenOdd) {
          // One single clip path with subtraction rect and all sub paths.
          var clipPath = ui.Path();
          clipPath.addRect(artboardRect);
          for (final path in shape.paths) {
            clipPath.addPath((path as FlutterPath).path, ui.Offset.zero,
                matrix4: path.pathTransform.mat4);
          }
          clipPath.fillType = PathFillType.evenOdd;
          canvas.clipPath(clipPath);
        } else {
          // One clip path with rect per shape path.
          for (final path in shape.paths) {
            var clipPath = ui.Path();
            clipPath.addRect(artboardRect);
            clipPath.addPath((path as FlutterPath).path, ui.Offset.zero,
                matrix4: path.pathTransform.mat4);
            clipPath.fillType = PathFillType.evenOdd;
            canvas.clipPath(clipPath);
          }
        }
      }
    }
  }
}