Skip to content

Commit

Permalink
Add option to control built-in box drawing chars
Browse files Browse the repository at this point in the history
This commit adds the config `font.builtin_box_drawing` option to
control built-in font, which is enabled by default.
  • Loading branch information
deathlyfrantic authored Jan 29, 2022
1 parent d1deff9 commit 094c2c9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Minimum Rust version has been bumped to 1.56.0

### Added

- Option `font.builtin_box_drawing` to disable the built-in font for drawing box characters

### Changed

- The `--help` output was reworked with a new colorful syntax
Expand Down
7 changes: 7 additions & 0 deletions alacritty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@
# it is recommended to set `use_thin_strokes` to `false`.
#use_thin_strokes: true

# Use built-in font for box drawing characters.
#
# If `true`, Alacritty will use a custom built-in font for box drawing
# characters (Unicode points 2500 - 259f).
#
#builtin_box_drawing: true

# If `true`, bold text is drawn using the bright color variants.
#draw_bold_text_with_bright_colors: false

Expand Down
21 changes: 20 additions & 1 deletion alacritty/src/config/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::config::ui_config::Delta;
/// field in this struct. It might be nice in the future to have defaults for
/// each value independently. Alternatively, maybe erroring when the user
/// doesn't provide complete config is Ok.
#[derive(ConfigDeserialize, Default, Debug, Clone, PartialEq, Eq)]
#[derive(ConfigDeserialize, Debug, Clone, PartialEq, Eq)]
pub struct Font {
/// Extra spacing per character.
pub offset: Delta<i8>,
Expand All @@ -38,6 +38,9 @@ pub struct Font {

/// Font size in points.
size: Size,

/// Whether to use the built-in font for box drawing characters.
pub builtin_box_drawing: bool,
}

impl Font {
Expand Down Expand Up @@ -72,6 +75,22 @@ impl Font {
}
}

impl Default for Font {
fn default() -> Font {
Self {
builtin_box_drawing: true,
use_thin_strokes: Default::default(),
glyph_offset: Default::default(),
bold_italic: Default::default(),
italic: Default::default(),
offset: Default::default(),
normal: Default::default(),
bold: Default::default(),
size: Default::default(),
}
}
}

/// Description of the normal font.
#[derive(ConfigDeserialize, Debug, Clone, PartialEq, Eq)]
pub struct FontDescription {
Expand Down
10 changes: 9 additions & 1 deletion alacritty/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub struct GlyphCache {

/// Font metrics.
metrics: crossfont::Metrics,

/// Whether to use the built-in font for box drawing characters.
builtin_box_drawing: bool,
}

impl GlyphCache {
Expand Down Expand Up @@ -167,6 +170,7 @@ impl GlyphCache {
bold_italic_key: bold_italic,
glyph_offset: font.glyph_offset,
metrics,
builtin_box_drawing: font.builtin_box_drawing,
};

cache.load_common_glyphs(loader);
Expand Down Expand Up @@ -268,7 +272,10 @@ impl GlyphCache {

// Rasterize the glyph using the built-in font for special characters or the user's font
// for everything else.
let rasterized = builtin_font::builtin_glyph(glyph_key.character, &self.metrics)
let rasterized = self
.builtin_box_drawing
.then(|| builtin_font::builtin_glyph(glyph_key.character, &self.metrics))
.flatten()
.map_or_else(|| self.rasterizer.get_glyph(glyph_key), Ok);

let glyph = match rasterized {
Expand Down Expand Up @@ -355,6 +362,7 @@ impl GlyphCache {
self.italic_key = italic;
self.bold_italic_key = bold_italic;
self.metrics = metrics;
self.builtin_box_drawing = font.builtin_box_drawing;

self.clear_glyph_cache(loader);

Expand Down

0 comments on commit 094c2c9

Please sign in to comment.