mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:18:12 +00:00
LibWeb: Move some common SVG gradient functions into SVGGradientElement
These functions will also be used by SVG radial gradients.
This commit is contained in:
parent
eda429111e
commit
2826bd2b45
3 changed files with 38 additions and 19 deletions
|
@ -49,6 +49,35 @@ Optional<Gfx::AffineTransform> SVGGradientElement::gradient_transform() const
|
|||
return {};
|
||||
}
|
||||
|
||||
// The gradient transform, appropriately scaled and combined with the paint transform.
|
||||
Gfx::AffineTransform SVGGradientElement::gradient_paint_transform(SVGPaintContext const& paint_context) const
|
||||
{
|
||||
auto transform = gradient_transform().value_or(Gfx::AffineTransform {});
|
||||
if (gradient_units() == GradientUnits::ObjectBoundingBox) {
|
||||
// Adjust transform to take place in the coordinate system defined by the bounding box:
|
||||
return Gfx::AffineTransform { paint_context.transform }
|
||||
.translate(paint_context.path_bounding_box.location())
|
||||
.scale(paint_context.path_bounding_box.width(), paint_context.path_bounding_box.height())
|
||||
.multiply(transform);
|
||||
}
|
||||
return Gfx::AffineTransform { paint_context.transform }.multiply(transform);
|
||||
}
|
||||
|
||||
void SVGGradientElement::add_color_stops(Gfx::SVGGradientPaintStyle& paint_style) const
|
||||
{
|
||||
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
|
||||
// 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.
|
||||
paint_style.add_color_stop(stop_offset, stop.stop_color()).release_value_but_fixme_should_propagate_errors();
|
||||
});
|
||||
}
|
||||
|
||||
JS::GCPtr<SVGGradientElement const> SVGGradientElement::xlink_href() const
|
||||
{
|
||||
// FIXME: This entire function is an ad-hoc hack!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue