From 79e0ced15d7e3c12485920e606e0e5672b68ee2d Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 22 Dec 2017 17:36:52 -0800 Subject: Fix macOS fallbacks (#956) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cascade list is now generated from Menlo for all fonts. This doesn't feel correct to me, but it seems to give the expected behavior on macOS. One of the problems cited was that certain glyphs like ❯ would not be rendered with default cascade lists for some fonts. --- font/src/darwin/mod.rs | 70 +++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'font/src/darwin/mod.rs') diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 70b9e1f3..ddda786a 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -154,23 +154,7 @@ impl ::Rasterize for Rasterizer { .get(&(desc.to_owned(), size)) .map(|k| Ok(*k)) .unwrap_or_else(|| { - let mut font = self.get_font(desc, size)?; - - // TODO, we can't use apple's proposed - // .Apple Symbol Fallback (filtered out below), - // but not having these makes us not able to render - // many chars. We add the symbols back in. - // Investigate if we can actually use the .-prefixed - // fallbacks somehow. - { - let symbols = { - let fallback_style = Style::Description { slant:Slant::Normal, weight:Weight::Normal } ; - let d = FontDesc::new("Apple Symbols".to_owned(), fallback_style); - self.get_font(&d, size)? - }; - font.fallbacks.push(symbols); - } - + let font = self.get_font(desc, size)?; let key = FontKey::next(); self.fonts.insert(key, font); @@ -375,20 +359,48 @@ impl Descriptor { let cg_font = ct_font.copy_to_CGFont(); let fallbacks = if load_fallbacks { - // TODO fixme, hardcoded en for english - cascade_list_for_languages(&ct_font, &vec!["en".to_owned()]) + descriptors_for_family("Menlo") .into_iter() - // the system lists contains (at least) two strange fonts: - // .Apple Symbol Fallback - // .Noto Sans Universal - // both have a .-prefix (to indicate they are internal?) - // neither work very well. the latter even breaks things because - // it defines code points with just [?] glyphs. - .filter(|desc| desc.font_path != "") - .map(|desc| desc.to_font(size, false)) - .collect() + .filter(|d| d.family_name == "Menlo Regular") + .nth(0) + .map(|descriptor| { + let menlo = ct_new_from_descriptor(&descriptor.ct_descriptor, size); + + // TODO fixme, hardcoded en for english + let mut fallbacks = cascade_list_for_languages(&menlo, &vec!["en".to_owned()]) + .into_iter() + .filter(|desc| desc.font_path != "") + .map(|desc| { + println!("{}", desc.display_name); + desc.to_font(size, false) + }) + .collect::>(); + + // TODO, we can't use apple's proposed + // .Apple Symbol Fallback (filtered out below), + // but not having these makes us not able to render + // many chars. We add the symbols back in. + // Investigate if we can actually use the .-prefixed + // fallbacks somehow. + descriptors_for_family("Apple Symbols") + .into_iter() + .next() // should only have one element; use it + .map(|descriptor| { + fallbacks.push(descriptor.to_font(size, false)) + }); + + // Include Menlo in the fallback list as well + fallbacks.insert(0, Font { + cg_font: menlo.copy_to_CGFont(), + ct_font: menlo, + fallbacks: Vec::new() + }); + + fallbacks + }) + .unwrap_or_else(Vec::new) } else { - vec![] + Vec::new() }; Font { -- cgit v1.2.3-54-g00ecf