Skip to content

Commit e2db268

Browse files
sakuraba07duskmoon314
authored andcommitted
fix: support single font file paths in fonts config
Previously, the fonts config only worked with directories because load_fonts_dir() was used unconditionally. This caused single font file paths (e.g., fonts = "/path/to/font.ttf") to be silently ignored. Now the code checks whether the path is a file or directory and uses the appropriate fontdb function: - load_font_file() for single files - load_fonts_dir() for directories Also adds a warning message when the specified font path does not exist.
1 parent 38e95bb commit e2db268

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,18 @@ impl Preprocessor for TypstProcessor {
194194
// Load fonts from the config
195195
if let Some(fonts) = config.fonts {
196196
for font_path in fonts.into_vec() {
197-
db.load_fonts_dir(font_path);
197+
let path = std::path::Path::new(&font_path);
198+
if path.is_file() {
199+
// Load single font file
200+
if let Err(e) = db.load_font_file(&font_path) {
201+
eprintln!("Warning: Failed to load font file {:?}: {}", font_path, e);
202+
}
203+
} else if path.is_dir() {
204+
// Load all fonts from directory
205+
db.load_fonts_dir(&font_path);
206+
} else {
207+
eprintln!("Warning: Font path does not exist: {:?}", font_path);
208+
}
198209
}
199210
}
200211
// Load system fonts, lower priority

0 commit comments

Comments
 (0)