From f726c92cb2cf5739fd5b21e825e5bf510040c62f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 10 Jun 2015 19:24:29 -0700 Subject: Convert CPDF_FontFileMap to std::map. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1144333008. --- core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 53 +++++++++++++++------------- core/src/fpdfapi/fpdf_page/pageint.h | 22 ++++++------ 2 files changed, 40 insertions(+), 35 deletions(-) (limited to 'core/src') diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 00d62fb7bd..7ccf948698 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -124,12 +124,10 @@ void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj) } GetPageData()->ReleaseColorSpace(pCSObj); } -CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc) +CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) : m_pPDFDoc(pPDFDoc), - m_FontFileMap(), m_bForceClear(FALSE) { - m_FontFileMap.InitHashTable(32); } CPDF_DocPageData::~CPDF_DocPageData() @@ -212,18 +210,16 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) } } - FX_POSITION pos = m_FontFileMap.GetStartPosition(); - while (pos) { - CPDF_Stream* ftKey; - CPDF_CountedObject* ftData; - m_FontFileMap.GetNextAssoc(pos, ftKey, ftData); - if (!ftData->m_Obj) { + for (auto it = m_FontFileMap.begin(); it != m_FontFileMap.end();) { + auto curr_it = it++; + CPDF_CountedStreamAcc* ftData = curr_it->second; + if (!ftData->m_Obj) continue; - } + if (bForceRelease || ftData->m_nCount < 2) { delete ftData->m_Obj; delete ftData; - m_FontFileMap.RemoveKey(ftKey); + m_FontFileMap.erase(curr_it); } } @@ -603,42 +599,49 @@ void CPDF_DocPageData::ReleaseIccProfile(CPDF_IccProfile* pIccProfile) CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(CPDF_Stream* pFontStream) { - if (!pFontStream) { - return NULL; - } - CPDF_CountedObject* ftData; - if (m_FontFileMap.Lookup(pFontStream, ftData)) { - ftData->m_nCount ++; + if (!pFontStream) + return nullptr; + + auto it = m_FontFileMap.find(pFontStream); + if (it != m_FontFileMap.end()) { + CPDF_CountedStreamAcc* ftData = it->second; + ftData->m_nCount++; return ftData->m_Obj; } - ftData = new CPDF_CountedObject; + + CPDF_CountedStreamAcc* ftData = new CPDF_CountedStreamAcc; CPDF_StreamAcc* pFontFile = new CPDF_StreamAcc; CPDF_Dictionary* pFontDict = pFontStream->GetDict(); - int32_t org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + pFontDict->GetInteger(FX_BSTRC("Length2")) + pFontDict->GetInteger(FX_BSTRC("Length3")); - if (org_size < 0) { + int32_t org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + + pFontDict->GetInteger(FX_BSTRC("Length2")) + + pFontDict->GetInteger(FX_BSTRC("Length3")); + if (org_size < 0) org_size = 0; - } + pFontFile->LoadAllData(pFontStream, FALSE, org_size); ftData->m_nCount = 2; ftData->m_Obj = pFontFile; - m_FontFileMap.SetAt(pFontStream, ftData); + m_FontFileMap[pFontStream] = ftData; return pFontFile; } + void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOOL bForce) { if (!pFontStream) return; - CPDF_CountedObject* findData = nullptr; - if (!m_FontFileMap.Lookup(pFontStream, findData)) + auto it = m_FontFileMap.find(pFontStream); + if (it == m_FontFileMap.end()) return; + + CPDF_CountedStreamAcc* findData = it->second; if (!findData) return; if ((--findData->m_nCount) == 0 || bForce) { delete findData->m_Obj; delete findData; - m_FontFileMap.RemoveKey(pFontStream); + m_FontFileMap.erase(it); } } diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h index ea48ef4fe3..eda0b9848a 100644 --- a/core/src/fpdfapi/fpdf_page/pageint.h +++ b/core/src/fpdfapi/fpdf_page/pageint.h @@ -352,27 +352,29 @@ class CPDF_DocPageData CPDF_CountedColorSpace* FindColorSpacePtr(CPDF_Object* pCSObj) const; CPDF_CountedPattern* FindPatternPtr(CPDF_Object* pPatternObj) const; - CPDF_Document* m_pPDFDoc; - CFX_MapByteStringToPtr m_HashProfileMap; - CPDF_FontFileMap m_FontFileMap; - FX_BOOL m_bForceClear; - private: using CPDF_CountedFont = CPDF_CountedObject; using CPDF_CountedIccProfile = CPDF_CountedObject; using CPDF_CountedImage = CPDF_CountedObject; + using CPDF_CountedStreamAcc = CPDF_CountedObject; using CPDF_ColorSpaceMap = std::map; + using CPDF_FontFileMap = std::map; using CPDF_FontMap = std::map; using CPDF_IccProfileMap = std::map; using CPDF_ImageMap = std::map; using CPDF_PatternMap = std::map; - CPDF_ColorSpaceMap m_ColorSpaceMap; - CPDF_FontMap m_FontMap; - CPDF_IccProfileMap m_IccProfileMap; - CPDF_ImageMap m_ImageMap; - CPDF_PatternMap m_PatternMap; + CPDF_Document* const m_pPDFDoc; + CFX_MapByteStringToPtr m_HashProfileMap; + FX_BOOL m_bForceClear; + + CPDF_ColorSpaceMap m_ColorSpaceMap; + CPDF_FontFileMap m_FontFileMap; + CPDF_FontMap m_FontMap; + CPDF_IccProfileMap m_IccProfileMap; + CPDF_ImageMap m_ImageMap; + CPDF_PatternMap m_PatternMap; }; class CPDF_Function -- cgit v1.2.3