Skip to content

Commit b6bb7e7

Browse files
author
Ali Mahdiyar
authored
Handle paragraph alignment and direction in newline rectangles (flutter#17750)
1 parent fa8b9a5 commit b6bb7e7

2 files changed

Lines changed: 521 additions & 6 deletions

File tree

third_party/txt/src/txt/paragraph_txt.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,7 @@ std::vector<Paragraph::TextBox> ParagraphTxt::GetRectsForRange(
16491649
// Text direction of the first line so we can extend the correct side for
16501650
// RectWidthStyle::kMax.
16511651
TextDirection first_line_dir = TextDirection::ltr;
1652+
std::map<size_t, size_t> newline_x_positions;
16521653

16531654
// Lines that are actually in the requested range.
16541655
size_t max_line = 0;
@@ -1660,6 +1661,11 @@ std::vector<Paragraph::TextBox> ParagraphTxt::GetRectsForRange(
16601661
// Check to see if we are finished.
16611662
if (run.code_units.start >= end)
16621663
break;
1664+
1665+
// Update new line x position with the ending of last bidi run on the line
1666+
newline_x_positions[run.line_number] =
1667+
run.direction == TextDirection::ltr ? run.x_pos.end : run.x_pos.start;
1668+
16631669
if (run.code_units.end <= start)
16641670
continue;
16651671

@@ -1730,11 +1736,12 @@ std::vector<Paragraph::TextBox> ParagraphTxt::GetRectsForRange(
17301736
if (line_box_metrics.find(line_number) == line_box_metrics.end()) {
17311737
if (line.end_index != line.end_including_newline &&
17321738
line.end_index >= start && line.end_including_newline <= end) {
1733-
SkScalar x = line_widths_[line_number];
1734-
// Move empty box to center if center aligned and is an empty line.
1735-
if (x == 0 && !isinf(width_) &&
1736-
paragraph_style_.effective_align() == TextAlign::center) {
1737-
x = width_ / 2;
1739+
SkScalar x;
1740+
auto it = newline_x_positions.find(line_number);
1741+
if (it != newline_x_positions.end()) {
1742+
x = it->second;
1743+
} else {
1744+
x = GetLineXOffset(0, false);
17381745
}
17391746
SkScalar top =
17401747
(line_number > 0) ? line_metrics_[line_number - 1].height : 0;

0 commit comments

Comments
 (0)