LibWeb: Implement gradient offset clamping for color stops

This commit is contained in:
Jelle Raaijmakers 2024-10-28 19:40:02 +01:00 committed by Andreas Kling
commit 4d7da9878d
Notes: github-actions[bot] 2024-10-28 21:54:19 +00:00

View file

@ -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()));
});
}