瀏覽代碼

LibWeb: Use PaintableFragment::baseline() in paint_text_decoration()

No need to calculate baseline based on glyph height when we can get
this information from a fragment.
Aliaksandr Kalenik 1 年之前
父節點
當前提交
d5e3158cfe

二進制
Tests/LibWeb/Ref/reference/images/text-decorations.png


+ 9 - 0
Tests/LibWeb/Ref/reference/text-decorations-ref.html

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

+ 39 - 0
Tests/LibWeb/Ref/text-decorations.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="match" href="reference/text-decorations-ref.html" />
+<style>
+    .underline {
+        text-decoration: underline;
+        text-decoration-thickness: 2px;
+    }
+
+    .overline {
+        text-decoration: overline;
+        text-decoration-thickness: 2px;
+    }
+
+    .line-through {
+        text-decoration: line-through;
+        text-decoration-thickness: 2px;
+    }
+
+    .underline-overline {
+        text-decoration: underline overline;
+        text-decoration-thickness: 2px;
+    }
+
+    .underline-line-through {
+        text-decoration: underline line-through;
+        text-decoration-thickness: 2px;
+    }
+</style>
+</head>
+<body>
+<p class="underline">Hello</p>
+<p class="overline">Hello</p>
+<p class="line-through">Hello</p>
+<p class="underline-overline">Hello</p>
+<p class="underline-line-through">Hello</p>
+</body>
+</html>

+ 1 - 1
Userland/Libraries/LibWeb/Painting/PaintableBox.cpp

@@ -505,7 +505,7 @@ void paint_text_decoration(PaintContext& context, Layout::Node const& text_node,
     auto& font = fragment.layout_node().first_available_font();
     auto fragment_box = fragment.absolute_rect();
     CSSPixels glyph_height = CSSPixels::nearest_value_for(font.pixel_size());
-    auto baseline = fragment_box.height() / 2 - (glyph_height + 4) / 2 + glyph_height;
+    auto baseline = fragment.baseline();
 
     auto line_color = text_node.computed_values().text_decoration_color();