summaryrefslogtreecommitdiff
path: root/xfa/fgas/font
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2017-01-06 09:48:18 -0800
committerCommit bot <commit-bot@chromium.org>2017-01-06 09:48:18 -0800
commit6fd07ef0a817dca5acbcadea41b8f880376f339a (patch)
treee330419f0289e503478bffc7638e836e113a7fe7 /xfa/fgas/font
parent8d94b6687f27e1238f352939434704f75b330c1d (diff)
downloadpdfium-6fd07ef0a817dca5acbcadea41b8f880376f339a.tar.xz
Remove CFX_MapPtrToPtr in xfa/fgas, part 2
Review-Url: https://codereview.chromium.org/2616623005
Diffstat (limited to 'xfa/fgas/font')
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp26
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h3
-rw-r--r--xfa/fgas/font/cfgas_gefont.cpp31
-rw-r--r--xfa/fgas/font/cfgas_gefont.h8
4 files changed, 32 insertions, 36 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 1849441a16..9d3954fb1e 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -575,14 +575,6 @@ CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum)
CFGAS_FontMgr::~CFGAS_FontMgr() {
for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++)
delete m_InstalledFonts[i];
- FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
- while (pos) {
- uint32_t dwHash;
- CFX_FontDescriptorInfos* pDescs;
- m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
- delete pDescs;
- }
- m_Hash2Fonts.clear();
}
bool CFGAS_FontMgr::EnumFontsFromFontMapper() {
@@ -645,12 +637,13 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage(
if (!pFontArray->empty())
return (*pFontArray)[0];
- CFX_FontDescriptorInfos* sortedFonts = nullptr;
- if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
- sortedFonts = new CFX_FontDescriptorInfos;
+ CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash].get();
+ if (!sortedFonts) {
+ auto pNewFonts = pdfium::MakeUnique<CFX_FontDescriptorInfos>();
+ sortedFonts = pNewFonts.get();
MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
CFX_WideString(pszFontFamily), 0);
- m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
+ m_Hash2CandidateList[dwHash] = std::move(pNewFonts);
}
if (sortedFonts->GetSize() == 0)
return nullptr;
@@ -688,12 +681,13 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode(
if (VerifyUnicode((*pFonts)[i], wUnicode))
return (*pFonts)[i];
}
- CFX_FontDescriptorInfos* sortedFonts = nullptr;
- if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
- sortedFonts = new CFX_FontDescriptorInfos;
+ CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash].get();
+ if (!sortedFonts) {
+ auto pNewFonts = pdfium::MakeUnique<CFX_FontDescriptorInfos>();
+ sortedFonts = pNewFonts.get();
MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
CFX_WideString(pszFontFamily), wUnicode);
- m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
+ m_Hash2CandidateList[dwHash] = std::move(pNewFonts);
}
for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) {
CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont;
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index c4030e76ee..20efa3296b 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -249,7 +249,8 @@ class CFGAS_FontMgr {
const CFX_ByteString& bsFaceName);
CFX_FontDescriptors m_InstalledFonts;
- CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList;
+ std::map<uint32_t, std::unique_ptr<CFX_FontDescriptorInfos>>
+ m_Hash2CandidateList;
std::map<uint32_t, std::vector<CFX_RetainPtr<CFGAS_GEFont>>> m_Hash2Fonts;
std::map<CFX_RetainPtr<CFGAS_GEFont>, CFX_RetainPtr<IFX_SeekableReadStream>>
m_IFXFont2FileRead;
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index fc202f6bc3..49639c2005 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -214,6 +214,7 @@ bool CFGAS_GEFont::LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont) {
bool CFGAS_GEFont::InitFont() {
if (!m_pFont)
return false;
+
if (!m_pFontEncoding) {
m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont));
if (!m_pFontEncoding)
@@ -225,9 +226,6 @@ bool CFGAS_GEFont::InitFont() {
}
if (!m_pRectArray)
m_pRectArray = pdfium::MakeUnique<CFX_MassArrayTemplate<CFX_Rect>>(16);
- if (!m_pBBoxMap)
- m_pBBoxMap = pdfium::MakeUnique<CFX_MapPtrToPtr>(16);
-
return true;
}
@@ -312,19 +310,19 @@ bool CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode,
}
bool CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode,
- CFX_Rect& bbox,
+ CFX_Rect* bbox,
bool bCharCode) {
return GetCharBBoxInternal(wUnicode, bbox, true, bCharCode);
}
bool CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
- CFX_Rect& bbox,
+ CFX_Rect* bbox,
bool bRecursive,
bool bCharCode) {
ASSERT(m_pRectArray);
- ASSERT(m_pBBoxMap);
- void* pRect = nullptr;
- if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) {
+ CFX_Rect* pRect = nullptr;
+ auto it = m_BBoxMap.find(wUnicode);
+ if (it == m_BBoxMap.end()) {
CFX_RetainPtr<CFGAS_GEFont> pFont;
int32_t iGlyph = GetGlyphIndex(wUnicode, true, &pFont, bCharCode);
if (iGlyph != 0xFFFF && pFont) {
@@ -335,28 +333,31 @@ bool CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height());
int32_t index = m_pRectArray->Add(rt);
pRect = m_pRectArray->GetPtrAt(index);
- m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect);
+ m_BBoxMap[wUnicode] = pRect;
}
} else if (pFont->GetCharBBoxInternal(wUnicode, bbox, false, bCharCode)) {
return true;
}
}
+ } else {
+ pRect = it->second;
}
if (!pRect)
return false;
- bbox = *static_cast<const CFX_Rect*>(pRect);
+ *bbox = *pRect;
return true;
}
-bool CFGAS_GEFont::GetBBox(CFX_Rect& bbox) {
+bool CFGAS_GEFont::GetBBox(CFX_Rect* bbox) {
FX_RECT rt(0, 0, 0, 0);
if (!m_pFont->GetBBox(rt))
return false;
- bbox.left = rt.left;
- bbox.width = rt.Width();
- bbox.top = rt.bottom;
- bbox.height = -rt.Height();
+
+ bbox->left = rt.left;
+ bbox->width = rt.Width();
+ bbox->top = rt.bottom;
+ bbox->height = -rt.Height();
return true;
}
diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h
index 962b93fbb5..de4f9639e0 100644
--- a/xfa/fgas/font/cfgas_gefont.h
+++ b/xfa/fgas/font/cfgas_gefont.h
@@ -55,8 +55,8 @@ class CFGAS_GEFont : public CFX_Retainable {
int32_t GetGlyphIndex(FX_WCHAR wUnicode, bool bCharCode = false);
int32_t GetAscent() const;
int32_t GetDescent() const;
- bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect& bbox, bool bCharCode = false);
- bool GetBBox(CFX_Rect& bbox);
+ bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect* bbox, bool bCharCode = false);
+ bool GetBBox(CFX_Rect* bbox);
CFX_RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex) const;
CFX_Font* GetDevFont() const { return m_pFont; }
void SetFontProvider(CXFA_PDFFontMgr* pProvider) { m_pProvider = pProvider; }
@@ -83,7 +83,7 @@ class CFGAS_GEFont : public CFX_Retainable {
bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont);
bool InitFont();
bool GetCharBBoxInternal(FX_WCHAR wUnicode,
- CFX_Rect& bbox,
+ CFX_Rect* bbox,
bool bRecursive,
bool bCharCode = false);
bool GetCharWidthInternal(FX_WCHAR wUnicode,
@@ -109,7 +109,7 @@ class CFGAS_GEFont : public CFX_Retainable {
std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding;
std::unique_ptr<CFX_DiscreteArrayTemplate<uint16_t>> m_pCharWidthMap;
std::unique_ptr<CFX_MassArrayTemplate<CFX_Rect>> m_pRectArray;
- std::unique_ptr<CFX_MapPtrToPtr> m_pBBoxMap;
+ std::map<FX_WCHAR, CFX_Rect*> m_BBoxMap; // Rect owned by m_pRectArray.
CXFA_PDFFontMgr* m_pProvider; // not owned.
std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_SubstFonts;
std::map<FX_WCHAR, CFX_RetainPtr<CFGAS_GEFont>> m_FontMapper;