OpenTTD Source: src/os/macosx/font_osx.cpp Source File

OpenTTD Source 14.0-beta3

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