aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/platform/windows/font.rs
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/windows/font.rs
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/windows/font.rs')
-rw-r--r--components/gfx/platform/windows/font.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/components/gfx/platform/windows/font.rs b/components/gfx/platform/windows/font.rs
index a2156f85e73..3baef67ca28 100644
--- a/components/gfx/platform/windows/font.rs
+++ b/components/gfx/platform/windows/font.rs
@@ -8,6 +8,7 @@
use std::fmt;
use std::ops::Deref;
+use std::sync::Arc;
use app_units::Au;
use dwrote::{Font, FontFace, FontFile, FontStretch, FontStyle};
@@ -18,7 +19,7 @@ use style::values::computed::font::FontStyle as StyleFontStyle;
use style::values::specified::font::FontStretchKeyword;
use crate::font::{
- FontHandleMethods, FontMetrics, FontTableMethods, FontTableTag, FractionalPixel,
+ FontMetrics, FontTableMethods, FontTableTag, FractionalPixel, PlatformFontMethods,
};
use crate::font_cache_thread::FontIdentifier;
use crate::font_template::{FontTemplateRef, FontTemplateRefMethods};
@@ -198,9 +199,11 @@ impl FontInfo {
}
#[derive(Debug)]
-pub struct FontHandle {
- font_template: FontTemplateRef,
+pub struct PlatformFont {
face: Nondebug<FontFace>,
+ /// 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>>>,
info: FontInfo,
em_size: f32,
du_to_px: f32,
@@ -222,9 +225,7 @@ impl<T> Deref for Nondebug<T> {
}
}
-impl FontHandle {}
-
-impl FontHandleMethods for FontHandle {
+impl PlatformFontMethods for PlatformFont {
fn new_from_template(
font_template: FontTemplateRef,
pt_size: Option<Au>,
@@ -234,8 +235,12 @@ impl FontHandleMethods for FontHandle {
FontIdentifier::Web(_) => None,
};
- let (face, info) = match direct_write_font {
- Some(font) => (font.create_font_face(), FontInfo::new_from_font(&font)?),
+ let (face, info, data) = match direct_write_font {
+ Some(font) => (
+ font.create_font_face(),
+ FontInfo::new_from_font(&font)?,
+ None,
+ ),
None => {
let bytes = font_template.data();
let font_file =
@@ -244,7 +249,7 @@ impl FontHandleMethods for FontHandle {
.create_face(0, dwrote::DWRITE_FONT_SIMULATIONS_NONE)
.map_err(|_| "Could not create FontFace")?;
let info = FontInfo::new_from_face(&face)?;
- (face, info)
+ (face, info, font_template.borrow().data_if_in_memory())
},
};
@@ -257,9 +262,9 @@ impl FontHandleMethods for FontHandle {
let design_units_to_pixels = 1. / design_units_per_pixel;
let scaled_design_units_to_pixels = em_size / design_units_per_pixel;
- Ok(FontHandle {
- font_template,
+ Ok(PlatformFont {
face: Nondebug(face),
+ data,
info,
em_size,
du_to_px: design_units_to_pixels,
@@ -267,10 +272,6 @@ impl FontHandleMethods for FontHandle {
})
}
- fn template(&self) -> FontTemplateRef {
- self.font_template.clone()
- }
-
fn family_name(&self) -> Option<String> {
Some(self.info.family_name.clone())
}