1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 02:25:28 +03:00

glyphcache: adopt zeno crate for drawing

This changes the fill_rect function over to use the zeno crate.
zeno allows describing a path and filling or stroking.
This commit doesn't strictly need that, but it sets things
up for more interesting custom glyphs in later commits.

refs: #584
refs: #588
This commit is contained in:
Wez Furlong 2021-06-13 15:49:37 -07:00
parent bf3181e0a7
commit 6c702b568f
3 changed files with 26 additions and 18 deletions

7
Cargo.lock generated
View File

@ -4921,6 +4921,7 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
"window", "window",
"windows", "windows",
"zeno",
] ]
[[package]] [[package]]
@ -5413,6 +5414,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "zeno"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea708573d4a67f939793b0d3f923d105bfdf06bbd6acb3f9cd02ce1bd905f6c8"
[[package]] [[package]]
name = "zstd" name = "zstd"
version = "0.6.1+zstd.1.4.9" version = "0.6.1+zstd.1.4.9"

View File

@ -71,6 +71,7 @@ wezterm-ssh = { path = "../wezterm-ssh" }
wezterm-term = { path = "../term", features=["use_serde"] } wezterm-term = { path = "../term", features=["use_serde"] }
wezterm-toast-notification = { path = "../wezterm-toast-notification" } wezterm-toast-notification = { path = "../wezterm-toast-notification" }
window = { path = "../window" } window = { path = "../window" }
zeno = "0.2"
[target."cfg(windows)".dependencies] [target."cfg(windows)".dependencies]
shared_library = "0.1" shared_library = "0.1"

View File

@ -811,7 +811,6 @@ impl<T: Texture2d> GlyphCache<T> {
self.metrics.cell_size.height as usize, self.metrics.cell_size.height as usize,
); );
let black = SrgbaPixel::rgba(0, 0, 0, 0); let black = SrgbaPixel::rgba(0, 0, 0, 0);
let white = SrgbaPixel::rgba(0xff, 0xff, 0xff, 0xff);
let cell_rect = Rect::new(Point::new(0, 0), self.metrics.cell_size); let cell_rect = Rect::new(Point::new(0, 0), self.metrics.cell_size);
@ -822,24 +821,25 @@ impl<T: Texture2d> GlyphCache<T> {
buffer.clear_rect(cell_rect, black); buffer.clear_rect(cell_rect, black);
// Fill a rectangular region described by the x and y ranges // Fill a rectangular region described by the x and y ranges
// TODO: this could probably be a call to buffer.clear_rect?
let fill_rect = |buffer: &mut Image, x: Range<usize>, y: Range<usize>| { let fill_rect = |buffer: &mut Image, x: Range<usize>, y: Range<usize>| {
for y in y { use zeno::{Command, Fill, Format, Mask, PathBuilder};
buffer.draw_line( let (width, height) = buffer.image_dimensions();
Point::new( let x = x.start as f32..x.end as f32;
cell_rect.origin.x + x.start as isize, let y = y.start as f32..y.end as f32;
cell_rect.origin.y + y as isize, let mut path: Vec<Command> = vec![];
),
Point::new( path.add_rect([x.start, y.start], x.end - x.start, y.end - y.start);
// Note: draw_line uses inclusive coordinates, but our let (alpha, _placement) = Mask::new(&path)
// range is exclusive coordinates, so compensate here! .format(Format::Alpha)
// We don't need to do this for `y` since we are already .size(width as u32, height as u32)
// iterating over the correct set of `y` values in our loop. .style(Fill::NonZero)
cell_rect.origin.x + x.end.saturating_sub(1) as isize, .render();
cell_rect.origin.y + y as isize,
), for (alpha, dest) in alpha.into_iter().zip(buffer.pixels_mut()) {
white, let alpha = alpha as u32;
); // If existing pixel was blank, we want to replace it.
// If alpha is blank then we don't want to replace existing non-blank.
*dest |= alpha << 24 | alpha << 16 | alpha << 8 | alpha;
} }
}; };