From 66925a3d80ad4f822876b097900ce98536e807b0 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 28 Oct 2024 19:38:53 +0100 Subject: [PATCH] LibWeb: Misc. SVG improvements No functional changes: added spec comments, moved some code, removed an unused member. --- Userland/Libraries/LibWeb/Painting/SVGPathPaintable.cpp | 6 ++---- Userland/Libraries/LibWeb/SVG/SVGGradientElement.h | 2 ++ Userland/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp | 5 +++-- Userland/Libraries/LibWeb/SVG/SVGStopElement.h | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/SVGPathPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGPathPaintable.cpp index debc3390edf..cdee8fe5b03 100644 --- a/Userland/Libraries/LibWeb/Painting/SVGPathPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/SVGPathPaintable.cpp @@ -83,13 +83,10 @@ void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const return copy; }; - // Note: This is assuming .x_scale() == .y_scale() (which it does currently). - auto viewbox_scale = paint_transform.x_scale(); - auto svg_viewport = [&] { 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 { { 0, 0 }, svg_element_rect.size().to_type() }; + return Gfx::FloatRect { {}, svg_element_rect.size().to_type() }; }(); 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); // 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; if (auto paint_style = graphics_element.stroke_paint_style(paint_context); paint_style.has_value()) { diff --git a/Userland/Libraries/LibWeb/SVG/SVGGradientElement.h b/Userland/Libraries/LibWeb/SVG/SVGGradientElement.h index 3f50eda40fd..bbc05d9421a 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGradientElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGGradientElement.h @@ -93,7 +93,9 @@ private: SpreadMethod spread_method_impl(HashTable& seen_gradients) const; Optional gradient_transform_impl(HashTable& seen_gradients) const; + // https://svgwg.org/svg2-draft/pservers.html#LinearGradientAttributes Optional m_gradient_units = {}; + Optional m_spread_method = {}; Optional m_gradient_transform = {}; }; diff --git a/Userland/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp index 34be130cb2f..7389059e33f 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp @@ -118,6 +118,7 @@ Optional SVGLinearGradientElement::to_gfx_paint_style(SVGP // FIXME: Resolve percentages properly Gfx::FloatPoint start_point {}; Gfx::FloatPoint end_point {}; + // https://svgwg.org/svg2-draft/pservers.html#LinearGradientElementGradientUnitsAttribute if (units == GradientUnits::ObjectBoundingBox) { // If gradientUnits="objectBoundingBox", the user coordinate system for attributes ‘x1’, ‘y1’, ‘x2’ and ‘y2’ @@ -134,11 +135,11 @@ Optional SVGLinearGradientElement::to_gfx_paint_style(SVGP // 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’. // 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_y().resolve_relative_to(paint_context.viewport.height()), }; - end_point = Gfx::FloatPoint { + end_point = { end_x().resolve_relative_to(paint_context.viewport.width()), end_y().resolve_relative_to(paint_context.viewport.height()), }; diff --git a/Userland/Libraries/LibWeb/SVG/SVGStopElement.h b/Userland/Libraries/LibWeb/SVG/SVGStopElement.h index 11fd7510a97..b7a1d4cafc8 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGStopElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGStopElement.h @@ -13,6 +13,7 @@ namespace Web::SVG { +// https://svgwg.org/svg2-draft/pservers.html#GradientStops class SVGStopElement final : public SVGElement { WEB_PLATFORM_OBJECT(SVGStopElement, SVGElement); JS_DECLARE_ALLOCATOR(SVGStopElement); @@ -36,7 +37,6 @@ private: virtual void initialize(JS::Realm&) override; Optional m_offset; - Optional m_color; }; }