aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/platform/macos
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-04-17 19:44:34 +0200
committerGitHub <noreply@github.com>2024-04-17 17:44:34 +0000
commit5393d30a8eb92f0a62ca37bb1486927fdf3604ff (patch)
tree6702ced909c9c5c0de3d1df243c26810bbba4518 /components/gfx/platform/macos
parente9e46f4c0bf54c9ed1ba70c33cc9bcfe33c5e1c7 (diff)
downloadservo-5393d30a8eb92f0a62ca37bb1486927fdf3604ff.tar.gz
servo-5393d30a8eb92f0a62ca37bb1486927fdf3604ff.zip
Simplify `FontHandle` and rename it to `PlatformFont` (#32101)
* Simplify `FontHandle` and rename it to `PlatformFont` Rename it to `PlatformFont` and move the `FontTemplate` member to `Font`, because it's shared by all platforms. * Update components/gfx/platform/freetype/font.rs Co-authored-by: Mukilan Thiyagarajan <mukilanthiagarajan@gmail.com> * Fix build for MacOS and Windows --------- Co-authored-by: Mukilan Thiyagarajan <mukilanthiagarajan@gmail.com>
Diffstat (limited to 'components/gfx/platform/macos')
-rw-r--r--components/gfx/platform/macos/font.rs23
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())
}