diff options
author | Christian Duerr <contact@christianduerr.com> | 2018-02-16 22:21:48 +0100 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2018-02-16 22:43:07 +0100 |
commit | a0270d9774184755cbf6e42457c38343c3d28fff (patch) | |
tree | 7eca157b908ea546147022c62f8fe3089251f55b /font/src/ft | |
parent | b818d6acddb033e26c1ad8dcab23be537f04aca8 (diff) | |
download | alacritty-a0270d9774184755cbf6e42457c38343c3d28fff.tar.gz alacritty-a0270d9774184755cbf6e42457c38343c3d28fff.zip |
Add proper strikeout positioning
With this change the strikeout should make proper use of the metrics in
the OS2 table. These metrics are available for all TTF and OTF fonts. If
the metrics are not supplied, a fallback strikeout based on underline
thickness and cell height is used.
To go in line with the metrics supplied by the OS2 table, the term of
`strikethrough` has been replaced with `strikeout` everywhere. I think
it makes sense to go forward with using `strikeout` in general when
talking about this.
There has also been a small bug where the cell would not be
underlined/striked out when an underline is broken over multiple lines.
This has been fixed and the underline/strikeout should always be applied
to each cell with this flag.
Diffstat (limited to 'font/src/ft')
-rw-r--r-- | font/src/ft/mod.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 2eb3a034..d5642a56 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -18,6 +18,7 @@ use std::cmp::min; use std::path::PathBuf; use std::fmt; +use freetype::tt_os2::TrueTypeOS2Table; use freetype::{self, Library}; use libc::c_uint; @@ -103,12 +104,33 @@ impl ::Rasterize for FreeTypeRasterizer { .round() .max(1.); + // Get strikeout position and thickness in device pixels + let (strikeout_position, strikeout_thickness) = + match TrueTypeOS2Table::from_face(&mut face.ft_face.clone()) + { + Some(os2) => { + let strikeout_position = + (f32::from(os2.y_strikeout_position()) * x_scale / 64.).round(); + let strikeout_thickness = + (f32::from(os2.y_strikeout_size()) * x_scale / 64.).round(); + (strikeout_position, strikeout_thickness) + }, + _ => { + // Fallback if font doesn't provide info about strikeout + trace!("No strikeout data available for font, using fallback."); + let strikeout_position = height as f32 / 2. + descent; + (strikeout_position, underline_thickness) + }, + }; + Ok(Metrics { average_advance: full.cell_width, line_height: height, descent: descent, underline_position, underline_thickness, + strikeout_position, + strikeout_thickness, }) } |