summaryrefslogtreecommitdiffstats
path: root/font
diff options
context:
space:
mode:
authorJoe Wilm <jwilm@users.noreply.github.com>2017-12-22 17:36:52 -0800
committerGitHub <noreply@github.com>2017-12-22 17:36:52 -0800
commit79e0ced15d7e3c12485920e606e0e5672b68ee2d (patch)
tree0822a4409f1a2ed5865226953d7ef0f6c668ea36 /font
parent672ea9b05037c8efc5984835990c74ac1c46c298 (diff)
Fix macOS fallbacks (#956)
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.
Diffstat (limited to 'font')
-rw-r--r--font/src/darwin/mod.rs70
1 files changed, 41 insertions, 29 deletions
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::<Vec<_>>();
+
+ // 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 {