asge::media::Font
#include <Font.hpp>Private Attributes
Private Member Functions
Font(std::unordered_map< char32_t, GlyphMetrics > inGlyphs, Image inAtlasImage, int inLineHeight, int inAscent, int inDescent) noexceptprivatePublic Member Functions
Font()=deleteFont(Font const &)=deleteFont(Font &&)=defaultResult< GlyphMetrics > GetGlyph(char32_t inCodepoint) constconst media::Image & GetAtlasImage() const noexceptint GetLineHeight() const noexceptint GetAscent() const noexceptint GetDescent() const noexceptmath::Float2 Measure(str::StringView inText) const noexceptstr::String WrapText(str::StringView inText, float inMaxWidth) const noexceptGreedy 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
Loads a TTF file and bakes ASCII 32-126 into a single atlas.
inPath | Path to the .ttf file. |
inPixelHeight | Pixel height to bake glyphs at. |
static math::Int2 GetAtlasSize() noexceptThe 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.
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.
inUpperBound | Highest pixel height the search considers; defaults to the atlas's own height, since no font can plausibly still fit beyond that. |