10#include "resource/resource.h"
11#include "resource/resource_handle.h"
13namespace Vkm::Engine {
22 glm::vec2 uvMin = {0.0f, 0.0f};
23 glm::vec2 uvMax = {0.0f, 0.0f};
24 glm::vec2
size = {0.0f, 0.0f};
55 static constexpr uint32_t
MARKS[] = {
69 static constexpr uint32_t MARK_COUNT =
sizeof(
MARKS) /
sizeof(
MARKS[0]);
70 static constexpr uint32_t GLYPH_COUNT = ASCII_COUNT + LATIN1_COUNT + MARK_COUNT;
83 float pixelHeight = 0.0f;
95 std::array<FontGlyph, GLYPH_COUNT> glyphs{};
111 return static_cast<int>(ASCII_COUNT + codepoint -
LATIN1_FIRST);
113 for (uint32_t i = 0; i < MARK_COUNT; ++i) {
114 if (
MARKS[i] == codepoint)
return static_cast<int>(ASCII_COUNT + LATIN1_COUNT + i);
126 if (index < ASCII_COUNT)
return ASCII_FIRST + index;
127 if (index < ASCII_COUNT + LATIN1_COUNT)
return LATIN1_FIRST + index - ASCII_COUNT;
128 return MARKS[index - ASCII_COUNT - LATIN1_COUNT];
139 return index < 0 ? nullptr : &glyphs[static_cast<size_t>(index)];
150 float kern(
int left,
int right)
const {
151 const uint32_t pair =
static_cast<uint32_t
>(left) * GLYPH_COUNT +
static_cast<uint32_t
>(right);
152 const auto found = std::lower_bound(
156 [](
const KerningPair& entry, uint32_t key) { return entry.pair < key; }
158 return (found !=
kerning.end() && found->pair == pair) ? found->adjust : 0.0f;
162using FontHandle = Handle<FontAsset>;
A TrueType font baked to a signed-distance-field atlas.
Definition font_asset.h:48
static constexpr char32_t codepointAt(uint32_t index)
The codepoint glyph index holds; the inverse of glyphIndex.
Definition font_asset.h:125
std::vector< uint8_t > atlasPixels
Single-channel SDF atlas, atlasSize x atlasSize texels.
Definition font_asset.h:80
static constexpr uint32_t ASCII_FIRST
Space.
Definition font_asset.h:49
static constexpr uint32_t LATIN1_FIRST
No-break space.
Definition font_asset.h:51
uint32_t atlasSize
Atlas dimension in texels (square).
Definition font_asset.h:81
static constexpr uint32_t LATIN1_LAST
y with diaeresis.
Definition font_asset.h:52
float lineHeight
Baseline-to-baseline distance for stacked lines, in baked pixels.
Definition font_asset.h:93
float ascent
Definition font_asset.h:84
static constexpr uint32_t MARKS[]
Dashes, curly quotes, the bullet, the ellipsis and the euro sign, ascending.
Definition font_asset.h:55
float descent
Baseline-to-bottom, in baked pixels (negative below the baseline).
Definition font_asset.h:86
const FontGlyph * glyph(char32_t codepoint) const
The glyph for codepoint.
Definition font_asset.h:137
static constexpr uint32_t MIP_LEVELS
How many levels of the atlas a renderer may sample, the full size included.
Definition font_asset.h:78
float kern(int left, int right) const
The kerning between glyph left and glyph right, in baked pixels.
Definition font_asset.h:150
static constexpr uint32_t ASCII_LAST
'~'.
Definition font_asset.h:50
static constexpr int glyphIndex(char32_t codepoint)
Where codepoint sits in the glyph table.
Definition font_asset.h:106
std::vector< KerningPair > kerning
Sorted on KerningPair::pair; unkerned pairs are absent.
Definition font_asset.h:98
One glyph's atlas placement and layout metrics, in baked pixels.
Definition font_asset.h:21
glm::vec2 offset
Quad top-left relative to the pen on the baseline (negative y is above it).
Definition font_asset.h:26
glm::vec2 size
Definition font_asset.h:24
float advance
Pen advance in baked pixels.
Definition font_asset.h:27
How far the pen moves between one glyph and the next, past their advances.
Definition font_asset.h:36
float adjust
Added to the left glyph's advance, in baked pixels; negative pulls together.
Definition font_asset.h:38