summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-20 12:17:53 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-20 12:17:53 -0800
commit04f01ef650f0abe9b6b18196589ccbaaa623daa3 (patch)
tree455f76e28f5b85ec2a85ad6d96143f970faa8d26
parentd94d48bdb9e295127af77d7f329731133a236801 (diff)
downloadpdfium-04f01ef650f0abe9b6b18196589ccbaaa623daa3.tar.xz
Remove CFX_CMapByteStringToPtr usage in XFA.
R=ochang@chromium.org Review URL: https://codereview.chromium.org/1573243003 .
-rw-r--r--xfa/src/fxfa/src/app/xfa_fontmgr.cpp57
-rw-r--r--xfa/src/fxfa/src/app/xfa_fontmgr.h19
-rw-r--r--xfa/src/fxfa/src/parser/xfa_script_imp.h10
3 files changed, 44 insertions, 42 deletions
diff --git a/xfa/src/fxfa/src/app/xfa_fontmgr.cpp b/xfa/src/fxfa/src/app/xfa_fontmgr.cpp
index 05c9c24125..02f3d5e4b6 100644
--- a/xfa/src/fxfa/src/app/xfa_fontmgr.cpp
+++ b/xfa/src/fxfa/src/app/xfa_fontmgr.cpp
@@ -1839,16 +1839,10 @@ CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) {
}
CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {
m_FDE2PDFFont.RemoveAll();
- FX_POSITION ps = m_FontArray.GetStartPosition();
- while (ps) {
- CFX_ByteString strKey;
- IFX_Font* pFont = NULL;
- m_FontArray.GetNextAssoc(ps, strKey, (void*&)pFont);
- if (pFont != NULL) {
- pFont->Release();
- }
+ for (const auto& pair : m_FontMap) {
+ if (pair.second)
+ pair.second->Release();
}
- m_FontArray.RemoveAll();
}
IFX_Font* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
FX_BOOL bBold,
@@ -1903,20 +1897,18 @@ IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
FX_DWORD dwHashCode =
FX_HashCode_String_GetW(wsFontFamily.GetPtr(), wsFontFamily.GetLength());
CFX_ByteString strKey;
- IFX_Font* pFont = NULL;
strKey.Format("%u%u", dwHashCode, dwFontStyles);
- if (m_FontArray.Lookup(strKey, (void*&)pFont)) {
- return pFont;
- }
- CFX_ByteString bsPsName;
- bsPsName = CFX_ByteString::FromUnicode(wsFontFamily);
+ auto it = m_FontMap.find(strKey);
+ if (it != m_FontMap.end())
+ return it->second;
+ CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily);
FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold;
FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic;
CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
- pFont = FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch);
- if (pFont) {
- m_FontArray.SetAt(strKey, pFont);
- }
+ IFX_Font* pFont =
+ FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch);
+ if (pFont)
+ m_FontMap[strKey] = pFont;
return pFont;
}
CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName(
@@ -2034,41 +2026,38 @@ IFX_Font* CXFA_FontMgr::GetFont(IXFA_Doc* hDoc,
wsFontFamily.GetLength(), FALSE);
CFX_ByteString bsKey;
bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage);
- IFX_Font* pFont = NULL;
- if (m_FontArray.Lookup(bsKey, (void*&)pFont)) {
- return pFont;
- }
+ auto it = m_FontMap.find(bsKey);
+ if (it != m_FontMap.end())
+ return it->second;
CFX_WideString wsEnglishName;
XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName);
CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc);
CPDF_Font* pPDFFont = NULL;
- if (pMgr != NULL) {
+ IFX_Font* pFont = NULL;
+ if (pMgr) {
pFont = pMgr->GetFont(wsEnglishName, dwFontStyles, &pPDFFont);
- if (pFont) {
+ if (pFont)
return pFont;
- }
}
- if (pFont == NULL && m_pDefFontMgr != NULL) {
+ if (!pFont && m_pDefFontMgr) {
pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage);
}
- if (pFont == NULL && pMgr != NULL) {
+ if (!pFont && pMgr) {
pPDFFont = NULL;
pFont = pMgr->GetFont(wsEnglishName, dwFontStyles, &pPDFFont, FALSE);
- if (pFont) {
+ if (pFont)
return pFont;
- }
}
- if (pFont == NULL && m_pDefFontMgr != NULL) {
+ if (!pFont && m_pDefFontMgr) {
pFont = m_pDefFontMgr->GetDefaultFont(hDoc, wsFontFamily, dwFontStyles,
wCodePage);
}
- FXSYS_assert(pFont != NULL);
if (pFont) {
if (pPDFFont) {
pMgr->m_FDE2PDFFont.SetAt(pFont, pPDFFont);
pFont->SetFontProvider(pMgr);
}
- m_FontArray.SetAt(bsKey, pFont);
+ m_FontMap[bsKey] = pFont;
}
return pFont;
}
@@ -2097,7 +2086,7 @@ void CXFA_FontMgr::DelAllMgrMap() {
}
}
m_PDFFontMgrArray.RemoveAll();
- m_FontArray.RemoveAll();
+ m_FontMap.clear();
}
void CXFA_FontMgr::SetDefFontMgr(IXFA_FontMgr* pFontMgr) {
m_pDefFontMgr = pFontMgr;
diff --git a/xfa/src/fxfa/src/app/xfa_fontmgr.h b/xfa/src/fxfa/src/app/xfa_fontmgr.h
index 5afb09b3c7..b203dae295 100644
--- a/xfa/src/fxfa/src/app/xfa_fontmgr.h
+++ b/xfa/src/fxfa/src/app/xfa_fontmgr.h
@@ -4,8 +4,11 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _FXFA_FORMFILLER_FONTMGR_IMP_H
-#define _FXFA_FORMFILLER_FONTMGR_IMP_H
+#ifndef XFA_FONTMGR_H_
+#define XFA_FONTMGR_H_
+
+#include <map>
+
struct XFA_FONTINFO {
FX_DWORD dwFontNameHash;
const FX_WCHAR* pPsName;
@@ -13,6 +16,7 @@ struct XFA_FONTINFO {
FX_WORD dwStyles;
FX_WORD wCodePage;
};
+
class CXFA_DefFontMgr : public IXFA_FontMgr {
public:
CXFA_DefFontMgr() {}
@@ -31,6 +35,7 @@ class CXFA_DefFontMgr : public IXFA_FontMgr {
protected:
CFX_PtrArray m_CacheFonts;
};
+
class CXFA_PDFFontMgr : public IFX_FontProvider {
public:
CXFA_PDFFontMgr(CXFA_FFDoc* pDoc);
@@ -59,9 +64,11 @@ class CXFA_PDFFontMgr : public IFX_FontProvider {
FX_BOOL bItalic,
const CFX_ByteString& bsDRFontName,
FX_BOOL bStrictMatch = TRUE);
+
CXFA_FFDoc* m_pDoc;
- CFX_CMapByteStringToPtr m_FontArray;
+ std::map<CFX_ByteString, IFX_Font*> m_FontMap;
};
+
class CXFA_FontMgr {
public:
CXFA_FontMgr();
@@ -77,8 +84,10 @@ class CXFA_FontMgr {
protected:
void DelAllMgrMap();
+
CFX_MapPtrToPtr m_PDFFontMgrArray;
IXFA_FontMgr* m_pDefFontMgr;
- CFX_CMapByteStringToPtr m_FontArray;
+ std::map<CFX_ByteString, IFX_Font*> m_FontMap;
};
-#endif
+
+#endif // XFA_FONTMGR_H_
diff --git a/xfa/src/fxfa/src/parser/xfa_script_imp.h b/xfa/src/fxfa/src/parser/xfa_script_imp.h
index 0075c3f68c..039cb0f16f 100644
--- a/xfa/src/fxfa/src/parser/xfa_script_imp.h
+++ b/xfa/src/fxfa/src/parser/xfa_script_imp.h
@@ -4,8 +4,11 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _FXFA_SCRIPT_IMP_H
-#define _FXFA_SCRIPT_IMP_H
+#ifndef XFA_SCRIPT_IMP_H_
+#define XFA_SCRIPT_IMP_H_
+
+#include <map>
+
#define XFA_RESOLVENODE_TagName 0x0002
class CXFA_ResolveProcessor;
@@ -116,4 +119,5 @@ class CXFA_ScriptContext : public IXFA_ScriptContext {
FX_DWORD m_dwBuiltInInFlags;
XFA_ATTRIBUTEENUM m_eRunAtType;
};
-#endif
+
+#endif // XFA_SCRIPT_IMP_H_