diff options
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/object_set.rs | 9 | ||||
-rw-r--r-- | font/src/ft/fc/pattern.rs | 38 | ||||
-rw-r--r-- | font/src/ft/mod.rs | 30 |
5 files changed, 50 insertions, 37 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/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..7c5fb768 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, }) } @@ -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()))?; @@ -244,12 +244,12 @@ impl FreeTypeRasterizer { }; 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); @@ -269,14 +269,10 @@ impl FreeTypeRasterizer { 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 }; @@ -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) } } |