diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-03-24 15:20:25 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-24 18:08:34 +0100 |
commit | 5aad32b5042ebd3fedc8f0d0dc5871d78a7ac6c5 (patch) | |
tree | 9fd3d1b8439c04db3b1d124ce1dae5a8dbfba1bd /Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | |
parent | 03daa4653fcc336262e6592fd2080cbfc437490b (diff) | |
download | serenity-5aad32b5042ebd3fedc8f0d0dc5871d78a7ac6c5.zip |
LibWeb: Implement text-shadow painting
We don't yet take the spread-distance parameter into account, since we
don't have a way to "inflate" the text shadow.
Also, I'm not sure if we need to inflate the shadow slightly anyway.
Blurred shadows of our pixel fonts seem very faint. Part of this is
that a blur of < 3px does nothing, see #13231, but even so we might
want to inflate it a little.
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting/PaintableBox.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index a11a555bd3..b89eeb1b65 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -407,6 +407,35 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const context.painter().translate(-scroll_offset.to_type<int>()); } + // Text shadows + // This is yet another loop, but done here because all shadows should appear under all text. + // So, we paint the shadows before painting any text. + // FIXME: Find a smarter way to do this? + if (phase == PaintPhase::Foreground) { + for (auto& line_box : m_line_boxes) { + for (auto& fragment : line_box.fragments()) { + if (is<Layout::TextNode>(fragment.layout_node())) { + auto& text_shadow = fragment.layout_node().computed_values().text_shadow(); + if (!text_shadow.is_empty()) { + Vector<ShadowData> resolved_shadow_data; + resolved_shadow_data.ensure_capacity(text_shadow.size()); + for (auto const& layer : text_shadow) { + resolved_shadow_data.empend( + layer.color, + static_cast<int>(layer.offset_x.to_px(layout_box())), + static_cast<int>(layer.offset_y.to_px(layout_box())), + static_cast<int>(layer.blur_radius.to_px(layout_box())), + static_cast<int>(layer.spread_distance.to_px(layout_box())), + ShadowPlacement::Outer); + } + context.painter().set_font(fragment.layout_node().font()); + Painting::paint_text_shadow(context, fragment, resolved_shadow_data); + } + } + } + } + } + for (auto& line_box : m_line_boxes) { for (auto& fragment : line_box.fragments()) { if (context.should_show_line_box_borders()) |