OpenTTD Source: src/os/windows/font_win32.cpp Source File

OpenTTD Source 14.0-beta3

font_win32.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "../../stdafx.h"
11 #include "../../debug.h"
12 #include "../../blitter/factory.hpp"
13 #include "../../core/alloc_func.hpp"
14 #include "../../core/math_func.hpp"
15 #include "../../core/mem_func.hpp"
16 #include "../../error_func.h"
17 #include "../../fileio_func.h"
18 #include "../../fontcache.h"
19 #include "../../fontcache/truetypefontcache.h"
20 #include "../../fontdetection.h"
21 #include "../../library_loader.h"
22 #include "../../string_func.h"
23 #include "../../strings_func.h"
24 #include "../../zoom_func.h"
25 #include "font_win32.h"
26
27 #include "../../table/control_codes.h"
28
29 #include <windows.h>
30 #include <shlobj.h> /* SHGetFolderPath */
31 #include "os/windows/win32.h"
32 #undef small // Say what, Windows?
33
34 #include "safeguards.h"
35
36 struct EFCParam {
37 FontCacheSettings *settings;
38 LOCALESIGNATURE locale;
39 MissingGlyphSearcher *callback;
40 std::vector<std::wstring> fonts;
41
42 bool Add(const std::wstring_view &font)
43 {
44 for (const auto &entry : this->fonts) {
45 if (font.compare(entry) == 0) return false;
46 }
47
48 this->fonts.emplace_back(font);
49
50 return true;
51 }
52 };
53
54 static int CALLBACK EnumFontCallback(const ENUMLOGFONTEX *logfont, const NEWTEXTMETRICEX *metric, DWORD type, LPARAM lParam)
55 {
56 EFCParam *info = (EFCParam *)lParam;
57
58 /* Skip duplicates */
59 if (!info->Add(logfont->elfFullName)) return 1;
60 /* Only use TrueType fonts */
61 if (!(type & TRUETYPE_FONTTYPE)) return 1;
62 /* Don't use SYMBOL fonts */
63 if (logfont->elfLogFont.lfCharSet == SYMBOL_CHARSET) return 1;
64 /* Use monospaced fonts when asked for it. */
65 if (info->callback->Monospace() && (logfont->elfLogFont.lfPitchAndFamily & (FF_MODERN | FIXED_PITCH)) != (FF_MODERN | FIXED_PITCH)) return 1;
66
67 /* The font has to have at least one of the supported locales to be usable. */
68 if ((metric->ntmFontSig.fsCsb[0] & info->locale.lsCsbSupported[0]) == 0 && (metric->ntmFontSig.fsCsb[1] & info->locale.lsCsbSupported[1]) == 0) {
69 /* On win9x metric->ntmFontSig seems to contain garbage. */
70 FONTSIGNATURE fs;
71 memset(&fs, 0, sizeof(fs));
72 HFONT font = CreateFontIndirect(&logfont->elfLogFont);
73 if (font != nullptr) {
74 HDC dc = GetDC(nullptr);
75 HGDIOBJ oldfont = SelectObject(dc, font);
76 GetTextCharsetInfo(dc, &fs, 0);
77 SelectObject(dc, oldfont);
78 ReleaseDC(nullptr, dc);
79 DeleteObject(font);
80 }
81 if ((fs.fsCsb[0] & info->locale.lsCsbSupported[0]) == 0 && (fs.fsCsb[1] & info->locale.lsCsbSupported[1]) == 0) return 1;
82 }
83
84 char font_name[MAX_PATH];
85 convert_from_fs((const wchar_t *)logfont->elfFullName, font_name, lengthof(font_name));
86
87 info->callback->SetFontNames(info->settings, font_name, &logfont->elfLogFont);
88 if (info->callback->FindMissingGlyphs()) return 1;
89 Debug(fontcache, 1, "Fallback font: {}", font_name);
90 return 0; // stop enumerating
91 }
92
93 bool SetFallbackFont(FontCacheSettings *settings, const std::string &, int winlangid, MissingGlyphSearcher *callback)
94 {
95 Debug(fontcache, 1, "Trying fallback fonts");
96 EFCParam langInfo;
97 if (GetLocaleInfo(MAKELCID(winlangid, SORT_DEFAULT), LOCALE_FONTSIGNATURE, (LPTSTR)&langInfo.locale, sizeof(langInfo.locale) / sizeof(wchar_t)) == 0) {
98 /* Invalid langid or some other mysterious error, can't determine fallback font. */
99 Debug(fontcache, 1, "Can't get locale info for fallback font (langid=0x{:x})", winlangid);
100 return false;
101 }
102 langInfo.settings = settings;
103 langInfo.callback = callback;
104
105 LOGFONT font;
106 /* Enumerate all fonts. */
107 font.lfCharSet = DEFAULT_CHARSET;
108 font.lfFaceName[0] = '\0';
109 font.lfPitchAndFamily = 0;
110
111 HDC dc = GetDC(nullptr);
112 int ret = EnumFontFamiliesEx(dc, &font, (FONTENUMPROC)&EnumFontCallback, (LPARAM)&langInfo, 0);
113 ReleaseDC(nullptr, dc);
114 return ret == 0;
115 }
116
117
118 #ifndef ANTIALIASED_QUALITY
119 #define ANTIALIASED_QUALITY 4
120 #endif
121
128 Win32FontCache::Win32FontCache(FontSize fs, const LOGFONT &logfont, int pixels) : TrueTypeFontCache(fs, pixels), logfont(logfont)
129 {
130 this->dc = CreateCompatibleDC(nullptr);
131 this->SetFontSize(pixels);
132 }
133
134 Win32FontCache::~Win32FontCache()
135 {
136 this->ClearFontCache();
137 DeleteDC(this->dc);
138 DeleteObject(this->font);
139 }
140
141 void Win32FontCache::SetFontSize(int pixels)
142 {
143 if (pixels == 0) {
144 /* Try to determine a good height based on the minimal height recommended by the font. */
145 int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
146 pixels = scaled_height;
147
148 HFONT temp = CreateFontIndirect(&this->logfont);
149 if (temp != nullptr) {
150 HGDIOBJ old = SelectObject(this->dc, temp);
151
152 UINT size = GetOutlineTextMetrics(this->dc, 0, nullptr);
153 LPOUTLINETEXTMETRIC otm = (LPOUTLINETEXTMETRIC)new BYTE[size];
154 GetOutlineTextMetrics(this->dc, size, otm);
155
156 /* Font height is minimum height plus the difference between the default
157 * height for this font size and the small size. */
158 int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL));
159 /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */
160 pixels = std::min(std::max(std::min<int>(otm->otmusMinimumPPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE);
161
162 delete[] (BYTE*)otm;
163 SelectObject(dc, old);
164 DeleteObject(temp);
165 }
166 } else {
167 pixels = ScaleGUITrad(pixels);
168 }
169 this->used_size = pixels;
170
171 /* Create GDI font handle. */
172 this->logfont.lfHeight = -pixels;
173 this->logfont.lfWidth = 0;
174 this->logfont.lfOutPrecision = ANTIALIASED_QUALITY;
175
176 if (this->font != nullptr) {
177 SelectObject(dc, this->old_font);
178 DeleteObject(this->font);
179 }
180 this->font = CreateFontIndirect(&this->logfont);
181 this->old_font = SelectObject(this->dc, this->font);
182
183 /* Query the font metrics we needed. */
184 UINT otmSize = GetOutlineTextMetrics(this->dc, 0, nullptr);
185 POUTLINETEXTMETRIC otm = (POUTLINETEXTMETRIC)new BYTE[otmSize];
186 GetOutlineTextMetrics(this->dc, otmSize, otm);
187
188 this->units_per_em = otm->otmEMSquare;
189 this->ascender = otm->otmTextMetrics.tmAscent;
190 this->descender = otm->otmTextMetrics.tmDescent;
191 this->height = this->ascender + this->descender;
192 this->glyph_size.cx = otm->otmTextMetrics.tmMaxCharWidth;
193 this->glyph_size.cy = otm->otmTextMetrics.tmHeight;
194
195 this->fontname = FS2OTTD((LPWSTR)((BYTE *)otm + (ptrdiff_t)otm->otmpFaceName));
196
197 Debug(fontcache, 2, "Loaded font '{}' with size {}", this->fontname, pixels);
198 delete[] (BYTE*)otm;
199 }
200
204 void Win32FontCache::ClearFontCache()
205 {
206 /* GUI scaling might have changed, determine font size anew if it was automatically selected. */
207 if (this->font != nullptr) this->SetFontSize(this->req_size);
208
209 this->TrueTypeFontCache::ClearFontCache();
210 }
211
212 /* virtual */ const Sprite *Win32FontCache::InternalGetGlyph(GlyphID key, bool aa)
213 {
214 GLYPHMETRICS gm;
215 MAT2 mat = { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
216
217 /* Call GetGlyphOutline with zero size initially to get required memory size. */
218 DWORD size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, 0, nullptr, &mat);
219 if (size == GDI_ERROR) UserError("Unable to render font glyph");
220
221 /* Add 1 scaled pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
222 uint shadow = (this->fs == FS_NORMAL) ? ScaleGUITrad(1) : 0;
223 uint width = std::max(1U, (uint)gm.gmBlackBoxX + shadow);
224 uint height = std::max(1U, (uint)gm.gmBlackBoxY + shadow);
225
226 /* Limit glyph size to prevent overflows later on. */
227 if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
228
229 /* Call GetGlyphOutline again with size to actually render the glyph. */
230 byte *bmp = new byte[size];
231 GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
232
233 /* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
234 SpriteLoader::SpriteCollection spritecollection;
235 SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
236 sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
237 sprite.type = SpriteType::Font;
238 sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
239 sprite.width = width;
240 sprite.height = height;
241 sprite.x_offs = gm.gmptGlyphOrigin.x;
242 sprite.y_offs = this->ascender - gm.gmptGlyphOrigin.y;
243
244 if (size > 0) {
245 /* All pixel data returned by GDI is in the form of DWORD-aligned rows.
246 * For a non anti-aliased glyph, the returned bitmap has one bit per pixel.
247 * For anti-aliased rendering, GDI uses the strange value range of 0 to 64,
248 * inclusively. To map this to 0 to 255, we shift left by two and then
249 * subtract one. */
250 uint pitch = Align(aa ? gm.gmBlackBoxX : std::max((gm.gmBlackBoxX + 7u) / 8u, 1u), 4);
251
252 /* Draw shadow for medium size. */
253 if (this->fs == FS_NORMAL && !aa) {
254 for (uint y = 0; y < gm.gmBlackBoxY; y++) {
255 for (uint x = 0; x < gm.gmBlackBoxX; x++) {
256 if (aa ? (bmp[x + y * pitch] > 0) : HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
257 sprite.data[shadow + x + (shadow + y) * sprite.width].m = SHADOW_COLOUR;
258 sprite.data[shadow + x + (shadow + y) * sprite.width].a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
259 }
260 }
261 }
262 }
263
264 for (uint y = 0; y < gm.gmBlackBoxY; y++) {
265 for (uint x = 0; x < gm.gmBlackBoxX; x++) {
266 if (aa ? (bmp[x + y * pitch] > 0) : HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
267 sprite.data[x + y * sprite.width].m = FACE_COLOUR;
268 sprite.data[x + y * sprite.width].a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
269 }
270 }
271 }
272 }
273
274 GlyphEntry new_glyph;
275 new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
276 new_glyph.width = gm.gmCellIncX;
277
278 this->SetGlyphPtr(key, &new_glyph);
279
280 delete[] bmp;
281
282 return new_glyph.sprite;
283 }
284
285 /* virtual */ GlyphID Win32FontCache::MapCharToGlyph(char32_t key, bool allow_fallback)
286 {
287 assert(IsPrintable(key));
288
289 /* Convert characters outside of the BMP into surrogate pairs. */
290 WCHAR chars[2];
291 if (key >= 0x010000U) {
292 chars[0] = (wchar_t)(((key - 0x010000U) >> 10) + 0xD800);
293 chars[1] = (wchar_t)(((key - 0x010000U) & 0x3FF) + 0xDC00);
294 } else {
295 chars[0] = (wchar_t)(key & 0xFFFF);
296 }
297
298 WORD glyphs[2] = { 0, 0 };
299 GetGlyphIndicesW(this->dc, chars, key >= 0x010000U ? 2 : 1, glyphs, GGI_MARK_NONEXISTING_GLYPHS);
300
301 if (glyphs[0] != 0xFFFF) return glyphs[0];
302 return allow_fallback && key >= SCC_SPRITE_START && key <= SCC_SPRITE_END ? this->parent->MapCharToGlyph(key) : 0;
303 }
304
305 /* virtual */ const void *Win32FontCache::InternalGetFontTable(uint32_t tag, size_t &length)
306 {
307 DWORD len = GetFontData(this->dc, tag, 0, nullptr, 0);
308
309 void *result = nullptr;
310 if (len != GDI_ERROR && len > 0) {
311 result = MallocT<BYTE>(len);
312 GetFontData(this->dc, tag, 0, result, len);
313 }
314
315 length = len;
316 return result;
317 }
318
319
320 static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
321 {
322 wchar_t fontPath[MAX_PATH] = {};
323
324 /* See if this is an absolute path. */
325 if (FileExists(font_name)) {
326 convert_to_fs(font_name, fontPath, lengthof(fontPath));
327 } else {
328 /* Scan the search-paths to see if it can be found. */
329 std::string full_font = FioFindFullPath(BASE_DIR, font_name);
330 if (!full_font.empty()) {
331 convert_to_fs(font_name, fontPath, lengthof(fontPath));
332 }
333 }
334
335 if (fontPath[0] != 0) {
336 if (AddFontResourceEx(fontPath, FR_PRIVATE, 0) != 0) {
337 /* Try a nice little undocumented function first for getting the internal font name.
338 * Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
339 static LibraryLoader _gdi32("gdi32.dll");
340 typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
341 static PFNGETFONTRESOURCEINFO GetFontResourceInfo = _gdi32.GetFunction("GetFontResourceInfoW");
342
343 if (GetFontResourceInfo != nullptr) {
344 /* Try to query an array of LOGFONTs that describe the file. */
345 DWORD len = 0;
346 if (GetFontResourceInfo(fontPath, &len, nullptr, 2) && len >= sizeof(LOGFONT)) {
347 LOGFONT *buf = (LOGFONT *)new byte[len];
348 if (GetFontResourceInfo(fontPath, &len, buf, 2)) {
349 logfont = *buf; // Just use first entry.
350 }
351 delete[](byte *)buf;
352 }
353 }
354
355 /* No dice yet. Use the file name as the font face name, hoping it matches. */
356 if (logfont.lfFaceName[0] == 0) {
357 wchar_t fname[_MAX_FNAME];
358 _wsplitpath(fontPath, nullptr, nullptr, fname, nullptr);
359
360 wcsncpy_s(logfont.lfFaceName, lengthof(logfont.lfFaceName), fname, _TRUNCATE);
361 logfont.lfWeight = strcasestr(font_name.c_str(), " bold") != nullptr || strcasestr(font_name.c_str(), "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
362 }
363 }
364 }
365
366 return logfont.lfFaceName[0] != 0;
367 }
368
369 static void LoadWin32Font(FontSize fs, const LOGFONT &logfont, uint size, const char *font_name)
370 {
371 HFONT font = CreateFontIndirect(&logfont);
372 if (font == nullptr) {
373 ShowInfo("Unable to use '{}' for {} font, Win32 reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
374 return;
375 }
376 DeleteObject(font);
377
378 new Win32FontCache(fs, logfont, size);
379 }
386 void LoadWin32Font(FontSize fs)
387 {
388 FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
389
390 if (settings->font.empty()) return;
391
392 const char *font_name = settings->font.c_str();
393 LOGFONT logfont;
394 MemSetT(&logfont, 0);
395 logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
396 logfont.lfCharSet = DEFAULT_CHARSET;
397 logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
398 logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
399
400 if (settings->os_handle != nullptr) {
401 logfont = *(const LOGFONT *)settings->os_handle;
402 } else if (strchr(font_name, '.') != nullptr) {
403 /* Might be a font file name, try load it. */
404 if (!TryLoadFontFromFile(settings->font, logfont)) {
405 ShowInfo("Unable to load file '{}' for {} font, using default windows font selection instead", font_name, FontSizeToName(fs));
406 }
407 }
408
409 if (logfont.lfFaceName[0] == 0) {
410 logfont.lfWeight = strcasestr(font_name, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
411 convert_to_fs(font_name, logfont.lfFaceName, lengthof(logfont.lfFaceName));
412 }
413
414 LoadWin32Font(fs, logfont, settings->size, font_name);
415 }
416
423 void LoadWin32Font(FontSize fs, const std::string &file_name, uint size)
424 {
425 LOGFONT logfont;
426 MemSetT(&logfont, 0);
427 logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
428 logfont.lfCharSet = DEFAULT_CHARSET;
429 logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
430 logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
431
432 if (TryLoadFontFromFile(file_name, logfont)) {
433 LoadWin32Font(fs, logfont, size, file_name.c_str());
434 }
435 }
SCC_PAL
@ SCC_PAL
Sprite has palette data.
Definition: spriteloader.hpp:25
Win32FontCache::Win32FontCache
Win32FontCache(FontSize fs, const LOGFONT &logfont, int pixels)
Create a new Win32FontCache.
Definition: font_win32.cpp:128
MissingGlyphSearcher::FindMissingGlyphs
bool FindMissingGlyphs()
Check whether there are glyphs missing in the current language.
Definition: strings.cpp:2166
SpriteLoader::Sprite::x_offs
int16_t x_offs
The x-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:51
TrueTypeFontCache
Font cache for fonts that are based on a TrueType font.
Definition: truetypefontcache.h:22
MissingGlyphSearcher
A searcher for missing glyphs.
Definition: strings_func.h:115
Win32FontCache::old_font
HGDIOBJ old_font
Old font selected into the GDI context.
Definition: font_win32.h:24
FontCacheSubSetting
Settings for a single font.
Definition: fontcache.h:207
win32.h
SpriteLoader::Sprite::AllocateData
void AllocateData(ZoomLevel zoom, size_t size)
Allocate the sprite data of this sprite.
Definition: spriteloader.hpp:62
FontCache::height
int height
The height of the font.
Definition: fontcache.h:26
FioFindFullPath
std::string FioFindFullPath(Subdirectory subdir, const std::string &filename)
Find a path to the filename in one of the search directories.
Definition: fileio.cpp:159
font_win32.h
SpriteLoader::Sprite::height
uint16_t height
Height of the sprite.
Definition: spriteloader.hpp:49
Win32FontCache::dc
HDC dc
Cached GDI device context.
Definition: font_win32.h:23
SpriteType::Font
@ Font
A sprite used for fonts.
Win32FontCache::ClearFontCache
void ClearFontCache() override
Reset cached glyphs.
Definition: font_win32.cpp:204
SpriteLoader::SpriteCollection
std::array< Sprite, ZOOM_LVL_END > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
Definition: spriteloader.hpp:71
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
EFCParam
Definition: font_win32.cpp:36
SpriteLoader::Sprite::data
SpriteLoader::CommonPixel * data
The sprite itself.
Definition: spriteloader.hpp:55
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
FontCache::units_per_em
int units_per_em
The units per EM value of the font.
Definition: fontcache.h:29
convert_from_fs
char * convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen)
Convert to OpenTTD's encoding from that of the environment in UNICODE.
Definition: win32.cpp:498
BASE_DIR
@ BASE_DIR
Base directory for all subdirectories.
Definition: fileio_type.h:109
FontCacheSettings
Settings for the four different fonts.
Definition: fontcache.h:216
TrueTypeFontCache::MAX_GLYPH_DIM
static constexpr int MAX_GLYPH_DIM
Maximum glyph dimensions.
Definition: truetypefontcache.h:24
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
LoadWin32Font
void LoadWin32Font(FontSize fs)
Loads the GDI font.
Definition: font_win32.cpp:386
FS2OTTD
std::string FS2OTTD(const std::wstring &name)
Convert to OpenTTD's encoding from a wide string.
Definition: win32.cpp:462
SpriteLoader::Sprite::type
SpriteType type
The sprite type.
Definition: spriteloader.hpp:53
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
FileExists
bool FileExists(const std::string &filename)
Test whether the given filename exists.
Definition: fileio.cpp:140
Sprite::width
uint16_t width
Width of the sprite.
Definition: spritecache.h:19
SpriteLoader::CommonPixel::m
uint8_t m
Remap-channel.
Definition: spriteloader.hpp:39
TrueTypeFontCache::MAX_FONT_MIN_REC_SIZE
static constexpr uint MAX_FONT_MIN_REC_SIZE
Upper limit for the recommended font size in case a font file contains nonsensical values.
Definition: truetypefontcache.h:25
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
safeguards.h
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
MissingGlyphSearcher::Monospace
virtual bool Monospace()=0
Whether to search for a monospace font or not.
MissingGlyphSearcher::SetFontNames
virtual void SetFontNames(struct FontCacheSettings *settings, const char *font_name, const void *os_data=nullptr)=0
Set the right font names.
GetFontCacheSubSetting
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
Definition: fontcache.h:232
GlyphID
uint32_t GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
LibraryLoader
Definition: library_loader.h:13
Win32FontCache
Font cache for fonts that are based on a Win32 font.
Definition: font_win32.h:19
SetFallbackFont
bool SetFallbackFont(FontCacheSettings *settings, const std::string &, int winlangid, MissingGlyphSearcher *callback)
We would like to have a fallback font as the current one doesn't contain all characters we need.
Definition: font_win32.cpp:93
SpriteLoader::Sprite::colours
SpriteColourComponent colours
The colour components of the sprite with useful information.
Definition: spriteloader.hpp:54
SpriteLoader::Sprite::y_offs
int16_t y_offs
The y-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:52
TrueTypeFontCache::req_size
int req_size
Requested font size.
Definition: truetypefontcache.h:27
FontCache::descender
int descender
The descender value of the font.
Definition: fontcache.h:28
FontCache::MapCharToGlyph
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
SpriteLoader::Sprite::width
uint16_t width
Width of the sprite.
Definition: spriteloader.hpp:50
FontCache::parent
FontCache * parent
The parent of this font cache.
Definition: fontcache.h:24
SCC_ALPHA
@ SCC_ALPHA
Sprite has alpha.
Definition: spriteloader.hpp:24
FontCache::ascender
int ascender
The ascender value of the font.
Definition: fontcache.h:27
Win32FontCache::MapCharToGlyph
GlyphID MapCharToGlyph(char32_t key, bool allow_fallback=true) override
Map a character into a glyph.
Definition: font_win32.cpp:285
TrueTypeFontCache::ClearFontCache
void ClearFontCache() override
Reset cached glyphs.
Definition: truetypefontcache.cpp:45
SpriteLoader::Sprite
Structure for passing information from the sprite loader to the blitter.
Definition: spriteloader.hpp:48
convert_to_fs
wchar_t * convert_to_fs(const std::string_view name, wchar_t *system_buf, size_t buflen)
Convert from OpenTTD's encoding to that of the environment in UNICODE.
Definition: win32.cpp:518
TrueTypeFontCache::used_size
int used_size
Used font size.
Definition: truetypefontcache.h:28
Win32FontCache::glyph_size
SIZE glyph_size
Maximum size of regular glyphs.
Definition: font_win32.h:25
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
MemSetT
void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:206
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:22
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
SimpleSpriteAlloc
void * SimpleSpriteAlloc(size_t size)
Sprite allocator simply using malloc.
Definition: spritecache.cpp:880
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
SpriteLoader::CommonPixel::a
uint8_t a
Alpha-channel.
Definition: spriteloader.hpp:38
Align
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:37
MAX_FONT_SIZE
static const int MAX_FONT_SIZE
Maximum font size.
Definition: truetypefontcache.h:16
Win32FontCache::fontname
std::string fontname
Cached copy of loaded font facename.
Definition: font_win32.h:26
SpriteEncoder::Encode
virtual Sprite * Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)=0
Convert a sprite from the loader to our own format.
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103