Overview#
Implement basic SVG rendering support for inline SVG elements in HTML documents.
Requirements#
Parsing#
- Parse SVG elements in the HTML parser (SVG namespace):
<svg>container withwidth,height,viewBox<rect>withx,y,width,height,rx,ry<circle>withcx,cy,r<ellipse>withcx,cy,rx,ry<line>withx1,y1,x2,y2<path>withdattribute (SVG path data)<text>withx,yand text content<g>group element
- Parse SVG path data commands: M, L, H, V, C, S, Q, T, A, Z (and lowercase relative variants)
SVG Presentation Attributes#
fill: color ornonestroke: colorstroke-width: lengthopacityandfill-opacity/stroke-opacitytransform:translate(),rotate(),scale(),matrix()
Rendering#
- SVG coordinate system: viewBox mapping to viewport
- Rasterize filled shapes (rect, circle, ellipse, path)
- Rasterize strokes
- Path rendering: convert cubic/quadratic beziers to scanlines
- Apply transforms to coordinates before rasterization
- Render SVG text using the text crate's glyph rasterizer
- Generate appropriate paint commands (display list entries) for the GPU/software renderer
Integration#
- Extend HTML parser in
crates/html/to handle SVG namespace elements - Add SVG node types or attributes to DOM in
crates/dom/ - Add SVG layout handling in
crates/layout/(SVG elements create a replaced-element-like box) - Add SVG paint commands to
crates/render/
Acceptance Criteria#
-
<svg><rect width="100" height="100" fill="red"/></svg>renders a red square -
<svg><circle cx="50" cy="50" r="40" fill="blue"/></svg>renders a blue circle - SVG
<path>with line and curve commands renders correctly -
<text>renders text at specified position -
viewBoxscales SVG content to fit the viewport -
fill,stroke,stroke-widthattributes work -
transformattribute applies correctly - SVG embedded in HTML renders inline with surrounding content
- All existing tests continue to pass
- Unit tests for path data parsing and coordinate transforms