mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-25 10:17:02 -06:00
Opening, placing, pasting or importing a file, the font menus and MCP now find the installed system fonts (Arial, Times New Roman...) in a fresh session, so a file renders the same whatever happened earlier, and PDF import keeps the real family names (Microsoft YaHei, not "Microsoft Ya Hei"). Root cause: FontDb only consulted the system font catalog, which stayed empty until a CJK fallback or Character panel > Show System Fonts happened to scan the font folders. Every lookup by family name (face, families, styles, has_family) now waits for one cataloging scan per session: the app starts it in the background, other processes run it on first use. The scan reads only each file's table directory and name table (about 70 ms for 780 faces here, instead of reading every font file whole), the catalog is indexed by family, the family list is cached, and an installed style of a loaded family (a bundled family also installed with more weights) loads when asked for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
1.1 KiB
Rust
23 lines
1.1 KiB
Rust
//! A new session finds the installed system fonts by family name (#130). One test in its own
|
||
//! process, so the process-wide database starts fresh, as it does when the app starts.
|
||
// Integration tests: unwrapping and panicking on failure is fine here, unlike in shipped code (AGENTS.md › Robustness).
|
||
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
||
|
||
use vectorcraft_text::{FontDb, system_font_dirs};
|
||
|
||
#[test]
|
||
fn a_fresh_session_finds_installed_fonts_by_name() {
|
||
let bundled = FontDb::with_font_dirs(vec![]).families();
|
||
let probe = FontDb::with_font_dirs(system_font_dirs());
|
||
probe.load_system_fonts();
|
||
let installed = probe.families();
|
||
let Some(family) = installed.iter().find(|f| !bundled.contains(f)) else {
|
||
eprintln!("no system fonts installed: nothing to check");
|
||
return;
|
||
};
|
||
// The first lookup in the session: nothing has scanned the font folders yet.
|
||
let face = FontDb::global().face(family, "Regular").unwrap();
|
||
assert_eq!(&face.family, family);
|
||
assert!(FontDb::global().families().contains(family));
|
||
}
|