font fallback now also applies to italic, bold etc.

This means that emoji now render when the text is italic
This commit is contained in:
Wez Furlong committed 2019-02-20 20:52:46 -08:00
1 parent 7e2b4f006d
commit a5b5f82c6c
3 files changed
+11 -10

No files matched your search

+6 -6
View File
@@ -194,25 +194,27 @@ impl TextStyle {
}
}
fn add_fallback(&mut self) {
pub fn font_with_fallback(&self) -> Vec<FontAttributes> {
let mut font = self.font.clone();
#[cfg(target_os = "macos")]
self.font.push(FontAttributes {
font.push(FontAttributes {
family: "Apple Color Emoji".into(),
bold: None,
italic: None,
});
#[cfg(target_os = "macos")]
self.font.push(FontAttributes {
font.push(FontAttributes {
family: "Apple Symbols".into(),
bold: None,
italic: None,
});
#[cfg(windows)]
self.font.push(FontAttributes {
font.push(FontAttributes {
family: "Segoe UI".into(),
bold: None,
italic: None,
});
font
}
}
@@ -328,8 +330,6 @@ impl Config {
});
}
cfg.font.add_fallback();
cfg
}
}
+4 -3
View File
@@ -19,16 +19,17 @@ impl FontConfigAndFreeType {
impl FontSystem for FontConfigAndFreeType {
fn load_font(&self, config: &Config, style: &TextStyle) -> Result<Box<NamedFont>, Error> {
let mut pattern = if style.font.len() >= 1 {
let fonts = style.font_with_fallback();
let mut pattern = if fonts.len() >= 1 {
let mut pattern = FontPattern::new()?;
if style.font.len() > 1 {
if fonts.len() > 1 {
eprintln!(
"FIXME: fontconfig loader currently only processes
the first in your set of fonts for {:?}",
style
);
}
let attr = &style.font[0];
let attr = &fonts[0];
pattern.family(&attr.family)?;
if *attr.bold.as_ref().unwrap_or(&false) {
pattern.add_integer("weight", 200)?;
+1 -1
View File
@@ -7,7 +7,7 @@ pub fn load_system_fonts(
style: &TextStyle,
) -> Result<Vec<(Vec<u8>, i32)>, Error> {
let mut fonts = Vec::new();
for font_attr in &style.font {
for font_attr in style.font_with_fallback() {
let mut font_props = system_fonts::FontPropertyBuilder::new()
.family(&font_attr.family)
.monospace();