1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

LibWeb: Don't add an extra glyph spacing to width of TextNode

When calculating the width of text using a bitmap font, a glyph spacing
is added at the end of each fragment, including the last one. This meant
that everything was 1 pixel too long. This bug did not affect vector
fonts.
This commit is contained in:
circl 2023-10-28 15:39:57 +02:00 committed by Andreas Kling
parent 2660bbb94f
commit 6b30847120
3 changed files with 25 additions and 1 deletions

View file

@ -180,7 +180,6 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
m_text_node_context->is_last_chunk = true;
auto& chunk = chunk_opt.value();
CSSPixels chunk_width = CSSPixels::nearest_value_for(text_node.font().width(chunk.view) + text_node.font().glyph_spacing());
if (m_text_node_context->do_respect_linebreaks && chunk.has_breaking_newline) {
return Item {
@ -188,6 +187,13 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
};
}
CSSPixels chunk_width;
if (m_text_node_context->is_last_chunk)
chunk_width = CSSPixels::nearest_value_for(text_node.font().width(chunk.view));
else
chunk_width = CSSPixels::nearest_value_for(text_node.font().width(chunk.view) + text_node.font().glyph_spacing());
// NOTE: We never consider `content: ""` to be collapsible whitespace.
bool is_generated_empty_string = text_node.is_generated() && chunk.length == 0;