Tests: Japanese dialog clicks wait for the CJK font lookup

On Linux, the interface fonts find a CJK face through a fontconfig
lookup that runs on its own thread and starts the first time a CJK
character has no glyph. Until it ends, Japanese labels draw without
glyphs. The pass after it ends registers the face, and the next frame
lays the labels out again, which moves the controls around them.

hyphenation_keeps_focused_edits_until_cancel_or_ok and
localized_compact_gallery_pointer_applies_and_cancels measure their
controls in one frame and click them frames later. When the lookup ends
in between, the click misses: the Hyphenation checkbox keeps its old
value ("ja Cancel: Some(8.0), (Some(8.0), Some(false))"), or the
gallery's OK applies nothing. A loaded machine slows the lookup's
fc-match runs, so it ends inside the Japanese pass.

testing::wait_for_cjk_fonts starts the lookup and waits for it through
its completion callback, with no timeout. Both tests call it before
they measure anything, so each new context registers its face after its
first pass and the controls stay in place from then on.
This commit is contained in:
dotCooCoo committed 2026-11-28 02:37:26 -08:00
1 parent 4167e0abca
commit fbd72fc4af
3 files changed
+23

No files matched your search

@@ -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"] {
@@ -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"] {
+19
View File
@@ -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();