Fix memory leaks in font selection for Linux

Add some logging too, in particular warning when no font was found.
This commit is contained in:
Michał Janiszewski 2015-12-25 19:30:23 +01:00
parent eda733165e
commit c0830ae02e
2 changed files with 17 additions and 1 deletions

View File

@ -3,6 +3,7 @@
- Feature: Add displaying of frames per second (FPS).
- Feature: Changing the number of trains no longer requires retesting.
- Feature: Add SI units as a new measurement system for distance / speed.
- Feature: Update alternative font selection mechanism for all platforms.
- Fix: [#2126] Ferris Wheels set to "backward rotation" stop working (original
bug)
- Fix: [#2449] Turning off Day/Night Circle while it is night doesn't reset back to day

View File

@ -166,7 +166,17 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
{
assert(buffer != NULL);
assert(font != NULL);
log_verbose("Looking for font %s with FontConfig.", font->font_name);
FcConfig* config = FcInitLoadConfigAndFonts();
if (!config)
{
log_error("Failed to initialize FontConfig library");
FcFini();
return false;
}
FcPattern* pat = FcNameParse((const FcChar8*) font->font_name);
FcConfigSubstitute(config, pat, FcMatchPattern);
@ -182,12 +192,17 @@ bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
if (FcPatternGetString(match, FC_FILE, 0, &filename) == FcResultMatch)
{
found = true;
strcpy(buffer, (utf8*) filename);
safe_strncpy(buffer, (utf8*) filename, MAX_PATH);
log_verbose("FontConfig provided font %s", filename);
}
FcPatternDestroy(match);
} else {
log_warning("Failed to find required font.");
}
FcPatternDestroy(pat);
FcConfigDestroy(config);
FcFini();
return found;
}