Fix panic when font face name is not available

This commit is contained in:
Dominik Boehi 2017-04-12 20:36:20 +02:00
parent eb058e20a9
commit ecab3cd796
4 changed files with 14 additions and 8 deletions

View file

@ -113,9 +113,15 @@ impl FontHandleMethods for FontHandle {
c_str_to_string((*self.face).family_name as *const c_char)
}
}
fn face_name(&self) -> String {
fn face_name(&self) -> Option<String> {
unsafe {
c_str_to_string(FT_Get_Postscript_Name(self.face) as *const c_char)
let name = FT_Get_Postscript_Name(self.face) as *const c_char;
if !name.is_null() {
Some(c_str_to_string(name))
} else {
None
}
}
}
fn is_italic(&self) -> bool {

View file

@ -202,8 +202,8 @@ impl FontHandleMethods for FontHandle {
self.ctfont.family_name()
}
fn face_name(&self) -> String {
self.ctfont.face_name()
fn face_name(&self) -> Option<String> {
Some(self.ctfont.face_name())
}
fn is_italic(&self) -> bool {

View file

@ -299,8 +299,8 @@ impl FontHandleMethods for FontHandle {
self.info.family_name.clone()
}
fn face_name(&self) -> String {
self.info.face_name.clone()
fn face_name(&self) -> Option<String> {
Some(self.info.face_name.clone())
}
fn is_italic(&self) -> bool {