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

OpenTTD Source 15.3

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