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 ...@@ -175,9 +175,28 @@ CFontFile* CFontsCache::LockFont(FT_Library library, const std::wstring& strFile
if (NULL == pFile) if (NULL == pFile)
return NULL; 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 = pStream;
pFile->m_pStream->AddRef(); pFile->m_pStream->AddRef();
m_mapFiles[sLock] = pFile; m_mapFiles[sLock] = pFile;
return pFile; return pFile;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "FontFile.h" #include "FontFile.h"
#include <map> #include <map>
#include <list>
class CFontSelectFormat; class CFontSelectFormat;
class CFontInfo; class CFontInfo;
...@@ -52,10 +53,15 @@ private: ...@@ -52,10 +53,15 @@ private:
std::map<std::string, CFontFile*> m_mapFiles; std::map<std::string, CFontFile*> m_mapFiles;
CApplicationFontStreams* m_pApplicationFontStreams; CApplicationFontStreams* m_pApplicationFontStreams;
private:
std::list<std::string> m_arFiles;
int m_lCacheSize;
public: public:
CFontsCache() CFontsCache()
{ {
m_pApplicationFontStreams = NULL; m_pApplicationFontStreams = NULL;
m_lCacheSize = -1;
} }
~CFontsCache() ~CFontsCache()
{ {
...@@ -69,6 +75,16 @@ public: ...@@ -69,6 +75,16 @@ public:
RELEASEOBJECT(pFile); RELEASEOBJECT(pFile);
} }
m_mapFiles.clear(); 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: public:
......
...@@ -27,11 +27,6 @@ namespace Jpeg2000 ...@@ -27,11 +27,6 @@ namespace Jpeg2000
} }
return pMemBlock; return pMemBlock;
} }
void Free(void* pMem)
{
free(pMem);
pMem = NULL;
}
int check_j2000_type(FILE* pFile) int check_j2000_type(FILE* pFile)
{ {
if (!pFile) if (!pFile)
......
...@@ -17,7 +17,16 @@ namespace Jpeg2000 ...@@ -17,7 +17,16 @@ namespace Jpeg2000
#define J2K_MAXSSFTR 2 // Max SubSampling Factor (Значения больше 2 могут привести к ошибке) #define J2K_MAXSSFTR 2 // Max SubSampling Factor (Значения больше 2 могут привести к ошибке)
void* Malloc(size_t nSize); 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 // 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