diff --git a/src/render/render.cpp b/src/render/render.cpp index a819aad..4c2911a 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -286,9 +286,11 @@ void UiCanvas::DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color) double s0, t0, s1, t1; size_t w, h; - if(font->LocateGlyph(codepoint, &s0, &t0, &s1, &t1, &w, &h)) { + font->LocateGlyph(codepoint, &s0, &t0, &s1, &t1, &w, &h); + if(font->textureUpdated) { // LocateGlyph modified the texture, reload it. canvas->InvalidatePixmap(font->texture); + font->textureUpdated = false; } canvas->DrawPixmap(font->texture, diff --git a/src/resource.cpp b/src/resource.cpp index 7980b57..d2d4b21 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -545,6 +545,7 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) { } it = glyphs.emplace(codepoint, std::move(glyph)).first; + textureUpdated = true; return (*it).second; } @@ -553,10 +554,9 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) { return GetGlyph(0xfffd); } -bool BitmapFont::LocateGlyph(char32_t codepoint, +void BitmapFont::LocateGlyph(char32_t codepoint, double *s0, double *t0, double *s1, double *t1, size_t *w, size_t *h) { - bool textureUpdated = (glyphs.find(codepoint) == glyphs.end()); const Glyph &glyph = GetGlyph(codepoint); *w = glyph.advanceCells * 8; *h = 16; @@ -564,7 +564,6 @@ bool BitmapFont::LocateGlyph(char32_t codepoint, *s1 = *s0 + (double)(*w) / texture->width; *t0 = (16.0 * (glyph.position / (texture->width / 16))) / texture->height; *t1 = *t0 + (double)(*h) / texture->height; - return textureUpdated; } size_t BitmapFont::GetWidth(char32_t codepoint) { diff --git a/src/resource.h b/src/resource.h index 41fef78..200f240 100644 --- a/src/resource.h +++ b/src/resource.h @@ -58,6 +58,7 @@ public: std::string unifontData; std::map glyphs; std::shared_ptr texture; + bool textureUpdated; uint16_t nextPosition; static BitmapFont From(std::string &&unifontData); @@ -65,7 +66,7 @@ public: bool IsEmpty() const { return unifontData.empty(); } const Glyph &GetGlyph(char32_t codepoint); - bool LocateGlyph(char32_t codepoint, double *s0, double *t0, double *s1, double *t1, + void LocateGlyph(char32_t codepoint, double *s0, double *t0, double *s1, double *t1, size_t *advanceWidth, size_t *boundingHeight); void AddGlyph(char32_t codepoint, std::shared_ptr pixmap);