Fonts are scanned again when the font watch finds fonts installed or removed, as production's look at the installed fonts did, not whenever the shared catalog's generation moves: it also moves when a document's own fonts are added or removed and when another app in the process refreshes the font list, which journaled a Refresh Font List in the middle of an edit (tests::scrub::a_scrub_inside_an_open_undo_group_joins_its_step, run beside tests that refresh the fonts)

This commit is contained in:
bflatastic
2026-11-23 19:54:56 +07:00
parent e727a6aec6
commit e46b2e7520
3 changed files with 16 additions and 22 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ impl VectorcraftApp {
original_editor: Default::default(),
screen_pick: craft::color_ui::ui::ScreenPick::new(),
font_watch: None,
fonts_seen: 0,
fonts_changed: Default::default(),
font_preview_owner: None,
background: Default::default(),
opening: Default::default(),
+12 -19
View File
@@ -27,34 +27,27 @@ impl VectorcraftApp {
pub(super) fn watch_fonts(&mut self, ctx: &egui::Context) {
#[cfg(not(target_arch = "wasm32"))]
{
let ctx = ctx.clone();
let watch = vectorcraft_text::FontDb::global().catalog().watch(crate::state::FONT_INSTALL_POLL, move |_| ctx.request_repaint());
let (ctx, changed) = (ctx.clone(), std::sync::Arc::clone(&self.fonts_changed));
let watch = vectorcraft_text::FontDb::global().catalog().watch(crate::state::FONT_INSTALL_POLL, move |_| {
changed.store(true, std::sync::atomic::Ordering::Release);
ctx.request_repaint();
});
self.font_watch = Some(watch);
}
#[cfg(target_arch = "wasm32")]
let _ = ctx;
}
/// Once per frame: when the catalog changed since the last look, runs `text.rescanFonts`, so
/// documents and lists take up the fonts the watch ([`Self::watch_fonts`]) found. It reads no
/// input, so a second pass of a frame changes nothing.
// PLAN: keyed on the catalog's generation, as contract row ty.S2 says, not `FontDb::generation` (the settled note): that one also moves each time layout loads an installed family, which would rescan on every font first used.
/// Once per frame: when the watch ([`Self::watch_fonts`]) found fonts installed or removed since the last look,
/// runs `text.rescanFonts`, so documents and lists take up the fonts it found. It reads no input, so a second pass
/// of a frame changes nothing.
// PLAN: contract row ty.S2 keys this on the catalog's generation; that also moves when a document's own fonts are
// added or removed and when another app in the process rescans, which production's look at the installed fonts
// never rescanned for, so it is keyed on what the watch found.
pub(super) fn follow_fonts(&mut self) {
let catalog = vectorcraft_text::FontDb::global().catalog();
// Until the first scan ends there is nothing to follow, and its end changes no document.
if !catalog.is_ready() {
return;
}
let generation = catalog.generation();
if generation == self.fonts_seen {
return;
}
// 0: the first look after the first scan (the generation is at least 1 once it ran).
if self.fonts_seen != 0 {
if self.fonts_changed.swap(false, std::sync::atomic::Ordering::AcqRel) {
// A failure shows in the status bar, as the menu item's does.
let _ = self.run("text.rescanFonts", json!({}));
}
// The command's own rescan moves the generation too.
self.fonts_seen = catalog.generation();
}
}
+3 -2
View File
@@ -230,8 +230,9 @@ pub struct VectorcraftApp {
pub(crate) screen_pick: craft::color_ui::ui::ScreenPick,
/// The font catalog's watch for fonts installed or removed while the app runs.
pub(crate) font_watch: Option<craft::font_catalog::Watch>,
/// The font catalog generation the documents' fonts were last scanned again for.
pub(crate) fonts_seen: u64,
/// Set by [`Self::font_watch`] when it found fonts installed or removed, until the documents' fonts are scanned
/// again for them.
pub(crate) fonts_changed: std::sync::Arc<std::sync::atomic::AtomicBool>,
/// The font menu whose live preview the canvas shows, while one does.
pub(crate) font_preview_owner: Option<egui::Id>,
/// Saves and exports running in the background (Preferences → File Handling).