aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_thread
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-04-04 14:35:15 +0200
committerGitHub <noreply@github.com>2024-04-04 12:35:15 +0000
commitfe8b23d14a006de5569f967d6d6a78a46d48f367 (patch)
treec32b893761cf941c1187cdb610704f6e120b37d9 /components/layout_thread
parent24c3a2df1eb63a75274eb219128f305aabc236c2 (diff)
downloadservo-fe8b23d14a006de5569f967d6d6a78a46d48f367.tar.gz
servo-fe8b23d14a006de5569f967d6d6a78a46d48f367.zip
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.
Diffstat (limited to 'components/layout_thread')
-rw-r--r--components/layout_thread/lib.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs
index 1ed1db20a91..7fec0013cc2 100644
--- a/components/layout_thread/lib.rs
+++ b/components/layout_thread/lib.rs
@@ -92,6 +92,7 @@ use style::media_queries::{Device, MediaList, MediaType};
use style::properties::style_structs::Font;
use style::properties::PropertyId;
use style::selector_parser::{PseudoElement, SnapshotMap};
+use style::servo::media_queries::FontMetricsProvider;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
use style::stylesheets::{
@@ -263,6 +264,10 @@ impl Layout for LayoutThread {
self.handle_request(Request::FromFontCache);
}
+ fn device<'a>(&'a self) -> &'a Device {
+ self.stylist.device()
+ }
+
fn waiting_for_web_fonts_to_load(&self) -> bool {
self.outstanding_web_fonts.load(Ordering::SeqCst) != 0
}
@@ -506,6 +511,7 @@ impl LayoutThread {
QuirksMode::NoQuirks,
window_size.initial_viewport,
window_size.device_pixel_ratio,
+ Box::new(LayoutFontMetricsProvider),
);
// Ask the router to proxy IPC messages from the font cache thread to layout.
@@ -1477,6 +1483,7 @@ impl LayoutThread {
self.stylist.quirks_mode(),
window_size_data.initial_viewport,
window_size_data.device_pixel_ratio,
+ Box::new(LayoutFontMetricsProvider),
);
// Preserve any previously computed root font size.
@@ -1684,3 +1691,19 @@ impl RegisteredPainters for RegisteredPaintersImpl {
.map(|painter| painter as &dyn RegisteredPainter)
}
}
+
+#[derive(Debug)]
+struct LayoutFontMetricsProvider;
+
+impl FontMetricsProvider for LayoutFontMetricsProvider {
+ fn query_font_metrics(
+ &self,
+ _vertical: bool,
+ _font: &Font,
+ _base_size: style::values::computed::CSSPixelLength,
+ _in_media_query: bool,
+ _retrieve_math_scales: bool,
+ ) -> style::font_metrics::FontMetrics {
+ Default::default()
+ }
+}