Stylo's Device should have access to font metrics
Loirooriol opened this issue · comments
In Gecko, Device
has a document
member: https://searchfox.org/mozilla-central/rev/511d9c9e2eb0f2291dc2b2a5462ba054dfc2edfe/servo/components/style/gecko/media_queries.rs#37
From there is can get the nsPresContext
, which is used to get the font metrics to resolve line-height
:
- https://searchfox.org/mozilla-central/rev/511d9c9e2eb0f2291dc2b2a5462ba054dfc2edfe/servo/components/style/gecko/media_queries.rs#125-143
- https://searchfox.org/mozilla-central/rev/511d9c9e2eb0f2291dc2b2a5462ba054dfc2edfe/layout/generic/ReflowInput.cpp#2789-2794
Servo should do something similar in order to have proper support for lh
units: https://bugzilla.mozilla.org/show_bug.cgi?id=1310170
I think layout2020 gets the font metrics like this:
crate::context::with_thread_local_font_context(layout_context, |font_context| {
get_font_for_first_font_for_style(style, font_context)
.map(|font| font.borrow().metrics.clone())
});
and legacy like
pub fn font_metrics_for_style(
font_context: &mut LayoutFontContext,
style: crate::ServoArc<FontStyleStruct>,
) -> FontMetrics {
let font_group = font_context.font_group(style);
let font = font_group.borrow_mut().first(font_context);
let font = font.as_ref().unwrap().borrow();
font.metrics.clone()
}
where the LayoutFontContext
comes from something like
with_thread_local_font_context(self.layout_context, |font_context| {
inline_flow
.minimum_line_metrics(font_context, &node.style(self.style_context()))
});
So it seems we need to somehow expose the LayoutContext
of both 2020 and 2013 (they are different) to Device
.
cc @emilio
This will likely need to be exposed to Stylo using some sort of trait, I suspect.
How does servo implement stuff like ex units? Servo should have a font metrics provider that works for this, right?
Looks like this is currently unsupported: #14079.
I have a patch in progress for this one.