diff options
Diffstat (limited to 'font/src/lib.rs')
-rw-r--r-- | font/src/lib.rs | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/font/src/lib.rs b/font/src/lib.rs index 330ed362..05680da2 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -116,7 +116,7 @@ impl FontDesc { { FontDesc { name: name.into(), - style: style + style, } } } @@ -146,7 +146,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 +165,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 +196,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 +237,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 +258,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 +289,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]); |