summaryrefslogtreecommitdiff
path: root/core/src/fxge/ge/fx_ge_fontmap.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-08-19 09:49:24 -0700
committerTom Sepez <tsepez@chromium.org>2015-08-19 09:49:24 -0700
commit09d33bcd82a82cb55039d41651df13e17d6c3e59 (patch)
tree7a748b7570ff6ad0321c4334319bac101da0e6af /core/src/fxge/ge/fx_ge_fontmap.cpp
parent1b0023986bc22ce362097b25deb9746b693ef235 (diff)
downloadpdfium-09d33bcd82a82cb55039d41651df13e17d6c3e59.tar.xz
Merge to XFA: CFX_MapByteStringToPtr considered harmful (combo patch).
New manual edits: two unused members deleted, one adapted. fde_csscache.cpp fde_csscache.h fpdfxfa_doc.h fx_ge_fontmap.cpp (cherry picked from commit 1d9dbd53b205b2b4d9e75a7eeb95e80837917ea3) (cherry picked from commit cb4d0ea68308e3c51a6ba9551b393bb2f639afc4) (cherry picked from commit 9cf44c2ed09a8b2ff243eb6dbb72a8cceae1b5ff) (cherry picked from commit 2a2a6aa7f51352fc481e78f6ad9d41f2738bcc48) (cherry picked from commit ce4ffb8183af3fa2bb5133f0f7370a88e064c516) Original Review URL: https://codereview.chromium.org/1297723002 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1301793002 .
Diffstat (limited to 'core/src/fxge/ge/fx_ge_fontmap.cpp')
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp113
1 files changed, 54 insertions, 59 deletions
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,