diff options
Diffstat (limited to 'font/src')
-rw-r--r-- | font/src/darwin/mod.rs | 9 | ||||
-rw-r--r-- | font/src/ft/mod.rs | 3 | ||||
-rw-r--r-- | font/src/lib.rs | 3 | ||||
-rw-r--r-- | font/src/rusttype/mod.rs | 4 |
4 files changed, 17 insertions, 2 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index bdcbbdfa..7f01f57b 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -148,15 +148,16 @@ impl ::Rasterize for Rasterizer { } fn load_font(&mut self, desc: &FontDesc, size: Size) -> Result<FontKey, Error> { + let scaled_size = Size::new(size.as_f32_pts() * self.device_pixel_ratio); self.keys - .get(&(desc.to_owned(), size)) + .get(&(desc.to_owned(), scaled_size)) .map(|k| Ok(*k)) .unwrap_or_else(|| { let font = self.get_font(desc, size)?; let key = FontKey::next(); self.fonts.insert(key, font); - self.keys.insert((desc.clone(), size), key); + self.keys.insert((desc.clone(), scaled_size), key); Ok(key) }) @@ -184,6 +185,10 @@ impl ::Rasterize for Rasterizer { Err(Error::MissingGlyph(glyph.c)) }) } + + fn update_dpr(&mut self, device_pixel_ratio: f32) { + self.device_pixel_ratio = device_pixel_ratio; + } } impl Rasterizer { diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 55409174..c67665ab 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -106,6 +106,9 @@ impl ::Rasterize for FreeTypeRasterizer { self.get_rendered_glyph(glyph_key) } + fn update_dpr(&mut self, device_pixel_ratio: f32) { + self.device_pixel_ratio = device_pixel_ratio; + } } pub trait IntoFontconfigType { diff --git a/font/src/lib.rs b/font/src/lib.rs index 5fb50217..4c4f2653 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -355,4 +355,7 @@ pub trait Rasterize { /// Rasterize the glyph described by `GlyphKey`. fn get_glyph(&mut self, GlyphKey) -> Result<RasterizedGlyph, Self::Err>; + + /// Update the Rasterizer's DPI factor + fn update_dpr(&mut self, device_pixel_ratio: f32); } diff --git a/font/src/rusttype/mod.rs b/font/src/rusttype/mod.rs index 62d17de8..c4fda66f 100644 --- a/font/src/rusttype/mod.rs +++ b/font/src/rusttype/mod.rs @@ -133,6 +133,10 @@ impl ::Rasterize for RustTypeRasterizer { buf, }) } + + fn update_dpr(&mut self, device_pixel_ratio: f32) { + self.dpi_ratio = device_pixel_ratio; + } } #[derive(Debug)] |