Support bold alt font

This commit is contained in:
mars 2022-10-04 17:34:53 -06:00
parent 89f51bd6a5
commit 188dae668a
1 changed files with 22 additions and 8 deletions

View File

@ -21,7 +21,8 @@ use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Window, WindowBuilder};
static FONT_DATA: &[u8] = include_bytes!("ter-u16n.bdf");
static NORMAL_FONT_DATA: &[u8] = include_bytes!("ter-u16n.bdf");
static BOLD_FONT_DATA: &[u8] = include_bytes!("ter-u16b.bdf");
pub struct TermListener {
sender: Sender<TermEvent>,
@ -40,7 +41,8 @@ impl EventListener for TermListener {
}
pub struct App {
font: bdf::Font,
normal_font: bdf::Font,
bold_font: bdf::Font,
graphics: GraphicsContext<Window>,
should_quit: bool,
cell_width: usize,
@ -54,10 +56,15 @@ pub struct App {
impl App {
pub fn new(window: Window) -> Self {
let font = bdf::read(FONT_DATA).unwrap();
let normal_font = bdf::read(NORMAL_FONT_DATA).unwrap();
let bold_font = bdf::read(BOLD_FONT_DATA).unwrap();
let cell_width = font.bounds().width as usize;
let cell_height = font.bounds().height as usize;
if normal_font.bounds() != bold_font.bounds() {
panic!("Normal and bold font bounds do not match!");
}
let cell_width = normal_font.bounds().width as usize;
let cell_height = normal_font.bounds().height as usize;
let term_size = alacritty_terminal::term::SizeInfo::new(
2000.0,
@ -100,7 +107,8 @@ impl App {
Self::load_colors(&mut colors);
Self {
font,
normal_font,
bold_font,
graphics: unsafe { GraphicsContext::new(window).unwrap() },
should_quit: false,
cell_width,
@ -181,7 +189,13 @@ impl App {
continue;
}
if let Some(glyph) = self.font.glyphs().get(&cell.c) {
let font = if cell.flags.contains(CellFlags::BOLD) {
&self.bold_font
} else {
&self.normal_font
};
if let Some(glyph) = font.glyphs().get(&cell.c) {
let term_row = cell.point.line.0 as usize;
let term_col = cell.point.column.0 as usize;
@ -215,7 +229,7 @@ impl App {
buffer[px_start + x as usize] = color;
}
}
if cell.flags.contains(CellFlags::STRIKEOUT) {
let px_start = px_start + (self.cell_height >> 1) * width;