Phase 18: Canvas 2D API — Issue 5/10#
Implement line style properties and dashed line support for canvas stroke operations.
Dependencies#
- Canvas path API & rasterization (issue 4)
Requirements#
Line cap styles (lineCap property):
'butt'(default) — flat edge at endpoint'round'— semicircle at endpoint'square'— half-square projection at endpoint
Line join styles (lineJoin property):
'miter'(default) — sharp corner, clipped by miterLimit'round'— circular arc at corner'bevel'— flat diagonal at corner
Miter limit:
miterLimitproperty (default 10.0)- When miter length / lineWidth exceeds miterLimit, fall back to bevel join
Dash patterns:
setLineDash(segments)— set the dash pattern (alternating dash/gap lengths)getLineDash()— return current dash patternlineDashOffsetproperty — offset into the dash pattern- If segments array has odd length, double it per spec
- Empty segments array = solid line
Stroke geometry:
- Generate offset curves at ±lineWidth/2 from the path centerline
- Apply line caps at sub-path endpoints
- Apply line joins at path segment junctions
- Apply dash pattern along the path length
Acceptance criteria#
- Stroked paths respect lineCap, lineJoin, miterLimit settings
- Dashed lines render correctly with various dash patterns
- lineDashOffset shifts the dash pattern
- Round caps and joins produce visually smooth curves
- save/restore correctly preserves line style state
- Unit tests for dash pattern application and join geometry