Skip to content

Commit f854cbb

Browse files
Specify the Noto Naskh Arabic font to get consistent results in tests using Arabic characters (flutter#21974)
See flutter#68493
1 parent d4ac8e6 commit f854cbb

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

third_party/txt/src/utils/LinuxUtils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@
3939
FRIEND_TEST_LINUX_ONLY_EXPANDED(SUITE, DISABLE_TEST_LINUX(TEST_NAME))
4040
#endif // defined(__linux__)
4141

42-
#define LINUX_ONLY_DISABLED(TEST_NAME) DISABLED_##TEST_NAME
43-
4442
#endif // LINUX_UTILS_H

third_party/txt/tests/paragraph_unittests.cc

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3973,23 +3973,21 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeCenterParagraph)) {
39733973
ASSERT_TRUE(Snapshot());
39743974
}
39753975

3976-
// 10/19/20 Temporarily disabled tests while being they are being fixed.
3977-
// https://github.com/flutter/flutter/issues/68493
3978-
TEST_F(ParagraphTest,
3979-
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineLeftAlign)) {
3976+
TEST_F(ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineLeftAlign)) {
39803977
const char* text = "01234\n\nعab\naعلی\n";
39813978
auto icu_text = icu::UnicodeString::fromUTF8(text);
39823979
std::u16string u16_text(icu_text.getBuffer(),
39833980
icu_text.getBuffer() + icu_text.length());
39843981

39853982
txt::ParagraphStyle paragraph_style;
3983+
paragraph_style.font_family = "Roboto";
39863984
paragraph_style.max_lines = 10;
39873985
paragraph_style.text_direction = TextDirection::ltr;
39883986
paragraph_style.text_align = TextAlign::left;
39893987
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
39903988

39913989
txt::TextStyle text_style;
3992-
text_style.font_families = std::vector<std::string>(1, "Roboto");
3990+
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
39933991
text_style.font_size = 50;
39943992
text_style.letter_spacing = 0;
39953993
text_style.font_weight = FontWeight::w500;
@@ -4056,9 +4054,9 @@ TEST_F(ParagraphTest,
40564054
GetCanvas()->drawRect(boxes[i].rect, paint);
40574055
}
40584056
EXPECT_EQ(boxes.size(), 1ull);
4059-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 77);
4060-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 77);
4061-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
4057+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 85);
4058+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 85);
4059+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);
40624060

40634061
boxes =
40644062
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
@@ -4068,26 +4066,26 @@ TEST_F(ParagraphTest,
40684066
EXPECT_EQ(boxes.size(), 1ull);
40694067
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 27);
40704068
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 27);
4071-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
4069+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);
40724070

40734071
ASSERT_TRUE(Snapshot());
40744072
}
40754073

4076-
TEST_F(ParagraphTest,
4077-
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineRightAlign)) {
4074+
TEST_F(ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineRightAlign)) {
40784075
const char* text = "01234\n\nعab\naعلی\n";
40794076
auto icu_text = icu::UnicodeString::fromUTF8(text);
40804077
std::u16string u16_text(icu_text.getBuffer(),
40814078
icu_text.getBuffer() + icu_text.length());
40824079

40834080
txt::ParagraphStyle paragraph_style;
4081+
paragraph_style.font_family = "Roboto";
40844082
paragraph_style.max_lines = 10;
40854083
paragraph_style.text_direction = TextDirection::ltr;
40864084
paragraph_style.text_align = TextAlign::right;
40874085
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
40884086

40894087
txt::TextStyle text_style;
4090-
text_style.font_families = std::vector<std::string>(1, "Roboto");
4088+
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
40914089
text_style.font_size = 50;
40924090
text_style.letter_spacing = 0;
40934091
text_style.font_weight = FontWeight::w500;
@@ -4156,36 +4154,37 @@ TEST_F(ParagraphTest,
41564154
EXPECT_EQ(boxes.size(), 1ull);
41574155
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 550);
41584156
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 550);
4159-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
4157+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);
41604158

41614159
boxes =
41624160
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
41634161
for (size_t i = 0; i < boxes.size(); ++i) {
41644162
GetCanvas()->drawRect(boxes[i].rect, paint);
41654163
}
41664164
EXPECT_EQ(boxes.size(), 1ull);
4167-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 483);
4168-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 483);
4169-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
4165+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 478);
4166+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 478);
4167+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);
41704168

41714169
ASSERT_TRUE(Snapshot());
41724170
}
41734171

41744172
TEST_F(ParagraphTest,
4175-
LINUX_ONLY_DISABLED(GetRectsForRangeCenterParagraphNewlineCentered)) {
4173+
LINUX_ONLY(GetRectsForRangeCenterParagraphNewlineCentered)) {
41764174
const char* text = "01234\n\nعab\naعلی\n";
41774175
auto icu_text = icu::UnicodeString::fromUTF8(text);
41784176
std::u16string u16_text(icu_text.getBuffer(),
41794177
icu_text.getBuffer() + icu_text.length());
41804178

41814179
txt::ParagraphStyle paragraph_style;
4180+
paragraph_style.font_family = "Roboto";
41824181
paragraph_style.max_lines = 10;
41834182
paragraph_style.text_direction = TextDirection::ltr;
41844183
paragraph_style.text_align = TextAlign::center;
41854184
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
41864185

41874186
txt::TextStyle text_style;
4188-
text_style.font_families = std::vector<std::string>(1, "Roboto");
4187+
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
41894188
text_style.font_size = 50;
41904189
text_style.letter_spacing = 0;
41914190
text_style.font_weight = FontWeight::w500;
@@ -4252,38 +4251,39 @@ TEST_F(ParagraphTest,
42524251
GetCanvas()->drawRect(boxes[i].rect, paint);
42534252
}
42544253
EXPECT_EQ(boxes.size(), 1ull);
4255-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 313);
4256-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 313);
4257-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
4254+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 317);
4255+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 317);
4256+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);
42584257

42594258
boxes =
42604259
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
42614260
for (size_t i = 0; i < boxes.size(); ++i) {
42624261
GetCanvas()->drawRect(boxes[i].rect, paint);
42634262
}
42644263
EXPECT_EQ(boxes.size(), 1ull);
4265-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 255);
4266-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 255);
4267-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
4264+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 252);
4265+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 252);
4266+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);
42684267

42694268
ASSERT_TRUE(Snapshot());
42704269
}
42714270

42724271
TEST_F(ParagraphTest,
4273-
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineRTLLeftAlign)) {
4272+
LINUX_ONLY(GetRectsForRangeParagraphNewlineRTLLeftAlign)) {
42744273
const char* text = "01234\n\nعab\naعلی\n";
42754274
auto icu_text = icu::UnicodeString::fromUTF8(text);
42764275
std::u16string u16_text(icu_text.getBuffer(),
42774276
icu_text.getBuffer() + icu_text.length());
42784277

42794278
txt::ParagraphStyle paragraph_style;
4279+
paragraph_style.font_family = "Roboto";
42804280
paragraph_style.max_lines = 10;
42814281
paragraph_style.text_direction = TextDirection::rtl;
42824282
paragraph_style.text_align = TextAlign::left;
42834283
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
42844284

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

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

43674367
ASSERT_TRUE(Snapshot());
43684368
}
43694369

43704370
TEST_F(ParagraphTest,
4371-
LINUX_ONLY_DISABLED(GetRectsForRangeParagraphNewlineRTLRightAlign)) {
4371+
LINUX_ONLY(GetRectsForRangeParagraphNewlineRTLRightAlign)) {
43724372
const char* text = "01234\n\nعab\naعلی\n";
43734373
auto icu_text = icu::UnicodeString::fromUTF8(text);
43744374
std::u16string u16_text(icu_text.getBuffer(),
43754375
icu_text.getBuffer() + icu_text.length());
43764376

43774377
txt::ParagraphStyle paragraph_style;
4378+
paragraph_style.font_family = "Roboto";
43784379
paragraph_style.max_lines = 10;
43794380
paragraph_style.text_direction = TextDirection::rtl;
43804381
paragraph_style.text_align = TextAlign::right;
43814382
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
43824383

43834384
txt::TextStyle text_style;
4384-
text_style.font_families = std::vector<std::string>(1, "Roboto");
4385+
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
43854386
text_style.font_size = 50;
43864387
text_style.letter_spacing = 0;
43874388
text_style.font_weight = FontWeight::w500;
@@ -4448,38 +4449,39 @@ TEST_F(ParagraphTest,
44484449
GetCanvas()->drawRect(boxes[i].rect, paint);
44494450
}
44504451
EXPECT_EQ(boxes.size(), 1ull);
4451-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 527);
4452-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 527);
4453-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
4452+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 519);
4453+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 519);
4454+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);
44544455

44554456
boxes =
44564457
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
44574458
for (size_t i = 0; i < boxes.size(); ++i) {
44584459
GetCanvas()->drawRect(boxes[i].rect, paint);
44594460
}
44604461
EXPECT_EQ(boxes.size(), 1ull);
4461-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 456);
4462-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 456);
4463-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
4462+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 451);
4463+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 451);
4464+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);
44644465

44654466
ASSERT_TRUE(Snapshot());
44664467
}
44674468

44684469
TEST_F(ParagraphTest,
4469-
LINUX_ONLY_DISABLED(GetRectsForRangeCenterParagraphNewlineRTLCentered)) {
4470+
LINUX_ONLY(GetRectsForRangeCenterParagraphNewlineRTLCentered)) {
44704471
const char* text = "01234\n\nعab\naعلی\n";
44714472
auto icu_text = icu::UnicodeString::fromUTF8(text);
44724473
std::u16string u16_text(icu_text.getBuffer(),
44734474
icu_text.getBuffer() + icu_text.length());
44744475

44754476
txt::ParagraphStyle paragraph_style;
4477+
paragraph_style.font_family = "Roboto";
44764478
paragraph_style.max_lines = 10;
44774479
paragraph_style.text_direction = TextDirection::rtl;
44784480
paragraph_style.text_align = TextAlign::center;
44794481
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
44804482

44814483
txt::TextStyle text_style;
4482-
text_style.font_families = std::vector<std::string>(1, "Roboto");
4484+
text_style.font_families = {"Roboto", "Noto Naskh Arabic"};
44834485
text_style.font_size = 50;
44844486
text_style.letter_spacing = 0;
44854487
text_style.font_weight = FontWeight::w500;
@@ -4546,19 +4548,19 @@ TEST_F(ParagraphTest,
45464548
GetCanvas()->drawRect(boxes[i].rect, paint);
45474549
}
45484550
EXPECT_EQ(boxes.size(), 1ull);
4549-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 291);
4550-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 291);
4551-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 134);
4551+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 287);
4552+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 287);
4553+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 160);
45524554

45534555
boxes =
45544556
paragraph->GetRectsForRange(15, 16, rect_height_style, rect_width_style);
45554557
for (size_t i = 0; i < boxes.size(); ++i) {
45564558
GetCanvas()->drawRect(boxes[i].rect, paint);
45574559
}
45584560
EXPECT_EQ(boxes.size(), 1ull);
4559-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 228);
4560-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 228);
4561-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 193);
4561+
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 225);
4562+
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 225);
4563+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 245);
45624564

45634565
ASSERT_TRUE(Snapshot());
45644566
}

0 commit comments

Comments
 (0)