Selaa lähdekoodia

LibWeb: Convert `stroke-width` to LengthPercentage

This is a guinea pig. So far so good?
Sam Atkins 3 vuotta sitten
vanhempi
commit
a26cec3805

+ 3 - 3
Userland/Libraries/LibWeb/CSS/ComputedValues.h

@@ -135,7 +135,7 @@ public:
 
     Optional<Color> fill() const { return m_inherited.fill; }
     Optional<Color> stroke() const { return m_inherited.stroke; }
-    Optional<Length> const& stroke_width() const { return m_inherited.stroke_width; }
+    Optional<LengthPercentage> const& stroke_width() const { return m_inherited.stroke_width; }
 
     Vector<CSS::Transformation> transformations() const { return m_noninherited.transformations; }
 
@@ -158,7 +158,7 @@ protected:
 
         Optional<Color> fill;
         Optional<Color> stroke;
-        Optional<Length> stroke_width;
+        Optional<LengthPercentage> stroke_width;
     } m_inherited;
 
     struct {
@@ -256,7 +256,7 @@ public:
 
     void set_fill(Color value) { m_inherited.fill = value; }
     void set_stroke(Color value) { m_inherited.stroke = value; }
-    void set_stroke_width(Length value) { m_inherited.stroke_width = value; }
+    void set_stroke_width(LengthPercentage value) { m_inherited.stroke_width = value; }
 };
 
 }

+ 6 - 2
Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp

@@ -59,8 +59,12 @@ Optional<float> SVGGraphicsElement::stroke_width() const
         return {};
     // FIXME: Converting to pixels isn't really correct - values should be in "user units"
     //        https://svgwg.org/svg2-draft/coords.html#TermUserUnits
-    if (auto width = layout_node()->computed_values().stroke_width(); width.has_value())
-        return width->to_px(*layout_node());
+    if (auto width = layout_node()->computed_values().stroke_width(); width.has_value()) {
+        // Resolved relative to the "Scaled viewport size": https://www.w3.org/TR/2017/WD-fill-stroke-3-20170413/#scaled-viewport-size
+        // FIXME: This isn't right, but it's something.
+        auto scaled_viewport_size = CSS::Length::make_px((client_width() + client_height()) * 0.5f);
+        return width->resolved(scaled_viewport_size).to_px(*layout_node());
+    }
     return {};
 }