Make measure string go brrrrrrr
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 4m9s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 4m9s
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_OUTLINE_H
|
||||
#include <JGL/FontCache.h>
|
||||
|
||||
#endif
|
||||
#if _WIN32
|
||||
#include <ft2build.h>
|
||||
@@ -94,7 +96,7 @@ namespace JGL
|
||||
return Font(path);
|
||||
}
|
||||
|
||||
Vector2 Font::MeasureString(const std::string &text, float ptSize) {
|
||||
Vector2 Font::MeasureString(const std::string &text, unsigned int ptSize) {
|
||||
|
||||
// TODO: Check if a font of that size is in the cache and if so use the info from that because this is sloooooooooooooow.
|
||||
// That'll make it go vroom vroom.
|
||||
@@ -102,12 +104,32 @@ namespace JGL
|
||||
// This is likely returning slightly incorrect results for likely several reasons.
|
||||
// Half-ass solution for now ~ dawsh.
|
||||
|
||||
FT_BBox glyph_bbox;
|
||||
Vector2 extents = Vector2(0,0);
|
||||
bool font_of_size_in_cache = false;
|
||||
|
||||
for(const auto& f : fontCache.getFonts()) {
|
||||
if (f->getFontSize() == ptSize) {
|
||||
font_of_size_in_cache = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (font_of_size_in_cache) {
|
||||
CachedFont* font;
|
||||
|
||||
for (auto* f: fontCache.getFonts())
|
||||
if (f->getFontSize() == ptSize)
|
||||
font = f;
|
||||
|
||||
for (const char& c : text)
|
||||
extents.x += font->getGlyph(c)->advanceX;
|
||||
|
||||
extents.y = ptSize;
|
||||
return extents;
|
||||
}
|
||||
|
||||
FT_Set_Pixel_Sizes(this->face, ptSize, ptSize);
|
||||
|
||||
Vector2 extents = Vector2(0,0);
|
||||
|
||||
for (const char& c : text) {
|
||||
|
||||
FT_GlyphSlot slot = face->glyph;
|
||||
@@ -136,8 +158,6 @@ namespace JGL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return extents;
|
||||
}
|
||||
|
||||
|
@@ -18,8 +18,6 @@
|
||||
|
||||
namespace JGL {
|
||||
|
||||
FontCache fontCache; // <-- Not implemented yet
|
||||
|
||||
void PurgeFontCache() {
|
||||
fontCache.purgeCache();
|
||||
}
|
||||
|
Reference in New Issue
Block a user