diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 8a0377cd2b0..bf4b6a7df77 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -48,7 +48,7 @@ pub trait FontHandleMethods: Sized { -> Result; fn template(&self) -> Arc; fn family_name(&self) -> String; - fn face_name(&self) -> String; + fn face_name(&self) -> Option; fn is_italic(&self) -> bool; fn boldness(&self) -> font_weight::T; fn stretchiness(&self) -> font_stretch::T; @@ -254,7 +254,7 @@ impl Font { debug!("{} font table[{}] with family={}, face={}", status, tag.tag_to_str(), - self.handle.family_name(), self.handle.face_name()); + self.handle.family_name(), self.handle.face_name().unwrap_or("unavailable".to_owned())); result } diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 02460d93dc8..be4d6aae036 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -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 { 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 { diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index 8fb867a2f5c..d87fec6f36d 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -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 { + Some(self.ctfont.face_name()) } fn is_italic(&self) -> bool { diff --git a/components/gfx/platform/windows/font.rs b/components/gfx/platform/windows/font.rs index eff93d7e5f5..6046a70770f 100644 --- a/components/gfx/platform/windows/font.rs +++ b/components/gfx/platform/windows/font.rs @@ -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 { + Some(self.info.face_name.clone()) } fn is_italic(&self) -> bool {