Skip to content

Commit

Permalink
[libTxt] multi-codeunit glyph hit test minor fix (flutter#25270)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCatIsLooong authored Mar 29, 2021
1 parent dac726c commit 4c8e49d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 1 addition & 2 deletions third_party/txt/src/txt/paragraph_txt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 44 additions & 0 deletions third_party/txt/tests/paragraph_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit 4c8e49d

Please sign in to comment.