Testing MeasureString with underlaid box. But it appears to be offset by half-height?
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 4m39s

This commit is contained in:
2024-07-17 15:19:38 -04:00
parent 480502f89e
commit 3a658b1096
2 changed files with 19 additions and 8 deletions

View File

@@ -121,10 +121,11 @@ namespace JGL
FT_BBox glyph_bbox;
FT_Set_Pixel_Sizes(this->face, ptSize, ptSize);
Vector2 extents = Vector2(0,0);
for (const char& c : text)
{
for (const char& c : text) {
FT_GlyphSlot slot = face->glyph;
auto glyph_index = FT_Get_Char_Index(this->face, c);
@@ -134,18 +135,25 @@ namespace JGL
continue;
Vector2 advance = {static_cast<float>(slot->advance.x >> 6),
static_cast<float>(slot->advance.y >> 6)};
extents += advance;
// Gives smaller results than we'd want.
if (extents.y < slot->metrics.height / 64) {
extents.y = slot->metrics.height / 64;
}
// Just fucking hardcode it, we know the glyph height is roughly always the ptSize anyway.
if (extents.y < ptSize)
{
extents.y = ptSize;
}
}
if (extents.y == 0)
{
extents.y = face->bbox.yMax / 64;
}
return extents;
}