11#include "../fontcache.h"
12#include "../gfx_layout.h"
13#include "../spritecache.h"
14#include "../string_func.h"
15#include "../zoom_func.h"
18#include "../table/sprites.h"
19#include "../table/control_codes.h"
20#include "../table/unicode.h"
22#include "../safeguards.h"
26static std::array<std::unordered_map<char32_t, SpriteID>, FS_END>
_char_maps{};
36 if (found != std::end(
_char_maps[fs]))
return found->second;
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;
78 for (
const auto &unicode_map : _default_unicode_map) {
79 uint8_t key = unicode_map.key;
87 if (!SpriteExists(sprite))
continue;
109 this->UpdateMetrics();
115 this->UpdateMetrics();
118void SpriteFontCache::UpdateMetrics()
126int SpriteFontCache::GetGlyphYOffset()
128 return FontCache::GetFontBaseline(this->
fs) - this->scaled_ascender;
147 assert(IsPrintable(key));
149 if (sprite == 0)
return 0;
150 return static_cast<GlyphID>(sprite);
162 std::unique_ptr<FontCache> LoadFont(
FontSize fs,
FontType fonttype,
bool,
const std::string &, std::span<const std::byte>)
const override
166 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.
static const int DEFAULT_FONT_ASCENDER[FS_END]
Default unscaled font ascenders.
static const int DEFAULT_FONT_HEIGHT[FS_END]
Default unscaled font heights.
int descender
The descender value of the font.
int ascender
The ascender value of the font.
static void ResetFontCache(FontSize fs)
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) 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.
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.
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.
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 ScaleFontTrad(int value)
Scale traditional pixel dimensions to font zoom level, for drawing sprite fonts.