ソースを参照

LibWeb: Add .scaled_font() helper to Layout::Node

This returns the font scaled for the current zoom level.
MacDue 2 年 前
コミット
7061a3d8e6

+ 8 - 0
Userland/Libraries/LibWeb/Layout/Node.h

@@ -14,6 +14,7 @@
 #include <LibJS/Heap/Handle.h>
 #include <LibJS/Heap/Handle.h>
 #include <LibWeb/CSS/ComputedValues.h>
 #include <LibWeb/CSS/ComputedValues.h>
 #include <LibWeb/CSS/StyleProperties.h>
 #include <LibWeb/CSS/StyleProperties.h>
+#include <LibWeb/FontCache.h>
 #include <LibWeb/Forward.h>
 #include <LibWeb/Forward.h>
 #include <LibWeb/Layout/BoxModelMetrics.h>
 #include <LibWeb/Layout/BoxModelMetrics.h>
 #include <LibWeb/Painting/PaintContext.h>
 #include <LibWeb/Painting/PaintContext.h>
@@ -117,6 +118,8 @@ public:
     bool can_contain_boxes_with_position_absolute() const;
     bool can_contain_boxes_with_position_absolute() const;
 
 
     Gfx::Font const& font() const;
     Gfx::Font const& font() const;
+    Gfx::Font const& scaled_font(PaintContext&) const;
+
     CSS::ImmutableComputedValues const& computed_values() const;
     CSS::ImmutableComputedValues const& computed_values() const;
     CSSPixels line_height() const;
     CSSPixels line_height() const;
 
 
@@ -237,6 +240,11 @@ inline Gfx::Font const& Node::font() const
     return parent()->font();
     return parent()->font();
 }
 }
 
 
+inline Gfx::Font const& Node::scaled_font(PaintContext& context) const
+{
+    return *FontCache::the().scaled_font(font(), context.device_pixels_per_css_pixel());
+}
+
 inline const CSS::ImmutableComputedValues& Node::computed_values() const
 inline const CSS::ImmutableComputedValues& Node::computed_values() const
 {
 {
     if (m_has_style)
     if (m_has_style)

+ 3 - 4
Userland/Libraries/LibWeb/Painting/PaintableBox.cpp

@@ -8,7 +8,6 @@
 #include <AK/GenericShorthands.h>
 #include <AK/GenericShorthands.h>
 #include <LibUnicode/CharacterTypes.h>
 #include <LibUnicode/CharacterTypes.h>
 #include <LibWeb/DOM/Document.h>
 #include <LibWeb/DOM/Document.h>
-#include <LibWeb/FontCache.h>
 #include <LibWeb/HTML/HTMLHtmlElement.h>
 #include <LibWeb/HTML/HTMLHtmlElement.h>
 #include <LibWeb/Layout/BlockContainer.h>
 #include <LibWeb/Layout/BlockContainer.h>
 #include <LibWeb/Layout/Viewport.h>
 #include <LibWeb/Layout/Viewport.h>
@@ -525,16 +524,16 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t
         DevicePixelPoint baseline_start { fragment_absolute_device_rect.x(), fragment_absolute_device_rect.y() + context.rounded_device_pixels(fragment.baseline()) };
         DevicePixelPoint baseline_start { fragment_absolute_device_rect.x(), fragment_absolute_device_rect.y() + context.rounded_device_pixels(fragment.baseline()) };
         Utf8View view { text.substring_view(fragment.start(), fragment.length()) };
         Utf8View view { text.substring_view(fragment.start(), fragment.length()) };
 
 
-        auto scaled_font = FontCache::the().scaled_font(fragment.layout_node().font(), context.device_pixels_per_css_pixel());
+        auto& scaled_font = fragment.layout_node().scaled_font(context);
 
 
-        painter.draw_text_run(baseline_start.to_type<int>(), view, *scaled_font, text_node.computed_values().color());
+        painter.draw_text_run(baseline_start.to_type<int>(), view, scaled_font, text_node.computed_values().color());
 
 
         auto selection_rect = context.enclosing_device_rect(fragment.selection_rect(text_node.font())).to_type<int>();
         auto selection_rect = context.enclosing_device_rect(fragment.selection_rect(text_node.font())).to_type<int>();
         if (!selection_rect.is_empty()) {
         if (!selection_rect.is_empty()) {
             painter.fill_rect(selection_rect, context.palette().selection());
             painter.fill_rect(selection_rect, context.palette().selection());
             Gfx::PainterStateSaver saver(painter);
             Gfx::PainterStateSaver saver(painter);
             painter.add_clip_rect(selection_rect);
             painter.add_clip_rect(selection_rect);
-            painter.draw_text_run(baseline_start.to_type<int>(), view, *scaled_font, context.palette().selection_text());
+            painter.draw_text_run(baseline_start.to_type<int>(), view, scaled_font, context.palette().selection_text());
         }
         }
 
 
         paint_text_decoration(context, painter, text_node, fragment);
         paint_text_decoration(context, painter, text_node, fragment);