Truly independent web browser
LibWeb: Paint MathML fraction bars and radical symbols
Andreas Kling247314735adf
diff --git a/Libraries/LibWeb/Rust/src/gfx_test_stubs.rs b/Libraries/LibWeb/Rust/src/gfx_test_stubs.rsindex 13ed1cb179f..71448f3564e 100644--- a/Libraries/LibWeb/Rust/src/gfx_test_stubs.rs+++ b/Libraries/LibWeb/Rust/src/gfx_test_stubs.rs@@ -39,6 +39,15 @@ extern "C" fn ladybird_gfx_font_math_data(_font: *const c_void) -> *const libgfxunreachable!("no unit test reads a font");}+#[unsafe(no_mangle)]+extern "C" fn ladybird_gfx_font_glyph_metrics(+ _font: *const c_void,+ _glyph_id: u32,+ _out_metrics: *mut libgfx_rust::math_table::FfiGlyphMetrics,+) {+ unreachable!("no unit test reads a font");+}+#[unsafe(no_mangle)]extern "C" fn ladybird_gfx_font_invisible_variant(_font: *const c_void) -> *const c_void {unreachable!("no unit test reads a font");diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex ac4b2d2986d..942e4450e3a 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -35,6 +35,7 @@ pub(crate) struct Fragment {pub(crate) grid_layout_data: Option<std::sync::Arc<grid_formatting_context::GridLayoutData>>,pub(crate) flex_layout_data: Option<std::sync::Arc<formatting_context::FlexLayoutData>>,pub(crate) multicol_layout_data: Option<std::sync::Arc<fragmentation::MulticolLayoutData>>,+ pub(crate) math_paint_data: Option<std::sync::Arc<math_formatting_context::MathPaintData>>,pub(crate) used_grid_tracks: Option<std::sync::Arc<grid_formatting_context::OwnedUsedGridTracks>>,/// Boxed, as only SVG boxes have any and the facts are larger than the rest of the fragment's box.pub(crate) svg: Option<Box<CommittedSvgFacts>>,@@ -95,6 +96,7 @@ impl Fragment {&& self.grid_layout_data.is_none()&& self.flex_layout_data.is_none()&& self.multicol_layout_data.is_none()+ && self.math_paint_data.is_none()&& self.used_grid_tracks.is_none()&& self.svg.is_none()&& self.computed_svg_path.is_none()@@ -136,6 +138,7 @@ impl Fragment {&& same_allocation(self.grid_layout_data.as_ref(), previous.grid_layout_data.as_ref())&& same_allocation(self.flex_layout_data.as_ref(), previous.flex_layout_data.as_ref())&& self.multicol_layout_data == previous.multicol_layout_data+ && self.math_paint_data == previous.math_paint_data&& same_allocation(self.used_grid_tracks.as_ref(), previous.used_grid_tracks.as_ref())&& self.svg == previous.svg&& same_allocation(self.computed_svg_path.as_ref(), previous.computed_svg_path.as_ref())@@ -242,6 +245,7 @@ impl FragmentLink {grid_layout_data: None,flex_layout_data: None,multicol_layout_data: None,+ math_paint_data: None,used_grid_tracks: None,svg: None,computed_svg_path: None,@@ -438,6 +442,7 @@ struct CommittedRarePayloads {grid_layout_data: Option<std::sync::Arc<grid_formatting_context::GridLayoutData>>,flex_layout_data: Option<std::sync::Arc<formatting_context::FlexLayoutData>>,multicol_layout_data: Option<std::sync::Arc<fragmentation::MulticolLayoutData>>,+ math_paint_data: Option<std::sync::Arc<math_formatting_context::MathPaintData>>,used_grid_tracks: Option<std::sync::Arc<grid_formatting_context::OwnedUsedGridTracks>>,svg: CommittedSvgFacts,computed_svg_path: Option<std::sync::Arc<libgfx_rust::path::Path>>,@@ -462,6 +467,7 @@ fn snapshot_fragment(grid_layout_data: rare.grid_layout_data.take(),flex_layout_data: rare.flex_layout_data.take(),multicol_layout_data: rare.multicol_layout_data.take(),+ math_paint_data: rare.math_paint_data.take(),used_grid_tracks: rare.used_grid_tracks.take(),svg: rare.svg,computed_svg_path: rare.computed_svg_path.take(),@@ -474,6 +480,7 @@ fn snapshot_fragment(grid_layout_data,flex_layout_data,multicol_layout_data,+ math_paint_data,used_grid_tracks,svg,computed_svg_path,@@ -506,6 +513,7 @@ fn snapshot_fragment(grid_layout_data,flex_layout_data,multicol_layout_data,+ math_paint_data,used_grid_tracks,svg: (svg != CommittedSvgFacts::default()).then(|| Box::new(svg)),computed_svg_path,diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex 890e926e51e..8d00aecd24c 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -7,6 +7,7 @@// https://w3c.github.io/mathml-core/#layout-algorithmsuse super::*;+use libgfx_rust::font::FontHandle;use libgfx_rust::math_table::{FfiMathData, MathConstant, StretchAxis};/// The layout algorithm a MathML element's tag name selects when its computed display is block math or inline math.@@ -630,6 +631,178 @@ struct MathContent {ascent: CssPixels,descent: CssPixels,positions: Vec<ChildPosition>,+ /// The fraction bars and radical overbars, positioned like the children.+ rules: Vec<MathRule>,+ /// The radical symbols and stretched operator glyphs, positioned like the children.+ glyph_runs: Vec<PlacedGlyphRun>,+}++impl MathContent {+ /// The rules and glyphs of the math content, positioned in the content box.+ fn paint_data(+ &self,+ math_content_line_left: CssPixels,+ content_box_inline_size: CssPixels,+ is_rtl: bool,+ ) -> MathPaintData {+ let content = self;+ let line_left_in_content_box = |line_left_offset: CssPixels, inline_size: CssPixels| {+ math_content_line_left+ + if is_rtl {+ content.inline_size - line_left_offset - inline_size+ } else {+ line_left_offset+ }+ };+ let rules = content+ .rules+ .iter()+ .map(|rule| {+ let (x, width) = if rule.spans_content_box {+ (CssPixels::default(), content_box_inline_size)+ } else {+ (+ line_left_in_content_box(rule.line_left_offset, rule.inline_size),+ rule.inline_size,+ )+ };+ CssPixelRect::new(x, content.ascent + rule.baseline_shift, width, rule.block_size)+ })+ .collect();+ let glyph_runs = content+ .glyph_runs+ .iter()+ .map(|placed| {+ let run = &placed.glyphs;+ let origin_x = line_left_in_content_box(placed.line_left_offset, run.advance);+ let baseline = content.ascent + placed.baseline_shift;+ MathGlyphRun {+ font: run.font.clone(),+ glyphs: run+ .glyphs+ .iter()+ .map(|glyph| MathGlyph {+ x: origin_x.to_float() + glyph.x,+ y: baseline.to_float() + glyph.y,+ glyph_id: glyph.glyph_id,+ })+ .collect(),+ ink_bounds: CssPixelRect::new(+ origin_x,+ baseline - run.ascent,+ run.advance,+ run.ascent + run.descent,+ ),+ }+ })+ .collect();+ MathPaintData { rules, glyph_runs }+ }++ /// The content with its children, rules and glyphs moved by the given line-left offset and baseline shift.+ fn translated(self, line_left_offset: CssPixels, baseline_shift: CssPixels) -> Self {+ Self {+ positions: self+ .positions+ .into_iter()+ .map(|position| ChildPosition {+ line_left_offset: position.line_left_offset + line_left_offset,+ baseline_shift: position.baseline_shift + baseline_shift,+ })+ .collect(),+ rules: self+ .rules+ .into_iter()+ .map(|rule| MathRule {+ line_left_offset: rule.line_left_offset + line_left_offset,+ baseline_shift: rule.baseline_shift + baseline_shift,+ ..rule+ })+ .collect(),+ glyph_runs: self+ .glyph_runs+ .into_iter()+ .map(|run| PlacedGlyphRun {+ line_left_offset: run.line_left_offset + line_left_offset,+ baseline_shift: run.baseline_shift + baseline_shift,+ ..run+ })+ .collect(),+ ..self+ }+ }+}++/// A rule that the box paints: its line-left offset and the offset of its line-over edge from the alphabetic+/// baseline of the math content towards the line-under.+#[derive(Clone, Copy)]+struct MathRule {+ line_left_offset: CssPixels,+ baseline_shift: CssPixels,+ inline_size: CssPixels,+ block_size: CssPixels,+ /// Whether the rule spans the content box along the inline axis instead, like a fraction bar.+ spans_content_box: bool,+}++/// Glyphs that the box paints, with their origin at a line-left offset, on a baseline shifted away from the+/// alphabetic baseline of the math content towards the line-under.+struct PlacedGlyphRun {+ line_left_offset: CssPixels,+ baseline_shift: CssPixels,+ glyphs: GlyphRun,+}++/// Glyphs of one font, positioned relative to their origin, with the box metrics they cover.+#[derive(Clone)]+struct GlyphRun {+ font: FontHandle,+ /// The glyph ids, with the offsets of their origins from the origin of the run.+ glyphs: Vec<MathGlyph>,+ advance: CssPixels,+ ascent: CssPixels,+ descent: CssPixels,+}++impl GlyphRun {+ /// A single glyph, with the box metrics of its ink.+ fn for_glyph(font: FontHandle, glyph_id: u32) -> Self {+ let metrics = font.glyph_metrics(glyph_id);+ Self {+ font,+ glyphs: vec![MathGlyph {+ x: 0.0,+ y: 0.0,+ glyph_id,+ }],+ advance: CssPixels::nearest_value_for_f32(metrics.advance),+ ascent: CssPixels::nearest_value_for_f32(metrics.ascent),+ descent: CssPixels::nearest_value_for_f32(metrics.descent),+ }+ }+}++/// What MathML layout produced for a box that painting draws: fraction bars, radical symbols and the glyphs of+/// stretched operators. Positions are relative to the top-left corner of the content box.+#[derive(Debug, PartialEq)]+pub(crate) struct MathPaintData {+ pub(crate) rules: Vec<CssPixelRect>,+ pub(crate) glyph_runs: Vec<MathGlyphRun>,+}++#[derive(Debug, PartialEq)]+pub(crate) struct MathGlyphRun {+ pub(crate) font: FontHandle,+ /// The glyphs, each positioned by its origin on its baseline.+ pub(crate) glyphs: Vec<MathGlyph>,+ pub(crate) ink_bounds: CssPixelRect,+}++#[derive(Clone, Copy, Debug, PartialEq)]+pub(crate) struct MathGlyph {+ pub(crate) x: f32,+ pub(crate) y: f32,+ pub(crate) glyph_id: u32,}/// The layout constants of the first available font of a box.@@ -1371,6 +1544,16 @@ impl<'pass> MathFormattingContext<'pass> {formatting_context::place_child(run, child.node, offset, None);}+ if run.layout_mode == LayoutMode::Normal && (!content.rules.is_empty() || !content.glyph_runs.is_empty()) {+ let bar_inline_size = if content_box_is_known {+ content_box_inline_size+ } else {+ content.inline_size+ };+ let paint_data = content.paint_data(math_content_line_left, bar_inline_size, is_rtl);+ root_used.rare_data_mut().math_paint_data = Some(std::sync::Arc::new(paint_data));+ }+self.derived_baselines_of_root_box = DerivedBaselines {first: Some(content.ascent),last: Some(content.ascent),@@ -1521,6 +1704,7 @@ impl<'pass> MathFormattingContext<'pass> {baseline_shift: position.baseline_shift - requested_voffset,}).collect(),+ ..MathContent::default()}}@@ -1629,6 +1813,17 @@ impl<'pass> MathFormattingContext<'pass> {.max(half_thickness - axis_height).max(CssPixels::default());+ // The inline size of the fraction bar is the inline size of the content box and its inline-start edge is the+ // aligned with the one the content box. The center of the fraction bar is shifted away from the alphabetic+ // baseline of the math content box by a distance of AxisHeight towards the line-over. Its block size is the+ // fraction line thickness.+ let fraction_bar = MathRule {+ line_left_offset: CssPixels::default(),+ baseline_shift: -(axis_height + half_thickness),+ inline_size,+ block_size: line_thickness,+ spans_content_box: true,+ };MathContent {inline_size,ascent,@@ -1643,6 +1838,8 @@ impl<'pass> MathFormattingContext<'pass> {baseline_shift: denominator_shift,},],+ rules: vec![fraction_bar],+ ..MathContent::default()}}@@ -1732,6 +1929,7 @@ fn layout_row(children: &[Child], spacing: &[Option<(CssPixels, CssPixels)>]) ->ascent,descent,positions,+ ..MathContent::default()}}@@ -1802,6 +2000,7 @@ fn layout_fraction_without_bar(baseline_shift: bottom_shift,},],+ ..MathContent::default()}}@@ -1910,6 +2109,7 @@ fn layout_scripts(ascent,descent,positions,+ ..MathContent::default()}}@@ -2008,6 +2208,7 @@ fn layout_multiscripts(ascent,descent,positions,+ ..MathContent::default()}}@@ -2153,15 +2354,14 @@ fn layout_underover(ascent,descent,positions,+ ..MathContent::default()}}/// The radical glyph of an <msqrt> or <mroot> and the radical parameters of its font.// https://w3c.github.io/mathml-core/#radical-symbolstruct RadicalMetrics {- glyph_advance: CssPixels,- glyph_ascent: CssPixels,- glyph_descent: CssPixels,+ glyph: GlyphRun,gap: CssPixels,rule_thickness: CssPixels,extra_ascender: CssPixels,@@ -2177,7 +2377,7 @@ impl RadicalMetrics {SQUARE_ROOT,libgfx_rust::font::emoji_presentation_for_code_point(SQUARE_ROOT, None),);- let facts = font.facts();+ let glyph_id = font.glyph_id_for_code_point(SQUARE_ROOT);// The radical gap is given by RadicalVerticalGap if the math-style is compact and// RadicalDisplayStyleVerticalGap if the math-style is normal.let gap = if style.math_style() == math_style::NORMAL {@@ -2186,9 +2386,7 @@ impl RadicalMetrics {constants.radical_vertical_gap()};Self {- glyph_advance: CssPixels::nearest_value_for_f32(font.glyph_width(SQUARE_ROOT)),- glyph_ascent: CssPixels::nearest_value_for_f32(facts.ascent),- glyph_descent: CssPixels::nearest_value_for_f32(facts.descent),+ glyph: GlyphRun::for_glyph(font, glyph_id),gap,rule_thickness: constants.radical_rule_thickness(),extra_ascender: constants.radical_extra_ascender(),@@ -2198,9 +2396,10 @@ impl RadicalMetrics {// https://w3c.github.io/mathml-core/#square-rootfn layout_square_root(base: MathContent, radical: &RadicalMetrics) -> MathContent {+ let glyph = &radical.glyph;// The inline size of the math content is the sum of the advance width of the box metrics of the radical glyph// and of the inline size of the msqrt base's margin's box.- let inline_size = radical.glyph_advance + base.inline_size;+ let inline_size = glyph.advance + base.inline_size;// The line-ascent of the math content is the maximum between:// - The line-ascent of the msqrt base's margin box.// - The sum of the ink line-ascent of the msqrt base, the radical gap, the RadicalRuleThickness and@@ -2214,22 +2413,36 @@ fn layout_square_root(base: MathContent, radical: &RadicalMetrics) -> MathConten// RadicalExtraAscender, minus the line-ascent of the math content.let descent = base.descent- .max(radical.glyph_ascent + radical.glyph_descent + radical.extra_ascender - ascent);- // The inline offsets of the msqrt base and overbar are also the same and equal to the width of the box metrics of- // the radical glyph.- let positions = base- .positions- .into_iter()- .map(|position| ChildPosition {- line_left_offset: position.line_left_offset + radical.glyph_advance,- ..position- })- .collect();+ .max(glyph.ascent + glyph.descent + radical.extra_ascender - ascent);+ // The inline size of the overbar is the inline size of the msqrt base's margin's box. The inline offsets of the+ // msqrt base and overbar are also the same and equal to the width of the box metrics of the radical glyph.+ // The block size of the overbar is RadicalRuleThickness. Its vertical center is shifted away from the alphabetic+ // baseline by a distance towards the line-over equal to the line-ascent of the math content, minus the+ // RadicalExtraAscender, minus half the RadicalRuleThickness.+ let overbar_baseline_shift = radical.extra_ascender - ascent;+ let base_inline_size = base.inline_size;+ let mut content = base.translated(glyph.advance, CssPixels::default());+ content.rules.push(MathRule {+ line_left_offset: glyph.advance,+ baseline_shift: overbar_baseline_shift,+ inline_size: base_inline_size,+ block_size: radical.rule_thickness,+ spans_content_box: false,+ });+ // Finally, the painting of the surd is performed:+ // - At inline offset 0.+ // - At block offset shifted away from the line-over edge of the overbar towards the line-under by a distance+ // given by the ascent of the box metrics of the radical glyph.+ content.glyph_runs.push(PlacedGlyphRun {+ line_left_offset: CssPixels::default(),+ baseline_shift: overbar_baseline_shift + glyph.ascent,+ glyphs: glyph.clone(),+ });MathContent {inline_size,ascent,descent,- positions,+ ..content}}@@ -2243,6 +2456,7 @@ fn layout_root(base: &Child, index: &Child, radical: &RadicalMetrics, constants:ascent: base.ascent,descent: base.descent,positions: vec![ChildPosition::default()],+ ..MathContent::default()},radical,);@@ -2267,19 +2481,15 @@ fn layout_root(base: &Child, index: &Child, radical: &RadicalMetrics, constants:// same + the inline size of the index's margin box.// NB: The base also follows the radical glyph and AdjustedRadicalKernAfterDegree.let b_offset = adjusted_kern_before_degree + index.inline_size + adjusted_kern_after_degree;+ let mut content = b.translated(b_offset, CssPixels::default());+ content.positions.push(ChildPosition {+ line_left_offset: adjusted_kern_before_degree,+ baseline_shift: index_baseline_shift,+ });MathContent {inline_size,ascent,descent,- positions: vec![- ChildPosition {- line_left_offset: b_offset + b.positions[0].line_left_offset,- baseline_shift: CssPixels::default(),- },- ChildPosition {- line_left_offset: adjusted_kern_before_degree,- baseline_shift: index_baseline_shift,- },- ],+ ..content}}diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rsindex b5ec19a16a0..c1a401e1dbb 100644--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs@@ -252,6 +252,7 @@ pub(crate) struct UsedValuesRareData {pub(crate) grid_layout_data: Option<std::sync::Arc<grid_formatting_context::GridLayoutData>>,pub(crate) flex_layout_data: Option<std::sync::Arc<formatting_context::FlexLayoutData>>,pub(crate) multicol_layout_data: Option<std::sync::Arc<fragmentation::MulticolLayoutData>>,+ pub(crate) math_paint_data: Option<std::sync::Arc<math_formatting_context::MathPaintData>>,pub(crate) used_grid_tracks: Option<std::sync::Arc<grid_formatting_context::OwnedUsedGridTracks>>,pub(crate) collapsed_table_borders: Option<std::sync::Arc<table_formatting_context::OwnedCollapsedTableBorders>>,pub(crate) abspos_layout_inputs: Option<abspos_inputs::AbsposLayoutInputs>,@@ -269,6 +270,7 @@ impl UsedValuesRareData {grid_layout_data,flex_layout_data,multicol_layout_data,+ math_paint_data,used_grid_tracks,collapsed_table_borders,abspos_layout_inputs,@@ -284,6 +286,7 @@ impl UsedValuesRareData {&& grid_layout_data.is_none()&& flex_layout_data.is_none()&& multicol_layout_data.is_none()+ && math_paint_data.is_none()&& used_grid_tracks.is_none()&& collapsed_table_borders.is_none()&& orthogonal_flow_baselines.is_none()@@ -307,6 +310,9 @@ impl UsedValuesRareData {if let Some(data) = multicol_layout_data {rare.multicol_layout_data = Some(data);}+ if let Some(data) = math_paint_data {+ rare.math_paint_data = Some(data);+ }if let Some(tracks) = used_grid_tracks {rare.used_grid_tracks = Some(tracks);}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rsindex 51b00cf5104..99192494834 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs@@ -211,6 +211,13 @@ pub(crate) fn committed_multicol_layout_data(})}+pub(crate) fn committed_math_paint_data(+ arena: &impl GeometryRead,+ slot: NodeSlotId,+) -> Option<std::sync::Arc<crate::layout::math_formatting_context::MathPaintData>> {+ arena.with_committed_fragment_link(slot, |link| link.and_then(|link| link.fragment.math_paint_data.clone()))+}+pub(crate) fn committed_flex_layout_data(arena: &impl GeometryRead,slot: NodeSlotId,diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/math.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/math.rsnew file mode 100644index 00000000000..af70231496e--- /dev/null+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/math.rs@@ -0,0 +1,82 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use crate::painting::paint_read::PaintRead;+use crate::painting::record::trace::Observer;++use crate::layout::math_formatting_context::MathPaintData;+use crate::layout::node_data::NodeSlotId;+use crate::painting::display_list::commands::{DisplayListGlyph, FontResourceId};+use crate::painting::display_list::recorder::GlyphRunForRecording;+use crate::painting::force_dark::ForceDarkRole;+use crate::painting::paintable_geometry;+use crate::painting::record::PaintRecorder;+use libgfx_rust::{Color, FloatPoint, Orientation};++/// Paints what MathML layout drew for a box: its fraction bar, its radical symbol and overbar, or the glyphs of its+/// stretched operator.+pub(crate) fn paint_foreground<O: Observer>(+ recorder: &mut PaintRecorder<'_, O>,+ paintable: NodeSlotId,+ data: &MathPaintData,+) {+ // https://w3c.github.io/mathml-core/#fraction-with-nonzero-line-thickness+ // https://w3c.github.io/mathml-core/#radical-symbol+ // The radical symbol must only be painted if the visibility of the <msqrt> or <mroot> element is visible. In that+ // case, the radical symbol must be painted with the color of that element.+ if !recorder.is_visible(paintable) {+ return;+ }+ let Some(style) = recorder.source.node_style_if_live(paintable) else {+ return;+ };+ let color = Color(style.inherited_text().color);+ let font_smoothing = style.inherited_text().font_smoothing;+ let content_box = paintable_geometry::absolute_rect(recorder.source, paintable);+ let converter = recorder.converter;+ for rule in &data.rules {+ let rect = rule.translated_by(content_box.location());+ recorder+ .recorder+ .fill_rect(converter.rounded_device_rect(rect), color, ForceDarkRole::Foreground);+ }+ let scale = recorder.inputs.device_pixels_per_css_pixel;+ let origin = FloatPoint {+ x: (f64::from(content_box.x.to_float()) * scale) as f32,+ y: (f64::from(content_box.y.to_float()) * scale) as f32,+ };+ for run in &data.glyph_runs {+ let font_id = recorder.register_font(&run.font);+ // NB: Display list glyphs are positioned by the top of the font's ascent rather than by their baseline.+ let ascent = run.font.facts().ascent;+ let glyphs: Vec<DisplayListGlyph> = run+ .glyphs+ .iter()+ .map(|glyph| DisplayListGlyph {+ position: FloatPoint {+ x: glyph.x,+ y: glyph.y - ascent,+ },+ glyph_id: glyph.glyph_id,+ })+ .collect();+ let ink_rect = converter.enclosing_device_rect(run.ink_bounds.translated_by(content_box.location()));+ recorder.recorder.draw_glyph_run(+ origin,+ GlyphRunForRecording {+ font_smoothing,+ font_id: FontResourceId(font_id),+ glyphs: &glyphs,+ },+ color,+ ink_rect,+ scale,+ Orientation::Horizontal,+ ink_rect,+ ForceDarkRole::Foreground,+ );+ }+}diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rsindex 331fe8f94c3..6bbbe15f3ae 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rs@@ -17,6 +17,7 @@ pub mod form_controls;pub mod gradient_resolution;pub mod inline_box;pub mod inspector_overlay;+pub mod math;pub mod outline;pub mod overlay;pub mod replaced;@@ -31,6 +32,7 @@ use crate::css::computed_value_views::ComputedValuesView;use crate::css::css_pixels::{CssPixelRect, CssPixels};use crate::layout::node_data::{NodeKind, NodeSlotId};use crate::painting::node_painting;+use crate::painting::paintable_geometry;use crate::painting::record::{BasePaintFacts, PaintPhase, PaintRecorder};use crate::painting::style_queries;@@ -104,6 +106,9 @@ pub(crate) fn paint<O: Observer>(recorder: &mut PaintRecorder<'_, O>, paintable:}paint_base(recorder, paintable, phase);if phase == PaintPhase::Foreground {+ if let Some(data) = paintable_geometry::committed_math_paint_data(recorder.source, paintable) {+ math::paint_foreground(recorder, paintable, &data);+ }if recorder.is_recording_svg_resource_content()|| recorder.sourcediff --git a/Tests/LibWeb/Ref/expected/wpt-import/fonts/math/fraction-rulethickness10000.woff b/Tests/LibWeb/Ref/expected/wpt-import/fonts/math/fraction-rulethickness10000.woffnew file mode 100644index 00000000000..ec69f2424f2Binary files /dev/null and b/Tests/LibWeb/Ref/expected/wpt-import/fonts/math/fraction-rulethickness10000.woff differdiff --git a/Tests/LibWeb/Ref/expected/wpt-import/fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woff b/Tests/LibWeb/Ref/expected/wpt-import/fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woffnew file mode 100644index 00000000000..cb702661195Binary files /dev/null and b/Tests/LibWeb/Ref/expected/wpt-import/fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woff differdiff --git a/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-001-ref.htmlnew file mode 100644index 00000000000..5b7a8dff47e--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-001-ref.html@@ -0,0 +1,21 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <title>fractions bar</title>+ <style type="text/css">+ #container {+ position: absolute;+ left: 10px;+ top: 50px;+ width: 150px;+ height: 150px;+ background: green;+ }+ </style>+ </head>+ <body>+ <p>This test passes if you see a green square.</p>+ <div id="container"></div>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-002-ref.htmlnew file mode 100644index 00000000000..9d5eef896ab--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-002-ref.html@@ -0,0 +1,23 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <title>fractions bar</title>+ <style type="text/css">+ #green {+ position: absolute;+ background: green;+ width: 150px;+ height: 150px;+ left: 50px;+ top: 50px;+ }+ </style>+ </head>+ <body>+ <p>This test passes if you see a green <strong>square</strong> and no red.</p>+ <div>+ <div id="green"></div>+ </div>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001-ref.htmlnew file mode 100644index 00000000000..66d6361814e--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001-ref.html@@ -0,0 +1,62 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <title>fractions linethickness</title>+ <style type="text/css">+ @font-face {+ font-family: TestFont;+ src: url("../../../fonts/math/fraction-rulethickness10000.woff");+ }+ math {+ /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */+ font-family: "TestFont";+ font-size: 1px;+ }+ </style>+ </head>+ <body>+ <p>This test passes if you see the same fraction eight times.</p>+ <math>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac>+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ </math>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004-ref.htmlnew file mode 100644index 00000000000..257f40a277b--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004-ref.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <title>fractions linethickness</title>+ <style type="text/css">+ @font-face {+ font-family: TestFont;+ src: url("../../../fonts/math/fraction-rulethickness10000.woff");+ }+ math {+ /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */+ font-family: "TestFont";+ font-size: 1px;+ }+ </style>+ </head>+ <body>+ <p>This test passes if you see no fraction bar.</p>+ <math>+ <mfrac linethickness="0px">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ </math>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001-ref.htmlnew file mode 100644index 00000000000..64dcf4bc34c--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001-ref.html@@ -0,0 +1,125 @@+<!DOCTYPE html>+<html>+<head>+<meta charset="utf-8">+<title>Dynamic radical: paint invalidation (expectation)</title>+<style>+ @font-face {+ font-family: RadicalFont;+ src: url("../../../fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woff");+ }+ math {+ font-family: RadicalFont;+ font-size: 10px;+ }+ #container > div {+ height: 80px;+ border-top: solid;+ }+ .withPaddingBorderAndMargin {+ padding: 5px;+ border: 5px solid yellow;+ margin: 5px;+ }+</style>+</head>+<body>+ <div id="container">+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="60px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="60px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="20px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="20px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="40px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="40px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt class="withPaddingBorderAndMargin">+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot class="withPaddingBorderAndMargin">+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ </div>+</body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/fonts/math/fraction-rulethickness10000.woff b/Tests/LibWeb/Ref/input/wpt-import/fonts/math/fraction-rulethickness10000.woffnew file mode 100644index 00000000000..ec69f2424f2Binary files /dev/null and b/Tests/LibWeb/Ref/input/wpt-import/fonts/math/fraction-rulethickness10000.woff differdiff --git a/Tests/LibWeb/Ref/input/wpt-import/fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woff b/Tests/LibWeb/Ref/input/wpt-import/fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woffnew file mode 100644index 00000000000..cb702661195Binary files /dev/null and b/Tests/LibWeb/Ref/input/wpt-import/fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woff differdiff --git a/Tests/LibWeb/Ref/input/wpt-import/fonts/math/radical-kernbeforedegree4000-rulethickness1000.woff b/Tests/LibWeb/Ref/input/wpt-import/fonts/math/radical-kernbeforedegree4000-rulethickness1000.woffnew file mode 100644index 00000000000..9ed871062efBinary files /dev/null and b/Tests/LibWeb/Ref/input/wpt-import/fonts/math/radical-kernbeforedegree4000-rulethickness1000.woff differdiff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-bar-001.html b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-bar-001.htmlnew file mode 100644index 00000000000..cd5d5a483bc--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-bar-001.html@@ -0,0 +1,56 @@+<!DOCTYPE html>+<html class="reftest-wait">+ <head>+ <meta charset="utf-8">+ <title>fractions bar</title>+ <link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">+ <meta name="assert" content="Verifies painting of the fraction bar">+ <link rel="match" href="../../../../../expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-001-ref.html">+ <style type="text/css">+ @font-face {+ font-family: TestFont;+ src: url("../../../fonts/math/fraction-rulethickness10000.woff");+ }+ math {+ /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */+ /* The gap / shift / axisheight parameters are set to 0. */+ font-family: "TestFont";+ font-size: 1px;+ }+ #container {+ position: absolute;+ left: 0;+ top: 0;+ }+ </style>+ <script src="../../../common/reftest-wait.js"></script>+ <script src="../../../mathml/support/fonts.js"></script>+ <script>+ window.addEventListener("load", () => { loadAllFonts().then(adjustPositionOfFraction); });++ function adjustPositionOfFraction()+ {+ requestAnimationFrame(() => {+ var container = document.getElementById("container");+ var numeratorBox = document.getElementById("numerator").getBoundingClientRect();+ container.style.left = (10 - numeratorBox.left) + "px";+ container.style.top = (50 - numeratorBox.top) + "px";+ requestAnimationFrame(takeScreenshot);+ });+ }+ </script>+ </head>+ <body>+ <p>This test passes if you see a green square.</p>+ <div id="container">+ <math>+ <mfrac style="color: green; font-size: 15em">+ <mspace id="numerator" width="150px"></mspace>+ <mspace></mspace>+ </mfrac>+ </math>+ </div>+ <script src="../../../mathml/support/feature-detection.js"></script>+ <script>MathMLFeatureDetection.ensure_for_match_reftest("has_mfrac");</script>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-bar-002.html b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-bar-002.htmlnew file mode 100644index 00000000000..0a3edc1a9d9--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-bar-002.html@@ -0,0 +1,83 @@+<!DOCTYPE html>+<html class="reftest-wait">+ <head>+ <meta charset="utf-8">+ <title>fractions bar</title>+ <link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">+ <meta name="assert" content="Verify painting of the fraction bar when margin/padding/border are involved.">+ <link rel="match" href="../../../../../expected/wpt-import/mathml/presentation-markup/fractions/frac-bar-002-ref.html">+ <style type="text/css">+ @font-face {+ font-family: TestFont;+ src: url("../../../fonts/math/fraction-rulethickness10000.woff");+ }+ math {+ /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */+ /* The gap / shift / axisheight parameters are set to 0. */+ font-family: "TestFont";+ font-size: 1px;+ }+ #container {+ position: absolute;+ left: 0;+ top: 0;+ }+ #red {+ position: absolute;+ background: red;+ margin: 1px;+ width: 148px;+ height: 148px;+ }+ </style>+ <script src="../../../mathml/support/fonts.js"></script>+ <script src="../../../common/reftest-wait.js"></script>+ <script>+ window.addEventListener("load", () => { loadAllFonts().then(adjustPositionOfFraction); });++ function adjustPositionOfFraction()+ {+ requestAnimationFrame(() => {+ var container = document.getElementById("container");+ var red = document.getElementById("red");+ var numeratorBox = document.getElementById("numerator").getBoundingClientRect();+ const shift = 50;+ const numeratorMargin = 20;++ /* Move the red square at the expected position,+ with a 1px gap to avoid antialiasing issues. */+ red.style.left = `${shift}px`;+ red.style.top = `${shift}px`;++ /* Move the fraction bar at the expected position. */+ container.style.left = (shift - numeratorBox.left + numeratorMargin) + "px";+ container.style.top = (shift - numeratorBox.bottom - numeratorMargin) + "px";+ requestAnimationFrame(takeScreenshot);+ });+ }+ </script>+ </head>+ <body>+ <p>This test passes if you see a green <strong>square</strong> and no red.</p>+ <div>+ <div id="red"></div>+ <div id="container">+ <math>+ <!-- border, padding and margin should not affect the width of the fraction bar. -->+ <mfrac style="color: green; font-size: 15em;+ border: 30px solid transparent;+ padding: 60px; margin: 120px;+ ">+ <!-- the bar width is the one of the numerator margin box i.e. 80 + 2 * (5 + 10 + 20) = 150px -->+ <mspace id="numerator" width="80px"+ style="border: 5px solid transparent;+ padding: 10px; margin: 20px;"></mspace>+ <mspace></mspace>+ </mfrac>+ </math>+ </div>+ </div>+ <script src="../../../mathml/support/feature-detection.js"></script>+ <script>MathMLFeatureDetection.ensure_for_match_reftest("has_mfrac");</script>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001.html b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001.htmlnew file mode 100644index 00000000000..33632592376--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001.html@@ -0,0 +1,67 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <title>fractions linethickness</title>+ <link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">+ <meta name="assert" content="Verifies deprecated 'thin', 'medium', 'thick' and unitless values have no effect on the linethickness of the mfrac element">+ <link rel="match" href="../../../../../expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-001-ref.html">+ <style type="text/css">+ @font-face {+ font-family: TestFont;+ src: url("../../../fonts/math/fraction-rulethickness10000.woff");+ }+ math {+ /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */+ font-family: "TestFont";+ font-size: 1px;+ }+ </style>+ </head>+ <body>+ <p>This test passes if you see the same fraction eight times.</p>+ <math>+ <mfrac linethickness="thin">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="medium">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="thick">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="5">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="100%">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="100%">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="2km">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ <mspace width="20px"/>+ <mfrac linethickness="cat">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ </math>+ <script src="../../../mathml/support/feature-detection.js"></script>+ <script>MathMLFeatureDetection.ensure_for_match_reftest("has_mfrac");</script>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004.html b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004.htmlnew file mode 100644index 00000000000..4ed90162967--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <title>fractions linethickness</title>+ <link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">+ <meta name="assert" content="Verifies that unitless value of zero causes no fraction bar to be painted">+ <link rel="match" href="../../../../../expected/wpt-import/mathml/presentation-markup/fractions/frac-linethickness-004-ref.html">+ <style type="text/css">+ @font-face {+ font-family: TestFont;+ src: url("../../../fonts/math/fraction-rulethickness10000.woff");+ }+ math {+ /* FractionRuleThickness = 10000 * 1 / 1000 = 10px; */+ font-family: "TestFont";+ font-size: 1px;+ }+ </style>+ </head>+ <body>+ <p>This test passes if you see no fraction bar.</p>+ <math>+ <mfrac linethickness="0">+ <mspace width="20px" height="10px" style="background: blue"></mspace>+ <mspace width="20px" height="10px" style="background: cyan"></mspace>+ </mfrac>+ </math>+ <script src="../../../mathml/support/feature-detection.js"></script>+ <script>MathMLFeatureDetection.ensure_for_match_reftest("has_mfrac");</script>+ </body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001.html b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001.htmlnew file mode 100644index 00000000000..6a6b449ba92--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001.html@@ -0,0 +1,167 @@+<!DOCTYPE html>+<html class="reftest-wait">+<head>+<meta charset="utf-8">+<title>Dynamic radical: paint invalidation</title>+<link rel="help" href="https://w3c.github.io/mathml-core/#radicals-msqrt-mroot">+<meta name="assert" content="">+<link rel="match" href="../../../../../expected/wpt-import/mathml/presentation-markup/radicals/dynamic-radical-paint-invalidation-001-ref.html">+<style>+ @font-face {+ font-family: RadicalFont;+ src: url("../../../fonts/math/radical-displaystyleverticalgap7000-rulethickness1000.woff");+ }+ @font-face {+ font-family: RadicalFont2;+ src: url("../../../fonts/math/radical-kernbeforedegree4000-rulethickness1000.woff");+ }+ math {+ font-family: RadicalFont;+ font-size: 10px;+ }+ #container > div {+ height: 80px;+ border-top: solid;+ }+ .withPaddingBorderAndMargin {+ padding: 5px;+ border: 5px solid yellow;+ margin: 5px;+ }+</style>+<script src="../../../mathml/support/fonts.js"></script>+<script>+ window.addEventListener("load", () => { loadAllFonts().then(runTests); });+ function runTests() {+ // force initial layout so we're sure what we're testing against+ document.documentElement.getBoundingClientRect();++ var mroot = document.getElementsByTagName("mroot");+ var msqrt = document.getElementsByTagName("msqrt");++ // Modify base's width.+ msqrt[0].firstElementChild.setAttribute("width", "60px")+ mroot[0].firstElementChild.setAttribute("width", "60px")++ // Modify base's ascent.+ msqrt[1].firstElementChild.setAttribute("height", "20px")+ mroot[1].firstElementChild.setAttribute("height", "20px")++ // Modify base's descent.+ msqrt[2].firstElementChild.setAttribute("depth", "40px")+ mroot[2].firstElementChild.setAttribute("depth", "40px")++ // Modify the radical's font family.+ msqrt[3].parentNode.removeAttribute("style");+ mroot[3].parentNode.removeAttribute("style");++ // Modify radical's margin/border/padding+ msqrt[4].setAttribute("class", "withPaddingBorderAndMargin");+ mroot[4].setAttribute("class", "withPaddingBorderAndMargin");++ document.documentElement.classList.remove('reftest-wait');+ };+</script>+</head>+<body>+ <div id="container">+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math style="font-family: RadicalFont2">+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math style="font-family: RadicalFont2">+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ </msqrt>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ <div>+ <math>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ <mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: blue"/>+ <mspace width="20px" height="10px" depth="10px" style="background: lightblue"/>+ </mroot>+ <mspace width="20px" height="10px" depth="10px" style="background: gray"/>+ </math>+ </div>+ </div>+ <script src="../../../mathml/support/feature-detection.js"></script>+ <script>MathMLFeatureDetection.ensure_for_match_reftest("has_mspace");</script>+</body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/support/feature-detection.js b/Tests/LibWeb/Ref/input/wpt-import/mathml/support/feature-detection.jsnew file mode 100644index 00000000000..bc69be46bc1--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/support/feature-detection.js@@ -0,0 +1,330 @@+// This is a helper for MathML feature detection.+// It is indented to be used to prevent false negative test results.++var MathMLFeatureDetection = {++ "has_a": function() {+ // FIXME: Improve feature detection.+ return this.has_mrow();+ },++ "has_annotation": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_annotation-xml": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_maction": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_math": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_menclose": function() {+ // Just check whether <mrow> is supported because discussion on this is+ // still open ( https://github.com/mathml-refresh/mathml/issues/105 )+ // and it would have to behave at least like an mrow, even if it becomes+ // an unknown element at the end.+ return this.has_mrow();+ },++ "has_merror": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mfrac": function() {+ if (!this.hasOwnProperty("_has_mfrac")) {+ // Use tall enough fraction to avoid side effect of min num/denum shifts.+ document.body.insertAdjacentHTML("beforeend", "<math>\+<mfrac>\+ <mspace height='50px' depth='50px'></mspace>\+ <mspace height='50px' depth='50px'></mspace>\+</mfrac>\+<mfrac>\+ <mspace height='60px' depth='60px'></mspace>\+ <mspace height='60px' depth='60px'></mspace>\+</mfrac>\+</math>");+ var math = document.body.lastElementChild;+ var mfrac = math.getElementsByTagName("mfrac");+ // height/depth will add 40px per MathML, 20px if mfrac does not stack its children and none if mspace is not supported.+ this._has_mfrac =+ mfrac[1].getBoundingClientRect().height -+ mfrac[0].getBoundingClientRect().height > 30;+ document.body.removeChild(math);+ }+ return this._has_mfrac;+ },++ "has_mi": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mmultiscripts": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mn": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mo": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mover": function() {+ // FIXME: Improve feature detection.+ return this.has_munderover();+ },++ "has_mpadded": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mphantom": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mprescripts": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mroot": function() {+ // FIXME: Improve feature detection.+ return this.has_msqrt();+ },++ "has_mrow": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_ms": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mspace": function() {+ // https://w3c.github.io/mathml-core/#space-mspace+ if (!this.hasOwnProperty("_has_mspace")) {+ document.body.insertAdjacentHTML("beforeend", "<math>\+<mspace></mspace>\+<mspace width='20px'></mspace>\+</math>");+ var math = document.body.lastElementChild;+ // The width attribute will add 20px per MathML and none if not supported.+ this._has_mspace =+ math.lastChild.getBoundingClientRect().width -+ math.firstChild.getBoundingClientRect().width > 10;+ document.body.removeChild(math);+ }+ return this._has_mspace;+ },++ "has_msqrt": function() {+ if (!this.hasOwnProperty("_has_msqrt")) {+ document.body.insertAdjacentHTML("beforeend", "<math>\+<mrow style='font-size: 20px !important'>\+ <mtext>A</mtext>\+</mrow>\+<msqrt style='font-size: 20px !important'>\+ <mtext>A</mtext>\+</msqrt>\+</math>");+ var math = document.body.lastElementChild;+ // The radical symbol will make msqrt wider than mrow, if the former is supported.+ this._has_msqrt =+ math.lastElementChild.getBoundingClientRect().width -+ math.firstElementChild.getBoundingClientRect().width > 5;+ document.body.removeChild(math);+ }+ return this._has_msqrt;+ },++ "has_mstyle": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_msub": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_msubsup": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_msup": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mtable": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mtd": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mtext": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_mtr": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_munder": function() {+ // FIXME: Improve feature detection.+ return this.has_munderover();+ },++ "has_munderover": function() {+ if (!this.hasOwnProperty("_has_munderover")) {+ document.body.insertAdjacentHTML("beforeend", "<math>\+<munderover>\+ <mspace width='20px'></mspace>\+ <mspace width='20px'></mspace>\+ <mspace width='20px'></mspace>\+</munderover>\+<munderover>\+ <mspace width='40px'></mspace>\+ <mspace width='40px'></mspace>\+ <mspace width='40px'></mspace>\+</munderover>\+</math>");+ var math = document.body.lastElementChild;+ var munderover = math.getElementsByTagName("munderover");+ // width_delta will be 20px per MathML, 3 * 20 = 60px if mundeover does not stack its children and 0px if mspace is not supported.+ var width_delta =+ munderover[1].getBoundingClientRect().width -+ munderover[0].getBoundingClientRect().width;+ this._has_munderover = width_delta > 10 && width_delta < 30;+ document.body.removeChild(math);+ }+ return this._has_munderover;+ },++ "has_none": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_semantics": function() {+ // FIXME: Improve feature detection.+ return this.has_mspace();+ },++ "has_dir": function() {+ if (!this.hasOwnProperty("_has_dir")) {+ document.body.insertAdjacentHTML("beforeend", "<math style='direction: ltr !important;'>\+<mtext dir='rtl'></mtext>\+</math>");+ var math = document.body.lastElementChild;+ this._has_dir =+ window.getComputedStyle(math.firstElementChild).+ getPropertyValue('direction') === 'rtl';+ document.body.removeChild(math);+ }+ return this._has_dir;+ },++ "has_mathsize": function() {+ if (!this.hasOwnProperty("_has_mathsize")) {+ document.body.insertAdjacentHTML("beforeend", "<math style='font-size: 64px !important;'>\+<mtext mathsize='32px'></mtext>\+</math>");+ var math = document.body.lastElementChild;+ this._has_mathsize =+ window.getComputedStyle(math.firstElementChild).+ getPropertyValue('font-size') === '32px';+ document.body.removeChild(math);+ }+ return this._has_mathsize;+ },++ "has_movablelimits": function() {+ if (!this.hasOwnProperty("_has_movablelimits")) {+ document.body.insertAdjacentHTML("beforeend", "<math>\+<munder>\+ <mo style='font-size: 30px !important' movablelimits='false'>A</mo>\+ <mspace width='100px'></mspace>\+</munder>\+<munder>\+ <mo style='font-size: 30px !important' movablelimits='true'>A</mo>\+ <mspace width='100px'></mspace>\+</munder>\+</math>");+ var math = document.body.lastElementChild;+ var munder = math.getElementsByTagName("munder");+ // If movablelimits is supported, the <mspace> will be placed next+ // to <mo> rather than below it, so width_delta is about the width+ // of the <mo>.+ var width_delta =+ munder[1].getBoundingClientRect().width -+ munder[0].getBoundingClientRect().width;+ this._has_movablelimits = this.has_munder() && width_delta > 20;+ document.body.removeChild(math);+ }+ return this._has_movablelimits;+ },++ "has_operator_spacing": function() {+ // https://w3c.github.io/mathml-core/#dfn-lspace+ // https://w3c.github.io/mathml-core/#layout-of-mrow+ if (!this.hasOwnProperty("_has_operator_spacing")) {+ document.body.insertAdjacentHTML("beforeend", "<math>\+<mrow>\+ <mn>1</mn><mo lspace='0px' rspace='0px'>+</mo><mn>2</mn>\+</mrow>\+<mrow>\+ <mn>1</mn><mo lspace='20px' rspace='20px'>+</mo><mn>2</mn>\+</mrow>\+</math>");+ var math = document.body.lastElementChild;+ var mrow = math.getElementsByTagName("mrow");+ // lspace/rspace will add 40px per MathML and none if not supported.+ this._has_operator_spacing =+ mrow[1].getBoundingClientRect().width -+ mrow[0].getBoundingClientRect().width > 30;+ document.body.removeChild(math);+ }+ return this._has_operator_spacing;+ },++ ensure_for_match_reftest: function(has_function) {+ if (!document.querySelector("link[rel='match']"))+ throw "This function must only be used for match reftest";+ // Add a little red square at the top left corner if the feature is not supported in order to make match reftest fail.+ if (!this[has_function]()) {+ document.body.insertAdjacentHTML("beforeend", "\+<div style='width: 10px !important; height: 10px !important;\+ position: absolute !important;\+ left: 0 !important; top: 0 !important;\+ background: red !important; z-index: 1000 !important;'></div>");+ }+ }+};diff --git a/Tests/LibWeb/Ref/input/wpt-import/mathml/support/fonts.js b/Tests/LibWeb/Ref/input/wpt-import/mathml/support/fonts.jsnew file mode 100644index 00000000000..f05d7278adb--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/mathml/support/fonts.js@@ -0,0 +1,9 @@+function loadAllFonts() {+ // Use this to wait for all fonts in a testcase to load rather than just using+ // `document.fonts.ready.then(...)` in the load event, since there are compat+ // issues between browsers as to whether content initiated font loads are+ // guaranteed to have been started by this point.++ // FIXME: Use Promise.all() to cause an obvious failure when a font fails to load.+ return Promise.allSettled([...document.fonts].map(f => f.load()));+}