OpenTTD Source  13.2.1
font_osx.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 "font_osx.h"
13 #include "../../blitter/factory.hpp"
14 #include "../../fileio_func.h"
15 #include "../../fontdetection.h"
16 #include "../../string_func.h"
17 #include "../../strings_func.h"
18 #include "../../zoom_func.h"
19 #include "macos.h"
20 #include <cmath>
21 
22 #include "../../table/control_codes.h"
23 
24 #include "safeguards.h"
25 
26 
27 #ifdef WITH_FREETYPE
28 
29 #include <ft2build.h>
30 #include FT_FREETYPE_H
31 
32 extern FT_Library _library;
33 
34 
35 FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
36 {
37  FT_Error err = FT_Err_Cannot_Open_Resource;
38 
39  /* Get font reference from name. */
40  UInt8 file_path[PATH_MAX];
41  OSStatus os_err = -1;
42  CFAutoRelease<CFStringRef> name(CFStringCreateWithCString(kCFAllocatorDefault, font_name, kCFStringEncodingUTF8));
43 
44  /* Simply creating the font using CTFontCreateWithNameAndSize will *always* return
45  * something, no matter the name. As such, we can't use it to check for existence.
46  * We instead query the list of all font descriptors that match the given name which
47  * does not do this stupid name fallback. */
48  CFAutoRelease<CTFontDescriptorRef> name_desc(CTFontDescriptorCreateWithNameAndSize(name.get(), 0.0));
49  CFAutoRelease<CFSetRef> mandatory_attribs(CFSetCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontNameAttribute)), 1, &kCFTypeSetCallBacks));
50  CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(name_desc.get(), mandatory_attribs.get()));
51 
52  /* Loop over all matches until we can get a path for one of them. */
53  for (CFIndex i = 0; descs.get() != nullptr && i < CFArrayGetCount(descs.get()) && os_err != noErr; i++) {
54  CFAutoRelease<CTFontRef> font(CTFontCreateWithFontDescriptor((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), i), 0.0, nullptr));
55  CFAutoRelease<CFURLRef> fontURL((CFURLRef)CTFontCopyAttribute(font.get(), kCTFontURLAttribute));
56  if (CFURLGetFileSystemRepresentation(fontURL.get(), true, file_path, lengthof(file_path))) os_err = noErr;
57  }
58 
59  if (os_err == noErr) {
60  Debug(fontcache, 3, "Font path for {}: {}", font_name, file_path);
61  err = FT_New_Face(_library, (const char *)file_path, 0, face);
62  }
63 
64  return err;
65 }
66 
67 #endif /* WITH_FREETYPE */
68 
69 
70 bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
71 {
72  /* Determine fallback font using CoreText. This uses the language isocode
73  * to find a suitable font. CoreText is available from 10.5 onwards. */
74  char lang[16];
75  if (strcmp(language_isocode, "zh_TW") == 0) {
76  /* Traditional Chinese */
77  strecpy(lang, "zh-Hant", lastof(lang));
78  } else if (strcmp(language_isocode, "zh_CN") == 0) {
79  /* Simplified Chinese */
80  strecpy(lang, "zh-Hans", lastof(lang));
81  } else {
82  /* Just copy the first part of the isocode. */
83  strecpy(lang, language_isocode, lastof(lang));
84  char *sep = strchr(lang, '_');
85  if (sep != nullptr) *sep = '\0';
86  }
87 
88  /* Create a font descriptor matching the wanted language and latin (english) glyphs.
89  * Can't use CFAutoRelease here for everything due to the way the dictionary has to be created. */
90  CFStringRef lang_codes[2];
91  lang_codes[0] = CFStringCreateWithCString(kCFAllocatorDefault, lang, kCFStringEncodingUTF8);
92  lang_codes[1] = CFSTR("en");
93  CFArrayRef lang_arr = CFArrayCreate(kCFAllocatorDefault, (const void **)lang_codes, lengthof(lang_codes), &kCFTypeArrayCallBacks);
94  CFAutoRelease<CFDictionaryRef> lang_attribs(CFDictionaryCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontLanguagesAttribute)), (const void **)&lang_arr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
95  CFAutoRelease<CTFontDescriptorRef> lang_desc(CTFontDescriptorCreateWithAttributes(lang_attribs.get()));
96  CFRelease(lang_arr);
97  CFRelease(lang_codes[0]);
98 
99  /* Get array of all font descriptors for the wanted language. */
100  CFAutoRelease<CFSetRef> mandatory_attribs(CFSetCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void *const *>(&kCTFontLanguagesAttribute)), 1, &kCFTypeSetCallBacks));
101  CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(lang_desc.get(), mandatory_attribs.get()));
102 
103  bool result = false;
104  for (int tries = 0; tries < 2; tries++) {
105  for (CFIndex i = 0; descs.get() != nullptr && i < CFArrayGetCount(descs.get()); i++) {
106  CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), i);
107 
108  /* Get font traits. */
109  CFAutoRelease<CFDictionaryRef> traits((CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute));
110  CTFontSymbolicTraits symbolic_traits;
111  CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait), kCFNumberIntType, &symbolic_traits);
112 
113  /* Skip symbol fonts and vertical fonts. */
114  if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue;
115  /* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */
116  if (symbolic_traits & kCTFontBoldTrait) continue;
117  /* Select monospaced fonts if asked for. */
118  if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
119 
120  /* Get font name. */
121  char name[128];
122  CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute));
123  CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
124 
125  /* Serif fonts usually look worse on-screen with only small
126  * font sizes. As such, we try for a sans-serif font first.
127  * If we can't find one in the first try, try all fonts. */
128  if (tries == 0 && (symbolic_traits & kCTFontClassMaskTrait) != (CTFontStylisticClass)kCTFontSansSerifClass) continue;
129 
130  /* There are some special fonts starting with an '.' and the last
131  * resort font that aren't usable. Skip them. */
132  if (name[0] == '.' || strncmp(name, "LastResort", 10) == 0) continue;
133 
134  /* Save result. */
135  callback->SetFontNames(settings, name);
136  if (!callback->FindMissingGlyphs()) {
137  Debug(fontcache, 2, "CT-Font for {}: {}", language_isocode, name);
138  result = true;
139  break;
140  }
141  }
142  }
143 
144  if (!result) {
145  /* For some OS versions, the font 'Arial Unicode MS' does not report all languages it
146  * supports. If we didn't find any other font, just try it, maybe we get lucky. */
147  callback->SetFontNames(settings, "Arial Unicode MS");
148  result = !callback->FindMissingGlyphs();
149  }
150 
151  callback->FindMissingGlyphs();
152  return result;
153 }
154 
155 
156 CoreTextFontCache::CoreTextFontCache(FontSize fs, CFAutoRelease<CTFontDescriptorRef> &&font, int pixels) : TrueTypeFontCache(fs, pixels), font_desc(std::move(font))
157 {
158  this->SetFontSize(pixels);
159 }
160 
165 {
166  /* GUI scaling might have changed, determine font size anew if it was automatically selected. */
167  if (this->font) this->SetFontSize(this->req_size);
168 
170 }
171 
172 void CoreTextFontCache::SetFontSize(int pixels)
173 {
174  if (pixels == 0) {
175  /* Try to determine a good height based on the height recommended by the font. */
176  int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
177  pixels = scaled_height;
178 
179  CFAutoRelease<CTFontRef> font(CTFontCreateWithFontDescriptor(this->font_desc.get(), 0.0f, nullptr));
180  if (font) {
181  float min_size = 0.0f;
182 
183  /* The 'head' TrueType table contains information about the
184  * 'smallest readable size in pixels'. Try to read it, if
185  * that doesn't work, we use the default OS font size instead.
186  *
187  * Reference: https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6head.html */
188  CFAutoRelease<CFDataRef> data(CTFontCopyTable(font.get(), kCTFontTableHead, kCTFontTableOptionNoOptions));
189  if (data) {
190  uint16_t lowestRecPPEM; // At offset 46 of the 'head' TrueType table.
191  CFDataGetBytes(data.get(), CFRangeMake(46, sizeof(lowestRecPPEM)), (UInt8 *)&lowestRecPPEM);
192  min_size = CFSwapInt16BigToHost(lowestRecPPEM); // TrueType data is always big-endian.
193  } else {
194  CFAutoRelease<CFNumberRef> size((CFNumberRef)CTFontCopyAttribute(font.get(), kCTFontSizeAttribute));
195  CFNumberGetValue(size.get(), kCFNumberFloatType, &min_size);
196  }
197 
198  /* Font height is minimum height plus the difference between the default
199  * height for this font size and the small size. */
200  int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL));
201  /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */
202  pixels = std::min(std::max(std::min<int>(min_size, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE);
203  }
204  } else {
205  pixels = ScaleGUITrad(pixels);
206  }
207  this->used_size = pixels;
208 
209  this->font.reset(CTFontCreateWithFontDescriptor(this->font_desc.get(), pixels, nullptr));
210 
211  /* Query the font metrics we needed. We generally round all values up to
212  * make sure we don't inadvertently cut off a row or column of pixels,
213  * except when determining glyph to glyph advances. */
214  this->units_per_em = CTFontGetUnitsPerEm(this->font.get());
215  this->ascender = (int)std::ceil(CTFontGetAscent(this->font.get()));
216  this->descender = -(int)std::ceil(CTFontGetDescent(this->font.get()));
217  this->height = this->ascender - this->descender;
218 
219  /* Get real font name. */
220  char name[128];
221  CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontCopyAttribute(this->font.get(), kCTFontDisplayNameAttribute));
222  CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
223  this->font_name = name;
224 
225  Debug(fontcache, 2, "Loaded font '{}' with size {}", this->font_name, pixels);
226 }
227 
229 {
230  assert(IsPrintable(key));
231 
232  if (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END) {
233  return this->parent->MapCharToGlyph(key);
234  }
235 
236  /* Convert characters outside of the Basic Multilingual Plane into surrogate pairs. */
237  UniChar chars[2];
238  if (key >= 0x010000U) {
239  chars[0] = (UniChar)(((key - 0x010000U) >> 10) + 0xD800);
240  chars[1] = (UniChar)(((key - 0x010000U) & 0x3FF) + 0xDC00);
241  } else {
242  chars[0] = (UniChar)(key & 0xFFFF);
243  }
244 
245  CGGlyph glyph[2] = {0, 0};
246  if (CTFontGetGlyphsForCharacters(this->font.get(), chars, glyph, key >= 0x010000U ? 2 : 1)) {
247  return glyph[0];
248  }
249 
250  return 0;
251 }
252 
253 const void *CoreTextFontCache::InternalGetFontTable(uint32 tag, size_t &length)
254 {
255  CFAutoRelease<CFDataRef> data(CTFontCopyTable(this->font.get(), (CTFontTableTag)tag, kCTFontTableOptionNoOptions));
256  if (!data) return nullptr;
257 
258  length = CFDataGetLength(data.get());
259  auto buf = MallocT<UInt8>(length);
260 
261  CFDataGetBytes(data.get(), CFRangeMake(0, (CFIndex)length), buf);
262  return buf;
263 }
264 
265 const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
266 {
267  /* Get glyph size. */
268  CGGlyph glyph = (CGGlyph)key;
269  CGRect bounds = CGRectNull;
270  if (MacOSVersionIsAtLeast(10, 8, 0)) {
271  bounds = CTFontGetOpticalBoundsForGlyphs(this->font.get(), &glyph, nullptr, 1, 0);
272  } else {
273  bounds = CTFontGetBoundingRectsForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1);
274  }
275  if (CGRectIsNull(bounds)) usererror("Unable to render font glyph");
276 
277  uint bb_width = (uint)std::ceil(bounds.size.width) + 1; // Sometimes the glyph bounds are too tight and cut of the last pixel after rounding.
278  uint bb_height = (uint)std::ceil(bounds.size.height);
279 
280  /* Add 1 scaled pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
281  uint shadow = (this->fs == FS_NORMAL) ? ScaleGUITrad(1) : 0;
282  uint width = std::max(1U, bb_width + shadow);
283  uint height = std::max(1U, bb_height + shadow);
284 
285  /* Limit glyph size to prevent overflows later on. */
286  if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
287 
288  SpriteLoader::Sprite sprite;
289  sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
290  sprite.type = ST_FONT;
291  sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
292  sprite.width = width;
293  sprite.height = height;
294  sprite.x_offs = (int16)std::round(CGRectGetMinX(bounds));
295  sprite.y_offs = this->ascender - (int16)std::ceil(CGRectGetMaxY(bounds));
296 
297  if (bounds.size.width > 0) {
298  /* Glyph is not a white-space glyph. Render it to a bitmap context. */
299 
300  /* We only need the alpha channel, as we apply our own colour constants to the sprite. */
301  int pitch = Align(bb_width, 16);
302  byte *bmp = CallocT<byte>(bb_height * pitch);
303  CFAutoRelease<CGContextRef> context(CGBitmapContextCreate(bmp, bb_width, bb_height, 8, pitch, nullptr, kCGImageAlphaOnly));
304  /* Set antialias according to requirements. */
305  CGContextSetAllowsAntialiasing(context.get(), use_aa);
306  CGContextSetAllowsFontSubpixelPositioning(context.get(), use_aa);
307  CGContextSetAllowsFontSubpixelQuantization(context.get(), !use_aa);
308  CGContextSetShouldSmoothFonts(context.get(), false);
309 
310  float offset = 0.5f; // CoreText uses 0.5 as pixel centers. We want pixel alignment.
311  CGPoint pos{offset - bounds.origin.x, offset - bounds.origin.y};
312  CTFontDrawGlyphs(this->font.get(), &glyph, &pos, 1, context.get());
313 
314  /* Draw shadow for medium size. */
315  if (this->fs == FS_NORMAL && !use_aa) {
316  for (uint y = 0; y < bb_height; y++) {
317  for (uint x = 0; x < bb_width; x++) {
318  if (bmp[y * pitch + x] > 0) {
319  sprite.data[shadow + x + (shadow + y) * sprite.width].m = SHADOW_COLOUR;
320  sprite.data[shadow + x + (shadow + y) * sprite.width].a = use_aa ? bmp[x + y * pitch] : 0xFF;
321  }
322  }
323  }
324  }
325 
326  /* Extract pixel data. */
327  for (uint y = 0; y < bb_height; y++) {
328  for (uint x = 0; x < bb_width; x++) {
329  if (bmp[y * pitch + x] > 0) {
330  sprite.data[x + y * sprite.width].m = FACE_COLOUR;
331  sprite.data[x + y * sprite.width].a = use_aa ? bmp[x + y * pitch] : 0xFF;
332  }
333  }
334  }
335  }
336 
337  GlyphEntry new_glyph;
338  new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
339  new_glyph.width = (byte)std::round(CTFontGetAdvancesForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1));
340  this->SetGlyphPtr(key, &new_glyph);
341 
342  return new_glyph.sprite;
343 }
344 
352 {
354 
355  if (settings->font.empty()) return;
356 
358 
359  if (settings->os_handle != nullptr) {
360  font_ref.reset(static_cast<CTFontDescriptorRef>(const_cast<void *>(settings->os_handle)));
361  CFRetain(font_ref.get()); // Increase ref count to match a later release.
362  }
363 
364  if (!font_ref && MacOSVersionIsAtLeast(10, 6, 0)) {
365  /* Might be a font file name, try load it. Direct font loading is
366  * only supported starting on OSX 10.6. */
368 
369  /* See if this is an absolute path. */
370  if (FileExists(settings->font)) {
371  path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8));
372  } else {
373  /* Scan the search-paths to see if it can be found. */
374  std::string full_font = FioFindFullPath(BASE_DIR, settings->font.c_str());
375  if (!full_font.empty()) {
376  path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8));
377  }
378  }
379 
380  if (path) {
381  /* Try getting a font descriptor to see if the system can use it. */
382  CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false));
383  CFAutoRelease<CFArrayRef> descs(CTFontManagerCreateFontDescriptorsFromURL(url.get()));
384 
385  if (descs && CFArrayGetCount(descs.get()) > 0) {
386  font_ref.reset((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0));
387  CFRetain(font_ref.get());
388  } else {
389  ShowInfoF("Unable to load file '%s' for %s font, using default OS font selection instead", settings->font.c_str(), FontSizeToName(fs));
390  }
391  }
392  }
393 
394  if (!font_ref) {
395  CFAutoRelease<CFStringRef> name(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8));
396 
397  /* Simply creating the font using CTFontCreateWithNameAndSize will *always* return
398  * something, no matter the name. As such, we can't use it to check for existence.
399  * We instead query the list of all font descriptors that match the given name which
400  * does not do this stupid name fallback. */
401  CFAutoRelease<CTFontDescriptorRef> name_desc(CTFontDescriptorCreateWithNameAndSize(name.get(), 0.0));
402  CFAutoRelease<CFSetRef> mandatory_attribs(CFSetCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void * const *>(&kCTFontNameAttribute)), 1, &kCFTypeSetCallBacks));
403  CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(name_desc.get(), mandatory_attribs.get()));
404 
405  /* Assume the first result is the one we want. */
406  if (descs && CFArrayGetCount(descs.get()) > 0) {
407  font_ref.reset((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0));
408  CFRetain(font_ref.get());
409  }
410  }
411 
412  if (!font_ref) {
413  ShowInfoF("Unable to use '%s' for %s font, using sprite font instead", settings->font.c_str(), FontSizeToName(fs));
414  return;
415  }
416 
417  new CoreTextFontCache(fs, std::move(font_ref), settings->size);
418 }
SpriteLoader::CommonPixel::m
uint8 m
Remap-channel.
Definition: spriteloader.hpp:39
SCC_PAL
@ SCC_PAL
Sprite has palette data.
Definition: spriteloader.hpp:25
GlyphID
uint32 GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
MissingGlyphSearcher::FindMissingGlyphs
bool FindMissingGlyphs()
Check whether there are glyphs missing in the current language.
Definition: strings.cpp:2060
CoreTextFontCache::font_name
std::string font_name
Cached font name.
Definition: font_osx.h:22
TrueTypeFontCache
Font cache for fonts that are based on a TrueType font.
Definition: truetypefontcache.h:23
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
usererror
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
Definition: openttd.cpp:105
MissingGlyphSearcher
A searcher for missing glyphs.
Definition: strings_func.h:243
ST_FONT
@ ST_FONT
A sprite used for fonts.
Definition: gfx_type.h:310
FontCacheSubSetting
Settings for a single font.
Definition: fontcache.h:203
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:27
SpriteEncoder::Encode
virtual Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)=0
Convert a sprite from the loader to our own format.
CFAutoRelease
std::unique_ptr< typename std::remove_pointer< T >::type, CFDeleter< typename std::remove_pointer< T >::type > > CFAutoRelease
Specialisation of std::unique_ptr for CoreFoundation objects.
Definition: macos.h:52
SpriteLoader::Sprite::data
SpriteLoader::CommonPixel * data
The sprite itself.
Definition: spriteloader.hpp:55
FontCache::units_per_em
int units_per_em
The units per EM value of the font.
Definition: fontcache.h:30
BASE_DIR
@ BASE_DIR
Base directory for all subdirectories.
Definition: fileio_type.h:109
FontCacheSettings
Settings for the four different fonts.
Definition: fontcache.h:212
Align
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:35
TrueTypeFontCache::MAX_GLYPH_DIM
static constexpr int MAX_GLYPH_DIM
Maximum glyph dimensions.
Definition: truetypefontcache.h:25
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
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:122
CoreTextFontCache::ClearFontCache
void ClearFontCache() override
Reset cached glyphs.
Definition: font_osx.cpp:164
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:26
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
GetFontCacheSubSetting
static FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
Definition: fontcache.h:226
safeguards.h
Sprite::width
uint16 width
Width of the sprite.
Definition: spritecache.h:19
GetFontByFaceName
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
Load a freetype font face with the given font name.
Definition: font_osx.cpp:35
SpriteLoader::Sprite::x_offs
int16 x_offs
The x-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:51
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.
CoreTextFontCache::font_desc
CFAutoRelease< CTFontDescriptorRef > font_desc
Font descriptor exlcuding font size.
Definition: font_osx.h:19
FontCache::fs
const FontSize fs
The size of the font.
Definition: fontcache.h:26
CoreTextFontCache
Definition: font_osx.h:18
SpriteLoader::Sprite::colours
SpriteColourComponent colours
The colour components of the sprite with useful information.
Definition: spriteloader.hpp:54
TrueTypeFontCache::req_size
int req_size
Requested font size.
Definition: truetypefontcache.h:28
FontCache::descender
int descender
The descender value of the font.
Definition: fontcache.h:29
MacOSVersionIsAtLeast
static bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
Check if we are at least running on the specified version of Mac OS.
Definition: macos.h:25
SpriteLoader::Sprite::width
uint16 width
Width of the sprite.
Definition: spriteloader.hpp:50
FontCache::parent
FontCache * parent
The parent of this font cache.
Definition: fontcache.h:25
SCC_ALPHA
@ SCC_ALPHA
Sprite has alpha.
Definition: spriteloader.hpp:24
ShowInfoF
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Definition: openttd.cpp:156
FontCache::ascender
int ascender
The ascender value of the font.
Definition: fontcache.h:28
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
CoreTextFontCache::font
CFAutoRelease< CTFontRef > font
CoreText font handle.
Definition: font_osx.h:20
TrueTypeFontCache::used_size
int used_size
Used font size.
Definition: truetypefontcache.h:29
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
SpriteLoader::CommonPixel::a
uint8 a
Alpha-channel.
Definition: spriteloader.hpp:38
macos.h
SetFallbackFont
bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, 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_osx.cpp:70
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
SpriteLoader::Sprite::y_offs
int16 y_offs
The y-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:52
LoadCoreTextFont
void LoadCoreTextFont(FontSize fs)
Loads the TrueType font.
Definition: font_osx.cpp:351
SpriteLoader::Sprite::height
uint16 height
Height of the sprite.
Definition: spriteloader.hpp:49
FioFindFullPath
std::string FioFindFullPath(Subdirectory subdir, const char *filename)
Find a path to the filename in one of the search directories.
Definition: fileio.cpp:141
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
SimpleSpriteAlloc
void * SimpleSpriteAlloc(size_t size)
Sprite allocator simply using malloc.
Definition: spritecache.cpp:882
FontCache::MapCharToGlyph
virtual GlyphID MapCharToGlyph(WChar key)=0
Map a character into a glyph.
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
font_osx.h
CoreTextFontCache::MapCharToGlyph
GlyphID MapCharToGlyph(WChar key) override
Map a character into a glyph.
Definition: font_osx.cpp:228
MAX_FONT_SIZE
static const int MAX_FONT_SIZE
Maximum font size.
Definition: truetypefontcache.h:17
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168