LibWeb: Clamp any values less than 1 in perspective() transform function

This commit is contained in:
Psychpsyo 2025-11-12 17:33:05 +01:00 committed by Jelle Raaijmakers
parent 0cb9f4b66f
commit d284b4c2b8
Notes: github-actions[bot] 2025-11-12 17:46:31 +00:00
4 changed files with 77 additions and 3 deletions

View file

@ -75,15 +75,20 @@ ErrorOr<Gfx::FloatMatrix4x4> Transformation::to_matrix(Optional<Painting::Painta
switch (m_function) {
case CSS::TransformFunction::Perspective:
// https://drafts.csswg.org/css-transforms-2/#perspective
// https://drafts.csswg.org/css-transforms-2/#funcdef-perspective
// Count is zero when null parameter
if (count == 1) {
// FIXME: Add support for the 'perspective-origin' CSS property.
auto distance = TRY(value(0));
// If the depth value is less than '1px', it must be treated as '1px' for the purpose of rendering, for
// computing the resolved value of 'transform', and when used as the endpoint of interpolation.
// Note: The intent of the above rules on values less than '1px' is that they cover the cases where
// the 'perspective()' function needs to be converted into a matrix.
if (distance < 1)
distance = 1;
return Gfx::FloatMatrix4x4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, -1 / (distance <= 0 ? 1 : distance), 1);
0, 0, -1 / distance, 1);
}
return Gfx::FloatMatrix4x4(1, 0, 0, 0,
0, 1, 0, 0,