LibWeb: Normalize negative drawImage() source/destination dimensions

This commit is contained in:
Tim Ledbetter 2025-10-22 10:52:56 +01:00 committed by Jelle Raaijmakers
parent e93f44112d
commit 976912f3e9
Notes: github-actions[bot] 2025-10-22 10:30:20 +00:00
10 changed files with 539 additions and 0 deletions

View file

@ -171,6 +171,22 @@ WebIDL::ExceptionOr<void> CanvasRenderingContext2D::draw_image_internal(CanvasIm
// The source rectangle is the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh).
// The destination rectangle is the rectangle whose corners are the four points (dx, dy), (dx+dw, dy), (dx+dw, dy+dh), (dx, dy+dh).
// NOTE: Implemented in drawImage() overloads
if (source_width < 0) {
source_x += source_width;
source_width = abs(source_width);
}
if (source_height < 0) {
source_y += source_height;
source_height = abs(source_height);
}
if (destination_width < 0) {
destination_x += destination_width;
destination_width = abs(destination_width);
}
if (destination_height < 0) {
destination_y += destination_height;
destination_height = abs(destination_height);
}
// The source rectangle is the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh).
auto source_rect = Gfx::FloatRect { source_x, source_y, source_width, source_height };