mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 02:29:21 +00:00
LibWeb: Layout text chunks based on their Unicode direction
Append text chunks to either the start or end of the text fragment, depending on the text direction. The direction is determined by what script its code points are from.
This commit is contained in:
parent
2f5b070716
commit
11e7d72686
Notes:
github-actions[bot]
2024-08-31 09:50:41 +00:00
Author: https://github.com/BenJilks
Commit: 11e7d72686
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1133
Reviewed-by: https://github.com/diegoiast
18 changed files with 460 additions and 150 deletions
|
@ -19,19 +19,14 @@ void LineBox::add_fragment(Node const& layout_node, int start, int length, CSSPi
|
|||
{
|
||||
bool text_align_is_justify = layout_node.computed_values().text_align() == CSS::TextAlign::Justify;
|
||||
if (glyph_run && !text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node && &m_fragments.last().m_glyph_run->font() == &glyph_run->font()) {
|
||||
auto const fragment_width = m_fragments.last().width();
|
||||
// The fragment we're adding is from the last Layout::Node on the line.
|
||||
// Expand the last fragment instead of adding a new one with the same Layout::Node.
|
||||
m_fragments.last().m_length = (start - m_fragments.last().m_start) + length;
|
||||
m_fragments.last().set_width(m_fragments.last().width() + content_width);
|
||||
for (auto& glyph : glyph_run->glyphs()) {
|
||||
glyph.visit([&](auto& glyph) { glyph.position.translate_by(fragment_width.to_float(), 0); });
|
||||
m_fragments.last().m_glyph_run->append(glyph);
|
||||
}
|
||||
m_fragments.last().append_glyph_run(glyph_run, content_width);
|
||||
} else {
|
||||
CSSPixels x_offset = leading_margin + leading_size + m_width;
|
||||
CSSPixels y_offset = 0;
|
||||
m_fragments.append(LineBoxFragment { layout_node, start, length, CSSPixelPoint(x_offset, y_offset), CSSPixelSize(content_width, content_height), border_box_top, move(glyph_run) });
|
||||
m_fragments.append(LineBoxFragment { layout_node, start, length, CSSPixelPoint(x_offset, y_offset), CSSPixelSize(content_width, content_height), border_box_top, m_direction, move(glyph_run) });
|
||||
}
|
||||
m_width += leading_margin + leading_size + content_width + trailing_size + trailing_margin;
|
||||
m_height = max(m_height, content_height + border_box_top + border_box_bottom);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue