فهرست منبع

Render inline SVG and fix tagesschau.de layout gaps

tagesschau.de showed no header logo, wordmark or burger icon, a dark box
in the navigation, its hero image below a grey placeholder, doubled teaser
line spacing and "mehr" links on their own line.

- Inline SVG is now rendered by svg_raster.c: every path command
  including curves and arcs, rect/circle/ellipse/line/polyline/polygon,
  <g>/nested <svg>/<use> of a <symbol>, transform lists, viewBox with
  preserveAspectRatio, nonzero/even-odd fill, strokes, opacity,
  currentColor and gradients painted as their average stop colour.
  Coverage is antialiased into an RGB565 + alpha layer cached per node
  and size; percentages resolve against the viewBox.  Host test:
  make test-svg.
- SVG paint is its own inherited style state (fill/stroke modes, colours
  and stroke width) instead of reusing background/border, so CSS fill on
  an HTML element (the burger button) no longer paints its background.
  getComputedStyle exposes fill and stroke.
- Absolutely positioned boxes: the deferred paint list held 16 entries,
  so later posters fell back into the flow below their padding-top
  aspect box.  It now holds 256, and an overflow still paints against
  the containing block.
- line-height in rem is an absolute length, not a multiplier.
- An inline-flex box around inline content stays in the text line.

Compat ladder: new pages 067-070, and 058 now checks fill instead of
the old background shortcut.
Johannes Zellner 1 هفته پیش
والد
کامیت
13291ce526

+ 1 - 0
.gitignore

@@ -16,6 +16,7 @@ text_canvas_test
 ufont_test
 ufont_test_asan
 touchpad_gesture_test
+svg_test
 libc.a
 malloc_test
 format_test

+ 25 - 6
AGENTS.md

@@ -81,6 +81,7 @@ make test-libc  # host tests for ring-3 malloc, stdio, math, div64 and setjmp
 make test-mujs  # host smoke test for the vendored MuJS engine
 make test-font  # host TrueType parser/rasterizer specimen test
 make test-font-asan  # ASan/UBSan variant
+make test-svg   # host tests for the inline-SVG rasterizer (ASan/UBSan)
 make test-touchpad  # host tests for the contact gesture engine
 make test-wpa   # host tests for the WPA2-PSK supplicant (SHA-1/PBKDF2/PRF/AES, 4-way)
 make test-chat  # host tests: JSON parser, cookie jar, chat login parsers (ASan)
@@ -991,10 +992,26 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `@font-face` loads one regular TTF per family from a local path or HTTP URL
   (the browser fetches remote faces before layout).  The compatibility
   ladder is `testdata/browser/compat/`
-  (`make compat-serve`); pages 010–046 and 030a pass (036a needs the
-  POST echo server).  Inline
-  `<svg>` subtrees and closed `<details>` are skipped (not renderable), and
-  `<video>` gets a placeholder box.  The default page canvas follows
+  (`make compat-serve`); pages 010–070 and 030a pass (036a needs the
+  POST echo server).  Closed `<details>` are skipped and `<video>` gets a
+  placeholder box.  Inline `<svg>` is rendered by `svg_raster.c/h`
+  (freestanding, host test `make test-svg`): every path command including
+  curves and elliptical arcs, `rect`/`circle`/`ellipse`/`line`/`polyline`/
+  `polygon`, `<g>`/`<a>`/nested `<svg>`/`<use>` of a `<symbol>`, `transform`
+  lists, viewBox + `preserveAspectRatio`, nonzero/even-odd fill, strokes,
+  `opacity`/`fill-opacity`, `currentColor`, and a gradient `url(#id)` painted
+  as the average of its stops.  Coverage is antialiased (4 vertical
+  subsamples, exact horizontal spans) into an RGB565 + alpha layer that is
+  cached per node and size (`SVG_CACHE_PIXELS`, page heap, dropped before
+  `heap_reset()`) and blitted on repaint; `<text>` is drawn on top each
+  frame.  SVG paint is its own inherited style state (`fill_mode`/`fill`/
+  `stroke_mode`/`stroke`/`stroke_w`, `BR_PAINT_*`): CSS `fill`/`stroke` on an
+  HTML element no longer paint its background or border, and
+  `getComputedStyle` exposes `fill`/`stroke`.  `line-height` in `rem` is an
+  absolute length, and an `inline-flex` box with only inline content stays in
+  the text line.  Up to `BR_MAX_DEFERRED` (256) absolute/fixed boxes are
+  painted after the flow; past that a box is painted in place against its
+  containing block.  The default page canvas follows
   `ngui_theme_dark` (dark page, light text, `theme.panel` for `<pre>`), but
   the `html`/`body` background fills the whole page canvas, so a site's white
   page has no dark side gutters; other `background-color`/`color` CSS still
@@ -1828,8 +1845,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     CSS custom properties (`var()`), flex rows with wrap/grow/gap/justify/
     align, two-track and `repeat(auto-fit, minmax(...))` grids, inline-block
     runs, basic proportional table columns, table rowspan/colspan/percentage
-    columns and inline SVG (`rect`, `line`, `path` with M/L/H/V, and `text`) are
-    supported.
+    columns and inline SVG (filled/stroked geometry, `use`/`symbol`,
+    transforms; gradients, patterns, clip paths, masks, filters, markers and
+    `textPath` are not rendered, a gradient paints its average stop colour)
+    are supported.
     `position:fixed`/`absolute` boxes are deferred and painted above the
     flow; `z-index` sorts that deferred list; `position:relative` shifts
     painting without moving flow (and joins the deferred stack when it has a

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 12 - 3
Makefile


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 699 - 186
browser.c


+ 155 - 36
browser_html.c

@@ -2316,6 +2316,83 @@ static int str_eq(const char *a, const char *b)
 
 /* ---- CSS ---- */
 
+static int parse_color(const char *s, unsigned int len, unsigned short *out);
+
+int br_parse_color(const char *s, unsigned int len, unsigned short *out)
+{
+	return parse_color(s, len, out);
+}
+
+/* SVG paint value -> BR_PAINT_* (0 when unrecognised). */
+static int paint_mode(const char *s, unsigned int len, unsigned short *c)
+{
+	while (len && is_space(*s)) {
+		s++;
+		len--;
+	}
+	while (len && is_space(s[len - 1]))
+		len--;
+	if (!len)
+		return 0;
+	if (len == 4 && ci_eq_n(s, "none", 4))
+		return BR_PAINT_NONE;
+	if (len == 12 && ci_eq_n(s, "currentcolor", 12))
+		return BR_PAINT_CURRENT;
+	if (len > 4 && ci_eq_n(s, "url(", 4))
+		return BR_PAINT_URL;
+	if (len == 11 && ci_eq_n(s, "transparent", 11))
+		return BR_PAINT_NONE;
+	if (parse_color(s, len, c))
+		return BR_PAINT_COLOR;
+	return 0;
+}
+
+/* A plain SVG length ("1.5", "2px") in 1/16 units; -1 when not a number. */
+static int svg_len16(const char *s, unsigned int len)
+{
+	unsigned int i = 0;
+	int v = 0, frac = 0, digits = 0;
+
+	while (i < len && is_space(s[i]))
+		i++;
+	while (i < len && s[i] >= '0' && s[i] <= '9') {
+		if (v < 4000)
+			v = v * 10 + (s[i] - '0');
+		i++;
+		digits++;
+	}
+	if (i < len && s[i] == '.') {
+		int scale = 1;
+
+		i++;
+		while (i < len && s[i] >= '0' && s[i] <= '9') {
+			if (scale < 10000) {
+				frac = frac * 10 + (s[i] - '0');
+				scale *= 10;
+			}
+			i++;
+			digits++;
+		}
+		frac = frac * 16 / scale;
+	}
+	if (!digits)
+		return -1;
+	return v * 16 + frac;
+}
+
+/* Inside an <svg> subtree (including the <svg> element itself). */
+static int in_svg(const struct br_doc *d, unsigned int node)
+{
+	unsigned int k;
+
+	for (k = 0; node && node < d->nnode && k < 64; k++) {
+		if (d->nodes[node].tag == BR_TAG_SVG)
+			return 1;
+		node = d->nodes[node].parent;
+	}
+	return 0;
+}
+
 enum {
 	PROP_COLOR, PROP_BG, PROP_BG_IMAGE, PROP_BG_REPEAT,
 	PROP_BG_POS_X_KIND, PROP_BG_POS_X, PROP_BG_POS_Y_KIND, PROP_BG_POS_Y,
@@ -2356,6 +2433,8 @@ enum {
 	PROP_TRANSFORM_PAINT, PROP_SCALE_X, PROP_SCALE_Y, PROP_ROTATE,
 	PROP_ORIGIN_X_KIND, PROP_ORIGIN_X, PROP_ORIGIN_Y_KIND, PROP_ORIGIN_Y,
 	PROP_VIS_HIDDEN, PROP_OPACITY_HIDDEN, PROP_OVERFLOW_HIDDEN,
+	PROP_FILL_MODE, PROP_FILL, PROP_STROKE_MODE, PROP_STROKE,
+	PROP_STROKE_W, PROP_FILL_RULE,
 	PROP_COUNT
 };
 
@@ -3103,6 +3182,12 @@ static int parse_line_height(const char *s, unsigned int len,
 	else if (i < len && s[i] == '%')
 		is_pct = 1;
 	v1000 = whole * 1000 + frac * 1000 / fscale;
+	/* rem is an absolute length (the root font is known by the time
+	 * rules are parsed, as for font-size); em behaves like a multiplier. */
+	if (i + 3 <= len && ci_eq_n(s + i, "rem", 3)) {
+		v1000 = v1000 * root_font_px;
+		is_px = 1;
+	}
 	if (is_px) {
 		int v = v1000 / 1000;
 
@@ -3118,8 +3203,8 @@ static int parse_line_height(const char *s, unsigned int len,
 			v = v1000 / 1000;
 		if (v < 50)
 			v = 50;
-		if (v > 400)
-			v = 400;
+		if (v > 255)            /* stored in an unsigned char */
+			v = 255;
 		*pct = (unsigned char)v;
 	}
 	return 1;
@@ -3199,7 +3284,7 @@ static int parse_display(const char *s, unsigned int len)
 	if (i == 4 && ci_eq_n(s, "flex", 4))
 		return BR_DISPLAY_FLEX;
 	if (i == 11 && ci_eq_n(s, "inline-flex", 11))
-		return BR_DISPLAY_FLEX;
+		return BR_DISPLAY_FLEX | BR_DISPLAY_INLINE_FLAG;
 	/* Legacy -webkit-box is the line-clamp idiom; render it as a normal
 	 * block instead of an inline box. */
 	if (i == 11 && ci_eq_n(s, "-webkit-box", 11))
@@ -4497,34 +4582,32 @@ static void parse_decls(struct br_doc *d, const char *s,
 			unsigned short c;
 			if (parse_color(s + vstart, vend - vstart, &c))
 				decl_add(out, nout, PROP_COLOR, c, important);
-		} else if (str_eq(prop, "fill")) {
-			unsigned short c;
-
-			if (parse_color(s + vstart, vend - vstart, &c)) {
-				decl_add(out, nout, PROP_BG, c, important);
-				decl_add(out, nout, PROP_COLOR, c, important);
-			}
-		} else if (str_eq(prop, "stroke")) {
+		} else if (str_eq(prop, "fill") || str_eq(prop, "stroke")) {
+			/* SVG paint only: an HTML element's fill never paints
+			 * its background (tagesschau sets fill on buttons). */
+			int is_fill = prop[0] == 'f';
 			unsigned short c;
-
-			if (parse_color(s + vstart, vend - vstart, &c)) {
-				decl_add(out, nout, PROP_BORDER_COLOR, c,
-					 important);
-				decl_add(out, nout, PROP_BORDER_W, 1, important);
+			int mode = paint_mode(s + vstart, vend - vstart, &c);
+
+			if (mode) {
+				decl_add(out, nout, is_fill ? PROP_FILL_MODE :
+					 PROP_STROKE_MODE, mode, important);
+				if (mode == BR_PAINT_COLOR)
+					decl_add(out, nout, is_fill ? PROP_FILL :
+						 PROP_STROKE, (short)c,
+						 important);
 			}
 		} else if (str_eq(prop, "stroke-width")) {
-			unsigned int j = vstart;
-			int sw = 0;
+			int sw = svg_len16(s + vstart, vend - vstart);
 
-			while (j < vend && s[j] >= '0' && s[j] <= '9') {
-				sw = sw * 10 + (s[j] - '0');
-				j++;
-			}
-			if (sw < 1)
-				sw = 1;
-			if (sw > 3)
-				sw = 3;
-			decl_add(out, nout, PROP_BORDER_W, sw, important);
+			if (sw >= 0)
+				decl_add(out, nout, PROP_STROKE_W, sw,
+					 important);
+		} else if (str_eq(prop, "fill-rule")) {
+			decl_add(out, nout, PROP_FILL_RULE,
+				 contains_ci_len(s + vstart, vend - vstart,
+						 "evenodd") ? 1 : 0,
+				 important);
 		} else if (str_eq(prop, "text-anchor")) {
 			int a = BR_ALIGN_LEFT;
 
@@ -6753,7 +6836,9 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 		st->overline = (unsigned char)(dcl->val != 0);
 		break;
 	case PROP_DISPLAY:
-		st->display = (unsigned char)dcl->val;
+		st->display = (unsigned char)(dcl->val &
+					      ~BR_DISPLAY_INLINE_FLAG);
+		st->inline_flex = (dcl->val & BR_DISPLAY_INLINE_FLAG) != 0;
 		st->list_item = 0;
 		break;
 	case PROP_VIS_HIDDEN:
@@ -6762,6 +6847,24 @@ static void apply_decl(struct br_style *st, const struct br_decl *dcl)
 	case PROP_OPACITY_HIDDEN:
 		st->opacity_hidden = (unsigned char)(dcl->val != 0);
 		break;
+	case PROP_FILL_MODE:
+		st->fill_mode = (unsigned char)dcl->val;
+		break;
+	case PROP_FILL:
+		st->fill = (unsigned short)dcl->val;
+		break;
+	case PROP_STROKE_MODE:
+		st->stroke_mode = (unsigned char)dcl->val;
+		break;
+	case PROP_STROKE:
+		st->stroke = (unsigned short)dcl->val;
+		break;
+	case PROP_STROKE_W:
+		st->stroke_w = (unsigned short)dcl->val;
+		break;
+	case PROP_FILL_RULE:
+		st->fill_evenodd = (unsigned char)(dcl->val != 0);
+		break;
 	case PROP_OVERFLOW_HIDDEN:
 		st->overflow_hidden = (unsigned char)(dcl->val != 0);
 		break;
@@ -7107,6 +7210,7 @@ void br_style_for(struct br_doc *d, unsigned int node,
 	out->origin_x = out->origin_y = 50;
 	out->origin_x_kind = out->origin_y_kind = 1;
 	out->vis_hidden = out->opacity_hidden = 0;
+	out->inline_flex = 0;
 	out->overflow_hidden = 0;
 	tag = d->nodes[node].tag;
 	out->display = br_tag_is_block(tag) ? BR_DISPLAY_BLOCK :
@@ -7243,21 +7347,36 @@ void br_style_for(struct br_doc *d, unsigned int node,
 		if (parse_color(v, s_len(v), &c))
 			out->color = c;
 	}
-	/* SVG fill/stroke attributes; CSS declarations still win below. */
-	{
+	/* SVG presentation attributes; CSS declarations still win below. */
+	if (in_svg(d, node)) {
 		const char *fa = br_find_attr(d, node, "fill");
 		const char *sa = br_find_attr(d, node, "stroke");
+		const char *wa = br_find_attr(d, node, "stroke-width");
+		const char *ra = br_find_attr(d, node, "fill-rule");
+		const char *ca = br_find_attr(d, node, "color");
 		unsigned short c;
+		int mode;
 
-		if (fa && parse_color(fa, s_len(fa), &c)) {
-			out->bg = c;
-			out->has_bg = 1;
+		if (ca && parse_color(ca, s_len(ca), &c))
 			out->color = c;
+		if (fa && (mode = paint_mode(fa, s_len(fa), &c)) != 0) {
+			out->fill_mode = (unsigned char)mode;
+			if (mode == BR_PAINT_COLOR)
+				out->fill = c;
 		}
-		if (sa && parse_color(sa, s_len(sa), &c)) {
-			out->border_c[0] = c;
-			out->border_w[0] = 1;
+		if (sa && (mode = paint_mode(sa, s_len(sa), &c)) != 0) {
+			out->stroke_mode = (unsigned char)mode;
+			if (mode == BR_PAINT_COLOR)
+				out->stroke = c;
+		}
+		if (wa) {
+			int sw = svg_len16(wa, s_len(wa));
+
+			if (sw >= 0)
+				out->stroke_w = (unsigned short)sw;
 		}
+		if (ra)
+			out->fill_evenodd = same_string(ra, "evenodd");
 	}
 
 	/* UA behaviour for a closed <details>: only its <summary> is shown.

+ 16 - 0
browser_html.h

@@ -56,6 +56,8 @@
 #define BR_DISPLAY_FLEX   3
 #define BR_DISPLAY_GRID   4
 #define BR_DISPLAY_INLINE_BLOCK 5
+/* Decl-only bit: display:inline-flex is FLEX plus st->inline_flex. */
+#define BR_DISPLAY_INLINE_FLAG 0x40
 
 /* Text alignment. */
 #define BR_ALIGN_LEFT   0
@@ -188,8 +190,20 @@ struct br_style {
 	 * 5 calc (the raw value is the percent, mp_calc_px the px part) */
 	unsigned char mp_unit[8];
 	signed short mp_calc_px[8];
+	/* SVG paint (inherited, like CSS fill/stroke): BR_PAINT_* modes.
+	 * stroke_w is in 1/16 user units; 0 means the default 1. */
+	unsigned char fill_mode, stroke_mode, fill_evenodd;
+	unsigned short fill, stroke;
+	unsigned short stroke_w;
+	unsigned char inline_flex;  /* display:inline-flex (not inherited) */
 };
 
+#define BR_PAINT_UNSET   0    /* fill: black, stroke: none */
+#define BR_PAINT_COLOR   1
+#define BR_PAINT_NONE    2
+#define BR_PAINT_CURRENT 3    /* currentColor -> style color */
+#define BR_PAINT_URL     4    /* url(#id): resolved from the attribute */
+
 struct br_node {
 	unsigned char type;
 	unsigned char tag;
@@ -295,6 +309,8 @@ void br_set_viewport(unsigned int width);
 void br_set_theme(unsigned short text, unsigned short bg,
 		  unsigned short panel, unsigned short link);
 void br_parse_css_text(struct br_doc *d, const char *css, unsigned int len);
+/* CSS colour value (names, #hex, rgb()/rgba()) -> RGB565; 1 on success. */
+int  br_parse_color(const char *s, unsigned int len, unsigned short *out);
 void br_parse_inline_css(struct br_doc *d);
 void br_reset_styles(struct br_doc *d);
 

+ 1 - 0
docs/development.html

@@ -185,6 +185,7 @@
 					<tr><td><code>make test-libc</code></td><td>Host tests for the ring-3 malloc, stdio/float formatting, math, 64-bit division helpers and setjmp/longjmp.</td></tr>
 					<tr><td><code>make test-mujs</code></td><td>Host smoke test for the vendored MuJS engine: arithmetic, strings, Math, Date, JSON, exceptions and the run limit.</td></tr>
 					<tr><td><code>make test-font</code> / <code>test-font-asan</code></td><td>Host specimen test for the fixed-point TrueType parser/rasterizer and glyph cache, with an AddressSanitizer/UBSan variant.</td></tr>
+					<tr><td><code>make test-svg</code></td><td>Host tests (ASan/UBSan) for the inline-SVG rasterizer: exact rect coverage, antialiased edges, relative commands, nonzero vs even-odd, circle area, curves and arcs, transforms, number grammar and strokes; <code>./svg_test out.ppm</code> writes a specimen.</td></tr>
 					<tr><td><code>make test-touchpad</code></td><td>Host tests for the device-independent contact gesture engine: taps, right-click zones, physical-button latch, two-finger scroll, direction and pointer re-anchoring.</td></tr>
 					<tr><td><code>make test-chat</code></td><td>Host tests (ASan/UBSan) for the chat client's JSON parser, cookie jar and the OIDC login page/reply/config parsers.</td></tr>
 					<tr><td><code>make test-chat-e2e</code></td><td>Boots QEMU with an NE2000 on slirp, starts <code>tools/mock_chat.py</code> and drives <code>chat</code> through QMP: native login, send, live poll, read marker, older paging, browse/join, new DM, saved-session resume and sign-out.  <code>CHAT_E2E=--totp|--consent|--passkey|--wrong</code> runs a login variant.</td></tr>

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
docs/userland.html


+ 1 - 0
js_browser.c

@@ -2690,6 +2690,7 @@ static const struct computed_prop computed_props[] = {
 	{ "display", "display" }, { "position", "position" },
 	{ "width", "width" }, { "height", "height" },
 	{ "color", "color" }, { "backgroundColor", "background-color" },
+	{ "fill", "fill" }, { "stroke", "stroke" },
 	{ "fontSize", "font-size" }, { "fontWeight", "font-weight" },
 	{ "fontStyle", "font-style" }, { "fontFamily", "font-family" },
 	{ "textAlign", "text-align" }, { "float", "float" },

+ 924 - 0
svg_raster.c

@@ -0,0 +1,924 @@
+/* svg_raster: SVG geometry flattening + antialiased scanline fill.
+ * See svg_raster.h. */
+
+#include "svg_raster.h"
+#include <stdlib.h>
+#include <math.h>
+
+#define SVGR_PI 3.14159265358979323846
+
+/* ---- numbers and transforms ---- */
+
+static int is_ws(char c)
+{
+	return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
+}
+
+static const char *skip_sep(const char *p)
+{
+	while (is_ws(*p) || *p == ',')
+		p++;
+	return p;
+}
+
+double svgr_num(const char **pp, int *ok)
+{
+	const char *p = skip_sep(*pp);
+	double v = 0, scale = 1;
+	int neg = 0, digits = 0;
+
+	if (*p == '-' || *p == '+') {
+		neg = *p == '-';
+		p++;
+	}
+	while (*p >= '0' && *p <= '9') {
+		v = v * 10 + (*p - '0');
+		p++;
+		digits++;
+	}
+	if (*p == '.') {
+		p++;
+		while (*p >= '0' && *p <= '9') {
+			scale /= 10;
+			v += (*p - '0') * scale;
+			p++;
+			digits++;
+		}
+	}
+	if (!digits) {
+		if (ok)
+			*ok = 0;
+		return 0;
+	}
+	if ((*p == 'e' || *p == 'E') &&
+	    ((p[1] >= '0' && p[1] <= '9') ||
+	     ((p[1] == '-' || p[1] == '+') && p[2] >= '0' && p[2] <= '9'))) {
+		int eneg = 0, e = 0;
+
+		p++;
+		if (*p == '-' || *p == '+') {
+			eneg = *p == '-';
+			p++;
+		}
+		while (*p >= '0' && *p <= '9') {
+			if (e < 300)
+				e = e * 10 + (*p - '0');
+			p++;
+		}
+		while (e-- > 0)
+			v = eneg ? v / 10 : v * 10;
+	}
+	*pp = p;
+	if (ok)
+		*ok = 1;
+	return neg ? -v : v;
+}
+
+void svgr_mat_mul(double out[6], const double a[6], const double b[6])
+{
+	double r[6];
+
+	r[0] = a[0] * b[0] + a[2] * b[1];
+	r[1] = a[1] * b[0] + a[3] * b[1];
+	r[2] = a[0] * b[2] + a[2] * b[3];
+	r[3] = a[1] * b[2] + a[3] * b[3];
+	r[4] = a[0] * b[4] + a[2] * b[5] + a[4];
+	r[5] = a[1] * b[4] + a[3] * b[5] + a[5];
+	out[0] = r[0];
+	out[1] = r[1];
+	out[2] = r[2];
+	out[3] = r[3];
+	out[4] = r[4];
+	out[5] = r[5];
+}
+
+static int name_is(const char *p, const char *name, const char **end)
+{
+	while (*name) {
+		char c = *p;
+
+		if (c >= 'A' && c <= 'Z')
+			c = (char)(c - 'A' + 'a');
+		if (c != *name)
+			return 0;
+		p++;
+		name++;
+	}
+	*end = p;
+	return 1;
+}
+
+void svgr_transform(double m[6], const char *s)
+{
+	const char *p = s;
+
+	while (p && *p) {
+		double v[6], t[6] = { 1, 0, 0, 1, 0, 0 };
+		int n = 0, ok = 1, kind;
+		const char *q;
+
+		p = skip_sep(p);
+		if (!*p)
+			break;
+		if (name_is(p, "matrix", &q))
+			kind = 0;
+		else if (name_is(p, "translate", &q))
+			kind = 1;
+		else if (name_is(p, "scale", &q))
+			kind = 2;
+		else if (name_is(p, "rotate", &q))
+			kind = 3;
+		else if (name_is(p, "skewx", &q))
+			kind = 4;
+		else if (name_is(p, "skewy", &q))
+			kind = 5;
+		else
+			return;
+		p = q;
+		while (is_ws(*p))
+			p++;
+		if (*p != '(')
+			return;
+		p++;
+		while (n < 6) {
+			const char *save = p;
+			double x = svgr_num(&p, &ok);
+
+			if (!ok) {
+				p = save;
+				break;
+			}
+			v[n++] = x;
+		}
+		p = skip_sep(p);
+		if (*p != ')')
+			return;
+		p++;
+		switch (kind) {
+		case 0:
+			if (n != 6)
+				return;
+			t[0] = v[0]; t[1] = v[1]; t[2] = v[2];
+			t[3] = v[3]; t[4] = v[4]; t[5] = v[5];
+			break;
+		case 1:
+			if (n < 1)
+				return;
+			t[4] = v[0];
+			t[5] = n > 1 ? v[1] : 0;
+			break;
+		case 2:
+			if (n < 1)
+				return;
+			t[0] = v[0];
+			t[3] = n > 1 ? v[1] : v[0];
+			break;
+		case 3: {
+			double a, c, sn;
+
+			if (n < 1)
+				return;
+			a = v[0] * SVGR_PI / 180.0;
+			c = cos(a);
+			sn = sin(a);
+			t[0] = c; t[1] = sn; t[2] = -sn; t[3] = c;
+			if (n >= 3) {
+				t[4] = v[1] - c * v[1] + sn * v[2];
+				t[5] = v[2] - sn * v[1] - c * v[2];
+			}
+			break;
+		}
+		case 4:
+			if (n < 1)
+				return;
+			t[2] = tan(v[0] * SVGR_PI / 180.0);
+			break;
+		default:
+			if (n < 1)
+				return;
+			t[1] = tan(v[0] * SVGR_PI / 180.0);
+			break;
+		}
+		svgr_mat_mul(m, m, t);
+	}
+}
+
+/* ---- geometry ---- */
+
+void svgr_init(struct svgr *r, void *buf, unsigned int cap)
+{
+	r->pt = (float *)buf;
+	r->fl = (unsigned char *)buf + cap * 2 * sizeof(float);
+	r->cap = cap;
+	r->n = 0;
+	r->overflow = 0;
+	r->m[0] = 1; r->m[1] = 0; r->m[2] = 0;
+	r->m[3] = 1; r->m[4] = 0; r->m[5] = 0;
+	r->open = 0;
+	r->sp = 0;
+	r->last = 0;
+	r->cx = r->cy = r->sx = r->sy = r->lcx = r->lcy = 0;
+}
+
+void svgr_reset(struct svgr *r, const double m[6])
+{
+	unsigned int i;
+
+	r->n = 0;
+	r->overflow = 0;
+	for (i = 0; i < 6; i++)
+		r->m[i] = m[i];
+	r->open = 0;
+	r->sp = 0;
+	r->last = 0;
+	r->cx = r->cy = r->sx = r->sy = r->lcx = r->lcy = 0;
+}
+
+static void add_dev(struct svgr *r, double x, double y, unsigned char fl)
+{
+	if (r->n >= r->cap) {
+		r->overflow = 1;
+		return;
+	}
+	/* Keep coordinates sane: a wild transform must not overflow the
+	 * float -> int conversions in the scanline code. */
+	if (x < -100000)
+		x = -100000;
+	if (x > 100000)
+		x = 100000;
+	if (y < -100000)
+		y = -100000;
+	if (y > 100000)
+		y = 100000;
+	r->pt[2 * r->n] = (float)x;
+	r->pt[2 * r->n + 1] = (float)y;
+	r->fl[r->n] = fl;
+	r->n++;
+}
+
+static void add_user(struct svgr *r, double x, double y, unsigned char fl)
+{
+	const double *m = r->m;
+
+	add_dev(r, m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5], fl);
+}
+
+void svgr_move(struct svgr *r, double x, double y)
+{
+	r->sp = r->n;
+	add_user(r, x, y, SVGR_PT_START);
+	r->open = 1;
+	r->cx = r->sx = x;
+	r->cy = r->sy = y;
+	r->lcx = x;
+	r->lcy = y;
+}
+
+void svgr_line(struct svgr *r, double x, double y)
+{
+	if (!r->open)
+		svgr_move(r, r->cx, r->cy);
+	add_user(r, x, y, 0);
+	r->cx = r->lcx = x;
+	r->cy = r->lcy = y;
+}
+
+/* Device-space length of a control polygon, for the flattening step. */
+static double dev_len(const struct svgr *r, const double *xy, int npts)
+{
+	const double *m = r->m;
+	double len = 0, px = 0, py = 0;
+	int i;
+
+	for (i = 0; i < npts; i++) {
+		double x = m[0] * xy[2 * i] + m[2] * xy[2 * i + 1] + m[4];
+		double y = m[1] * xy[2 * i] + m[3] * xy[2 * i + 1] + m[5];
+
+		if (i)
+			len += sqrt((x - px) * (x - px) + (y - py) * (y - py));
+		px = x;
+		py = y;
+	}
+	return len;
+}
+
+static int seg_count(double len)
+{
+	int n = (int)(len / 3.0) + 1;
+
+	if (n > 64)
+		n = 64;
+	return n;
+}
+
+void svgr_cubic(struct svgr *r, double x1, double y1, double x2, double y2,
+		double x, double y)
+{
+	double xy[8];
+	double x0 = r->cx, y0 = r->cy;
+	int i, n;
+
+	if (!r->open)
+		svgr_move(r, x0, y0);
+	xy[0] = x0; xy[1] = y0; xy[2] = x1; xy[3] = y1;
+	xy[4] = x2; xy[5] = y2; xy[6] = x; xy[7] = y;
+	n = seg_count(dev_len(r, xy, 4));
+	for (i = 1; i <= n; i++) {
+		double t = (double)i / n, u = 1 - t;
+		double a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t,
+		       d = t * t * t;
+
+		add_user(r, a * x0 + b * x1 + c * x2 + d * x,
+			 a * y0 + b * y1 + c * y2 + d * y, 0);
+	}
+	r->cx = x;
+	r->cy = y;
+	r->lcx = x2;
+	r->lcy = y2;
+}
+
+void svgr_quad(struct svgr *r, double x1, double y1, double x, double y)
+{
+	double xy[6];
+	double x0 = r->cx, y0 = r->cy;
+	int i, n;
+
+	if (!r->open)
+		svgr_move(r, x0, y0);
+	xy[0] = x0; xy[1] = y0; xy[2] = x1; xy[3] = y1; xy[4] = x; xy[5] = y;
+	n = seg_count(dev_len(r, xy, 3));
+	for (i = 1; i <= n; i++) {
+		double t = (double)i / n, u = 1 - t;
+
+		add_user(r, u * u * x0 + 2 * u * t * x1 + t * t * x,
+			 u * u * y0 + 2 * u * t * y1 + t * t * y, 0);
+	}
+	r->cx = x;
+	r->cy = y;
+	r->lcx = x1;
+	r->lcy = y1;
+}
+
+static double vec_angle(double ux, double uy, double vx, double vy)
+{
+	return atan2(ux * vy - uy * vx, ux * vx + uy * vy);
+}
+
+/* Endpoint -> center parameterization (SVG 1.1 implementation notes F.6). */
+void svgr_arc(struct svgr *r, double rx, double ry, double rot, int large,
+	      int sweep, double x, double y)
+{
+	double x0 = r->cx, y0 = r->cy;
+	double phi, cp, sp, dx2, dy2, x1p, y1p, lam, sq, num, den, coef;
+	double cxp, cyp, cx, cy, th1, dth, scale;
+	int i, n;
+
+	if (!r->open)
+		svgr_move(r, x0, y0);
+	if (x0 == x && y0 == y)
+		return;
+	rx = fabs(rx);
+	ry = fabs(ry);
+	if (rx == 0 || ry == 0) {
+		svgr_line(r, x, y);
+		return;
+	}
+	phi = rot * SVGR_PI / 180.0;
+	cp = cos(phi);
+	sp = sin(phi);
+	dx2 = (x0 - x) / 2;
+	dy2 = (y0 - y) / 2;
+	x1p = cp * dx2 + sp * dy2;
+	y1p = -sp * dx2 + cp * dy2;
+	lam = (x1p * x1p) / (rx * rx) + (y1p * y1p) / (ry * ry);
+	if (lam > 1) {
+		sq = sqrt(lam);
+		rx *= sq;
+		ry *= sq;
+	}
+	num = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
+	den = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
+	coef = (den > 0 && num > 0) ? sqrt(num / den) : 0;
+	if (large == sweep)
+		coef = -coef;
+	cxp = coef * rx * y1p / ry;
+	cyp = -coef * ry * x1p / rx;
+	cx = cp * cxp - sp * cyp + (x0 + x) / 2;
+	cy = sp * cxp + cp * cyp + (y0 + y) / 2;
+	th1 = vec_angle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
+	dth = vec_angle((x1p - cxp) / rx, (y1p - cyp) / ry,
+			(-x1p - cxp) / rx, (-y1p - cyp) / ry);
+	if (!sweep && dth > 0)
+		dth -= 2 * SVGR_PI;
+	else if (sweep && dth < 0)
+		dth += 2 * SVGR_PI;
+	scale = sqrt(fabs(r->m[0] * r->m[3] - r->m[1] * r->m[2]));
+	n = seg_count(fabs(dth) * (rx > ry ? rx : ry) * scale);
+	if (n < 2)
+		n = 2;
+	for (i = 1; i <= n; i++) {
+		double t = th1 + dth * i / n;
+		double ex = rx * cos(t), ey = ry * sin(t);
+
+		if (i == n)
+			add_user(r, x, y, 0);
+		else
+			add_user(r, cp * ex - sp * ey + cx,
+				 sp * ex + cp * ey + cy, 0);
+	}
+	r->cx = r->lcx = x;
+	r->cy = r->lcy = y;
+}
+
+void svgr_close(struct svgr *r)
+{
+	if (r->open && r->sp < r->n)
+		r->fl[r->sp] |= SVGR_PT_CLOSED;
+	r->open = 0;
+	r->cx = r->lcx = r->sx;
+	r->cy = r->lcy = r->sy;
+}
+
+static const char *read_flag(const char *p, int *flag, int *ok)
+{
+	p = skip_sep(p);
+	if (*p == '0' || *p == '1') {
+		*flag = *p - '0';
+		*ok = 1;
+		return p + 1;
+	}
+	*ok = 0;
+	return p;
+}
+
+int svgr_path(struct svgr *r, const char *d)
+{
+	const char *p = d;
+	char cmd = 0;
+
+	r->last = 0;
+	while (p && *p) {
+		double a[7];
+		int fresh = 0, rel, need, i, ok = 1;
+		char c;
+
+		p = skip_sep(p);
+		if (!*p)
+			break;
+		if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')) {
+			cmd = *p++;
+			fresh = 1;
+		} else if (!cmd) {
+			return -1;
+		}
+		rel = cmd >= 'a' && cmd <= 'z';
+		c = rel ? (char)(cmd - 'a' + 'A') : cmd;
+		if (c == 'Z') {
+			if (!fresh)
+				return -1;
+			svgr_close(r);
+			r->last = 'Z';
+			continue;
+		}
+		switch (c) {
+		case 'M': case 'L': case 'T': need = 2; break;
+		case 'H': case 'V': need = 1; break;
+		case 'C': need = 6; break;
+		case 'S': case 'Q': need = 4; break;
+		case 'A': need = 7; break;
+		default: return -1;
+		}
+		for (i = 0; i < need && ok; i++) {
+			if (c == 'A' && (i == 3 || i == 4)) {
+				int f = 0;
+
+				p = read_flag(p, &f, &ok);
+				a[i] = f;
+			} else {
+				a[i] = svgr_num(&p, &ok);
+			}
+		}
+		if (!ok)
+			return -1;
+		if (rel) {
+			double ox = r->cx, oy = r->cy;
+
+			switch (c) {
+			case 'H': a[0] += ox; break;
+			case 'V': a[0] += oy; break;
+			case 'A': a[5] += ox; a[6] += oy; break;
+			default:
+				for (i = 0; i + 1 < need; i += 2) {
+					a[i] += ox;
+					a[i + 1] += oy;
+				}
+			}
+		}
+		switch (c) {
+		case 'M':
+			if (fresh)
+				svgr_move(r, a[0], a[1]);
+			else
+				svgr_line(r, a[0], a[1]);
+			break;
+		case 'L':
+			svgr_line(r, a[0], a[1]);
+			break;
+		case 'H':
+			svgr_line(r, a[0], r->cy);
+			break;
+		case 'V':
+			svgr_line(r, r->cx, a[0]);
+			break;
+		case 'C':
+			svgr_cubic(r, a[0], a[1], a[2], a[3], a[4], a[5]);
+			break;
+		case 'S': {
+			double x1 = r->cx, y1 = r->cy;
+
+			if (r->last == 'C' || r->last == 'S') {
+				x1 = 2 * r->cx - r->lcx;
+				y1 = 2 * r->cy - r->lcy;
+			}
+			svgr_cubic(r, x1, y1, a[0], a[1], a[2], a[3]);
+			break;
+		}
+		case 'Q':
+			svgr_quad(r, a[0], a[1], a[2], a[3]);
+			break;
+		case 'T': {
+			double x1 = r->cx, y1 = r->cy;
+
+			if (r->last == 'Q' || r->last == 'T') {
+				x1 = 2 * r->cx - r->lcx;
+				y1 = 2 * r->cy - r->lcy;
+			}
+			svgr_quad(r, x1, y1, a[0], a[1]);
+			break;
+		}
+		case 'A':
+			svgr_arc(r, a[0], a[1], a[2], (int)a[3], (int)a[4],
+				 a[5], a[6]);
+			break;
+		}
+		r->last = c;
+		/* Extra coordinate pairs after a moveto are linetos. */
+		if (c == 'M')
+			cmd = rel ? 'l' : 'L';
+	}
+	return 0;
+}
+
+void svgr_rect(struct svgr *r, double x, double y, double w, double h,
+	       double rx, double ry)
+{
+	if (w <= 0 || h <= 0)
+		return;
+	if (rx < 0)
+		rx = 0;
+	if (ry < 0)
+		ry = 0;
+	if (rx > w / 2)
+		rx = w / 2;
+	if (ry > h / 2)
+		ry = h / 2;
+	if (rx == 0 || ry == 0) {
+		svgr_move(r, x, y);
+		svgr_line(r, x + w, y);
+		svgr_line(r, x + w, y + h);
+		svgr_line(r, x, y + h);
+		svgr_close(r);
+		return;
+	}
+	svgr_move(r, x + rx, y);
+	svgr_line(r, x + w - rx, y);
+	svgr_arc(r, rx, ry, 0, 0, 1, x + w, y + ry);
+	svgr_line(r, x + w, y + h - ry);
+	svgr_arc(r, rx, ry, 0, 0, 1, x + w - rx, y + h);
+	svgr_line(r, x + rx, y + h);
+	svgr_arc(r, rx, ry, 0, 0, 1, x, y + h - ry);
+	svgr_line(r, x, y + ry);
+	svgr_arc(r, rx, ry, 0, 0, 1, x + rx, y);
+	svgr_close(r);
+}
+
+void svgr_ellipse(struct svgr *r, double cx, double cy, double rx, double ry)
+{
+	if (rx <= 0 || ry <= 0)
+		return;
+	svgr_move(r, cx + rx, cy);
+	svgr_arc(r, rx, ry, 0, 0, 1, cx - rx, cy);
+	svgr_arc(r, rx, ry, 0, 0, 1, cx + rx, cy);
+	svgr_close(r);
+}
+
+void svgr_points(struct svgr *r, const char *pts, int close)
+{
+	const char *p = pts;
+	int first = 1, ok = 1;
+
+	while (p && *p) {
+		double x = svgr_num(&p, &ok), y;
+
+		if (!ok)
+			break;
+		y = svgr_num(&p, &ok);
+		if (!ok)
+			break;
+		if (first)
+			svgr_move(r, x, y);
+		else
+			svgr_line(r, x, y);
+		first = 0;
+	}
+	if (!first && close)
+		svgr_close(r);
+}
+
+/* ---- scanline fill ---- */
+
+struct edge {
+	float x0, y0, x1, y1;   /* y0 < y1 */
+	float dxdy;
+	int dir;
+	int next;               /* bucket chain */
+};
+
+struct cross {
+	float x;
+	int dir;
+};
+
+static void composite_row(struct svgr_layer *L, int y, const int *cov,
+			  int x0, int x1, unsigned short color,
+			  unsigned int alpha)
+{
+	unsigned int sr = (color >> 11) & 31, sg = (color >> 5) & 63,
+		     sb = color & 31;
+	int x;
+
+	for (x = x0; x <= x1; x++) {
+		int c = cov[x];
+		unsigned int sa, da, oa, idx;
+		unsigned short d;
+
+		if (c <= 0)
+			continue;
+		if (c > 256)
+			c = 256;
+		sa = (unsigned int)c * alpha / 256;
+		if (!sa)
+			continue;
+		idx = (unsigned int)y * (unsigned int)L->w + (unsigned int)x;
+		da = L->a[idx];
+		if (sa >= 255 || !da) {
+			L->px[idx] = color;
+			oa = sa + da * (255 - sa) / 255;
+			L->a[idx] = (unsigned char)(oa > 255 ? 255 : oa);
+			continue;
+		}
+		d = L->px[idx];
+		{
+			unsigned int dw = da * (255 - sa) / 255;
+			unsigned int r5, g6, b5;
+
+			oa = sa + dw;
+			r5 = (sr * sa + ((d >> 11) & 31) * dw) / oa;
+			g6 = (sg * sa + ((d >> 5) & 63) * dw) / oa;
+			b5 = (sb * sa + (d & 31) * dw) / oa;
+			L->px[idx] = (unsigned short)((r5 << 11) | (g6 << 5) |
+						      b5);
+			L->a[idx] = (unsigned char)(oa > 255 ? 255 : oa);
+		}
+	}
+}
+
+static void span_add(int *cov, int w, float xa, float xb, int *minx,
+		     int *maxx)
+{
+	int ia, ib, i;
+
+	if (xa < 0)
+		xa = 0;
+	if (xb > (float)w)
+		xb = (float)w;
+	if (xb <= xa)
+		return;
+	ia = (int)xa;
+	ib = (int)xb;
+	if (ia < *minx)
+		*minx = ia;
+	if ((ib < w ? ib : w - 1) > *maxx)
+		*maxx = ib < w ? ib : w - 1;
+	if (ia == ib) {
+		cov[ia] += (int)(64.0f * (xb - xa) + 0.5f);
+		return;
+	}
+	cov[ia] += (int)(64.0f * ((float)(ia + 1) - xa) + 0.5f);
+	for (i = ia + 1; i < ib; i++)
+		cov[i] += 64;
+	if (ib < w)
+		cov[ib] += (int)(64.0f * (xb - (float)ib) + 0.5f);
+}
+
+void svgr_fill(struct svgr *r, struct svgr_layer *L, unsigned short color,
+	       unsigned int alpha, int evenodd)
+{
+	struct edge *e;
+	struct cross *xs;
+	int *head, *active, *cov;
+	unsigned int i, ne = 0, start = 0;
+	int nact = 0, y, ymin_all = L->h, ymax_all = -1;
+
+	if (r->n < 2 || L->w <= 0 || L->h <= 0 || !alpha)
+		return;
+	e = (struct edge *)malloc((r->n + 1) * sizeof(*e));
+	xs = (struct cross *)malloc((r->n + 1) * sizeof(*xs));
+	head = (int *)malloc((unsigned int)L->h * sizeof(int));
+	active = (int *)malloc((r->n + 1) * sizeof(int));
+	cov = (int *)malloc(((unsigned int)L->w + 1) * sizeof(int));
+	if (!e || !xs || !head || !active || !cov)
+		goto out;
+	for (i = 0; i < (unsigned int)L->h; i++)
+		head[i] = -1;
+	for (i = 0; i <= (unsigned int)L->w; i++)
+		cov[i] = 0;
+
+	/* Edges: consecutive points of each subpath, plus the implicit
+	 * closing edge (fills always close). */
+	for (i = 0; i < r->n; i++) {
+		unsigned int j;
+		float ax, ay, bx, by;
+
+		if (i + 1 < r->n && !(r->fl[i + 1] & SVGR_PT_START))
+			j = i + 1;
+		else
+			j = start;
+		if (i + 1 >= r->n || (r->fl[i + 1] & SVGR_PT_START))
+			start = i + 1;
+		ax = r->pt[2 * i];
+		ay = r->pt[2 * i + 1];
+		bx = r->pt[2 * j];
+		by = r->pt[2 * j + 1];
+		if (ay == by || j == i)
+			continue;
+		if (ay < by) {
+			e[ne].x0 = ax; e[ne].y0 = ay;
+			e[ne].x1 = bx; e[ne].y1 = by;
+			e[ne].dir = 1;
+		} else {
+			e[ne].x0 = bx; e[ne].y0 = by;
+			e[ne].x1 = ax; e[ne].y1 = ay;
+			e[ne].dir = -1;
+		}
+		if (e[ne].y1 <= 0 || e[ne].y0 >= (float)L->h)
+			continue;
+		e[ne].dxdy = (e[ne].x1 - e[ne].x0) / (e[ne].y1 - e[ne].y0);
+		{
+			int row = e[ne].y0 < 0 ? 0 : (int)e[ne].y0;
+			int last = (int)e[ne].y1;
+
+			if (row >= L->h)
+				continue;
+			if (last >= L->h)
+				last = L->h - 1;
+			if (row < ymin_all)
+				ymin_all = row;
+			if (last > ymax_all)
+				ymax_all = last;
+			e[ne].next = head[row];
+			head[row] = (int)ne;
+		}
+		ne++;
+	}
+
+	for (y = ymin_all; y <= ymax_all && y < L->h; y++) {
+		int k, minx = L->w, maxx = -1, a;
+
+		for (a = head[y]; a >= 0; a = e[a].next)
+			active[nact++] = a;
+		/* drop finished edges */
+		for (k = 0; k < nact;) {
+			if (e[active[k]].y1 <= (float)y)
+				active[k] = active[--nact];
+			else
+				k++;
+		}
+		if (!nact)
+			continue;
+		for (k = 0; k < 4; k++) {
+			float sy = (float)y + ((float)k + 0.5f) * 0.25f;
+			int nx = 0, q, wind = 0;
+
+			for (q = 0; q < nact; q++) {
+				struct edge *ed = &e[active[q]];
+				int t;
+				float x;
+
+				if (sy < ed->y0 || sy >= ed->y1)
+					continue;
+				x = ed->x0 + (sy - ed->y0) * ed->dxdy;
+				/* insertion sort by x */
+				t = nx++;
+				while (t > 0 && xs[t - 1].x > x) {
+					xs[t] = xs[t - 1];
+					t--;
+				}
+				xs[t].x = x;
+				xs[t].dir = ed->dir;
+			}
+			for (q = 0; q + 1 < nx; q++) {
+				int inside;
+
+				wind += xs[q].dir;
+				inside = evenodd ? (wind & 1) : wind != 0;
+				if (inside)
+					span_add(cov, L->w, xs[q].x,
+						 xs[q + 1].x, &minx, &maxx);
+			}
+		}
+		if (maxx >= minx) {
+			composite_row(L, y, cov, minx, maxx, color, alpha);
+			for (k = minx; k <= maxx; k++)
+				cov[k] = 0;
+		}
+	}
+out:
+	free(e);
+	free(xs);
+	free(head);
+	free(active);
+	free(cov);
+}
+
+/* Strokes become filled geometry: one quad per segment, all with the same
+ * winding, plus an octagon at each joint, filled with the nonzero rule so
+ * the overlaps union. */
+void svgr_stroke(struct svgr *r, struct svgr_layer *L, double width,
+		 unsigned short color, unsigned int alpha)
+{
+	struct svgr s;
+	unsigned int i, start = 0, cap;
+	double hw = width / 2;
+	void *buf;
+	int joins = width > 1.5;
+
+	if (r->n < 2 || width <= 0)
+		return;
+	if (hw < 0.35)
+		hw = 0.35;
+	cap = r->n * (joins ? 12 : 4) + 16;
+	buf = malloc(cap * (2 * sizeof(float) + 1));
+	if (!buf)
+		return;
+	svgr_init(&s, buf, cap);
+	for (i = 0; i < r->n; i++) {
+		unsigned int j;
+		int closing = 0;
+		double ax, ay, bx, by, dx, dy, len, nx, ny;
+
+		if (r->fl[i] & SVGR_PT_START)
+			start = i;
+		if (i + 1 < r->n && !(r->fl[i + 1] & SVGR_PT_START)) {
+			j = i + 1;
+		} else {
+			if (!(r->fl[start] & SVGR_PT_CLOSED))
+				continue;
+			j = start;
+			closing = 1;
+		}
+		(void)closing;
+		ax = r->pt[2 * i];
+		ay = r->pt[2 * i + 1];
+		bx = r->pt[2 * j];
+		by = r->pt[2 * j + 1];
+		dx = bx - ax;
+		dy = by - ay;
+		len = sqrt(dx * dx + dy * dy);
+		if (len < 1e-6)
+			continue;
+		nx = -dy / len * hw;
+		ny = dx / len * hw;
+		add_dev(&s, ax + nx, ay + ny, SVGR_PT_START);
+		add_dev(&s, bx + nx, by + ny, 0);
+		add_dev(&s, bx - nx, by - ny, 0);
+		add_dev(&s, ax - nx, ay - ny, 0);
+		if (joins) {
+			/* The quad above runs clockwise in device space
+			 * (y down) for every direction; draw the octagon in
+			 * the same sense. */
+			int k;
+			double sgn = (nx * dy - ny * dx) > 0 ? 1 : -1;
+
+			for (k = 0; k < 8; k++) {
+				double ang = sgn * k * SVGR_PI / 4;
+
+				add_dev(&s, bx + hw * cos(ang),
+					by + hw * sin(ang),
+					k ? 0 : SVGR_PT_START);
+			}
+		}
+	}
+	svgr_fill(&s, L, color, alpha, 0);
+	free(buf);
+}

+ 74 - 0
svg_raster.h

@@ -0,0 +1,74 @@
+/* svg_raster: a small freestanding SVG geometry rasterizer.
+ *
+ * Shapes are flattened into device-space polylines (path data with every
+ * SVG command, including curves and elliptical arcs, plus rect/ellipse/
+ * polygon helpers), transformed by an affine matrix, and then filled with
+ * the nonzero or even-odd rule or stroked.  Coverage is antialiased with
+ * four vertical subsamples and exact horizontal span coverage, and is
+ * composited "over" into an RGB565 + 8-bit alpha layer, so a whole <svg>
+ * can be rendered once and blitted on every repaint.
+ *
+ * Nothing here knows about the DOM: browser.c walks the SVG tree, resolves
+ * paint and transforms, and drives this module.  Host test: svg_test.c. */
+#ifndef SVG_RASTER_H
+#define SVG_RASTER_H
+
+struct svgr_layer {
+	unsigned short *px;     /* RGB565, w*h */
+	unsigned char *a;       /* coverage/alpha, w*h */
+	int w, h;
+};
+
+struct svgr {
+	float *pt;              /* x,y pairs in device space */
+	unsigned char *fl;      /* SVGR_PT_* per point */
+	unsigned int n, cap;
+	int overflow;
+	double m[6];            /* user -> device: a b c d e f */
+	/* path state, user space */
+	double cx, cy, sx, sy, lcx, lcy;
+	char last;              /* previous command (upper case) */
+	int open;               /* a subpath is in progress */
+	unsigned int sp;        /* index of the current subpath's first point */
+};
+
+#define SVGR_PT_START  1    /* first point of a subpath */
+#define SVGR_PT_CLOSED 2    /* set on a subpath's first point when closed */
+
+/* buf must hold cap points: cap * (2 * sizeof(float) + 1) bytes. */
+void svgr_init(struct svgr *r, void *buf, unsigned int cap);
+void svgr_reset(struct svgr *r, const double m[6]);
+
+void svgr_move(struct svgr *r, double x, double y);
+void svgr_line(struct svgr *r, double x, double y);
+void svgr_cubic(struct svgr *r, double x1, double y1, double x2, double y2,
+		double x, double y);
+void svgr_quad(struct svgr *r, double x1, double y1, double x, double y);
+void svgr_arc(struct svgr *r, double rx, double ry, double rot, int large,
+	      int sweep, double x, double y);
+void svgr_close(struct svgr *r);
+
+/* Parse SVG path data ("M10 10h5c..."); returns 0, -1 on a parse error
+ * (whatever was valid before the error is kept, as browsers do). */
+int svgr_path(struct svgr *r, const char *d);
+void svgr_rect(struct svgr *r, double x, double y, double w, double h,
+	       double rx, double ry);
+void svgr_ellipse(struct svgr *r, double cx, double cy, double rx, double ry);
+/* "x1,y1 x2,y2 ..."; close != 0 for <polygon>. */
+void svgr_points(struct svgr *r, const char *pts, int close);
+
+/* Composite the current geometry into the layer. alpha 0..255. */
+void svgr_fill(struct svgr *r, struct svgr_layer *L, unsigned short color,
+	       unsigned int alpha, int evenodd);
+/* width is in device pixels. */
+void svgr_stroke(struct svgr *r, struct svgr_layer *L, double width,
+		 unsigned short color, unsigned int alpha);
+
+/* Number/transform helpers shared with the DOM side. */
+double svgr_num(const char **pp, int *ok);
+/* Multiply: out = a * b (apply b first, then a). */
+void svgr_mat_mul(double out[6], const double a[6], const double b[6]);
+/* Parse a transform list and post-multiply it onto m. */
+void svgr_transform(double m[6], const char *s);
+
+#endif

+ 176 - 0
svg_test.c

@@ -0,0 +1,176 @@
+/* Host test for svg_raster.c: coverage of basic shapes, fill rules, path
+ * commands, transforms and strokes.  `./svg_test out.ppm` also writes a
+ * specimen image. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "svg_raster.h"
+
+#define W 160
+#define H 120
+
+static unsigned short px[W * H];
+static unsigned char al[W * H];
+static struct svgr_layer L = { px, al, W, H };
+static unsigned char ptbuf[8192 * 9];
+static struct svgr R;
+static int fails;
+
+static void clear(void)
+{
+	memset(px, 0, sizeof(px));
+	memset(al, 0, sizeof(al));
+}
+
+static const double ident[6] = { 1, 0, 0, 1, 0, 0 };
+
+static void check(const char *what, int cond)
+{
+	if (!cond) {
+		printf("FAIL %s\n", what);
+		fails++;
+	}
+}
+
+static unsigned int sum_alpha(void)
+{
+	unsigned int i, s = 0;
+
+	for (i = 0; i < W * H; i++)
+		s += al[i];
+	return s;
+}
+
+static void path_fill(const char *d, const double m[6], int evenodd)
+{
+	svgr_reset(&R, m);
+	svgr_path(&R, d);
+	svgr_fill(&R, &L, 0xFFFF, 255, evenodd);
+}
+
+int main(int argc, char **argv)
+{
+	double m[6];
+	unsigned int s;
+
+	svgr_init(&R, ptbuf, 8192);
+
+	/* axis-aligned rect: exact coverage */
+	clear();
+	path_fill("M10 10 H30 V20 H10 Z", ident, 0);
+	check("rect inside", al[15 * W + 15] == 255);
+	check("rect outside", al[5 * W + 5] == 0 && al[15 * W + 30] == 0);
+	s = sum_alpha();
+	check("rect area", s > 200 * 250 && s <= 200 * 255);
+
+	/* half-pixel edge antialiasing */
+	clear();
+	path_fill("M10.5 10 L20 10 L20 20 L10.5 20 Z", ident, 0);
+	check("half pixel", al[15 * W + 10] > 100 && al[15 * W + 10] < 160);
+
+	/* relative commands, implicit lineto after m, and h/v */
+	clear();
+	path_fill("m10 10 20 0 0 10 h-20z", ident, 0);
+	check("relative", al[15 * W + 15] == 255 && al[15 * W + 31] == 0);
+
+	/* nonzero vs even-odd: two nested squares, same direction */
+	clear();
+	path_fill("M0 0H40V40H0Z M10 10H30V30H10Z", ident, 0);
+	check("nonzero hole filled", al[20 * W + 20] == 255);
+	clear();
+	path_fill("M0 0H40V40H0Z M10 10H30V30H10Z", ident, 1);
+	check("evenodd hole", al[20 * W + 20] == 0 && al[5 * W + 5] == 255);
+
+	/* circle via arcs: area ~ pi r^2 */
+	clear();
+	svgr_reset(&R, ident);
+	svgr_ellipse(&R, 50, 50, 20, 20);
+	svgr_fill(&R, &L, 0xFFFF, 255, 0);
+	s = sum_alpha() / 255;
+	check("circle area", s > 1220 && s < 1290);
+	check("circle centre", al[50 * W + 50] == 255);
+
+	/* cubic + smooth cubic + quadratic + arc in one path */
+	clear();
+	path_fill("M10 60 C10 20 50 20 50 60 S90 100 90 60 Q120 20 150 60 "
+		  "A20 20 0 0 1 110 60 Z", ident, 0);
+	check("curves drew", sum_alpha() > 255 * 500);
+
+	/* transform: scale(2) translate(5,5) of a 10x10 square */
+	clear();
+	memcpy(m, ident, sizeof(m));
+	svgr_transform(m, "scale(2) translate(5 5)");
+	path_fill("M0 0h10v10h-10z", m, 0);
+	check("transform", al[15 * W + 15] == 255 && al[31 * W + 31] == 0 &&
+	      al[9 * W + 9] == 0);
+	memcpy(m, ident, sizeof(m));
+	svgr_transform(m, "rotate(90 20 20)");
+	check("rotate about point", (int)(m[4] + 0.5) == 40 &&
+	      (int)(m[5] + 0.5) == 0);
+
+	/* number grammar: ".5.5", exponents, negative separators */
+	{
+		const char *p = ".5.5-1e1";
+		int ok;
+		double a = svgr_num(&p, &ok), b = svgr_num(&p, &ok),
+		       c = svgr_num(&p, &ok);
+
+		check("numbers", a == 0.5 && b == 0.5 && c == -10 && ok);
+	}
+
+	/* stroke: a 4px horizontal line */
+	clear();
+	svgr_reset(&R, ident);
+	svgr_move(&R, 10, 50);
+	svgr_line(&R, 60, 50);
+	svgr_stroke(&R, &L, 4, 0xFFFF, 255);
+	check("stroke body", al[49 * W + 30] == 255 && al[51 * W + 30] == 255);
+	check("stroke edge", al[45 * W + 30] == 0);
+
+	/* the tagesschau burger (cubic caps, s commands, implicit repeats) */
+	clear();
+	memcpy(m, ident, sizeof(m));
+	m[0] = m[3] = 3;
+	path_fill("M1.5,9.02h32c0.83,0,1.5-0.67,1.5-1.5s-0.67-1.5-1.5-1.5h-32"
+		  "C0.67,6.02,0,6.69,0,7.52S0.67,9.02,1.5,9.02z", m, 0);
+	check("burger bar", al[22 * W + 50] == 255 && al[30 * W + 50] == 0);
+
+	if (argc > 1) {
+		FILE *f = fopen(argv[1], "wb");
+		int i;
+
+		clear();
+		memcpy(m, ident, sizeof(m));
+		m[0] = m[3] = 0.22;
+		m[4] = 2;
+		m[5] = 20;
+		path_fill("M101.9,71.9c0,11-7.6,22.3-19,22.3c-6.5,0-10.7-3.8-10.7-9.7"
+			  "c0-6.3,5.4-13.8,29.8-13.8v1.2H101.9z M114.9,102.9c-0.1-6.1-0.3-13.5-0.3-20.2"
+			  "V54.8c0-14-5.8-23.4-26-23.4c-9.3,0-17.8,2.3-24.5,5.1l1.3,10.9"
+			  "c6.1-3.7,14.5-5.8,21.2-5.8c11.6,0,15.4,5.2,15.4,15v5.2"
+			  "c-26.5,0-42.2,9.7-42.2,25.1c0,11.1,7.9,17.4,19.5,17.4"
+			  "s20.5-6.6,23.8-15.2c-0.4,4-0.4,9-0.4,14h12.2V102.9z", m, 0);
+		svgr_reset(&R, ident);
+		svgr_ellipse(&R, 110, 60, 30, 20);
+		svgr_fill(&R, &L, 0x001F, 200, 0);
+		svgr_reset(&R, ident);
+		svgr_move(&R, 60, 100);
+		svgr_line(&R, 150, 80);
+		svgr_line(&R, 150, 110);
+		svgr_stroke(&R, &L, 3, 0xF800, 255);
+		fprintf(f, "P6\n%d %d\n255\n", W, H);
+		for (i = 0; i < W * H; i++) {
+			unsigned int a = al[i], c = px[i];
+			unsigned int r = ((c >> 11) & 31) * 255 / 31,
+				     g = ((c >> 5) & 63) * 255 / 63,
+				     b = (c & 31) * 255 / 31;
+
+			fputc((int)(r * a / 255), f);
+			fputc((int)(g * a / 255), f);
+			fputc((int)(b * a / 255), f);
+		}
+		fclose(f);
+	}
+	printf("%s (%d failures)\n", fails ? "FAIL" : "ok", fails);
+	return fails ? 1 : 0;
+}

+ 6 - 3
testdata/browser/compat/058-svg-viewbox-fill.html

@@ -27,19 +27,22 @@
     <rect id="rect2" width="100%" height="100%" fill="#B00020"></rect>
   </svg>
 </div>
+<p><span id="c1" style="color:#005AB4">blue</span>
+   <span id="c2" style="color:#B00020">red</span></p>
 <div id="result">checking...</div>
 <script>
 setTimeout(function () {
   function R(id) { return document.getElementById(id).getBoundingClientRect(); }
-  function B(id) { return getComputedStyle(document.getElementById(id)).backgroundColor; }
+  /* SVG paint is `fill`, never the element's background. */
+  function B(id) { return getComputedStyle(document.getElementById(id)).fill; }
   var s1 = R('svg1'), s2 = R('svg2');
   var r1 = B('rect1'), r2 = B('rect2');
   var ok = Math.abs(s1.width - 60) <= 2 &&
            Math.abs(s1.height - 60) <= 2 &&
            Math.abs(s2.width - 150) <= 2 &&
            Math.abs(s2.height - 30) <= 2 &&
-           r1 === 'rgb(0, 90, 189)' &&
-           r2 === 'rgb(176, 0, 32)';
+           r1 === getComputedStyle(document.getElementById('c1')).color &&
+           r2 === getComputedStyle(document.getElementById('c2')).color;
 
   var r = document.getElementById('result');
   if (r) {

+ 64 - 0
testdata/browser/compat/067-svg-geometry.html

@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>067 SVG geometry and paint</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  .pane { float: left; width: 200px; height: 140px; margin-right: 20px;
+          background: #eeeeee; }
+  .icon { fill: currentColor; color: #008000; }
+  #result { clear: both; background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>067 &mdash; SVG geometry and paint</h1>
+<p>Filled curves, arcs, circles, groups with transforms, &lt;use&gt; of a
+   symbol, fill-rule, strokes and gradient paint.  Expected: a blue disc, a
+   red ring with a hole, a green chevron, a black stroked zigzag and a
+   mid-blue square (the average of its gradient stops).</p>
+
+<div class="pane">
+  <svg width="200" height="140" viewBox="0 0 200 140">
+    <defs>
+      <linearGradient id="g1"><stop offset="0" stop-color="#0000ff"/>
+        <stop offset="1" style="stop-color:#000080"/></linearGradient>
+      <symbol id="chev" viewBox="0 0 24 24">
+        <path d="M9 5l7 7-7 7-1.4-1.4L13.2 12 7.6 6.4z"/>
+      </symbol>
+    </defs>
+    <circle id="disc" cx="35" cy="35" r="25" fill="#2040c0"/>
+    <g fill="#c02020" transform="translate(100 35)">
+      <path id="ring" fill-rule="evenodd"
+            d="M0-25a25 25 0 1 1 0 50a25 25 0 1 1 0-50zM0-12a12 12 0 1 0 0 24a12 12 0 1 0 0-24z"/>
+    </g>
+    <use class="icon" href="#chev" x="140" y="10" width="50" height="50"/>
+    <polyline id="zig" points="10,120 40,80 70,120 100,80" fill="none"
+              stroke="#000000" stroke-width="4"/>
+    <rect id="grad" x="130" y="80" width="50" height="50" fill="url(#g1)"/>
+  </svg>
+</div>
+<p><span id="c1" style="color:#2040c0">blue</span>
+   <span id="c2" style="color:#c02020">red</span></p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function F(id, p) { return getComputedStyle(document.getElementById(id))[p]; }
+  var disc = F('disc', 'fill'), ring = F('ring', 'fill'),
+      zig = F('zig', 'fill'), zs = F('zig', 'stroke'),
+      bg = F('disc', 'backgroundColor');
+  var ok = disc === F('c1', 'color') && ring === F('c2', 'color') &&
+           zig === 'none' && zs === 'rgb(0, 0, 0)' &&
+           bg === 'rgba(0, 0, 0, 0)';
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'SVGPAINT-OK ' : 'SVGPAINT-FAIL ') + disc + ' ' +
+                    ring + ' ' + zig + '/' + zs + ' bg=' + bg;
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 39 - 0
testdata/browser/compat/068-rem-line-height.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>068 rem line-height</title>
+<style>
+  html { font-size: 62.5%; }
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  #a { font-size: 1.8rem; line-height: 2.4rem; margin: 0;
+       background: #e0e0ff; }
+  #b { font-size: 18px; line-height: 24px; margin: 8px 0 0 0;
+       background: #e0ffe0; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>068 &mdash; rem line-height</h1>
+<p>With a 10px root, <code>line-height: 2.4rem</code> is 24px, not a 2.4&times;
+   multiplier.  Both blocks must be the same height.</p>
+<p id="a">one<br>two<br>three</p>
+<p id="b">one<br>two<br>three</p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var a = R('a'), b = R('b');
+  var ok = Math.abs(a.height - b.height) <= 2 && a.height < 100;
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'REMLH-OK ' : 'REMLH-FAIL ') + 'a=' +
+                    Math.round(a.height) + ' b=' + Math.round(b.height);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 39 - 0
testdata/browser/compat/069-inline-flex-tail.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>069 inline-flex tail</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  p { width: 600px; line-height: 24px; margin: 0 0 8px 0; }
+  #a { background: #e0e0ff; }
+  #b { background: #e0ffe0; }
+  .more { display: inline-flex; align-items: center; font-weight: bold;
+          color: #0050a0; }
+  #result { background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>069 &mdash; inline-flex tail</h1>
+<p>An <code>inline-flex</code> span with only text continues the line, like
+   an inline-block (news teasers end their text with one).</p>
+<p id="a">Short teaser text. <span class="more">more</span></p>
+<p id="b">Short teaser text. <b style="color:#0050a0">more</b></p>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(id) { return document.getElementById(id).getBoundingClientRect(); }
+  var a = R('a'), b = R('b');
+  var ok = Math.abs(a.height - b.height) <= 2 && a.height < 40;
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
+    r.textContent = (ok ? 'INLFLEX-OK ' : 'INLFLEX-FAIL ') + 'a=' +
+                    Math.round(a.height) + ' b=' + Math.round(b.height);
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 70 - 0
testdata/browser/compat/070-many-absolute.html

@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<title>070 many absolute boxes</title>
+<style>
+  body { background: #ffffff; color: #202020; font-family: sans-serif;
+         margin: 12px; font-size: 18px; }
+  .box { position: relative; float: left; width: 60px; height: 0;
+         padding-top: 40px; margin: 0 8px 8px 0; background: #eeeeee; }
+  .abs { position: absolute; top: 0; left: 0; width: 100%; height: 40px;
+         background: #2060c0; }
+  #result { clear: both; background: #ffc8c8; color: #000000; padding: 8px;
+            margin-top: 12px; }
+</style>
+</head>
+<body>
+<h1>070 &mdash; many absolute boxes</h1>
+<p>Thirty padding-top aspect boxes, each covered by an absolutely positioned
+   child at <code>top: 0</code>.  Every box must be solid blue (news front
+   pages have one such poster per teaser).</p>
+<div class="box"><div class="abs" id="a0"></div></div>
+<div class="box"><div class="abs" id="a1"></div></div>
+<div class="box"><div class="abs" id="a2"></div></div>
+<div class="box"><div class="abs" id="a3"></div></div>
+<div class="box"><div class="abs" id="a4"></div></div>
+<div class="box"><div class="abs" id="a5"></div></div>
+<div class="box"><div class="abs" id="a6"></div></div>
+<div class="box"><div class="abs" id="a7"></div></div>
+<div class="box"><div class="abs" id="a8"></div></div>
+<div class="box"><div class="abs" id="a9"></div></div>
+<div class="box"><div class="abs" id="a10"></div></div>
+<div class="box"><div class="abs" id="a11"></div></div>
+<div class="box"><div class="abs" id="a12"></div></div>
+<div class="box"><div class="abs" id="a13"></div></div>
+<div class="box"><div class="abs" id="a14"></div></div>
+<div class="box"><div class="abs" id="a15"></div></div>
+<div class="box"><div class="abs" id="a16"></div></div>
+<div class="box"><div class="abs" id="a17"></div></div>
+<div class="box"><div class="abs" id="a18"></div></div>
+<div class="box"><div class="abs" id="a19"></div></div>
+<div class="box"><div class="abs" id="a20"></div></div>
+<div class="box"><div class="abs" id="a21"></div></div>
+<div class="box"><div class="abs" id="a22"></div></div>
+<div class="box"><div class="abs" id="a23"></div></div>
+<div class="box"><div class="abs" id="a24"></div></div>
+<div class="box"><div class="abs" id="a25"></div></div>
+<div class="box"><div class="abs" id="a26"></div></div>
+<div class="box"><div class="abs" id="a27"></div></div>
+<div class="box"><div class="abs" id="a28"></div></div>
+<div class="box"><div class="abs" id="a29"></div></div>
+<div id="result">checking...</div>
+<script>
+setTimeout(function () {
+  function R(el) { return el.getBoundingClientRect(); }
+  var bad = 0, i;
+  for (i = 0; i < 30; i++) {
+    var a = document.getElementById('a' + i);
+    if (Math.abs(R(a).top - R(a.parentNode).top) > 2)
+      bad++;
+  }
+  var r = document.getElementById('result');
+  if (r) {
+    r.style.background = bad ? '#ffc8c8' : '#c8f0c8';
+    r.textContent = (bad ? 'ABS30-FAIL ' : 'ABS30-OK ') + bad + ' misplaced';
+  }
+}, 300);
+</script>
+</body>
+</html>

+ 1 - 1
testdata/browser/compat/README

@@ -17,7 +17,7 @@ Serve this directory from the host and open it on the board:
   browser http://<host>:8000/            # board
   browser http://10.0.2.2:8000/         # QEMU with -netdev user
 
-Status: 010-066 and 030a pass.  036a needs the POST echo server:
+Status: 010-070 and 030a pass.  036a needs the POST echo server:
 
   python3 testdata/browser/compat/post_server.py
   browser /floppy1/036a.htm      # action is http://10.0.2.2:8765/echo

+ 4 - 0
testdata/browser/compat/index.html

@@ -89,6 +89,10 @@ a { color: #0645ad; }
 <tr><td>064</td><td><a href="064-structural-pseudo.html">structural pseudo-classes</a></td><td>first-child drops margins/padding; first/last-of-type</td><td class="pass">PASS</td></tr>
 <tr><td>065</td><td><a href="065-transparent-border.html">transparent borders</a></td><td>a transparent border keeps its width but paints nothing</td><td class="pass">PASS</td></tr>
 <tr><td>066</td><td><a href="066-deep-nesting.html">deep nesting</a></td><td>text 16 containers deep is still laid out</td><td class="pass">PASS</td></tr>
+<tr><td>067</td><td><a href="067-svg-geometry.html">SVG geometry and paint</a></td><td>curves, arcs, circle, g transform, use/symbol, fill-rule, stroke, gradient paint</td><td class="pass">PASS</td></tr>
+<tr><td>068</td><td><a href="068-rem-line-height.html">rem line-height</a></td><td>line-height in rem is a length, not a multiplier</td><td class="pass">PASS</td></tr>
+<tr><td>069</td><td><a href="069-inline-flex-tail.html">inline-flex tail</a></td><td>inline-flex around text stays in the line</td><td class="pass">PASS</td></tr>
+<tr><td>070</td><td><a href="070-many-absolute.html">many absolute boxes</a></td><td>more than 16 absolute boxes keep their containing block</td><td class="pass">PASS</td></tr>
 </table>
 </body>
 </html>

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است