1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

fonts: FontSlant -> FontStyle

after reading around italic vs. oblique, I think "slant" is a misleading
way to categorize this, as slant implies something about the angle of
the font but really the difference between italic and oblique is purely
stylistic and without a suggested angle.

style more closely matches the CSS name which is well understood by
many, so we go for that.

refs: #1646
This commit is contained in:
Wez Furlong 2022-03-12 09:44:21 -07:00
parent 1aad1cf1a2
commit 6df26b476e
7 changed files with 75 additions and 75 deletions

View File

@ -10,13 +10,13 @@ use termwiz::color::RgbColor;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Hash, Display, PartialOrd, Ord,
)]
pub enum FontSlant {
pub enum FontStyle {
Normal,
Italic,
Oblique,
}
impl Default for FontSlant {
impl Default for FontStyle {
fn default() -> Self {
Self::Normal
}
@ -350,7 +350,7 @@ pub struct FontAttributes {
pub stretch: FontStretch,
/// Whether the font should be an italic variant
#[serde(default)]
pub slant: FontSlant,
pub style: FontStyle,
pub is_fallback: bool,
pub is_synthetic: bool,
@ -369,8 +369,8 @@ impl std::fmt::Display for FontAttributes {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(
fmt,
"wezterm.font('{}', {{weight={}, stretch='{}', slant={}}})",
self.family, self.weight, self.stretch, self.slant
"wezterm.font('{}', {{weight={}, stretch='{}', style={}}})",
self.family, self.weight, self.stretch, self.style
)
}
}
@ -381,7 +381,7 @@ impl FontAttributes {
family: family.into(),
weight: FontWeight::default(),
stretch: FontStretch::default(),
slant: FontSlant::Normal,
style: FontStyle::Normal,
is_fallback: false,
is_synthetic: false,
harfbuzz_features: None,
@ -396,7 +396,7 @@ impl FontAttributes {
family: family.into(),
weight: FontWeight::default(),
stretch: FontStretch::default(),
slant: FontSlant::Normal,
style: FontStyle::Normal,
is_fallback: true,
is_synthetic: false,
harfbuzz_features: None,
@ -413,7 +413,7 @@ impl Default for FontAttributes {
family: "JetBrains Mono".into(),
weight: FontWeight::default(),
stretch: FontStretch::default(),
slant: FontSlant::Normal,
style: FontStyle::Normal,
is_fallback: false,
is_synthetic: false,
harfbuzz_features: None,
@ -550,7 +550,7 @@ impl TextStyle {
.iter()
.map(|attr| {
let mut attr = attr.clone();
attr.slant = FontSlant::Italic;
attr.style = FontStyle::Italic;
attr.is_synthetic = true;
attr
})

View File

@ -1,6 +1,6 @@
use crate::keyassignment::KeyAssignment;
use crate::{
FontAttributes, FontSlant, FontStretch, FontWeight, FreeTypeLoadTarget, Gradient, TextStyle,
FontAttributes, FontStretch, FontStyle, FontWeight, FreeTypeLoadTarget, Gradient, TextStyle,
};
use anyhow::anyhow;
use bstr::BString;
@ -451,8 +451,8 @@ struct TextStyleAttributes {
pub stretch: FontStretch,
/// Whether the font should be an italic variant
#[serde(default)]
pub slant: FontSlant,
// Ideally we'd simply use serde's aliasing functionality on the `slant`
pub style: FontStyle,
// Ideally we'd simply use serde's aliasing functionality on the `style`
// field to support backwards compatibility, but aliases are invisible
// to serde_lua, so we do a little fixup here ourselves in our from_lua impl.
italic: Option<bool>,
@ -466,10 +466,10 @@ impl<'lua> FromLua<'lua> for TextStyleAttributes {
fn from_lua(value: Value<'lua>, _lua: &'lua Lua) -> Result<Self, mlua::Error> {
let mut attr: TextStyleAttributes = from_lua_value(value)?;
if let Some(italic) = attr.italic.take() {
attr.slant = if italic {
FontSlant::Italic
attr.style = if italic {
FontStyle::Italic
} else {
FontSlant::Normal
FontStyle::Normal
};
}
Ok(attr)
@ -487,8 +487,8 @@ struct LuaFontAttributes {
pub stretch: FontStretch,
/// Whether the font should be an italic variant
#[serde(default)]
pub slant: FontSlant,
// Ideally we'd simply use serde's aliasing functionality on the `slant`
pub style: FontStyle,
// Ideally we'd simply use serde's aliasing functionality on the `style`
// field to support backwards compatibility, but aliases are invisible
// to serde_lua, so we do a little fixup here ourselves in our from_lua impl.
#[serde(default)]
@ -514,10 +514,10 @@ impl<'lua> FromLua<'lua> for LuaFontAttributes {
v => {
let mut attr: LuaFontAttributes = from_lua_value(v)?;
if let Some(italic) = attr.italic.take() {
attr.slant = if italic {
FontSlant::Italic
attr.style = if italic {
FontStyle::Italic
} else {
FontSlant::Normal
FontStyle::Normal
};
}
Ok(attr)
@ -549,7 +549,7 @@ fn font<'lua>(
None => map_defaults.weight.unwrap_or(FontWeight::REGULAR),
};
attrs.stretch = map_defaults.stretch;
attrs.slant = map_defaults.slant;
attrs.style = map_defaults.style;
text_style.foreground = map_defaults.foreground;
}
@ -557,7 +557,7 @@ fn font<'lua>(
family: attrs.family,
stretch: attrs.stretch,
weight: attrs.weight,
slant: attrs.slant,
style: attrs.style,
is_fallback: false,
is_synthetic: false,
harfbuzz_features: attrs.harfbuzz_features,
@ -594,7 +594,7 @@ fn font_with_fallback<'lua>(
None => map_defaults.weight.unwrap_or(FontWeight::REGULAR),
};
attrs.stretch = map_defaults.stretch;
attrs.slant = map_defaults.slant;
attrs.style = map_defaults.style;
text_style.foreground = map_defaults.foreground;
}
@ -602,7 +602,7 @@ fn font_with_fallback<'lua>(
family: attrs.family,
stretch: attrs.stretch,
weight: attrs.weight,
slant: attrs.slant,
style: attrs.style,
is_fallback: idx != 0,
is_synthetic: false,
harfbuzz_features: attrs.harfbuzz_features,

View File

@ -5,7 +5,7 @@ use crate::rasterizer::{new_rasterizer, FontRasterizer};
use crate::shaper::{new_shaper, FontShaper, PresentationWidth};
use anyhow::{Context, Error};
use config::{
configuration, ConfigHandle, FontAttributes, FontRasterizerSelection, FontSlant, FontStretch,
configuration, ConfigHandle, FontAttributes, FontRasterizerSelection, FontStretch, FontStyle,
FontWeight, TextStyle,
};
use rangeset::RangeSet;
@ -697,7 +697,7 @@ impl FontConfigInner {
for attr in &attributes {
if !attr.is_synthetic && !attr.is_fallback && !loaded.contains(attr) {
let styled_extra = if attr.weight != FontWeight::default()
|| attr.slant != FontSlant::default()
|| attr.style != FontStyle::default()
|| attr.stretch != FontStretch::default()
{
". An alternative variant of the font was requested; \

View File

@ -2,7 +2,7 @@
use crate::locator::{FontDataSource, FontLocator, FontOrigin};
use crate::parser::ParsedFont;
use config::{FontAttributes, FontSlant, FontStretch, FontWeight};
use config::{FontAttributes, FontStretch, FontStyle, FontWeight};
use core_foundation::array::CFArray;
use core_foundation::base::TCFType;
use core_foundation::dictionary::CFDictionary;
@ -190,7 +190,7 @@ fn build_fallback_list_impl() -> anyhow::Result<Vec<ParsedFont>> {
family: "Apple Symbols".to_string(),
weight: FontWeight::REGULAR,
stretch: FontStretch::Normal,
slant: FontSlant::Normal,
slant: FontStyle::Normal,
is_fallback: true,
is_synthetic: true,
harfbuzz_features: None,
@ -208,7 +208,7 @@ fn build_fallback_list_impl() -> anyhow::Result<Vec<ParsedFont>> {
fonts.retain(|f| {
f.weight() == FontWeight::REGULAR
&& f.stretch() == FontStretch::Normal
&& f.slant() == FontSlant::Normal
&& f.slant() == FontStyle::Normal
});
let mut seen = HashSet::new();

View File

@ -2,7 +2,7 @@ use crate::fcwrap;
use crate::locator::{FontDataHandle, FontDataSource, FontLocator, FontOrigin};
use crate::parser::ParsedFont;
use anyhow::Context;
use config::{FontAttributes, FontSlant, FontWeight};
use config::{FontAttributes, FontStyle, FontWeight};
use fcwrap::{CharSet, FontSet, Pattern as FontPattern, FC_DUAL, FC_MONO};
use std::collections::HashSet;
use std::convert::TryInto;
@ -118,10 +118,10 @@ impl FontLocator for FontConfigFontLocator {
pattern.add_integer("weight", to_fc_weight(attr.weight))?;
pattern.add_integer(
"slant",
match attr.slant {
FontSlant::Normal => fcwrap::FC_SLANT_ROMAN,
FontSlant::Italic => fcwrap::FC_SLANT_ITALIC,
FontSlant::Oblique => fcwrap::FC_SLANT_OBLIQUE,
match attr.style {
FontStyle::Normal => fcwrap::FC_SLANT_ROMAN,
FontStyle::Italic => fcwrap::FC_SLANT_ITALIC,
FontStyle::Oblique => fcwrap::FC_SLANT_OBLIQUE,
},
)?;
pattern.config_substitute(fcwrap::MatchKind::Pattern)?;

View File

@ -3,7 +3,7 @@
use crate::locator::{FontDataSource, FontLocator, FontOrigin};
use crate::parser::{best_matching_font, parse_and_collect_font_info, ParsedFont};
use config::{
FontAttributes, FontSlant as WTFontSlant, FontStretch as WTFontStretch,
FontAttributes, FontStretch as WTFontStretch, FontStyle as WTFontStyle,
FontWeight as WTFontWeight,
};
use dwrote::{FontDescriptor, FontStretch, FontStyle, FontWeight};
@ -102,7 +102,7 @@ fn load_font(font_attr: &FontAttributes, pixel_size: u16) -> anyhow::Result<Pars
lfEscapement: 0,
lfOrientation: 0,
lfWeight: font_attr.weight.to_opentype_weight() as _,
lfItalic: if font_attr.slant != WTFontSlant::Normal {
lfItalic: if font_attr.slant != WTFontStyle::Normal {
1
} else {
0
@ -150,7 +150,7 @@ pub fn parse_log_font(log_font: &LOGFONTW, hdc: HDC) -> anyhow::Result<(ParsedFo
let mut attr = FontAttributes::new(&name);
attr.weight = config::FontWeight::from_opentype_weight(log_font.lfWeight as u16);
if log_font.lfItalic == 1 {
attr.slant = WTFontSlant::Italic;
attr.slant = WTFontStyle::Italic;
}
let mut font_info = vec![];
@ -171,9 +171,9 @@ fn attributes_to_descriptor(font_attr: &FontAttributes) -> FontDescriptor {
weight: FontWeight::from_u32(font_attr.weight.to_opentype_weight() as u32),
stretch: FontStretch::Normal,
style: match font_attr.slant {
WTFontSlant::Italic => FontStyle::Italic,
WTFontSlant::Oblique => FontStyle::Oblique,
WTFontSlant::Normal => FontStyle::Normal,
WTFontStyle::Italic => FontStyle::Italic,
WTFontStyle::Oblique => FontStyle::Oblique,
WTFontStyle::Normal => FontStyle::Normal,
},
}
}
@ -319,7 +319,7 @@ impl FontLocator for GdiFontLocator {
let attr = FontAttributes {
weight: WTFontWeight::from_opentype_weight(font.weight().to_u32() as _),
stretch: WTFontStretch::from_opentype_stretch(font.stretch().to_u32() as _),
slant: WTFontSlant::Normal,
slant: WTFontStyle::Normal,
family: font.family_name(),
is_fallback: true,
is_synthetic: true,

View File

@ -1,6 +1,6 @@
use crate::locator::{FontDataHandle, FontDataSource, FontOrigin};
use crate::shaper::GlyphInfo;
use config::{FontAttributes, FontSlant, FreeTypeLoadFlags, FreeTypeLoadTarget};
use config::{FontAttributes, FontStyle, FreeTypeLoadFlags, FreeTypeLoadTarget};
pub use config::{FontStretch, FontWeight};
use rangeset::RangeSet;
use std::cmp::Ordering;
@ -17,7 +17,7 @@ pub struct ParsedFont {
names: Names,
weight: FontWeight,
stretch: FontStretch,
slant: FontSlant,
style: FontStyle,
cap_height: Option<f64>,
pub handle: FontDataHandle,
coverage: Mutex<RangeSet<u32>>,
@ -39,7 +39,7 @@ impl std::fmt::Debug for ParsedFont {
.field("names", &self.names)
.field("weight", &self.weight)
.field("stretch", &self.stretch)
.field("slant", &self.slant)
.field("style", &self.style)
.field("handle", &self.handle)
.field("cap_height", &self.cap_height)
.field("synthesize_italic", &self.synthesize_italic)
@ -57,7 +57,7 @@ impl Clone for ParsedFont {
names: self.names.clone(),
weight: self.weight,
stretch: self.stretch,
slant: self.slant,
style: self.style,
synthesize_italic: self.synthesize_italic,
synthesize_bold: self.synthesize_bold,
synthesize_dim: self.synthesize_dim,
@ -80,7 +80,7 @@ impl PartialEq for ParsedFont {
fn eq(&self, rhs: &Self) -> bool {
self.stretch == rhs.stretch
&& self.weight == rhs.weight
&& self.slant == rhs.slant
&& self.style == rhs.style
&& self.names == rhs.names
}
}
@ -93,7 +93,7 @@ impl Ord for ParsedFont {
o @ Ordering::Less | o @ Ordering::Greater => o,
Ordering::Equal => match self.weight.cmp(&rhs.weight) {
o @ Ordering::Less | o @ Ordering::Greater => o,
Ordering::Equal => match self.slant.cmp(&rhs.slant) {
Ordering::Equal => match self.style.cmp(&rhs.style) {
o @ Ordering::Less | o @ Ordering::Greater => o,
Ordering::Equal => self.handle.cmp(&rhs.handle),
},
@ -151,8 +151,8 @@ impl ParsedFont {
pub fn lua_name(&self) -> String {
format!(
"wezterm.font(\"{}\", {{weight={}, stretch=\"{}\", slant={}}})",
self.names.family, self.weight, self.stretch, self.slant
"wezterm.font(\"{}\", {{weight={}, stretch=\"{}\", style={}}})",
self.names.family, self.weight, self.stretch, self.style
)
}
@ -178,7 +178,7 @@ impl ParsedFont {
if p.weight == FontWeight::REGULAR
&& p.stretch == FontStretch::Normal
&& p.slant == FontSlant::Normal
&& p.style == FontStyle::Normal
&& p.freetype_render_target.is_none()
&& p.freetype_load_target.is_none()
&& p.freetype_load_flags.is_none()
@ -193,8 +193,8 @@ impl ParsedFont {
if p.stretch != FontStretch::Normal {
code.push_str(&format!(", stretch=\"{}\"", p.stretch));
}
if p.slant != FontSlant::Normal {
code.push_str(&format!(", slant=\"{}\"", p.slant));
if p.style != FontStyle::Normal {
code.push_str(&format!(", style=\"{}\"", p.style));
}
if let Some(item) = p.freetype_load_flags {
code.push_str(&format!(", freetype_load_flags=\"{}\"", item.to_string()));
@ -226,10 +226,10 @@ impl ParsedFont {
}
pub fn from_face(face: &crate::ftwrap::Face, handle: FontDataHandle) -> anyhow::Result<Self> {
let slant = if face.italic() {
FontSlant::Italic
let style = if face.italic() {
FontStyle::Italic
} else {
FontSlant::Normal
FontStyle::Normal
};
let (ot_weight, width) = face.weight_and_width();
let weight = FontWeight::from_opentype_weight(ot_weight);
@ -244,34 +244,34 @@ impl ParsedFont {
let names = Names::from_ft_face(&face);
// Objectively gross, but freetype's italic property is very coarse grained.
// fontconfig resorts to name matching, so we do too :-/
let slant = match slant {
FontSlant::Normal => {
let style = match style {
FontStyle::Normal => {
let lower = names.full_name.to_lowercase();
if lower.contains("italic") || lower.contains("kursiv") {
FontSlant::Italic
FontStyle::Italic
} else if lower.contains("oblique") {
FontSlant::Oblique
FontStyle::Oblique
} else {
FontSlant::Normal
FontStyle::Normal
}
}
FontSlant::Italic => {
FontStyle::Italic => {
let lower = names.full_name.to_lowercase();
if lower.contains("oblique") {
FontSlant::Oblique
FontStyle::Oblique
} else {
FontSlant::Italic
FontStyle::Italic
}
}
// Currently "impossible" because freetype only knows italic or normal
FontSlant::Oblique => FontSlant::Oblique,
FontStyle::Oblique => FontStyle::Oblique,
};
Ok(Self {
names,
weight,
stretch,
slant,
style,
synthesize_italic: false,
synthesize_bold: false,
synthesize_dim: false,
@ -321,8 +321,8 @@ impl ParsedFont {
self.stretch
}
pub fn slant(&self) -> FontSlant {
self.slant
pub fn style(&self) -> FontStyle {
self.style
}
pub fn matches_name(&self, attr: &FontAttributes) -> bool {
@ -413,18 +413,18 @@ impl ParsedFont {
candidates.retain(|&idx| fonts[idx].stretch == stretch);
// Now match style: italics.
let styles = match attr.slant {
FontSlant::Normal => [FontSlant::Normal, FontSlant::Italic, FontSlant::Oblique],
FontSlant::Italic => [FontSlant::Italic, FontSlant::Oblique, FontSlant::Normal],
FontSlant::Oblique => [FontSlant::Oblique, FontSlant::Italic, FontSlant::Normal],
let styles = match attr.style {
FontStyle::Normal => [FontStyle::Normal, FontStyle::Italic, FontStyle::Oblique],
FontStyle::Italic => [FontStyle::Italic, FontStyle::Oblique, FontStyle::Normal],
FontStyle::Oblique => [FontStyle::Oblique, FontStyle::Italic, FontStyle::Normal],
};
let slant = *styles
let style = *styles
.iter()
.filter(|&&slant| candidates.iter().any(|&idx| fonts[idx].slant == slant))
.filter(|&&style| candidates.iter().any(|&idx| fonts[idx].style == style))
.next()?;
// Reduce to matching italics
candidates.retain(|&idx| fonts[idx].slant == slant);
candidates.retain(|&idx| fonts[idx].style == style);
// And now match by font weight
let query_weight = attr.weight.to_opentype_weight();
@ -525,7 +525,7 @@ impl ParsedFont {
self.freetype_load_target = attr.freetype_load_target;
self.freetype_load_flags = attr.freetype_load_flags;
self.synthesize_italic = self.slant == FontSlant::Normal && attr.slant != FontSlant::Normal;
self.synthesize_italic = self.style == FontStyle::Normal && attr.style != FontStyle::Normal;
self.synthesize_bold = attr.weight >= FontWeight::BOLD
&& attr.weight > self.weight
&& self.weight <= FontWeight::REGULAR;