Skip to content

armgit / raea

Public Imported from GitHub
0

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.

An SVG shape whose style attribute holds transforms alone is turned by them

James Dimachkieeb3c8ea6bf6a
diff --git a/bench/svg-css-transform/check.sh b/bench/svg-css-transform/check.sh
index 26c1ee55..a268e0cc 100755
--- a/bench/svg-css-transform/check.sh
+++ b/bench/svg-css-transform/check.sh
@@ -4,7 +4,10 @@
# transform-origin over the transform raea had computed from the cascade (`rotate(30deg)`, which SVG's syntax can't
# read: the shape drew unturned). sheet.tsx's class-turned square (red) must be the inline-turned one (green) moved
# 600 px (each recoloured black, so only its shape counts), and mixed.tsx's class box and origin with an inline turn
-# must be the all-inline square. Before: 8827 and 5598 px differed. Exits 1 on a failure.
+# 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.
# bench/svg-css-transform/check.sh (RAEA_BIN: the raea to run, default target/release/raea)
cd "$(dirname "$0")/../.." || exit 2
BIN=${RAEA_BIN:-$PWD/target/release/raea}
@@ -23,5 +26,14 @@ same() { # PNG LEFT-COLOUR RIGHT-COLOUR MAX WHAT
}
same "$OUT/sheet/frame-00000.png" "#e0245e" "#17bf63" 300 "a class's transform, box and origin turn it as inline ones do"
same "$OUT/mixed/frame-00000.png" "#000000" "#000000" 50 "a class's box and origin with an inline turn"
+at() { # PAGE X,Y COLOUR WHAT: the page's pixel there
+ local c; c=$(magick "$OUT/$1/frame-00000.png" -alpha off -format "%[hex:p{$2}]" info:)
+ [ "$c" = "$3" ] && echo "ok $4" || { echo "FAIL $4: #$c at $2, wanted #$3"; status=1; }
+}
+# a 200 px square turned 30deg about its middle: its top edge passes 15 px above the middle of its unturned one
+at mixed 150,34 000000 "the square turned by a style attribute of a transform alone: its turned top edge"
+at 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"
[ $status = 0 ] && echo "PASS SVG transforms from a stylesheet"
exit $status
diff --git a/vendor/blitz-dom/src/node/serialize.rs b/vendor/blitz-dom/src/node/serialize.rs
index b9f8ebf2..df22c952 100644
--- a/vendor/blitz-dom/src/node/serialize.rs
+++ b/vendor/blitz-dom/src/node/serialize.rs
@@ -468,6 +468,7 @@ impl Node {
writer.push(' ');
write_attr_name(&attr.name, writer);
writer.push_str("=\"");
+ let value_at = writer.len();
// raea: an svg's attribute that names var() or a colour usvg can't read, as Chrome resolves it
let resolved = opts
.resolve_current_color
@@ -495,7 +496,17 @@ impl Node {
encode_quoted_attribute_to_string(&attr.value, writer);
}
if !css_paint.is_empty() && attr.name.ns == ns!() && &*attr.name.local == "style" {
- encode_quoted_attribute_to_string(&format!(";{css_paint}"), writer);
+ // raea: after the element's own declarations when any are left, which start at the first
+ // of them. A style attribute of transforms alone is empty by now, and a `;` before the
+ // first declaration stops usvg's parser (simplecss) there: the element lost its transform
+ // and its CSS paint, so `style="transform: rotate(30deg)"` drew unturned
+ let own = from_first_declaration(&writer[value_at..]).to_string();
+ writer.truncate(value_at);
+ if !own.is_empty() {
+ writer.push_str(&own);
+ writer.push(';');
+ }
+ encode_quoted_attribute_to_string(&css_paint, writer);
}
writer.push('"');
}
@@ -555,6 +566,16 @@ fn without_transform_decls(style: &str) -> String {
.join(";")
}
+/// raea: a style attribute from its first declaration on: without the separators, spaces and comments before it,
+/// which CSS allows there and simplecss doesn't (a comment left open runs to the end, as in CSS: nothing is left)
+fn from_first_declaration(mut style: &str) -> &str {
+ loop {
+ style = style.trim_start_matches(|c: char| c == ';' || c.is_whitespace());
+ let Some(comment) = style.strip_prefix("/*") else { return style };
+ style = comment.split_once("*/").map_or("", |(_, rest)| rest);
+ }
+}
+
/// raea: a CSS colour (any syntax stylo parses) as sRGB `rgba()`, the form usvg reads; None when `value` isn't one.
fn css_color_rgba(value: &str) -> Option<String> {
use style::parser::{Parse, ParserContext};
diff --git a/vendor/vendor.toml b/vendor/vendor.toml
index ac84fa75..c0939fc0 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)"
+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"
exit = "a Blitz release with #1244/#1246 and these"
[parley_engine]