Allow setting font features on the terminal as well

This commit is contained in:
Antonio Scandurra 2023-03-17 11:42:24 +01:00
parent b2c733baab
commit 7d13b00914
5 changed files with 20 additions and 8 deletions

View File

@ -6769,6 +6769,7 @@ fn build_style(
} }
} else { } else {
let font_family_id = settings.buffer_font_family; let font_family_id = settings.buffer_font_family;
let font_features = settings.buffer_font_features;
let font_family_name = cx.font_cache().family_name(font_family_id).unwrap(); let font_family_name = cx.font_cache().family_name(font_family_id).unwrap();
let font_properties = Default::default(); let font_properties = Default::default();
let font_id = font_cache let font_id = font_cache
@ -6779,6 +6780,7 @@ fn build_style(
text: TextStyle { text: TextStyle {
color: settings.theme.editor.text_color, color: settings.theme.editor.text_color,
font_family_name, font_family_name,
font_features,
font_family_id, font_family_id,
font_id, font_id,
font_size, font_size,

View File

@ -30,6 +30,7 @@ pub struct Features {
pub struct TextStyle { pub struct TextStyle {
pub color: Color, pub color: Color,
pub font_family_name: Arc<str>, pub font_family_name: Arc<str>,
pub font_features: Features,
pub font_family_id: FamilyId, pub font_family_id: FamilyId,
pub font_id: FontId, pub font_id: FontId,
pub font_size: f32, pub font_size: f32,
@ -124,6 +125,7 @@ impl TextStyle {
Ok(Self { Ok(Self {
color, color,
font_family_name, font_family_name,
font_features,
font_family_id, font_family_id,
font_id, font_id,
font_size, font_size,
@ -270,6 +272,7 @@ impl Default for TextStyle {
Self { Self {
color: Default::default(), color: Default::default(),
font_family_name, font_family_name,
font_features: Default::default(),
font_family_id, font_family_id,
font_id, font_id,
font_size: 14., font_size: 14.,
@ -351,6 +354,7 @@ impl ToJson for TextStyle {
json!({ json!({
"color": self.color.to_json(), "color": self.color.to_json(),
"font_family": self.font_family_name.as_ref(), "font_family": self.font_family_name.as_ref(),
"font_features": serde_json::to_value(&self.font_features).unwrap(),
"font_properties": self.font_properties.to_json(), "font_properties": self.font_properties.to_json(),
}) })
} }

View File

@ -227,6 +227,7 @@ pub struct TerminalSettings {
pub working_directory: Option<WorkingDirectory>, pub working_directory: Option<WorkingDirectory>,
pub font_size: Option<f32>, pub font_size: Option<f32>,
pub font_family: Option<String>, pub font_family: Option<String>,
pub font_features: Option<fonts::Features>,
pub env: Option<HashMap<String, String>>, pub env: Option<HashMap<String, String>>,
pub blinking: Option<TerminalBlink>, pub blinking: Option<TerminalBlink>,
pub alternate_scroll: Option<AlternateScroll>, pub alternate_scroll: Option<AlternateScroll>,

View File

@ -505,18 +505,21 @@ impl TerminalElement {
///Configures a text style from the current settings. ///Configures a text style from the current settings.
pub fn make_text_style(font_cache: &FontCache, settings: &Settings) -> TextStyle { pub fn make_text_style(font_cache: &FontCache, settings: &Settings) -> TextStyle {
// TODO allow font features let font_family_name = settings
// Pull the font family from settings properly overriding
let family_id = settings
.terminal_overrides .terminal_overrides
.font_family .font_family
.as_ref() .as_ref()
.or(settings.terminal_defaults.font_family.as_ref()) .or(settings.terminal_defaults.font_family.as_ref())
.and_then(|family_name| { .unwrap_or(&settings.buffer_font_family_name);
font_cache let font_features = settings
.load_family(&[family_name], Default::default()) .terminal_overrides
.log_err() .font_features
}) .or(settings.terminal_defaults.font_features)
.unwrap_or(settings.buffer_font_features);
let family_id = font_cache
.load_family(&[font_family_name], font_features)
.log_err()
.unwrap_or(settings.buffer_font_family); .unwrap_or(settings.buffer_font_family);
let font_size = settings let font_size = settings
@ -533,6 +536,7 @@ impl TerminalElement {
color: settings.theme.editor.text_color, color: settings.theme.editor.text_color,
font_family_id: family_id, font_family_id: family_id,
font_family_name: font_cache.family_name(family_id).unwrap(), font_family_name: font_cache.family_name(family_id).unwrap(),
font_features,
font_id, font_id,
font_size, font_size,
font_properties: Default::default(), font_properties: Default::default(),

View File

@ -243,6 +243,7 @@ impl ThemeTestbench {
color: style.foreground, color: style.foreground,
font_family_id: family_id, font_family_id: family_id,
font_family_name: font_cache.family_name(family_id).unwrap(), font_family_name: font_cache.family_name(family_id).unwrap(),
font_features: settings.buffer_font_features,
font_id, font_id,
font_size, font_size,
font_properties: Default::default(), font_properties: Default::default(),