From 4d7da9878d667d0ecb183617a900f69d2a7f9c74 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 28 Oct 2024 19:40:02 +0100 Subject: [PATCH] LibWeb: Implement gradient offset clamping for color stops --- Userland/Libraries/LibWeb/SVG/SVGGradientElement.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/SVG/SVGGradientElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGradientElement.cpp index a857f997eb2..9b1186fef9d 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGradientElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGGradientElement.cpp @@ -96,15 +96,20 @@ Gfx::AffineTransform SVGGradientElement::gradient_paint_transform(SVGPaintContex void SVGGradientElement::add_color_stops(Painting::SVGGradientPaintStyle& paint_style) const { + auto largest_offset = 0.0f; for_each_color_stop([&](auto& stop) { // https://svgwg.org/svg2-draft/pservers.html#StopNotes // Gradient offset values less than 0 (or less than 0%) are rounded up to 0%. // Gradient offset values greater than 1 (or greater than 100%) are rounded down to 100%. float stop_offset = AK::clamp(stop.stop_offset().value(), 0.0f, 1.0f); - // FIXME: Each gradient offset value is required to be equal to or greater than the previous gradient + + // Each gradient offset value is required to be equal to or greater than the previous gradient // stop's offset value. If a given gradient stop's offset value is not equal to or greater than all // previous offset values, then the offset value is adjusted to be equal to the largest of all previous // offset values. + stop_offset = AK::max(stop_offset, largest_offset); + largest_offset = stop_offset; + paint_style.add_color_stop(stop_offset, stop.stop_color().with_opacity(stop.stop_opacity())); }); }