Skip to content

Truly independent web browser

LibGfx+LibWeb: Measure the actual bounding box of canvas text

Andreas Kling76b5d91f2174
diff --git a/Libraries/LibGfx/Rust/src/text_layout.rs b/Libraries/LibGfx/Rust/src/text_layout.rs
index 8489b9d0f97..3c7dc89cd9c 100644
--- a/Libraries/LibGfx/Rust/src/text_layout.rs
+++ b/Libraries/LibGfx/Rust/src/text_layout.rs
@@ -66,6 +66,14 @@ unsafe extern "C" {
out_rect: *mut f32,
);
+ fn ladybird_gfx_glyph_run_ink_bounding_box(
+ font: *const c_void,
+ glyphs: *const DrawGlyph,
+ glyph_count: usize,
+ scale: f32,
+ out_rect: *mut f32,
+ );
+
fn ladybird_gfx_glyph_run_glyph_intercepts(
font: *const c_void,
glyphs: *const DrawGlyph,
@@ -95,6 +103,25 @@ pub fn glyph_run_bounding_box(font: &FontHandle, glyphs: &[DrawGlyph], scale: f3
out_rect
}
+/// Tight bounds of the ink of the painted glyphs, from their own extents, in the coordinates of
+/// `glyph_run_bounding_box()`, as x, y, width and height. Empty if no painted glyph has ink.
+#[must_use]
+pub fn glyph_run_ink_bounding_box(font: &FontHandle, glyphs: &[DrawGlyph], scale: f32) -> [f32; 4] {
+ let mut out_rect = [0.0f32; 4];
+ // SAFETY: The handle keeps the font live and the glyph slice stays valid
+ // for the synchronous call, which fills the four floats out_rect points at.
+ unsafe {
+ ladybird_gfx_glyph_run_ink_bounding_box(
+ font.as_raw(),
+ glyphs.as_ptr(),
+ glyphs.len(),
+ scale,
+ out_rect.as_mut_ptr(),
+ );
+ }
+ out_rect
+}
+
#[must_use]
pub fn glyph_run_glyph_intercepts(
font: &FontHandle,
diff --git a/Libraries/LibGfx/TextLayout.cpp b/Libraries/LibGfx/TextLayout.cpp
index b33efb0ee17..570a38b7ec9 100644
--- a/Libraries/LibGfx/TextLayout.cpp
+++ b/Libraries/LibGfx/TextLayout.cpp
@@ -34,6 +34,41 @@ GlyphRun::GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font const> font, T
GlyphRun::~GlyphRun() = default;
+// Tight bounds of the ink of the painted glyphs, from their own extents, in the coordinates of glyph_run_bounding_box().
+// Empty if no painted glyph has ink.
+static FloatRect glyph_run_ink_bounding_box(Font const& font, ReadonlySpan<DrawGlyph> glyphs, float scale)
+{
+ auto font_ascent = font.pixel_metrics().ascent;
+ auto* hb_font = font.harfbuzz_font();
+ int x_scale = 0;
+ int y_scale = 0;
+ hb_font_get_scale(hb_font, &x_scale, &y_scale);
+ if (x_scale <= 0 || y_scale <= 0)
+ return {};
+ auto units_to_pixels_x = font.pixel_size() * scale / x_scale;
+ auto units_to_pixels_y = font.pixel_size() * scale / y_scale;
+
+ FloatRect bounds;
+ for (auto const& glyph : glyphs) {
+ if (!glyph.should_paint)
+ continue;
+ hb_glyph_extents_t extents;
+ if (!hb_font_get_glyph_extents(hb_font, glyph.glyph_id, &extents))
+ continue;
+ auto origin_x = glyph.position.x() * scale;
+ auto origin_y = (glyph.position.y() + font_ascent) * scale;
+ // HarfBuzz extents have y pointing up, so `height` is negative for ink above the baseline.
+ FloatRect glyph_bounds {
+ origin_x + extents.x_bearing * units_to_pixels_x,
+ origin_y - extents.y_bearing * units_to_pixels_y,
+ extents.width * units_to_pixels_x,
+ -extents.height * units_to_pixels_y,
+ };
+ bounds.unite(glyph_bounds);
+ }
+ return bounds;
+}
+
FloatRect glyph_run_bounding_box(Font const& font, ReadonlySpan<DrawGlyph> glyphs, float scale)
{
auto font_ascent = font.pixel_metrics().ascent;
@@ -73,34 +108,7 @@ FloatRect glyph_run_bounding_box(Font const& font, ReadonlySpan<DrawGlyph> glyph
}
// The font doesn't record an overall bounding box (e.g. bitmap-only fonts), so unite the glyphs' own extents.
- auto* hb_font = font.harfbuzz_font();
- int x_scale = 0;
- int y_scale = 0;
- hb_font_get_scale(hb_font, &x_scale, &y_scale);
- if (x_scale <= 0 || y_scale <= 0)
- return {};
- auto units_to_pixels_x = font.pixel_size() * scale / x_scale;
- auto units_to_pixels_y = font.pixel_size() * scale / y_scale;
-
- FloatRect bounds;
- for (auto const& glyph : glyphs) {
- if (!glyph.should_paint)
- continue;
- hb_glyph_extents_t extents;
- if (!hb_font_get_glyph_extents(hb_font, glyph.glyph_id, &extents))
- continue;
- auto origin_x = glyph.position.x() * scale;
- auto origin_y = (glyph.position.y() + font_ascent) * scale;
- // HarfBuzz extents have y pointing up, so `height` is negative for ink above the baseline.
- FloatRect glyph_bounds {
- origin_x + extents.x_bearing * units_to_pixels_x,
- origin_y - extents.y_bearing * units_to_pixels_y,
- extents.width * units_to_pixels_x,
- -extents.height * units_to_pixels_y,
- };
- bounds.unite(glyph_bounds);
- }
- return bounds;
+ return glyph_run_ink_bounding_box(font, glyphs, scale);
}
namespace {
@@ -599,6 +607,7 @@ extern "C" {
void ladybird_gfx_shape_text_uncached(void const*, u16 const*, size_t, Gfx::FFI::TextType, float, float, void*, void (*)(void*, Gfx::FFI::DrawGlyph const*, size_t, float, size_t, float));
float ladybird_gfx_font_measure_text_width(void const*, u16 const*, size_t);
void ladybird_gfx_glyph_run_bounding_box(void const*, Gfx::FFI::DrawGlyph const*, size_t, float, float*);
+void ladybird_gfx_glyph_run_ink_bounding_box(void const*, Gfx::FFI::DrawGlyph const*, size_t, float, float*);
void ladybird_gfx_glyph_run_glyph_intercepts(void const*, Gfx::FFI::DrawGlyph const*, size_t, float, float, float, void*, void (*)(void*, float));
}
@@ -666,6 +675,26 @@ extern "C" void ladybird_gfx_glyph_run_bounding_box(
out_rect[3] = bounds.height();
}
+extern "C" void ladybird_gfx_glyph_run_ink_bounding_box(
+ void const* font,
+ Gfx::FFI::DrawGlyph const* glyphs,
+ size_t glyph_count,
+ float scale,
+ float* out_rect)
+{
+ VERIFY(font);
+ VERIFY(glyphs || glyph_count == 0);
+ VERIFY(out_rect);
+ auto bounds = Gfx::glyph_run_ink_bounding_box(
+ *static_cast<Gfx::Font const*>(font),
+ { reinterpret_cast<Gfx::DrawGlyph const*>(glyphs), glyph_count },
+ scale);
+ out_rect[0] = bounds.x();
+ out_rect[1] = bounds.y();
+ out_rect[2] = bounds.width();
+ out_rect[3] = bounds.height();
+}
+
extern "C" void ladybird_gfx_glyph_run_glyph_intercepts(
void const* font,
Gfx::FFI::DrawGlyph const* glyphs,
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs
index f51551e762e..d9e0d4ac78a 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_text.rs
@@ -11,6 +11,7 @@ use core::ptr::NonNull;
use ak::Utf16String;
use libcompositing_rust::display_list::commands::DisplayListGlyph;
use libgfx_rust::path::Path;
+use libgfx_rust::text_layout::glyph_run_ink_bounding_box;
use libgfx_rust::{CompositingAndBlendingOperator, FloatPoint, WindingRule};
use super::text_metrics::{TextMeasurements, TextMetrics};
@@ -225,17 +226,31 @@ impl<K: CanvasKind> RenderingContext2D<K> {
let text_baseline: CanvasTextBaseline = self.drawing_state().text_baseline;
let baseline_offset = baseline_offset(text_baseline, &first_font);
+ // NB: The bounding rectangle of the given text is that of the ink of its glyphs, which is relative to the
+ // alphabetic baseline at the start of the inline box. Text without ink has that of the inline box.
+ let ink_bounds = runs
+ .iter()
+ .filter(|run| !run.font.is_invisible())
+ .map(|run| glyph_run_ink_bounding_box(&run.font, &run.glyphs, 1.0))
+ .filter(|[_, _, width, height]| *width > 0.0 && *height > 0.0)
+ .map(|[x, y, width, height]| (x, x + width, y, y + height))
+ .reduce(|a, b| (a.0.min(b.0), a.1.max(b.1), a.2.min(b.2), a.3.max(b.3)));
+ let (text_left, text_right, text_top, text_bottom) = match ink_bounds {
+ Some((left, right, top, bottom)) => (alignment_offset + left, alignment_offset + right, top, bottom),
+ None => (box_left, box_right, -ascent, descent),
+ };
+
let measurements = TextMeasurements {
// width attribute: The width of that inline box, in CSS pixels. (The text's advance width.)
width: f64::from(width),
// actualBoundingBoxLeft attribute: The distance parallel to the baseline from the alignment point given by
// the textAlign attribute to the left side of the bounding rectangle of the given text, in CSS pixels;
// positive numbers indicating a distance going left from the given alignment point.
- actual_bounding_box_left: f64::from(-box_left),
+ actual_bounding_box_left: f64::from(-text_left),
// actualBoundingBoxRight attribute: The distance parallel to the baseline from the alignment point given
// by the textAlign attribute to the right side of the bounding rectangle of the given text, in CSS pixels;
// positive numbers indicating a distance going right from the given alignment point.
- actual_bounding_box_right: f64::from(box_right),
+ actual_bounding_box_right: f64::from(text_right),
// fontBoundingBoxAscent attribute: The distance from the horizontal line indicated by the textBaseline
// attribute to the ascent metric of the first available font, in CSS pixels; positive numbers indicating
// a distance going up from the given baseline.
@@ -247,11 +262,11 @@ impl<K: CanvasKind> RenderingContext2D<K> {
// actualBoundingBoxAscent attribute: The distance from the horizontal line indicated by the textBaseline
// attribute to the top of the bounding rectangle of the given text, in CSS pixels; positive numbers
// indicating a distance going up from the given baseline.
- actual_bounding_box_ascent: f64::from(ascent - baseline_offset),
+ actual_bounding_box_ascent: f64::from(-text_top - baseline_offset),
// actualBoundingBoxDescent attribute: The distance from the horizontal line indicated by the textBaseline
// attribute to the bottom of the bounding rectangle of the given text, in CSS pixels; positive numbers
// indicating a distance going down from the given baseline.
- actual_bounding_box_descent: f64::from(descent + baseline_offset),
+ actual_bounding_box_descent: f64::from(text_bottom + baseline_offset),
// emHeightAscent attribute: The distance from the horizontal line indicated by the textBaseline attribute
// to the highest top of the em squares in the inline box, in CSS pixels; positive numbers indicating that
// the given baseline is below the top of that em square (so this value will usually be positive). Zero if
diff --git a/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txt b/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txt
index 9a872cc5acc..c230dc9a484 100644
--- a/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txt
+++ b/Tests/LibWeb/Text/expected/canvas/2d-measure-text.txt
@@ -2,113 +2,113 @@ A canvas:
10px sans-serif
"": 0, 0, 0, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
" ": 5, 0, 5, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "Hello, world!": 61.953125, 0, 61.953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "a\tb\nc\fd\re": 47.6875, 0, 47.6875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "é😀漢字 mixed": 55.578125, 0, 55.578125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "\ud800 lone": 29.21875, 0, 29.21875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "Hello, world!": 61.953125, -0.59375, 61.40625, 7.998046875, 2.001953125, 7.28125, 0.4375, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "a\tb\nc\fd\re": 47.6875, -0.078125, 47.140625, 7.998046875, 2.001953125, 7.25, 0.078125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "é😀漢字 mixed": 55.578125, -0.328125, 54.921875, 7.998046875, 2.001953125, 8.46875, 1.625, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "\ud800 lone": 29.21875, -0.328125, 28.671875, 7.998046875, 2.001953125, 6.65625, 0.46875, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
23px serif
"": 0, 0, 0, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
" ": 11.5, 0, 11.5, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "Hello, world!": 142.59375, 0, 142.59375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "a\tb\nc\fd\re": 109.65625, 0, 109.65625, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "é😀漢字 mixed": 127.8125, 0, 127.8125, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "\ud800 lone": 67.234375, 0, 67.234375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "Hello, world!": 142.59375, -1.359375, 141.328125, 18.3955078125, 4.6044921875, 16.75, 1.03125, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "a\tb\nc\fd\re": 109.65625, -0.1875, 108.390625, 18.3955078125, 4.6044921875, 16.6875, 0.171875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "é😀漢字 mixed": 127.8125, -0.75, 126.265625, 18.3955078125, 4.6044921875, 19.484375, 3.75, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "\ud800 lone": 67.234375, -0.75, 65.96875, 18.3955078125, 4.6044921875, 15.3125, 1.078125, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
700 17.5px monospace
"": 0, 0, 0, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
" ": 8.75, 0, 8.75, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "Hello, world!": 108.4375, 0, 108.4375, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "a\tb\nc\fd\re": 83.421875, 0, 83.421875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "é😀漢字 mixed": 97.203125, 0, 97.203125, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "\ud800 lone": 51.140625, 0, 51.140625, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "Hello, world!": 108.4375, -1.03125, 107.46875, 13.99658203125, 3.50341796875, 12.734375, 0.78125, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "a\tb\nc\fd\re": 83.421875, -0.140625, 82.453125, 13.99658203125, 3.50341796875, 12.6875, 0.125, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "é😀漢字 mixed": 97.203125, -0.578125, 96.03125, 13.99658203125, 3.50341796875, 14.953125, 2.984375, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "\ud800 lone": 51.140625, -0.578125, 50.171875, 13.99658203125, 3.50341796875, 11.640625, 0.8125, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
italic 9px sans-serif
"": 0, 0, 0, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
" ": 4.5, 0, 4.5, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "Hello, world!": 55.78125, 0, 55.78125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "a\tb\nc\fd\re": 42.90625, 0, 42.90625, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "é😀漢字 mixed": 49.96875, 0, 49.96875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "\ud800 lone": 26.296875, 0, 26.296875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "Hello, world!": 55.78125, -0.53125, 55.28125, 7.1982421875, 1.8017578125, 6.546875, 0.390625, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "a\tb\nc\fd\re": 42.90625, -0.078125, 42.40625, 7.1982421875, 1.8017578125, 6.515625, 0.0625, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "é😀漢字 mixed": 49.96875, -0.296875, 49.375, 7.1982421875, 1.8017578125, 7.609375, 1.46875, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "\ud800 lone": 26.296875, -0.296875, 25.796875, 7.1982421875, 1.8017578125, 5.984375, 0.421875, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
textBaseline top
- "Baseline": 59.90625, 0, 59.90625, 0, 15, 0, 15, 0, 15, -2.3994140625, -11.9970703125, -15
+ "Baseline": 59.90625, -0.90625, 59.078125, 0, 15, -0.7314453125, 12.7001953125, 0, 15, -2.3994140625, -11.9970703125, -15
textBaseline hanging
- "Baseline": 59.90625, 0, 59.90625, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 0, -9.59765625, -12.6005859375
+ "Baseline": 59.90625, -0.90625, 59.078125, 2.3994140625, 12.6005859375, 1.66796875, 10.30078125, 2.3994140625, 12.6005859375, 0, -9.59765625, -12.6005859375
textBaseline middle
- "Baseline": 59.90625, 0, 59.90625, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 5.1005859375, -4.4970703125, -7.5
+ "Baseline": 59.90625, -0.90625, 59.078125, 7.5, 7.5, 6.7685546875, 5.2001953125, 7.5, 7.5, 5.1005859375, -4.4970703125, -7.5
textBaseline alphabetic
- "Baseline": 59.90625, 0, 59.90625, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Baseline": 59.90625, -0.90625, 59.078125, 11.9970703125, 3.0029296875, 11.265625, 0.703125, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textBaseline ideographic
- "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0
+ "Baseline": 59.90625, -0.90625, 59.078125, 15, 0, 14.2685546875, -2.2998046875, 15, 0, 12.6005859375, 3.0029296875, 0
textBaseline bottom
- "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0
+ "Baseline": 59.90625, -0.90625, 59.078125, 15, 0, 14.2685546875, -2.2998046875, 15, 0, 12.6005859375, 3.0029296875, 0
letterSpacing 3px
- "Spaced out": 115.5, 0, 115.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Spaced out": 115.5, -0.65625, 111.671875, 11.9970703125, 3.0029296875, 11.265625, 0.6875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
letterSpacing -1px
- "Spaced out": 75.5, 0, 75.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Spaced out": 75.5, -0.65625, 75.671875, 11.9970703125, 3.0029296875, 11.265625, 0.6875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
letterSpacing 0.5em
- "Spaced out": 160.5, 0, 160.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Spaced out": 160.5, -0.65625, 152.171875, 11.9970703125, 3.0029296875, 11.265625, 0.6875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign start
- "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, -0.671875, 52.265625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign end
- "Aligned": 53.28125, 53.28125, 0, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, 52.609375, -1.015625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign left
- "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, -0.671875, 52.265625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign right
- "Aligned": 53.28125, 53.28125, 0, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, 52.609375, -1.015625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign center
- "Aligned": 53.28125, 26.640625, 26.640625, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, 25.96875, 25.625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
An OffscreenCanvas:
10px sans-serif
"": 0, 0, 0, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
" ": 5, 0, 5, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "Hello, world!": 61.953125, 0, 61.953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "a\tb\nc\fd\re": 47.6875, 0, 47.6875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "é😀漢字 mixed": 55.578125, 0, 55.578125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
- "\ud800 lone": 29.21875, 0, 29.21875, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "Hello, world!": 61.953125, -0.59375, 61.40625, 7.998046875, 2.001953125, 7.28125, 0.4375, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "a\tb\nc\fd\re": 47.6875, -0.078125, 47.140625, 7.998046875, 2.001953125, 7.25, 0.078125, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "é😀漢字 mixed": 55.578125, -0.328125, 54.921875, 7.998046875, 2.001953125, 8.46875, 1.625, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
+ "\ud800 lone": 29.21875, -0.328125, 28.671875, 7.998046875, 2.001953125, 6.65625, 0.46875, 7.998046875, 2.001953125, 6.3984375, 0, -2.001953125
23px serif
"": 0, 0, 0, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
" ": 11.5, 0, 11.5, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "Hello, world!": 142.59375, 0, 142.59375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "a\tb\nc\fd\re": 109.65625, 0, 109.65625, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "é😀漢字 mixed": 127.8125, 0, 127.8125, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
- "\ud800 lone": 67.234375, 0, 67.234375, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "Hello, world!": 142.59375, -1.359375, 141.328125, 18.3955078125, 4.6044921875, 16.75, 1.03125, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "a\tb\nc\fd\re": 109.65625, -0.1875, 108.390625, 18.3955078125, 4.6044921875, 16.6875, 0.171875, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "é😀漢字 mixed": 127.8125, -0.75, 126.265625, 18.3955078125, 4.6044921875, 19.484375, 3.75, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
+ "\ud800 lone": 67.234375, -0.75, 65.96875, 18.3955078125, 4.6044921875, 15.3125, 1.078125, 18.3955078125, 4.6044921875, 14.71640682220459, 0, -4.6044921875
700 17.5px monospace
"": 0, 0, 0, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
" ": 8.75, 0, 8.75, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "Hello, world!": 108.4375, 0, 108.4375, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "a\tb\nc\fd\re": 83.421875, 0, 83.421875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "é😀漢字 mixed": 97.203125, 0, 97.203125, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
- "\ud800 lone": 51.140625, 0, 51.140625, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "Hello, world!": 108.4375, -1.03125, 107.46875, 13.99658203125, 3.50341796875, 12.734375, 0.78125, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "a\tb\nc\fd\re": 83.421875, -0.140625, 82.453125, 13.99658203125, 3.50341796875, 12.6875, 0.125, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "é😀漢字 mixed": 97.203125, -0.578125, 96.03125, 13.99658203125, 3.50341796875, 14.953125, 2.984375, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
+ "\ud800 lone": 51.140625, -0.578125, 50.171875, 13.99658203125, 3.50341796875, 11.640625, 0.8125, 13.99658203125, 3.50341796875, 11.197265625, 0, -3.50341796875
italic 9px sans-serif
"": 0, 0, 0, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
" ": 4.5, 0, 4.5, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "Hello, world!": 55.78125, 0, 55.78125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "a\tb\nc\fd\re": 42.90625, 0, 42.90625, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "é😀漢字 mixed": 49.96875, 0, 49.96875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
- "\ud800 lone": 26.296875, 0, 26.296875, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "Hello, world!": 55.78125, -0.53125, 55.28125, 7.1982421875, 1.8017578125, 6.546875, 0.390625, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "a\tb\nc\fd\re": 42.90625, -0.078125, 42.40625, 7.1982421875, 1.8017578125, 6.515625, 0.0625, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "é😀漢字 mixed": 49.96875, -0.296875, 49.375, 7.1982421875, 1.8017578125, 7.609375, 1.46875, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
+ "\ud800 lone": 26.296875, -0.296875, 25.796875, 7.1982421875, 1.8017578125, 5.984375, 0.421875, 7.1982421875, 1.8017578125, 5.758594036102295, 0, -1.8017578125
textBaseline top
- "Baseline": 59.90625, 0, 59.90625, 0, 15, 0, 15, 0, 15, -2.3994140625, -11.9970703125, -15
+ "Baseline": 59.90625, -0.90625, 59.078125, 0, 15, -0.7314453125, 12.7001953125, 0, 15, -2.3994140625, -11.9970703125, -15
textBaseline hanging
- "Baseline": 59.90625, 0, 59.90625, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 2.3994140625, 12.6005859375, 0, -9.59765625, -12.6005859375
+ "Baseline": 59.90625, -0.90625, 59.078125, 2.3994140625, 12.6005859375, 1.66796875, 10.30078125, 2.3994140625, 12.6005859375, 0, -9.59765625, -12.6005859375
textBaseline middle
- "Baseline": 59.90625, 0, 59.90625, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 5.1005859375, -4.4970703125, -7.5
+ "Baseline": 59.90625, -0.90625, 59.078125, 7.5, 7.5, 6.7685546875, 5.2001953125, 7.5, 7.5, 5.1005859375, -4.4970703125, -7.5
textBaseline alphabetic
- "Baseline": 59.90625, 0, 59.90625, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Baseline": 59.90625, -0.90625, 59.078125, 11.9970703125, 3.0029296875, 11.265625, 0.703125, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textBaseline ideographic
- "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0
+ "Baseline": 59.90625, -0.90625, 59.078125, 15, 0, 14.2685546875, -2.2998046875, 15, 0, 12.6005859375, 3.0029296875, 0
textBaseline bottom
- "Baseline": 59.90625, 0, 59.90625, 15, 0, 15, 0, 15, 0, 12.6005859375, 3.0029296875, 0
+ "Baseline": 59.90625, -0.90625, 59.078125, 15, 0, 14.2685546875, -2.2998046875, 15, 0, 12.6005859375, 3.0029296875, 0
letterSpacing 3px
- "Spaced out": 115.5, 0, 115.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Spaced out": 115.5, -0.65625, 111.671875, 11.9970703125, 3.0029296875, 11.265625, 0.6875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
letterSpacing -1px
- "Spaced out": 75.5, 0, 75.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Spaced out": 75.5, -0.65625, 75.671875, 11.9970703125, 3.0029296875, 11.265625, 0.6875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
letterSpacing 0.5em
- "Spaced out": 160.5, 0, 160.5, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Spaced out": 160.5, -0.65625, 152.171875, 11.9970703125, 3.0029296875, 11.265625, 0.6875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign start
- "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, -0.671875, 52.265625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign end
- "Aligned": 53.28125, 53.28125, 0, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, 52.609375, -1.015625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign left
- "Aligned": 53.28125, 0, 53.28125, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, -0.671875, 52.265625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign right
- "Aligned": 53.28125, 53.28125, 0, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, 52.609375, -1.015625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
textAlign center
- "Aligned": 53.28125, 26.640625, 26.640625, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
+ "Aligned": 53.28125, 25.96875, 25.625, 11.9970703125, 3.0029296875, 11.265625, 1.859375, 11.9970703125, 3.0029296875, 9.59765625, 0, -3.0029296875
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.txt
index 614daaf21cb..8656df7541a 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Testing actualBoundingBox
\ No newline at end of file
+1 Pass
+Pass Testing actualBoundingBox
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.txt
index a2c43291bd6..a46c0a2b875 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Testing actualBoundingBox with leading/trailing whitespace
\ No newline at end of file
+1 Pass
+Pass Testing actualBoundingBox with leading/trailing whitespace
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.txt
index 614daaf21cb..8656df7541a 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Testing actualBoundingBox
\ No newline at end of file
+1 Pass
+Pass Testing actualBoundingBox
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.txt
index a2c43291bd6..a46c0a2b875 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Testing actualBoundingBox with leading/trailing whitespace
\ No newline at end of file
+1 Pass
+Pass Testing actualBoundingBox with leading/trailing whitespace
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.txt
index a2c43291bd6..a46c0a2b875 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Testing actualBoundingBox with leading/trailing whitespace
\ No newline at end of file
+1 Pass
+Pass Testing actualBoundingBox with leading/trailing whitespace
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker.txt
index 614daaf21cb..8656df7541a 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Testing actualBoundingBox
\ No newline at end of file
+1 Pass
+Pass Testing actualBoundingBox
\ No newline at end of file