diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-07-21 17:17:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-21 17:17:41 +0000 |
commit | f50ca1a54c94fe324d22d985c1acae1ff7c16a80 (patch) | |
tree | 7fc2e79f7dccf512fe71f841ef5434e0b1d2b5d7 /font/src/lib.rs | |
parent | b05ad74fe6d42ce0f913e02ef633ca119fc0b43e (diff) | |
download | alacritty-f50ca1a54c94fe324d22d985c1acae1ff7c16a80.tar.gz alacritty-f50ca1a54c94fe324d22d985c1acae1ff7c16a80.zip |
Scrollback cleanup
There were some unneeded codeblocks and TODO/XXX comments in the code
that have been removed. All issues marked with TODO/XXX have either been
already resolved or tracking issues exist.
Diffstat (limited to 'font/src/lib.rs')
-rw-r--r-- | font/src/lib.rs | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/font/src/lib.rs b/font/src/lib.rs index 330ed362..fe9e9e85 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -17,6 +17,9 @@ //! CoreText is used on Mac OS. //! FreeType is used on everything that's not Mac OS. //! Eventually, ClearType support will be available for windows + +#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))] + #[cfg(not(target_os = "macos"))] extern crate fontconfig; #[cfg(not(target_os = "macos"))] @@ -116,7 +119,7 @@ impl FontDesc { { FontDesc { name: name.into(), - style: style + style, } } } @@ -146,7 +149,7 @@ impl FontKey { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Eq)] pub struct GlyphKey { pub c: char, pub font_key: FontKey, @@ -165,6 +168,19 @@ impl Hash for GlyphKey { } } +impl PartialEq for GlyphKey { + fn eq(&self, other: &Self) -> bool { + unsafe { + // This transmute is fine: + // + // - If GlyphKey ever becomes a different size, this will fail to compile + // - Result is being used for equality checking and has no fields (it's a u64) + let other = ::std::mem::transmute::<GlyphKey, u64>(*other); + ::std::mem::transmute::<GlyphKey, u64>(*self).eq(&other) + } + } +} + /// Font size stored as integer #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Size(i16); @@ -183,7 +199,7 @@ impl Size { /// Get the f32 size in points pub fn as_f32_pts(self) -> f32 { - self.0 as f32 / Size::factor() + f32::from(self.0) / Size::factor() } } @@ -224,14 +240,14 @@ pub fn get_underline_cursor_glyph(descent: i32, width: i32) -> Result<Rasterized let buf = vec![255u8; (width * height * 3) as usize]; // Create a custom glyph with the rectangle data attached to it - return Ok(RasterizedGlyph { + Ok(RasterizedGlyph { c: UNDERLINE_CURSOR_CHAR, top: descent + height, left: 0, height, width, - buf: buf, - }); + buf, + }) } // Returns a custom beam cursor character @@ -245,14 +261,14 @@ pub fn get_beam_cursor_glyph( let buf = vec![255u8; (beam_width * height * 3) as usize]; // Create a custom glyph with the rectangle data attached to it - return Ok(RasterizedGlyph { + Ok(RasterizedGlyph { c: BEAM_CURSOR_CHAR, top: ascent, left: 0, height, width: beam_width, - buf: buf, - }); + buf, + }) } // Returns a custom box cursor character @@ -276,14 +292,14 @@ pub fn get_box_cursor_glyph( } // Create a custom glyph with the rectangle data attached to it - return Ok(RasterizedGlyph { + Ok(RasterizedGlyph { c: BOX_CURSOR_CHAR, top: ascent, left: 0, height, width, - buf: buf, - }); + buf, + }) } struct BufDebugger<'a>(&'a [u8]); @@ -331,5 +347,5 @@ pub trait Rasterize { fn load_font(&mut self, &FontDesc, Size) -> Result<FontKey, Self::Err>; /// Rasterize the glyph described by `GlyphKey`. - fn get_glyph(&mut self, &GlyphKey) -> Result<RasterizedGlyph, Self::Err>; + fn get_glyph(&mut self, GlyphKey) -> Result<RasterizedGlyph, Self::Err>; } |