fix a rounding issue when computing block glyphs
The leftmost pixel was being set to at least 1 by the scale function. Fix that up by computing the x coordinate without calling the scale function. refs: https://github.com/wez/wezterm/issues/536
This commit is contained in:
1 parent
04a21acdf4
commit
333f5f9750
2 files changed
+22
-4
No files matched your search
@@ -135,7 +135,7 @@ bitflags::bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum BlockAlpha {
|
||||
/// 100%
|
||||
Full,
|
||||
@@ -150,7 +150,7 @@ pub enum BlockAlpha {
|
||||
/// Represents a Block Element glyph, decoded from
|
||||
/// <https://en.wikipedia.org/wiki/Block_Elements>
|
||||
/// <https://www.unicode.org/charts/PDF/U2580.pdf>
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum BlockKey {
|
||||
/// Number of 1/8ths in the upper half
|
||||
Upper(u8),
|
||||
@@ -668,7 +668,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
BlockKey::Upper(num) => {
|
||||
for n in 0..usize::from(num) {
|
||||
for a in 0..scale(y_eighth) {
|
||||
draw_horizontal(&mut buffer, scale(n as f32 * y_eighth) + a);
|
||||
draw_horizontal(&mut buffer, (n as f32 * y_eighth).floor() as usize + a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -684,7 +684,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
BlockKey::Left(num) => {
|
||||
for n in 0..usize::from(num) {
|
||||
for a in 0..scale(x_eighth) {
|
||||
draw_vertical(&mut buffer, scale(n as f32 * x_eighth) + a);
|
||||
draw_vertical(&mut buffer, (n as f32 * x_eighth).floor() as usize + a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -728,6 +728,11 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
log::info!("{:?}", block);
|
||||
buffer.log_bits();
|
||||
*/
|
||||
|
||||
let sprite = self.atlas.allocate(&buffer)?;
|
||||
self.block_glyphs.insert(block, sprite.clone());
|
||||
Ok(sprite)
|
||||
|
||||
@@ -483,6 +483,19 @@ impl Image {
|
||||
let height = (self.height as f64 * scale) as usize;
|
||||
self.resize(width, height)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn log_bits(&self) {
|
||||
log::info!("Image pixels:");
|
||||
for y in 0..self.height {
|
||||
let row = self.horizontal_pixel_range(0, self.width, y);
|
||||
let mut line = String::new();
|
||||
for p in row {
|
||||
line.push_str(&format!("{:08x} ", *p));
|
||||
}
|
||||
log::info!("{}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BitmapImage for Image {
|
||||
|
||||
Reference in new issue
Block a user