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/ft | |
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/ft')
-rw-r--r-- | font/src/ft/fc/char_set.rs | 8 | ||||
-rw-r--r-- | font/src/ft/fc/config.rs | 2 | ||||
-rw-r--r-- | font/src/ft/fc/mod.rs | 4 | ||||
-rw-r--r-- | font/src/ft/fc/object_set.rs | 9 | ||||
-rw-r--r-- | font/src/ft/fc/pattern.rs | 38 | ||||
-rw-r--r-- | font/src/ft/mod.rs | 42 |
6 files changed, 58 insertions, 45 deletions
diff --git a/font/src/ft/fc/char_set.rs b/font/src/ft/fc/char_set.rs index e6fe027a..151d14a3 100644 --- a/font/src/ft/fc/char_set.rs +++ b/font/src/ft/fc/char_set.rs @@ -24,7 +24,13 @@ foreign_type! { } impl CharSet { - pub fn new() -> CharSet { + pub fn new() -> Self { + Self::default() + } +} + +impl Default for CharSet { + fn default() -> Self { CharSet(unsafe { FcCharSetCreate() }) } } diff --git a/font/src/ft/fc/config.rs b/font/src/ft/fc/config.rs index 92993fe8..9744b37a 100644 --- a/font/src/ft/fc/config.rs +++ b/font/src/ft/fc/config.rs @@ -38,7 +38,7 @@ impl Config { impl ConfigRef { /// Returns one of the two sets of fonts from the configuration as /// specified by `set`. - pub fn get_fonts<'a>(&'a self, set: SetName) -> &'a FontSetRef { + pub fn get_fonts(&self, set: SetName) -> &FontSetRef { unsafe { let ptr = FcConfigGetFonts(self.as_ptr(), set as u32); FontSetRef::from_ptr(ptr) diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs index ac0c9442..865f63c9 100644 --- a/font/src/ft/fc/mod.rs +++ b/font/src/ft/fc/mod.rs @@ -180,9 +180,9 @@ pub enum Width { } impl Width { - fn to_isize(&self) -> isize { + fn to_isize(self) -> isize { use self::Width::*; - match *self { + match self { Ultracondensed => 50, Extracondensed => 63, Condensed => 75, diff --git a/font/src/ft/fc/object_set.rs b/font/src/ft/fc/object_set.rs index 42e03f64..47d11674 100644 --- a/font/src/ft/fc/object_set.rs +++ b/font/src/ft/fc/object_set.rs @@ -24,8 +24,13 @@ foreign_type! { } impl ObjectSet { - #[allow(dead_code)] - pub fn new() -> ObjectSet { + pub fn new() -> Self { + Self::default() + } +} + +impl Default for ObjectSet { + fn default() -> Self { ObjectSet(unsafe { FcObjectSetCreate() }) diff --git a/font/src/ft/fc/pattern.rs b/font/src/ft/fc/pattern.rs index 592d3859..bb0c4c38 100644 --- a/font/src/ft/fc/pattern.rs +++ b/font/src/ft/fc/pattern.rs @@ -39,8 +39,8 @@ pub struct StringPropertyIter<'a> { impl<'a> StringPropertyIter<'a> { fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> StringPropertyIter<'b> { StringPropertyIter { - pattern: pattern, - object: object, + pattern, + object, index: 0 } } @@ -82,8 +82,8 @@ pub struct BooleanPropertyIter<'a> { impl<'a> BooleanPropertyIter<'a> { fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> BooleanPropertyIter<'b> { BooleanPropertyIter { - pattern: pattern, - object: object, + pattern, + object, index: 0 } } @@ -101,7 +101,7 @@ impl<'a> BooleanPropertyIter<'a> { }; if result == FcResultMatch { - Some(!(value == 0)) + Some(value != 0) } else { None } @@ -118,8 +118,8 @@ pub struct IntPropertyIter<'a> { impl<'a> IntPropertyIter<'a> { fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> IntPropertyIter<'b> { IntPropertyIter { - pattern: pattern, - object: object, + pattern, + object, index: 0 } } @@ -171,7 +171,7 @@ pub struct HintStylePropertyIter<'a> { } impl<'a> HintStylePropertyIter<'a> { - fn new<'b>(pattern: &'b PatternRef) -> HintStylePropertyIter<'b> { + fn new(pattern: &PatternRef) -> HintStylePropertyIter { HintStylePropertyIter { inner: IntPropertyIter::new(pattern, b"hintstyle\0") } @@ -201,7 +201,7 @@ pub struct LcdFilterPropertyIter<'a> { } impl<'a> LcdFilterPropertyIter<'a> { - fn new<'b>(pattern: &'b PatternRef) -> LcdFilterPropertyIter<'b> { + fn new(pattern: &PatternRef) -> LcdFilterPropertyIter { LcdFilterPropertyIter { inner: IntPropertyIter::new(pattern, b"lcdfilter\0") } @@ -236,14 +236,14 @@ pub struct DoublePropertyIter<'a> { impl<'a> DoublePropertyIter<'a> { fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> DoublePropertyIter<'b> { DoublePropertyIter { - pattern: pattern, - object: object, + pattern, + object, index: 0 } } fn get_value(&self, index: usize) -> Option<f64> { - let mut value = 0 as c_double; + let mut value = f64::from(0); let result = unsafe { FcPatternGetDouble( @@ -379,7 +379,13 @@ macro_rules! string_accessor { } impl Pattern { - pub fn new() -> Pattern { + pub fn new() -> Self { + Self::default() + } +} + +impl Default for Pattern { + fn default() -> Self { Pattern(unsafe { FcPatternCreate() }) } } @@ -483,11 +489,11 @@ impl PatternRef { BooleanPropertyIter::new(self, object) } - pub fn hintstyle<'a>(&'a self) -> HintStylePropertyIter<'a> { + pub fn hintstyle(&self) -> HintStylePropertyIter { HintStylePropertyIter::new(self) } - pub fn lcdfilter<'a>(&'a self) -> LcdFilterPropertyIter<'a> { + pub fn lcdfilter(&self) -> LcdFilterPropertyIter { LcdFilterPropertyIter::new(self) } @@ -565,7 +571,7 @@ impl PatternRef { RgbaPropertyIter::new(self, b"rgba\0") } - pub fn set_rgba(&self, rgba: Rgba) -> bool { + pub fn set_rgba(&self, rgba: &Rgba) -> bool { unsafe { self.add_integer(b"rgba\0", rgba.to_isize()) } diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 68d2faf3..516f3b9c 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -80,8 +80,8 @@ impl ::Rasterize for FreeTypeRasterizer { Ok(FreeTypeRasterizer { faces: HashMap::new(), keys: HashMap::new(), - library: library, - device_pixel_ratio: device_pixel_ratio, + library, + device_pixel_ratio, }) } @@ -94,7 +94,7 @@ impl ::Rasterize for FreeTypeRasterizer { Ok(Metrics { average_advance: full.cell_width, line_height: height, - descent: descent, + descent, }) } @@ -102,7 +102,7 @@ impl ::Rasterize for FreeTypeRasterizer { self.get_face(desc, size) } - fn get_glyph(&mut self, glyph_key: &GlyphKey) -> Result<RasterizedGlyph, Error> { + fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> { self.get_rendered_glyph(glyph_key) } @@ -172,7 +172,7 @@ impl FreeTypeRasterizer { } as f64; Ok(FullMetrics { - size_metrics: size_metrics, + size_metrics, cell_width: width }) } @@ -188,7 +188,7 @@ impl FreeTypeRasterizer { pattern.add_family(&desc.name); pattern.set_weight(weight.into_fontconfig_type()); pattern.set_slant(slant.into_fontconfig_type()); - pattern.add_pixelsize(size.as_f32_pts() as _); + pattern.add_pixelsize(f64::from(size.as_f32_pts())); let font = fc::font_match(fc::Config::get_current(), &mut pattern) .ok_or_else(|| Error::MissingFont(desc.to_owned()))?; @@ -210,7 +210,7 @@ impl FreeTypeRasterizer { let mut pattern = fc::Pattern::new(); pattern.add_family(&desc.name); pattern.add_style(style); - pattern.add_pixelsize(size.as_f32_pts() as _); + pattern.add_pixelsize(f64::from(size.as_f32_pts())); let font = fc::font_match(fc::Config::get_current(), &mut pattern) .ok_or_else(|| Error::MissingFont(desc.to_owned()))?; @@ -232,24 +232,24 @@ impl FreeTypeRasterizer { let ft_face = self.library.new_face(&path, index)?; // Get available pixel sizes if font isn't scalable. - let non_scalable = if !pattern.scalable().next().unwrap_or(true) { + let non_scalable = if pattern.scalable().next().unwrap_or(true) { + None + } else { let mut pixelsize = pattern.pixelsize(); debug!("pixelsizes: {:?}", pixelsize); Some(FixedSize { pixelsize: pixelsize.next().expect("has 1+ pixelsize"), }) - } else { - None }; let face = Face { - ft_face: ft_face, + ft_face, key: FontKey::next(), load_flags: Self::ft_load_flags(pattern), render_mode: Self::ft_render_mode(pattern), lcd_filter: Self::ft_lcd_filter(pattern), - non_scalable: non_scalable, + non_scalable, }; debug!("Loaded Face {:?}", face); @@ -264,19 +264,15 @@ impl FreeTypeRasterizer { } } - fn face_for_glyph(&mut self, glyph_key: &GlyphKey, have_recursed: bool) -> Result<FontKey, Error> { + fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result<FontKey, Error> { let c = glyph_key.c; let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) { // Get face and unwrap since we just checked for presence. - let face = self.faces.get(&glyph_key.font_key).unwrap(); + let face = &self.faces[&glyph_key.font_key]; let index = face.ft_face.get_char_index(c as usize); - if index != 0 || have_recursed { - true - } else { - false - } + index != 0 || have_recursed } else { false }; @@ -289,7 +285,7 @@ impl FreeTypeRasterizer { } } - fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey) + fn get_rendered_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> { // Render a custom symbol for the underline and beam cursor match glyph_key.c { @@ -334,7 +330,7 @@ impl FreeTypeRasterizer { // Render a normal character if it's not a cursor let font_key = self.face_for_glyph(glyph_key, false)?; - let face = self.faces.get(&font_key).unwrap(); + let face = &self.faces[&font_key]; let index = face.ft_face.get_char_index(glyph_key.c as usize); let size = face.non_scalable.as_ref() @@ -360,7 +356,7 @@ impl FreeTypeRasterizer { left: glyph.bitmap_left(), width: pixel_width, height: glyph.bitmap().rows(), - buf: buf, + buf, }) } @@ -490,7 +486,7 @@ impl FreeTypeRasterizer { } Ok((bitmap.width(), packed)) }, - mode @ _ => panic!("unhandled pixel mode: {:?}", mode) + mode => panic!("unhandled pixel mode: {:?}", mode) } } |