← API Reference Class

asge::media::Font

#include <Font.hpp>

Private Attributes

#std::unordered_map< char32_t, GlyphMetrics > m_Glyphsprivate
#Image m_AtlasImageprivate
#int m_LineHeightprivate
#int m_Ascentprivate
#int m_Descentprivate

Private Member Functions

#Font(std::unordered_map< char32_t, GlyphMetrics > inGlyphs, Image inAtlasImage, int inLineHeight, int inAscent, int inDescent) noexceptprivate

Public Member Functions

#Font()=delete
#Font(Font const &)=delete
#Font & operator=(Font const &)=delete
#Font(Font &&)=default
#Font & operator=(Font &&)=default
#Result< GlyphMetrics > GetGlyph(char32_t inCodepoint) const
#const media::Image & GetAtlasImage() const noexcept
#int GetLineHeight() const noexcept
#int GetAscent() const noexcept
#int GetDescent() const noexcept
#math::Float2 Measure(str::StringView inText) const noexcept
#str::String WrapText(str::StringView inText, float inMaxWidth) const noexcept

Greedy word-wraps inText to inMaxWidth pixels by inserting a newline at spaces.

Existing newlines are kept; a word wider than inMaxWidth gets its own line, not split.

Static Public Member Functions

#static Result< Font > Load(const filesystem::Path &inPath, int inPixelHeight)

Loads a TTF file and bakes ASCII 32-126 into a single atlas.

Parameters
inPath

Path to the .ttf file.

inPixelHeight

Pixel height to bake glyphs at.

#static math::Int2 GetAtlasSize() noexcept

The fixed pixel dimensions of the atlas bitmap every Font bakes its glyphs into.

Same for every Font regardless of source file or requested pixel height Load's ASCII 32-126 bake fails (FontError::BakeFailed) once a requested height's glyphs no longer all fit within it. There's no formula from this alone to a given font's own actual max safe pixel height, since that also depends on that font's own glyph shapes; this just gives a caller (e.g. an editor's Font Size field) something concrete to reason about instead of an arbitrary guess.

#static Result< int > FindMaxPixelHeight(const filesystem::Path &inPath, int inUpperBound=512)

The largest pixel height inPath's own font can be baked at without its glyphs overflowing GetAtlasSize()'s fixed bitmap.

Found by binary search using Load itself as the oracle at each candidate height there's no direct formula for this (see GetAtlasSize's own doc comment for why), but Load's own success/ failure at a given height is exact, so the result here is too, not a heuristic. Fails with whatever error Load itself hits at 1px (e.g. the file isn't a valid font at all) rather than a "too big" one.

Parameters
inUpperBound

Highest pixel height the search considers; defaults to the atlas's own height, since no font can plausibly still fit beyond that.