summaryrefslogtreecommitdiff
path: root/core/src/fxge
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fxge')
-rw-r--r--core/src/fxge/apple/fx_mac_imp.cpp15
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp113
-rw-r--r--core/src/fxge/ge/fx_ge_linux.cpp47
-rw-r--r--core/src/fxge/ge/fx_ge_text.cpp33
4 files changed, 100 insertions, 108 deletions
diff --git a/core/src/fxge/apple/fx_mac_imp.cpp b/core/src/fxge/apple/fx_mac_imp.cpp
index e08f6224d8..88a51bd78c 100644
--- a/core/src/fxge/apple/fx_mac_imp.cpp
+++ b/core/src/fxge/apple/fx_mac_imp.cpp
@@ -65,10 +65,10 @@ void* CFX_MacFontInfo::MapFont(int weight,
if (iBaseFont < 12) {
return GetFont(face);
}
- void* p;
- if (m_FontList.Lookup(face, p)) {
- return p;
- }
+ auto it = m_FontList.find(face);
+ if (it != m_FontList.end())
+ return it->second;
+
if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
return GetFont("Courier New");
}
@@ -88,9 +88,10 @@ void* CFX_MacFontInfo::MapFont(int weight,
case FXFONT_CHINESEBIG5_CHARSET:
face = "LiSong Pro Light";
}
- if (m_FontList.Lookup(face, p)) {
- return p;
- }
+ it = m_FontList.find(face);
+ if (it != m_FontList.end())
+ return it->second;
+
return NULL;
}
IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() {
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp
index f755b69072..686e941c54 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;
@@ -74,14 +96,10 @@ 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();
+ for (const auto& pair : m_FaceMap) {
+ delete pair.second;
+ }
+ m_FaceMap.clear();
}
void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) {
m_pBuiltinMapper->SetSystemFontInfo(pFontInfo);
@@ -103,18 +121,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,
@@ -148,11 +162,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] = {
@@ -305,17 +315,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);
}
@@ -326,8 +334,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;
if (!pFontDesc) {
return NULL;
@@ -338,8 +344,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);
@@ -382,18 +387,16 @@ 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();
FX_BOOL bNeedFaceDone = TRUE;
- while (pos) {
- CFX_ByteString Key;
- CTTFontDesc* ttface;
- m_FaceMap.GetNextAssoc(pos, Key, (void*&)ttface);
- int nRet = ttface->ReleaseFace(face);
+ auto it = m_FaceMap.begin();
+ while (it != m_FaceMap.end()) {
+ auto temp = it++;
+ int nRet = temp->second->ReleaseFace(face);
if (nRet == 0) {
- m_FaceMap.RemoveKey(Key);
+ m_FaceMap.erase(temp);
bNeedFaceDone = FALSE;
} else if (nRet > 0) {
bNeedFaceDone = FALSE;
@@ -1373,12 +1376,8 @@ IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() {
#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 (const auto& pair : m_FontList) {
+ delete pair.second;
}
}
void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) {
@@ -1488,8 +1487,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 =
@@ -1533,7 +1531,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,
@@ -1550,11 +1548,8 @@ void* CFX_FolderFontInfo::MapFontByUnicode(FX_DWORD dwUnicode,
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,
diff --git a/core/src/fxge/ge/fx_ge_linux.cpp b/core/src/fxge/ge/fx_ge_linux.cpp
index bad3854afe..4e713dc412 100644
--- a/core/src/fxge/ge/fx_ge_linux.cpp
+++ b/core/src/fxge/ge/fx_ge_linux.cpp
@@ -105,7 +105,6 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
if (iBaseFont < 12) {
return GetFont(face);
}
- void* p = NULL;
FX_BOOL bCJK = TRUE;
switch (charset) {
case FXFONT_SHIFTJIS_CHARSET: {
@@ -113,34 +112,36 @@ void* CFX_LinuxFontInfo::MapFont(int weight,
if (index < 0) {
break;
}
- for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++)
- if (m_FontList.Lookup(LinuxGpFontList[index].NameArr[i], p)) {
- return p;
+ for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) {
+ auto it = m_FontList.find(LinuxGpFontList[index].NameArr[i]);
+ if (it != m_FontList.end()) {
+ return it->second;
}
+ }
} break;
case FXFONT_GB2312_CHARSET: {
- static int32_t s_gbCount =
- sizeof(g_LinuxGbFontList) / sizeof(const FX_CHAR*);
- for (int32_t i = 0; i < s_gbCount; i++)
- if (m_FontList.Lookup(g_LinuxGbFontList[i], p)) {
- return p;
+ for (int32_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) {
+ auto it = m_FontList.find(g_LinuxGbFontList[i]);
+ if (it != m_FontList.end()) {
+ return it->second;
}
+ }
} break;
case FXFONT_CHINESEBIG5_CHARSET: {
- static int32_t s_b5Count =
- sizeof(g_LinuxB5FontList) / sizeof(const FX_CHAR*);
- for (int32_t i = 0; i < s_b5Count; i++)
- if (m_FontList.Lookup(g_LinuxB5FontList[i], p)) {
- return p;
+ for (int32_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) {
+ auto it = m_FontList.find(g_LinuxB5FontList[i]);
+ if (it != m_FontList.end()) {
+ return it->second;
}
+ }
} break;
case FXFONT_HANGEUL_CHARSET: {
- static int32_t s_hgCount =
- sizeof(g_LinuxHGFontList) / sizeof(const FX_CHAR*);
- for (int32_t i = 0; i < s_hgCount; i++)
- if (m_FontList.Lookup(g_LinuxHGFontList[i], p)) {
- return p;
+ for (int32_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) {
+ auto it = m_FontList.find(g_LinuxHGFontList[i]);
+ if (it != m_FontList.end()) {
+ return it->second;
}
+ }
} break;
default:
bCJK = FALSE;
@@ -201,11 +202,9 @@ void* CFX_LinuxFontInfo::FindFont(int weight,
CFX_FontFaceInfo* pFind = NULL;
FX_DWORD charset_flag = _LinuxGetCharset(charset);
int32_t iBestSimilar = 0;
- FX_POSITION pos = m_FontList.GetStartPosition();
- while (pos) {
- CFX_ByteString bsName;
- CFX_FontFaceInfo* pFont = NULL;
- m_FontList.GetNextAssoc(pos, bsName, (void*&)pFont);
+ for (const auto& it : m_FontList) {
+ const CFX_ByteString& bsName = it.first;
+ CFX_FontFaceInfo* pFont = it.second;
if (!(pFont->m_Charsets & charset_flag) &&
charset != FXFONT_DEFAULT_CHARSET) {
continue;
diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp
index 0bb8eab812..93e3486b79 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -1204,15 +1204,11 @@ CFX_FaceCache::CFX_FaceCache(FXFT_Face face) {
m_Face = face;
}
CFX_FaceCache::~CFX_FaceCache() {
- FX_POSITION pos = m_SizeMap.GetStartPosition();
- CFX_ByteString Key;
- CFX_SizeGlyphCache* pSizeCache = NULL;
- while (pos) {
- m_SizeMap.GetNextAssoc(pos, Key, (void*&)pSizeCache);
- delete pSizeCache;
+ for (const auto& pair : m_SizeMap) {
+ delete pair.second;
}
- m_SizeMap.RemoveAll();
- pos = m_PathMap.GetStartPosition();
+ m_SizeMap.clear();
+ FX_POSITION pos = m_PathMap.GetStartPosition();
void* key1;
CFX_PathData* pPath;
while (pos) {
@@ -1232,13 +1228,13 @@ CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
FX_BOOL bFontStyle,
int dest_width,
int anti_alias) {
- CFX_SizeGlyphCache* pSizeCache = NULL;
- if (!m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {
+ CFX_SizeGlyphCache* pSizeCache;
+ auto it = m_SizeMap.find(FaceGlyphsKey);
+ if (it == m_SizeMap.end()) {
pSizeCache = new CFX_SizeGlyphCache;
- if (pSizeCache == NULL) {
- return NULL;
- }
- m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);
+ m_SizeMap[FaceGlyphsKey] = pSizeCache;
+ } else {
+ pSizeCache = it->second;
}
CFX_GlyphBitmap* pGlyphBitmap = NULL;
if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index,
@@ -1310,8 +1306,9 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(
bFontStyle, dest_width, anti_alias);
}
CFX_GlyphBitmap* pGlyphBitmap;
- CFX_SizeGlyphCache* pSizeCache = NULL;
- if (m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {
+ auto it = m_SizeMap.find(FaceGlyphsKey);
+ if (it != m_SizeMap.end()) {
+ CFX_SizeGlyphCache* pSizeCache = it->second;
if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index,
(void*&)pGlyphBitmap)) {
return pGlyphBitmap;
@@ -1326,8 +1323,8 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(
pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
dest_width, anti_alias);
if (pGlyphBitmap) {
- pSizeCache = new CFX_SizeGlyphCache;
- m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);
+ CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache;
+ m_SizeMap[FaceGlyphsKey] = pSizeCache;
pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap);
return pGlyphBitmap;
}