OpenTTD Source  12.0-beta2
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(freetype, 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(FreeTypeSettings *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(freetype, 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 = ScaleFontTrad(this->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 - ScaleFontTrad(this->GetDefaultFontHeight(FS_SMALL));
201  pixels = Clamp(std::min<int>(min_size, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height, MAX_FONT_SIZE);
202  }
203  } else {
204  pixels = ScaleFontTrad(pixels);
205  }
206  this->used_size = pixels;
207 
208  this->font.reset(CTFontCreateWithFontDescriptor(this->font_desc.get(), pixels, nullptr));
209 
210  /* Query the font metrics we needed. We generally round all values up to
211  * make sure we don't inadvertently cut off a row or column of pixels,
212  * except when determining glyph to glyph advances. */
213  this->units_per_em = CTFontGetUnitsPerEm(this->font.get());
214  this->ascender = (int)std::ceil(CTFontGetAscent(this->font.get()));
215  this->descender = -(int)std::ceil(CTFontGetDescent(this->font.get()));
216  this->height = this->ascender - this->descender;
217 
218  /* Get real font name. */
219  char name[128];
220  CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontCopyAttribute(this->font.get(), kCTFontDisplayNameAttribute));
221  CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
222  this->font_name = name;
223 
224  Debug(freetype, 2, "Loaded font '{}' with size {}", this->font_name, pixels);
225 }
226 
228 {
229  assert(IsPrintable(key));
230 
231  if (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END) {
232  return this->parent->MapCharToGlyph(key);
233  }
234 
235  /* Convert characters outside of the Basic Multilingual Plane into surrogate pairs. */
236  UniChar chars[2];
237  if (key >= 0x010000U) {
238  chars[0] = (UniChar)(((key - 0x010000U) >> 10) + 0xD800);
239  chars[1] = (UniChar)(((key - 0x010000U) & 0x3FF) + 0xDC00);
240  } else {
241  chars[0] = (UniChar)(key & 0xFFFF);
242  }
243 
244  CGGlyph glyph[2] = {0, 0};
245  if (CTFontGetGlyphsForCharacters(this->font.get(), chars, glyph, key >= 0x010000U ? 2 : 1)) {
246  return glyph[0];
247  }
248 
249  return 0;
250 }
251 
252 const void *CoreTextFontCache::InternalGetFontTable(uint32 tag, size_t &length)
253 {
254  CFAutoRelease<CFDataRef> data(CTFontCopyTable(this->font.get(), (CTFontTableTag)tag, kCTFontTableOptionNoOptions));
255  if (!data) return nullptr;
256 
257  length = CFDataGetLength(data.get());
258  auto buf = MallocT<UInt8>(length);
259 
260  CFDataGetBytes(data.get(), CFRangeMake(0, (CFIndex)length), buf);
261  return buf;
262 }
263 
264 const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
265 {
266  /* Get glyph size. */
267  CGGlyph glyph = (CGGlyph)key;
268  CGRect bounds = CGRectNull;
269  if (MacOSVersionIsAtLeast(10, 8, 0)) {
270  bounds = CTFontGetOpticalBoundsForGlyphs(this->font.get(), &glyph, nullptr, 1, 0);
271  } else {
272  bounds = CTFontGetBoundingRectsForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1);
273  }
274  if (CGRectIsNull(bounds)) usererror("Unable to render font glyph");
275 
276  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.
277  uint bb_height = (uint)std::ceil(bounds.size.height);
278 
279  /* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel. */
280  uint width = std::max(1U, bb_width + (this->fs == FS_NORMAL ? 1 : 0));
281  uint height = std::max(1U, bb_height + (this->fs == FS_NORMAL ? 1 : 0));
282 
283  /* Limit glyph size to prevent overflows later on. */
284  if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) usererror("Font glyph is too large");
285 
286  SpriteLoader::Sprite sprite;
287  sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
288  sprite.type = ST_FONT;
289  sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
290  sprite.width = width;
291  sprite.height = height;
292  sprite.x_offs = (int16)std::round(CGRectGetMinX(bounds));
293  sprite.y_offs = this->ascender - (int16)std::ceil(CGRectGetMaxY(bounds));
294 
295  if (bounds.size.width > 0) {
296  /* Glyph is not a white-space glyph. Render it to a bitmap context. */
297 
298  /* We only need the alpha channel, as we apply our own colour constants to the sprite. */
299  int pitch = Align(bb_width, 16);
300  byte *bmp = CallocT<byte>(bb_height * pitch);
301  CFAutoRelease<CGContextRef> context(CGBitmapContextCreate(bmp, bb_width, bb_height, 8, pitch, nullptr, kCGImageAlphaOnly));
302  /* Set antialias according to requirements. */
303  CGContextSetAllowsAntialiasing(context.get(), use_aa);
304  CGContextSetAllowsFontSubpixelPositioning(context.get(), use_aa);
305  CGContextSetAllowsFontSubpixelQuantization(context.get(), !use_aa);
306  CGContextSetShouldSmoothFonts(context.get(), false);
307 
308  float offset = 0.5f; // CoreText uses 0.5 as pixel centers. We want pixel alignment.
309  CGPoint pos{offset - bounds.origin.x, offset - bounds.origin.y};
310  CTFontDrawGlyphs(this->font.get(), &glyph, &pos, 1, context.get());
311 
312  /* Draw shadow for medium size. */
313  if (this->fs == FS_NORMAL && !use_aa) {
314  for (uint y = 0; y < bb_height; y++) {
315  for (uint x = 0; x < bb_width; x++) {
316  if (bmp[y * pitch + x] > 0) {
317  sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
318  sprite.data[1 + x + (1 + y) * sprite.width].a = use_aa ? bmp[x + y * pitch] : 0xFF;
319  }
320  }
321  }
322  }
323 
324  /* Extract pixel data. */
325  for (uint y = 0; y < bb_height; y++) {
326  for (uint x = 0; x < bb_width; x++) {
327  if (bmp[y * pitch + x] > 0) {
328  sprite.data[x + y * sprite.width].m = FACE_COLOUR;
329  sprite.data[x + y * sprite.width].a = use_aa ? bmp[x + y * pitch] : 0xFF;
330  }
331  }
332  }
333  }
334 
335  GlyphEntry new_glyph;
336  new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
337  new_glyph.width = (byte)std::round(CTFontGetAdvancesForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1));
338  this->SetGlyphPtr(key, &new_glyph);
339 
340  return new_glyph.sprite;
341 }
342 
350 {
351  static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
352 
353  FreeTypeSubSetting *settings = nullptr;
354  switch (fs) {
355  default: NOT_REACHED();
356  case FS_SMALL: settings = &_freetype.small; break;
357  case FS_NORMAL: settings = &_freetype.medium; break;
358  case FS_LARGE: settings = &_freetype.large; break;
359  case FS_MONO: settings = &_freetype.mono; break;
360  }
361 
362  if (settings->font.empty()) return;
363 
365 
366  if (settings->os_handle != nullptr) {
367  font_ref.reset(static_cast<CTFontDescriptorRef>(const_cast<void *>(settings->os_handle)));
368  CFRetain(font_ref.get()); // Increase ref count to match a later release.
369  }
370 
371  if (!font_ref && MacOSVersionIsAtLeast(10, 6, 0)) {
372  /* Might be a font file name, try load it. Direct font loading is
373  * only supported starting on OSX 10.6. */
375 
376  /* See if this is an absolute path. */
377  if (FileExists(settings->font)) {
378  path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8));
379  } else {
380  /* Scan the search-paths to see if it can be found. */
381  std::string full_font = FioFindFullPath(BASE_DIR, settings->font.c_str());
382  if (!full_font.empty()) {
383  path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8));
384  }
385  }
386 
387  if (path) {
388  /* Try getting a font descriptor to see if the system can use it. */
389  CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false));
390  CFAutoRelease<CFArrayRef> descs(CTFontManagerCreateFontDescriptorsFromURL(url.get()));
391 
392  if (descs && CFArrayGetCount(descs.get()) > 0) {
393  font_ref.reset((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0));
394  CFRetain(font_ref.get());
395  } else {
396  ShowInfoF("Unable to load file '%s' for %s font, using default OS font selection instead", settings->font.c_str(), SIZE_TO_NAME[fs]);
397  }
398  }
399  }
400 
401  if (!font_ref) {
402  CFAutoRelease<CFStringRef> name(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8));
403 
404  /* Simply creating the font using CTFontCreateWithNameAndSize will *always* return
405  * something, no matter the name. As such, we can't use it to check for existence.
406  * We instead query the list of all font descriptors that match the given name which
407  * does not do this stupid name fallback. */
408  CFAutoRelease<CTFontDescriptorRef> name_desc(CTFontDescriptorCreateWithNameAndSize(name.get(), 0.0));
409  CFAutoRelease<CFSetRef> mandatory_attribs(CFSetCreate(kCFAllocatorDefault, const_cast<const void **>(reinterpret_cast<const void * const *>(&kCTFontNameAttribute)), 1, &kCFTypeSetCallBacks));
410  CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(name_desc.get(), mandatory_attribs.get()));
411 
412  /* Assume the first result is the one we want. */
413  if (descs && CFArrayGetCount(descs.get()) > 0) {
414  font_ref.reset((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0));
415  CFRetain(font_ref.get());
416  }
417  }
418 
419  if (!font_ref) {
420  ShowInfoF("Unable to use '%s' for %s font, using sprite font instead", settings->font.c_str(), SIZE_TO_NAME[fs]);
421  return;
422  }
423 
424  new CoreTextFontCache(fs, std::move(font_ref), settings->size);
425 }
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:2012
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: fontcache_internal.h:23
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
usererror
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
Definition: openttd.cpp:103
MissingGlyphSearcher
A searcher for missing glyphs.
Definition: strings_func.h:242
ScaleFontTrad
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Definition: zoom_func.h:96
ST_FONT
@ ST_FONT
A sprite used for fonts.
Definition: gfx_type.h:304
FreeTypeSettings::large
FreeTypeSubSetting large
The largest font; mostly used for newspapers.
Definition: fontcache.h:228
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
FreeTypeSettings::mono
FreeTypeSubSetting mono
The mono space font used for license/readme viewers.
Definition: fontcache.h:229
FS_LARGE
@ FS_LARGE
Index of the large font in the font tables.
Definition: gfx_type.h:209
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
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: fontcache_internal.h:25
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
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:208
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: fontcache_internal.h:26
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
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.
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: fontcache_internal.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
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
SpriteLoader::Sprite::width
uint16 width
Width of the sprite.
Definition: spriteloader.hpp:50
FreeTypeSubSetting
Settings for a single freetype font.
Definition: fontcache.h:216
FreeTypeSettings::medium
FreeTypeSubSetting medium
The normal font size.
Definition: fontcache.h:227
MAX_FONT_SIZE
static const int MAX_FONT_SIZE
Maximum font size.
Definition: fontcache_internal.h:17
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:154
FontCache::ascender
int ascender
The ascender value of the font.
Definition: fontcache.h:28
TrueTypeFontCache::ClearFontCache
void ClearFontCache() override
Reset cached glyphs.
Definition: fontcache.cpp:230
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: fontcache_internal.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:378
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:210
SpriteLoader::CommonPixel::a
uint8 a
Alpha-channel.
Definition: spriteloader.hpp:38
macos.h
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:24
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:206
MissingGlyphSearcher::SetFontNames
virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name, const void *os_data=nullptr)=0
Set the right font names.
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:349
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:112
SimpleSpriteAlloc
void * SimpleSpriteAlloc(size_t size)
Sprite allocator simply using malloc.
Definition: spritecache.cpp:846
FontCache::MapCharToGlyph
virtual GlyphID MapCharToGlyph(WChar key)=0
Map a character into a glyph.
SetFallbackFont
bool SetFallbackFont(FreeTypeSettings *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
FreeTypeSettings::small
FreeTypeSubSetting small
The smallest font; mostly used for zoomed out view.
Definition: fontcache.h:226
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:394
font_osx.h
CoreTextFontCache::MapCharToGlyph
GlyphID MapCharToGlyph(WChar key) override
Map a character into a glyph.
Definition: font_osx.cpp:227
FreeTypeSettings
Settings for the freetype fonts.
Definition: fontcache.h:225