Skip to content

Commit 9e71621

Browse files
committed
Regression test for the new Freetype method.
1 parent b2bb3d6 commit 9e71621

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

modules/freetype/test/test_basic.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ TEST(Freetype_Basic, success )
5555
EXPECT_NO_THROW( ft2->putText(dst, "Basic,success", Point( 0, 50), 50, col, -1, LINE_AA, true ) );
5656
}
5757

58+
TEST(Freetype_Basic, in_memory_font )
59+
{
60+
const string root = cvtest::TS::ptr()->get_data_path();
61+
const string font_path = root + "freetype/mplus/Mplus1-Regular.ttf";
62+
63+
cv::Ptr<cv::freetype::FreeType2> ft2;
64+
EXPECT_NO_THROW( ft2 = cv::freetype::createFreeType2() );
65+
EXPECT_NO_THROW( ft2->loadFontData( font_path, 0 ) );
66+
67+
Mat dst(600,600, CV_8UC3, Scalar::all(255) );
68+
Scalar col(128,64,255,192);
69+
EXPECT_NO_THROW( ft2->putText(dst, "Basic,success", Point( 0, 50), 50, col, -1, LINE_AA, true ) );
70+
71+
FILE* fp = fopen(font_path.c_str(), "rb");
72+
ASSERT_TRUE(fp != NULL);
73+
fseek(fp, 0, SEEK_END);
74+
const size_t file_size = ftell(fp);
75+
fseek(fp, 0, SEEK_SET);
76+
77+
std::vector<uchar> font_buffer(file_size);
78+
const size_t actual_read = fread(&font_buffer[0], 1, file_size, fp);
79+
fclose(fp);
80+
ASSERT_EQ(file_size, actual_read);
81+
82+
cv::Ptr<cv::freetype::FreeType2> ft2_in_memory;
83+
EXPECT_NO_THROW( ft2_in_memory = cv::freetype::createFreeType2() );
84+
EXPECT_NO_THROW( ft2_in_memory->loadFontData( &font_buffer[0], file_size, 0 ) );
85+
Mat dst_in_memory(600,600, CV_8UC3, Scalar::all(255) );
86+
EXPECT_NO_THROW( ft2_in_memory->putText(dst_in_memory, "Basic,success", Point( 0, 50), 50, col, -1, LINE_AA, true ) );
87+
88+
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), dst, dst_in_memory);
89+
}
90+
5891
/******************
5992
* loadFontData()
6093
*****************/

0 commit comments

Comments
 (0)