Use builtin font to draw sextants

Sextants are similar to quadrants and should align with them and
other box drawing, thus use builtin font to align them properly.

Part-of: #7422.
This commit is contained in:
Popa Ioan Alexandru 2024-01-26 14:45:26 +02:00 committed by GitHub
parent 79b686df41
commit b48ab148ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 91 additions and 6 deletions

View File

@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- `alacritty migrate` will ignore null values in yaml instead of erroring out
- Use built-in font for sextant symbols from `U+1FB00` to `U+1FB3B`
### Fixed

View File

@ -1,5 +1,4 @@
//! Hand-rolled drawing of unicode [box drawing](http://www.unicode.org/charts/PDF/U2500.pdf)
//! and [block elements](https://www.unicode.org/charts/PDF/U2580.pdf), and also powerline symbols.
//! Hand-rolled drawing of unicode characters that need to fully cover their character area.
use std::{cmp, mem, ops};
@ -29,7 +28,9 @@ pub fn builtin_glyph(
) -> Option<RasterizedGlyph> {
let mut glyph = match character {
// Box drawing characters and block elements.
'\u{2500}'..='\u{259f}' => box_drawing(character, metrics, offset),
'\u{2500}'..='\u{259f}' | '\u{1fb00}'..='\u{1fb3b}' => {
box_drawing(character, metrics, offset)
},
// Powerline symbols: '','','',''
POWERLINE_TRIANGLE_LTR..=POWERLINE_ARROW_RTL => {
powerline_drawing(character, metrics, offset)?
@ -487,6 +488,89 @@ fn box_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> Raster
// Fourth quadrant.
canvas.draw_rect(x_center, y_center, w_fourth, h_fourth, COLOR_FILL);
},
// Sextants: '🬀', '🬁', '🬂', '🬃', '🬄', '🬅', '🬆', '🬇', '🬈', '🬉', '🬊', '🬋', '🬌', '🬍', '🬎',
// '🬏', '🬐', '🬑', '🬒', '🬓', '🬔', '🬕', '🬖', '🬗', '🬘', '🬙', '🬚', '🬛', '🬜', '🬝', '🬞', '🬟',
// '🬠', '🬡', '🬢', '🬣', '🬤', '🬥', '🬦', '🬧', '🬨', '🬩', '🬪', '🬫', '🬬', '🬭', '🬮', '🬯', '🬰',
// '🬱', '🬲', '🬳', '🬴', '🬵', '🬶', '🬷', '🬸', '🬹', '🬺', '🬻'.
'\u{1fb00}'..='\u{1fb3b}' => {
let x_center = canvas.x_center().round().max(1.);
let y_third = (height as f32 / 3.).round().max(1.);
let y_last_third = height as f32 - 2. * y_third;
let (w_top_left, h_top_left) = match character {
'\u{1fb00}' | '\u{1fb02}' | '\u{1fb04}' | '\u{1fb06}' | '\u{1fb08}'
| '\u{1fb0a}' | '\u{1fb0c}' | '\u{1fb0e}' | '\u{1fb10}' | '\u{1fb12}'
| '\u{1fb15}' | '\u{1fb17}' | '\u{1fb19}' | '\u{1fb1b}' | '\u{1fb1d}'
| '\u{1fb1f}' | '\u{1fb21}' | '\u{1fb23}' | '\u{1fb25}' | '\u{1fb27}'
| '\u{1fb28}' | '\u{1fb2a}' | '\u{1fb2c}' | '\u{1fb2e}' | '\u{1fb30}'
| '\u{1fb32}' | '\u{1fb34}' | '\u{1fb36}' | '\u{1fb38}' | '\u{1fb3a}' => {
(x_center, y_third)
},
_ => (0., 0.),
};
let (w_top_right, h_top_right) = match character {
'\u{1fb01}' | '\u{1fb02}' | '\u{1fb05}' | '\u{1fb06}' | '\u{1fb09}'
| '\u{1fb0a}' | '\u{1fb0d}' | '\u{1fb0e}' | '\u{1fb11}' | '\u{1fb12}'
| '\u{1fb14}' | '\u{1fb15}' | '\u{1fb18}' | '\u{1fb19}' | '\u{1fb1c}'
| '\u{1fb1d}' | '\u{1fb20}' | '\u{1fb21}' | '\u{1fb24}' | '\u{1fb25}'
| '\u{1fb28}' | '\u{1fb2b}' | '\u{1fb2c}' | '\u{1fb2f}' | '\u{1fb30}'
| '\u{1fb33}' | '\u{1fb34}' | '\u{1fb37}' | '\u{1fb38}' | '\u{1fb3b}' => {
(x_center, y_third)
},
_ => (0., 0.),
};
let (w_mid_left, h_mid_left) = match character {
'\u{1fb03}' | '\u{1fb04}' | '\u{1fb05}' | '\u{1fb06}' | '\u{1fb0b}'
| '\u{1fb0c}' | '\u{1fb0d}' | '\u{1fb0e}' | '\u{1fb13}' | '\u{1fb14}'
| '\u{1fb15}' | '\u{1fb1a}' | '\u{1fb1b}' | '\u{1fb1c}' | '\u{1fb1d}'
| '\u{1fb22}' | '\u{1fb23}' | '\u{1fb24}' | '\u{1fb25}' | '\u{1fb29}'
| '\u{1fb2a}' | '\u{1fb2b}' | '\u{1fb2c}' | '\u{1fb31}' | '\u{1fb32}'
| '\u{1fb33}' | '\u{1fb34}' | '\u{1fb39}' | '\u{1fb3a}' | '\u{1fb3b}' => {
(x_center, y_third)
},
_ => (0., 0.),
};
let (w_mid_right, h_mid_right) = match character {
'\u{1fb07}' | '\u{1fb08}' | '\u{1fb09}' | '\u{1fb0a}' | '\u{1fb0b}'
| '\u{1fb0c}' | '\u{1fb0d}' | '\u{1fb0e}' | '\u{1fb16}' | '\u{1fb17}'
| '\u{1fb18}' | '\u{1fb19}' | '\u{1fb1a}' | '\u{1fb1b}' | '\u{1fb1c}'
| '\u{1fb1d}' | '\u{1fb26}' | '\u{1fb27}' | '\u{1fb28}' | '\u{1fb29}'
| '\u{1fb2a}' | '\u{1fb2b}' | '\u{1fb2c}' | '\u{1fb35}' | '\u{1fb36}'
| '\u{1fb37}' | '\u{1fb38}' | '\u{1fb39}' | '\u{1fb3a}' | '\u{1fb3b}' => {
(x_center, y_third)
},
_ => (0., 0.),
};
let (w_bottom_left, h_bottom_left) = match character {
'\u{1fb0f}' | '\u{1fb10}' | '\u{1fb11}' | '\u{1fb12}' | '\u{1fb13}'
| '\u{1fb14}' | '\u{1fb15}' | '\u{1fb16}' | '\u{1fb17}' | '\u{1fb18}'
| '\u{1fb19}' | '\u{1fb1a}' | '\u{1fb1b}' | '\u{1fb1c}' | '\u{1fb1d}'
| '\u{1fb2d}' | '\u{1fb2e}' | '\u{1fb2f}' | '\u{1fb30}' | '\u{1fb31}'
| '\u{1fb32}' | '\u{1fb33}' | '\u{1fb34}' | '\u{1fb35}' | '\u{1fb36}'
| '\u{1fb37}' | '\u{1fb38}' | '\u{1fb39}' | '\u{1fb3a}' | '\u{1fb3b}' => {
(x_center, y_last_third)
},
_ => (0., 0.),
};
let (w_bottom_right, h_bottom_right) = match character {
'\u{1fb1e}' | '\u{1fb1f}' | '\u{1fb20}' | '\u{1fb21}' | '\u{1fb22}'
| '\u{1fb23}' | '\u{1fb24}' | '\u{1fb25}' | '\u{1fb26}' | '\u{1fb27}'
| '\u{1fb28}' | '\u{1fb29}' | '\u{1fb2a}' | '\u{1fb2b}' | '\u{1fb2c}'
| '\u{1fb2d}' | '\u{1fb2e}' | '\u{1fb2f}' | '\u{1fb30}' | '\u{1fb31}'
| '\u{1fb32}' | '\u{1fb33}' | '\u{1fb34}' | '\u{1fb35}' | '\u{1fb36}'
| '\u{1fb37}' | '\u{1fb38}' | '\u{1fb39}' | '\u{1fb3a}' | '\u{1fb3b}' => {
(x_center, y_last_third)
},
_ => (0., 0.),
};
canvas.draw_rect(0., 0., w_top_left, h_top_left, COLOR_FILL);
canvas.draw_rect(x_center, 0., w_top_right, h_top_right, COLOR_FILL);
canvas.draw_rect(0., y_third, w_mid_left, h_mid_left, COLOR_FILL);
canvas.draw_rect(x_center, y_third, w_mid_right, h_mid_right, COLOR_FILL);
canvas.draw_rect(0., y_third * 2., w_bottom_left, h_bottom_left, COLOR_FILL);
canvas.draw_rect(x_center, y_third * 2., w_bottom_right, h_bottom_right, COLOR_FILL);
},
_ => unreachable!(),
}
@ -926,7 +1010,7 @@ mod tests {
let glyph_offset = Default::default();
// Test coverage of box drawing characters.
for character in '\u{2500}'..='\u{259f}' {
for character in ('\u{2500}'..='\u{259f}').chain('\u{1fb00}'..='\u{1fb3b}') {
assert!(builtin_glyph(character, &METRICS, &offset, &glyph_offset).is_some());
}

View File

@ -272,8 +272,8 @@ macOS: { family = _"Menlo"_, style = _"Regular"_ }
*builtin_box_drawing* = _true_ | _false_
When _true_, Alacritty will use a custom built-in font for box drawing
characters (Unicode points _U+2500_ - _U+259F_) and powerline symbols
(Unicode points _U+E0B0_ - _U+E0B3_).
characters (Unicode points _U+2500_ - _U+259F_), legacy computing symbols
(_U+1FB00_ - _U+1FB3B_), and powerline symbols (_U+E0B0_ - _U+E0B3_).
Default: _true_