diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-02-13 17:34:22 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-02-13 20:09:14 +0100 |
commit | c6af8f16f63d878371d1a823c12fbf21423505b5 (patch) | |
tree | bd0e33995d016b99d39187f2da04ccbee847504f /src/os/windows/font_win32.h | |
parent | 5ad16409847a17534389054a1b7f5fb83703fb4d (diff) | |
download | openttd-c6af8f16f63d878371d1a823c12fbf21423505b5.tar.xz |
Codechange: [Win32] Move Win32-specific font code to a seperate file.
Diffstat (limited to 'src/os/windows/font_win32.h')
-rw-r--r-- | src/os/windows/font_win32.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/os/windows/font_win32.h b/src/os/windows/font_win32.h new file mode 100644 index 000000000..9a552125f --- /dev/null +++ b/src/os/windows/font_win32.h @@ -0,0 +1,42 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file font_win32.h Functions related to font handling on Win32. */ + +#ifndef FONT_WIN32_H +#define FONT_WIN32_H + +#include "../../fontcache_internal.h" +#include "win32.h" + +/** Font cache for fonts that are based on a Win32 font. */ +class Win32FontCache : public TrueTypeFontCache { +private: + LOGFONT logfont; ///< Logical font information for selecting the font face. + HFONT font = nullptr; ///< The font face associated with this font. + HDC dc = nullptr; ///< Cached GDI device context. + HGDIOBJ old_font; ///< Old font selected into the GDI context. + SIZE glyph_size; ///< Maximum size of regular glyphs. + + void SetFontSize(FontSize fs, int pixels); + +protected: + const void *InternalGetFontTable(uint32 tag, size_t &length) override; + const Sprite *InternalGetGlyph(GlyphID key, bool aa) override; + +public: + Win32FontCache(FontSize fs, const LOGFONT &logfont, int pixels); + ~Win32FontCache(); + void ClearFontCache() override; + GlyphID MapCharToGlyph(WChar key) override; + const char *GetFontName() override { return WIDE_TO_MB(this->logfont.lfFaceName); } + const void *GetOSHandle() override { return &this->logfont; } +}; + +void LoadWin32Font(FontSize fs); + +#endif /* FONT_WIN32_H */ |