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
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 4m39s
This commit is contained in:
3
main.cpp
3
main.cpp
@@ -123,6 +123,9 @@ public:
|
||||
auto result = Jupiteroid->MeasureString("Jupiteroid Font", 16);
|
||||
DEBUG(std::format("Result: {},{}", result.x, result.y ));
|
||||
|
||||
// TODO: Note the discrepancy in Y between the FillRect and DrawString call here.
|
||||
J2D::FillRect(JGL::Colors::Gray, {0, 0}, result);
|
||||
// TODO: Does text render from the middle-point of the glyphs?
|
||||
J2D::DrawString(JGL::Colors::Green, "Jupteroid Font", 0.f, 16, 1.f, 16, *Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, 33, 1,16, *Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, 50, 1,16, *Jupiteroid);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
if (extents.y == 0)
|
||||
// Just fucking hardcode it, we know the glyph height is roughly always the ptSize anyway.
|
||||
if (extents.y < ptSize)
|
||||
{
|
||||
extents.y = face->bbox.yMax / 64;
|
||||
extents.y = ptSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return extents;
|
||||
}
|
||||
|
Reference in New Issue
Block a user