11#include "../fontcache.h"
12#include "../gfx_layout.h"
13#include "../string_func.h"
14#include "../zoom_func.h"
17#include "../table/sprites.h"
18#include "../table/control_codes.h"
19#include "../table/unicode.h"
21#include "../safeguards.h"
35static std::array<std::unordered_map<char32_t, SpriteID>, FS_END>
_char_maps{};
45 if (found != std::end(
_char_maps[fs]))
return found->second;
72 default: NOT_REACHED();
74 case FS_NORMAL: base = SPR_ASCII_SPACE;
break;
75 case FS_SMALL: base = SPR_ASCII_SPACE_SMALL;
break;
76 case FS_LARGE: base = SPR_ASCII_SPACE_BIG;
break;
81 if (!SpriteExists(sprite))
continue;
87 for (
const auto &unicode_map : _default_unicode_map) {
88 uint8_t key = unicode_map.key;
144 assert(IsPrintable(key));
146 if (sprite == 0)
return 0;
147 return SPRITE_GLYPH | sprite;
159 std::unique_ptr<FontCache> LoadFont(
FontSize fs,
FontType fonttype)
override
163 return std::make_unique<SpriteFontCache>(fs);
Font cache for basic fonts.
int height
The height of the font.
const FontSize fs
The size of the font.
int ascender
The ascender value of the font.
static void ResetFontCache(FontSize size)
Reset cached font information.
A searcher for missing glyphs.
SpriteFontCache(FontSize fs)
Create a new sprite font cache.
uint GetGlyphWidth(GlyphID key) override
Get the width of the glyph with the given key.
GlyphID MapCharToGlyph(char32_t key, bool allow_fallback=true) override
Map a character into a glyph.
bool GetDrawGlyphShadow() override
Do we need to draw a glyph shadow?
void ClearFontCache() override
Clear the font cache.
const Sprite * GetGlyph(GlyphID key) override
Get the glyph (sprite) of the given key.
FontType
Different types of font that can be loaded.
@ Sprite
Bitmap sprites from GRF files.
uint32_t GlyphID
Glyphs are characters from a font.
ZoomLevel _font_zoom
Sprite font Zoom level (not clamped)
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ Font
A sprite used for fonts.
FontSize
Available font sizes.
@ FS_MONO
Index of the monospaced font in the font tables.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
@ FS_LARGE
Index of the large font in the font tables.
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to font zoom level, for drawing sprite fonts.
void SetUnicodeGlyph(FontSize fs, char32_t key, SpriteID sprite)
Set the SpriteID for a unicode character.
static const int ASCII_LETTERSTART
First printable ASCII letter.
static std::array< std::unordered_map< char32_t, SpriteID >, FS_END > _char_maps
Glyph map for each font size.
void InitializeUnicodeGlyphMap()
Initialize the glyph map.
static SpriteID GetUnicodeGlyph(FontSize fs, char32_t key)
Get SpriteID associated with a character.
Sprite font cache implementation definition.
Settings for the four different fonts.
Data structure describing a sprite.
uint16_t width
Width of the sprite.
static const uint8_t CLRA
Identifier to clear all glyphs at this codepoint.
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZoomLevel::Min) When shifting right,...