[libTxt] multi-codeunit glyph hit test minor fix (flutter/engine#25270)

This commit is contained in:
LongCatIsLooong 2021-03-29 09:49:02 -07:00 committed by GitHub
parent 93be026f56
commit b2ee2f3db8
2 changed files with 45 additions and 2 deletions

View File

@ -1927,8 +1927,7 @@ Paragraph::PositionWithAffinity ParagraphTxt::GetGlyphPositionAtCoordinate(
}
if (gp == nullptr) {
const GlyphPosition& last_glyph = line_glyph_position.back();
return PositionWithAffinity(last_glyph.code_units.end, UPSTREAM);
gp = &line_glyph_position.back();
}
// Find the direction of the run that contains this glyph.

View File

@ -2465,6 +2465,50 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(LeftAlignParagraph)) {
ASSERT_TRUE(Snapshot());
}
TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(LeftAlignRTLParagraphHitTest)) {
// Regression test for https://github.com/flutter/flutter/issues/54969.
const char* text = "بمباركة التقليدية قام عن. تصفح";
auto icu_text = icu::UnicodeString::fromUTF8(text);
std::u16string u16_text(icu_text.getBuffer(),
icu_text.getBuffer() + icu_text.length());
txt::ParagraphStyle paragraph_style;
paragraph_style.max_lines = 1;
paragraph_style.text_align = TextAlign::left;
paragraph_style.text_direction = TextDirection::rtl;
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);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = BuildParagraph(builder);
paragraph->Layout(GetTestCanvasWidth());
paragraph->Paint(GetCanvas(), 0, 0);
ASSERT_TRUE(Snapshot());
// Tests for GetGlyphPositionAtCoordinate()
ASSERT_EQ(
paragraph->GetGlyphPositionAtCoordinate(GetTestCanvasWidth() - 0.5, 0.5)
.position,
0ull);
ASSERT_TRUE(Snapshot());
}
TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph)) {
const char* text =
"This is a very long sentence to test if the text will properly wrap "