Add unittests for kerning.

Change-Id: I494bbd3993cde76cabc9dfc042dcee4b0fb6af4d
This commit is contained in:
Gary Qian
2017-07-24 15:06:37 -07:00
parent 34dfd6c602
commit 1ccc959d00
3 changed files with 44 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ class Paragraph {
FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph);
FRIEND_TEST(RenderTest, SpacingParagraph);
FRIEND_TEST(RenderTest, LongWordParagraph);
FRIEND_TEST(RenderTest, KernParagraph);
std::vector<uint16_t> text_;
StyledRuns runs_;

View File

@@ -71,6 +71,7 @@ class StyledRuns {
FRIEND_TEST(RenderTest, ChineseParagraph);
FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph);
FRIEND_TEST(RenderTest, LongWordParagraph);
FRIEND_TEST(RenderTest, KernParagraph);
struct IndexedRun {
size_t style_index = 0;

View File

@@ -1217,7 +1217,8 @@ TEST_F(RenderTest, LongWordParagraph) {
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::TextStyle text_style;
text_style.font_size = 30;
text_style.font_family = "Roboto";
text_style.font_size = 31;
text_style.letter_spacing = 0;
text_style.word_spacing = 0;
text_style.color = SK_ColorBLACK;
@@ -1245,4 +1246,44 @@ TEST_F(RenderTest, LongWordParagraph) {
ASSERT_TRUE(Snapshot());
}
TEST_F(RenderTest, KernParagraph) {
txt::ParagraphStyle paragraph_style;
paragraph_style.break_strategy = minikin::kBreakStrategy_HighQuality;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::TextStyle text_style;
text_style.font_family = "Roboto";
text_style.font_size = 100;
text_style.letter_spacing = 0;
text_style.word_spacing = 0;
text_style.color = SK_ColorBLACK;
text_style.height = 1;
builder.PushStyle(text_style);
builder.AddText("AVAVAWAH A0 V0 VA To The Lo");
builder.PushStyle(text_style);
builder.AddText("A");
builder.PushStyle(text_style);
builder.AddText("V");
builder.PushStyle(text_style);
builder.AddText(" Dialog");
builder.Pop();
auto paragraph = builder.Build();
paragraph->Layout(GetTestCanvasWidth());
paragraph->Paint(GetCanvas(), 0, 0);
ASSERT_TRUE(Snapshot());
EXPECT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0);
EXPECT_DOUBLE_EQ(paragraph->records_[1].offset().x(), 0);
EXPECT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 441.16796875f);
EXPECT_DOUBLE_EQ(paragraph->records_[3].offset().x(), 506.16796875);
EXPECT_DOUBLE_EQ(paragraph->records_[4].offset().x(), 570.16796875);
ASSERT_TRUE(Snapshot());
}
} // namespace txt