19typedef uint32_t GlyphID;
20static const GlyphID SPRITE_GLYPH = 1U << 30;
33 static void Register(std::unique_ptr<FontCache> &&fc);
51 static void AddFallback(FontSizes fontsizes, std::string_view name,
const std::any &os_handle = {});
53 static bool TryFallback(FontSizes fontsizes,
const std::set<char32_t> &glyphs,
const std::string &name,
const std::any &os_handle = {});
65 inline int GetHeight()
const {
return this->height; }
150 return this->parent !=
nullptr;
184inline bool GetDrawGlyphShadow(
FontSize size)
217 default: NOT_REACHED();
227bool GetFontAAState();
228void SetFont(
FontSize fontsize,
const std::string &font, uint size);
241 ProviderManager<FontCacheFactory>::Register(*
this);
247 ProviderManager<FontCacheFactory>::Unregister(*
this);
259 virtual std::unique_ptr<FontCache>
LoadFont(
FontSize fs,
FontType fonttype,
bool search,
const std::string &font_name,
const std::any &os_handle)
const = 0;
273 static std::unique_ptr<FontCache>
LoadFont(
FontSize fs,
FontType fonttype,
bool search,
const std::string &font_name,
const std::any &os_handle = {});
constexpr BaseProvider(std::string_view name, std::string_view description)
const std::string_view name
const std::string_view description
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific enum class.
virtual std::unique_ptr< FontCache > LoadFont(FontSize fs, FontType fonttype, bool search, const std::string &font_name, const std::any &os_handle) const =0
Try loading a font with this factory.
~FontCacheFactory() override
Unregister this factory.
virtual bool FindFallbackFont(const std::string &language_isocode, class MissingGlyphSearcher *callback) const =0
We would like to have a fallback font as the current one doesn't contain all characters we need.
Font cache for basic fonts.
virtual std::string GetFontName()=0
Get the name of this font.
int GetHeight() const
Get the height of the font.
virtual void ClearFontCache()=0
Clear the font cache.
static void UninitializeFontCaches()
Free everything allocated w.r.t.
int height
The height of the font.
virtual ~FontCache()=default
Ensure the destructor of the sub classes are called as well.
bool HasParent()
Check whether the font cache has a parent.
virtual int GetFontSize() const
Get the nominal font size of the font.
std::unique_ptr< FontCache > parent
The parent of this font cache.
virtual const void * GetOSHandle()
Get the native OS font handle, if there is one.
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
static const EnumClassIndexContainer< std::array< int, to_underlying(FontSize::End)>, FontSize > DEFAULT_FONT_ASCENDER
Default unscaled font ascenders.
virtual bool IsBuiltInFont()=0
Is this a built-in sprite font?
virtual const Sprite * GetGlyph(GlyphID key)=0
Get the glyph (sprite) of the given key.
static const EnumClassIndexContainer< std::array< int, to_underlying(FontSize::End)>, FontSize > DEFAULT_FONT_HEIGHT
Default unscaled font heights.
static void AddFallback(FontSizes fontsizes, std::string_view name, const std::any &os_handle={})
Add a fallback font, with optional OS-specific handle.
static void ClearFontCaches(FontSizes fontsizes)
Clear cached information for the specified font caches.
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
static void Register(std::unique_ptr< FontCache > &&fc)
Register a FontCache for its font size.
const FontSize fs
The size of the font.
static std::string GetName(FontSize fs)
Get the font name of a given font size.
int GetAscender() const
Get the ascender value of the font.
static void LoadFontCaches(FontSizes fontsizes)
(Re)initialize the font cache related things, i.e.
int descender
The descender value of the font.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
FontSize GetSize() const
Get the FontSize of the font.
int GetDescender() const
Get the descender value of the font.
static bool TryFallback(FontSizes fontsizes, const std::set< char32_t > &glyphs, const std::string &name, const std::any &os_handle={})
Test a fallback font, with optional OS-specific handle, for specific glyphs.
virtual bool GetDrawGlyphShadow()=0
Do we need to draw a glyph shadow?
static void InitializeFontCaches()
Initialise font caches with the base sprite font cache for all sizes.
static EnumClassIndexContainer< std::array< std::unique_ptr< FontCache >, to_underlying(FontSize::End)>, FontSize > caches
All the font caches.
int ascender
The ascender value of the font.
static std::unique_ptr< FontCache > LoadFont(FontSize fs, FontType fonttype, bool search, const std::string &font_name, const std::any &os_handle={})
Try loading a font with any fontcache factory.
static bool FindFallbackFont(const std::string &language_isocode, MissingGlyphSearcher *callback)
We would like to have a fallback font as the current one doesn't contain all characters we need.
A searcher for missing glyphs.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
void SetUnicodeGlyph(FontSize size, char32_t key, SpriteID sprite)
Set the SpriteID for a unicode character.
const Sprite * GetGlyph(FontSize size, char32_t key)
Get the Sprite for a glyph.
FontType
Different types of font that can be loaded.
@ TrueType
Scalable TrueType fonts.
uint GetGlyphWidth(FontSize size, char32_t key)
Get the width of a glyph.
void InitializeUnicodeGlyphMap()
Initialize the glyph map.
uint GetFontCacheFontSize(FontSize fs)
Get the scalable font size to use for a FontSize.
FontCacheSubSetting * GetFontCacheSubSetting(FontSize fs)
Get the settings of a given font size.
uint32_t GlyphID
Glyphs are characters from a font.
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
FontSize
Available font sizes.
@ Small
Index of the small font in the font tables.
@ Large
Index of the large font in the font tables.
@ End
Marker for the end of the enumerations.
@ Normal
Index of the normal font in the font tables.
@ Monospace
Index of the monospaced font in the font tables.
Definition of the ProviderManager.
Types related to the sprite cache.
Settings for the four different fonts.
FontCacheSubSetting large
The largest font; mostly used for newspapers.
FontCacheSubSetting mono
The mono space font used for license/readme viewers.
FontCacheSubSetting medium
The normal font size.
bool prefer_sprite
Whether to prefer the built-in sprite font over resizable fonts.
FontCacheSubSetting small
The smallest font; mostly used for zoomed out view.
bool global_aa
Whether to anti alias all font sizes.
Settings for a single font.
std::any os_handle
Optional native OS font info.
std::string font
The name of the font, or path to the font.
uint size
The (requested) size of the font.
Data structure describing a sprite.