layout: Add a FontMetricsProvider for resolving font-relative units (#31966)

The only font relative unit that Servo knows how to resolve currently is
`rem` (relative to the root font size). This is because Stylo cannot do
any font queries. This adds a mechanism to allow this, exposing the
ability to properly render `ex` units in Servo.

This change only allows resolving some font size relative units thoug,
as Servo doesn't collect all the FontMetrics it needs to resolve them
all. This capability will be added in followup changes.

Some new tests fail:
 - ex-unit-001.html: This test fails because Servo does not yet have
   support for setting the weight using @font-face rules on web fonts.
 - ex-unit-004.html: This test fails because Servo does not yet have
   support for setting the Unicode range of a web font using @font-face
   rules.
 - first-available-font-001.html: This test fails because the above
   two feature are missing.
This commit is contained in:
Martin Robinson 2024-04-04 14:35:15 +02:00 committed by GitHub
parent 24c3a2df1e
commit fe8b23d14a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
98 changed files with 208 additions and 232 deletions

View file

@ -669,10 +669,8 @@ impl HTMLImageElement {
_width: Option<Length>,
) -> Au {
let document = document_from_node(self);
let device = document.device();
let quirks_mode = document.quirks_mode();
//FIXME https://github.com/whatwg/html/issues/3832
source_size_list.evaluate(&device, quirks_mode)
document.with_device(move |device| source_size_list.evaluate(device, quirks_mode))
}
/// <https://html.spec.whatwg.org/multipage/#matches-the-environment>
@ -698,7 +696,7 @@ impl HTMLImageElement {
let mut parserInput = ParserInput::new(&media_query);
let mut parser = Parser::new(&mut parserInput);
let media_list = MediaList::parse(&context, &mut parser);
media_list.evaluate(&document.device(), quirks_mode)
document.with_device(move |device| media_list.evaluate(device, quirks_mode))
}
/// <https://html.spec.whatwg.org/multipage/#normalise-the-source-densities>
@ -769,11 +767,14 @@ impl HTMLImageElement {
// Step 5
let mut best_candidate = max;
let device = document_from_node(self).device();
let device_den = device.device_pixel_ratio().get() as f64;
let device_pixel_ratio = document_from_node(self)
.window()
.window_size()
.device_pixel_ratio
.get() as f64;
for (index, image_source) in img_sources.iter().enumerate() {
let current_den = image_source.descriptor.den.unwrap();
if current_den < best_candidate.0 && current_den >= device_den {
if current_den < best_candidate.0 && current_den >= device_pixel_ratio {
best_candidate = (current_den, index);
}
}