diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-29 14:52:01 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-10-08 16:30:12 +0800 |
| commit | 43feb2ce51f63f4dfbabbafd9c02bc42dc6faefc (patch) | |
| tree | 9b172a44470fbaad11c81e889b16c0d796a4a3e6 /src/image.rs | |
| parent | 56a7b7b6aac1f63b352129e13476b83951c538ae (diff) | |
image(font): simplify sansserif system font lookup
Diffstat (limited to 'src/image.rs')
| -rw-r--r-- | src/image.rs | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/image.rs b/src/image.rs index b78dc04..077bb82 100644 --- a/src/image.rs +++ b/src/image.rs @@ -74,25 +74,24 @@ fn get_font() -> Result<FontArc, io::Error> { let mut db = Database::new(); db.load_system_fonts(); - let id = db - .query(&Query { - families: &[Family::SansSerif], - weight: fontdb::Weight::NORMAL, - stretch: fontdb::Stretch::Normal, - style: fontdb::Style::Normal, - }) - .or_else(|| { - db.faces() - .next() - .map(|f| f.id) - }) - .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "no system fonts"))?; - - let face = db - .face(id) - .ok_or_else(|| io::Error::other("face missing"))?; - - match &face.source { + match &db + .face( + db.query(&Query { + families: &[Family::SansSerif], + weight: fontdb::Weight::NORMAL, + stretch: fontdb::Stretch::Normal, + style: fontdb::Style::Normal, + }) + .or_else(|| { + db.faces() + .next() + .map(|f| f.id) + }) + .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "no system fonts"))?, + ) + .ok_or_else(|| io::Error::other("face missing"))? + .source + { Source::File(path) => std::fs::read(path).and_then(|bytes| FontArc::try_from_vec(bytes).map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "parse font failed"))), Source::Binary(data) => FontArc::try_from_vec( data.as_ref() |
