1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibGfx: Take the glyph spacing into account when building a line

Without this, a word might be added to a line despite going outside the
rect, due to the glyph spacing between blocks not being considered.
This commit is contained in:
sin-ack 2021-07-27 21:24:47 +00:00 committed by Andreas Kling
parent 89d5797705
commit 7f1677d574

View file

@ -120,6 +120,7 @@ Vector<String, 32> TextLayout::wrap_lines(TextElision elision, TextWrapping wrap
Vector<String> lines;
StringBuilder builder;
size_t line_width = 0;
size_t current_block = 0;
bool did_not_finish = false;
for (Block& block : blocks) {
switch (block.type) {
@ -133,11 +134,17 @@ Vector<String, 32> TextLayout::wrap_lines(TextElision elision, TextWrapping wrap
goto blocks_processed;
}
current_block++;
continue;
}
case BlockType::Whitespace:
case BlockType::Word: {
size_t block_width = font().width(block.characters);
// FIXME: This should look at the specific advance amount of the
// last character, but we don't support that yet.
if (current_block != blocks.size() - 1) {
block_width += font().glyph_spacing();
}
if (wrapping == TextWrapping::Wrap && line_width + block_width > static_cast<unsigned>(m_rect.width())) {
lines.append(builder.to_string());
@ -152,6 +159,7 @@ Vector<String, 32> TextLayout::wrap_lines(TextElision elision, TextWrapping wrap
builder.append(block.characters.as_string());
line_width += block_width;
current_block++;
}
}
}