Skip to content

Commit 9893a29

Browse files
account for inline placeholders in longest line calculation (flutter#20370)
1 parent 3242a69 commit 9893a29

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

third_party/txt/src/txt/paragraph_txt.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,25 +1045,25 @@ void ParagraphTxt::Layout(double width) {
10451045
return a.code_units.start < b.code_units.start;
10461046
});
10471047

1048+
double blob_x_pos_start = glyph_positions.front().x_pos.start;
1049+
double blob_x_pos_end = run.is_placeholder_run()
1050+
? glyph_positions.back().x_pos.start +
1051+
run.placeholder_run()->width
1052+
: glyph_positions.back().x_pos.end;
10481053
line_code_unit_runs.emplace_back(
10491054
std::move(code_unit_positions),
10501055
Range<size_t>(run.start(), run.end()),
1051-
Range<double>(glyph_positions.front().x_pos.start,
1052-
run.is_placeholder_run()
1053-
? glyph_positions.back().x_pos.start +
1054-
run.placeholder_run()->width
1055-
: glyph_positions.back().x_pos.end),
1056-
line_number, *metrics, run.style(), run.direction(),
1057-
run.placeholder_run());
1056+
Range<double>(blob_x_pos_start, blob_x_pos_end), line_number,
1057+
*metrics, run.style(), run.direction(), run.placeholder_run());
10581058

10591059
if (run.is_placeholder_run()) {
10601060
line_inline_placeholder_code_unit_runs.push_back(
10611061
line_code_unit_runs.back());
10621062
}
10631063

10641064
if (!run.is_ghost()) {
1065-
min_left_ = std::min(min_left_, glyph_positions.front().x_pos.start);
1066-
max_right_ = std::max(max_right_, glyph_positions.back().x_pos.end);
1065+
min_left_ = std::min(min_left_, blob_x_pos_start);
1066+
max_right_ = std::max(max_right_, blob_x_pos_end);
10671067
}
10681068
} // for each in glyph_blobs
10691069

third_party/txt/src/txt/paragraph_txt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class ParagraphTxt : public Paragraph {
139139
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, CenterAlignParagraph);
140140
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, JustifyAlignParagraph);
141141
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, JustifyRTL);
142+
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, InlinePlaceholderLongestLine);
142143
FRIEND_TEST_LINUX_ONLY(ParagraphTest, JustifyRTLNewLine);
143144
FRIEND_TEST(ParagraphTest, DecorationsParagraph);
144145
FRIEND_TEST(ParagraphTest, ItalicsParagraph);

third_party/txt/tests/paragraph_unittests.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,35 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderGetRectsParagraph)) {
14541454
ASSERT_TRUE(Snapshot());
14551455
}
14561456

1457+
TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderLongestLine)) {
1458+
txt::ParagraphStyle paragraph_style;
1459+
paragraph_style.max_lines = 1;
1460+
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1461+
1462+
txt::TextStyle text_style;
1463+
text_style.font_families = std::vector<std::string>(1, "Roboto");
1464+
text_style.font_size = 26;
1465+
text_style.letter_spacing = 1;
1466+
text_style.word_spacing = 5;
1467+
text_style.color = SK_ColorBLACK;
1468+
text_style.height = 1;
1469+
text_style.decoration = TextDecoration::kUnderline;
1470+
text_style.decoration_color = SK_ColorBLACK;
1471+
builder.PushStyle(text_style);
1472+
1473+
txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
1474+
TextBaseline::kAlphabetic, 0);
1475+
builder.AddPlaceholder(placeholder_run);
1476+
builder.Pop();
1477+
1478+
auto paragraph = BuildParagraph(builder);
1479+
paragraph->Layout(GetTestCanvasWidth());
1480+
1481+
ASSERT_DOUBLE_EQ(paragraph->width_, GetTestCanvasWidth());
1482+
ASSERT_TRUE(paragraph->longest_line_ < GetTestCanvasWidth());
1483+
ASSERT_TRUE(paragraph->longest_line_ >= 50);
1484+
}
1485+
14571486
#if OS_LINUX
14581487
// Tests if manually inserted 0xFFFC characters are replaced to 0xFFFD in order
14591488
// to not interfere with the placeholder box layout.

0 commit comments

Comments
 (0)