vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::FontAsset Struct Reference

A TrueType font baked to a signed-distance-field atlas. More...

#include <font_asset.h>

Inheritance diagram for Vkm::Engine::FontAsset:
Vkm::Engine::Resource

Public Member Functions

const FontGlyph * glyph (char32_t codepoint) const
 The glyph for codepoint.
float kern (int left, int right) const
 The kerning between glyph left and glyph right, in baked pixels.
Public Member Functions inherited from Vkm::Engine::Resource
 Resource (const Resource &other)
 Duplicate other's contents and name, but not its identity.
const std::string & name () const noexcept
 Serializable identity; non-empty and unique within its type once added.
uint64_t uid () const noexcept
 Process-unique id stamped by add(); names the asset, not the slot it sits in.
uint64_t version () const noexcept
 Change counter the backend keys GPU re-uploads on; moved by commit().
bool isHidden () const noexcept
 Added by ResourceManager::addPrivate: not user-facing, not saved.
nlohmann::json & sourceJson ()
 Mutable source JSON, allocating a null document if there is none.
const nlohmann::json & sourceJson () const
 Const source JSON; asserts hasSource(), so guard the call with it.

Static Public Member Functions

static constexpr int glyphIndex (char32_t codepoint)
 Where codepoint sits in the glyph table.
static constexpr char32_t codepointAt (uint32_t index)
 The codepoint glyph index holds; the inverse of glyphIndex.

Public Attributes

std::vector< uint8_t > atlasPixels
 Single-channel SDF atlas, atlasSize x atlasSize texels.
uint32_t atlasSize = 0
 Atlas dimension in texels (square).
float ascent = 0.0f
float descent = 0.0f
 Baseline-to-bottom, in baked pixels (negative below the baseline).
float lineHeight = 0.0f
 Baseline-to-baseline distance for stacked lines, in baked pixels.
std::vector< KerningPair > kerning
 Sorted on KerningPair::pair; unkerned pairs are absent.

Static Public Attributes

static constexpr uint32_t ASCII_FIRST = 0x20
 Space.
static constexpr uint32_t ASCII_LAST = 0x7E
 '~'.
static constexpr uint32_t LATIN1_FIRST = 0xA0
 No-break space.
static constexpr uint32_t LATIN1_LAST = 0xFF
 y with diaeresis.
static constexpr uint32_t MARKS []
 Dashes, curly quotes, the bullet, the ellipsis and the euro sign, ascending.
static constexpr uint32_t MIP_LEVELS = 4
 How many levels of the atlas a renderer may sample, the full size included.

Detailed Description

A TrueType font baked to a signed-distance-field atlas.

Covers printable ASCII, printable Latin-1 and MARKS; one bake renders cleanly to roughly three times its baked height. Self-contained (pixels, no texture handle), so ResourceManager::swap can keep the slot across a scene load.

Member Function Documentation

◆ glyphIndex()

constexpr int Vkm::Engine::FontAsset::glyphIndex ( char32_t codepoint)
inlinestaticconstexpr

Where codepoint sits in the glyph table.

Parameters
codepointThe character.
Returns
Its index, or -1 when a bake does not cover it.

◆ codepointAt()

constexpr char32_t Vkm::Engine::FontAsset::codepointAt ( uint32_t index)
inlinestaticconstexpr

The codepoint glyph index holds; the inverse of glyphIndex.

Parameters
indexGlyph table index, below GLYPH_COUNT.
Returns
The character at that index.

◆ glyph()

const FontGlyph * Vkm::Engine::FontAsset::glyph ( char32_t codepoint) const
inline

The glyph for codepoint.

Parameters
codepointThe character.
Returns
Its glyph, or nullptr when a bake does not cover it.

◆ kern()

float Vkm::Engine::FontAsset::kern ( int left,
int right ) const
inline

The kerning between glyph left and glyph right, in baked pixels.

Parameters
leftGlyph index of the earlier glyph.
rightGlyph index of the one after it.
Returns
The adjustment to the left glyph's advance; zero for a pair the face does not kern.

Member Data Documentation

◆ MIP_LEVELS

uint32_t Vkm::Engine::FontAsset::MIP_LEVELS = 4
staticconstexpr

How many levels of the atlas a renderer may sample, the full size included.

bakeFontSDF's gutter is 2^(MIP_LEVELS - 1) texels; more levels would bleed neighbouring glyphs together.

◆ ascent

float Vkm::Engine::FontAsset::ascent = 0.0f

Baseline-to-top, in baked pixels (positive).

◆ lineHeight

float Vkm::Engine::FontAsset::lineHeight = 0.0f

Baseline-to-baseline distance for stacked lines, in baked pixels.

The face's own ascent - descent + line gap.


The documentation for this struct was generated from the following file: