|
OpenTTD Source
14.0-beta3
|
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"
53 SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
73 default: NOT_REACHED();
75 case FS_NORMAL: base = SPR_ASCII_SPACE;
break;
76 case FS_SMALL: base = SPR_ASCII_SPACE_SMALL;
break;
77 case FS_LARGE: base = SPR_ASCII_SPACE_BIG;
break;
82 if (!SpriteExists(sprite))
continue;
87 for (uint i = 0; i <
lengthof(_default_unicode_map); i++) {
88 byte key = _default_unicode_map[i].key;
108 for (uint i = 0; i < 256; i++) {
124 SpriteID sprite = this->GetUnicodeGlyph(key);
125 if (sprite == 0) sprite = this->GetUnicodeGlyph(
'?');
131 SpriteID sprite = this->GetUnicodeGlyph(key);
132 if (sprite == 0) sprite = this->GetUnicodeGlyph(
'?');
const Sprite * GetGlyph(GlyphID key) override
Get the glyph (sprite) of the given key.
int height
The height of the font.
uint GetGlyphWidth(GlyphID key) override
Get the width of the glyph with the given key.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
void InitializeUnicodeGlyphMap() override
Initialize the glyph map.
@ FS_LARGE
Index of the large font in the font tables.
static void ResetFontCache(FontSize size)
Reset cached font information.
@ Font
A sprite used for fonts.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
void SetUnicodeGlyph(char32_t key, SpriteID sprite) override
Map a SpriteID to the key.
@ FS_NORMAL
Index of the normal font in the font tables.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
@ FS_SMALL
Index of the small font in the font tables.
uint16_t width
Width of the sprite.
bool GetDrawGlyphShadow() override
Do we need to draw a glyph shadow?
uint32_t GlyphID
Glyphs are characters from a font.
SpriteID ** glyph_to_spriteid_map
Mapping of glyphs to sprite IDs.
const FontSize fs
The size of the font.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
static const byte CLRA
Identifier to clear all glyphs at this codepoint.
ZoomLevel _font_zoom
Sprite font Zoom level (not clamped)
void ClearFontCache() override
Clear the font cache.
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Font cache for basic fonts.
static const int ASCII_LETTERSTART
First printable ASCII letter.
int ascender
The ascender value of the font.
~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.
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to font zoom level, for drawing sprite fonts.
void ClearGlyphToSpriteMap()
Clear the glyph to sprite mapping.
FontSize
Available font sizes.
SpriteFontCache(FontSize fs)
Create a new sprite font cache.
Data structure describing a sprite.