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.

LR10: a Google family from raea/text's loadFont is fetched when loadFont is called, and a canvas's measureText and svg text have it. The page fetched it at the first layout that named it, after a component's first effect had measured (its canvas found the fallback), and a family the page fetched first was cached without ever reaching usvg's font database, so document.fonts.load found it already known and gave the canvas nothing. Figtree's "scene" at 600 64px measured 145.72 (the fallback) against Chrome's 171.25; now 171.26. blitz-dom leaves out an app-bundled svg face of a family the page already gave (Geist fetched at import came before the bundled Geist, and both stayed; tested). snapcn 17 -> 18 of 33: bloom-lockup passes (40.8 px off before), word-gather 25.5 -> 1.2; P26 unchanged (185 of 215, every frame at the same SSIM)

shinyobjectz6abeb6ed4315
diff --git a/docs/layout-reads.feature b/docs/layout-reads.feature
index 58ca31a3..39647363 100644
--- a/docs/layout-reads.feature
+++ b/docs/layout-reads.feature
@@ -322,7 +322,7 @@ Feature: Layout reads: a composition measures its text and layout as Chrome does
And a composition that measures every frame (karaoke-captions, 300 frames) has its cost per read and per frame
measured and written here
And sdk/raea/conformance covers the JS side, and Rust tests cover the call, the wait and the hang guard
- And 11-12, in progress (snapcn: 3 of 33 before LR work, 7 after LR1-LR9, 12 after the usvg and font fixes, 17 now):
+ And 11-12, in progress (snapcn: 3 of 33 before LR work, 7 after LR1-LR9, 12 after the usvg and font fixes, 17 with kerning and the manifest, 18 now):
- Kerning across spans. blitz-dom gave every composition span a border edge: with `border-style: none` (the
initial style) a border's computed width is still `medium`, and inline_edges read the width alone, so each
plain span got a zero-width spacer box at both ends and parley split its shaping there. "AVAWATAVAWAT" in a
@@ -341,9 +341,15 @@ Feature: Layout reads: a composition measures its text and layout as Chrome does
size), as Chrome's canvas takes them: fontdb knew neither, so a list headed by them was measured in
Helvetica, about 10% wider at 72px. text-build, which places its words from measureText, went from 9 px off
to 1.3: what's left is SF's `trak` table (CoreText tracks SF about 0.12 px a letter at 72px; usvg doesn't).
- - Still off (16), not yet traced: announce-title (frame 0's runs), bloom-lockup, capture-reveal (3 runs only
- raea has), font-shuffle, portal-intro, prompt-send, punch-lines, search-typing, status-cycle, text-build
- (SF's trak), text-rewrite, text-select, word-gather, card-rail, hero-launch (a video's frame, not text) and
+ - A Google family from raea/text's loadFont is fetched when loadFont is called, and a canvas and svg text have
+ it too. The page fetched it at the first layout that named it, after a component's first effect had measured
+ (its canvas found the fallback), and a family the page fetched first never reached the canvas's faces at all.
+ Figtree's "scene" at 600 64px measured 145.72 against Chrome's 171.25, now 171.26. An app-bundled face of a
+ family the page already gave is left out (Geist fetched at import came before the bundled Geist).
+ bloom-lockup passes (40.8 px off before), word-gather is 1.2 px off (25.5 before).
+ - Still off (15), not yet traced: announce-title (frame 0's runs), capture-reveal (3 runs only raea has),
+ font-shuffle, portal-intro, prompt-send, punch-lines, search-typing, status-cycle, text-build (SF's trak),
+ text-rewrite, text-select, word-gather, card-rail, hero-launch (a video's frame, not text) and
wordmark-cut.
- P26 with these: 185 of 215 frames at the bar, the same frames at the same SSIM (to six places) as a binary
before them. The 12 compositions under it are all 3D (classbg, datamaps, paint, planes, texmaps, the four
diff --git a/runtime/calls/src/lib.rs b/runtime/calls/src/lib.rs
index 795b639a..a4cf8cbf 100644
--- a/runtime/calls/src/lib.rs
+++ b/runtime/calls/src/lib.rs
@@ -177,6 +177,9 @@ pub fn call(name: &str, v: &Value) -> R<Value> {
"fonts.google" => {
let family = s(v, "family")?;
raea_sys_fonts::google::want(&family);
+ // fetched now, not at the first layout that names it: a component measures its text in an effect
+ // (canvas measureText, svg text), which runs before that layout and would get the fallback
+ raea_sys_fonts::google::load_now(&family);
Ok(json!({ "family": family }))
}
"fonts.atlases" => font_atlases(v),
diff --git a/sdk/video/src/fonts.ts b/sdk/video/src/fonts.ts
index 99c55030..99bc7df7 100644
--- a/sdk/video/src/fonts.ts
+++ b/sdk/video/src/fonts.ts
@@ -1,6 +1,7 @@
// loadFont (raea/text): a Google Fonts family for the page, as a stylesheet <link> loads it in Chrome. Inside raea the
-// page fetches the family's Latin faces (each weight and style Google has) once, through raea's URL cache
-// (raea-sys-fonts google.rs), so a render stays a function of its code and plays offline once cached. Families
+// family's Latin faces (each weight and style Google has) are fetched when it's called, once, through raea's URL cache
+// (raea-sys-fonts google.rs), so a canvas or svg measure in the first effect already has them, a render stays a
+// function of its code, and it plays offline once cached. Families
// nobody asked for aren't fetched: Chrome loads only what a page links (RAEA_PAGE_GOOGLE_FONTS=1 fetches every family
// a page names). In a browser it links Google's stylesheet, so the same code shows the same family there.
import { hasNative, native } from "@raea/app/native";
diff --git a/systems/fonts/src/google.rs b/systems/fonts/src/google.rs
index 1d8a10c8..e54e2352 100644
--- a/systems/fonts/src/google.rs
+++ b/systems/fonts/src/google.rs
@@ -69,10 +69,27 @@ pub fn load_missing(doc: &mut BaseDocument) -> bool {
doc.load_resource(ResourceLoadResponse { request_id: usize::MAX, node_id: None, resolved_url: None, result: Ok(Resource::Font(ttf.clone(), overrides)) });
loaded = true;
}
+ // a canvas's measureText and svg text find a family the page has, as Chrome's do (snapcn's word-gather, whose
+ // Figtree the page loaded first, measured its words in the fallback)
+ to_svg(&family, &faces);
}
loaded
}
+/// Gives usvg's font database (a canvas's and svg text's) each of `family`'s faces once, each at the weight and style
+/// its @font-face gives it (one variable file is every weight of a family).
+fn to_svg(family: &str, faces: &Faces) {
+ static GIVEN: Mutex<Vec<String>> = Mutex::new(Vec::new());
+ let mut given = GIVEN.lock().unwrap();
+ if faces.is_empty() || given.iter().any(|f| f == family) {
+ return;
+ }
+ for (ttf, weight, italic) in faces.iter() {
+ blitz_dom::util::add_svg_font(ttf.to_vec(), Some(family), Some((*weight as u16, *italic)));
+ }
+ given.push(family.to_string());
+}
+
/// The family's faces for a canvas and SVG text now (document.fonts.load, layout-reads LR7): a family the composition
/// asked for, fetched as load_missing would and given to usvg's font database at once, where the page would only
/// fetch it once an element names it. How many faces it has; 0 for one not asked for or not on Google Fonts.
@@ -80,17 +97,13 @@ pub fn load_now(family: &str) -> usize {
if !wanted(family) {
return 0;
}
- let mut known = FAMILIES.lock().unwrap();
- let known = known.get_or_insert_default();
- if let Some(faces) = known.get(family) {
- return faces.len();
- }
- let faces = Arc::new(fetch(family));
- for (ttf, weight, italic) in faces.iter() {
- // each at the weight and style its @font-face gives it (one variable file is every weight of a family)
- blitz_dom::util::add_svg_font(ttf.to_vec(), Some(family), Some((*weight as u16, *italic)));
- }
- known.insert(family.to_string(), faces.clone());
+ let faces = {
+ let mut known = FAMILIES.lock().unwrap();
+ let known = known.get_or_insert_default();
+ // one the page fetched first (load_missing) is in the cache but may not be in usvg's database yet
+ known.entry(family.to_string()).or_insert_with(|| Arc::new(fetch(family))).clone()
+ };
+ to_svg(family, &faces);
faces.len()
}
diff --git a/vendor/blitz-dom/src/util.rs b/vendor/blitz-dom/src/util.rs
index 2793bd4e..7a26ac9d 100644
--- a/vendor/blitz-dom/src/util.rs
+++ b/vendor/blitz-dom/src/util.rs
@@ -86,11 +86,22 @@ fn add_face(bytes: Vec<u8>, family: Option<&str>, face: Option<(u16, bool)>, bun
return;
}
}
+ // the families the page has given faces of, in lower case
+ static PAGE: LazyLock<Mutex<std::collections::HashSet<String>>> = LazyLock::new(Default::default);
+ let mut page = PAGE.lock().unwrap();
+ // a bundled face of a family the page already has isn't added: raea/text's loadFont fetches Google's Geist when
+ // the composition's module runs, which can be before the app's bundled Geist is loaded
+ if let (true, Some(family)) = (bundled, family) {
+ if page.contains(&family.to_lowercase()) {
+ return;
+ }
+ }
let mut db = FONT_DB.lock().unwrap();
let db = Arc::make_mut(&mut db);
let mut bundled_ids = BUNDLED.lock().unwrap();
// the page's own faces of a family: the bundled ones of that name go
if let (false, Some(family)) = (bundled, family) {
+ page.insert(family.to_lowercase());
for id in bundled_ids.remove(&family.to_lowercase()).unwrap_or_default() {
db.remove_face(id);
}
@@ -359,6 +370,21 @@ mod svg_tests {
assert_eq!(count(&svg_fonts()), 1);
}
+ /// raea: a bundled face of a family the page gave first isn't added beside the page's (loadFont fetches at import)
+ #[cfg(target_os = "macos")]
+ #[test]
+ fn a_bundled_face_after_the_page_s_own_is_left_out() {
+ use super::{add_bundled_svg_font, add_svg_font, svg_fonts};
+ let family = "raea lr10 page first";
+ let var = std::fs::read("/System/Library/Fonts/SFNS.ttf").unwrap();
+ let stat = std::fs::read("/System/Library/Fonts/Supplemental/Arial.ttf").unwrap();
+ add_svg_font(var, Some(family), Some((400, false)));
+ add_bundled_svg_font(stat, Some(family), Some((400, false)));
+ let names: Vec<_> = svg_fonts().faces().filter(|f| f.families.iter().any(|(n, _)| n == family)).map(|f| f.post_script_name.clone()).collect();
+ assert_eq!(names.len(), 1, "{names:?}");
+ assert!(!names[0].contains("Arial"), "{names:?}");
+ }
+
#[test]
fn svg_without_xmlns_parses() {
let src = br#"<svg viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>"#;
diff --git a/vendor/vendor.toml b/vendor/vendor.toml
index 4a20a45f..06fbaf75 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 ; getBoundingClientRect and the geometry walks stop at a freed containing-block link instead of panicking on its key, and an element in a display: none subtree answers a zero rect (raea #108)"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; every inline box laid out in full while its line is only measured, since Taffy's measure cache keeps a box's size without its baseline (raea #109); an inline element has a border edge only where its border has a style, so a plain span (border-style none, its width still `medium`) doesn't split the shaping at its edges and lose the kerning across them (docs/layout-reads.feature LR10)"
+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 ; getBoundingClientRect and the geometry walks stop at a freed containing-block link instead of panicking on its key, and an element in a display: none subtree answers a zero rect (raea #108)"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; every inline box laid out in full while its line is only measured, since Taffy's measure cache keeps a box's size without its baseline (raea #109); an inline element has a border edge only where its border has a style, so a plain span (border-style none, its width still `medium`) doesn't split the shaping at its edges and lose the kerning across them (docs/layout-reads.feature LR10); an app-bundled svg face of a family the page already gave is left out, as one given before the page's is removed (raea/text loadFont fetches Google's faces at import, LR10)"
exit = "a Blitz release with #1244/#1246 and these"
[parley_engine]