Set small fontscache size by allfontsgen working... (#244)

This commit is contained in:
Oleg Korshul
2020-04-11 12:12:50 +03:00
committed by GitHub
parent 60904a6df0
commit a0c0171d12
2 changed files with 28 additions and 1 deletions

View File

@ -392,6 +392,7 @@ namespace NSCommon
{
NSFonts::IFontManager* pManager = applicationFonts->GenerateFontManager();
NSFonts::IFontsCache* pCache = NSFonts::NSFontCache::Create();
pCache->SetCacheSize(3);
pCache->SetStreams(applicationFonts->GetStreams());
pManager->SetOwnerCache(pCache);
@ -427,6 +428,9 @@ namespace NSCommon
pRenderer->put_Width(lWidthPix * 25.4 / dDpi);
pRenderer->put_Height(lHeightPix * 25.4 / dDpi);
bool isUseMapForStreams = false;
std::map<std::wstring, bool> mapUsedFiles;
for (int index = 0; index < nCountFonts; ++index)
{
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[index]);
@ -476,6 +480,9 @@ namespace NSCommon
if (NULL != pInfoCur)
{
if (isUseMapForStreams)
mapUsedFiles.insert(std::pair<std::wstring, bool>(pInfoCur->m_wsFontPath, true));
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
}
pRenderer->put_FontPath(pInfoCur->m_wsFontPath);
@ -503,6 +510,9 @@ namespace NSCommon
if (NULL != pInfoCur)
{
if (isUseMapForStreams)
mapUsedFiles.insert(std::pair<std::wstring, bool>(pInfoCur->m_wsFontPath, true));
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
}
pRenderer->put_FontPath(pInfoCur->m_wsFontPath);
@ -514,6 +524,11 @@ namespace NSCommon
pRenderer->put_FontSize(14);
pRenderer->CommandDrawText(pPair->second.m_sName, 5, 25.4 * (index * lH1_px + lH1_px) / dDpi - 2, 0, 0);
if (isUseMapForStreams)
applicationFonts->GetStreams()->CheckStreams(mapUsedFiles);
else
applicationFonts->GetStreams()->Clear();
}
std::wstring strThumbnailPath = strFolderThumbnails + L"/fonts_thumbnail";

View File

@ -104,7 +104,19 @@ NSFonts::IFontStream* CApplicationFontStreams::GetStream(const std::wstring &str
}
void CApplicationFontStreams::CheckStreams(std::map<std::wstring,bool> &mapFiles)
{
// TODO:
std::map<std::wstring, CFontStream*>::iterator iter = m_mapStreams.begin();
while (iter != m_mapStreams.end())
{
CFontStream* pFile = iter->second;
if (mapFiles.find(iter->first) != mapFiles.end())
{
iter = m_mapStreams.erase(iter);
RELEASEINTERFACE(pFile);
}
else
iter++;
}
}
void CApplicationFontStreams::Clear()