aboutsummaryrefslogtreecommitdiff
path: root/font
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-02-01 19:56:46 +0100
committerChristian Duerr <contact@christianduerr.com>2018-02-16 22:41:56 +0100
commit6428ce28b44c377738c91940b27ff44350c8b60e (patch)
tree1e619637092d7dc3ac8ed271d6330dd771335c9c /font
parentb86c1ff9edbbc0fe28d77b4a247a1cb7ff596183 (diff)
downloadalacritty-6428ce28b44c377738c91940b27ff44350c8b60e.tar.gz
alacritty-6428ce28b44c377738c91940b27ff44350c8b60e.zip
Render underline/strikethrough as rects
Support for strikethrough has been added by inserting and removing a `STRIKE_THROUGH` flag on the cell. Now all strikethrough and underline drawing is also done through the rectangle renderer. So no glyphs are used to render underlines and strikethrough. The position is taken from the font metrics and should be accurate for linux, however is not yet tested on macos. It works by checking the underline state for each cell and then drawing from the start until the last position whenever an underline ended. This adds a few checks even if no underline is rendered but I was not able to measure any significant performance impact. Fixes jwilm/alacritty#806. Fixes jwilm/alacritty#31.
Diffstat (limited to 'font')
-rw-r--r--font/src/darwin/mod.rs4
-rw-r--r--font/src/ft/mod.rs9
-rw-r--r--font/src/lib.rs2
3 files changed, 15 insertions, 0 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs
index 14381113..89858f77 100644
--- a/font/src/darwin/mod.rs
+++ b/font/src/darwin/mod.rs
@@ -422,11 +422,15 @@ impl Font {
let descent = self.ct_font.descent() as f64;
let leading = self.ct_font.leading() as f64;
let line_height = (ascent + descent + leading + 0.5).floor();
+ let underline_position = self.ct_font.underline_position() as f32;
+ let underline_thickness = self.ct_font.underline_thickness() as f32;
Metrics {
average_advance: average_advance,
line_height: line_height,
descent: -(self.ct_font.descent() as f32),
+ underline_position,
+ underline_thickness,
}
}
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index 68d2faf3..6d77a61c 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -86,15 +86,24 @@ impl ::Rasterize for FreeTypeRasterizer {
}
fn metrics(&self, key: FontKey) -> Result<Metrics, Error> {
+ let face = self.faces
+ .get(&key)
+ .ok_or(Error::FontNotLoaded)?;
let full = self.full_metrics(key)?;
let height = (full.size_metrics.height / 64) as f64;
let descent = (full.size_metrics.descender / 64) as f32;
+ let underline_position =
+ (f32::from(face.ft_face.underline_position()) / 64.).round();
+ let underline_thickness =
+ (f32::from(face.ft_face.underline_thickness()) / 64.).round();
Ok(Metrics {
average_advance: full.cell_width,
line_height: height,
descent: descent,
+ underline_position,
+ underline_thickness,
})
}
diff --git a/font/src/lib.rs b/font/src/lib.rs
index 330ed362..7a8ac7a7 100644
--- a/font/src/lib.rs
+++ b/font/src/lib.rs
@@ -314,6 +314,8 @@ pub struct Metrics {
pub average_advance: f64,
pub line_height: f64,
pub descent: f32,
+ pub underline_position: f32,
+ pub underline_thickness: f32,
}
pub trait Rasterize {