Bug 1649676 - use fallback font if loading WR mac font descriptor fails. r=jfkthame
authorLee Salzman <lsalzman@mozilla.com>
Thu, 23 Jul 2020 13:34:36 +0000
changeset 541812 f25c770ccbf3cd6876f06f9b1940461064c1b64e
parent 541811 cf217b49d014efd5b82557b6bb9d85788852dcfd
child 541813 d9e15f6cc3505d97898daafe3e6c7282060f2021
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1649676
milestone80.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1649676 - use fallback font if loading WR mac font descriptor fails. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D84625
gfx/webrender_bindings/src/bindings.rs
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -2134,17 +2134,28 @@ fn read_font_descriptor(bytes: &mut WrVe
         index,
     }
 }
 
 #[cfg(target_os = "macos")]
 fn read_font_descriptor(bytes: &mut WrVecU8, _index: u32) -> NativeFontHandle {
     let chars = bytes.flush_into_vec();
     let name = String::from_utf8(chars).unwrap();
-    let font = CGFont::from_name(&CFString::new(&*name)).unwrap();
+    let font = match CGFont::from_name(&CFString::new(&*name)) {
+        Ok(font) => font,
+        Err(_) => {
+            // If for some reason we failed to load a font descriptor, then our
+            // only options are to either abort or substitute a fallback font.
+            // It is preferable to use a fallback font instead so that rendering
+            // can at least still proceed in some fashion without erroring.
+            // Lucida Grande is the fallback font in Gecko, so use that here.
+            CGFont::from_name(&CFString::from_static_string("Lucida Grande"))
+                .expect("Failed reading font descriptor and could not load fallback font")
+        }
+    };
     NativeFontHandle(font)
 }
 
 #[cfg(not(any(target_os = "macos", target_os = "windows")))]
 fn read_font_descriptor(bytes: &mut WrVecU8, index: u32) -> NativeFontHandle {
     let chars = bytes.flush_into_vec();
     NativeFontHandle {
         path: PathBuf::from(OsString::from_vec(chars)),