diff options
author | Christian Duerr <contact@christianduerr.com> | 2017-12-09 17:07:07 +0100 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-12-24 09:46:54 -0800 |
commit | 8195d7103498043270523bd81d703cb678cd11a2 (patch) | |
tree | 8af420bc50c79156e07b1002b9ec4f740c960539 /font/src/darwin | |
parent | ce8bd1aaf2ba8c5a931b8667b354f90ddf50a1a6 (diff) | |
download | alacritty-8195d7103498043270523bd81d703cb678cd11a2.tar.gz alacritty-8195d7103498043270523bd81d703cb678cd11a2.zip |
Format cursor code and add documentation
As requested a few comments have been added to the darwin code. There
also was an off by one error in the ascent calculation which has been
corrected.
The beam cursor width has also been tweaked to be slightly slimmer in
general.
All code added in this PR has also been run through the default rustfmt
to make sure the formatting is okay.
Diffstat (limited to 'font/src/darwin')
-rw-r--r-- | font/src/darwin/mod.rs | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 877564fa..a6deba3b 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -462,17 +462,31 @@ impl Font { pub fn get_glyph(&self, character: char, _size: f64, use_thin_strokes: bool) -> Result<RasterizedGlyph, Error> { // Render custom symbols for underline and beam cursor - if character == super::UNDERLINE_CURSOR_CHAR { - let descent = -(self.ct_font.descent() as i32); - let width = self.glyph_advance('0') as i32; - return super::get_underline_cursor_glyph(descent, width); - } else if character == super::BEAM_CURSOR_CHAR { - let metrics = self.metrics(); - let height = metrics.line_height; - let ascent = height - self.ct_font.descent() + 1.; - let width = self.glyph_advance('0') as i32; - return super::get_beam_cursor_glyph(ascent as i32, height as i32, width); - }; + match character { + super::UNDERLINE_CURSOR_CHAR => { + // Get the bottom of the bounding box + let descent = -(self.ct_font.descent() as i32); + // Get the width of the cell + let width = self.glyph_advance('0') as i32; + // Return the new custom glyph + return super::get_underline_cursor_glyph(descent, width); + }, + super::BEAM_CURSOR_CHAR => { + // Get the top of the bounding box + let metrics = self.metrics(); + let height = metrics.line_height; + let mut ascent = height - self.ct_font.descent() + 1.; + if ascent.floor() == ascent { + // Fix off-by-one with an exact X.0 ascent + ascent -= 1.; + } + // Get the width of the cell + let width = self.glyph_advance('0') as i32; + // Return the new custom glyph + return super::get_beam_cursor_glyph(ascent as i32, height as i32, width); + }, + _ => (), + } let glyph_index = self.glyph_index(character) .ok_or(Error::MissingGlyph(character))?; |