Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions third_party/txt/src/utils/LinuxUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@
FRIEND_TEST_LINUX_ONLY_EXPANDED(SUITE, DISABLE_TEST_LINUX(TEST_NAME))
#endif // defined(__linux__)

#define LINUX_ONLY_DISABLED(TEST_NAME) DISABLED_##TEST_NAME

Comment on lines -42 to -43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well keep this. If we needed it once we may well need it in the future.

#endif // LINUX_UTILS_H
90 changes: 46 additions & 44 deletions third_party/txt/tests/paragraph_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3973,23 +3973,21 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeCenterParagraph)) {
ASSERT_TRUE(Snapshot());
}

// 10/19/20 Temporarily disabled tests while being they are being fixed.
// https://github.com/flutter/flutter/issues/68493
TEST_F(ParagraphTest,
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineLeftAlign)) {
TEST_F(ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineLeftAlign)) {
const char* text = "01234\n\nعab\naعلی\n";
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.font_family = "Roboto";
paragraph_style.max_lines = 10;
paragraph_style.text_direction = TextDirection::ltr;
paragraph_style.text_align = TextAlign::left;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make the test able to run on macos now as well? I'm not sure why it was turned off for mac but if it was relying on a fallback arabic font that could have been why it was turned off.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC many of these tests run only on Linux because the Skia font manager for Apple platforms uses Core Text APIs that may not yield the same text metrics as the libraries used on Linux.

text_style.font_size = 50;
text_style.letter_spacing = 0;
text_style.font_weight = FontWeight::w500;
Expand Down Expand Up @@ -4056,9 +4054,9 @@ TEST_F(ParagraphTest,
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 77);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 77);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 85);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 85);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);

boxes =
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
Expand All @@ -4068,26 +4066,26 @@ TEST_F(ParagraphTest,
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 27);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 27);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);

ASSERT_TRUE(Snapshot());
}

TEST_F(ParagraphTest,
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineRightAlign)) {
TEST_F(ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineRightAlign)) {
const char* text = "01234\n\nعab\naعلی\n";
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.font_family = "Roboto";
paragraph_style.max_lines = 10;
paragraph_style.text_direction = TextDirection::ltr;
paragraph_style.text_align = TextAlign::right;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
text_style.font_size = 50;
text_style.letter_spacing = 0;
text_style.font_weight = FontWeight::w500;
Expand Down Expand Up @@ -4156,36 +4154,37 @@ TEST_F(ParagraphTest,
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 550);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 550);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);

boxes =
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
for (size_t i = 0; i < boxes.size(); ++i) {
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 483);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 483);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 478);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 478);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);

ASSERT_TRUE(Snapshot());
}

TEST_F(ParagraphTest,
LINUX_ONLY_DISABLED(GetRectsForRangeCenterParagraphNewlineCentered)) {
LINUX_ONLY(GetRectsForRangeCenterParagraphNewlineCentered)) {
const char* text = "01234\n\nعab\naعلی\n";
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.font_family = "Roboto";
paragraph_style.max_lines = 10;
paragraph_style.text_direction = TextDirection::ltr;
paragraph_style.text_align = TextAlign::center;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
text_style.font_size = 50;
text_style.letter_spacing = 0;
text_style.font_weight = FontWeight::w500;
Expand Down Expand Up @@ -4252,38 +4251,39 @@ TEST_F(ParagraphTest,
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 313);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 313);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 317);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 317);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);

boxes =
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
for (size_t i = 0; i < boxes.size(); ++i) {
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 255);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 255);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 252);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 252);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);

ASSERT_TRUE(Snapshot());
}

TEST_F(ParagraphTest,
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineRTLLeftAlign)) {
LINUX_ONLY(GetRectsForRangeParagraphNewlineRTLLeftAlign)) {
const char* text = "01234\n\nعab\naعلی\n";
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.font_family = "Roboto";
paragraph_style.max_lines = 10;
paragraph_style.text_direction = TextDirection::rtl;
paragraph_style.text_align = TextAlign::left;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
text_style.font_size = 50;
text_style.letter_spacing = 0;
text_style.font_weight = FontWeight::w500;
Expand Down Expand Up @@ -4352,7 +4352,7 @@ TEST_F(ParagraphTest,
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 55);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 55);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);

boxes =
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
Expand All @@ -4362,26 +4362,27 @@ TEST_F(ParagraphTest,
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 0);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 0);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);

ASSERT_TRUE(Snapshot());
}

TEST_F(ParagraphTest,
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineRTLRightAlign)) {
LINUX_ONLY(GetRectsForRangeParagraphNewlineRTLRightAlign)) {
const char* text = "01234\n\nعab\naعلی\n";
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.font_family = "Roboto";
paragraph_style.max_lines = 10;
paragraph_style.text_direction = TextDirection::rtl;
paragraph_style.text_align = TextAlign::right;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
text_style.font_size = 50;
text_style.letter_spacing = 0;
text_style.font_weight = FontWeight::w500;
Expand Down Expand Up @@ -4448,38 +4449,39 @@ TEST_F(ParagraphTest,
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 527);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 527);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 519);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 519);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);

boxes =
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
for (size_t i = 0; i < boxes.size(); ++i) {
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 456);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 456);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 451);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 451);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);

ASSERT_TRUE(Snapshot());
}

TEST_F(ParagraphTest,
LINUX_ONLY_DISABLED(GetRectsForRangeCenterParagraphNewlineRTLCentered)) {
LINUX_ONLY(GetRectsForRangeCenterParagraphNewlineRTLCentered)) {
const char* text = "01234\n\nعab\naعلی\n";
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.font_family = "Roboto";
paragraph_style.max_lines = 10;
paragraph_style.text_direction = TextDirection::rtl;
paragraph_style.text_align = TextAlign::center;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());

txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Roboto");
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
text_style.font_size = 50;
text_style.letter_spacing = 0;
text_style.font_weight = FontWeight::w500;
Expand Down Expand Up @@ -4546,19 +4548,19 @@ TEST_F(ParagraphTest,
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 291);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 291);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 287);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 287);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);

boxes =
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
for (size_t i = 0; i < boxes.size(); ++i) {
GetCanvas()->drawRect(boxes[i].rect, paint);
}
EXPECT_EQ(boxes.size(), 1ull);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 228);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 228);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 225);
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 225);
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);

ASSERT_TRUE(Snapshot());
}
Expand Down