mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-01 21:59:11 +00:00
LibWeb: Implement gradient offset clamping for color stops
This commit is contained in:
parent
66925a3d80
commit
4d7da9878d
Notes:
github-actions[bot]
2024-10-28 21:54:19 +00:00
Author: https://github.com/gmta
Commit: 4d7da9878d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2026
Reviewed-by: https://github.com/kalenikaliaksandr ✅
1 changed files with 6 additions and 1 deletions
|
@ -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()));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue