viewBoxToCanvas method
Implementation
void viewBoxToCanvas(Canvas canvas, Size size) {
if (this.debugOptions.showViewPort) {
Rect clipRect1 = Offset.zero & size;
Paint ppp = new Paint()
..style = PaintingStyle.stroke
..color = Colors.green
..strokeWidth = 10.50;
canvas.drawRect(clipRect1, ppp);
}
if (scaleToViewport) {
//Viewbox with Offset.zero
Size viewBox = (this.customDimensions != null)
? this.customDimensions!
: Size.copy(size);
_ScaleFactor scale = calculateScaleFactor(viewBox);
canvas.scale(scale.x, scale.y);
//If offset
Offset offset = Offset.zero - this.pathBoundingBox.topLeft;
canvas.translate(offset.dx, offset.dy);
//Center offset - TODO should this be a option flag?
if (this.debugOptions.recordFrames != true) {
Offset center = Offset(
(size.width / scale.x - this.pathBoundingBox.width) / 2,
(size.height / scale.y - this.pathBoundingBox.height) / 2);
canvas.translate(center.dx, center.dy);
}
}
//Clip bounds
Rect clipRect = this.pathBoundingBox;
if (!(this.debugOptions.showBoundingBox || this.debugOptions.showViewPort))
canvas.clipRect(clipRect);
if (this.debugOptions.showBoundingBox) {
Paint pp = new Paint()
..style = PaintingStyle.stroke
..color = Colors.red
..strokeWidth = 0.500;
canvas.drawRect(clipRect, pp);
}
}