diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index e266e0b81a..1e50fb5727 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -311,11 +311,11 @@ Gfx::Path CanvasRenderingContext2D::text_path(Utf16String const& text, float x, auto glyph_runs = Gfx::shape_text({ x, y }, text.utf16_view(), *font_cascade_list, resolved_letter_spacing(drawing_state, canvas_element())); Gfx::Path path; + float text_width = 0; for (auto const& glyph_run : glyph_runs) { path.glyph_run(glyph_run); + text_width += glyph_run->width(); } - - auto text_width = path.bounding_box().width(); Gfx::AffineTransform transform = {}; // https://html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm: diff --git a/Tests/LibWeb/Screenshot/expected/canvas-text.png b/Tests/LibWeb/Screenshot/expected/canvas-text.png index 8ecdfb383d..c9056042af 100644 Binary files a/Tests/LibWeb/Screenshot/expected/canvas-text.png and b/Tests/LibWeb/Screenshot/expected/canvas-text.png differ diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.center.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.center.txt new file mode 100644 index 0000000000..71a7f198fe --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.center.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass textAlign center is the center of the em squares (not the bounding box) \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.end.ltr.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.end.ltr.txt new file mode 100644 index 0000000000..f6a962bb6e --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.end.ltr.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass textAlign end with ltr is the right edge \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.right.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.right.txt new file mode 100644 index 0000000000..da38024c62 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.align.right.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass textAlign right is the right of the last em square (not the bounding box) \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.fill.maxWidth.bound.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.fill.maxWidth.bound.txt new file mode 100644 index 0000000000..a97ed69a8c --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.fill.maxWidth.bound.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass fillText handles maxWidth based on line size, not bounding box size \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.space.collapse.end.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.space.collapse.end.txt new file mode 100644 index 0000000000..e0d65f5391 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/text/2d.text.draw.space.collapse.end.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Space characters at the end of a line are NOT collapsed \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.center.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.center.html new file mode 100644 index 0000000000..20ab6b6d59 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.center.html @@ -0,0 +1,48 @@ + + + +
textAlign center is the center of the em squares (not the bounding box)
+ + + +Actual output:
+ +Expected output:
+
textAlign end with ltr is the right edge
+ + + +Actual output:
+ +Expected output:
+
textAlign right is the right of the last em square (not the bounding box)
+ + + +Actual output:
+ +Expected output:
+
fillText handles maxWidth based on line size, not bounding box size
+ + + +Actual output:
+ +Expected output:
+
Space characters at the end of a line are NOT collapsed
+ + + +Actual output:
+ +Expected output:
+