Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 426ba83

Browse files
more tests
1 parent b703222 commit 426ba83

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

testing/dart/text_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ void main() {
5454
const TextHeightBehavior behavior3 = TextHeightBehavior(
5555
applyHeightToLastDescent: false
5656
);
57+
const TextHeightBehavior behavior4 = TextHeightBehavior(
58+
applyHeightToLastDescent: false,
59+
leadingDistribution: LeadingDistribution.even,
60+
);
5761

5862
test('default constructor works', () {
5963
expect(behavior0.applyHeightToFirstAscent, equals(true));
@@ -67,27 +71,33 @@ void main() {
6771

6872
expect(behavior3.applyHeightToFirstAscent, equals(true));
6973
expect(behavior3.applyHeightToLastDescent, equals(false));
74+
75+
expect(behavior4.applyHeightToLastDescent, equals(false));
76+
expect(behavior4.leadingDistribution, equals(LeadingDistribution.even));
7077
});
7178

7279
test('encode works', () {
7380
expect(behavior0.encode(), equals(0));
7481
expect(behavior1.encode(), equals(3));
7582
expect(behavior2.encode(), equals(1));
7683
expect(behavior3.encode(), equals(2));
84+
expect(behavior4.encode(), equals(5));
7785
});
7886

7987
test('decode works', () {
8088
expect(TextHeightBehavior.fromEncoded(0), equals(behavior0));
8189
expect(TextHeightBehavior.fromEncoded(3), equals(behavior1));
8290
expect(TextHeightBehavior.fromEncoded(1), equals(behavior2));
8391
expect(TextHeightBehavior.fromEncoded(2), equals(behavior3));
92+
expect(TextHeightBehavior.fromEncoded(5), equals(behavior4));
8493
});
8594

8695
test('toString works', () {
8796
expect(behavior0.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: true, leadingDistribution: LeadingDistribution.proportional)'));
8897
expect(behavior1.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false, leadingDistribution: LeadingDistribution.proportional)'));
8998
expect(behavior2.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: true, leadingDistribution: LeadingDistribution.proportional)'));
9099
expect(behavior3.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false, leadingDistribution: LeadingDistribution.proportional)'));
100+
expect(behavior4.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false, leadingDistribution: LeadingDistribution.even)'));
91101
});
92102
});
93103

third_party/txt/tests/paragraph_unittests.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7045,4 +7045,64 @@ TEST_F(ParagraphTest, TextHeightBehaviorRectsParagraph) {
70457045
ASSERT_TRUE(Snapshot());
70467046
}
70477047

7048+
TEST_F(ParagraphTest, MixedTextHeightBehaviorRectsParagraph) {
7049+
const char* text = "0123456789";
7050+
auto icu_text = icu::UnicodeString::fromUTF8(text);
7051+
std::u16string u16_text(icu_text.getBuffer(),
7052+
icu_text.getBuffer() + icu_text.length());
7053+
7054+
txt::ParagraphStyle paragraph_style;
7055+
// paragraph_style.text_height_behavior will be overridden later.
7056+
paragraph_style.text_height_behavior =
7057+
txt::TextHeightBehavior::kDisableFirstAscent |
7058+
txt::TextHeightBehavior::kDisableLastDescent;
7059+
7060+
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
7061+
7062+
txt::TextStyle text_style;
7063+
text_style.color = SK_ColorBLACK;
7064+
text_style.font_families = std::vector<std::string>(1, "Roboto");
7065+
text_style.font_size = 30;
7066+
text_style.height = 5;
7067+
text_style.has_height_override = true;
7068+
text_style.has_text_height_behavior_override = true;
7069+
text_style.text_height_behavior = txt::TextHeightBehavior::kDisableAll |
7070+
txt::TextHeightBehavior::kHalfLeading;
7071+
builder.PushStyle(text_style);
7072+
builder.AddText(u16_text);
7073+
7074+
text_style.text_height_behavior = txt::TextHeightBehavior::kHalfLeading;
7075+
builder.PushStyle(text_style);
7076+
builder.AddText(u16_text);
7077+
7078+
builder.Pop();
7079+
7080+
auto paragraph = BuildParagraph(builder);
7081+
paragraph->Layout(GetTestCanvasWidth() - 300);
7082+
7083+
paragraph->Paint(GetCanvas(), 0, 0);
7084+
7085+
SkPaint paint;
7086+
paint.setStyle(SkPaint::kStroke_Style);
7087+
paint.setAntiAlias(true);
7088+
paint.setStrokeWidth(1);
7089+
7090+
// Tests for GetRectsForRange()
7091+
Paragraph::RectHeightStyle rect_height_style =
7092+
Paragraph::RectHeightStyle::kMax;
7093+
Paragraph::RectWidthStyle rect_width_style =
7094+
Paragraph::RectWidthStyle::kTight;
7095+
paint.setColor(SK_ColorRED);
7096+
std::vector<txt::Paragraph::TextBox> boxes =
7097+
paragraph->GetRectsForRange(0, 20, rect_height_style, rect_width_style);
7098+
7099+
for (size_t i = 0; i < boxes.size(); ++i) {
7100+
GetCanvas()->drawRect(boxes[i].rect, paint);
7101+
}
7102+
// The line-height is the same as not having the kDisableAll flag.
7103+
EXPECT_GT(boxes.size(), 1ull);
7104+
EXPECT_FLOAT_EQ(boxes[0].rect.bottom() - boxes[0].rect.top(), 150.0);
7105+
7106+
ASSERT_TRUE(Snapshot());
7107+
}
70487108
} // namespace txt

0 commit comments

Comments
 (0)