From 3095b856ee765bc05431d7a4f7e25aceb112a60f Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 04:54:38 +0100 Subject: [PATCH] Render: text lists the font file of a run that draws no glyph; tests clean their temp dirs An empty first paragraph draws no glyph, but in a box its face sets the first baseline that places every later line. The read list took faces only from glyphs, so it could be complete without that file. Note each style run's resolved face as well. The font-reads and confine tests use tempfile::tempdir(): a fresh directory per run, removed on panic too. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 2 ++ crates/automation/Cargo.toml | 1 + crates/automation/src/confine.rs | 5 +++-- crates/render/Cargo.toml | 3 +++ crates/render/src/text.rs | 7 +++++++ crates/render/src/text/tests.rs | 29 ++++++++++++++++++++++++----- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b35796cce..f897737db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1468,6 +1468,7 @@ dependencies = [ "effectcraft-script", "image", "serde_json", + "tempfile", "thiserror 2.0.21", ] @@ -1878,6 +1879,7 @@ dependencies = [ "lz4_flex", "rayon", "serde", + "tempfile", "web-time", ] diff --git a/crates/automation/Cargo.toml b/crates/automation/Cargo.toml index 916cc3501..e0caf3218 100644 --- a/crates/automation/Cargo.toml +++ b/crates/automation/Cargo.toml @@ -19,3 +19,4 @@ effectcraft-model = { workspace = true } [dev-dependencies] effectcraft-script = { workspace = true } effectcraft-host = { workspace = true } +tempfile = { workspace = true } diff --git a/crates/automation/src/confine.rs b/crates/automation/src/confine.rs index ebc68900e..55fa8043c 100644 --- a/crates/automation/src/confine.rs +++ b/crates/automation/src/confine.rs @@ -646,7 +646,9 @@ mod tests { thread_local! { static NOTED: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; } - let base = std::env::temp_dir().join(format!("ec-confine-3184-{}", std::process::id())); + // (a fresh directory, removed when the test ends, panicking or not) + let tmp = tempfile::tempdir().unwrap(); + let base = tmp.path(); let (inside, outside) = (base.join("in"), base.join("elsewhere")); for d in [&inside, &outside] { std::fs::create_dir_all(d).unwrap(); @@ -666,7 +668,6 @@ mod tests { assert!(!shown && !files.is_complete(), "outside the roots: {files:?}"); // The next render on the thread is not affected. assert!(read(&footage(&inside)).1.is_complete()); - let _ = std::fs::remove_dir_all(&base); } #[test] diff --git a/crates/render/Cargo.toml b/crates/render/Cargo.toml index efbd1fc19..cd67e846a 100644 --- a/crates/render/Cargo.toml +++ b/crates/render/Cargo.toml @@ -26,3 +26,6 @@ rayon = { workspace = true } web-time = { workspace = true } serde = { workspace = true } log = { workspace = true } + +[dev-dependencies] +tempfile = { workspace = true } diff --git a/crates/render/src/text.rs b/crates/render/src/text.rs index 4165d150d..efe95023f 100644 --- a/crates/render/src/text.rs +++ b/crates/render/src/text.rs @@ -668,7 +668,14 @@ fn note_layout_fonts(ctx: &EvalCtx, styles: &[effectcraft_keyframe::CharStyle], if resolved.iter().any(|r| r.missing) { log.mark_incomplete(); } + // Each run's face, glyphs or not: an empty paragraph's face sets its line's metrics (in a + // box, the first baseline that places every later line). let mut faces: Vec = Vec::new(); + for r in &resolved { + if !faces.contains(&r.face) { + faces.push(r.face); + } + } for g in &layout.glyphs { if g.id == 0 || resolved.get(g.run).is_none_or(|r| r.face != g.face) { log.mark_incomplete(); diff --git a/crates/render/src/text/tests.rs b/crates/render/src/text/tests.rs index c4e43bb2e..9b52d3098 100644 --- a/crates/render/src/text/tests.rs +++ b/crates/render/src/text/tests.rs @@ -742,10 +742,9 @@ fn text_notes_the_font_files_it_draws_with() { }] } } - let dir = std::env::temp_dir().join(format!("effectcraft-font-reads-{}", std::process::id())); - let _ = std::fs::remove_dir_all(&dir); - std::fs::create_dir_all(&dir).unwrap(); - let font = dir.join("reads-test-sans.ttf"); + // (a fresh directory, removed when the test ends, panicking or not) + let dir = tempfile::tempdir().unwrap(); + let font = dir.path().join("reads-test-sans.ttf"); std::fs::write(&font, fonts::INTER_REGULAR).unwrap(); fonts::add_source(&OneFile(font.clone())); let stamp = FileStamp::native(&font.to_string_lossy()).unwrap(); @@ -781,5 +780,25 @@ fn text_notes_the_font_files_it_draws_with() { // One it lacks (Inter has no CJK) is drawn with a fallback face, or none: another installed // font could take it, so the list can't vouch for the text. assert!(!files_with("Reads Test Sans", Some('\u{4e2d}')).is_complete()); - let _ = std::fs::remove_dir_all(&dir); + // An empty first paragraph in the face draws no glyph, but in a box its face sets the first + // baseline that places the lines after it: the file is read all the same. + let (mut p, cid, comp) = setup(200, 80); + let base = TextDoc { + text: "\rHi".into(), + font: fonts::DEFAULT_FAMILY.into(), + style: "Regular".into(), + size: 30.0, + box_size: Some([180.0, 60.0]), + ..Default::default() + }; + let first = effectcraft_keyframe::CharStyle { font: "Reads Test Sans".into(), ..base.base_style() }; + let runs = vec![effectcraft_keyframe::StyleRun { len: 1, style: first }, effectcraft_keyframe::StyleRun { len: 2, style: base.base_style() }]; + let l = text_layer(&mut p, &comp, TextDoc { runs, ..base }); + p.comp_mut(cid).unwrap().layers.push(l); + let log = ReadLog::new(); + let c = EvalCtx { reads: Some(&log), ..ctx(&p, cid, 0.0) }; + assert!(text_geom(&c, &p.comp(cid).unwrap().layers[0]).is_some()); + let files = log.into_files(); + assert!(files.is_complete(), "{files:?}"); + assert_eq!(files.get(&font.to_string_lossy()), Some(stamp), "{files:?}"); }