1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:57:45 +00:00

LibWeb: Use the new Gfx::Painter::draw_text_run() API for drawing text

This avoids a bunch of unnecessary work in Painter which not only took
time, but sometimes also led to alignment issues. draw_text_run() will
draw the text where we tell it, and that's it.
This commit is contained in:
Andreas Kling 2022-03-28 21:05:51 +02:00
parent dd940dfa85
commit 1c88536298
4 changed files with 16 additions and 9 deletions

View file

@ -43,6 +43,10 @@ public:
const Gfx::FloatPoint& offset() const { return m_offset; }
void set_offset(const Gfx::FloatPoint& offset) { m_offset = offset; }
// The baseline of a fragment is the number of pixels from the top to the text baseline.
void set_baseline(float y) { m_baseline = y; }
float baseline() const { return m_baseline; }
const Gfx::FloatSize& size() const { return m_size; }
void set_width(float width) { m_size.set_width(width); }
void set_height(float height) { m_size.set_height(height); }
@ -75,6 +79,7 @@ private:
Gfx::FloatSize m_size;
float m_border_box_top { 0 };
float m_border_box_bottom { 0 };
float m_baseline { 0 };
Type m_type { Type::Normal };
};

View file

@ -159,7 +159,7 @@ void LineBuilder::update_last_line()
auto line_box_baseline = [&] {
float line_box_baseline = 0;
for (auto const& fragment : line_box.fragments()) {
for (auto& fragment : line_box.fragments()) {
auto baseline = fragment_baseline(fragment);
if (fragment.height() < m_context.containing_block().line_height())
baseline += (m_context.containing_block().line_height() - fragment.height()) / 2;
@ -168,6 +168,9 @@ void LineBuilder::update_last_line()
if (auto length_percentage = fragment.layout_node().computed_values().vertical_align().template get_pointer<CSS::LengthPercentage>(); length_percentage && length_percentage->is_length())
baseline += length_percentage->length().to_px(fragment.layout_node());
// Store the baseline on the fragment. This is used when painting.
fragment.set_baseline(baseline);
line_box_baseline = max(line_box_baseline, baseline);
}
return line_box_baseline;