Fonts: the scan reads the fonts the registry lists when the font service is off

With a complete platform lister the font catalog does not ask the font
service and does not read the registry's font list, so a font listed only
in the registry was noted as a change but never cataloged. The catalog's
lister now adds the registry's full paths to the platform files it lists,
as the catalog does itself when the font service is on.

RegisteredFonts::changed reads the registry before it takes its lock, so a
scan noting the registry's list does not wait for that read.

The registry tests scan with a lister of their own that lists no platform
files, so the process-wide lister another test sets does not change what
they scan. The first one now checks that the registered font is cataloged.
This commit is contained in:
dotCooCoo committed 2026-12-05 17:41:12 -08:00
1 parent afa7fbb1ca
commit 311280dbc7
3 files changed
+25 -14

No files matched your search

+2 -1
View File
@@ -50,9 +50,10 @@ impl FontDb {
/// [`FontDb::for_system_scan_test`] as with a complete platform lister
/// ([`super::set_platform_font_files_complete`]): the scan does not ask the platform's font service.
/// Its lister lists no platform files, so another test's process-wide lister does not change what it scans.
#[cfg(test)]
pub(crate) fn for_complete_lister_scan_test() -> Self {
Self::new(super::dirs::system_catalog_with(false))
Self::new(super::dirs::system_catalog_with(false, Vec::new))
}
fn new((catalog, registered): (Catalog, Option<Arc<RegisteredFonts>>)) -> Self {
+17 -11
View File
@@ -93,20 +93,22 @@ pub(crate) fn uses_font_service() -> bool {
/// ([`uses_font_service`]), the font store, VectorCraft's own folders ([`app_dirs`]) and the files
/// [`set_platform_font_files`] lists, with the registry's fonts its own change check leaves out.
pub(super) fn system_catalog() -> (Catalog, Option<Arc<RegisteredFonts>>) {
system_catalog_with(uses_font_service())
system_catalog_with(uses_font_service(), platform_font_files)
}
/// [`system_catalog`], asking the platform's font service when `service`. Without it the catalog
/// neither reads nor compares the fonts the Windows registry lists, so the database compares them
/// [`system_catalog`], asking the platform's font service when `service` and reading the files
/// `platform` lists. Without the service the catalog neither reads nor compares the fonts the
/// Windows registry lists, so its lister adds them to the scan and the database compares them
/// ([`RegisteredFonts`]).
pub(super) fn system_catalog_with(service: bool) -> (Catalog, Option<Arc<RegisteredFonts>>) {
pub(super) fn system_catalog_with(service: bool, platform: fn() -> Vec<PathBuf>) -> (Catalog, Option<Arc<RegisteredFonts>>) {
let registered = (!service).then(|| Arc::new(RegisteredFonts::default()));
let seen = registered.clone();
let lister = move || {
let mut files = platform();
if let Some(seen) = &seen {
seen.record();
files.extend(seen.record());
}
platform_font_files()
files
};
let catalog = Catalog::new(FontEnv::from_process()).with_font_service(service).with_lister(Arc::new(lister));
catalog.set_app_dirs(app_dirs());
@@ -122,15 +124,19 @@ pub(super) fn system_catalog_with(service: bool) -> (Catalog, Option<Arc<Registe
pub(super) struct RegisteredFonts(super::Mutex<Option<Vec<PathBuf>>>);
impl RegisteredFonts {
/// Note the registry's list for the scan that is starting.
fn record(&self) {
/// Note the registry's list for the scan that is starting, and return it for the scan to read.
fn record(&self) -> Vec<PathBuf> {
let now = registered_font_files();
*self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = Some(now);
*self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = Some(now.clone());
now
}
/// Whether the registry's list changed since the last scan noted it: `false` before one.
/// Whether the registry's list changed since the last scan noted it: `false` before one. The
/// registry is read before the lock is taken, so a scan's [`RegisteredFonts::record`] does not
/// wait for the read.
pub(super) fn changed(&self) -> bool {
self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).as_ref().is_some_and(|seen| *seen != registered_font_files())
let now = registered_font_files();
self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).as_ref().is_some_and(|seen| *seen != now)
}
}
+6 -2
View File
@@ -787,7 +787,7 @@ fn fonts_the_platform_lists_outside_the_font_folders_are_cataloged() {
/// With a complete platform lister the catalog does not compare the fonts the Windows registry
/// lists, so the database does: a font registered from a folder no scan has read is a change, and
/// the scan that follows notes it.
/// the scan that follows catalogs it and notes it.
#[test]
fn a_font_registered_since_the_scan_is_a_change_with_a_complete_lister() {
use crate::fontdb::REGISTERED_IN_TESTS;
@@ -797,11 +797,15 @@ fn a_font_registered_since_the_scan_is_a_change_with_a_complete_lister() {
db.load_system_fonts();
assert!(!db.installed_fonts_changed());
let registered = std::env::temp_dir().join(format!("vc-sysfonts-{}-registered", std::process::id())).join("Registered.ttf");
REGISTERED_IN_TESTS.set(Some(vec![registered]));
std::fs::create_dir_all(registered.parent().unwrap()).unwrap();
std::fs::write(&registered, renamed_to("SourceSans3-Regular.ttf", "Registry Sans")).unwrap();
REGISTERED_IN_TESTS.set(Some(vec![registered.clone()]));
assert!(db.installed_fonts_changed(), "a font registered since the scan");
db.load_system_fonts();
assert_eq!(db.styles("Registry Sans"), ["Regular"], "the scan reads the font the registry lists");
assert!(!db.installed_fonts_changed(), "the scan noted the registered font");
REGISTERED_IN_TESTS.set(None);
let _ = std::fs::remove_dir_all(registered.parent().unwrap());
}
/// Each look of the font watch (`FontDb::watch`) uses the database's check, so a font registered