diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2022-01-29 23:06:44 +0300 |
---|---|---|
committer | Kirill Chibisov <contact@kchibisov.com> | 2022-02-10 03:17:21 +0300 |
commit | 4628f561551ba59472a1e390bc86064bee210aca (patch) | |
tree | 1ecba1ba78acb898944540eef26babef5afb2ef3 | |
parent | f466fde35d37bb7f358bdba56c85080c90938a60 (diff) | |
download | alacritty-4628f561551ba59472a1e390bc86064bee210aca.tar.gz alacritty-4628f561551ba59472a1e390bc86064bee210aca.zip |
Account for font.offset and glyph.offset in built-in font
This commit takes into account `font.offset` and `font.glyph_offset`
when generating built-in font.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | alacritty/src/renderer/builtin_font.rs | 37 | ||||
-rw-r--r-- | alacritty/src/renderer/mod.rs | 14 |
3 files changed, 42 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 74887563..5f48967f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - OSC 4 not handling `?` - `?` in OSC strings reporting default colors instead of modified ones - OSC 104 not clearing colors when second parameter is empty +- Builtin font lines not contiguous when `font.offset` is used +- `font.glyph_offset` is no longer applied on builtin font ## 0.10.0 diff --git a/alacritty/src/renderer/builtin_font.rs b/alacritty/src/renderer/builtin_font.rs index 17e85799..e905a1ef 100644 --- a/alacritty/src/renderer/builtin_font.rs +++ b/alacritty/src/renderer/builtin_font.rs @@ -5,6 +5,8 @@ use std::{cmp, mem}; use crossfont::{BitmapBuffer, Metrics, RasterizedGlyph}; +use crate::config::ui_config::Delta; + // Colors which are used for filling shade variants. const COLOR_FILL_ALPHA_STEP_1: Pixel = Pixel { _r: 192, _g: 192, _b: 192 }; const COLOR_FILL_ALPHA_STEP_2: Pixel = Pixel { _r: 128, _g: 128, _b: 128 }; @@ -14,17 +16,29 @@ const COLOR_FILL_ALPHA_STEP_3: Pixel = Pixel { _r: 64, _g: 64, _b: 64 }; const COLOR_FILL: Pixel = Pixel { _r: 255, _g: 255, _b: 255 }; /// Returns the rasterized glyph if the character is part of the built-in font. -pub fn builtin_glyph(character: char, metrics: &Metrics) -> Option<RasterizedGlyph> { - match character { +pub fn builtin_glyph( + character: char, + metrics: &Metrics, + offset: &Delta<i8>, + glyph_offset: &Delta<i8>, +) -> Option<RasterizedGlyph> { + let mut glyph = match character { // Box drawing characters and block elements. - '\u{2500}'..='\u{259f}' => Some(box_drawing(character, metrics)), - _ => None, - } + '\u{2500}'..='\u{259f}' => box_drawing(character, metrics, offset), + _ => return None, + }; + + // Since we want to ignore `glyph_offset` for the built-in font, subtract it to compensate its + // addition when loading glyphs in the renderer. + glyph.left -= glyph_offset.x as i32; + glyph.top -= glyph_offset.y as i32; + + Some(glyph) } -fn box_drawing(character: char, metrics: &Metrics) -> RasterizedGlyph { - let height = metrics.line_height as usize; - let width = metrics.average_advance as usize; +fn box_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> RasterizedGlyph { + let height = (metrics.line_height as i32 + offset.y as i32) as usize; + let width = (metrics.average_advance as i32 + offset.x as i32) as usize; let stroke_size = cmp::max(metrics.underline_thickness as usize, 1); let heavy_stroke_size = stroke_size * 3; // Certain symbols require larger canvas than the cell itself, since for proper contiguous @@ -741,13 +755,16 @@ mod test { strikeout_thickness: 2., }; + let offset = Default::default(); + let glyph_offset = Default::default(); + // Test coverage of box drawing characters. for character in '\u{2500}'..='\u{259f}' { - assert!(builtin_glyph(character, &metrics).is_some()); + assert!(builtin_glyph(character, &metrics, &offset, &glyph_offset).is_some()); } for character in ('\u{2450}'..'\u{2500}').chain('\u{25a0}'..'\u{2600}') { - assert!(builtin_glyph(character, &metrics).is_none()); + assert!(builtin_glyph(character, &metrics, &offset, &glyph_offset).is_none()); } } } diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 50a0e7d7..715d33b5 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -132,6 +132,9 @@ pub struct GlyphCache { /// Font size. font_size: crossfont::Size, + /// Font offset. + font_offset: Delta<i8>, + /// Glyph offset. glyph_offset: Delta<i8>, @@ -168,6 +171,7 @@ impl GlyphCache { bold_key: bold, italic_key: italic, bold_italic_key: bold_italic, + font_offset: font.offset, glyph_offset: font.glyph_offset, metrics, builtin_box_drawing: font.builtin_box_drawing, @@ -274,7 +278,14 @@ impl GlyphCache { // for everything else. let rasterized = self .builtin_box_drawing - .then(|| builtin_font::builtin_glyph(glyph_key.character, &self.metrics)) + .then(|| { + builtin_font::builtin_glyph( + glyph_key.character, + &self.metrics, + &self.font_offset, + &self.glyph_offset, + ) + }) .flatten() .map_or_else(|| self.rasterizer.get_glyph(glyph_key), Ok); @@ -342,6 +353,7 @@ impl GlyphCache { ) -> Result<(), crossfont::Error> { // Update dpi scaling. self.rasterizer.update_dpr(dpr as f32); + self.font_offset = font.offset; // Recompute font keys. let (regular, bold, italic, bold_italic) = |