8000 Revert f6359e4111d37652409e2392fdb3cb72f1119c2a (#5233) · flutter/engine@9ae10ef · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9ae10ef

Browse files
authored
Revert f6359e4 (#5233)
In introduced a regression in text layout: flutter/flutter#17502
1 parent b856303 commit 9ae10ef

File tree

6 files changed

+25
-53
lines changed

6 files changed

+25
-53
lines changed

third_party/txt/src/minikin/LineBreaker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void LineBreaker::setIndents(const std::vector<float>& indents) {
107107
// end of line. It is the Unicode set:
108108
// [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]], plus '\n'. Note:
109109
// all such characters are in the BMP, so it's ok to use code units for this.
110-
bool isLineEndSpace(uint16_t c) {
110+
static bool isLineEndSpace(uint16_t c) {
111111
return c == '\n' || c == ' ' || c == 0x1680 ||
112112
(0x2000 <= c && c <= 0x200A && c != 0x2007) || c == 0x205F ||
113113
c == 0x3000;

third_party/txt/src/minikin/LineBreaker.h

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ enum HyphenationFrequency {
4949
kHyphenationFrequency_Full = 2
5050
};
5151

52-
bool isLineEndSpace(uint16_t c);
53-
5452
// TODO: want to generalize to be able to handle array of line widths
5553
class LineWidths {
5654
public:

third_party/txt/src/txt/paragraph.cc

+21-27
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ bool Paragraph::ComputeLineBreaks() {
258258
size_t block_size = block_end - block_start;
259259

260260
if (block_size == 0) {
261-
line_ranges_.emplace_back(block_start, block_end, block_end,
262-
block_end + 1, true);
261+
line_ranges_.emplace_back(block_start, block_end, block_end + 1, true);
263262
line_widths_.push_back(0);
264263
continue;
265264
}
@@ -312,14 +311,7 @@ bool Paragraph::ComputeLineBreaks() {
312311
bool hard_break = i == breaks_count - 1;
313312
size_t line_end_including_newline =
314313
(hard_break && line_end < text_.size()) ? line_end + 1 : line_end;
315-
size_t line_end_excluding_whitespace = line_end;
316-
while (
317-
line_end_excluding_whitespace > 0 &&
318-
minikin::isLineEndSpace(text_[line_end_excluding_whitespace - 1])) {
319-
line_end_excluding_whitespace--;
320-
}
321314
line_ranges_.emplace_back(line_start, line_end,
322-
line_end_excluding_whitespace,
323315
line_end_including_newline, hard_break);
324316
line_widths_.push_back(breaker_.getWidths()[i]);
325317
}
@@ -470,20 +462,13 @@ void Paragraph::Layout(double width, bool force) {
470462
}
471463
}
472464

473-
// Exclude trailing whitespace from right-justified lines so the last
474-
// visible character in the line will be flush with the right margin.
475-
size_t line_end_index =
476-
(paragraph_style_.effective_align() == TextAlign::right)
477-
? line_range.end_excluding_whitespace
478-
: line_range.end;
479-
480465
// Find the runs comprising this line.
481466
std::vector<BidiRun> line_runs;
482467
for (const BidiRun& bidi_run : bidi_runs) {
483-
if (bidi_run.start() < line_end_index &&
468+
if (bidi_run.start() < line_range.end &&
484469
bidi_run.end() > line_range.start) {
485470
line_runs.emplace_back(std::max(bidi_run.start(), line_range.start),
486-
std::min(bidi_run.end(), line_end_index),
471+
std::min(bidi_run.end(), line_range.end),
487472
bidi_run.direction(), bidi_run.style());
488473
}
489474
}
@@ -702,7 +687,7 @@ void Paragraph::Layout(double width, bool force) {
702687
}
703688

704689
// Adjust the glyph positions based on the alignment of the line.
705-
double line_x_offset = GetLineXOffset(run_x_offset);
690+
double line_x_offset = GetLineXOffset(line_number, run_x_offset);
706691
if (line_x_offset) {
707692
for (CodeUnitRun& code_unit_run : line_code_unit_runs) {
708693
for (GlyphPosition& position : code_unit_run.positions) {
@@ -795,16 +780,25 @@ void Paragraph::Layout(double width, bool force) {
795780
});
796781
}
797782

798-
double Paragraph::GetLineXOffset(double line_total_advance) {
799-
if (isinf(width_))
783+
double Paragraph::GetLineXOffset(size_t line_number,
784+
double line_total_advance) {
785+
if (line_number >= line_widths_.size() || isinf(width_))
800786
return 0;
801787

802-
TextAlign align = paragraph_style_.effective_align();
803-
804-
if (align == TextAlign::right) {
805-
return width_ - line_total_advance;
806-
} else if (align == TextAlign::center) {
807-
return (width_ - line_total_advance) / 2;
788+
TextAlign align = paragraph_style_.text_align;
789+
TextDirection direction = paragraph_style_.text_direction;
790+
791+
if (align == TextAlign::right ||
792+
(align == TextAlign::start && direction == TextDirection::rtl) ||
793+
(align == TextAlign::end && direction == TextDirection::ltr)) {
794+
// If this line has a soft break, then use the line width calculated by the
795+
// line breaker because that width excludes the soft break's whitespace.
796+
double text_width = line_ranges_[line_number].hard_break
797+
? line_total_advance
798+
: line_widths_[line_number];
799+
return width_ - text_width;
800+
} else if (paragraph_style_.text_align == TextAlign::center) {
801+
return (width_ - line_widths_[line_number]) / 2;
808802
} else {
809803
return 0;
810804
}

third_party/txt/src/txt/paragraph.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,9 @@ class Paragraph {
187187
mutable std::unique_ptr<icu::BreakIterator> word_breaker_;
188188

189189
struct LineRange {
190-
LineRange(size_t s, size_t e, size_t eew, size_t ein, bool h)
191-
: start(s),
192-
end(e),
193-
end_excluding_whitespace(eew),
194-
end_including_newline(ein),
195-
hard_break(h) {}
190+
LineRange(size_t s, size_t e, size_t ewn, bool h)
191+
: start(s), end(e), end_including_newline(ewn), hard_break(h) {}
196192
size_t start, end;
197-
size_t end_excluding_whitespace;
198193
size_t end_including_newline;
199194
bool hard_break;
200195
};
@@ -305,7 +300,7 @@ class Paragraph {
305300

306301
// Calculate the starting X offset of a line based on the line's width and
307302
// alignment.
308-
double GetLineXOffset(double line_total_advance);
303+
double GetLineXOffset(size_t line_number, double line_total_advance);
309304

310305
// Creates and draws the decorations onto the canvas.
311306
void PaintDecorations(SkCanvas* canvas, const PaintRecord& record);

third_party/txt/src/txt/paragraph_style.cc

-12
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,4 @@ bool ParagraphStyle::ellipsized() const {
3737
return !ellipsis.empty();
3838
}
3939

40-
TextAlign ParagraphStyle::effective_align() const {
41-
if (text_align == TextAlign::start) {
42-
return (text_direction == TextDirection::ltr) ? TextAlign::left
43-
: TextAlign::righ CE91 t;
44-
} else if (text_align == TextAlign::end) {
45-
return (text_direction == TextDirection::ltr) ? TextAlign::right
46-
: TextAlign::left;
47-
} else {
48-
return text_align;
49-
}
50-
}
51-
5240
} // namespace txt

third_party/txt/src/txt/paragraph_style.h

-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class ParagraphStyle {
6666

6767
bool unlimited_lines() const;
6868
bool ellipsized() const;
69-
70-
// Return a text alignment value that is not dependent on the text direction.
71-
TextAlign effective_align() const;
7269
};
7370

7471
} // namespace txt

0 commit comments

Comments
 (0)
0