diff options
author | glx <glx@openttd.org> | 2011-11-30 17:05:14 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2011-11-30 17:05:14 +0000 |
commit | 44918dded0fad238231c89227ae6fe749a8cf9c3 (patch) | |
tree | c398235d85be48e877ef32661a42072c244a94f6 /src | |
parent | a42866cee17cda47d901087caea17c8cccbd7202 (diff) | |
download | openttd-44918dded0fad238231c89227ae6fe749a8cf9c3.tar.xz |
(svn r23380) -Add: monospace font detection for win32 (also ignore duplicates)
Diffstat (limited to 'src')
-rw-r--r-- | src/fontcache.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp index d203a4513..5ded50ce7 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -304,20 +304,60 @@ err1: return ret_font_name == NULL ? WIDE_TO_MB((const TCHAR*)logfont->elfFullName) : ret_font_name; } +class FontList { +protected: + TCHAR **fonts; + uint items; + uint capacity; + +public: + FontList() : fonts(NULL), items(0), capacity(0) { }; + + ~FontList() { + if (this->fonts == NULL) return; + + for (uint i = 0; i < this->items; i++) { + free(this->fonts[i]); + } + + free(this->fonts); + } + + bool Add(const TCHAR *font) { + for (uint i = 0; i < this->items; i++) { + if (_tcscmp(this->fonts[i], font) == 0) return false; + } + + if (this->items == this->capacity) { + this->capacity += 10; + this->fonts = ReallocT(this->fonts, this->capacity); + } + + this->fonts[this->items++] = _tcsdup(font); + + return true; + } +}; + struct EFCParam { FreeTypeSettings *settings; LOCALESIGNATURE locale; MissingGlyphSearcher *callback; + FontList fonts; }; static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXTMETRICEX *metric, DWORD type, LPARAM lParam) { EFCParam *info = (EFCParam *)lParam; + /* Skip duplicates */ + if (!info->fonts.Add(logfont->elfFullName)) return 1; /* Only use TrueType fonts */ if (!(type & TRUETYPE_FONTTYPE)) return 1; /* Don't use SYMBOL fonts */ if (logfont->elfLogFont.lfCharSet == SYMBOL_CHARSET) return 1; + /* Use monospaced fonts when asked for it. */ + if (info->callback->Monospace() && (logfont->elfLogFont.lfPitchAndFamily & (FF_MODERN | FIXED_PITCH)) != (FF_MODERN | FIXED_PITCH)) return 1; /* The font has to have at least one of the supported locales to be usable. */ if ((metric->ntmFontSig.fsCsb[0] & info->locale.lsCsbSupported[0]) == 0 && (metric->ntmFontSig.fsCsb[1] & info->locale.lsCsbSupported[1]) == 0) { |