canvaskit-wasm 0.39
build 2026-04-29
StrokeCap
The shape drawn at the open ends of a stroked path. Set via paint.setStrokeCap(CK.StrokeCap.<value>). Closed paths (those that end with close()) have no caps — only joins.
const cap = controls.select('cap', ['Butt', 'Round', 'Square'], 'Round');
const stroke = new CK.Paint();
stroke.setStyle(CK.PaintStyle.Stroke);
stroke.setStrokeWidth(20);
stroke.setColor(CK.Color(40, 90, 180, 1));
stroke.setAntiAlias(true);
loop(() => {
stroke.setStrokeCap(CK.StrokeCap[cap()]);
canvas.clear(CK.WHITE);
canvas.drawLine(80, 128, 340, 128, stroke);
surface.flush();
});
All values
| Value | Shape | Notes |
|---|---|---|
Butt | Flat end exactly at the endpoint. | Default. Stroke does not extend. |
Round | Semicircular cap. | Stroke extends by half the width past the endpoint. Combine with MakeDash([0.01, gap]) for dotted lines. |
Square | Square cap. | Stroke extends by half the width as a flat square. |