Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions third_party/txt/src/txt/paragraph_txt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ std::vector<Paragraph::TextBox> ParagraphTxt::GetRectsForRange(
// Text direction of the first line so we can extend the correct side for
// RectWidthStyle::kMax.
TextDirection first_line_dir = TextDirection::ltr;
std::map<size_t, size_t> newline_x_positions;

// Lines that are actually in the requested range.
size_t max_line = 0;
Expand All @@ -1660,6 +1661,11 @@ std::vector<Paragraph::TextBox> ParagraphTxt::GetRectsForRange(
// Check to see if we are finished.
if (run.code_units.start >= end)
break;

// Update new line x position with the ending of last bidi run on the line
newline_x_positions[run.line_number] =
run.direction == TextDirection::ltr ? run.x_pos.end : run.x_pos.start;

if (run.code_units.end <= start)
continue;

Expand Down Expand Up @@ -1730,11 +1736,12 @@ std::vector<Paragraph::TextBox> ParagraphTxt::GetRectsForRange(
if (line_box_metrics.find(line_number) == line_box_metrics.end()) {
if (line.end_index != line.end_including_newline &&
line.end_index >= start && line.end_including_newline <= end) {
SkScalar x = line_widths_[line_number];
// Move empty box to center if center aligned and is an empty line.
if (x == 0 && !isinf(width_) &&
paragraph_style_.effective_align() == TextAlign::center) {
x = width_ / 2;
SkScalar x;
auto it = newline_x_positions.find(line_number);
if (it != newline_x_positions.end()) {
x = it->second;
} else {
x = GetLineXOffset(0, false);
}
SkScalar top =
(line_number > 0) ? line_metrics_[line_number - 1].height : 0;
Expand Down
Loading