LibWeb: Misc. SVG improvements

No functional changes: added spec comments, moved some code, removed an
unused member.
This commit is contained in:
Jelle Raaijmakers 2024-10-28 19:38:53 +01:00 committed by Andreas Kling
commit 66925a3d80
Notes: github-actions[bot] 2024-10-28 21:54:26 +00:00
4 changed files with 8 additions and 7 deletions

View file

@ -83,13 +83,10 @@ void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const
return copy; return copy;
}; };
// Note: This is assuming .x_scale() == .y_scale() (which it does currently).
auto viewbox_scale = paint_transform.x_scale();
auto svg_viewport = [&] { auto svg_viewport = [&] {
if (maybe_view_box.has_value()) if (maybe_view_box.has_value())
return Gfx::FloatRect { maybe_view_box->min_x, maybe_view_box->min_y, maybe_view_box->width, maybe_view_box->height }; return Gfx::FloatRect { maybe_view_box->min_x, maybe_view_box->min_y, maybe_view_box->width, maybe_view_box->height };
return Gfx::FloatRect { { 0, 0 }, svg_element_rect.size().to_type<float>() }; return Gfx::FloatRect { {}, svg_element_rect.size().to_type<float>() };
}(); }();
if (context.draw_svg_geometry_for_clip_path()) { if (context.draw_svg_geometry_for_clip_path()) {
@ -137,6 +134,7 @@ void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const
auto stroke_opacity = graphics_element.stroke_opacity().value_or(1); auto stroke_opacity = graphics_element.stroke_opacity().value_or(1);
// Note: This is assuming .x_scale() == .y_scale() (which it does currently). // Note: This is assuming .x_scale() == .y_scale() (which it does currently).
auto viewbox_scale = paint_transform.x_scale();
float stroke_thickness = graphics_element.stroke_width().value_or(1) * viewbox_scale; float stroke_thickness = graphics_element.stroke_width().value_or(1) * viewbox_scale;
if (auto paint_style = graphics_element.stroke_paint_style(paint_context); paint_style.has_value()) { if (auto paint_style = graphics_element.stroke_paint_style(paint_context); paint_style.has_value()) {

View file

@ -93,7 +93,9 @@ private:
SpreadMethod spread_method_impl(HashTable<SVGGradientElement const*>& seen_gradients) const; SpreadMethod spread_method_impl(HashTable<SVGGradientElement const*>& seen_gradients) const;
Optional<Gfx::AffineTransform> gradient_transform_impl(HashTable<SVGGradientElement const*>& seen_gradients) const; Optional<Gfx::AffineTransform> gradient_transform_impl(HashTable<SVGGradientElement const*>& seen_gradients) const;
// https://svgwg.org/svg2-draft/pservers.html#LinearGradientAttributes
Optional<GradientUnits> m_gradient_units = {}; Optional<GradientUnits> m_gradient_units = {};
Optional<SpreadMethod> m_spread_method = {}; Optional<SpreadMethod> m_spread_method = {};
Optional<Gfx::AffineTransform> m_gradient_transform = {}; Optional<Gfx::AffineTransform> m_gradient_transform = {};
}; };

View file

@ -118,6 +118,7 @@ Optional<Painting::PaintStyle> SVGLinearGradientElement::to_gfx_paint_style(SVGP
// FIXME: Resolve percentages properly // FIXME: Resolve percentages properly
Gfx::FloatPoint start_point {}; Gfx::FloatPoint start_point {};
Gfx::FloatPoint end_point {}; Gfx::FloatPoint end_point {};
// https://svgwg.org/svg2-draft/pservers.html#LinearGradientElementGradientUnitsAttribute // https://svgwg.org/svg2-draft/pservers.html#LinearGradientElementGradientUnitsAttribute
if (units == GradientUnits::ObjectBoundingBox) { if (units == GradientUnits::ObjectBoundingBox) {
// If gradientUnits="objectBoundingBox", the user coordinate system for attributes x1, y1, x2 and y2 // If gradientUnits="objectBoundingBox", the user coordinate system for attributes x1, y1, x2 and y2
@ -134,11 +135,11 @@ Optional<Painting::PaintStyle> SVGLinearGradientElement::to_gfx_paint_style(SVGP
// is referenced (i.e., the user coordinate system for the element referencing the gradient element via a // is referenced (i.e., the user coordinate system for the element referencing the gradient element via a
// fill or stroke property) and then applying the transform specified by attribute gradientTransform. // fill or stroke property) and then applying the transform specified by attribute gradientTransform.
// Percentages represent values relative to the current SVG viewport. // Percentages represent values relative to the current SVG viewport.
start_point = Gfx::FloatPoint { start_point = {
start_x().resolve_relative_to(paint_context.viewport.width()), start_x().resolve_relative_to(paint_context.viewport.width()),
start_y().resolve_relative_to(paint_context.viewport.height()), start_y().resolve_relative_to(paint_context.viewport.height()),
}; };
end_point = Gfx::FloatPoint { end_point = {
end_x().resolve_relative_to(paint_context.viewport.width()), end_x().resolve_relative_to(paint_context.viewport.width()),
end_y().resolve_relative_to(paint_context.viewport.height()), end_y().resolve_relative_to(paint_context.viewport.height()),
}; };

View file

@ -13,6 +13,7 @@
namespace Web::SVG { namespace Web::SVG {
// https://svgwg.org/svg2-draft/pservers.html#GradientStops
class SVGStopElement final : public SVGElement { class SVGStopElement final : public SVGElement {
WEB_PLATFORM_OBJECT(SVGStopElement, SVGElement); WEB_PLATFORM_OBJECT(SVGStopElement, SVGElement);
JS_DECLARE_ALLOCATOR(SVGStopElement); JS_DECLARE_ALLOCATOR(SVGStopElement);
@ -36,7 +37,6 @@ private:
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
Optional<NumberPercentage> m_offset; Optional<NumberPercentage> m_offset;
Optional<Gfx::Color> m_color;
}; };
} }