13#include <pango/pango.h>
20#ifdef INCLUDE_TENSORFLOW
29 "DejaVu Sans Ultra-Light",
31#if PANGO_VERSION <= 12005
40const char kArabicText[] =
"والفكر والصراع 1234,\nوالفكر والصراع";
41const char kEngText[] =
"the quick brown fox jumps over the lazy dog";
42const char kHinText[] =
"पिताने विवाह की | हो गई उद्विग्न वह सोचा";
46#if PANGO_VERSION <= 12005
47 "उपयोक्ताो",
"नहीें",
"कहीअे",
"पत्रिाका",
"छह्णाीस",
52static PangoFontMap *font_map;
58 font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
60 pango_cairo_font_map_set_default(PANGO_CAIRO_FONT_MAP(font_map));
66 static std::locale system_locale(
"");
67 std::locale::global(system_locale);
69 FLAGS_fonts_dir = TESTING_DIR;
70 FLAGS_fontconfig_tmpdir = FLAGS_test_tmpdir;
85 EXPECT_TRUE(font_info_.ParseFontDescriptionName(
"Arial Bold Italic 12"));
87 EXPECT_EQ(
"Arial", font_info_.family_name());
89 EXPECT_TRUE(font_info_.ParseFontDescriptionName(
"Verdana 10"));
91 EXPECT_EQ(
"Verdana", font_info_.family_name());
93 EXPECT_TRUE(font_info_.ParseFontDescriptionName(
"DejaVu Sans Ultra-Light"));
94 EXPECT_EQ(
"DejaVu Sans", font_info_.family_name());
99 EXPECT_TRUE(font_info_.ParseFontDescriptionName(
"Arial Italic 12"));
101 EXPECT_EQ(
"Arial", font_info_.family_name());
106 EXPECT_TRUE(font_info_.ParseFontDescriptionName(
"Georgia 10"));
108 EXPECT_EQ(
"Georgia", font_info_.family_name());
112 EXPECT_TRUE(font_info_.ParseFontDescriptionName(
"Arial Italic 12"));
113 int x_bearing, x_advance;
114 EXPECT_TRUE(font_info_.GetSpacingProperties(
"A", &x_bearing, &x_advance));
116 EXPECT_TRUE(font_info_.GetSpacingProperties(
"a", &x_bearing, &x_advance));
121 font_info_.ParseFontDescriptionName(
"Verdana 12");
124 font_info_.ParseFontDescriptionName(
"UnBatang 12");
127 font_info_.ParseFontDescriptionName(
"Lohit Hindi 12");
132 font_info_.ParseFontDescriptionName(
"Arab 12");
133 const char kArabicLigature[] =
"لا";
134 EXPECT_TRUE(font_info_.CanRenderString(kArabicLigature, strlen(kArabicLigature)));
136 printf(
"Next word\n");
141 font_info_.ParseFontDescriptionName(
"Verdana 12");
146 font_info_.ParseFontDescriptionName(
"Lohit Hindi 12");
155 font_info_.ParseFontDescriptionName(
"Verdana 12");
157 std::string word =
"office";
158 EXPECT_EQ(1, font_info_.DropUncoveredChars(&word));
162 const char *kJoiners[] = {
167 for (
auto &kJoiner : kJoiners) {
169 EXPECT_EQ(0, font_info_.DropUncoveredChars(&word));
184 FLAGS_fonts_dir = TESTING_DIR;
185 FLAGS_fontconfig_tmpdir = FLAGS_test_tmpdir;
187 font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
189 pango_cairo_font_map_set_default(PANGO_CAIRO_FONT_MAP(font_map));
192#ifdef INCLUDE_TENSORFLOW
193 void CountUnicodeChars(
const char *utf8_text, std::unordered_map<char32, int64_t> *ch_map) {
201 if (std::isspace(*it))
235 for (
auto &font : fonts) {
241#ifdef INCLUDE_TENSORFLOW
242TEST_F(FontUtilsTest, DoesFindBestFonts) {
243 std::string fonts_list;
244 std::unordered_map<char32, int64_t> ch_map;
245 CountUnicodeChars(
kEngText, &ch_map);
247 std::vector<std::pair<const char *, std::vector<bool> > > font_flags;
253 CountUnicodeChars(
kKorText, &ch_map);
264 const char *kLangNames[] = {
"Arabic",
"English",
"Hindi",
"Korean",
nullptr};
265 for (
int i = 0; kLangText[
i] !=
nullptr; ++
i) {
267 std::vector<std::string> graphemes;
268 std::string selected_font;
277 const char kMixedScriptText[] =
"पिताने विवाह की | والفكر والصراع";
278 std::vector<std::string> graphemes;
279 std::string selected_font;
287TEST_F(FontUtilsTest, GetAllRenderableCharacters) {
288 const int32_t kHindiChar = 0x0905;
289 const int32_t kArabicChar = 0x0623;
290 const int32_t kMongolianChar = 0x180E;
291 const int32_t kOghamChar = 0x1680;
292 std::vector<bool> unicode_mask;
293 FontUtils::GetAllRenderableCharacters(&unicode_mask);
302 unicode_mask.clear();
304 std::vector<std::string> selected_fonts;
305 selected_fonts.push_back(
"Lohit Hindi");
306 FontUtils::GetAllRenderableCharacters(selected_fonts, &unicode_mask);
313 unicode_mask.clear();
325 unicode_mask.clear();
#define EXPECT_THAT(value, matcher)
#define EXPECT_EQ(val1, val2)
#define SCOPED_TRACE(message)
#define EXPECT_GT(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_FALSE(condition)
bool IsWhitespace(const char32 ch)
constexpr size_t countof(T const (&)[N]) noexcept
const char * kBadlyFormedHinWords[]
const char * kExpectedFontNames[]
TEST_F(EuroText, FastLatinOCR)
bool ParseFontDescriptionName(const std::string &name)
const std::string & family_name() const
static void SoftInitFontConfig()
static std::string BestFonts(const std::unordered_map< char32, int64_t > &ch_map, std::vector< std::pair< const char *, std::vector< bool > > > *font_flag)
static bool SelectFont(const char *utf8_word, const int utf8_len, std::string *font_name, std::vector< std::string > *graphemes)
static bool IsAvailableFont(const char *font_desc)
static const std::vector< std::string > & ListAvailableFonts()
static void SetUpTestCase()
static void SetUpTestCase()
const_iterator end() const
UnicodeText & PointToUTF8(const char *utf8_buffer, int byte_length)
const_iterator begin() const