diff options
Diffstat (limited to 'font')
-rw-r--r-- | font/src/darwin/mod.rs | 11 | ||||
-rw-r--r-- | font/src/ft/mod.rs | 2 | ||||
-rw-r--r-- | font/src/lib.rs | 31 |
3 files changed, 29 insertions, 15 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 42927654..dae7ee04 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -591,12 +591,11 @@ mod tests { let index = ((glyph.width * 3 * row) + (col * 3)) as usize; let value = glyph.buf[index]; let c = match value { - 0...50 => ' ', - 51...100 => '.', - 101...150 => '~', - 151...200 => '*', - 201...255 => '#', - _ => unreachable!(), + 0..=50 => ' ', + 51..=100 => '.', + 101..=150 => '~', + 151..=200 => '*', + 201..=255 => '#', }; print!("{}", c); } diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 5388aeb4..0886f177 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -546,7 +546,7 @@ pub enum Error { } impl ::std::error::Error for Error { - fn cause(&self) -> Option<&dyn (::std::error::Error)> { + fn cause(&self) -> Option<&dyn std::error::Error> { match *self { Error::FreeType(ref err) => Some(err), _ => None, diff --git a/font/src/lib.rs b/font/src/lib.rs index d3bddd54..262cf911 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -47,6 +47,7 @@ extern crate log; use std::fmt; use std::hash::{Hash, Hasher}; +use std::ops::{Add, Mul}; use std::sync::atomic::{AtomicUsize, Ordering}; // If target isn't macos or windows, reexport everything from ft @@ -173,28 +174,42 @@ impl PartialEq for GlyphKey { pub struct Size(i16); impl Size { + /// Create a new `Size` from a f32 size in points + pub fn new(size: f32) -> Size { + Size((size * Size::factor()) as i16) + } + /// Scale factor between font "Size" type and point size #[inline] pub fn factor() -> f32 { 2.0 } - /// Create a new `Size` from a f32 size in points - pub fn new(size: f32) -> Size { - Size((size * Size::factor()) as i16) - } - /// Get the f32 size in points pub fn as_f32_pts(self) -> f32 { f32::from(self.0) / Size::factor() } } -impl ::std::ops::Add for Size { +impl<T: Into<Size>> Add<T> for Size { type Output = Size; - fn add(self, other: Size) -> Size { - Size(self.0.saturating_add(other.0)) + fn add(self, other: T) -> Size { + Size(self.0.saturating_add(other.into().0)) + } +} + +impl<T: Into<Size>> Mul<T> for Size { + type Output = Size; + + fn mul(self, other: T) -> Size { + Size(self.0 * other.into().0) + } +} + +impl From<f32> for Size { + fn from(float: f32) -> Size { + Size::new(float) } } |