Reset all font caches when font size changes

This commit is contained in:
vsonnier 2016-06-21 21:05:17 +02:00
parent 308baf163b
commit 85178095ca
2 changed files with 18 additions and 8 deletions

View File

@ -793,7 +793,10 @@ void GLFont::doCacheGC() {
} //end while
}
void GLFont::flushGC() {
void GLFont::clearCache() {
std::lock_guard<std::mutex> lock(cache_busy);
std::map<std::wstring, GLFontStringCache * >::iterator cache_iter;
cache_iter = stringCache.begin();
@ -806,6 +809,14 @@ void GLFont::flushGC() {
}
}
void GLFont::clearAllCaches() {
for (int i = 0; i < GLFont::GLFONT_SIZE_MAX; i++) {
fonts[i].clearCache();
}
}
GLFont &GLFont::getFont(GLFontSize esize) {
@ -864,8 +875,6 @@ void GLFont::setScale(GLFontScale scale) {
userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE48;
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE72;
userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE96;
}
//Large : 2x normal, more or less
else if (currentScaleFactor == GLFontScale::GLFONT_SCALE_LARGE) {
@ -880,10 +889,8 @@ void GLFont::setScale(GLFontScale scale) {
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE96;
}
//Not overridden mapping stays normal, like the biggest fonts.
//Note that there is no need to flush the GC, no longer used fonts will be purged auto-magically by aging,
//and the new fonts will show up.
//Flush all the GC stuff
clearAllCaches();
}
GLFont::GLFontScale GLFont::getScale() {

View File

@ -137,7 +137,10 @@ private:
void drawCacheString(GLFontStringCache *fc, float xpos, float ypos, Align hAlign, Align vAlign);
void doCacheGC();
void flushGC();
void clearCache();
//force GC of all available fonts
static void clearAllCaches();
float getStringWidth(const std::wstring& str, float size, float viewAspect);