diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2015-08-04 17:05:42 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2015-08-04 17:07:44 -0700 |
commit | d6b9e3bdfd8b473b9251de0f0d277f42d9b75fc5 (patch) | |
tree | 7b90a2e2b182523698835f216d6882248cb6dda0 /components/gfx/platform/macos | |
parent | 56d3426431d98a6f43698f33bb7ce4d3ad67adeb (diff) | |
download | servo-d6b9e3bdfd8b473b9251de0f0d277f42d9b75fc5.tar.gz servo-d6b9e3bdfd8b473b9251de0f0d277f42d9b75fc5.zip |
gfx: Fix Core Text font instantiation for Web fonts on Mac.
Fixes GitHub Octicons. A reftest has been added for this.
Diffstat (limited to 'components/gfx/platform/macos')
-rw-r--r-- | components/gfx/platform/macos/font.rs | 6 | ||||
-rw-r--r-- | components/gfx/platform/macos/font_template.rs | 28 |
2 files changed, 15 insertions, 19 deletions
diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index b8474aa6da9..6ef613572d5 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -57,9 +57,9 @@ pub struct FontHandle { impl FontHandleMethods for FontHandle { fn new_from_template(_fctx: &FontContextHandle, - template: Arc<FontTemplateData>, - pt_size: Option<Au>) - -> Result<FontHandle, ()> { + template: Arc<FontTemplateData>, + pt_size: Option<Au>) + -> Result<FontHandle, ()> { let size = match pt_size { Some(s) => s.to_f64_px(), None => 0.0 diff --git a/components/gfx/platform/macos/font_template.rs b/components/gfx/platform/macos/font_template.rs index e84691971ac..7e8229babe1 100644 --- a/components/gfx/platform/macos/font_template.rs +++ b/components/gfx/platform/macos/font_template.rs @@ -38,22 +38,8 @@ unsafe impl Sync for FontTemplateData {} impl FontTemplateData { pub fn new(identifier: Atom, font_data: Option<Vec<u8>>) -> FontTemplateData { - let ctfont = match font_data { - Some(ref bytes) => { - let fontprov = CGDataProvider::from_buffer(bytes); - let cgfont_result = CGFont::from_data_provider(fontprov); - match cgfont_result { - Ok(cgfont) => Some(core_text::font::new_from_CGFont(&cgfont, 0.0)), - Err(_) => None - } - }, - None => { - Some(core_text::font::new_from_name(identifier.as_slice(), 0.0).unwrap()) - } - }; - FontTemplateData { - ctfont: CachedCTFont(Mutex::new(ctfont)), + ctfont: CachedCTFont(Mutex::new(None)), identifier: identifier.to_owned(), font_data: font_data } @@ -63,7 +49,17 @@ impl FontTemplateData { pub fn ctfont(&self) -> Option<CTFont> { let mut ctfont = self.ctfont.lock().unwrap(); if ctfont.is_none() { - *ctfont = core_text::font::new_from_name(self.identifier.as_slice(), 0.0).ok() + *ctfont = match self.font_data { + Some(ref bytes) => { + let fontprov = CGDataProvider::from_buffer(bytes); + let cgfont_result = CGFont::from_data_provider(fontprov); + match cgfont_result { + Ok(cgfont) => Some(core_text::font::new_from_CGFont(&cgfont, 0.0)), + Err(_) => None + } + } + None => core_text::font::new_from_name(self.identifier.as_slice(), 0.0).ok(), + } } ctfont.as_ref().map(|ctfont| (*ctfont).clone()) } |