From f7177101eda589596ab08866892bd4629bd1ef44 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Thu, 6 Jan 2022 00:45:06 +0300 Subject: Use builtin font for box drawing unicode characters This commit adds hand rolled drawing of unicode box drawing[1] and block elements[2] from ranges U+2500 up to U+259f. While using system font for such characters will look better most of the time, the characters tend to overlap or not align, so providing builtin font is the lesser evil here. [1] - https://www.unicode.org/charts/PDF/U2500.pdf [2] - https://www.unicode.org/charts/PDF/U2580.pdf Fixes #5485. --- alacritty/src/renderer/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'alacritty/src/renderer/mod.rs') diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index eaaa97bb..33c6a7e3 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -25,6 +25,7 @@ use crate::gl; use crate::gl::types::*; use crate::renderer::rects::{RectRenderer, RenderRect}; +pub mod builtin_font; pub mod rects; // Shader source. @@ -265,8 +266,12 @@ impl GlyphCache { return *glyph; }; - // Rasterize glyph. - let glyph = match self.rasterizer.get_glyph(glyph_key) { + // 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) + .map_or_else(|| self.rasterizer.get_glyph(glyph_key), Ok); + + let glyph = match rasterized { Ok(rasterized) => self.load_glyph(loader, rasterized), // Load fallback glyph. Err(RasterizerError::MissingGlyph(rasterized)) if show_missing => { @@ -827,9 +832,9 @@ impl<'a> RenderApi<'a> { self.batch.clear(); } - /// Render a string in a variable location. Used for printing the render timer, warnings and + /// Draw a string in a variable location. Used for printing the render timer, warnings and /// errors. - pub fn render_string( + pub fn draw_string( &mut self, glyph_cache: &mut GlyphCache, point: Point, @@ -852,7 +857,7 @@ impl<'a> RenderApi<'a> { .collect::>(); for cell in cells { - self.render_cell(cell, glyph_cache); + self.draw_cell(cell, glyph_cache); } } @@ -871,7 +876,7 @@ impl<'a> RenderApi<'a> { } } - pub fn render_cell(&mut self, mut cell: RenderableCell, glyph_cache: &mut GlyphCache) { + pub fn draw_cell(&mut self, mut cell: RenderableCell, glyph_cache: &mut GlyphCache) { // Get font key for cell. let font_key = match cell.flags & Flags::BOLD_ITALIC { Flags::BOLD_ITALIC => glyph_cache.bold_italic_key, -- cgit