Ver Fonte

LibWeb: Paint full bitmap font glyphs, even if there's overlap

Since we now honor the CSS font-size values when deciding line box
metrics, we sometimes find ourselves needing to paint text with a bitmap
font into a box that isn't large enough for the glyphs.

As it turns out, it looks a bit better if we just grow the paint rect to
fit the glyphs (instead of painting chopped-off glyphs.) So let's just
do that for now.
Andreas Kling há 3 anos atrás
pai
commit
8daf603f46
1 ficheiros alterados com 8 adições e 3 exclusões
  1. 8 3
      Userland/Libraries/LibWeb/Layout/TextNode.cpp

+ 8 - 3
Userland/Libraries/LibWeb/Layout/TextNode.cpp

@@ -88,10 +88,12 @@ void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& frag
     auto& painter = context.painter();
 
     if (phase == PaintPhase::Foreground) {
+        auto fragment_absolute_rect = fragment.absolute_rect();
+
         painter.set_font(font());
 
         if (document().inspected_node() == &dom_node())
-            context.painter().draw_rect(enclosing_int_rect(fragment.absolute_rect()), Color::Magenta);
+            context.painter().draw_rect(enclosing_int_rect(fragment_absolute_rect), Color::Magenta);
 
         paint_text_decoration(painter, fragment);
 
@@ -103,14 +105,17 @@ void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& frag
         if (text_transform == CSS::TextTransform::Lowercase)
             text = m_text_for_rendering.to_lowercase();
 
-        painter.draw_text(enclosing_int_rect(fragment.absolute_rect()), text.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::CenterLeft, computed_values().color());
+        // FIXME: This is a hack to prevent text clipping when painting a bitmap font into a too-small box.
+        auto draw_rect = enclosing_int_rect(fragment_absolute_rect);
+        draw_rect.set_height(max(draw_rect.height(), font().glyph_height()));
+        painter.draw_text(draw_rect, text.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::CenterLeft, computed_values().color());
 
         auto selection_rect = fragment.selection_rect(font());
         if (!selection_rect.is_empty()) {
             painter.fill_rect(enclosing_int_rect(selection_rect), context.palette().selection());
             Gfx::PainterStateSaver saver(painter);
             painter.add_clip_rect(enclosing_int_rect(selection_rect));
-            painter.draw_text(enclosing_int_rect(fragment.absolute_rect()), text.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::CenterLeft, context.palette().selection_text());
+            painter.draw_text(enclosing_int_rect(fragment_absolute_rect), text.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::CenterLeft, context.palette().selection_text());
         }
 
         paint_cursor_if_needed(context, fragment);