GR_Font* GR_Graphics::findFont(const char* pszFontFamily, const char* pszFontStyle, const char* pszFontVariant, const char* pszFontWeight, const char* pszFontStretch, const char* pszFontSize, const char* pszLang) { GR_Font * pFont = NULL; // NOTE: we currently favor a readable hash key to make debugging easier // TODO: speed things up with a smaller key (the three AP pointers?) std::string key = UT_std_string_sprintf("%s;%s;%s;%s;%s;%s",pszFontFamily, pszFontStyle, pszFontVariant, pszFontWeight, pszFontStretch, pszFontSize); FontCache::const_iterator iter = m_hashFontCache.find(key); if (iter == m_hashFontCache.end()) { // TODO -- note that we currently assume font-family to be a single name, // TODO -- not a list. This is broken. pFont = _findFont(pszFontFamily, pszFontStyle, pszFontVariant,pszFontWeight, pszFontStretch, pszFontSize, pszLang); UT_ASSERT(pFont); xxx_UT_DEBUGMSG(("Insert font %x in gr_Graphics cache \n",pFont)); // add it to the cache if(pFont) m_hashFontCache.insert(std::make_pair(key, pFont)); } else { pFont = iter->second; } return pFont; }
GR_Font* GR_Graphics::findFont(const char* pszFontFamily, const char* pszFontStyle, const char* pszFontVariant, const char* pszFontWeight, const char* pszFontStretch, const char* pszFontSize, const char* pszLang) { GR_Font * pFont = NULL; // NOTE: we currently favor a readable hash key to make debugging easier // TODO: speed things up with a smaller key (the three AP pointers?) UT_String key; UT_String_sprintf(key,"%s;%s;%s;%s;%s;%s",pszFontFamily, pszFontStyle, pszFontVariant, pszFontWeight, pszFontStretch, pszFontSize); GR_Font *pEntry = m_hashFontCache.pick(key.c_str()); if (!pEntry) { // TODO -- note that we currently assume font-family to be a single name, // TODO -- not a list. This is broken. pFont = _findFont(pszFontFamily, pszFontStyle, pszFontVariant,pszFontWeight, pszFontStretch, pszFontSize, pszLang); UT_ASSERT(pFont); xxx_UT_DEBUGMSG(("Insert font %x in gr_Graphics cache \n",pFont)); // add it to the cache if(pFont) m_hashFontCache.insert(key.c_str(), pFont); } else { pFont = pEntry; } return pFont; }