mirror of
https://github.com/wez/wezterm.git
synced 2024-11-24 07:46:59 +03:00
Clean up FontAttributes bold and italic
There doesn't seem to be a need for a tristate Option<bool>, since we always treat unset as false.
This commit is contained in:
parent
b751c6590b
commit
0ba11a8bbd
@ -13,17 +13,19 @@ pub struct FontAttributes {
|
||||
/// The font family name
|
||||
pub family: String,
|
||||
/// Whether the font should be a bold variant
|
||||
pub bold: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub bold: bool,
|
||||
/// Whether the font should be an italic variant
|
||||
pub italic: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub italic: bool,
|
||||
}
|
||||
|
||||
impl Default for FontAttributes {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
family: FONT_FAMILY.into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,7 +62,7 @@ impl TextStyle {
|
||||
.iter()
|
||||
.map(|attr| {
|
||||
let mut attr = attr.clone();
|
||||
attr.bold = Some(true);
|
||||
attr.bold = true;
|
||||
attr
|
||||
})
|
||||
.collect(),
|
||||
@ -76,7 +78,7 @@ impl TextStyle {
|
||||
.iter()
|
||||
.map(|attr| {
|
||||
let mut attr = attr.clone();
|
||||
attr.italic = Some(true);
|
||||
attr.italic = true;
|
||||
attr
|
||||
})
|
||||
.collect(),
|
||||
@ -98,53 +100,53 @@ impl TextStyle {
|
||||
#[cfg(target_os = "macos")]
|
||||
font.push(FontAttributes {
|
||||
family: "Apple Color Emoji".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
#[cfg(target_os = "macos")]
|
||||
font.push(FontAttributes {
|
||||
family: "Apple Symbols".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
#[cfg(target_os = "macos")]
|
||||
font.push(FontAttributes {
|
||||
family: "Zapf Dingbats".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
#[cfg(target_os = "macos")]
|
||||
font.push(FontAttributes {
|
||||
family: "Apple LiGothic".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
|
||||
// Fallback font that has unicode replacement character
|
||||
#[cfg(windows)]
|
||||
font.push(FontAttributes {
|
||||
family: "Segoe UI".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
#[cfg(windows)]
|
||||
font.push(FontAttributes {
|
||||
family: "Segoe UI Emoji".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
#[cfg(windows)]
|
||||
font.push(FontAttributes {
|
||||
family: "Segoe UI Symbol".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
font.push(FontAttributes {
|
||||
family: "Noto Color Emoji".into(),
|
||||
bold: None,
|
||||
italic: None,
|
||||
bold: false,
|
||||
italic: false,
|
||||
});
|
||||
|
||||
font
|
||||
|
@ -56,14 +56,12 @@ impl FontSystem for CoreTextSystem {
|
||||
None => continue,
|
||||
};
|
||||
if let Some(desc) = col.get_descriptors() {
|
||||
let want_bold = *font_attr.bold.as_ref().unwrap_or(&false);
|
||||
let want_italic = *font_attr.italic.as_ref().unwrap_or(&false);
|
||||
for d in desc.iter() {
|
||||
let traits = d.traits().symbolic_traits();
|
||||
if want_bold != traits.is_bold() {
|
||||
if font_attr.bold != traits.is_bold() {
|
||||
continue;
|
||||
}
|
||||
if want_italic != traits.is_italic() {
|
||||
if font_attr.italic != traits.is_italic() {
|
||||
continue;
|
||||
}
|
||||
let has_color = (traits & kCTFontTraitColorGlyphs) == kCTFontTraitColorGlyphs;
|
||||
|
@ -29,10 +29,10 @@ impl FontSystem for FontConfigAndFreeType {
|
||||
for attr in style.font_with_fallback() {
|
||||
let mut pattern = FontPattern::new()?;
|
||||
pattern.family(&attr.family)?;
|
||||
if *attr.bold.as_ref().unwrap_or(&false) {
|
||||
if attr.bold {
|
||||
pattern.add_integer("weight", 200)?;
|
||||
}
|
||||
if *attr.italic.as_ref().unwrap_or(&false) {
|
||||
if attr.italic {
|
||||
pattern.add_integer("slant", 100)?;
|
||||
}
|
||||
pattern.add_double("size", config.font_size * font_scale)?;
|
||||
|
@ -11,12 +11,12 @@ pub fn load_system_fonts(
|
||||
let mut font_props = system_fonts::FontPropertyBuilder::new()
|
||||
.family(&font_attr.family)
|
||||
.monospace();
|
||||
font_props = if *font_attr.bold.as_ref().unwrap_or(&false) {
|
||||
font_props = if font_attr.bold {
|
||||
font_props.bold()
|
||||
} else {
|
||||
font_props
|
||||
};
|
||||
font_props = if *font_attr.italic.as_ref().unwrap_or(&false) {
|
||||
font_props = if font_attr.italic {
|
||||
font_props.italic()
|
||||
} else {
|
||||
font_props
|
||||
|
Loading…
Reference in New Issue
Block a user