Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../fontcache.h"
12 #include "../gfx_layout.h"
13 #include "../zoom_func.h"
16 #include "../table/sprites.h"
17 #include "../table/control_codes.h"
18 #include "../table/unicode.h"
20 #include "../safeguards.h"
63 default: NOT_REACHED();
65 case FS_NORMAL: base = SPR_ASCII_SPACE;
break;
66 case FS_SMALL: base = SPR_ASCII_SPACE_SMALL;
break;
67 case FS_LARGE: base = SPR_ASCII_SPACE_BIG;
break;
72 if (!SpriteExists(sprite))
continue;
77 for (uint i = 0; i <
lengthof(_default_unicode_map); i++) {
78 byte key = _default_unicode_map[i].key;
98 for (uint i = 0; i < 256; i++) {
114 SpriteID sprite = this->GetUnicodeGlyph(key);
115 if (sprite == 0) sprite = this->GetUnicodeGlyph(
'?');
116 return GetSprite(sprite,
ST_FONT);
121 SpriteID sprite = this->GetUnicodeGlyph(key);
122 if (sprite == 0) sprite = this->GetUnicodeGlyph(
'?');
uint32 GlyphID
Glyphs are characters from a font.
virtual void InitializeUnicodeGlyphMap()
Initialize the glyph map.
char32_t WChar
Type for wide characters, i.e.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
@ ST_FONT
A sprite used for fonts.
virtual uint GetGlyphWidth(GlyphID key)
Get the width of the glyph with the given key.
int height
The height of the font.
@ FS_LARGE
Index of the large font in the font tables.
static void ResetFontCache(FontSize size)
Reset cached font information.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
@ FS_NORMAL
Index of the normal font in the font tables.
@ FS_SMALL
Index of the small font in the font tables.
static int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
SpriteID ** glyph_to_spriteid_map
Mapping of glyphs to sprite IDs.
const FontSize fs
The size of the font.
virtual bool GetDrawGlyphShadow()
Do we need to draw a glyph shadow?
static const byte CLRA
Identifier to clear all glyphs at this codepoint.
Font cache for basic fonts.
virtual void SetUnicodeGlyph(WChar key, SpriteID sprite)
Map a SpriteID to the key.
static const int ASCII_LETTERSTART
First printable ASCII letter.
int ascender
The ascender value of the font.
virtual void ClearFontCache()
Clear the font cache.
~SpriteFontCache()
Free everything we allocated.
#define lengthof(x)
Return the length of an fixed size array.
@ FS_MONO
Index of the monospaced font in the font tables.
void ClearGlyphToSpriteMap()
Clear the glyph to sprite mapping.
FontSize
Available font sizes.
virtual const Sprite * GetGlyph(GlyphID key)
Get the glyph (sprite) of the given key.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
SpriteFontCache(FontSize fs)
Create a new sprite font cache.
Data structure describing a sprite.