diff options
Diffstat (limited to 'font/src/rusttype/mod.rs')
-rw-r--r-- | font/src/rusttype/mod.rs | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/font/src/rusttype/mod.rs b/font/src/rusttype/mod.rs index e8e0bd2c..be39ecc9 100644 --- a/font/src/rusttype/mod.rs +++ b/font/src/rusttype/mod.rs @@ -15,10 +15,7 @@ impl crate::Rasterize for RustTypeRasterizer { type Err = Error; fn new(device_pixel_ratio: f32, _: bool) -> Result<RustTypeRasterizer, Error> { - Ok(RustTypeRasterizer { - fonts: Vec::new(), - dpi_ratio: device_pixel_ratio, - }) + Ok(RustTypeRasterizer { fonts: Vec::new(), dpi_ratio: device_pixel_ratio }) } fn metrics(&self, key: FontKey, size: Size) -> Result<Metrics, Error> { @@ -56,17 +53,13 @@ impl crate::Rasterize for RustTypeRasterizer { } fn load_font(&mut self, desc: &FontDesc, _size: Size) -> Result<FontKey, Error> { - let fp = system_fonts::FontPropertyBuilder::new() - .family(&desc.name) - .monospace(); + let fp = system_fonts::FontPropertyBuilder::new().family(&desc.name).monospace(); let fp = match desc.style { - Style::Specific(ref style) => { - match style.to_lowercase().as_str() { - "italic" => fp.italic(), - "bold" => fp.bold(), - _ => fp, - } + Style::Specific(ref style) => match style.to_lowercase().as_str() { + "italic" => fp.italic(), + "bold" => fp.bold(), + _ => fp, }, Style::Description { slant, weight } => { let fp = match slant { @@ -79,52 +72,52 @@ impl crate::Rasterize for RustTypeRasterizer { Weight::Bold => fp.bold(), Weight::Normal => fp, } - } + }, }; - self.fonts.push(FontCollection::from_bytes( - system_fonts::get(&fp.build()) - .ok_or_else(|| Error::MissingFont(desc.clone()))? - .0, - ).into_font() - .ok_or(Error::UnsupportedFont)?); - Ok(FontKey { - token: (self.fonts.len() - 1) as u16, - }) + self.fonts.push( + FontCollection::from_bytes( + system_fonts::get(&fp.build()).ok_or_else(|| Error::MissingFont(desc.clone()))?.0, + ) + .into_font() + .ok_or(Error::UnsupportedFont)?, + ); + Ok(FontKey { token: (self.fonts.len() - 1) as u16 }) } fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> { match glyph_key.c { super::UNDERLINE_CURSOR_CHAR => { let metrics = self.metrics(glyph_key.font_key, glyph_key.size)?; - return super::get_underline_cursor_glyph(metrics.descent as i32, metrics.average_advance as i32); - } + return super::get_underline_cursor_glyph( + metrics.descent as i32, + metrics.average_advance as i32, + ); + }, super::BEAM_CURSOR_CHAR => { let metrics = self.metrics(glyph_key.font_key, glyph_key.size)?; return super::get_beam_cursor_glyph( (metrics.line_height + f64::from(metrics.descent)).round() as i32, metrics.line_height.round() as i32, - metrics.average_advance.round() as i32 + metrics.average_advance.round() as i32, ); - } + }, super::BOX_CURSOR_CHAR => { let metrics = self.metrics(glyph_key.font_key, glyph_key.size)?; return super::get_box_cursor_glyph( (metrics.line_height + f64::from(metrics.descent)).round() as i32, metrics.line_height.round() as i32, - metrics.average_advance.round() as i32 + metrics.average_advance.round() as i32, ); - } - _ => () + }, + _ => (), } let scaled_glyph = self.fonts[glyph_key.font_key.token as usize] .glyph(glyph_key.c) .ok_or(Error::MissingGlyph)? - .scaled(Scale::uniform( - glyph_key.size.as_f32_pts() * self.dpi_ratio * 96. / 72., - )); + .scaled(Scale::uniform(glyph_key.size.as_f32_pts() * self.dpi_ratio * 96. / 72.)); let glyph = scaled_glyph.positioned(point(0.0, 0.0)); @@ -132,10 +125,7 @@ impl crate::Rasterize for RustTypeRasterizer { let bb = match glyph.pixel_bounding_box() { Some(bb) => bb, // Bounding box calculation fails for spaces so we provide a placeholder bounding box - None => rusttype::Rect { - min: point(0, 0), - max: point(0, 0), - }, + None => rusttype::Rect { min: point(0, 0), max: point(0, 0) }, }; let mut buf = Vec::with_capacity((bb.width() * bb.height()) as usize); @@ -185,8 +175,8 @@ impl ::std::fmt::Display for Error { match *self { Error::MissingFont(ref desc) => write!( f, - "Couldn't find a font with {}\ - \n\tPlease check the font config in your alacritty.yml.", + "Couldn't find a font with {}\n\tPlease check the font config in your \ + alacritty.yml.", desc ), Error::UnsupportedFont => write!( @@ -195,7 +185,7 @@ impl ::std::fmt::Display for Error { ), Error::UnsupportedStyle => { write!(f, "The selected font style is not supported by rusttype.") - } + }, Error::MissingGlyph => write!(f, "The selected font did not have the requested glyph."), } } |