Index: core/src/fxge/ge/fx_ge_fontmap.cpp |
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp |
index d4416d9487944bb28ffe6a33a011cc068d285b20..49b3af76ebd1abda6ae829aca4118e6ad17a047b 100644 |
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp |
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp |
@@ -9,9 +9,31 @@ |
#include "../../../include/fxge/fx_ge.h" |
#include "../../../include/fxge/fx_freetype.h" |
#include "text_int.h" |
+ |
#define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) |
#define GET_TT_LONG(w) \ |
(FX_DWORD)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3]) |
+ |
+namespace { |
+ |
+CFX_ByteString KeyNameFromFace(const CFX_ByteString& face_name, |
+ int weight, |
+ FX_BOOL bItalic) { |
+ CFX_ByteString key(face_name); |
+ key += ','; |
+ key += CFX_ByteString::FormatInteger(weight); |
+ key += bItalic ? 'I' : 'N'; |
+ return key; |
+} |
+ |
+CFX_ByteString KeyNameFromSize(int ttc_size, FX_DWORD checksum) { |
+ CFX_ByteString key; |
+ key.Format("%d:%d", ttc_size, checksum); |
+ return key; |
+} |
+ |
+} // namespace |
+ |
CFX_SubstFont::CFX_SubstFont() { |
m_ExtHandle = NULL; |
m_Charset = 0; |
@@ -76,14 +98,12 @@ void CFX_FontMgr::InitFTLibrary() { |
} |
} |
void CFX_FontMgr::FreeCache() { |
- FX_POSITION pos = m_FaceMap.GetStartPosition(); |
- while (pos) { |
- CFX_ByteString Key; |
- CTTFontDesc* face; |
- m_FaceMap.GetNextAssoc(pos, Key, (void*&)face); |
- delete face; |
- } |
- m_FaceMap.RemoveAll(); |
+ auto it = m_FaceMap.begin(); |
+ while (it != m_FaceMap.end()) { |
Lei Zhang
2015/08/15 00:47:33
Range-Based For Loop?
Tom Sepez
2015/08/17 20:15:26
Done.
|
+ auto temp = it++; |
+ delete temp->second; |
+ m_FaceMap.erase(temp); |
+ } |
} |
void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) { |
m_pBuiltinMapper->SetSystemFontInfo(pFontInfo); |
@@ -105,18 +125,14 @@ FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, |
int weight, |
FX_BOOL bItalic, |
uint8_t*& pFontData) { |
- CFX_ByteString key(face_name); |
- key += ','; |
- key += CFX_ByteString::FormatInteger(weight); |
- key += bItalic ? 'I' : 'N'; |
- CTTFontDesc* pFontDesc = NULL; |
- m_FaceMap.Lookup(key, (void*&)pFontDesc); |
- if (pFontDesc) { |
- pFontData = pFontDesc->m_pFontData; |
- pFontDesc->m_RefCount++; |
- return pFontDesc->m_SingleFace.m_pFace; |
- } |
- return NULL; |
+ auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); |
+ if (it == m_FaceMap.end()) |
+ return nullptr; |
+ |
+ CTTFontDesc* pFontDesc = it->second; |
+ pFontData = pFontDesc->m_pFontData; |
+ pFontDesc->m_RefCount++; |
+ return pFontDesc->m_SingleFace.m_pFace; |
} |
FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, |
int weight, |
@@ -147,11 +163,7 @@ FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, |
delete pFontDesc; |
return NULL; |
} |
- CFX_ByteString key(face_name); |
- key += ','; |
- key += CFX_ByteString::FormatInteger(weight); |
- key += bItalic ? 'I' : 'N'; |
- m_FaceMap.SetAt(key, pFontDesc); |
+ m_FaceMap[KeyNameFromFace(face_name, weight, bItalic)] = pFontDesc; |
return pFontDesc->m_SingleFace.m_pFace; |
} |
const FX_CHAR* const g_Base14FontNames[14] = { |
@@ -304,17 +316,15 @@ FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, |
FX_DWORD checksum, |
int font_offset, |
uint8_t*& pFontData) { |
- CFX_ByteString key; |
- key.Format("%d:%d", ttc_size, checksum); |
- CTTFontDesc* pFontDesc = NULL; |
- m_FaceMap.Lookup(key, (void*&)pFontDesc); |
- if (pFontDesc == NULL) { |
- return NULL; |
- } |
+ auto it = m_FaceMap.find(KeyNameFromSize(ttc_size, checksum)); |
+ if (it == m_FaceMap.end()) |
+ return nullptr; |
+ |
+ CTTFontDesc* pFontDesc = it->second; |
pFontData = pFontDesc->m_pFontData; |
pFontDesc->m_RefCount++; |
int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); |
- if (pFontDesc->m_TTCFace.m_pFaces[face_index] == NULL) { |
+ if (!pFontDesc->m_TTCFace.m_pFaces[face_index]) { |
pFontDesc->m_TTCFace.m_pFaces[face_index] = |
GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index); |
} |
@@ -325,8 +335,6 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, |
uint8_t* pData, |
FX_DWORD size, |
int font_offset) { |
- CFX_ByteString key; |
- key.Format("%d:%d", ttc_size, checksum); |
CTTFontDesc* pFontDesc = new CTTFontDesc; |
pFontDesc->m_Type = 2; |
pFontDesc->m_pFontData = pData; |
@@ -334,8 +342,7 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, |
pFontDesc->m_TTCFace.m_pFaces[i] = NULL; |
} |
pFontDesc->m_RefCount++; |
- key.Format("%d:%d", ttc_size, checksum); |
- m_FaceMap.SetAt(key, pFontDesc); |
+ m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = pFontDesc; |
int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); |
pFontDesc->m_TTCFace.m_pFaces[face_index] = |
GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index); |
@@ -378,16 +385,14 @@ FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) { |
return face; |
} |
void CFX_FontMgr::ReleaseFace(FXFT_Face face) { |
- if (face == NULL) { |
+ if (!face) { |
return; |
} |
- FX_POSITION pos = m_FaceMap.GetStartPosition(); |
- while (pos) { |
- CFX_ByteString Key; |
- CTTFontDesc* ttface; |
- m_FaceMap.GetNextAssoc(pos, Key, (void*&)ttface); |
- if (ttface->ReleaseFace(face)) { |
- m_FaceMap.RemoveKey(Key); |
+ auto it = m_FaceMap.begin(); |
+ while (it != m_FaceMap.end()) { |
+ auto temp = it++; |
+ if (temp->second->ReleaseFace(face)) { |
+ m_FaceMap.erase(temp); |
} |
} |
} |
@@ -1276,12 +1281,8 @@ IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) { |
#endif |
CFX_FolderFontInfo::CFX_FolderFontInfo() {} |
CFX_FolderFontInfo::~CFX_FolderFontInfo() { |
- FX_POSITION pos = m_FontList.GetStartPosition(); |
- while (pos) { |
- CFX_ByteString key; |
- void* value; |
- m_FontList.GetNextAssoc(pos, key, value); |
- delete (CFX_FontFaceInfo*)value; |
+ for (auto& pair : m_FontList) { |
+ delete pair.second; |
} |
} |
void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { |
@@ -1391,8 +1392,7 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, |
if (style != "Regular") { |
facename += " " + style; |
} |
- void* p; |
- if (m_FontList.Lookup(facename, p)) { |
+ if (m_FontList.find(facename) != m_FontList.end()) { |
return; |
} |
CFX_FontFaceInfo* pInfo = |
@@ -1436,7 +1436,7 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, |
if (facename.Find(FX_BSTRC("Serif")) > -1) { |
pInfo->m_Styles |= FXFONT_SERIF; |
} |
- m_FontList.SetAt(facename, pInfo); |
+ m_FontList[facename] = pInfo; |
} |
void* CFX_FolderFontInfo::MapFont(int weight, |
FX_BOOL bItalic, |
@@ -1447,11 +1447,8 @@ void* CFX_FolderFontInfo::MapFont(int weight, |
return NULL; |
} |
void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { |
- void* p; |
- if (!m_FontList.Lookup(face, p)) { |
- return NULL; |
- } |
- return p; |
+ auto it = m_FontList.find(face); |
+ return it != m_FontList.end() ? it->second : nullptr; |
} |
FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, |
FX_DWORD table, |