This commit is contained in:
Jorijn van der Graaf 2026-04-16 23:03:24 +02:00
commit c9ebd448f9
7 changed files with 278 additions and 73 deletions

View file

@ -56,4 +56,15 @@ Font::Font(const std::filesystem::path& fontFilePath) {
this->ascent = ascent;
this->descent = descent;
this->lineGap = lineGap;
}
std::uint32_t Font::GetLineWidth(const std::string_view text, float size) {
float scale = stbtt_ScaleForPixelHeight(&font, size);
std::uint32_t lineWidth = 0;
for (const char c : text) {
int advance, lsb;
stbtt_GetCodepointHMetrics(&font, c, &advance, &lsb);
lineWidth += (int)(advance * scale);
}
return lineWidth;
}