OpenTTD Source  14.1
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 
124 Win32FontCache::Win32FontCache(FontSize fs, const LOGFONT &logfont, int pixels) : TrueTypeFontCache(fs, pixels), logfont(logfont)
125 {
126  this->dc = CreateCompatibleDC(nullptr);
127  this->SetFontSize(pixels);
128 }
129 
130 Win32FontCache::~Win32FontCache()
131 {
132  this->ClearFontCache();
133  DeleteDC(this->dc);
134  DeleteObject(this->font);
135 }
136 
137 void Win32FontCache::SetFontSize(int pixels)
138 {
139  if (pixels == 0) {
140  /* Try to determine a good height based on the minimal height recommended by the font. */
141  int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
142  pixels = scaled_height;
143 
144  HFONT temp = CreateFontIndirect(&this->logfont);
145  if (temp != nullptr) {
146  HGDIOBJ old = SelectObject(this->dc, temp);
147 
148  UINT size = GetOutlineTextMetrics(this->dc, 0, nullptr);
149  LPOUTLINETEXTMETRIC otm = (LPOUTLINETEXTMETRIC)new BYTE[size];
150  GetOutlineTextMetrics(this->dc, size, otm);
151 
152  /* Font height is minimum height plus the difference between the default
153  * height for this font size and the small size. */
154  int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL));
155  /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */
156  pixels = std::min(std::max(std::min<int>(otm->otmusMinimumPPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE);
157 
158  delete[] (BYTE*)otm;
159  SelectObject(dc, old);
160  DeleteObject(temp);
161  }
162  } else {
163  pixels = ScaleGUITrad(pixels);
164  }
165  this->used_size = pixels;
166 
167  /* Create GDI font handle. */
168  this->logfont.lfHeight = -pixels;
169  this->logfont.lfWidth = 0;
170  this->logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
171  this->logfont.lfQuality = ANTIALIASED_QUALITY;
172 
173  if (this->font != nullptr) {
174  SelectObject(dc, this->old_font);
175  DeleteObject(this->font);
176  }
177  this->font = CreateFontIndirect(&this->logfont);
178  this->old_font = SelectObject(this->dc, this->font);
179 
180  /* Query the font metrics we needed. */
181  UINT otmSize = GetOutlineTextMetrics(this->dc, 0, nullptr);
182  POUTLINETEXTMETRIC otm = (POUTLINETEXTMETRIC)new BYTE[otmSize];
183  GetOutlineTextMetrics(this->dc, otmSize, otm);
184 
185  this->units_per_em = otm->otmEMSquare;
186  this->ascender = otm->otmTextMetrics.tmAscent;
187  this->descender = otm->otmTextMetrics.tmDescent;
188  this->height = this->ascender + this->descender;
189  this->glyph_size.cx = otm->otmTextMetrics.tmMaxCharWidth;
190  this->glyph_size.cy = otm->otmTextMetrics.tmHeight;
191 
192  this->fontname = FS2OTTD((LPWSTR)((BYTE *)otm + (ptrdiff_t)otm->otmpFaceName));
193 
194  Debug(fontcache, 2, "Loaded font '{}' with size {}", this->fontname, pixels);
195  delete[] (BYTE*)otm;
196 }
197 
202 {
203  /* GUI scaling might have changed, determine font size anew if it was automatically selected. */
204  if (this->font != nullptr) this->SetFontSize(this->req_size);
205 
207 }
208 
209 /* virtual */ const Sprite *Win32FontCache::InternalGetGlyph(GlyphID key, bool aa)
210 {
211  GLYPHMETRICS gm;
212  MAT2 mat = { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
213 
214  /* Call GetGlyphOutline with zero size initially to get required memory size. */
215  DWORD size = GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, 0, nullptr, &mat);
216  if (size == GDI_ERROR) UserError("Unable to render font glyph");
217 
218  /* Add 1 scaled pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
219  uint shadow = (this->fs == FS_NORMAL) ? ScaleGUITrad(1) : 0;
220  uint width = std::max(1U, (uint)gm.gmBlackBoxX + shadow);
221  uint height = std::max(1U, (uint)gm.gmBlackBoxY + shadow);
222 
223  /* Limit glyph size to prevent overflows later on. */
224  if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
225 
226  /* Call GetGlyphOutline again with size to actually render the glyph. */
227  byte *bmp = new byte[size];
228  GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
229 
230  /* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
231  SpriteLoader::SpriteCollection spritecollection;
232  SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
233  sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
234  sprite.type = SpriteType::Font;
235  sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
236  sprite.width = width;
237  sprite.height = height;
238  sprite.x_offs = gm.gmptGlyphOrigin.x;
239  sprite.y_offs = this->ascender - gm.gmptGlyphOrigin.y;
240 
241  if (size > 0) {
242  /* All pixel data returned by GDI is in the form of DWORD-aligned rows.
243  * For a non anti-aliased glyph, the returned bitmap has one bit per pixel.
244  * For anti-aliased rendering, GDI uses the strange value range of 0 to 64,
245  * inclusively. To map this to 0 to 255, we shift left by two and then
246  * subtract one. */
247  uint pitch = Align(aa ? gm.gmBlackBoxX : std::max((gm.gmBlackBoxX + 7u) / 8u, 1u), 4);
248 
249  /* Draw shadow for medium size. */
250  if (this->fs == FS_NORMAL && !aa) {
251  for (uint y = 0; y < gm.gmBlackBoxY; y++) {
252  for (uint x = 0; x < gm.gmBlackBoxX; x++) {
253  if (aa ? (bmp[x + y * pitch] > 0) : HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
254  sprite.data[shadow + x + (shadow + y) * sprite.width].m = SHADOW_COLOUR;
255  sprite.data[shadow + x + (shadow + y) * sprite.width].a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
256  }
257  }
258  }
259  }
260 
261  for (uint y = 0; y < gm.gmBlackBoxY; y++) {
262  for (uint x = 0; x < gm.gmBlackBoxX; x++) {
263  if (aa ? (bmp[x + y * pitch] > 0) : HasBit(bmp[(x / 8) + y * pitch], 7 - (x % 8))) {
264  sprite.data[x + y * sprite.width].m = FACE_COLOUR;
265  sprite.data[x + y * sprite.width].a = aa ? (bmp[x + y * pitch] << 2) - 1 : 0xFF;
266  }
267  }
268  }
269  }
270 
271  GlyphEntry new_glyph;
272  new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
273  new_glyph.width = gm.gmCellIncX;
274 
275  this->SetGlyphPtr(key, &new_glyph);
276 
277  delete[] bmp;
278 
279  return new_glyph.sprite;
280 }
281 
282 /* virtual */ GlyphID Win32FontCache::MapCharToGlyph(char32_t key, bool allow_fallback)
283 {
284  assert(IsPrintable(key));
285 
286  /* Convert characters outside of the BMP into surrogate pairs. */
287  WCHAR chars[2];
288  if (key >= 0x010000U) {
289  chars[0] = (wchar_t)(((key - 0x010000U) >> 10) + 0xD800);
290  chars[1] = (wchar_t)(((key - 0x010000U) & 0x3FF) + 0xDC00);
291  } else {
292  chars[0] = (wchar_t)(key & 0xFFFF);
293  }
294 
295  WORD glyphs[2] = { 0, 0 };
296  GetGlyphIndicesW(this->dc, chars, key >= 0x010000U ? 2 : 1, glyphs, GGI_MARK_NONEXISTING_GLYPHS);
297 
298  if (glyphs[0] != 0xFFFF) return glyphs[0];
299  return allow_fallback && key >= SCC_SPRITE_START && key <= SCC_SPRITE_END ? this->parent->MapCharToGlyph(key) : 0;
300 }
301 
302 /* virtual */ const void *Win32FontCache::InternalGetFontTable(uint32_t tag, size_t &length)
303 {
304  DWORD len = GetFontData(this->dc, tag, 0, nullptr, 0);
305 
306  void *result = nullptr;
307  if (len != GDI_ERROR && len > 0) {
308  result = MallocT<BYTE>(len);
309  GetFontData(this->dc, tag, 0, result, len);
310  }
311 
312  length = len;
313  return result;
314 }
315 
316 
317 static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
318 {
319  wchar_t fontPath[MAX_PATH] = {};
320 
321  /* See if this is an absolute path. */
322  if (FileExists(font_name)) {
323  convert_to_fs(font_name, fontPath, lengthof(fontPath));
324  } else {
325  /* Scan the search-paths to see if it can be found. */
326  std::string full_font = FioFindFullPath(BASE_DIR, font_name);
327  if (!full_font.empty()) {
328  convert_to_fs(font_name, fontPath, lengthof(fontPath));
329  }
330  }
331 
332  if (fontPath[0] != 0) {
333  if (AddFontResourceEx(fontPath, FR_PRIVATE, 0) != 0) {
334  /* Try a nice little undocumented function first for getting the internal font name.
335  * Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
336  static LibraryLoader _gdi32("gdi32.dll");
337  typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
338  static PFNGETFONTRESOURCEINFO GetFontResourceInfo = _gdi32.GetFunction("GetFontResourceInfoW");
339 
340  if (GetFontResourceInfo != nullptr) {
341  /* Try to query an array of LOGFONTs that describe the file. */
342  DWORD len = 0;
343  if (GetFontResourceInfo(fontPath, &len, nullptr, 2) && len >= sizeof(LOGFONT)) {
344  LOGFONT *buf = (LOGFONT *)new byte[len];
345  if (GetFontResourceInfo(fontPath, &len, buf, 2)) {
346  logfont = *buf; // Just use first entry.
347  }
348  delete[](byte *)buf;
349  }
350  }
351 
352  /* No dice yet. Use the file name as the font face name, hoping it matches. */
353  if (logfont.lfFaceName[0] == 0) {
354  wchar_t fname[_MAX_FNAME];
355  _wsplitpath(fontPath, nullptr, nullptr, fname, nullptr);
356 
357  wcsncpy_s(logfont.lfFaceName, lengthof(logfont.lfFaceName), fname, _TRUNCATE);
358  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.
359  }
360  }
361  }
362 
363  return logfont.lfFaceName[0] != 0;
364 }
365 
366 static void LoadWin32Font(FontSize fs, const LOGFONT &logfont, uint size, const char *font_name)
367 {
368  HFONT font = CreateFontIndirect(&logfont);
369  if (font == nullptr) {
370  ShowInfo("Unable to use '{}' for {} font, Win32 reported error 0x{:X}, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
371  return;
372  }
373  DeleteObject(font);
374 
375  new Win32FontCache(fs, logfont, size);
376 }
384 {
386 
387  if (settings->font.empty()) return;
388 
389  const char *font_name = settings->font.c_str();
390  LOGFONT logfont;
391  MemSetT(&logfont, 0);
392  logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
393  logfont.lfCharSet = DEFAULT_CHARSET;
394  logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
395  logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
396 
397  if (settings->os_handle != nullptr) {
398  logfont = *(const LOGFONT *)settings->os_handle;
399  } else if (strchr(font_name, '.') != nullptr) {
400  /* Might be a font file name, try load it. */
401  if (!TryLoadFontFromFile(settings->font, logfont)) {
402  ShowInfo("Unable to load file '{}' for {} font, using default windows font selection instead", font_name, FontSizeToName(fs));
403  }
404  }
405 
406  if (logfont.lfFaceName[0] == 0) {
407  logfont.lfWeight = strcasestr(font_name, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
408  convert_to_fs(font_name, logfont.lfFaceName, lengthof(logfont.lfFaceName));
409  }
410 
411  LoadWin32Font(fs, logfont, settings->size, font_name);
412 }
413 
420 void LoadWin32Font(FontSize fs, const std::string &file_name, uint size)
421 {
422  LOGFONT logfont;
423  MemSetT(&logfont, 0);
424  logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
425  logfont.lfCharSet = DEFAULT_CHARSET;
426  logfont.lfOutPrecision = OUT_OUTLINE_PRECIS;
427  logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
428 
429  if (TryLoadFontFromFile(file_name, logfont)) {
430  LoadWin32Font(fs, logfont, size, file_name.c_str());
431  }
432 }
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:124
MissingGlyphSearcher::FindMissingGlyphs
bool FindMissingGlyphs()
Check whether there are glyphs missing in the current language.
Definition: strings.cpp:2169
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:160
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:201
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:383
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:141
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
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
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:282
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
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