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

OpenTTD Source 15.0-beta1

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