diff options
Diffstat (limited to 'font/src/darwin/mod.rs')
-rw-r--r-- | font/src/darwin/mod.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 4db8dad1..1b295801 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -75,6 +75,7 @@ pub struct Descriptor { /// Given a fontdesc, can rasterize fonts. pub struct Rasterizer { fonts: HashMap<FontKey, Font>, + keys: HashMap<(FontDesc, Size), FontKey>, device_pixel_ratio: f32, } @@ -83,6 +84,7 @@ impl Rasterizer { println!("device_pixel_ratio: {}", device_pixel_ratio); Rasterizer { fonts: HashMap::new(), + keys: HashMap::new(), device_pixel_ratio: device_pixel_ratio, } } @@ -100,12 +102,19 @@ impl Rasterizer { } pub fn load_font(&mut self, desc: &FontDesc, size: Size) -> Option<FontKey> { - self.get_font(desc, size) - .map(|font| { - let key = FontKey::next(); - self.fonts.insert(key, font); - - key + self.keys + .get(&(desc.to_owned(), size)) + .map(|k| *k) + .or_else(|| { + self.get_font(desc, size) + .map(|font| { + let key = FontKey::next(); + + self.fonts.insert(key, font); + self.keys.insert((desc.clone(), size), key); + + key + }) }) } |