1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

LibWeb/SVG: Support url() in the stroke attribute

This allows you to draw gradients in strokes, for example.
This commit is contained in:
Luke Wilde 2023-06-06 20:40:10 +01:00 committed by Andreas Kling
parent 8993a710f8
commit 42a183720b
8 changed files with 51 additions and 12 deletions

View file

@ -40,15 +40,12 @@ void SVGGraphicsElement::parse_attribute(DeprecatedFlyString const& name, Deprec
}
}
Optional<Gfx::PaintStyle const&> SVGGraphicsElement::fill_paint_style(SVGPaintContext const& paint_context) const
Optional<Gfx::PaintStyle const&> SVGGraphicsElement::svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const
{
// FIXME: This entire function is an ad-hoc hack:
if (!layout_node())
if (!paint_value.has_value() || !paint_value->is_url())
return {};
auto& fill = layout_node()->computed_values().fill();
if (!fill.has_value() || !fill->is_url())
return {};
auto& url = fill->as_url();
auto& url = paint_value->as_url();
auto gradient = document().get_element_by_id(url.fragment());
if (!gradient)
return {};
@ -57,6 +54,20 @@ Optional<Gfx::PaintStyle const&> SVGGraphicsElement::fill_paint_style(SVGPaintCo
return {};
}
Optional<Gfx::PaintStyle const&> SVGGraphicsElement::fill_paint_style(SVGPaintContext const& paint_context) const
{
if (!layout_node())
return {};
return svg_paint_computed_value_to_gfx_paint_style(paint_context, layout_node()->computed_values().fill());
}
Optional<Gfx::PaintStyle const&> SVGGraphicsElement::stroke_paint_style(SVGPaintContext const& paint_context) const
{
if (!layout_node())
return {};
return svg_paint_computed_value_to_gfx_paint_style(paint_context, layout_node()->computed_values().stroke());
}
Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list)
{
Gfx::AffineTransform affine_transform;

View file

@ -43,12 +43,15 @@ public:
Gfx::AffineTransform get_transform() const;
Optional<Gfx::PaintStyle const&> fill_paint_style(SVGPaintContext const&) const;
Optional<Gfx::PaintStyle const&> stroke_paint_style(SVGPaintContext const&) const;
protected:
SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
Optional<Gfx::PaintStyle const&> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
Gfx::AffineTransform m_transform = {};
};