Skip to content

Commit

Permalink
prefer to use FreeType for pango_cairo_font_map
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenop committed Sep 28, 2018
1 parent 5fe1390 commit 345e5ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/training/pango_font_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ void PangoFontInfo::SoftInitFontConfig() {
}
}

PangoFontMap* PangoFontInfo::get_font_map() {
PangoFontMap* font_map =
pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
if (!font_map) // cairo withtout support of Freetype?
font_map = pango_cairo_font_map_get_default();
return font_map;
}

// Re-initializes font config, whether or not already initialized.
// If already initialized, any existing cache is deleted, just to be sure.
/* static */
Expand Down Expand Up @@ -163,7 +171,7 @@ void PangoFontInfo::HardInitFontConfig(const std::string& fonts_dir,
static void ListFontFamilies(PangoFontFamily*** families,
int* n_families) {
PangoFontInfo::SoftInitFontConfig();
PangoFontMap* font_map = pango_cairo_font_map_get_default();
PangoFontMap* font_map = PangoFontInfo::get_font_map();
DISABLE_HEAP_LEAK_CHECK;
pango_font_map_list_families(font_map, families, n_families);
}
Expand Down Expand Up @@ -202,7 +210,7 @@ bool PangoFontInfo::ParseFontDescriptionName(const std::string& name) {
// correspond to a completely different font family and face.
PangoFont* PangoFontInfo::ToPangoFont() const {
SoftInitFontConfig();
PangoFontMap* font_map = pango_cairo_font_map_get_default();
PangoFontMap* font_map = PangoFontInfo::get_font_map();
PangoContext* context = pango_context_new();
pango_cairo_context_set_resolution(context, resolution_);
pango_context_set_font_map(context, font_map);
Expand Down Expand Up @@ -359,7 +367,7 @@ bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
// when there is an illegal grapheme sequence.
const char32 kDottedCircleGlyph = 9676;
bool bad_glyph = false;
PangoFontMap* font_map = pango_cairo_font_map_get_default();
PangoFontMap* font_map = PangoFontInfo::get_font_map();
PangoContext* context = pango_context_new();
pango_context_set_font_map(context, font_map);
PangoLayout* layout;
Expand Down Expand Up @@ -483,7 +491,7 @@ bool FontUtils::IsAvailableFont(const char* input_query_desc,
PangoFont* selected_font = nullptr;
{
PangoFontInfo::SoftInitFontConfig();
PangoFontMap* font_map = pango_cairo_font_map_get_default();
PangoFontMap* font_map = PangoFontInfo::get_font_map();
PangoContext* context = pango_context_new();
pango_context_set_font_map(context, font_map);
{
Expand Down
1 change: 1 addition & 0 deletions src/training/pango_font_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class PangoFontInfo {
// environment variable and creating a fonts.conf file that points to the
// FLAGS_fonts_dir and the cache to FLAGS_fontconfig_tmpdir.
static void SoftInitFontConfig();
static PangoFontMap* get_font_map();
// Re-initializes font config, whether or not already initialized.
// If already initialized, any existing cache is deleted, just to be sure.
static void HardInitFontConfig(const std::string& fonts_dir,
Expand Down

0 comments on commit 345e5ee

Please sign in to comment.