diff options
author | Michael Lutz <michi@icosahedron.de> | 2018-11-25 02:02:20 +0100 |
---|---|---|
committer | Owen Rudge <owen@owenrudge.net> | 2019-05-14 11:21:36 +0100 |
commit | d2ed4260772e0a2ce8805e9c40525d0abb9345ea (patch) | |
tree | 2daef56dc038e55aa630a4f55f8af0eeeaff9b06 /src/fontcache.cpp | |
parent | 2675762ae9c58c47dc442b422927206c7bee13a8 (diff) | |
download | openttd-d2ed4260772e0a2ce8805e9c40525d0abb9345ea.tar.xz |
Codechange: [Win32] Pass a native GDI font description around when we have one, instead of repeatedly guessing the font.
Diffstat (limited to 'src/fontcache.cpp')
-rw-r--r-- | src/fontcache.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 778af3440..709b8a7d6 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -737,6 +737,7 @@ public: virtual GlyphID MapCharToGlyph(WChar key); virtual const char *GetFontName() { return WIDE_TO_MB(this->logfont.lfFaceName); } virtual bool IsBuiltInFont() { return false; } + virtual void *GetOSHandle() { return &this->logfont; } }; @@ -960,13 +961,16 @@ static void LoadWin32Font(FontSize fs) LOGFONT logfont; MemSetT(&logfont, 0); - - logfont.lfWeight = strcasestr(settings->font, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts. - logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH; - logfont.lfCharSet = DEFAULT_CHARSET; - logfont.lfOutPrecision = OUT_OUTLINE_PRECIS; - logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; - convert_to_fs(settings->font, logfont.lfFaceName, lengthof(logfont.lfFaceName), false); + if (settings->os_handle != nullptr) logfont = *(const LOGFONT *)settings->os_handle; + + if (logfont.lfFaceName[0] == 0) { + logfont.lfWeight = strcasestr(settings->font, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts. + logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH; + logfont.lfCharSet = DEFAULT_CHARSET; + logfont.lfOutPrecision = OUT_OUTLINE_PRECIS; + logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; + convert_to_fs(settings->font, logfont.lfFaceName, lengthof(logfont.lfFaceName), false); + } HFONT font = CreateFontIndirect(&logfont); if (font == nullptr) { |