Skip to content

Commit 1ee1d06

Browse files
committed
Refactor FontExt::new to simplify face parsing logic and fix MacOS font panic
1 parent a212c30 commit 1ee1d06

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

plotters/src/style/font/ttf.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ impl Drop for FontExt {
7676
impl FontExt {
7777
fn new(font: Font) -> Self {
7878
let handle = font.handle();
79-
let (data, idx) = match handle.as_ref() {
80-
Some(Handle::Memory { bytes, font_index }) => (&bytes[..], *font_index),
81-
_ => unreachable!(),
82-
};
83-
let face = unsafe {
84-
std::mem::transmute::<Option<_>, Option<Face<'static>>>(
85-
ttf_parser::Face::parse(data, idx).ok(),
86-
)
79+
let face = match handle.as_ref() {
80+
Some(Handle::Memory { bytes, font_index }) => unsafe {
81+
std::mem::transmute::<Option<_>, Option<Face<'static>>>(
82+
ttf_parser::Face::parse(bytes, *font_index).ok(),
83+
)
84+
},
85+
_ => None,
8786
};
8887
Self { inner: font, face }
8988
}

0 commit comments

Comments
 (0)