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 @@ + + + +Canvas test: 2d.text.draw.align.center + + + + + + + +

2d.text.draw.align.center

+

textAlign center is the center of the em squares (not the bounding box)

+ + +A +

Actual output:

+

FAIL (fallback content)

+

Expected output:

+

+ + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.end.ltr.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.end.ltr.html new file mode 100644 index 0000000000..c0cf2acb8e --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.end.ltr.html @@ -0,0 +1,48 @@ + + + +Canvas test: 2d.text.draw.align.end.ltr + + + + + + + +

2d.text.draw.align.end.ltr

+

textAlign end with ltr is the right edge

+ + +A +

Actual output:

+

FAIL (fallback content)

+

Expected output:

+

+ + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.right.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.right.html new file mode 100644 index 0000000000..c9a1a46d89 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.align.right.html @@ -0,0 +1,48 @@ + + + +Canvas test: 2d.text.draw.align.right + + + + + + + +

2d.text.draw.align.right

+

textAlign right is the right of the last em square (not the bounding box)

+ + +A +

Actual output:

+

FAIL (fallback content)

+

Expected output:

+

+ + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.fill.maxWidth.bound.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.fill.maxWidth.bound.html new file mode 100644 index 0000000000..773ebc2d91 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.fill.maxWidth.bound.html @@ -0,0 +1,45 @@ + + + +Canvas test: 2d.text.draw.fill.maxWidth.bound + + + + + + + +

2d.text.draw.fill.maxWidth.bound

+

fillText handles maxWidth based on line size, not bounding box size

+ + +A +

Actual output:

+

FAIL (fallback content)

+

Expected output:

+

+ + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.space.collapse.end.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.space.collapse.end.html new file mode 100644 index 0000000000..99d1184b7f --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/text/2d.text.draw.space.collapse.end.html @@ -0,0 +1,44 @@ + + + +Canvas test: 2d.text.draw.space.collapse.end + + + + + + + +

2d.text.draw.space.collapse.end

+

Space characters at the end of a line are NOT collapsed

+ + +A +

Actual output:

+

FAIL (fallback content)

+

Expected output:

+

+ +