AGS: Try to load font with WinFont as a fallback when TTFFont fails

This fixes bug #12948 AGS: Segfault when picking up at police report.
For that bug the font is properly loaded by FreeType, but it is a
non-scalable Windows font whose size does not match the requested
size. The original AGS handles TTF font sizes differently to how we
do it in TTFFont (and also has some hacks on top of that), and it
was easier here to use WinFont that try to tweak TTFont to work
with this case.
This commit is contained in:
Thierry Crozat 2021-09-24 23:43:33 +01:00
parent 3e1c61cdb8
commit 07ce31ecae

View File

@ -22,6 +22,7 @@
#include "common/file.h"
#include "graphics/fonts/ttf.h"
#include "graphics/fonts/winfont.h"
#include "ags/lib/alfont/alfont.h"
#include "ags/ags.h"
#include "ags/globals.h"
@ -37,7 +38,16 @@ Graphics::Font *ALFONT_FONT::getFont() {
Graphics::TTFRenderMode renderMode = Graphics::kTTFRenderModeMonochrome;
if (ShouldAntiAliasText())
renderMode = Graphics::kTTFRenderModeLight;
_fonts[_size] = Graphics::loadTTFFont(_ttfData, _size, Graphics::kTTFSizeModeCharacter, 0, renderMode);
Graphics::Font *font = Graphics::loadTTFFont(_ttfData, _size, Graphics::kTTFSizeModeCharacter, 0, renderMode);
if (!font) {
// Try WinFont as TTFFont may fail loading those
Graphics::WinFont *winfont = new Graphics::WinFont();
if (winfont->loadFromFON(_ttfData))
font = winfont;
else
delete winfont;
}
_fonts[_size] = font;
assert(_fonts[_size]);
}