renderToContext2D method
void
renderToContext2D(
- dynamic context2D
Exports the signature to html canvas.
Implementation
void renderToContext2D(dynamic context2D) {
final String strokePenColor =
'${(strokeColor.r * 255).toInt()},${(strokeColor.g * 255).toInt()},${(strokeColor.b * 255).toInt()},${strokeColor.a.toStringAsFixed(2)}';
final String backgroundFillColor =
'${(backgroundColor.r * 255).toInt()},${(backgroundColor.g * 255).toInt()},${(backgroundColor.b * 255).toInt()},${backgroundColor.a.toStringAsFixed(2)}';
//Drawing the background of the SignaturePad
fillStyle(context2D, backgroundFillColor);
fillRect(context2D, size);
fill(context2D);
beginPath(context2D);
if (!_restrictBezierPathCalculation) {
for (int i = 0; i < _dotPoints.length; i++) {
final Offset point = _dotPoints[i];
drawContext2DArc(
context2D,
point.dx,
point.dy,
(_minimumStrokeWidth + _maximumStrokeWidth) / 2,
0,
pi * 2,
true,
);
}
for (int i = 0; i < _bezierPoints.length; i++) {
drawContext2DArc(
context2D,
_bezierPoints[i].x,
_bezierPoints[i].y,
_bezierPoints[i].width / 2,
0,
2 * pi,
false,
);
}
fillStyle(context2D, strokePenColor);
fill(context2D);
} else {
for (int i = 0; i < _data.length; i++) {
if (_data[i].length == 1) {
final _TouchPoint point = _data[i][0];
drawContext2DArc(
context2D,
point.x,
point.y,
(_minimumStrokeWidth + _maximumStrokeWidth) / 2,
0,
pi * 2,
true,
);
fillStyle(context2D, strokePenColor);
fill(context2D);
} else {
final List<_TouchPoint> drawPath = _data[i];
for (int i = 0; i < drawPath.length; i++) {
if (i < drawPath.length - 1) {
drawContext2DLine(
context2D,
drawPath[i].x,
drawPath[i].y,
drawPath[i + 1].x,
drawPath[i + 1].y,
);
}
}
lineWidth(context2D, _maximumStrokeWidth);
strokeStyle(context2D, strokePenColor);
lineCap(context2D, 'round');
stroke(context2D);
}
}
}
}