fonts: dont panic on load error

This commit is contained in:
galister
2024-03-17 11:25:11 +01:00
parent 31ec035db7
commit 67b6b90158

View File

@@ -115,7 +115,7 @@ impl FontCache {
let pattern = pattern.font_match(&mut self.fc);
if let Some(path) = pattern.filename() {
for path in pattern.filename().iter() {
log::debug!(
"Loading font: {} {}pt",
pattern.name().unwrap_or(path),
@@ -124,12 +124,20 @@ impl FontCache {
let font_idx = pattern.face_index().unwrap_or(0);
let face = self
.ft
.new_face(path, font_idx as _)
.expect("Failed to load font face");
face.set_char_size(size << 6, size << 6, 96, 96)
.expect("Failed to set font size");
let face = match self.ft.new_face(path, font_idx as _) {
Ok(face) => face,
Err(e) => {
log::warn!("Failed to load font at {}: {:?}", path, e);
break;
}
};
match face.set_char_size(size << 6, size << 6, 96, 96) {
Ok(_) => {}
Err(e) => {
log::warn!("Failed to set font size: {:?}", e);
break;
}
};
let idx = coll.fonts.len();
for cp in 0..0xFFFF {
@@ -156,12 +164,11 @@ impl FontCache {
let font = Font { face, glyphs };
coll.fonts.push(font);
idx
} else {
return idx;
}
coll.cp_map.insert(cp, 0);
0
}
}
fn get_glyph_for_cp(
&mut self,