summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-05-03 15:12:23 -0700
committerJoe Wilm <jwilm@users.noreply.github.com>2017-05-06 12:53:54 -0700
commit149fbaef09a56613c72855bc60355c7848256500 (patch)
tree89bb581b2135c702e2f8c03772bf9ddd4470ac8f /src
parent6659810a22e62f8b41d7bc35ed07905ccebda68b (diff)
Fix glyph offsets in cell
We previously had a hard-coded value for aligning glyphs within cells. The font descent is now used, and the offset should be correct by default.
Diffstat (limited to 'src')
-rw-r--r--src/display.rs4
-rw-r--r--src/renderer/mod.rs28
-rw-r--r--src/term/mod.rs4
3 files changed, 17 insertions, 19 deletions
diff --git a/src/display.rs b/src/display.rs
index 5f5dd688..c2636e7e 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -177,8 +177,8 @@ impl Display {
// Resize window to specified dimensions
let dimensions = options.dimensions()
.unwrap_or_else(|| config.dimensions());
- let width = cell_width * dimensions.columns_u32() + 4;
- let height = cell_height * dimensions.lines_u32() + 4;
+ let width = cell_width * dimensions.columns_u32();
+ let height = cell_height * dimensions.lines_u32();
let size = Size { width: Pixels(width), height: Pixels(height) };
info!("set_inner_size: {}", size);
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 48354018..60d83287 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -157,6 +157,8 @@ pub struct GlyphCache {
/// glyph offset
glyph_offset: Delta,
+
+ metrics: ::font::Metrics,
}
impl GlyphCache {
@@ -220,6 +222,12 @@ impl GlyphCache {
.unwrap_or_else(|_| regular)
};
+ // Need to load at least one glyph for the face before calling metrics.
+ // The glyph requested here ('m' at the time of writing) has no special
+ // meaning.
+ rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm' as char, size: font.size() })?;
+ let metrics = rasterizer.metrics(regular)?;
+
let mut cache = GlyphCache {
cache: HashMap::default(),
rasterizer: rasterizer,
@@ -228,12 +236,13 @@ impl GlyphCache {
bold_key: bold,
italic_key: italic,
glyph_offset: glyph_offset,
+ metrics: metrics
};
macro_rules! load_glyphs_for_font {
($font:expr) => {
for i in RangeInclusive::new(32u8, 128u8) {
- cache.load_and_cache_glyph(GlyphKey {
+ cache.get(&GlyphKey {
font_key: $font,
c: i as char,
size: font.size()
@@ -255,33 +264,22 @@ impl GlyphCache {
.expect("metrics load since font is loaded at glyph cache creation")
}
- fn load_and_cache_glyph<L>(&mut self, glyph_key: GlyphKey, loader: &mut L)
- where L: LoadGlyph
- {
- let mut rasterized = self.rasterizer.get_glyph(&glyph_key)
- .unwrap_or_else(|_| Default::default());
-
- rasterized.left += self.glyph_offset.x as i32;
- rasterized.top += self.glyph_offset.y as i32;
-
- let glyph = loader.load_glyph(&rasterized);
- self.cache.insert(glyph_key, glyph);
- }
-
pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph
where L: LoadGlyph
{
let glyph_offset = self.glyph_offset;
let rasterizer = &mut self.rasterizer;
+ let metrics = &self.metrics;
self.cache
.entry(*glyph_key)
.or_insert_with(|| {
let mut rasterized = rasterizer.get_glyph(&glyph_key)
.unwrap_or_else(|_| Default::default());
- // We need to apply the offset to glyphs that didn't get cached initially
+ // Apply offsets so they aren't computed every draw
rasterized.left += glyph_offset.x as i32;
rasterized.top += glyph_offset.y as i32;
+ rasterized.top -= metrics.descent as i32;
loader.load_glyph(&rasterized)
})
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 9981a3d1..4891e794 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -556,12 +556,12 @@ pub struct SizeInfo {
impl SizeInfo {
#[inline]
pub fn lines(&self) -> Line {
- Line((self.height / self.cell_height) as usize)
+ Line(((self.height - 4.0) / self.cell_height) as usize)
}
#[inline]
pub fn cols(&self) -> Column {
- Column((self.width / self.cell_width) as usize)
+ Column(((self.width - 4.0) / self.cell_width) as usize)
}
pub fn pixels_to_coords(&self, x: usize, y: usize) -> Option<Point> {