diff options
Diffstat (limited to 'font/src/lib.rs')
-rw-r--r-- | font/src/lib.rs | 31 |
1 files changed, 23 insertions, 8 deletions
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) } } |