fonts: Merge multiple methods into PlatformFont::descriptor() (#32115)

This combines `style()`, `boldness()`, `stretchiness()` into a
`descriptor()` method which is used when creating `FontTemplate`s for
web fonts. Eventually this method will simply read font tables using
skrifa. This is the first step.

In addition, `family_name()` and `face_name()` are removed. They were
only used for debugging and the `FontIdentifier` serves for that. On
Windows, this was adding another way in which font loading could fail,
without buying us very much. The path or URL to the font is more
important when debugging than the names in the font tables.

Closes #15103.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they should not change
observable behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->

<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->
This commit is contained in:
Martin Robinson 2024-04-23 15:27:32 +02:00 committed by GitHub
parent 7ca920927c
commit de47dfe5c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 126 additions and 226 deletions

View file

@ -26,6 +26,7 @@ use crate::font::{
FractionalPixel, PlatformFontMethods, GPOS, GSUB, KERN,
};
use crate::font_cache_thread::FontIdentifier;
use crate::font_template::FontTemplateDescriptor;
use crate::text::glyph::GlyphId;
const KERN_PAIR_LEN: usize = 6;
@ -187,24 +188,13 @@ impl PlatformFontMethods for PlatformFont {
Ok(handle)
}
fn family_name(&self) -> Option<String> {
Some(self.ctfont.family_name())
}
fn face_name(&self) -> Option<String> {
Some(self.ctfont.face_name())
}
fn style(&self) -> FontStyle {
self.ctfont.all_traits().style()
}
fn boldness(&self) -> FontWeight {
self.ctfont.all_traits().weight()
}
fn stretchiness(&self) -> FontStretch {
self.ctfont.all_traits().stretch()
fn descriptor(&self) -> FontTemplateDescriptor {
let traits = self.ctfont.all_traits();
FontTemplateDescriptor {
weight: traits.weight(),
stretch: traits.stretch(),
style: traits.style(),
}
}
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {