aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryshui <yshuiv7@gmail.com>2018-07-21 18:05:14 +0000
committerChristian Duerr <chrisduerr@users.noreply.github.com>2018-07-21 18:05:14 +0000
commit0d5edb7a7a7a33369bc2c1e5cc007edbd6fcf15f (patch)
treee9dcaf5c457a08223bf60336e85e26cedaa19eb2
parenta6e8974a06138c6ce1c71f8a80f7f013a9ad9463 (diff)
downloadalacritty-0d5edb7a7a7a33369bc2c1e5cc007edbd6fcf15f.tar.gz
alacritty-0d5edb7a7a7a33369bc2c1e5cc007edbd6fcf15f.zip
Add support for LCD-V pixel mode
-rw-r--r--font/src/ft/mod.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index 516f3b9c..9ace5b0c 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -348,14 +348,14 @@ impl FreeTypeRasterizer {
let glyph = face.ft_face.glyph();
glyph.render_glyph(face.render_mode)?;
- let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?;
+ let (pixel_height, pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?;
Ok(RasterizedGlyph {
c: glyph_key.c,
top: glyph.bitmap_top(),
left: glyph.bitmap_left(),
width: pixel_width,
- height: glyph.bitmap().rows(),
+ height: pixel_height,
buf,
})
}
@@ -427,7 +427,7 @@ impl FreeTypeRasterizer {
/// Given a FreeType `Bitmap`, returns packed buffer with 1 byte per LCD channel.
///
/// The i32 value in the return type is the number of pixels per row.
- fn normalize_buffer(bitmap: &freetype::bitmap::Bitmap) -> freetype::FtResult<(i32, Vec<u8>)> {
+ fn normalize_buffer(bitmap: &freetype::bitmap::Bitmap) -> freetype::FtResult<(i32, i32, Vec<u8>)> {
use freetype::bitmap::PixelMode;
let buf = bitmap.buffer();
@@ -440,7 +440,18 @@ impl FreeTypeRasterizer {
let stop = start + bitmap.width() as usize;
packed.extend_from_slice(&buf[start..stop]);
}
- Ok((bitmap.width() / 3, packed))
+ Ok((bitmap.rows(), bitmap.width() / 3, packed))
+ },
+ PixelMode::LcdV => {
+ for i in 0..bitmap.rows()/3 {
+ for j in 0..bitmap.width() {
+ for k in 0..3 {
+ let offset = ((i as usize) * 3 + k) * pitch + (j as usize);
+ packed.push(buf[offset]);
+ }
+ }
+ }
+ Ok((bitmap.rows() / 3, bitmap.width(), packed))
},
// Mono data is stored in a packed format using 1 bit per pixel.
PixelMode::Mono => {
@@ -471,7 +482,7 @@ impl FreeTypeRasterizer {
byte += 1;
}
}
- Ok((bitmap.width(), packed))
+ Ok((bitmap.rows(), bitmap.width(), packed))
},
// Gray data is stored as a value between 0 and 255 using 1 byte per pixel.
PixelMode::Gray => {
@@ -484,7 +495,7 @@ impl FreeTypeRasterizer {
packed.push(*byte);
}
}
- Ok((bitmap.width(), packed))
+ Ok((bitmap.rows(), bitmap.width(), packed))
},
mode => panic!("unhandled pixel mode: {:?}", mode)
}