From 044469ec5f8c2700d42ab07cc76d1028ef659d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Mary=C5=84czak?= Date: Tue, 15 Aug 2023 22:12:25 +0200 Subject: [PATCH] Handle ab glyph panics (#41) --- src/title/ab_glyph_renderer.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/title/ab_glyph_renderer.rs b/src/title/ab_glyph_renderer.rs index 6a3551a..2b2d4b3 100644 --- a/src/title/ab_glyph_renderer.rs +++ b/src/title/ab_glyph_renderer.rs @@ -31,7 +31,10 @@ impl AbGlyphTitleText { let size = parse_font(&font) .pt_to_px_scale(font_pref_pt_size) - .expect("invalid font units_per_em"); + .unwrap_or_else(|| { + log::error!("invalid font units_per_em"); + PxScale { x: 17.6, y: 17.6 } + }); Self { title: <_>::default(), @@ -148,8 +151,14 @@ fn parse_font(sys_font: &Option<(memmap2::Mmap, FontPreference)>) -> FontRef<'_> } f }) - .unwrap_or_else(|_| FontRef::try_from_slice(CANTARELL).unwrap()) + .unwrap_or_else(|_| { + // We control the default font, so I guess it's fine to unwrap it + #[allow(clippy::unwrap_used)] + FontRef::try_from_slice(CANTARELL).unwrap() + }) } + // We control the default font, so I guess it's fine to unwrap it + #[allow(clippy::unwrap_used)] _ => FontRef::try_from_slice(CANTARELL).unwrap(), } }