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>
This commit is contained in:
Martin Robinson 2024-04-17 19:44:34 +02:00 committed by GitHub
parent e9e46f4c0b
commit 5393d30a8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 71 additions and 80 deletions

View file

@ -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())
}