Reland "account for inline placeholders in longest line calculation (#20370)" reverted in (#20669) (flutter/engine#20678)

This commit is contained in:
LongCatIsLooong
2020-08-21 16:31:02 -07:00
committed by GitHub
parent 1945052c8e
commit fcfd260ae9
3 changed files with 40 additions and 9 deletions

View File

@@ -1045,16 +1045,16 @@ void ParagraphTxt::Layout(double width) {
return a.code_units.start < b.code_units.start; return a.code_units.start < b.code_units.start;
}); });
double blob_x_pos_start = glyph_positions.front().x_pos.start;
double blob_x_pos_end = run.is_placeholder_run()
? glyph_positions.back().x_pos.start +
run.placeholder_run()->width
: glyph_positions.back().x_pos.end;
line_code_unit_runs.emplace_back( line_code_unit_runs.emplace_back(
std::move(code_unit_positions), std::move(code_unit_positions),
Range<size_t>(run.start(), run.end()), Range<size_t>(run.start(), run.end()),
Range<double>(glyph_positions.front().x_pos.start, Range<double>(blob_x_pos_start, blob_x_pos_end), line_number,
run.is_placeholder_run() *metrics, run.style(), run.direction(), run.placeholder_run());
? glyph_positions.back().x_pos.start +
run.placeholder_run()->width
: glyph_positions.back().x_pos.end),
line_number, *metrics, run.style(), run.direction(),
run.placeholder_run());
if (run.is_placeholder_run()) { if (run.is_placeholder_run()) {
line_inline_placeholder_code_unit_runs.push_back( line_inline_placeholder_code_unit_runs.push_back(
@@ -1062,8 +1062,8 @@ void ParagraphTxt::Layout(double width) {
} }
if (!run.is_ghost()) { if (!run.is_ghost()) {
min_left_ = std::min(min_left_, glyph_positions.front().x_pos.start); min_left_ = std::min(min_left_, blob_x_pos_start);
max_right_ = std::max(max_right_, glyph_positions.back().x_pos.end); max_right_ = std::max(max_right_, blob_x_pos_end);
} }
} // for each in glyph_blobs } // for each in glyph_blobs

View File

@@ -139,6 +139,7 @@ class ParagraphTxt : public Paragraph {
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, CenterAlignParagraph); FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, CenterAlignParagraph);
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, JustifyAlignParagraph); FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, JustifyAlignParagraph);
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, JustifyRTL); FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, JustifyRTL);
FRIEND_TEST_WINDOWS_DISABLED(ParagraphTest, InlinePlaceholderLongestLine);
FRIEND_TEST_LINUX_ONLY(ParagraphTest, JustifyRTLNewLine); FRIEND_TEST_LINUX_ONLY(ParagraphTest, JustifyRTLNewLine);
FRIEND_TEST(ParagraphTest, DecorationsParagraph); FRIEND_TEST(ParagraphTest, DecorationsParagraph);
FRIEND_TEST(ParagraphTest, ItalicsParagraph); FRIEND_TEST(ParagraphTest, ItalicsParagraph);
@@ -234,6 +235,7 @@ class ParagraphTxt : public Paragraph {
end_(e), end_(e),
direction_(d), direction_(d),
style_(&st), style_(&st),
is_ghost_(false),
placeholder_run_(&placeholder) {} placeholder_run_(&placeholder) {}
size_t start() const { return start_; } size_t start() const { return start_; }

View File

@@ -1454,6 +1454,35 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderGetRectsParagraph)) {
ASSERT_TRUE(Snapshot()); ASSERT_TRUE(Snapshot());
} }
TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderLongestLine)) {
txt::ParagraphStyle paragraph_style;
paragraph_style.max_lines = 1;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_size = 26;
text_style.letter_spacing = 1;
text_style.word_spacing = 5;
text_style.color = SK_ColorBLACK;
text_style.height = 1;
text_style.decoration = TextDecoration::kUnderline;
text_style.decoration_color = SK_ColorBLACK;
builder.PushStyle(text_style);
txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
TextBaseline::kAlphabetic, 0);
builder.AddPlaceholder(placeholder_run);
builder.Pop();
auto paragraph = BuildParagraph(builder);
paragraph->Layout(GetTestCanvasWidth());
ASSERT_DOUBLE_EQ(paragraph->width_, GetTestCanvasWidth());
ASSERT_TRUE(paragraph->longest_line_ < GetTestCanvasWidth());
ASSERT_TRUE(paragraph->longest_line_ >= 50);
}
#if OS_LINUX #if OS_LINUX
// Tests if manually inserted 0xFFFC characters are replaced to 0xFFFD in order // Tests if manually inserted 0xFFFC characters are replaced to 0xFFFD in order
// to not interfere with the placeholder box layout. // to not interfere with the placeholder box layout.