1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
/* $Id$ */
/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file fontcache.cpp Cache for characters from fonts. */
#include "stdafx.h"
#include "fontcache.h"
#include "fontdetection.h"
#include "blitter/factory.hpp"
#include "core/math_func.hpp"
#include "strings_func.h"
#include "zoom_type.h"
#include "table/sprites.h"
#include "table/control_codes.h"
static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
static const int MAX_FONT_SIZE = 72; ///< Maximum font size.
/** Semi-constant for the height of the different sizes of fonts. */
int _font_height[FS_END];
/** Default heights for the different sizes of fonts. */
static const int _default_font_height[FS_END] = {10, 6, 18, 10};
/**
* Reset the font sizes to the defaults of the sprite based fonts.
* @param monospace Whether to reset the monospace or regular fonts.
*/
void ResetFontSizes(bool monospace)
{
if (monospace) {
_font_height[FS_MONO] = _default_font_height[FS_MONO];
} else {
_font_height[FS_SMALL] = _default_font_height[FS_SMALL];
_font_height[FS_NORMAL] = _default_font_height[FS_NORMAL];
_font_height[FS_LARGE] = _default_font_height[FS_LARGE];
}
}
/**
* Create a new font cache.
* @param fs The size of the font.
*/
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs)
{
assert(parent == NULL || this->fs == parent->fs);
FontCache::caches[this->fs] = this;
}
/** Clean everything up. */
FontCache::~FontCache()
{
assert(this->fs == parent->fs);
FontCache::caches[this->fs] = this->parent;
}
/** Font cache for fonts that are based on a freetype font. */
class SpriteFontCache : public FontCache {
public:
SpriteFontCache(FontSize fs) : FontCache(fs) {}
virtual SpriteID GetUnicodeGlyph(uint32 key);
virtual void SetUnicodeGlyph(uint32 key, SpriteID sprite);
virtual void InitializeUnicodeGlyphMap();
virtual void ClearFontCache();
virtual const Sprite *GetGlyph(uint32 key);
virtual uint GetGlyphWidth(uint32 key);
virtual bool GetDrawGlyphShadow();
};
void SpriteFontCache::ClearFontCache() {}
const Sprite *SpriteFontCache::GetGlyph(uint32 key)
{
SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return GetSprite(sprite, ST_FONT);
}
uint SpriteFontCache::GetGlyphWidth(uint32 key)
{
SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (this->fs != FS_NORMAL) : 0;
}
bool SpriteFontCache::GetDrawGlyphShadow()
{
return false;
}
/*static */ FontCache *FontCache::caches[FS_END] = { new SpriteFontCache(FS_NORMAL), new SpriteFontCache(FS_SMALL), new SpriteFontCache(FS_LARGE), new SpriteFontCache(FS_MONO) };
#ifdef WITH_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include FT_TRUETYPE_TABLES_H
/** Font cache for fonts that are based on a freetype font. */
class FreeTypeFontCache : public FontCache {
public:
FreeTypeFontCache(FontSize fs) : FontCache(fs) {}
virtual SpriteID GetUnicodeGlyph(uint32 key) { return this->parent->GetUnicodeGlyph(key); }
virtual void SetUnicodeGlyph(uint32 key, SpriteID sprite) { this->parent->SetUnicodeGlyph(key, sprite); }
virtual void InitializeUnicodeGlyphMap() { this->parent->InitializeUnicodeGlyphMap(); }
virtual void ClearFontCache();
virtual const Sprite *GetGlyph(uint32 key);
virtual uint GetGlyphWidth(uint32 key);
virtual bool GetDrawGlyphShadow();
};
FT_Library _library = NULL;
static FT_Face _face_small = NULL;
static FT_Face _face_medium = NULL;
static FT_Face _face_large = NULL;
static FT_Face _face_mono = NULL;
static int _ascender[FS_END];
FreeTypeSettings _freetype;
static const byte FACE_COLOUR = 1;
static const byte SHADOW_COLOUR = 2;
static void SetFontGeometry(FT_Face face, FontSize size, int pixels)
{
if (pixels == 0) {
/* Try to determine a good height based on the minimal height recommended by the font. */
pixels = _default_font_height[size];
TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(face, ft_sfnt_head);
if (head != NULL) {
/* Font height is minimum height plus the difference between the default
* height for this font size and the small size. */
int diff = _default_font_height[size] - _default_font_height[FS_SMALL];
pixels = Clamp(min(head->Lowest_Rec_PPEM, 20) + diff, _default_font_height[size], MAX_FONT_SIZE);
}
}
FT_Error err = FT_Set_Pixel_Sizes(face, 0, pixels);
if (err == FT_Err_Invalid_Pixel_Size) {
/* Find nearest size to that requested */
FT_Bitmap_Size *bs = face->available_sizes;
int i = face->num_fixed_sizes;
int n = bs->height;
for (; --i; bs++) {
if (abs(pixels - bs->height) < abs(pixels - n)) n = bs->height;
}
FT_Set_Pixel_Sizes(face, 0, n);
}
int asc = face->size->metrics.ascender >> 6;
int dec = face->size->metrics.descender >> 6;
_ascender[size] = asc;
_font_height[size] = asc - dec;
}
/**
* Loads the freetype font.
* First type to load the fontname as if it were a path. If that fails,
* try to resolve the filename of the font using fontconfig, where the
* format is 'font family name' or 'font family name, font style'.
*/
static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *type)
{
FT_Error error;
if (StrEmpty(font_name)) return;
error = FT_New_Face(_library, font_name, 0, face);
if (error != FT_Err_Ok) error = GetFontByFaceName(font_name, face);
if (error == FT_Err_Ok) {
DEBUG(freetype, 2, "Requested '%s', using '%s %s'", font_name, (*face)->family_name, (*face)->style_name);
/* Attempt to select the unicode character map */
error = FT_Select_Charmap(*face, ft_encoding_unicode);
if (error == FT_Err_Ok) return; // Success
if (error == FT_Err_Invalid_CharMap_Handle) {
/* Try to pick a different character map instead. We default to
* the first map, but platform_id 0 encoding_id 0 should also
* be unicode (strange system...) */
FT_CharMap found = (*face)->charmaps[0];
int i;
for (i = 0; i < (*face)->num_charmaps; i++) {
FT_CharMap charmap = (*face)->charmaps[i];
if (charmap->platform_id == 0 && charmap->encoding_id == 0) {
found = charmap;
}
}
if (found != NULL) {
error = FT_Set_Charmap(*face, found);
if (error == FT_Err_Ok) return;
}
}
}
FT_Done_Face(*face);
*face = NULL;
ShowInfoF("Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", font_name, type, error);
}
static void ResetGlyphCache(bool monospace);
/**
* Unload a face and set it to NULL.
* @param face the face to unload
*/
static void UnloadFace(FT_Face *face)
{
if (*face == NULL) return;
FT_Done_Face(*face);
*face = NULL;
}
/**
* (Re)initialize the freetype related things, i.e. load the non-sprite fonts.
* @param monospace Whether to initialise the monospace or regular fonts.
*/
void InitFreeType(bool monospace)
{
ResetFontSizes(monospace);
ResetGlyphCache(monospace);
if (monospace) {
UnloadFace(&_face_mono);
} else {
UnloadFace(&_face_small);
UnloadFace(&_face_medium);
UnloadFace(&_face_large);
}
if (StrEmpty(_freetype.small.font) && StrEmpty(_freetype.medium.font) && StrEmpty(_freetype.large.font) && StrEmpty(_freetype.mono.font)) {
DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
return;
}
if (_library == NULL) {
if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
ShowInfoF("Unable to initialize FreeType, using sprite fonts instead");
return;
}
DEBUG(freetype, 2, "Initialized");
}
/* Load each font */
if (monospace) {
LoadFreeTypeFont(_freetype.mono.font , &_face_mono, "mono");
if (_face_mono != NULL) {
new FreeTypeFontCache(FS_MONO);
SetFontGeometry(_face_mono, FS_MONO, _freetype.mono.size);
}
} else {
LoadFreeTypeFont(_freetype.small.font, &_face_small, "small");
LoadFreeTypeFont(_freetype.medium.font, &_face_medium, "medium");
LoadFreeTypeFont(_freetype.large.font, &_face_large, "large");
/* Set each font size */
if (_face_small != NULL) {
new FreeTypeFontCache(FS_SMALL);
SetFontGeometry(_face_small, FS_SMALL, _freetype.small.size);
}
if (_face_medium != NULL) {
new FreeTypeFontCache(FS_NORMAL);
SetFontGeometry(_face_medium, FS_NORMAL, _freetype.medium.size);
}
if (_face_large != NULL) {
new FreeTypeFontCache(FS_LARGE);
SetFontGeometry(_face_large, FS_LARGE, _freetype.large.size);
}
}
}
/**
* Free everything allocated w.r.t. fonts.
*/
void UninitFreeType()
{
ResetGlyphCache(true);
ResetGlyphCache(false);
UnloadFace(&_face_small);
UnloadFace(&_face_medium);
UnloadFace(&_face_large);
UnloadFace(&_face_mono);
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
FontCache *fc = FontCache::Get(fs);
if (fc->HasParent()) delete fc;
}
FT_Done_FreeType(_library);
_library = NULL;
}
/**
* Reset cached glyphs.
*/
void FreeTypeFontCache::ClearFontCache()
{
ResetGlyphCache(true);
ResetGlyphCache(false);
}
static FT_Face GetFontFace(FontSize size)
{
switch (size) {
default: NOT_REACHED();
case FS_NORMAL: return _face_medium;
case FS_SMALL: return _face_small;
case FS_LARGE: return _face_large;
case FS_MONO: return _face_mono;
}
}
struct GlyphEntry {
Sprite *sprite;
byte width;
bool duplicate;
};
/* The glyph cache. This is structured to reduce memory consumption.
* 1) There is a 'segment' table for each font size.
* 2) Each segment table is a discrete block of characters.
* 3) Each block contains 256 (aligned) characters sequential characters.
*
* The cache is accessed in the following way:
* For character 0x0041 ('A'): _glyph_ptr[FS_NORMAL][0x00][0x41]
* For character 0x20AC (Euro): _glyph_ptr[FS_NORMAL][0x20][0xAC]
*
* Currently only 256 segments are allocated, "limiting" us to 65536 characters.
* This can be simply changed in the two functions Get & SetGlyphPtr.
*/
static GlyphEntry **_glyph_ptr[FS_END];
/**
* Clear the complete cache
* @param monospace Whether to reset the monospace or regular font.
*/
static void ResetGlyphCache(bool monospace)
{
for (FontSize i = FS_BEGIN; i < FS_END; i++) {
if (monospace != (i == FS_MONO)) continue;
if (_glyph_ptr[i] == NULL) continue;
for (int j = 0; j < 256; j++) {
if (_glyph_ptr[i][j] == NULL) continue;
for (int k = 0; k < 256; k++) {
if (_glyph_ptr[i][j][k].duplicate) continue;
free(_glyph_ptr[i][j][k].sprite);
}
free(_glyph_ptr[i][j]);
}
free(_glyph_ptr[i]);
_glyph_ptr[i] = NULL;
}
}
static GlyphEntry *GetGlyphPtr(FontSize size, WChar key)
{
if (_glyph_ptr[size] == NULL) return NULL;
if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) return NULL;
return &_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)];
}
static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph, bool duplicate = false)
{
if (_glyph_ptr[size] == NULL) {
DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size);
_glyph_ptr[size] = CallocT<GlyphEntry*>(256);
}
if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) {
DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size);
_glyph_ptr[size][GB(key, 8, 8)] = CallocT<GlyphEntry>(256);
}
DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size);
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].duplicate = duplicate;
}
static void *AllocateFont(size_t size)
{
return MallocT<byte>(size);
}
/* Check if a glyph should be rendered with antialiasing */
static bool GetFontAAState(FontSize size)
{
/* AA is only supported for 32 bpp */
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
switch (size) {
default: NOT_REACHED();
case FS_NORMAL: return _freetype.medium.aa;
case FS_SMALL: return _freetype.small.aa;
case FS_LARGE: return _freetype.large.aa;
case FS_MONO: return _freetype.mono.aa;
}
}
const Sprite *FreeTypeFontCache::GetGlyph(WChar key)
{
FT_Face face = GetFontFace(this->fs);
FT_GlyphSlot slot;
GlyphEntry new_glyph;
GlyphEntry *glyph;
SpriteLoader::Sprite sprite;
int width;
int height;
int x;
int y;
assert(IsPrintable(key));
/* Bail out if no face loaded, or for our special characters */
if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
/* Load the sprite if it's known. */
if (sprite != 0) return GetSprite(sprite, ST_FONT);
/* For the 'rare' case there is no font available at all. */
if (face == NULL) error("No sprite font and no real font either... bailing!");
/* Use the '?' from the freetype font. */
key = '?';
}
/* Check for the glyph in our cache */
glyph = GetGlyphPtr(this->fs, key);
if (glyph != NULL && glyph->sprite != NULL) return glyph->sprite;
slot = face->glyph;
bool aa = GetFontAAState(this->fs);
FT_UInt glyph_index = FT_Get_Char_Index(face, key);
if (glyph_index == 0) {
if (key == '?') {
/* The font misses the '?' character. Use sprite font. */
SpriteID sprite = this->GetUnicodeGlyph(key);
Sprite *spr = (Sprite*)GetRawSprite(sprite, ST_FONT, AllocateFont);
assert(spr != NULL);
new_glyph.sprite = spr;
new_glyph.width = spr->width + (this->fs != FS_NORMAL);
SetGlyphPtr(this->fs, key, &new_glyph, false);
return new_glyph.sprite;
} else {
/* Use '?' for missing characters. */
this->GetGlyph('?');
glyph = GetGlyphPtr(this->fs, '?');
SetGlyphPtr(this->fs, key, glyph, true);
return glyph->sprite;
}
}
FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
FT_Render_Glyph(face->glyph, aa ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
/* Despite requesting a normal glyph, FreeType may have returned a bitmap */
aa = (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
width = max(1, slot->bitmap.width + (this->fs == FS_NORMAL));
height = max(1, slot->bitmap.rows + (this->fs == FS_NORMAL));
/* Limit glyph size to prevent overflows later on. */
if (width > 256 || height > 256) usererror("Font glyph is too large");
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
sprite.type = ST_FONT;
sprite.width = width;
sprite.height = height;
sprite.x_offs = slot->bitmap_left;
sprite.y_offs = _ascender[this->fs] - slot->bitmap_top;
/* Draw shadow for medium size */
if (this->fs == FS_NORMAL && !aa) {
for (y = 0; y < slot->bitmap.rows; y++) {
for (x = 0; x < slot->bitmap.width; x++) {
if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
sprite.data[1 + x + (1 + y) * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
}
}
}
}
for (y = 0; y < slot->bitmap.rows; y++) {
for (x = 0; x < slot->bitmap.width; x++) {
if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
sprite.data[x + y * sprite.width].m = FACE_COLOUR;
sprite.data[x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
}
}
}
new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont);
new_glyph.width = slot->advance.x >> 6;
SetGlyphPtr(this->fs, key, &new_glyph);
return new_glyph.sprite;
}
bool FreeTypeFontCache::GetDrawGlyphShadow()
{
return GetFontAAState(FS_NORMAL);
}
uint FreeTypeFontCache::GetGlyphWidth(WChar key)
{
FT_Face face = GetFontFace(this->fs);
GlyphEntry *glyph;
if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (this->fs != FS_NORMAL && this->fs != FS_MONO) : 0;
}
glyph = GetGlyphPtr(this->fs, key);
if (glyph == NULL || glyph->sprite == NULL) {
this->GetGlyph(key);
glyph = GetGlyphPtr(this->fs, key);
}
return glyph->width;
}
#endif /* WITH_FREETYPE */
/* Sprite based glyph mapping */
#include "table/unicode.h"
static SpriteID **_unicode_glyph_map[FS_END];
/** Get the SpriteID of the first glyph for the given font size */
static SpriteID GetFontBase(FontSize size)
{
switch (size) {
default: NOT_REACHED();
case FS_NORMAL: return SPR_ASCII_SPACE;
case FS_SMALL: return SPR_ASCII_SPACE_SMALL;
case FS_LARGE: return SPR_ASCII_SPACE_BIG;
case FS_MONO: return SPR_ASCII_SPACE;
}
}
SpriteID SpriteFontCache::GetUnicodeGlyph(uint32 key)
{
if (_unicode_glyph_map[this->fs][GB(key, 8, 8)] == NULL) return 0;
return _unicode_glyph_map[this->fs][GB(key, 8, 8)][GB(key, 0, 8)];
}
void SpriteFontCache::SetUnicodeGlyph(uint32 key, SpriteID sprite)
{
if (_unicode_glyph_map[this->fs] == NULL) _unicode_glyph_map[this->fs] = CallocT<SpriteID*>(256);
if (_unicode_glyph_map[this->fs][GB(key, 8, 8)] == NULL) _unicode_glyph_map[this->fs][GB(key, 8, 8)] = CallocT<SpriteID>(256);
_unicode_glyph_map[this->fs][GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
}
void SpriteFontCache::InitializeUnicodeGlyphMap()
{
/* Clear out existing glyph map if it exists */
if (_unicode_glyph_map[this->fs] != NULL) {
for (uint i = 0; i < 256; i++) {
free(_unicode_glyph_map[this->fs][i]);
}
free(_unicode_glyph_map[this->fs]);
_unicode_glyph_map[this->fs] = NULL;
}
SpriteID base = GetFontBase(this->fs);
for (uint i = ASCII_LETTERSTART; i < 256; i++) {
SpriteID sprite = base + i - ASCII_LETTERSTART;
if (!SpriteExists(sprite)) continue;
this->SetUnicodeGlyph(i, sprite);
this->SetUnicodeGlyph(i + SCC_SPRITE_START, sprite);
}
for (uint i = 0; i < lengthof(_default_unicode_map); i++) {
byte key = _default_unicode_map[i].key;
if (key == CLRA) {
/* Clear the glyph. This happens if the glyph at this code point
* is non-standard and should be accessed by an SCC_xxx enum
* entry only. */
this->SetUnicodeGlyph(_default_unicode_map[i].code, 0);
} else {
SpriteID sprite = base + key - ASCII_LETTERSTART;
this->SetUnicodeGlyph(_default_unicode_map[i].code, sprite);
}
}
}
|