aboutsummaryrefslogtreecommitdiff
path: root/src/text.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-04-11 08:05:19 -0700
committerJoe Wilm <joe@jwilm.com>2016-04-11 08:05:19 -0700
commite794bc11b962adef4d6fbbaeb85344cb138376da (patch)
tree71d0442ca31a24fcb3c8e64f7887d35688f2109b /src/text.rs
parentb84eb9e921c040c4eadaabd8f3087690efa267b6 (diff)
downloadr-alacritty-e794bc11b962adef4d6fbbaeb85344cb138376da.tar.gz
r-alacritty-e794bc11b962adef4d6fbbaeb85344cb138376da.tar.bz2
r-alacritty-e794bc11b962adef4d6fbbaeb85344cb138376da.zip
Use subpixel font rendering
OpenGL only supports shared alpha blending. Subpixel font rendering requires using the font RGB values as alpha masks for the corresponding RGB channels. To support this, blending is implemented in the fragment shader.
Diffstat (limited to 'src/text.rs')
-rw-r--r--src/text.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/text.rs b/src/text.rs
index ea0df76a..ca414342 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -87,15 +87,30 @@ impl Rasterizer {
pub fn get_glyph(&mut self, desc: &FontDesc, size: f32, c: char) -> RasterizedGlyph {
let face = self.get_face(desc).expect("TODO handle get_face error");
face.set_char_size(to_freetype_26_6(size * self.dpr), 0, self.dpi_x, self.dpi_y).unwrap();
- face.load_char(c as usize, freetype::face::RENDER).unwrap();
+ face.load_char(c as usize, freetype::face::TARGET_LIGHT).unwrap();
let glyph = face.glyph();
+ glyph.render_glyph(freetype::render_mode::RenderMode::Lcd).unwrap();
+
+ // FIXME need LCD filtering to reduce color fringes with subpixel rendering. The freetype
+ // bindings don't currently expose this!
+
+ let bitmap = glyph.bitmap();
+ let buf = bitmap.buffer();
+ let pitch = bitmap.pitch() as usize;
+
+ let mut packed = Vec::with_capacity((bitmap.rows() * bitmap.width()) as usize);
+ for i in 0..bitmap.rows() {
+ let start = (i as usize) * pitch;
+ let stop = start + bitmap.width() as usize;
+ packed.extend_from_slice(&buf[start..stop]);
+ }
RasterizedGlyph {
top: glyph.bitmap_top() as usize,
left: glyph.bitmap_left() as usize,
- width: glyph.bitmap().width() as usize,
+ width: glyph.bitmap().width() as usize / 3,
height: glyph.bitmap().rows() as usize,
- buf: glyph.bitmap().buffer().to_vec(),
+ buf: packed,
}
}
}