From b410d5a049bbb9c24ed07c62c0d755346f25b702 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 02:19:08 -0800 Subject: [PATCH 1/2] Fonts: hinting is off, so a face without instructions no longer hangs the font list egui hints text by default. For a TrueType face with no hinting instructions (no fpgm, no prep and no glyph instructions) it uses the automatic hinter of skrifa 0.44, whose blue-zone search never ends for some glyphs, such as a tall narrow Hebrew letter. The font list and the font picker draw each family's sample in its own face, so one installed face of that kind stops the app when its row is drawn (#10493). The faces reach egui through craft-libs, which sets no hinting option per face, so adopt_context now turns hinting off for every context the app adopts. Text layout does not change; only the rasterized outlines do. The craft-libs pin that brings the skrifa blue-zone exit (storytold/craft-libs#5222) removes ui_fonts::hinting_off and its call. --- crates/ui-egui/src/graphics.rs | 3 +- crates/ui-egui/src/tests/font_menu.rs | 69 +++++++++++++++++++++++++++ crates/ui-egui/src/ui_fonts.rs | 11 +++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/graphics.rs b/crates/ui-egui/src/graphics.rs index 27cf2c623c..69f91c1ed6 100644 --- a/crates/ui-egui/src/graphics.rs +++ b/crates/ui-egui/src/graphics.rs @@ -127,13 +127,14 @@ impl VectorcraftApp { /// after losing its graphics), everything uploaded to the old one is made again: the fonts and /// theme, the canvas, the place cursor's thumbnails and every [`TexCache`]. The host hands it /// the window's context when it creates the app, so the first frame's input has the app's - /// commands. + /// commands. Each new context draws its text without hinting ([`crate::ui_fonts::hinting_off`]). pub fn adopt_context(&mut self, ctx: &egui::Context) { let tag = context_tag(ctx); self.ui_ctx = Some(ctx.clone()); if self.context == tag { return; } + crate::ui_fonts::hinting_off(ctx); if self.context != 0 { log::info!("vectorcraft: new graphics context: uploading the UI again"); forget_textures(); diff --git a/crates/ui-egui/src/tests/font_menu.rs b/crates/ui-egui/src/tests/font_menu.rs index 28d573d09b..3b330fa3e0 100644 --- a/crates/ui-egui/src/tests/font_menu.rs +++ b/crates/ui-egui/src/tests/font_menu.rs @@ -75,6 +75,75 @@ fn samples_show_the_text_in_the_family_or_a_generic_sample() { assert_eq!(texts.iter().filter(|t| t.text == "Sample").count(), 2, "both runs are the generic sample: {texts:?}"); } +/// A face with no hinting instructions draws a sample in a context the app has adopted, as the font list and the +/// font picker draw each family's sample in its own face (a document face of the context): a Hebrew letter that is a +/// bar 20 by 700 thousandths of an em, whose blue zones the automatic hinter of skrifa 0.44 never finishes measuring. +/// The face is served to the fixture's context only, so the font database other tests read does not change. The +/// sample is one rasterized glyph from that face. It is drawn on a thread of its own, and the test fails when it has +/// not ended after 300 s. +#[test] +fn a_face_without_hinting_instructions_draws_its_sample() { + use std::sync::{Arc, Mutex}; + + use craft::ui::fonts::{FaceBytes, FaceState}; + use craft::ui::primitives::{ContentPainterCx, DocRun, DocText, FacesCx as _}; + use craft::ui::runtime::env::Env; + use craft::ui::style::{DataColor, SurfaceKind}; + use craft::ui::testing::Fixture; + use vectorcraft_text::{FileFontInfo, FileGlyph, build_file_font}; + + let mut glyph = FileGlyph { ch: '\u{5d1}', outline: Default::default(), advance: 300.0 }; + glyph.outline.move_to((0.0, 0.0)); + glyph.outline.line_to((0.0, 700.0)); + glyph.outline.line_to((20.0, 700.0)); + glyph.outline.line_to((20.0, 0.0)); + glyph.outline.close_path(); + let info = FileFontInfo { family: "Unhinted Bar".into(), style: "Regular".into(), ..Default::default() }; + let bytes: Arc<[u8]> = Arc::from(build_file_font(&info, &[glyph]).unwrap()); + let (tx, rx) = std::sync::mpsc::channel(); + std::thread::spawn(move || { + let sample = Arc::new(Mutex::new((false, false))); + let drawn_sample = Arc::clone(&sample); + let mut fixture = Fixture::new(move |ui| { + *drawn_sample.lock().unwrap() = (false, false); + let env = Env::of(ui); + let cx = ContentPainterCx::new(ui.painter().clone(), &env, SurfaceKind::Panel.ink()); + let state = cx.document_face("font-sample/Unhinted Bar/Regular", || { + let bytes = Arc::clone(&bytes); + move || Some(FaceBytes::new(bytes, 0)) + }); + let FaceState::Ready(font) = state else { return }; + let color = DataColor::new(egui::Color32::BLACK); + let runs = [DocRun::new("\u{5d1}", font, 16.0, color)]; + let layout = cx.layout(&DocText::new(&runs)); + let fixture_has_glyph = layout + .galley + .job + .sections + .first() + .is_some_and(|section| ui.ctx().fonts_mut(|fonts| fonts.has_glyph(§ion.format.font_id, '\u{5d1}'))); + let mut glyphs = layout.galley.rows.iter().flat_map(|row| row.glyphs.iter()); + let nonempty_glyph = + glyphs.next().is_some_and(|glyph| glyph.chr == '\u{5d1}' && glyph.uv_rect.size.x > 0.0 && glyph.uv_rect.size.y > 0.0) + && glyphs.next().is_none(); + *drawn_sample.lock().unwrap() = (fixture_has_glyph, nonempty_glyph); + cx.painter.galley(ui.max_rect().min, layout.galley.clone(), color.0); + }); + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.adopt_context(fixture.ctx()); + fixture.settle(); + let texts = fixture.texts().iter().map(|t| t.text.clone()).collect::>(); + let (fixture_has_glyph, nonempty_glyph) = *sample.lock().unwrap(); + tx.send((texts, fixture.ctx().global_style().visuals.text_options.font_hinting, fixture_has_glyph, nonempty_glyph)).ok() + }); + let (texts, hinting, fixture_has_glyph, nonempty_glyph) = + rx.recv_timeout(std::time::Duration::from_secs(300)).unwrap_or_else(|e| panic!("drawing the sample: {e}")); + assert!(texts.iter().any(|t| t == "\u{5d1}"), "the sample is the letter, in the face: {texts:?}"); + assert!(!hinting, "a context the app adopts draws text without hinting"); + assert!(fixture_has_glyph, "the sample's face maps U+05D1"); + assert!(nonempty_glyph, "the sample is one rasterized glyph for U+05D1"); +} + #[test] fn preview_changes_the_text_live_and_only_a_choice_is_a_step() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); diff --git a/crates/ui-egui/src/ui_fonts.rs b/crates/ui-egui/src/ui_fonts.rs index 0e00238ab4..9cf7346b0e 100644 --- a/crates/ui-egui/src/ui_fonts.rs +++ b/crates/ui-egui/src/ui_fonts.rs @@ -22,6 +22,17 @@ pub fn ui_fonts() -> UiFonts<'static> { } } +/// Turns font hinting off for all text `ctx` draws, in both themes. With hinting on, egui hints a TrueType face that +/// has no hinting instructions (no `fpgm`, no `prep` and no glyph instructions) with skrifa 0.44's automatic hinter, +/// whose blue-zone search never ends for some glyphs, such as a tall narrow Hebrew letter, so the font list stops +/// responding when a row draws such a face. The font list and the samples get their faces through craft-libs, which +/// sets no hinting option per face, so the switch covers every face of the context. Hinting stays off until the +/// skrifa blue-zone exit (storytold/craft-libs#5222) is in the build; the craft-libs pin that brings it removes this +/// function and its call. +pub(crate) fn hinting_off(ctx: &egui::Context) { + ctx.all_styles_mut(|style| style.visuals.text_options.font_hinting = false); +} + #[cfg(test)] mod tests { use craft::ui::fonts::{FontRef, Sample, UiFonts, assert_covers, missing_glyphs}; From bb4a3fc3d8e3fbf18703a06137913247601cae7f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 06:24:15 -0800 Subject: [PATCH 2/2] Tests: the unhinted-face sample test checks hinting is off in both themes hinting_off turns hinting off in the light and the dark style of a context. The test now reads both styles as well as the global one, so a switch that changes only the current theme fails it. --- crates/ui-egui/src/tests/font_menu.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tests/font_menu.rs b/crates/ui-egui/src/tests/font_menu.rs index 3b330fa3e0..2045e85976 100644 --- a/crates/ui-egui/src/tests/font_menu.rs +++ b/crates/ui-egui/src/tests/font_menu.rs @@ -134,12 +134,20 @@ fn a_face_without_hinting_instructions_draws_its_sample() { fixture.settle(); let texts = fixture.texts().iter().map(|t| t.text.clone()).collect::>(); let (fixture_has_glyph, nonempty_glyph) = *sample.lock().unwrap(); - tx.send((texts, fixture.ctx().global_style().visuals.text_options.font_hinting, fixture_has_glyph, nonempty_glyph)).ok() + let ctx = fixture.ctx(); + let hinting = [ + ctx.global_style().visuals.text_options.font_hinting, + ctx.style_of(egui::Theme::Light).visuals.text_options.font_hinting, + ctx.style_of(egui::Theme::Dark).visuals.text_options.font_hinting, + ]; + tx.send((texts, hinting, fixture_has_glyph, nonempty_glyph)).ok() }); - let (texts, hinting, fixture_has_glyph, nonempty_glyph) = + let (texts, [hinting, light_hinting, dark_hinting], fixture_has_glyph, nonempty_glyph) = rx.recv_timeout(std::time::Duration::from_secs(300)).unwrap_or_else(|e| panic!("drawing the sample: {e}")); assert!(texts.iter().any(|t| t == "\u{5d1}"), "the sample is the letter, in the face: {texts:?}"); assert!(!hinting, "a context the app adopts draws text without hinting"); + assert!(!light_hinting, "the light theme draws text without hinting"); + assert!(!dark_hinting, "the dark theme draws text without hinting"); assert!(fixture_has_glyph, "the sample's face maps U+05D1"); assert!(nonempty_glyph, "the sample is one rasterized glyph for U+05D1"); }