From a25b699966cb27246741fcda296a8946dd3cba53 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sat, 27 Apr 2024 06:46:20 +1000 Subject: [PATCH] Update StarFont.cpp --- source/core/StarFont.cpp | 13 +++++++++---- source/core/StarFont.hpp | 2 -- 2 files changed, 9 insertions(+), 6 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 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; diff --git a/source/core/StarFont.hpp b/source/core/StarFont.hpp index 6686dbc..e62e91b 100644 --- a/source/core/StarFont.hpp +++ b/source/core/StarFont.hpp @@ -41,8 +41,6 @@ private: FontImplPtr m_fontImpl; ByteArrayConstPtr m_fontBuffer; unsigned m_pixelSize; - unsigned m_loadedPixelSize; - String::Char m_loadedChar; uint8_t m_alphaThreshold; HashMap, unsigned> m_widthCache;