diff options
Diffstat (limited to 'components/gfx/platform/macos')
-rw-r--r-- | components/gfx/platform/macos/font.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index 05e8fdc0614..477ec36e3cd 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -4,6 +4,7 @@ use std::cmp::Ordering; use std::ops::Range; +use std::sync::Arc; use std::{fmt, ptr}; /// Implementation of Quartz (CoreGraphics) fonts. @@ -22,7 +23,7 @@ use style::values::computed::font::{FontStretch, FontStyle, FontWeight}; use super::font_template::CoreTextFontTemplateMethods; use crate::font::{ - FontHandleMethods, FontMetrics, FontTableMethods, FontTableTag, FractionalPixel, GPOS, GSUB, + FontMetrics, FontTableMethods, FontTableTag, FractionalPixel, PlatformFontMethods, GPOS, GSUB, KERN, }; use crate::font_template::FontTemplateRef; @@ -52,14 +53,16 @@ impl FontTableMethods for FontTable { } #[derive(Debug)] -pub struct FontHandle { - font_template: FontTemplateRef, +pub struct PlatformFont { ctfont: CTFont, + /// A reference to this data used to create this [`PlatformFont`], ensuring the + /// data stays alive of the lifetime of this struct. + _data: Option<Arc<Vec<u8>>>, h_kern_subtable: Option<CachedKernTable>, can_do_fast_shaping: bool, } -impl FontHandle { +impl PlatformFont { /// Cache all the data needed for basic horizontal kerning. This is used only as a fallback or /// fast path (when the GPOS table is missing or unnecessary) so it needn't handle every case. fn find_h_kern_subtable(&self) -> Option<CachedKernTable> { @@ -154,11 +157,11 @@ impl fmt::Debug for CachedKernTable { } } -impl FontHandleMethods for FontHandle { +impl PlatformFontMethods for PlatformFont { fn new_from_template( font_template: FontTemplateRef, pt_size: Option<Au>, - ) -> Result<FontHandle, &'static str> { + ) -> Result<PlatformFont, &'static str> { let size = match pt_size { Some(s) => s.to_f64_px(), None => 0.0, @@ -167,8 +170,8 @@ impl FontHandleMethods for FontHandle { return Err("Could not generate CTFont for FontTemplateData"); }; - let mut handle = FontHandle { - font_template, + let mut handle = PlatformFont { + _data: font_template.borrow().data_if_in_memory(), ctfont: core_text_font.clone_with_font_size(size), h_kern_subtable: None, can_do_fast_shaping: false, @@ -181,10 +184,6 @@ impl FontHandleMethods for FontHandle { Ok(handle) } - fn template(&self) -> FontTemplateRef { - self.font_template.clone() - } - fn family_name(&self) -> Option<String> { Some(self.ctfont.family_name()) } |