diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-04-27 06:46:20 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-04-27 06:46:20 +1000 |
commit | a25b699966cb27246741fcda296a8946dd3cba53 (patch) | |
tree | 2c29c4106b6ac408fd8b89aa7460811a5db079e9 /source/core/StarFont.cpp | |
parent | 929c75c3641aa0a3b31aba39fa0612c88d19289a (diff) |
Update StarFont.cpp
Diffstat (limited to 'source/core/StarFont.cpp')
-rw-r--r-- | source/core/StarFont.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/core/StarFont.cpp b/source/core/StarFont.cpp index 7155d69..47569f2 100644 --- a/source/core/StarFont.cpp +++ b/source/core/StarFont.cpp @@ -30,6 +30,8 @@ FTContext ftContext; struct FontImpl { FT_Face face; + unsigned loadedPixelSize = 0; + String::Char loadedChar = 0; }; FontPtr Font::loadFont(String const& fileName, unsigned pixelSize) { @@ -95,20 +97,23 @@ tuple<Image, Vec2I, bool> Font::render(String::Char c) { throw FontException("Font::render called on uninitialized font."); FT_Face face = m_fontImpl->face; - if (m_loadedPixelSize != m_pixelSize || m_loadedChar != c) { + + if (m_fontImpl->loadedPixelSize != m_pixelSize || m_fontImpl->loadedChar != c) { FT_UInt glyph_index = FT_Get_Char_Index(face, c); if (FT_Load_Glyph(face, glyph_index, FontLoadFlags) != 0) return {}; - /* convert to an anti-aliased bitmap */ + // convert to an anti-aliased bitmap if (FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL) != 0) return {}; } - m_loadedPixelSize = m_pixelSize; - m_loadedChar = c; + m_fontImpl->loadedPixelSize = m_pixelSize; + m_fontImpl->loadedChar = c; FT_GlyphSlot slot = face->glyph; + if (!slot->bitmap.buffer) + return {}; unsigned width = slot->bitmap.width; unsigned height = slot->bitmap.rows; |