diff --git a/crates/ui-egui/src/dialogs/effect_gallery.rs b/crates/ui-egui/src/dialogs/effect_gallery.rs index cf8b1e113e..b9783083bc 100644 --- a/crates/ui-egui/src/dialogs/effect_gallery.rs +++ b/crates/ui-egui/src/dialogs/effect_gallery.rs @@ -724,6 +724,8 @@ mod tests { use egui::accesskit::Role; use egui::{Event, Modifiers, MouseWheelSource, MouseWheelUnit, PointerButton, Pos2, RawInput, Rect, TouchPhase, pos2, vec2}; + // The Japanese pass measures OK when the dialog opens and clicks it after other edits. + crate::testing::wait_for_cjk_fonts(); let viewport = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 500.0)); let mut preview_heights = Vec::new(); for language in ["en", "de", "ja"] { diff --git a/crates/ui-egui/src/dialogs/hyphenation.rs b/crates/ui-egui/src/dialogs/hyphenation.rs index c60c40fc4a..4e9fae0914 100644 --- a/crates/ui-egui/src/dialogs/hyphenation.rs +++ b/crates/ui-egui/src/dialogs/hyphenation.rs @@ -175,6 +175,8 @@ mod tests { ui["dialogs"].as_array().unwrap().iter().find(|dialog| dialog["key"] == KIND).expect("open Hyphenation dialog")["fields"].clone() } + // The Japanese pass measures the controls once and clicks them frames later. + crate::testing::wait_for_cjk_fonts(); let screen = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 500.0)); let mut failures = Vec::new(); for lang in ["en", "de", "fr", "ja"] { diff --git a/crates/ui-egui/src/testing.rs b/crates/ui-egui/src/testing.rs index 3650c423f8..6098a8467a 100644 --- a/crates/ui-egui/src/testing.rs +++ b/crates/ui-egui/src/testing.rs @@ -29,6 +29,25 @@ pub(crate) fn windowed(mut app: crate::VectorcraftApp) -> crate::VectorcraftApp app } +/// Waits until the process's lookup of the installed CJK faces has ended: fontconfig's scan on Linux, which +/// [`crate::ui_fonts`]'s loader starts the first time a CJK character has no glyph. Nothing waits on macOS and Windows. +/// While the scan runs, Japanese, Chinese and Korean text draws without glyphs; the pass after it ends registers the +/// face it found, and the next frame lays the text out again, wider or narrower, moving the controls around it. A test +/// that measures controls in one frame and clicks them in a later one calls this first; then each new context +/// registers its face after its first pass, and the controls hold still from the second frame on. +pub(crate) fn wait_for_cjk_fonts() { + use craft::ui::fonts::{FontCandidates as _, SystemCandidates}; + // `pending` starts the scan when it has not started. + if !SystemCandidates.pending() { + return; + } + let (ended, wait) = std::sync::mpsc::channel(); + SystemCandidates.wake_when_ready(craft::host::Wake::new(move || { + let _ = ended.send(()); + })); + let _ = wait.recv(); +} + /// A context with the runtime, the app's interface fonts and its root theme installed. pub(crate) fn ui_context() -> egui::Context { let ctx = egui::Context::default();