fonts: Simplify FontContext in two ways that affect the unit test (#33541)

This is done by no longer forwarding compositor-bound messages through
SystemFontService and making `FontContext` non-generic:

- Messages from the `FontContext` to the `Compositor` no longer need to be
  forwarded through the `SystemFontService`. Instead send these messages
  directly through the script IPC channel to the `Compositor`.

- Instead of adding a mock `SystemFontServiceProxy`, simply implement a
  mock `SystemFontService` on the other side of an IPC channel in the
  `font_context` unit test. This allows making `FontContext`
  non-generic, greatly simplifying the code. The extra complexity moves
  into the unit test.

These changes necessitate adding a new kind of `FontIdentifier`,
`FontIdentifier::Mock` due to the fact that local fonts have
platform-specific identifiers. This avoids having to pretend like the
system font service can have web fonts -- which was always a bit of a
hack.

These two changes are combined into one PR because they both require
extensive and similar chages in the font_context unit test which
dependended on the details of both of them.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-09-25 22:15:47 +02:00 committed by GitHub
parent 1daa0b4fc7
commit ac567645a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 482 additions and 425 deletions

View file

@ -19,7 +19,8 @@ use style::Atom;
use super::xml::{Attribute, Node};
use crate::{
FallbackFontSelectionOptions, FontTemplate, FontTemplateDescriptor, LowercaseFontFamilyName,
FallbackFontSelectionOptions, FontIdentifier, FontTemplate, FontTemplateDescriptor,
LowercaseFontFamilyName,
};
static FONT_LIST: LazyLock<FontList> = LazyLock::new(|| FontList::new());
@ -491,9 +492,10 @@ where
None => StyleFontStyle::NORMAL,
};
let descriptor = FontTemplateDescriptor::new(weight, stretch, style);
callback(FontTemplate::new_for_local_font(
local_font_identifier,
callback(FontTemplate::new(
FontIdentifier::Local(local_font_identifier),
descriptor,
None,
));
};

View file

@ -36,7 +36,10 @@ use super::c_str_to_string;
use crate::font::map_platform_values_to_style_values;
use crate::font_template::{FontTemplate, FontTemplateDescriptor};
use crate::platform::add_noto_fallback_families;
use crate::{EmojiPresentationPreference, FallbackFontSelectionOptions, LowercaseFontFamilyName};
use crate::{
EmojiPresentationPreference, FallbackFontSelectionOptions, FontIdentifier,
LowercaseFontFamilyName,
};
/// An identifier for a local font on systems using Freetype.
#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
@ -155,9 +158,10 @@ where
};
let descriptor = FontTemplateDescriptor::new(weight, stretch, style);
callback(FontTemplate::new_for_local_font(
local_font_identifier,
callback(FontTemplate::new(
FontIdentifier::Local(local_font_identifier),
descriptor,
None,
))
}

View file

@ -22,7 +22,7 @@ use style::Atom;
use unicode_script::Script;
use crate::{
EmojiPresentationPreference, FallbackFontSelectionOptions, FontTemplate,
EmojiPresentationPreference, FallbackFontSelectionOptions, FontIdentifier, FontTemplate,
FontTemplateDescriptor, LowercaseFontFamilyName,
};
@ -492,9 +492,10 @@ where
None => StyleFontStyle::NORMAL,
};
let descriptor = FontTemplateDescriptor::new(weight, stretch, style);
callback(FontTemplate::new_for_local_font(
local_font_identifier,
callback(FontTemplate::new(
FontIdentifier::Local(local_font_identifier),
descriptor,
None,
));
};

View file

@ -86,7 +86,7 @@ impl CoreTextFontCache {
core_text::font::new_from_descriptor(&descriptor, clamped_pt_size)
},
FontIdentifier::Web(_) => {
FontIdentifier::Web(_) | FontIdentifier::Mock(_) => {
let provider = CGDataProvider::from_buffer(data);
let cgfont = CGFont::from_data_provider(provider).ok()?;
core_text::font::new_from_CGFont(&cgfont, clamped_pt_size)

View file

@ -18,7 +18,7 @@ use webrender_api::NativeFontHandle;
use crate::platform::add_noto_fallback_families;
use crate::platform::font::CoreTextFontTraitsMapping;
use crate::{
EmojiPresentationPreference, FallbackFontSelectionOptions, FontTemplate,
EmojiPresentationPreference, FallbackFontSelectionOptions, FontIdentifier, FontTemplate,
FontTemplateDescriptor, LowercaseFontFamilyName,
};
@ -85,7 +85,11 @@ where
postscript_name: Atom::from(family_descriptor.font_name()),
path: Atom::from(path),
};
callback(FontTemplate::new_for_local_font(identifier, descriptor));
callback(FontTemplate::new(
FontIdentifier::Local(identifier),
descriptor,
None,
));
}
}
}

View file

@ -14,7 +14,7 @@ use style::values::computed::{FontStyle as StyleFontStyle, FontWeight as StyleFo
use style::values::specified::font::FontStretchKeyword;
use crate::{
EmojiPresentationPreference, FallbackFontSelectionOptions, FontTemplate,
EmojiPresentationPreference, FallbackFontSelectionOptions, FontIdentifier, FontTemplate,
FontTemplateDescriptor, LowercaseFontFamilyName,
};
@ -78,9 +78,10 @@ where
let local_font_identifier = LocalFontIdentifier {
font_descriptor: Arc::new(font.to_descriptor()),
};
callback(FontTemplate::new_for_local_font(
local_font_identifier,
callback(FontTemplate::new(
FontIdentifier::Local(local_font_identifier),
template_descriptor,
None,
))
}
}