Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
An SVG element's transform under a viewBox that doesn't start at 0 0 lands where Chrome puts it
James Dimachkiec6f4c9132d06
diff --git a/bench/svg-css-transform/check.sh b/bench/svg-css-transform/check.shindex a268e0cc..796bdb50 100755--- a/bench/svg-css-transform/check.sh+++ b/bench/svg-css-transform/check.sh@@ -7,7 +7,10 @@# must be the all-inline square. Before: 8827 and 5598 px differed. Two squares drawn the same can both be wrong, and# mixed.tsx's were: a style attribute holding transforms alone was written back for usvg as `;transform:matrix(...)`,# and usvg's declaration parser stops at a leading `;`, so both drew unturned and the comparison passed. Each is now-# probed on its turned top edge as well, and where its unturned edge would be. Exits 1 on a failure.+# probed on its turned top edge as well, and where its unturned edge would be. And viewbox.tsx's three shapes,+# turned or scaled under a viewBox that doesn't start at 0 0, must be where Chrome 157 draws them: transform-box:+# view-box's reference box is at the origin of user space, and raea put it at the viewBox's x and y, which moved+# every origin by them. Exits 1 on a failure.# bench/svg-css-transform/check.sh (RAEA_BIN: the raea to run, default target/release/raea)cd "$(dirname "$0")/../.." || exit 2BIN=${RAEA_BIN:-$PWD/target/release/raea}@@ -15,7 +18,7 @@ export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-svg-css-transform.XXXXXX")trap 'rm -rf "$OUT"' EXITstatus=0-for c in sheet mixed; do+for c in sheet mixed viewbox; do"$BIN" render bench/svg-css-transform/$c.tsx --at 0 -o "$OUT/$c" > "$OUT/$c.log" 2>&1 && [ -f "$OUT/$c/frame-00000.png" ] || { echo "FAIL $c: the render failed"; sed 's/^/ /' "$OUT/$c.log" | tail -4; exit 1; }donesame() { # PNG LEFT-COLOUR RIGHT-COLOUR MAX WHAT@@ -35,5 +38,9 @@ at mixed 150,34 000000 "the square turned by a style attribute of a transform alat mixed 150,50 FFFFFF "and nothing where its unturned edge was"at mixed 750,34 000000 "the all-inline square: its turned top edge"at mixed 750,50 FFFFFF "and nothing where its unturned edge was"+at viewbox 160,110 000000 "scale(2) under an offset viewBox scales about user 0 0"+at viewbox 30,30 FFFFFF "and not about the viewBox's corner"+at viewbox 80,180 008000 "a 50% 50% origin is the middle of a box at user 0 0"+at viewbox 85,110 FF0000 "a nested svg's viewBox, the same"[ $status = 0 ] && echo "PASS SVG transforms from a stylesheet"exit $statusdiff --git a/bench/svg-css-transform/viewbox.tsx b/bench/svg-css-transform/viewbox.tsxnew file mode 100644index 00000000..2a7fbc96--- /dev/null+++ b/bench/svg-css-transform/viewbox.tsx@@ -0,0 +1,19 @@+// transform-box: view-box (an SVG element's default) under a viewBox that doesn't start at 0 0: the reference box is the+// viewBox's size at the origin of user space, so a 0 0 origin is user 0 0 and 50% 50% is half the viewBox's size.+// Chrome 157 draws the black square at 100,50 to 220,170, the green at 60,160 to 100,200 and the red at 70,90 to+// 110,130. bench/svg-css-transform/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+function O() {+ return (+ <AbsoluteFill style={{ background: "#fff" }}>+ <svg width={300} height={300} viewBox="100 50 300 300" style={{ position: "absolute", left: 0, top: 0 }}>+ <rect x={100} y={50} width={40} height={40} fill="#008000" style={{ transformOrigin: "50% 50%", transform: "rotate(180deg)" }} />+ <g transform="scale(2)"><rect x={100} y={50} width={60} height={60} fill="#000" /></g>+ <svg x={150} y={100} width={100} height={100} viewBox="10 20 50 50">+ <rect x={10} y={20} width={10} height={10} fill="#f00" transform="scale(2)" />+ </svg>+ </svg>+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="o" component={O} width={300} height={300} fps={30} durationInFrames={1} />);diff --git a/vendor/blitz-dom/src/node/serialize.rs b/vendor/blitz-dom/src/node/serialize.rsindex df22c952..ec94e2fc 100644--- a/vendor/blitz-dom/src/node/serialize.rs+++ b/vendor/blitz-dom/src/node/serialize.rs@@ -247,7 +247,10 @@ impl Node {Some(format!("matrix({a} {b} {c} {d} {e} {f})"))}- /// The nearest svg viewport's box in this element's user space: its `viewBox`, or its size.+ /// The nearest svg viewport's reference box in this element's user space: the `viewBox`'s size (or the viewport's)+ /// at the origin of user space, where css-transforms-1 #transform-box puts it. A viewBox's x and y move the+ /// content, not the box: placed at them, the box moved a 0 0 origin there, and `scale(2)` under+ /// `viewBox="100 50 400 300"` drew its content 100 px left of and 50 px above where Chrome draws it.#[cfg(feature = "svg")]fn svg_view_box(&self) -> kurbo::Rect {let mut at = self.parent;@@ -256,7 +259,7 @@ impl Node {let Some(el) = node.element_data() else { break };if el.name.ns == ns!(svg) && &*el.name.local == "svg" {if let Some(vb) = el.attr(local_name!("viewBox")).and_then(|v| v.parse::<svgtypes::ViewBox>().ok()) {- return kurbo::Rect::new(vb.x, vb.y, vb.x + vb.w, vb.y + vb.h);+ return kurbo::Rect::new(0.0, 0.0, vb.w, vb.h);}let outer = node.parent.and_then(|p| self.tree()[p].element_data()).is_none_or(|p| p.name.ns != ns!(svg));if outer {diff --git a/vendor/vendor.toml b/vendor/vendor.tomlindex c0939fc0..e58b55e7 100644--- a/vendor/vendor.toml+++ b/vendor/vendor.toml@@ -70,7 +70,7 @@ exit = "a Blitz release that draws these"path = "vendor/blitz-dom"upstream = "crates.io:0.3.0-beta.4"kind = "patch"-reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in "raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39); an SVG's paint properties from CSS written into its serialized source for usvg (raea #45); transform-box: stroke-box as fill-box under non-scaling-stroke, a stylesheet's stroke in the stroke box, and the non-scaling mark on an element with its own id (raea #50); an SVG element's rewritten style attribute without a leading `;` when its own declarations were transforms alone"+reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in "raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39); an SVG's paint properties from CSS written into its serialized source for usvg (raea #45); transform-box: stroke-box as fill-box under non-scaling-stroke, a stylesheet's stroke in the stroke box, and the non-scaling mark on an element with its own id (raea #50); an SVG element's rewritten style attribute without a leading `;` when its own declarations were transforms alone; transform-box: view-box's reference box at the origin of user space, not at the viewBox's x and y"exit = "a Blitz release with #1244/#1246 and these"[parley_engine]