Browse Source

LibWeb: Do not floor SVG offset in SVGPathPaintable

Resolves a FIXME and improves the visuals of https://tweakers.net :^)
Jelle Raaijmakers 9 months ago
parent
commit
e4533e5595

BIN
Tests/LibWeb/Screenshot/images/svg-path-offset-rounding-ref.png


+ 9 - 0
Tests/LibWeb/Screenshot/reference/svg-path-offset-rounding-ref.html

@@ -0,0 +1,9 @@
+<style>
+    * {
+        margin: 0;
+    }
+    body {
+        background-color: white;
+    }
+</style>
+<img src="../images/svg-path-offset-rounding-ref.png">

+ 16 - 0
Tests/LibWeb/Screenshot/svg-path-offset-rounding.html

@@ -0,0 +1,16 @@
+<!doctype html>
+<link rel="match" href="reference/svg-path-offset-rounding-ref.html" />
+<style>
+    body {
+        padding-left: 10.6px;
+    }
+</style>
+<body>
+    <svg width="34" height="22" viewBox="0 0 34 22">
+        <path
+                d="M -0.2 0 L 34 0 L 34 22 L -0.2 22 Z"
+                fill="none"
+                stroke="#000000"
+        ></path>
+    </svg>
+</body>

+ 1 - 2
Userland/Libraries/LibWeb/Painting/SVGPathPaintable.cpp

@@ -65,10 +65,9 @@ void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const
     auto const* svg_node = layout_box().first_ancestor_of_type<Layout::SVGSVGBox>();
     auto svg_element_rect = svg_node->paintable_box()->absolute_rect();
 
-    // FIXME: This should not be trucated to an int.
     DisplayListRecorderStateSaver save_painter { context.display_list_recorder() };
 
-    auto offset = context.floored_device_point(svg_element_rect.location()).to_type<int>().to_type<float>();
+    auto offset = context.rounded_device_point(svg_element_rect.location()).to_type<int>().to_type<float>();
     auto maybe_view_box = svg_node->dom_node().view_box();
 
     auto paint_transform = computed_transforms().svg_to_device_pixels_transform(context);