diff options
-rw-r--r-- | core/include/fpdfapi/fpdf_resource.h | 3 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 53 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/pageint.h | 22 |
3 files changed, 40 insertions, 38 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index 54aa1ccea9..268e75c7bf 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -43,12 +43,9 @@ public: ObjClass m_Obj; FX_DWORD m_nCount; }; -typedef CPDF_CountedObject<CPDF_StreamAcc*> CPDF_CountedStreamAcc; using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace*>; using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern*>; -typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedStreamAcc*> CPDF_FontFileMap; - #define PDFFONT_TYPE1 1 #define PDFFONT_TRUETYPE 2 #define PDFFONT_TYPE3 3 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<CPDF_StreamAcc*>* 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<CPDF_StreamAcc*>* 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_StreamAcc*>; + + 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<CPDF_StreamAcc*>* 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<CPDF_Font*>; using CPDF_CountedIccProfile = CPDF_CountedObject<CPDF_IccProfile*>; using CPDF_CountedImage = CPDF_CountedObject<CPDF_Image*>; + using CPDF_CountedStreamAcc = CPDF_CountedObject<CPDF_StreamAcc*>; using CPDF_ColorSpaceMap = std::map<CPDF_Object*, CPDF_CountedColorSpace*>; + using CPDF_FontFileMap = std::map<CPDF_Stream*, CPDF_CountedStreamAcc*>; using CPDF_FontMap = std::map<CPDF_Dictionary*, CPDF_CountedFont*>; using CPDF_IccProfileMap = std::map<CPDF_Stream*, CPDF_CountedIccProfile*>; using CPDF_ImageMap = std::map<FX_DWORD, CPDF_CountedImage*>; using CPDF_PatternMap = std::map<CPDF_Object*, CPDF_CountedPattern*>; - 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 |