ClearCharacterSet();
// FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
- FcInitReinitialize();
+ // FcInitReinitialize resets global Fonconfig state and cache, which can cause race conditions or double free.
+ // FcInitLoadConfigAndFonts sets the current default configuration for the library, which is specific to the calling process.
+
+ FcConfig* newConfig = FcInitLoadConfigAndFonts();
+
+ if(newConfig)
+ {
+ for(auto &path: mCustomFontDirectories)
+ {
+ FcConfigAppFontAddDir(newConfig, reinterpret_cast<const FcChar8*>(path.c_str()));
+ }
+
+ FcConfigBuildFonts(newConfig);
+ FcConfigSetCurrent(newConfig);
+ FcConfigDestroy(newConfig);
+ }
+ else
+ {
+ DALI_LOG_ERROR("Can't init font config library\n");
+ }
FcPattern* matchPattern = FcPatternCreate(); // Creates a pattern that needs to be destroyed by calling FcPatternDestroy.
FcPatternDestroy(matchPattern);
}
- // Create again the character sets as they are not valid after FcInitReinitialize()
+ // Create again the character sets as they are not valid after FcInitLoadConfigAndFonts()
CreateCharacterSet();
}
}
std::vector<PixelBufferCacheItem> mPixelBufferCache; ///< Caches the pixel buffer of a url.
std::vector<EmbeddedItem> mEmbeddedItemCache; ///< Cache embedded items.
+ std::vector<std::string> mCustomFontDirectories; ///< Cache custom font directories to recovery upon reinitialization.
+
private: // Member value
std::unique_ptr<GlyphCacheManager> mGlyphCacheManager; ///< The glyph cache manager. It will cache this face's glyphs.
mCustomFonts.clear();
}
mCustomFonts.push_back(path);
+
+ if(mCacheHandler)
+ {
+ mCacheHandler->mCustomFontDirectories.push_back(path);
+ }
}
// nullptr as first parameter means the current configuration is used.
return FcConfigAppFontAddDir(nullptr, reinterpret_cast<const FcChar8*>(path.c_str()));