diff options
author | Chris Morgan <me@chrismorgan.info> | 2019-08-25 20:46:52 +1000 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2019-08-25 14:30:42 +0200 |
commit | e69f259d0e68a1ac382028cad7a50eb4652ef12a (patch) | |
tree | 2ce124c6eb7e484ff1b5b42019feb53a4c09c182 /alacritty_terminal/src | |
parent | ad0365219f7f264ef0fdf0b3e4401bad7ac40e55 (diff) | |
download | alacritty-e69f259d0e68a1ac382028cad7a50eb4652ef12a.tar.gz alacritty-e69f259d0e68a1ac382028cad7a50eb4652ef12a.zip |
Add bold italic font support
If the terminal escape sequences for bold and italic text are active,
the text should be rendered as bold and italic. However, due to missing
support in Alacritty, it would always render this text in bold.
This adds support for combining the bold and italic escapes to render
text in both styles and allows users to override the font for this
scenario using the `font.bold_italic` configuration option.
Diffstat (limited to 'alacritty_terminal/src')
-rw-r--r-- | alacritty_terminal/src/config/font.rs | 20 | ||||
-rw-r--r-- | alacritty_terminal/src/renderer/mod.rs | 42 |
2 files changed, 44 insertions, 18 deletions
diff --git a/alacritty_terminal/src/config/font.rs b/alacritty_terminal/src/config/font.rs index 3c78ad29..6148c982 100644 --- a/alacritty_terminal/src/config/font.rs +++ b/alacritty_terminal/src/config/font.rs @@ -23,11 +23,15 @@ pub struct Font { /// Bold font face #[serde(deserialize_with = "failure_default")] - italic: SecondaryFontDescription, + bold: SecondaryFontDescription, /// Italic font face #[serde(deserialize_with = "failure_default")] - bold: SecondaryFontDescription, + italic: SecondaryFontDescription, + + /// Bold italic font face + #[serde(deserialize_with = "failure_default")] + bold_italic: SecondaryFontDescription, /// Font size in points #[serde(deserialize_with = "DeserializeSize::deserialize")] @@ -53,6 +57,7 @@ impl Default for Font { normal: Default::default(), bold: Default::default(), italic: Default::default(), + bold_italic: Default::default(), glyph_offset: Default::default(), offset: Default::default(), #[cfg(target_os = "macos")] @@ -72,14 +77,19 @@ impl Font { &self.normal } + // Get bold font description + pub fn bold(&self) -> FontDescription { + self.bold.desc(&self.normal) + } + // Get italic font description pub fn italic(&self) -> FontDescription { self.italic.desc(&self.normal) } - // Get bold font description - pub fn bold(&self) -> FontDescription { - self.bold.desc(&self.normal) + // Get bold italic font description + pub fn bold_italic(&self) -> FontDescription { + self.bold_italic.desc(&self.normal) } #[cfg(target_os = "macos")] diff --git a/alacritty_terminal/src/renderer/mod.rs b/alacritty_terminal/src/renderer/mod.rs index f074c6d5..2a0529da 100644 --- a/alacritty_terminal/src/renderer/mod.rs +++ b/alacritty_terminal/src/renderer/mod.rs @@ -164,11 +164,14 @@ pub struct GlyphCache { /// regular font font_key: FontKey, + /// bold font + bold_key: FontKey, + /// italic font italic_key: FontKey, - /// bold font - bold_key: FontKey, + /// bold italic font + bold_italic_key: FontKey, /// font size font_size: font::Size, @@ -188,7 +191,7 @@ impl GlyphCache { where L: LoadGlyph, { - let (regular, bold, italic) = Self::compute_font_keys(font, &mut rasterizer)?; + let (regular, bold, italic, bold_italic) = Self::compute_font_keys(font, &mut rasterizer)?; // Need to load at least one glyph for the face before calling metrics. // The glyph requested here ('m' at the time of writing) has no special @@ -205,6 +208,7 @@ impl GlyphCache { font_key: regular, bold_key: bold, italic_key: italic, + bold_italic_key: bold_italic, glyph_offset: font.glyph_offset, metrics, }; @@ -212,6 +216,7 @@ impl GlyphCache { cache.load_glyphs_for_font(regular, loader); cache.load_glyphs_for_font(bold, loader); cache.load_glyphs_for_font(italic, loader); + cache.load_glyphs_for_font(bold_italic, loader); Ok(cache) } @@ -223,11 +228,11 @@ impl GlyphCache { } } - /// Computes font keys for (Regular, Bold, Italic) + /// Computes font keys for (Regular, Bold, Italic, Bold Italic) fn compute_font_keys( font: &config::Font, rasterizer: &mut Rasterizer, - ) -> Result<(FontKey, FontKey, FontKey), font::Error> { + ) -> Result<(FontKey, FontKey, FontKey, FontKey), font::Error> { let size = font.size; // Load regular font @@ -256,7 +261,13 @@ impl GlyphCache { let italic = load_or_regular(italic_desc); - Ok((regular, bold, italic)) + // Load bold italic font + let bold_italic_desc = + Self::make_desc(&font.bold_italic(), font::Slant::Italic, font::Weight::Bold); + + let bold_italic = load_or_regular(bold_italic_desc); + + Ok((regular, bold, italic, bold_italic)) } fn make_desc( @@ -314,7 +325,8 @@ impl GlyphCache { // Recompute font keys let font = font.to_owned().with_size(size); - let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?; + let (regular, bold, italic, bold_italic) = + Self::compute_font_keys(&font, &mut self.rasterizer)?; self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size })?; let metrics = self.rasterizer.metrics(regular, size)?; @@ -325,11 +337,13 @@ impl GlyphCache { self.font_key = regular; self.bold_key = bold; self.italic_key = italic; + self.bold_italic_key = bold_italic; self.metrics = metrics; self.load_glyphs_for_font(regular, loader); self.load_glyphs_for_font(bold, loader); self.load_glyphs_for_font(italic, loader); + self.load_glyphs_for_font(bold_italic, loader); Ok(()) } @@ -1013,12 +1027,14 @@ impl<'a> RenderApi<'a> { // Get font key for cell // FIXME this is super inefficient. - let font_key = if cell.flags.contains(cell::Flags::BOLD) { - glyph_cache.bold_key - } else if cell.flags.contains(cell::Flags::ITALIC) { - glyph_cache.italic_key - } else { - glyph_cache.font_key + let font_key = match ( + cell.flags.contains(cell::Flags::BOLD), + cell.flags.contains(cell::Flags::ITALIC), + ) { + (false, false) => glyph_cache.font_key, + (true, false) => glyph_cache.bold_key, + (false, true) => glyph_cache.italic_key, + (true, true) => glyph_cache.bold_italic_key, }; // Don't render text of HIDDEN cells |