Commit 3d8dbf0e authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov
parent 8ec910fd
......@@ -175,9 +175,28 @@ CFontFile* CFontsCache::LockFont(FT_Library library, const std::wstring& strFile
if (NULL == pFile)
return NULL;
if (-1 != m_lCacheSize)
{
m_arFiles.push_back(sLock);
if ((int)m_arFiles.size() > m_lCacheSize)
{
std::string sPop = *m_arFiles.begin();
m_arFiles.pop_front();
std::map<std::string, CFontFile*>::iterator _find = m_mapFiles.find(sPop);
if (m_mapFiles.end() != _find)
{
CFontFile* pFontRemove = _find->second;
RELEASEOBJECT(pFontRemove);
m_mapFiles.erase(_find);
}
}
}
pFile->m_pStream = pStream;
pFile->m_pStream->AddRef();
m_mapFiles[sLock] = pFile;
return pFile;
}
......
......@@ -3,6 +3,7 @@
#include "FontFile.h"
#include <map>
#include <list>
class CFontSelectFormat;
class CFontInfo;
......@@ -52,10 +53,15 @@ private:
std::map<std::string, CFontFile*> m_mapFiles;
CApplicationFontStreams* m_pApplicationFontStreams;
private:
std::list<std::string> m_arFiles;
int m_lCacheSize;
public:
CFontsCache()
{
m_pApplicationFontStreams = NULL;
m_lCacheSize = -1;
}
~CFontsCache()
{
......@@ -69,6 +75,16 @@ public:
RELEASEOBJECT(pFile);
}
m_mapFiles.clear();
if (-1 != m_lCacheSize)
m_arFiles.clear();
}
void SetCacheSize(const int& lMaxSize)
{
if (lMaxSize <= 0)
m_lCacheSize = -1;
else
m_lCacheSize = lMaxSize;
}
public:
......
......@@ -27,11 +27,6 @@ namespace Jpeg2000
}
return pMemBlock;
}
void Free(void* pMem)
{
free(pMem);
pMem = NULL;
}
int check_j2000_type(FILE* pFile)
{
if (!pFile)
......
......@@ -17,7 +17,16 @@ namespace Jpeg2000
#define J2K_MAXSSFTR 2 // Max SubSampling Factor (Значения больше 2 могут привести к ошибке)
void* Malloc(size_t nSize);
void Free(void* pMem);
template<typename T>
void Free(T*& pMem)
{
if (NULL != pMem)
{
free(pMem);
pMem = NULL;
}
}
//-------------------------------------------------------------------------------------------------------------------------------
// Enum definitions
//-------------------------------------------------------------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment