Skip to content

Commit

Permalink
Revert "free PangoFontMap; fixes #1999"
Browse files Browse the repository at this point in the history
This reverts commit d1d73b9.
  • Loading branch information
zdenop committed Oct 20, 2018
1 parent a03f23e commit 276c684
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
19 changes: 1 addition & 18 deletions src/training/pango_font_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,11 @@ 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 without support of Freetype?
if (!font_map) // cairo withtout support of Freetype?
font_map = pango_cairo_font_map_get_default();
return font_map;
}

// PangoFontMap created with pango_cairo_font_map_new_for_font_type should() be freed
// PangoFontMap created with pango_cairo_font_map_get_default() must not be freed
void PangoFontInfo::free_font_map(PangoFontMap* font_map) {
if (pango_cairo_font_map_get_font_type((PangoCairoFontMap*)(font_map)) == CAIRO_FONT_TYPE_FT) {
g_object_unref(font_map);
font_map = nullptr;
}
}

// 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 @@ -183,7 +174,6 @@ static void ListFontFamilies(PangoFontFamily*** families,
PangoFontMap* font_map = PangoFontInfo::get_font_map();
DISABLE_HEAP_LEAK_CHECK;
pango_font_map_list_families(font_map, families, n_families);
PangoFontInfo::free_font_map(font_map);
}

bool PangoFontInfo::ParseFontDescription(const PangoFontDescription *desc) {
Expand Down Expand Up @@ -230,7 +220,6 @@ PangoFont* PangoFontInfo::ToPangoFont() const {
font = pango_font_map_load_font(font_map, context, desc_);
}
g_object_unref(context);
PangoFontInfo::free_font_map(font_map);
return font;
}

Expand All @@ -247,8 +236,6 @@ bool PangoFontInfo::CoversUTF8Text(const char* utf8_text, int byte_length) const
int len = it.get_utf8(tmp);
tmp[len] = '\0';
tlog(2, "'%s' (U+%x) not covered by font\n", tmp, *it);
pango_coverage_unref(coverage);
g_object_unref(font);
return false;
}
}
Expand Down Expand Up @@ -342,7 +329,6 @@ bool PangoFontInfo::GetSpacingProperties(const std::string& utf8_char,
if (!glyph_index) {
// Glyph for given unicode character doesn't exist in font.
g_object_unref(font);
font = nullptr;
return false;
}
// Find the ink glyph extents for the glyph
Expand All @@ -360,7 +346,6 @@ bool PangoFontInfo::GetSpacingProperties(const std::string& utf8_char,
*x_bearing = min_bearing;
*x_advance = total_advance;
g_object_unref(font);
font = nullptr;
return true;
}

Expand Down Expand Up @@ -480,7 +465,6 @@ bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
pango_layout_iter_free(run_iter);
g_object_unref(context);
g_object_unref(layout);
free_font_map(font_map);
if (bad_glyph && graphemes) graphemes->clear();
return !bad_glyph;
}
Expand Down Expand Up @@ -515,7 +499,6 @@ bool FontUtils::IsAvailableFont(const char* input_query_desc,
selected_font = pango_font_map_load_font(font_map, context, desc);
}
g_object_unref(context);
PangoFontInfo::free_font_map(font_map);
}
if (selected_font == nullptr) {
pango_font_description_free(desc);
Expand Down
1 change: 0 additions & 1 deletion src/training/pango_font_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class PangoFontInfo {
// FLAGS_fonts_dir and the cache to FLAGS_fontconfig_tmpdir.
static void SoftInitFontConfig();
static PangoFontMap* get_font_map();
static void free_font_map(PangoFontMap* 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 276c684

Please sign in to comment.