mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Ignore non-finite arguments to canvas text drawing methods
This commit is contained in:
parent
26b82986c4
commit
303ebc0a67
Notes:
github-actions[bot]
2025-10-20 11:13:27 +00:00
Author: https://github.com/tcl3
Commit: 303ebc0a67
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6516
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 46 additions and 0 deletions
|
|
@ -310,13 +310,21 @@ Gfx::Path CanvasRenderingContext2D::text_path(Utf16String const& text, float x,
|
|||
return path.copy_transformed(transform);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filltext
|
||||
void CanvasRenderingContext2D::fill_text(Utf16String const& text, float x, float y, Optional<double> max_width)
|
||||
{
|
||||
if (!isfinite(x) || !isfinite(y) || (max_width.has_value() && !isfinite(max_width.value())))
|
||||
return;
|
||||
|
||||
fill_internal(text_path(text, x, y, max_width), Gfx::WindingRule::Nonzero);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroketext
|
||||
void CanvasRenderingContext2D::stroke_text(Utf16String const& text, float x, float y, Optional<double> max_width)
|
||||
{
|
||||
if (!isfinite(x) || !isfinite(y) || (max_width.has_value() && !isfinite(max_width.value())))
|
||||
return;
|
||||
|
||||
stroke_internal(text_path(text, x, y, max_width));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
Harness status: OK
|
||||
|
||||
Found 1 tests
|
||||
|
||||
1 Pass
|
||||
Pass fillText handles maxWidth correctly
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||
<meta charset="UTF-8">
|
||||
<title>Canvas test: 2d.text.draw.fill.maxWidth.NaN</title>
|
||||
<script src="../../../../resources/testharness.js"></script>
|
||||
<script src="../../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
|
||||
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
|
||||
<body class="show_output">
|
||||
|
||||
<h1>2d.text.draw.fill.maxWidth.NaN</h1>
|
||||
<p class="desc">fillText handles maxWidth correctly</p>
|
||||
|
||||
|
||||
<p class="output">Actual output:</p>
|
||||
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||
<p class="output expectedtext">Expected output:<p><img src="../../../../images/green-100x50.png" class="output expected" id="expected" alt="">
|
||||
<ul id="d"></ul>
|
||||
<script>
|
||||
var t = async_test("fillText handles maxWidth correctly");
|
||||
_addTest(function(canvas, ctx) {
|
||||
|
||||
ctx.fillStyle = '#0f0';
|
||||
ctx.fillRect(0, 0, 100, 50);
|
||||
ctx.fillStyle = '#f00';
|
||||
ctx.font = '35px Arial, sans-serif';
|
||||
ctx.fillText('fail fail fail fail fail', 5, 35, NaN);
|
||||
_assertGreen(ctx, 100, 50);
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue