mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-22 09:53:03 +08:00
Merge pull request #3189 from stweil/pango_font_info_test
Enable pango_font_info_test and fix crash for MacOS with M1
This commit is contained in:
commit
b672eeee01
@ -72,6 +72,19 @@ const int kDefaultResolution = 300;
|
||||
std::string PangoFontInfo::fonts_dir_;
|
||||
std::string PangoFontInfo::cache_dir_;
|
||||
|
||||
static PangoGlyph get_glyph(PangoFont* font, gunichar wc) {
|
||||
#if PANGO_VERSION_CHECK(1, 44, 0)
|
||||
// pango_font_get_hb_font requires Pango 1.44 or newer.
|
||||
hb_font_t* hb_font = pango_font_get_hb_font(font);
|
||||
hb_codepoint_t glyph;
|
||||
hb_font_get_nominal_glyph(hb_font, wc, &glyph);
|
||||
#else
|
||||
// Use deprecated pango_fc_font_get_glyph for older Pango versions.
|
||||
PangoGlyph glyph = pango_fc_font_get_glyph(PANGO_FC_FONT(font), wc);
|
||||
#endif
|
||||
return glyph;
|
||||
}
|
||||
|
||||
PangoFontInfo::PangoFontInfo()
|
||||
: desc_(nullptr), resolution_(kDefaultResolution) {
|
||||
Clear();
|
||||
@ -327,8 +340,7 @@ bool PangoFontInfo::GetSpacingProperties(const std::string& utf8_char,
|
||||
const UNICHAR::const_iterator it_end = UNICHAR::end(utf8_char.c_str(),
|
||||
utf8_char.length());
|
||||
for (UNICHAR::const_iterator it = it_begin; it != it_end; ++it) {
|
||||
PangoGlyph glyph_index = pango_fc_font_get_glyph(
|
||||
reinterpret_cast<PangoFcFont*>(font), *it);
|
||||
PangoGlyph glyph_index = get_glyph(font, *it);
|
||||
if (!glyph_index) {
|
||||
// Glyph for given unicode character doesn't exist in font.
|
||||
g_object_unref(font);
|
||||
@ -402,15 +414,7 @@ bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
|
||||
PangoGlyph dotted_circle_glyph;
|
||||
PangoFont* font = run->item->analysis.font;
|
||||
|
||||
#ifdef _WIN32
|
||||
PangoGlyphString* glyphs = pango_glyph_string_new();
|
||||
const char s[] = "\xc2\xa7";
|
||||
pango_shape(s, strlen(s), &(run->item->analysis), glyphs);
|
||||
dotted_circle_glyph = glyphs->glyphs[0].glyph;
|
||||
#else // TODO: Do we need separate solution for non win build?
|
||||
dotted_circle_glyph = pango_fc_font_get_glyph(
|
||||
reinterpret_cast<PangoFcFont*>(font), kDottedCircleGlyph);
|
||||
#endif
|
||||
dotted_circle_glyph = get_glyph(font, kDottedCircleGlyph);
|
||||
|
||||
if (TLOG_IS_ON(2)) {
|
||||
PangoFontDescription* desc = pango_font_describe(font);
|
||||
@ -463,9 +467,6 @@ bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
|
||||
if (bad_glyph)
|
||||
tlog(1, "Found illegal glyph!\n");
|
||||
}
|
||||
#ifdef _WIN32
|
||||
pango_glyph_string_free(glyphs);
|
||||
#endif
|
||||
} while (!bad_glyph && pango_layout_iter_next_run(run_iter));
|
||||
|
||||
pango_layout_iter_free(run_iter);
|
||||
|
@ -177,9 +177,7 @@ check_PROGRAMS += osd_test
|
||||
endif # !DISABLED_LEGACY_ENGINE
|
||||
check_PROGRAMS += pagesegmode_test
|
||||
if ENABLE_TRAINING
|
||||
if TENSORFLOW
|
||||
check_PROGRAMS += pango_font_info_test
|
||||
endif # TENSORFLOW
|
||||
endif # ENABLE_TRAINING
|
||||
check_PROGRAMS += paragraphs_test
|
||||
if !DISABLED_LEGACY_ENGINE
|
||||
@ -363,15 +361,16 @@ endif # !DISABLED_LEGACY_ENGINE
|
||||
pagesegmode_test_SOURCES = pagesegmode_test.cc
|
||||
pagesegmode_test_LDADD = $(TRAINING_LIBS) $(LEPTONICA_LIBS)
|
||||
|
||||
if TENSORFLOW
|
||||
pango_font_info_test_SOURCES = pango_font_info_test.cc
|
||||
if TENSORFLOW
|
||||
pango_font_info_test_SOURCES += third_party/utf/rune.c
|
||||
pango_font_info_test_SOURCES += util/utf8/unicodetext.cc util/utf8/unilib.cc
|
||||
pango_font_info_test_SOURCES += util/utf8/unicodetext.cc
|
||||
pango_font_info_test_SOURCES += util/utf8/unilib.cc
|
||||
endif # TENSORFLOW
|
||||
pango_font_info_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(LEPTONICA_LIBS)
|
||||
pango_font_info_test_LDADD += $(ICU_I18N_LIBS)
|
||||
pango_font_info_test_LDADD += $(pangocairo_LIBS)
|
||||
pango_font_info_test_LDADD += $(pangoft2_LIBS)
|
||||
endif # TENSORFLOW
|
||||
|
||||
paragraphs_test_SOURCES = paragraphs_test.cc
|
||||
paragraphs_test_LDADD = $(ABSEIL_LIBS) $(TESS_LIBS)
|
||||
|
@ -18,7 +18,9 @@
|
||||
#include "pango_font_info.h"
|
||||
#include "absl/strings/str_cat.h" // for absl::StrCat
|
||||
#include "gmock/gmock-matchers.h" // for EXPECT_THAT
|
||||
#ifdef INCLUDE_TENSORFLOW
|
||||
#include "util/utf8/unicodetext.h" // for UnicodeText
|
||||
#endif
|
||||
|
||||
DECLARE_STRING_PARAM_FLAG(fonts_dir);
|
||||
DECLARE_STRING_PARAM_FLAG(fontconfig_tmpdir);
|
||||
@ -187,6 +189,7 @@ class FontUtilsTest : public ::testing::Test {
|
||||
FLAGS_fontconfig_tmpdir = FLAGS_test_tmpdir;
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_TENSORFLOW
|
||||
void CountUnicodeChars(const char* utf8_text,
|
||||
std::unordered_map<char32, int64_t>* ch_map) {
|
||||
ch_map->clear();
|
||||
@ -201,6 +204,7 @@ class FontUtilsTest : public ::testing::Test {
|
||||
++(*ch_map)[*it];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
TEST_F(FontUtilsTest, DoesFindAvailableFonts) {
|
||||
@ -234,6 +238,7 @@ TEST_F(FontUtilsTest, DoesListAvailableFonts) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_TENSORFLOW
|
||||
TEST_F(FontUtilsTest, DoesFindBestFonts) {
|
||||
std::string fonts_list;
|
||||
std::unordered_map<char32, int64_t> ch_map;
|
||||
@ -252,6 +257,7 @@ TEST_F(FontUtilsTest, DoesFindBestFonts) {
|
||||
EXPECT_EQ(1, font_flags.size());
|
||||
EXPECT_STREQ("UnBatang", font_flags[0].first);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(FontUtilsTest, DoesSelectFont) {
|
||||
const char* kLangText[] = {kArabicText, kEngText, kHinText, kKorText, nullptr};
|
||||
|
Loading…
Reference in New Issue
Block a user