aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/tests
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-04-16 19:50:50 +0200
committerGitHub <noreply@github.com>2024-04-16 17:50:50 +0000
commit6b2fa91357ea289d03e206018389c43ffd836047 (patch)
tree164367ab35aa156bd944f58a1e6e9f9fa9a967b0 /components/gfx/tests
parent689c14471430bb331ff0d46d5be7e16b81a1de54 (diff)
downloadservo-6b2fa91357ea289d03e206018389c43ffd836047.tar.gz
servo-6b2fa91357ea289d03e206018389c43ffd836047.zip
gfx: Remove `FontTemplateData` (#32034)
Now that `FontTemplateData` is more or less the same on all platforms, it can be removed. This is a preparatory change for a full refactor of the font system on Servo. The major changes here are: - Remove `FontTemplateData` and move its members into `FontTemplate` - Make `FontTemplate` have full interior mutability instead of only the `FontTemplateData` member. This is preparation for having these data types `Send` and `Sync` with locking. - Remove the strong/weak reference concept for font data. In practice, all font data references were strong, so this was never fully complete. Instead of using this approach, the new font system will use a central font data cache with references associated to layouts. - The `CTFont` cache is now a global cache, so `CTFont`s can be shared between threads. The cache is cleared when clearing font caches. A benefit of this change (apart from `CTFont` sharing) is that font data loading is platform-independent now.
Diffstat (limited to 'components/gfx/tests')
-rw-r--r--components/gfx/tests/font_context.rs13
-rw-r--r--components/gfx/tests/font_template.rs7
2 files changed, 12 insertions, 8 deletions
diff --git a/components/gfx/tests/font_context.rs b/components/gfx/tests/font_context.rs
index 24965e272f1..9d26f7603dd 100644
--- a/components/gfx/tests/font_context.rs
+++ b/components/gfx/tests/font_context.rs
@@ -11,7 +11,8 @@ use std::rc::Rc;
use app_units::Au;
use gfx::font::{
- fallback_font_families, FontDescriptor, FontFamilyDescriptor, FontFamilyName, FontSearchScope,
+ fallback_font_families, FontDescriptor, FontFamilyDescriptor, FontFamilyName,
+ FontHandleMethods, FontSearchScope,
};
use gfx::font_cache_thread::{FontIdentifier, FontTemplateInfo, FontTemplates};
use gfx::font_context::{FontContext, FontSource};
@@ -175,7 +176,7 @@ fn test_font_group_find_by_codepoint() {
.find_by_codepoint(&mut context, 'a')
.unwrap();
assert_eq!(
- *font.borrow().identifier(),
+ font.borrow().handle.template().borrow().identifier,
TestFontSource::identifier_for_font_name("csstest-ascii")
);
assert_eq!(
@@ -189,7 +190,7 @@ fn test_font_group_find_by_codepoint() {
.find_by_codepoint(&mut context, 'a')
.unwrap();
assert_eq!(
- *font.borrow().identifier(),
+ font.borrow().handle.template().borrow().identifier,
TestFontSource::identifier_for_font_name("csstest-ascii")
);
assert_eq!(
@@ -203,7 +204,7 @@ fn test_font_group_find_by_codepoint() {
.find_by_codepoint(&mut context, 'á')
.unwrap();
assert_eq!(
- *font.borrow().identifier(),
+ font.borrow().handle.template().borrow().identifier,
TestFontSource::identifier_for_font_name("csstest-basic-regular")
);
assert_eq!(count.get(), 2, "both fonts should now have been loaded");
@@ -224,7 +225,7 @@ fn test_font_fallback() {
.find_by_codepoint(&mut context, 'a')
.unwrap();
assert_eq!(
- *font.borrow().identifier(),
+ font.borrow().handle.template().borrow().identifier,
TestFontSource::identifier_for_font_name("csstest-ascii"),
"a family in the group should be used if there is a matching glyph"
);
@@ -234,7 +235,7 @@ fn test_font_fallback() {
.find_by_codepoint(&mut context, 'á')
.unwrap();
assert_eq!(
- *font.borrow().identifier(),
+ font.borrow().handle.template().borrow().identifier,
TestFontSource::identifier_for_font_name("csstest-basic-regular"),
"a fallback font should be used if there is no matching glyph in the group"
);
diff --git a/components/gfx/tests/font_template.rs b/components/gfx/tests/font_template.rs
index d35c3607497..5c8e9f8b37a 100644
--- a/components/gfx/tests/font_template.rs
+++ b/components/gfx/tests/font_template.rs
@@ -6,12 +6,14 @@
#[cfg(not(target_os = "macos"))]
#[test]
fn test_font_template_descriptor() {
+ use std::cell::RefCell;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
+ use std::rc::Rc;
use gfx::font_cache_thread::FontIdentifier;
- use gfx::font_template::{FontTemplate, FontTemplateDescriptor};
+ use gfx::font_template::{FontTemplate, FontTemplateDescriptor, FontTemplateRefMethods};
use servo_url::ServoUrl;
use style::values::computed::font::{FontStretch, FontStyle, FontWeight};
@@ -28,11 +30,12 @@ fn test_font_template_descriptor() {
path.push(format!("{}.ttf", filename));
let file = File::open(path.clone()).unwrap();
- let mut template = FontTemplate::new(
+ let template = FontTemplate::new(
FontIdentifier::Web(ServoUrl::from_file_path(path).unwrap()),
Some(file.bytes().map(|b| b.unwrap()).collect()),
)
.unwrap();
+ let template = Rc::new(RefCell::new(template));
template.descriptor().unwrap()
}