summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xfa/fxfa/app/xfa_fontmgr.cpp62
-rw-r--r--xfa/fxfa/include/xfa_fontmgr.h9
2 files changed, 28 insertions, 43 deletions
diff --git a/xfa/fxfa/app/xfa_fontmgr.cpp b/xfa/fxfa/app/xfa_fontmgr.cpp
index bf8c1a7326..9fec265a5a 100644
--- a/xfa/fxfa/app/xfa_fontmgr.cpp
+++ b/xfa/fxfa/app/xfa_fontmgr.cpp
@@ -1818,7 +1818,6 @@ CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) {
m_pDoc = pDoc;
}
CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {
- m_FDE2PDFFont.RemoveAll();
for (const auto& pair : m_FontMap) {
if (pair.second)
pair.second->Release();
@@ -1986,23 +1985,21 @@ FX_BOOL CXFA_PDFFontMgr::GetCharWidth(IFX_Font* pFont,
FX_WCHAR wUnicode,
int32_t& iWidth,
FX_BOOL bCharCode) {
- if (wUnicode != 0x20 || bCharCode) {
+ if (wUnicode != 0x20 || bCharCode)
return FALSE;
- }
- CPDF_Font* pPDFFont = (CPDF_Font*)m_FDE2PDFFont.GetValueAt(pFont);
- if (!pPDFFont) {
+
+ auto it = m_FDE2PDFFont.find(pFont);
+ if (it == m_FDE2PDFFont.end())
return FALSE;
- }
- wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode);
- iWidth = pPDFFont->GetCharWidthF(wUnicode);
+
+ CPDF_Font* pPDFFont = it->second;
+ iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode));
return TRUE;
}
CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(nullptr) {}
-CXFA_FontMgr::~CXFA_FontMgr() {
- DelAllMgrMap();
-}
+CXFA_FontMgr::~CXFA_FontMgr() {}
IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
const CFX_WideStringC& wsFontFamily,
@@ -2011,14 +2008,16 @@ IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false);
CFX_ByteString bsKey;
bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage);
- auto it = m_FontMap.find(bsKey);
- if (it != m_FontMap.end())
- return it->second;
+ auto iter = m_FontMap.find(bsKey);
+ if (iter != m_FontMap.end())
+ return iter->second;
CFX_WideString wsEnglishName;
XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName);
- CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc);
- CPDF_Font* pPDFFont = NULL;
- IFX_Font* pFont = NULL;
+ auto it = m_PDFFontMgrMap.find(hDoc);
+ CXFA_PDFFontMgr* pMgr =
+ it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr;
+ CPDF_Font* pPDFFont = nullptr;
+ IFX_Font* pFont = nullptr;
if (pMgr) {
pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont);
if (pFont)
@@ -2028,7 +2027,7 @@ IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage);
}
if (!pFont && pMgr) {
- pPDFFont = NULL;
+ pPDFFont = nullptr;
pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont,
FALSE);
if (pFont)
@@ -2040,36 +2039,23 @@ IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
}
if (pFont) {
if (pPDFFont) {
- pMgr->m_FDE2PDFFont.SetAt(pFont, pPDFFont);
+ pMgr->m_FDE2PDFFont[pFont] = pPDFFont;
pFont->SetFontProvider(pMgr);
}
m_FontMap[bsKey] = pFont;
}
return pFont;
}
+
void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) {
- if (!m_PDFFontMgrArray.GetValueAt(hDoc)) {
- m_PDFFontMgrArray.SetAt(hDoc, new CXFA_PDFFontMgr(hDoc));
- }
+ if (!m_PDFFontMgrMap[hDoc])
+ m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc));
}
+
void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) {
- CXFA_PDFFontMgr* pMgr = NULL;
- if (m_PDFFontMgrArray.Lookup(hDoc, (void*&)pMgr)) {
- delete pMgr;
- m_PDFFontMgrArray.RemoveKey(hDoc);
- }
-}
-void CXFA_FontMgr::DelAllMgrMap() {
- FX_POSITION ps = m_PDFFontMgrArray.GetStartPosition();
- while (ps) {
- CXFA_FFDoc* hDoc = NULL;
- CXFA_PDFFontMgr* pMgr = NULL;
- m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr);
- delete pMgr;
- }
- m_PDFFontMgrArray.RemoveAll();
- m_FontMap.clear();
+ m_PDFFontMgrMap.erase(hDoc);
}
+
void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) {
m_pDefFontMgr = pFontMgr;
}
diff --git a/xfa/fxfa/include/xfa_fontmgr.h b/xfa/fxfa/include/xfa_fontmgr.h
index c7358a4c2a..d2e731769a 100644
--- a/xfa/fxfa/include/xfa_fontmgr.h
+++ b/xfa/fxfa/include/xfa_fontmgr.h
@@ -8,6 +8,7 @@
#define XFA_FXFA_INCLUDE_XFA_FONTMGR_H_
#include <map>
+#include <memory>
#include "core/fxcrt/include/fx_ext.h"
#include "core/fxcrt/include/fx_system.h"
@@ -55,7 +56,7 @@ class CXFA_PDFFontMgr {
FX_WCHAR wUnicode,
int32_t& iWidth,
FX_BOOL bCharCode);
- CFX_MapPtrToPtr m_FDE2PDFFont;
+ std::map<IFX_Font*, CPDF_Font*> m_FDE2PDFFont;
protected:
IFX_Font* FindFont(CFX_ByteString strFamilyName,
@@ -80,20 +81,18 @@ class CXFA_FontMgr {
public:
CXFA_FontMgr();
~CXFA_FontMgr();
+
IFX_Font* GetFont(CXFA_FFDoc* hDoc,
const CFX_WideStringC& wsFontFamily,
uint32_t dwFontStyles,
uint16_t wCodePage = 0xFFFF);
void LoadDocFonts(CXFA_FFDoc* hDoc);
void ReleaseDocFonts(CXFA_FFDoc* hDoc);
-
void SetDefFontMgr(CXFA_DefFontMgr* pFontMgr);
protected:
- void DelAllMgrMap();
-
- CFX_MapPtrToPtr m_PDFFontMgrArray;
CXFA_DefFontMgr* m_pDefFontMgr;
+ std::map<CXFA_FFDoc*, std::unique_ptr<CXFA_PDFFontMgr>> m_PDFFontMgrMap;
std::map<CFX_ByteString, IFX_Font*> m_FontMap;
};