From 91d3f3a43a56b118703695cf544aa30e42e2b41d Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 4 Aug 2024 12:16:13 +0200 Subject: [PATCH] Fixed a regression where text shaping stopped working --- es-core/src/resources/Font.cpp | 24 ++++++++++++------------ es-core/src/resources/Font.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index 59407c680..f7f446ef1 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -885,7 +885,7 @@ void Font::rebuildTextures() // Re-upload the texture data. for (auto it = mGlyphMap.cbegin(); it != mGlyphMap.cend(); ++it) { - FT_Face* face {getFaceForChar(it->first, returnedFont)}; + FT_Face* face {getFaceForChar(it->first, &returnedFont)}; FT_GlyphSlot glyphSlot {(*face)->glyph}; // Load the glyph bitmap through FreeType. @@ -906,7 +906,7 @@ void Font::rebuildTextures() for (auto it = mGlyphMapByIndex.cbegin(); it != mGlyphMapByIndex.cend(); ++it) { FT_Face* face { - getFaceForGlyphIndex(std::get<0>(it->first), std::get<1>(it->first), returnedFont)}; + getFaceForGlyphIndex(std::get<0>(it->first), std::get<1>(it->first), &returnedFont)}; FT_GlyphSlot glyphSlot {(*face)->glyph}; // Load the glyph bitmap through FreeType. @@ -956,11 +956,11 @@ void Font::getTextureForNewGlyph(const glm::ivec2& glyphSize, } } -FT_Face* Font::getFaceForChar(unsigned int id, hb_font_t* returnedFont) +FT_Face* Font::getFaceForChar(unsigned int id, hb_font_t** returnedFont) { // Look for the glyph in our current font and then in the fallback fonts if needed. if (FT_Get_Char_Index(mFontFace->face, id) != 0) { - returnedFont = mFontHB; + *returnedFont = mFontHB; return &mFontFace->face; } @@ -969,20 +969,20 @@ FT_Face* Font::getFaceForChar(unsigned int id, hb_font_t* returnedFont) // This is most definitely not thread safe. FT_Set_Char_Size(font.face->face, static_cast(0.0f), static_cast(mFontSize * 64.0f), 0, 0); - returnedFont = font.fontHB; + *returnedFont = font.fontHB; return &font.face->face; } } // Couldn't find a valid glyph, return the current font face so we get a "no glyph" character. - returnedFont = nullptr; + *returnedFont = nullptr; return &mFontFace->face; } -FT_Face* Font::getFaceForGlyphIndex(unsigned int id, hb_font_t* fontArg, hb_font_t* returnedFont) +FT_Face* Font::getFaceForGlyphIndex(unsigned int id, hb_font_t* fontArg, hb_font_t** returnedFont) { if (mFontFace->fontHB == fontArg && FT_Load_Glyph(mFontFace->face, id, FT_LOAD_RENDER) == 0) { - returnedFont = mFontHB; + *returnedFont = mFontHB; return &mFontFace->face; } @@ -990,13 +990,13 @@ FT_Face* Font::getFaceForGlyphIndex(unsigned int id, hb_font_t* fontArg, hb_font if (font.fontHB == fontArg && FT_Load_Glyph(font.face->face, id, FT_LOAD_RENDER) == 0) { FT_Set_Char_Size(font.face->face, static_cast(0.0f), static_cast(mFontSize * 64.0f), 0, 0); - returnedFont = font.fontHB; + *returnedFont = font.fontHB; return &font.face->face; } } // Couldn't find a valid glyph, return the current font face so we get a "no glyph" character. - returnedFont = nullptr; + *returnedFont = nullptr; return &mFontFace->face; } @@ -1010,7 +1010,7 @@ Font::Glyph* Font::getGlyph(const unsigned int id) hb_font_t* returnedFont {nullptr}; // We need to create a new entry. - FT_Face* face {getFaceForChar(id, returnedFont)}; + FT_Face* face {getFaceForChar(id, &returnedFont)}; if (!face) { LOG(LogError) << "Couldn't find appropriate font face for character " << id << " for font " << mPath; @@ -1082,7 +1082,7 @@ Font::Glyph* Font::getGlyphByIndex(const unsigned int id, hb_font_t* fontArg, in hb_font_t* returnedFont {nullptr}; // We need to create a new entry. - FT_Face* face {getFaceForGlyphIndex(id, fontArg, returnedFont)}; + FT_Face* face {getFaceForGlyphIndex(id, fontArg, &returnedFont)}; if (!face) { LOG(LogError) << "Couldn't find appropriate font face for character " << id << " for font " << mPath; diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index 6de58b473..0df5b9732 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -221,8 +221,8 @@ private: glm::ivec2& cursorOut); std::vector getFallbackFontPaths(); - FT_Face* getFaceForChar(unsigned int id, hb_font_t* returnedFont); - FT_Face* getFaceForGlyphIndex(unsigned int id, hb_font_t* fontArg, hb_font_t* returnedFont); + FT_Face* getFaceForChar(unsigned int id, hb_font_t** returnedFont); + FT_Face* getFaceForGlyphIndex(unsigned int id, hb_font_t* fontArg, hb_font_t** returnedFont); Glyph* getGlyph(const unsigned int id); Glyph* getGlyphByIndex(const unsigned int id, hb_font_t* fontArg, int xAdvance);