Truly independent web browser
LibWeb: Scale lengths and font sizes by the unrounded font size
sideshowbarker2624a54641d8
diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/canvas.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/canvas.rsindex 702b71d2947..4367f626989 100644--- a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/canvas.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/canvas.rs@@ -113,8 +113,8 @@ unsafe extern "C" {pub(crate) struct FontMetricsSource {/// The Gfx::FontCascadeList of the font, or null for the font that a context starts with.cascade: *const c_void,- /// The size of the font, as the raw value of a CSSPixels.- font_size: i32,+ /// The computed size of the font in pixels, unrounded, which lengths relative to it scale.+ font_size: f64,}impl FontMetricsSource {@@ -126,7 +126,7 @@ impl FontMetricsSource {},None => Self {cascade: core::ptr::null(),- font_size: 0,+ font_size: 0.0,},}}@@ -138,7 +138,7 @@ struct ResolvedFontAbi {/// A Gfx::FontCascadeList with a reference that the caller takes over.cascade: *const c_void,environment_generation: u64,- font_size: i32,+ font_size: f64,/// An AK::Utf16String that the caller takes over.serialized: usize,}@@ -171,8 +171,8 @@ impl FontSelection {pub(crate) struct ResolvedFont {pub(crate) cascade: FontCascadeListHandle,pub(crate) environment_generation: u64,- /// The size of the font, as the raw value of a CSSPixels.- pub(crate) font_size: i32,+ /// The computed size of the font in pixels, unrounded, which lengths relative to it scale.+ pub(crate) font_size: f64,pub(crate) serialized: Utf16String,}@@ -300,7 +300,7 @@ impl Canvas {let mut resolved = ResolvedFontAbi {cascade: core::ptr::null(),environment_generation: 0,- font_size: 0,+ font_size: 0.0,serialized: 0,};let is_font = unsafe {diff --git a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cppindex 186f3f156df..7bebc948f6d 100644--- a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp+++ b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp@@ -401,6 +401,7 @@ ComputedValuesFFI::FfiFontGroupBuildInputs ComputedStyleWorkingSet::font_group_bauto math_style = keyword_to_math_style(property(PropertyID::MathStyle).to_keyword()).release_value();return {.font_size_raw = font_size().raw_value(),+ .font_size = font_size_for_lengths(),.line_height_used_raw = line_height(document.font_computer()).raw_value(),.font_variant_emoji = to_underlying(font_variant_emoji()),.font_ascent = metrics.ascent,@@ -467,7 +468,12 @@ Optional<FontSizeAdjust> ComputedStyleWorkingSet::font_size_adjust() constCSSPixels ComputedStyleWorkingSet::font_size() const{- return CSSPixels { StyleValueFFI::rust_style_value_computed_length_value(effective_property_data(PropertyID::FontSize)) };+ return CSSPixels { font_size_for_lengths() };+}++double ComputedStyleWorkingSet::font_size_for_lengths() const+{+ return StyleValueFFI::rust_style_value_computed_length_value(effective_property_data(PropertyID::FontSize));}Vector<ComputedFontFamily> ComputedStyleWorkingSet::computed_font_families() constdiff --git a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.hindex 87563a8bc95..60d624358e4 100644--- a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h+++ b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h@@ -91,6 +91,8 @@ public:[[nodiscard]] CSSPixels line_height(FontComputer const&) const;[[nodiscard]] CSSPixels font_size() const;+ // The computed font size, unrounded, which em and rem lengths scale.+ [[nodiscard]] double font_size_for_lengths() const;[[nodiscard]] Optional<FontSizeAdjust> font_size_adjust() const;Vector<ComputedFontFamily> computed_font_families() const;FontOpticalSizing font_optical_sizing() const;diff --git a/Libraries/LibWeb/CSS/ComputedValues.h b/Libraries/LibWeb/CSS/ComputedValues.hindex 851103e324c..0a561ff6e49 100644--- a/Libraries/LibWeb/CSS/ComputedValues.h+++ b/Libraries/LibWeb/CSS/ComputedValues.h@@ -512,6 +512,7 @@ public:Gfx::FontCascadeList const& font_list() const { return m_inherited.font->font_list_value(); }CSSPixels font_size() const { return m_inherited.font->font_size; }+ double font_size_for_lengths() const { return m_inherited.font->font_size_for_lengths(); }double font_weight() const { return m_inherited.font->font_weight; }CSSPixels line_height() const { return m_inherited.font->line_height_used_value(); }@@ -641,6 +642,7 @@ public:WEB_API Gfx::FontCascadeList const& font_list_value() const;FontStyleKeyword font_style_keyword() const;CSSPixels line_height_used_value() const { return CSSPixels::from_raw(ComputedValuesFFI::rust_font_values_line_height_used_raw(this)); }+ double font_size_for_lengths() const { return ComputedValuesFFI::rust_font_values_font_size_for_lengths(this); }};private:diff --git a/Libraries/LibWeb/CSS/FontFace.cpp b/Libraries/LibWeb/CSS/FontFace.cppindex 4ab04bd7b11..17b0a756cbf 100644--- a/Libraries/LibWeb/CSS/FontFace.cpp+++ b/Libraries/LibWeb/CSS/FontFace.cpp@@ -600,7 +600,7 @@ ComputationContext FontFaceState::computation_context() constreturn ComputationContext { .length_resolution_context = Length::ResolutionContext::for_document(*document) };auto const& initial_font = FontComputer::initial_font();auto const& pixel_metrics = initial_font.pixel_metrics();- Length::FontMetrics font_metrics { CSSPixels { initial_font.pixel_size() }, pixel_metrics, normal_line_height(pixel_metrics) };+ Length::FontMetrics font_metrics { initial_font.pixel_size(), pixel_metrics, normal_line_height(pixel_metrics) };return ComputationContext {.length_resolution_context = {.viewport_rect = {},diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cppindex a2b03efa8e8..95f8bae1789 100644--- a/Libraries/LibWeb/CSS/Length.cpp+++ b/Libraries/LibWeb/CSS/Length.cpp@@ -114,7 +114,7 @@ static GC::Ptr<DOM::Element const> get_or_compute_query_container_for_axis(Lengtreturn cached_query_container.value();}-Length::FontMetrics::FontMetrics(CSSPixels font_size, Gfx::FontPixelMetrics const& pixel_metrics, CSSPixels line_height)+Length::FontMetrics::FontMetrics(double font_size, Gfx::FontPixelMetrics const& pixel_metrics, CSSPixels line_height): font_size(font_size), x_height(pixel_metrics.x_height), cap_height(pixel_metrics.cap_height)@@ -234,8 +234,8 @@ Length::ResolutionContext Length::ResolutionContext::for_element(DOM::AbstractElreturn Length::ResolutionContext {.viewport_rect = element.element().navigable()->viewport_rect(),- .font_metrics = { computed_values.font_size(), computed_values.font_list().first_available_font().pixel_metrics(), computed_values.line_height() },- .root_font_metrics = { root_computed_values->font_size(), root_computed_values->font_list().first_available_font().pixel_metrics(), root_computed_values->line_height() },+ .font_metrics = { computed_values.font_size_for_lengths(), computed_values.font_list().first_available_font().pixel_metrics(), computed_values.line_height() },+ .root_font_metrics = { root_computed_values->font_size_for_lengths(), root_computed_values->font_list().first_available_font().pixel_metrics(), root_computed_values->line_height() },.font_metrics_depend_on_viewport_metrics = computed_values.font_metrics_depend_on_viewport_metrics(),.root_font_metrics_depend_on_viewport_metrics = root_computed_values->font_metrics_depend_on_viewport_metrics(),.subject_inline_axis_is_horizontal = inline_axis_is_horizontal(computed_values.writing_mode()),@@ -251,7 +251,7 @@ Length::ResolutionContext Length::ResolutionContext::for_document(DOM::Document// https://drafts.csswg.org/css-values-4/#font-relative-lengths// When used outside the context of an element (such as in media queries), the font-relative lengths units refer// to the metrics corresponding to the initial values of the font and line-height properties.- Length::FontMetrics font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font_metrics, normal_line_height(initial_font_metrics) };+ Length::FontMetrics font_metrics { initial_font.pixel_size(), initial_font_metrics, normal_line_height(initial_font_metrics) };CSSPixelRect viewport_rect;if (document.navigable())@@ -286,8 +286,8 @@ Length::ResolutionContext Length::ResolutionContext::for_layout_node(Layout::Nodreturn Length::ResolutionContext {.viewport_rect = node.navigable()->viewport_rect(),- .font_metrics = { node.font_size(), node.first_available_font().pixel_metrics(), node.line_height() },- .root_font_metrics = { root_layout_node->font_size(), root_layout_node->first_available_font().pixel_metrics(), node.line_height() },+ .font_metrics = { node.font_size_for_lengths(), node.first_available_font().pixel_metrics(), node.line_height() },+ .root_font_metrics = { root_layout_node->font_size_for_lengths(), root_layout_node->first_available_font().pixel_metrics(), node.line_height() },.subject_inline_axis_is_horizontal = inline_axis_is_horizontal(node.writing_mode()),.subject_is_pseudo_element = node.is_generated_for_pseudo_element(),.subject_element = subject_element,@@ -363,9 +363,9 @@ double ratio_between_font_relative_unit_and_px(LengthUnit font_relative_unit, Le{switch (font_relative_unit) {case LengthUnit::Em:- return font_metrics.font_size.to_double();+ return font_metrics.font_size;case LengthUnit::Rem:- return root_font_metrics.font_size.to_double();+ return root_font_metrics.font_size;case LengthUnit::Ex:return font_metrics.x_height.to_double();case LengthUnit::Rex:@@ -380,10 +380,10 @@ double ratio_between_font_relative_unit_and_px(LengthUnit font_relative_unit, Lereturn root_font_metrics.zero_advance.to_double();case LengthUnit::Ic:// FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"- return font_metrics.font_size.to_double();+ return font_metrics.font_size;case LengthUnit::Ric:// FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"- return root_font_metrics.font_size.to_double();+ return root_font_metrics.font_size;case LengthUnit::Lh:return font_metrics.line_height.to_double();case LengthUnit::Rlh:diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.hindex ef98fc40b52..f27a062e755 100644--- a/Libraries/LibWeb/CSS/Length.h+++ b/Libraries/LibWeb/CSS/Length.h@@ -25,9 +25,10 @@ namespace Web::CSS {class WEB_API Length {public:struct WEB_API FontMetrics {- FontMetrics(CSSPixels font_size, Gfx::FontPixelMetrics const&, CSSPixels line_height);+ FontMetrics(double font_size, Gfx::FontPixelMetrics const&, CSSPixels line_height);- CSSPixels font_size;+ // The computed font size, unrounded, so that em and rem lengths scale it exactly.+ double font_size;CSSPixels x_height;CSSPixels cap_height;CSSPixels zero_advance;diff --git a/Libraries/LibWeb/CSS/StyleComputeFFI.h b/Libraries/LibWeb/CSS/StyleComputeFFI.hindex ee10da51eec..1af310b34e4 100644--- a/Libraries/LibWeb/CSS/StyleComputeFFI.h+++ b/Libraries/LibWeb/CSS/StyleComputeFFI.h@@ -30,7 +30,7 @@ inline constexpr u8 all_container_relative_length_units_mask = cqw_container_relinline ComputedValuesFFI::FfiFontMetrics to_ffi_font_metrics(Length::FontMetrics const& metrics){return {- .font_size = metrics.font_size.to_double(),+ .font_size = metrics.font_size,.x_height = metrics.x_height.to_double(),.cap_height = metrics.cap_height.to_double(),.zero_advance = metrics.zero_advance.to_double(),diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cppindex 6b77e60a466..9e7881426c5 100644--- a/Libraries/LibWeb/CSS/StyleComputer.cpp+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp@@ -1218,7 +1218,7 @@ void StyleComputer::sweep_custom_property_environments() constvoid StyleComputer::update_root_element_font_metrics(ComputedValues const& values){- m_root_element_font_metrics = Length::FontMetrics { values.font_size(), values.font_list().first_available_font().pixel_metrics(), values.line_height() };+ m_root_element_font_metrics = Length::FontMetrics { values.font_size_for_lengths(), values.font_list().first_available_font().pixel_metrics(), values.line_height() };m_root_element_font_metrics_depend_on_viewport_metrics = values.font_metrics_depend_on_viewport_metrics();m_root_element_effective_zoom = values.effective_zoom();}@@ -1275,7 +1275,7 @@ Length::ResolutionContext StyleComputer::make_length_resolution_context(LengthRereturn normal_line_height(document().font_computer().initial_font().pixel_metrics());}();auto font_metrics = Length::FontMetrics {- style.font_size(),+ style.font_size_for_lengths(),style.first_available_computed_font(document().font_computer())->pixel_metrics(),line_height};diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cppindex 9b4c3046a91..6c6fc3f14bd 100644--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp@@ -676,19 +676,19 @@ void StyleEngine::gather_computation_inputs(LentComputationInputs& lent)}auto const& root_font_metrics = m_style_computer->root_element_font_metrics();auto const& initial_font = m_style_computer->document().font_computer().initial_font();- Length::FontMetrics const initial_font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font.pixel_metrics(), normal_line_height(initial_font.pixel_metrics()) };+ Length::FontMetrics const initial_font_metrics { initial_font.pixel_size(), initial_font.pixel_metrics(), normal_line_height(initial_font.pixel_metrics()) };lent.inputs = {.in_quirks_mode = m_style_computer->document().in_quirks_mode(),.viewport_width = viewport_rect.width().to_double(),.viewport_height = viewport_rect.height().to_double(),- .root_font_size = root_font_metrics.font_size.to_double(),+ .root_font_size = root_font_metrics.font_size,.root_font_x_height = root_font_metrics.x_height.to_double(),.root_font_cap_height = root_font_metrics.cap_height.to_double(),.root_font_zero_advance = root_font_metrics.zero_advance.to_double(),.root_line_height = root_font_metrics.line_height.to_double(),.root_font_metrics_depend_on_viewport_metrics = m_style_computer->root_element_font_metrics_depend_on_viewport_metrics(),.root_effective_zoom = m_style_computer->root_element_effective_zoom(),- .initial_font_size = initial_font_metrics.font_size.to_double(),+ .initial_font_size = initial_font_metrics.font_size,.initial_font_x_height = initial_font_metrics.x_height.to_double(),.initial_font_cap_height = initial_font_metrics.cap_height.to_double(),.initial_font_zero_advance = initial_font_metrics.zero_advance.to_double(),diff --git a/Libraries/LibWeb/HTML/Canvas/Canvas2DContextBase.cpp b/Libraries/LibWeb/HTML/Canvas/Canvas2DContextBase.cppindex 4c97beef10e..e8daff30bd6 100644--- a/Libraries/LibWeb/HTML/Canvas/Canvas2DContextBase.cpp+++ b/Libraries/LibWeb/HTML/Canvas/Canvas2DContextBase.cpp@@ -84,8 +84,8 @@ struct ContextCreationArguments {// `FontMetricsSource` of Bindings/Rust/src/canvas_2d/canvas.rs: the font of the context, if it has one yet.struct FontMetricsSource {Gfx::FontCascadeList const* cascade { nullptr };- // The size of the font, as the raw value of a CSSPixels.- i32 font_size { 0 };+ // The computed size of the font in pixels, unrounded, which lengths relative to it scale.+ double font_size { 0 };};// `ResolvedFontAbi` of Bindings/Rust/src/canvas_2d/canvas.rs.@@ -93,7 +93,7 @@ struct ResolvedFont {// A Gfx::FontCascadeList with a reference that Rust takes over.Gfx::FontCascadeList const* cascade { nullptr };u64 environment_generation { 0 };- i32 font_size { 0 };+ double font_size { 0 };// An AK::Utf16String that Rust takes over.FlatPtr serialized { 0 };};@@ -525,7 +525,7 @@ static bool resolve_font(CanvasType& canvas_element, Utf16View font, CanvasFontSout_font = {.cascade = &cascade.leak_ref(),.environment_generation = font_computer.environment_generation(),- .font_size = font_size.raw_value(),+ .font_size = computed_font_size->as_length().length().absolute_length_to_px_without_rounding(),// On getting, the font attribute must return the serialized form of the current font of the context (with no 'line-height' component)..serialized = resolved_font_style_value->to_utf16_string(CSS::SerializationMode::ResolvedValue).into_raw(),};@@ -553,7 +553,7 @@ static CSS::ComputationContext computation_context_for(CanvasHost& canvas_host,}auto const& first_font = font.cascade->first_available_font();- return CSS::Length::FontMetrics { CSSPixels::from_raw(font.font_size), first_font.pixel_metrics(), CSS::InitialValues::line_height() };+ return CSS::Length::FontMetrics { font.font_size, first_font.pixel_metrics(), CSS::InitialValues::line_height() };}();return {diff --git a/Libraries/LibWeb/Layout/Node.h b/Libraries/LibWeb/Layout/Node.hindex cee9121070e..d08e547d2ce 100644--- a/Libraries/LibWeb/Layout/Node.h+++ b/Libraries/LibWeb/Layout/Node.h@@ -474,6 +474,7 @@ public:Color text_decoration_color() const { return CSS::resolve_style_color(style_group<CSS::ComputedValues::TextResetValues>().text_decoration_color, color()); }CSSPixels line_height() const { return style_group<CSS::ComputedValues::FontValues>().line_height_used_value(); }CSSPixels font_size() const { return style_group<CSS::ComputedValues::FontValues>().font_size; }+ double font_size_for_lengths() const { return style_group<CSS::ComputedValues::FontValues>().font_size_for_lengths(); }Gfx::FontCascadeList const& font_list() const { return style_group<CSS::ComputedValues::FontValues>().font_list_value(); }CSS::LengthBox inset() const { return length_box(style_group<CSS::ComputedValues::SurroundValues>().inset); }CSS::LengthBox margin() const { return length_box(style_group<CSS::ComputedValues::SurroundValues>().margin); }diff --git a/Libraries/LibWeb/Rust/src/css/computed_value_types.rs b/Libraries/LibWeb/Rust/src/css/computed_value_types.rsindex 504d51af5fa..1e7f4cbafe7 100644--- a/Libraries/LibWeb/Rust/src/css/computed_value_types.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_value_types.rs@@ -741,6 +741,19 @@ pub struct FirstAvailableFontMetrics {}impl FontValues {+ /// The computed font size, which `font_size` holds rounded to the nearest pixel fraction, as+ /// the lengths relative to it read it: An em or rem length scales the size unrounded.+ pub fn font_size_for_lengths(&self) -> f64 {+ match self.font_size_value.style_value() {+ Some(crate::css::style_value::StyleValueData::Length { value, unit })+ if *unit == crate::css::style_compute::px_length_unit() =>+ {+ *value+ }+ _ => self.font_size.to_double(),+ }+ }+/// https://drafts.csswg.org/css-fonts/#first-available-font/// The frozen cascade answers where the font computer published one: a load filling one of its/// faces in moves the answer without a new style. A cascade nobody published (a unit test's)diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rsindex 2b581bc5457..aeaca8fc6ee 100644--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs@@ -2533,6 +2533,12 @@ pub extern "C" fn rust_sizing_values_clamp_size(*height = clamp(*height, basis_height, &values.min_height, &values.max_height);}+/// The computed font size of a font group, unrounded, as [`FontValues::font_size_for_lengths`] reads it.+#[unsafe(no_mangle)]+pub extern "C" fn rust_font_values_font_size_for_lengths(values: &FontValues) -> f64 {+ values.font_size_for_lengths()+}+/// The used line height of a font group, as [`FontValues::line_height_used`] reads it.#[unsafe(no_mangle)]pub extern "C" fn rust_font_values_line_height_used_raw(values: &FontValues) -> i32 {diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 35aea2e3148..ba5d796cbf0 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -434,6 +434,20 @@ impl FfiFontResolutionRequest {pub fn font_size(&self) -> f64 {crate::css::css_pixels::CssPixels::from_raw(self.font_size_raw).to_double()}++ /// The font size the lengths of the element whose values made this request scale: its+ /// computed `font-size`, unrounded, where `computed` holds one in pixels, and the request's+ /// otherwise.+ pub fn font_size_for_lengths(&self, computed: Option<&crate::css::style_value::StyleValueData>) -> f64 {+ match computed {+ Some(crate::css::style_value::StyleValueData::Length { value, unit })+ if *unit == crate::css::style_compute::px_length_unit() =>+ {+ *value+ }+ _ => self.font_size(),+ }+ }}#[repr(C)]diff --git a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs b/Libraries/LibWeb/Rust/src/css/style/container_queries.rsindex 6db8c108bcb..aa1dbb2990f 100644--- a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs+++ b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs@@ -219,7 +219,7 @@ impl RetainedState {viewport_width: document.viewport_width,viewport_height: document.viewport_height,font_metrics: crate::css::style_compute::FfiFontMetrics {- font_size: font.font_size.to_double(),+ font_size: font.font_size_for_lengths(),x_height: super::pipeline::drive::drive_font_metric(first_available.x_height),cap_height: super::pipeline::drive::drive_font_metric(first_available.cap_height),zero_advance: super::pipeline::drive::drive_font_metric(first_available.zero_advance),diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rsindex 789ab8187fd..917fbd04014 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs@@ -39,7 +39,7 @@ impl RecordFont {let first_available = font.first_available_font_metrics();Self {metrics: FfiFontMetrics {- font_size: font.font_size.to_double(),+ font_size: font.font_size_for_lengths(),x_height: drive_font_metric(first_available.x_height),cap_height: drive_font_metric(first_available.cap_height),zero_advance: drive_font_metric(first_available.zero_advance),@@ -253,7 +253,7 @@ impl RetainedState {let font_inputs = font.filter(|_| rebuilds_font);let own_font = match font_inputs {Some(font) => FfiFontMetrics {- font_size: CssPixels::from_raw(font.font_size_raw).to_double(),+ font_size: font.font_size,x_height: drive_font_metric(font.font_x_height),cap_height: drive_font_metric(font.font_cap_height),zero_advance: drive_font_metric(font.font_zero_advance),@@ -1498,6 +1498,8 @@ pub(super) fn font_group_build_inputs<'a>(};FfiFontGroupBuildInputs {font_size_raw: request.font_size_raw,+ font_size: request+ .font_size_for_lengths(values(prop::FONT_SIZE).and_then(RetainedStyleValueData::optional_data)),line_height_used_raw: CssPixels::nearest_value_for(line_height_used).raw_value(),font_variant_emoji: keyword_code(prop::FONT_VARIANT_EMOJI,diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rsindex dca69b3fcb2..b9ad8535e37 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs@@ -93,7 +93,7 @@ impl RootFontInputs {let first_available = font.first_available_font_metrics();Self {metrics: [- font.font_size.to_double().to_bits(),+ font.font_size_for_lengths().to_bits(),drive_font_metric(first_available.x_height).to_bits(),drive_font_metric(first_available.cap_height).to_bits(),drive_font_metric(first_available.zero_advance).to_bits(),@@ -1820,9 +1820,14 @@ impl RetainedState {*suspended_font = Some(font_resolution::FontRequest::new(request));return None;};+ let own_font_size = request.font_size_for_lengths(+ values+ .get(crate::css::property_metadata::property_id::FONT_SIZE)+ .map(|value| value.data()),+ );let own_length = |line_height: f64| {let font_metrics = crate::css::style_compute::FfiFontMetrics {- font_size: request.font_size(),+ font_size: own_font_size,x_height: drive::drive_font_metric(resolved.x_height),cap_height: drive::drive_font_metric(resolved.cap_height),zero_advance: drive::drive_font_metric(resolved.zero_advance),@@ -1907,7 +1912,7 @@ impl RetainedState {viewport_width: inputs.viewport_width,viewport_height: inputs.viewport_height,font_metrics: FfiFontMetrics {- font_size: parent_font.font_size.to_double(),+ font_size: parent_font.font_size_for_lengths(),x_height: drive::drive_font_metric(first_available.x_height),cap_height: drive::drive_font_metric(first_available.cap_height),zero_advance: drive::drive_font_metric(first_available.zero_advance),diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rsindex 301b45e9418..5f53ad3ee69 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs@@ -47,8 +47,8 @@ impl DriveRecords for RetainedState {/// What the monospace font-size recascade answers for a drive target.enum MonospaceRecascade {- /// The font size the recascade reaches, and whether reaching it read the viewport.- Size(i32, bool),+ /// The font size the recascade reaches, in pixels, and whether reaching it read the viewport.+ Size(f64, bool),/// A length in the ancestor chain resolves against the monospace font at the size reached so/// far, which the font resolver has not resolved yet.AwaitsFont(bridge::FfiFontResolutionRequest),@@ -116,24 +116,25 @@ impl RetainedState {).map(|_| (index, view))});- let (start_index, start_size_raw, start_depends_on_viewport) =- animated.map_or((0, default_size, false), |(index, view)| {+ let (start_index, start_size, start_depends_on_viewport) = animated.map_or(+ (0, CssPixels::from_raw(default_size).to_double(), false),+ |(index, view)| {(index + 1,crate::css::computed_value_views::ComputedValuesView::of(view.payloads).font()- .font_size- .raw_value(),+ .font_size_for_lengths(),view.dependency_flags & FONT_METRICS_DEPEND_ON_VIEWPORT_METRICS != 0,)- });+ },+ );let mut batch = recascade_font_size_batch(views.len(),value_at,|index| zooms[index],applies_zoom_at,start_index,- start_size_raw,+ start_size,start_depends_on_viewport,default_size,document_inputs,@@ -145,7 +146,7 @@ impl RetainedState {let parent_zoom = index.checked_sub(1).map_or(1.0, |parent| zooms[parent]);let applies_zoom = applies_zoom_at(index);let own_zoom = if applies_zoom { zoom / parent_zoom } else { 1.0 };- let inherited_size = CssPixels::from_raw(batch.current_size_raw).scaled(own_zoom);+ let inherited_size = batch.current_size * own_zoom;let root_zoom = if !applies_zoom {1.0} else if inputs.root_effective_zoom > 0.0 {@@ -159,7 +160,7 @@ impl RetainedState {let request = bridge::FfiFontResolutionRequest {font_family: bridge::FfiHostHandle::from_pointer(self.monospace_font_family.pointer().cast()),font_feature_values: [bridge::FfiHostHandle::default(); bridge::FONT_RESOLUTION_FEATURE_INPUT_COUNT],- font_size_raw: inherited_size.raw_value(),+ font_size_raw: CssPixels::nearest_value_for(inherited_size).raw_value(),font_slope: 0,font_weight: 400.0,font_width: 100.0,@@ -199,7 +200,7 @@ impl RetainedState {viewport_width: inputs.viewport_width,viewport_height: inputs.viewport_height,font_metrics: FfiFontMetrics {- font_size: inherited_size.to_double(),+ font_size: inherited_size,x_height: drive_font_metric(resolved.x_height),cap_height: drive_font_metric(resolved.cap_height),zero_advance: drive_font_metric(resolved.zero_advance),@@ -234,7 +235,7 @@ impl RetainedState {|index| zooms[index],applies_zoom_at,index,- batch.current_size_raw,+ batch.current_size,batch.depends_on_viewport_metrics,default_size,document_inputs,@@ -245,7 +246,7 @@ impl RetainedState {"the context resolves every length a cascaded font-size holds");}- MonospaceRecascade::Size(batch.current_size_raw, batch.depends_on_viewport_metrics)+ MonospaceRecascade::Size(batch.current_size, batch.depends_on_viewport_metrics)}/// The tree scope whose `@font-feature-values` an element's `font-variant-alternates` names@@ -363,7 +364,6 @@ impl RetainedState {.then(|| self.container_unit_bases_with(records, subject.target.node(), subject.target.is_pseudo()));let document_base_url = &self.document_resource_contexts.document_base_url;let store = store.view(self);- use crate::css::css_pixels::CssPixels;use crate::css::property_metadata::property_id as prop;use crate::css::style_compute::{FfiEffectiveColorSchemeInput, FfiFontMetrics, FfiInputLineHeightMetrics, FfiLengthResolutionContext,@@ -422,7 +422,7 @@ impl RetainedState {let first_available = parent_font.first_available_font_metrics();(FfiFontMetrics {- font_size: parent_font.font_size.to_double(),+ font_size: parent_font.font_size_for_lengths(),x_height: drive_font_metric(first_available.x_height),cap_height: drive_font_metric(first_available.cap_height),zero_advance: drive_font_metric(first_available.zero_advance),@@ -595,7 +595,7 @@ impl RetainedState {writer.set_computed(prop::FONT_SIZE,StyleValueData::Length {- value: CssPixels::from_raw(recascaded).to_double(),+ value: recascaded,unit: crate::css::style_compute::px_length_unit(),},);@@ -622,7 +622,7 @@ impl RetainedState {inputs,|| self.font_feature_values_scope(target.node()),);- let font_size = request.font_size();+ let font_size = request.font_size_for_lengths(writer.get(prop::FONT_SIZE).map(|value| value.data()));let Some(resolved) = self.resolved_font(request) else {*suspended_font = Some(font_resolution::FontRequest::new(request));return None;diff --git a/Libraries/LibWeb/Rust/src/css/style/position_try.rs b/Libraries/LibWeb/Rust/src/css/style/position_try.rsindex df5d79c284a..558a06fd628 100644--- a/Libraries/LibWeb/Rust/src/css/style/position_try.rs+++ b/Libraries/LibWeb/Rust/src/css/style/position_try.rs@@ -944,7 +944,7 @@ impl RetainedState {viewport_width: inputs.viewport_width,viewport_height: inputs.viewport_height,font_metrics: FfiFontMetrics {- font_size: font.font_size.to_double(),+ font_size: font.font_size_for_lengths(),x_height: font_metric(first_available.x_height),cap_height: font_metric(first_available.cap_height),zero_advance: font_metric(first_available.zero_advance),diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex ccee50eef8e..28e6e1313fd 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -685,16 +685,17 @@ fn absolute_size_font_mapping(keyword: u16, default_font_size: CssPixels) -> Opt/// A <relative-size> keyword is interpreted relative to the computed font-size of the parent/// element. User agents may use a simple ratio, which should be around 1.2-1.5.-fn relative_size_font_mapping(keyword: u16, inherited_font_size: CssPixels) -> Option<CssPixels> {- let entry = |numerator: i64, denominator: i64| {- Some(- (inherited_font_size * CssPixels::from_integer(numerator))- .div_as_fraction(CssPixels::from_integer(denominator)),- )- };+/// A font size computed from another, in the single precision a computed font size is kept in, so+/// that a percentage of a size like 13.333333px comes out whole: 300% of it is 40px.+pub(crate) fn single_precision_font_size(px: f64) -> f64 {+ f64::from(px as f32)+}++/// The factor a relative-size keyword scales the inherited font size by.+fn relative_size_font_ratio(keyword: u16) -> Option<f64> {match keyword {- keyword::SMALLER => entry(5, 6),- keyword::LARGER => entry(6, 5),+ keyword::SMALLER => Some(5.0 / 6.0),+ keyword::LARGER => Some(6.0 / 5.0),_ => None,}}@@ -702,17 +703,17 @@ fn relative_size_font_mapping(keyword: u16, inherited_font_size: CssPixels) -> O// https://drafts.csswg.org/css-fonts/#font-size-prop// an absolute length//-// The keyword mappings use CSSPixels fixed-point arithmetic, exactly as the-// C++ implementation does.+// The absolute-size keywords map through CSSPixels fixed-point arithmetic. A size relative to the+// inherited one scales it unrounded, as the computed value holds it.fn compute_font_size(value: &StyleValueData,computed_math_depth: i32,- inherited_font_size: CssPixels,+ inherited_font_size: f64,inherited_math_depth: i32,default_font_size: CssPixels,default_font_size_scale: f64,) -> Option<ComputedNumber> {- let computed = |px: f64| Some(ComputedNumber::Computed(px));+ let computed = |px: f64| Some(ComputedNumber::Computed(single_precision_font_size(px)));match value {// <length-percentage [0,inf]>// A length value specifies an absolute font size (independent of the user agent's font@@ -720,13 +721,13 @@ fn compute_font_size(StyleValueData::Length { .. } => Some(ComputedNumber::Unchanged),// A percentage value specifies an absolute font size relative to the parent element's// computed font-size. Negative percentages are invalid.- StyleValueData::Percentage { value } => computed(inherited_font_size.to_double() * (value / 100.0)),+ StyleValueData::Percentage { value } => computed(inherited_font_size * (value / 100.0)),StyleValueData::Keyword { keyword } => {if let Some(px) = absolute_size_font_mapping(*keyword, default_font_size) {- return computed(px.scaled(default_font_size_scale).to_double());+ return computed(px.to_double() * default_font_size_scale);}- if let Some(px) = relative_size_font_mapping(*keyword, inherited_font_size) {- return computed(px.to_double());+ if let Some(ratio) = relative_size_font_ratio(*keyword) {+ return computed(inherited_font_size * ratio);}match *keyword {// math@@ -769,7 +770,7 @@ fn compute_font_size(// 6. Return S if InvertScaleFactor is false and 1/S otherwise.if !invert_scale_factor { scale } else { 1.0 / scale }};- computed(inherited_font_size.scaled(math_scaling_factor).to_double())+ computed(inherited_font_size * math_scaling_factor)}_ => None,}@@ -777,8 +778,8 @@ fn compute_font_size(// Calc lengths and percentages resolve in the calc core against the inherited// font size; anything the core cannot resolve is left to the caller.StyleValueData::Calculated { .. } => {- crate::css::calc::resolve_calculated_length_without_context(value, inherited_font_size.to_double())- .map(ComputedNumber::Computed)+ crate::css::calc::resolve_calculated_length_without_context(value, inherited_font_size)+ .map(|px| ComputedNumber::Computed(single_precision_font_size(px)))}_ => None,}@@ -797,7 +798,7 @@ pub extern "C" fn rust_compute_font_size(compute_font_size(absolutized_value,computed_math_depth,- CssPixels::from_raw(inherited_font_size_raw),+ CssPixels::from_raw(inherited_font_size_raw).to_double(),inherited_math_depth,CssPixels::from_raw(default_font_size_raw),1.0,@@ -821,7 +822,8 @@ pub enum FontSizeRecascadeStatus {pub struct FontSizeRecascadeBatch {pub status: FontSizeRecascadeStatus,pub next_index: usize,- pub current_size_raw: i32,+ /// The font size reached so far, in pixels, unrounded.+ pub current_size: f64,pub depends_on_viewport_metrics: bool,}@@ -867,14 +869,14 @@ pub(crate) fn recascade_font_size_batch<'a>(effective_zoom_at: impl Fn(usize) -> f64,applies_zoom_at: impl Fn(usize) -> bool,start_index: usize,- current_size_raw: i32,+ current_size: f64,current_depends_on_viewport_metrics: bool,default_size_raw: i32,document_inputs: FontSizeRecascadeDocumentInputs,supplied_length_resolution_context: Option<&FfiLengthResolutionContext>,) -> FontSizeRecascadeBatch {assert!(start_index <= value_count);- let mut current_size = CssPixels::from_raw(current_size_raw);+ let mut current_size = current_size;let mut depends_on_viewport_metrics = current_depends_on_viewport_metrics;let default_size = CssPixels::from_raw(default_size_raw);let root_zoom = if document_inputs.root_effective_zoom > 0.0 {@@ -882,14 +884,16 @@ pub(crate) fn recascade_font_size_batch<'a>(} else {1.0};- let stopped = |status, next_index, current_size: CssPixels, depends_on_viewport_metrics| FontSizeRecascadeBatch {+ let stopped = |status, next_index, current_size: f64, depends_on_viewport_metrics| FontSizeRecascadeBatch {status,next_index,- current_size_raw: current_size.raw_value(),+ current_size: single_precision_font_size(current_size),depends_on_viewport_metrics,};for index in start_index..value_count {+ // NB: Each ancestor's size is computed in single precision, as the cascade computes it.+ current_size = single_precision_font_size(current_size);// NB: Keep the size before this ancestor for a batch that must retry this index with font metrics.let inherited_size = current_size;let zoom = effective_zoom_at(index);@@ -898,8 +902,8 @@ pub(crate) fn recascade_font_size_batch<'a>(let own_zoom = if applies_zoom { zoom / parent_zoom } else { 1.0 };let length_zoom = if applies_zoom { zoom } else { 1.0 };let root_metric_zoom = if applies_zoom { zoom / root_zoom } else { 1.0 };- current_size = current_size.scaled(own_zoom);- let zoomed_default_size = default_size.scaled(length_zoom);+ current_size *= own_zoom;+ let zoomed_default_size = default_size.to_double() * length_zoom;let Some(value) = value_at(index) else {continue;};@@ -914,12 +918,12 @@ pub(crate) fn recascade_font_size_batch<'a>(continue;}if let Some(px) = absolute_size_font_mapping(*keyword, default_size) {- current_size = px.scaled(length_zoom);+ current_size = px.to_double() * length_zoom;depends_on_viewport_metrics = false;continue;}- if let Some(px) = relative_size_font_mapping(*keyword, current_size) {- current_size = px;+ if let Some(ratio) = relative_size_font_ratio(*keyword) {+ current_size *= ratio;continue;}// FIXME: Resolve `font-size: math`@@ -928,7 +932,7 @@ pub(crate) fn recascade_font_size_batch<'a>(}}StyleValueData::Percentage { value } => {- current_size = CssPixels::nearest_value_for(value / 100.0 * current_size.to_double());+ current_size *= value / 100.0;continue;}StyleValueData::Length { value, unit } => {@@ -945,7 +949,7 @@ pub(crate) fn recascade_font_size_batch<'a>(Some(LengthUnitKind::FontRelative {metric: FontMetricSelector::FontSize,root: false,- }) => Some((*value * current_size.to_double(), depends_on_viewport_metrics)),+ }) => Some((*value * current_size, depends_on_viewport_metrics)),// NB: Logical viewport units need the ancestor's writing mode from its resolution context.Some(LengthUnitKind::ViewportRelative {axis: ViewportAxis::Inline | ViewportAxis::Block,@@ -963,7 +967,7 @@ pub(crate) fn recascade_font_size_batch<'a>(_ => None,};if let Some((px, resolved_viewport_relative_length)) = directly_resolved {- current_size = CssPixels::nearest_value_for(px);+ current_size = px;depends_on_viewport_metrics = resolved_viewport_relative_length;continue;}@@ -987,7 +991,7 @@ pub(crate) fn recascade_font_size_batch<'a>(depends_on_viewport_metrics,);}- current_size = CssPixels::nearest_value_for(result.px);+ current_size = result.px;depends_on_viewport_metrics = result.resolved_viewport_relative_length;continue;}@@ -1436,7 +1440,7 @@ fn compute_math_depth(value: &StyleValueData, inherited_math_depth: i32, inherit}// https://drafts.csswg.org/css-inline-3/#line-height-property-fn compute_line_height(value: &StyleValueData, computed_font_size: CssPixels) -> ComputedLineHeight {+fn compute_line_height(value: &StyleValueData, computed_font_size: f64) -> ComputedLineHeight {match value {// normal// <length [0,inf]>@@ -1447,17 +1451,12 @@ fn compute_line_height(value: &StyleValueData, computed_font_size: CssPixels) ->| StyleValueData::Length { .. }| StyleValueData::Number { .. } => ComputedLineHeight::Unchanged,// <percentage [0,inf]>- StyleValueData::Percentage { value } => {- ComputedLineHeight::Px(computed_font_size.to_double() * (value / 100.0))- }+ StyleValueData::Percentage { value } => ComputedLineHeight::Px(computed_font_size * (value / 100.0)),// Calc lengths, percentages, and numbers resolve in the calc core against the// computed font size.StyleValueData::Calculated { .. } => {- match crate::css::calc::resolve_calculated_line_height_without_context(- value,- computed_font_size.to_double(),- )- .expect("a calculated line-height resolves to a length or a number")+ match crate::css::calc::resolve_calculated_line_height_without_context(value, computed_font_size)+ .expect("a calculated line-height resolves to a length or a number"){crate::css::calc::ResolvedLineHeightCalc::Px(px) => ComputedLineHeight::Px(px),crate::css::calc::ResolvedLineHeightCalc::Number(number) => ComputedLineHeight::Number(number),@@ -3305,10 +3304,7 @@ pub(crate) unsafe fn drive_property_computation(if zoom.length_zoom() != 1.0 {let recascaded = writer.get(property_id).and_then(|value| {if let StyleValueData::Length { value, unit } = value.data() {- Some((- CssPixels::nearest_value_for(value * zoom.length_zoom()).to_double(),- *unit,- ))+ Some((value * zoom.length_zoom(), *unit))} else {None}@@ -3781,12 +3777,12 @@ pub(crate) unsafe fn drive_property_computation(// https://drafts.csswg.org/css-viewport/#zoom-property// NB: The parent's font-size is zoomed by its effective zoom already, so it takes// the element's own zoom alone.- Some((CssPixels::nearest_value_for(*value * zoom.length_zoom()), math_depth))+ Some((*value * zoom.length_zoom(), math_depth))}_ => None,},None => Some((- CssPixels::from_raw(initial_font_size_raw).scaled(zoom.length_effective_zoom()),+ CssPixels::from_raw(initial_font_size_raw).to_double() * zoom.length_effective_zoom(),0,)),};@@ -3886,13 +3882,10 @@ pub(crate) unsafe fn drive_property_computation() {let resolution_context =length_resolution_context.expect("line-height must run with a resolution context");- compute_line_height(- value_data,- CssPixels::nearest_value_for(resolution_context.font_metrics.font_size),- )+ compute_line_height(value_data, resolution_context.font_metrics.font_size)} else {let synthesized = synthesized_px_length(absolutized);- compute_line_height(synthesized.as_ref().unwrap_or(value_data), CssPixels::from_raw(0))+ compute_line_height(synthesized.as_ref().unwrap_or(value_data), 0.0)};match result {ComputedLineHeight::Unchanged => absolutized.map_or(NativeValue::Unchanged, NativeValue::Px),@@ -4924,10 +4917,8 @@ pub(crate) fn compute_font_values<'a>(_ => None,};let inherited_size = match (parentless_font_size, inherited(prop::FONT_SIZE)) {- (Some(size), _) => size,- (None, Some(StyleValueData::Length { value, unit })) if *unit == px_length_unit() => {- CssPixels::nearest_value_for(*value)- }+ (Some(size), _) => size.to_double(),+ (None, Some(StyleValueData::Length { value, unit })) if *unit == px_length_unit() => *value,_ => return false,};// NB: The element declares no math-depth of its own, so its computed one is the@@ -4992,7 +4983,7 @@ pub(crate) fn compute_font_values<'a>((true, false) => value.clone(),}}- _ => match compute_line_height(data, CssPixels::nearest_value_for(length.font_metrics.font_size)) {+ _ => match compute_line_height(data, length.font_metrics.font_size) {ComputedLineHeight::Unchanged => value.clone(),ComputedLineHeight::Number(value) => {RetainedStyleValueData::from_owned(StyleValueData::Number { value })diff --git a/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs b/Libraries/LibWeb/Rust/src/css/style_compute/tests.rsindex 1e45137abef..231b36d17c2 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs@@ -308,7 +308,7 @@ fn font_size_recascade_resolves_em_without_a_host_context() {|_| 1.0,|_| true,0,- default_size.raw_value(),+ default_size.to_double(),false,default_size.raw_value(),FontSizeRecascadeDocumentInputs {@@ -322,7 +322,7 @@ fn font_size_recascade_resolves_em_without_a_host_context() {);assert!(batch.status == FontSizeRecascadeStatus::Complete);assert_eq!(batch.next_index, values.len());- assert_eq!(batch.current_size_raw, CssPixels::from_integer(26).raw_value());+ assert_eq!(batch.current_size, 26.0);}#[test]@@ -342,7 +342,7 @@ fn font_size_recascade_resolves_document_lengths() {|_| 1.0,|_| true,0,- CssPixels::from_integer(13).raw_value(),+ 13.0,false,CssPixels::from_integer(13).raw_value(),FontSizeRecascadeDocumentInputs {@@ -355,7 +355,7 @@ fn font_size_recascade_resolves_document_lengths() {None,);assert!(batch.status == FontSizeRecascadeStatus::Complete);- assert_eq!(batch.current_size_raw, CssPixels::from_integer(80).raw_value());+ assert_eq!(batch.current_size, 80.0);assert!(batch.depends_on_viewport_metrics);}@@ -378,7 +378,7 @@ fn font_size_recascade_applies_each_ancestor_zoom_once() {|index| zooms[index],|_| true,0,- CssPixels::from_integer(13).raw_value(),+ 13.0,false,CssPixels::from_integer(13).raw_value(),FontSizeRecascadeDocumentInputs {@@ -391,7 +391,7 @@ fn font_size_recascade_applies_each_ancestor_zoom_once() {None,);assert!(batch.status == FontSizeRecascadeStatus::Complete);- assert_eq!(batch.current_size_raw, CssPixels::from_integer(60).raw_value());+ assert_eq!(batch.current_size, 60.0);}#[test]@@ -407,7 +407,7 @@ fn font_size_recascade_stops_for_a_length_that_needs_font_metrics() {|_| 1.0,|_| true,0,- CssPixels::from_integer(13).raw_value(),+ 13.0,false,CssPixels::from_integer(13).raw_value(),FontSizeRecascadeDocumentInputs {@@ -511,12 +511,13 @@ fn font_width_keywords_compute() {#[test]fn font_size_keywords_compute() {let sixteen = CssPixels::from_integer(16);+ let inherited = 16.0;let medium = compute_font_size(&StyleValueData::Keyword {keyword: keyword::MEDIUM,},0,- sixteen,+ inherited,0,sixteen,1.0,@@ -527,7 +528,7 @@ fn font_size_keywords_compute() {keyword: keyword::LARGE,},0,- sixteen,+ inherited,0,sixteen,1.0,@@ -536,7 +537,7 @@ fn font_size_keywords_compute() {let percent = compute_font_size(&StyleValueData::Percentage { value: 150.0 },0,- sixteen,+ inherited,0,sixteen,1.0,@@ -545,23 +546,23 @@ fn font_size_keywords_compute() {let math = compute_font_size(&StyleValueData::Keyword { keyword: keyword::MATH },1,- sixteen,+ inherited,0,sixteen,1.0,);- assert_eq!(math, computed(CssPixels::from_integer(16).scaled(0.71).to_double()));+ assert_eq!(math, computed(single_precision_font_size(16.0 * 0.71)));let math_two_levels = compute_font_size(&StyleValueData::Keyword { keyword: keyword::MATH },2,- sixteen,+ inherited,0,sixteen,1.0,);assert_eq!(math_two_levels,- computed(CssPixels::from_integer(16).scaled(0.71f64.powi(2)).to_double())+ computed(single_precision_font_size(16.0 * 0.71f64.powi(2))));}@@ -581,7 +582,7 @@ fn math_depth_computes() {#[test]fn line_height_computes() {- let sixteen = CssPixels::from_integer(16);+ let sixteen = 16.0;assert_eq!(compute_line_height(&StyleValueData::Keyword {diff --git a/Libraries/LibWeb/Rust/src/css/table_group_builder.rs b/Libraries/LibWeb/Rust/src/css/table_group_builder.rsindex 01004b18ad0..a43affd75b3 100644--- a/Libraries/LibWeb/Rust/src/css/table_group_builder.rs+++ b/Libraries/LibWeb/Rust/src/css/table_group_builder.rs@@ -101,6 +101,8 @@ pub(crate) struct GroupBuildInputs<'a> {#[repr(C)]pub struct FfiFontGroupBuildInputs {pub font_size_raw: i32,+ /// The computed font size, unrounded, which the lengths relative to it scale.+ pub font_size: f64,pub line_height_used_raw: i32,pub font_variant_emoji: u8,pub font_ascent: f32,diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 3fa6b3f0bd7..c45029fba91 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -3379,7 +3379,7 @@ impl<'pass> SvgFormattingContext<'pass> {fn font_metrics_for_length_resolution(style: StyleValues<'_>) -> crate::css::style_compute::FfiFontMetrics {let font = style.font().first_available_font_metrics();crate::css::style_compute::FfiFontMetrics {- font_size: style.font_size().to_double(),+ font_size: style.font().font_size_for_lengths(),x_height: CssPixels::nearest_value_for_f32(font.x_height).to_double(),cap_height: CssPixels::nearest_value_for_f32(font.cap_height).to_double(),zero_advance: CssPixels::nearest_value_for_f32(font.zero_advance).to_double(),diff --git a/Tests/LibWeb/Layout/expected/input-placeholder-with-line-height.txt b/Tests/LibWeb/Layout/expected/input-placeholder-with-line-height.txtindex 91d166d967c..f4fab4e401f 100644--- a/Tests/LibWeb/Layout/expected/input-placeholder-with-line-height.txt+++ b/Tests/LibWeb/Layout/expected/input-placeholder-with-line-height.txt@@ -1,19 +1,19 @@Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 88.640625 0+0+0] [BFC] children: not-inline- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 72.640625 0+0+8] children: inline- frag 0 from TextInputBox start: 0, length: 0, rect: [13,11 167.6875x66.640625] baseline: 40.609375- frag 1 from TextNode start: 0, length: 4, rect: [185.6875,35.609375 32.140625x16] baseline: 13+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 88.671875 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 72.671875 0+0+8] children: inline+ frag 0 from TextInputBox start: 0, length: 0, rect: [13,11 167.6875x66.671875] baseline: 40.625+ frag 1 from TextNode start: 0, length: 4, rect: [185.6875,35.625 32.140625x16] baseline: 13"text"- TextInputBox <input> at [13,11] inline-block [0+2+3 167.6875 3+2+0] [0+2+1 66.640625 1+2+0] [BFC] children: not-inline- Box <div> at [13,11] flex-container(row) [0+0+0 167.6875 0+0+0] [0+0+0 66.640625 0+0+0] [FFC] children: not-inline- BlockContainer <div> at [13,11] flex-item [0+0+0 167.6875 0+0+0] [0+0+0 66.640625 0+0+0] [BFC] children: inline- frag 0 from TextNode start: 0, length: 0, rect: [13,37.3125 0x14] baseline: 11+ TextInputBox <input> at [13,11] inline-block [0+2+3 167.6875 3+2+0] [0+2+1 66.671875 1+2+0] [BFC] children: not-inline+ Box <div> at [13,11] flex-container(row) [0+0+0 167.6875 0+0+0] [0+0+0 66.671875 0+0+0] [FFC] children: not-inline+ BlockContainer <div> at [13,11] flex-item [0+0+0 167.6875 0+0+0] [0+0+0 66.671875 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 0, rect: [13,37.328125 0x14] baseline: 11TextNode <#text> (not painted)- BlockContainer <div> at [13,11] flex-item [-167.6875+0+0 167.6875 0+0+0] [0+0+0 66.640625 0+0+0] [BFC] children: inline- frag 0 from TextNode start: 0, length: 11, rect: [13,37.3125 74.90625x14] baseline: 11+ BlockContainer <div> at [13,11] flex-item [-167.6875+0+0 167.6875 0+0+0] [0+0+0 66.671875 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 11, rect: [13,37.328125 74.90625x14] baseline: 11"placeholder"TextNode <#text> (not painted)TextNode <#text> (not painted)SC for Viewport<#document> [0,0 800x600] (z-index: auto)- SC for BlockContainer<HTML> [0,0 800x88.640625] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x88.671875] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt b/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txtindex 65f405b9185..40f7c507cc2 100644--- a/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt+++ b/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt@@ -1,9 +1,9 @@Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 147.9375 0+0+0] [BFC] children: not-inline- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 131.9375 0+0+8] children: inline- frag 0 from BlockContainer start: 0, length: 0, rect: [9,10 69.84375x127.9375] baseline: 128.9375- BlockContainer <select> at [9,10] inline-block [0+1+0 69.84375 0+1+0] [0+1+1 127.9375 1+1+0] [BFC] children: not-inline- BlockContainer <div> at [9,10] [0+0+0 69.84375 0+0+0] [0+0+0 127.9375 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 148 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 132 0+0+8] children: inline+ frag 0 from BlockContainer start: 0, length: 0, rect: [9,10 69.84375x128] baseline: 129+ BlockContainer <select> at [9,10] inline-block [0+1+0 69.84375 0+1+0] [0+1+1 128 1+1+0] [BFC] children: not-inline+ BlockContainer <div> at [9,10] [0+0+0 69.84375 0+0+0] [0+0+0 128 0+0+0] [BFC] children: not-inlineBlockContainer <div> at [13,10] [0+0+4 61.84375 4+0+0] [0+0+0 16 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 9, rect: [13,11 61.84375x14] baseline: 11"New label"@@ -23,4 +23,4 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenTextNode <#text> (not painted)SC for Viewport<#document> [0,0 800x600] (z-index: auto)- SC for BlockContainer<HTML> [0,0 800x147.9375] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x148] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txt b/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txtindex 6a481abd0a3..46148402640 100644--- a/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txt+++ b/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txt@@ -1,9 +1,9 @@Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 83.96875 0+0+0] [BFC] children: not-inline- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 67.96875 0+0+8] children: inline- frag 0 from BlockContainer start: 0, length: 0, rect: [9,10 55.8125x63.96875] baseline: 64.96875- BlockContainer <select> at [9,10] inline-block [0+1+0 55.8125 0+1+0] [0+1+1 63.96875 1+1+0] [BFC] children: not-inline- BlockContainer <div> at [9,10] [0+0+0 55.8125 0+0+0] [0+0+0 63.96875 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 84 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 68 0+0+8] children: inline+ frag 0 from BlockContainer start: 0, length: 0, rect: [9,10 55.8125x64] baseline: 65+ BlockContainer <select> at [9,10] inline-block [0+1+0 55.8125 0+1+0] [0+1+1 64 1+1+0] [BFC] children: not-inline+ BlockContainer <div> at [9,10] [0+0+0 55.8125 0+0+0] [0+0+0 64 0+0+0] [BFC] children: not-inlineBlockContainer <div> at [13,10] [0+0+4 47.8125 4+0+0] [0+0+0 16 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 5, rect: [13,11 35.109375x14] baseline: 11"First"@@ -15,4 +15,4 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenTextNode <#text> (not painted)SC for Viewport<#document> [0,0 800x600] (z-index: auto)- SC for BlockContainer<HTML> [0,0 800x83.96875] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x84] (z-index: auto)diff --git a/Tests/LibWeb/Screenshot/expected/css-background-clip-text.png b/Tests/LibWeb/Screenshot/expected/css-background-clip-text.pngindex 3091abfaa07..2c951d65f05 100644Binary files a/Tests/LibWeb/Screenshot/expected/css-background-clip-text.png and b/Tests/LibWeb/Screenshot/expected/css-background-clip-text.png differdiff --git a/Tests/LibWeb/TestLengthAbsolutizeParity.cpp b/Tests/LibWeb/TestLengthAbsolutizeParity.cppindex 52cff95758c..143aefcd1b2 100644--- a/Tests/LibWeb/TestLengthAbsolutizeParity.cpp+++ b/Tests/LibWeb/TestLengthAbsolutizeParity.cpp@@ -21,8 +21,8 @@ static Length::ResolutionContext make_context(bool* did_resolve_viewport_relativGfx::FontPixelMetrics const root_pixel_metrics { .x_height = 10, .advance_of_ascii_zero = 9, .ascent = 14, .descent = 5 };Length::ResolutionContext context {.viewport_rect = { 0, 0, 800, 600 },- .font_metrics = { CSSPixels(16), pixel_metrics, CSSPixels(19) },- .root_font_metrics = { CSSPixels(20), root_pixel_metrics, CSSPixels(24) },+ .font_metrics = { 16.0, pixel_metrics, CSSPixels(19) },+ .root_font_metrics = { 20.0, root_pixel_metrics, CSSPixels(24) },.font_metrics_depend_on_viewport_metrics = false,.root_font_metrics_depend_on_viewport_metrics = true,};diff --git a/Tests/LibWeb/Text/expected/css/attr-element-reference-pseudo-invalidation.txt b/Tests/LibWeb/Text/expected/css/attr-element-reference-pseudo-invalidation.txtindex f8686751883..72133e420d0 100644--- a/Tests/LibWeb/Text/expected/css/attr-element-reference-pseudo-invalidation.txt+++ b/Tests/LibWeb/Text/expected/css/attr-element-reference-pseudo-invalidation.txt@@ -1,6 +1,6 @@-::placeholder-before=19.992188px-::placeholder-after=39.984375px-::file-selector-button-before=19.992188px-::file-selector-button-after=39.984375px+::placeholder-before=20px+::placeholder-after=40px+::file-selector-button-before=20px+::file-selector-button-after=40px::details-content-before=24px::details-content-after=48pxdiff --git a/Tests/LibWeb/Text/expected/css/font-size-lengths-scale-unrounded-size.txt b/Tests/LibWeb/Text/expected/css/font-size-lengths-scale-unrounded-size.txtnew file mode 100644index 00000000000..dd42636117d--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/font-size-lengths-scale-unrounded-size.txt@@ -0,0 +1,5 @@+rem margin: -16.5px+em width: 16.5px+110%: 19.360001px+larger: 23.232px+canvas 10em letter-spacing, per glyph: 176diff --git a/Tests/LibWeb/Text/expected/css/style-engine/computed-font-size-representation-change.txt b/Tests/LibWeb/Text/expected/css/style-engine/computed-font-size-representation-change.txtindex 780fe2304a8..42d7d2a45d4 100644--- a/Tests/LibWeb/Text/expected/css/style-engine/computed-font-size-representation-change.txt+++ b/Tests/LibWeb/Text/expected/css/style-engine/computed-font-size-representation-change.txt@@ -1,2 +1,2 @@inherited: 20.1px-after: 20.09375px+after: 20.1pxdiff --git a/Tests/LibWeb/Text/input/css/font-size-lengths-scale-unrounded-size.html b/Tests/LibWeb/Text/input/css/font-size-lengths-scale-unrounded-size.htmlnew file mode 100644index 00000000000..80b7127fcc3--- /dev/null+++ b/Tests/LibWeb/Text/input/css/font-size-lengths-scale-unrounded-size.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<style>+ html { font-size: 17.6px; }+ #rem { margin: 0 -0.9375rem; }+ #em { font-size: 17.6px; width: 0.9375em; }+ #percentage { font-size: 110%; }+ #larger { font-size: larger; }+</style>+<div id="rem"></div>+<div id="em"></div>+<div id="percentage"><div id="larger"></div></div>+<canvas id="canvas"></canvas>+<script src="../include.js"></script>+<script>+ test(() => {+ // A font size of 17.6px isn't a whole number of 1/64px, so a length or a size relative to it scales it unrounded.+ println(`rem margin: ${getComputedStyle(document.getElementById("rem")).marginLeft}`);+ println(`em width: ${getComputedStyle(document.getElementById("em")).width}`);+ println(`110%: ${getComputedStyle(document.getElementById("percentage")).fontSize}`);+ println(`larger: ${getComputedStyle(document.getElementById("larger")).fontSize}`);+ const context = document.getElementById("canvas").getContext("2d");+ context.font = "17.6px serif";+ const unspaced = context.measureText("ab").width;+ context.letterSpacing = "10em";+ println(`canvas 10em letter-spacing, per glyph: ${(context.measureText("ab").width - unspaced) / 2}`);+ });+</script>