summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-06-10 11:32:54 -0700
committerLei Zhang <thestig@chromium.org>2015-06-10 11:32:54 -0700
commit22f429fc4875027b10ab071102c9ac8a88abf825 (patch)
tree1f66f6ce3ea02a76276a73a7f178e55a0ecca078 /core
parentfbf266fc0ea4be2523cbb901a641aa33f0035662 (diff)
downloadpdfium-22f429fc4875027b10ab071102c9ac8a88abf825.tar.xz
Convert CPDF_ColorSpaceMap to std::map.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1154963003.
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfapi/fpdf_resource.h3
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp121
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h4
3 files changed, 60 insertions, 68 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 651b894ec2..60a93e1832 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -43,14 +43,13 @@ public:
ObjClass m_Obj;
FX_DWORD m_nCount;
};
-typedef CPDF_CountedObject<CPDF_ColorSpace*> CPDF_CountedColorSpace;
typedef CPDF_CountedObject<CPDF_Pattern*> CPDF_CountedPattern;
typedef CPDF_CountedObject<CPDF_Image*> CPDF_CountedImage;
typedef CPDF_CountedObject<CPDF_IccProfile*> CPDF_CountedICCProfile;
typedef CPDF_CountedObject<CPDF_StreamAcc*> CPDF_CountedStreamAcc;
+using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace*>;
-typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedColorSpace*> CPDF_ColorSpaceMap;
typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedPattern*> CPDF_PatternMap;
typedef CFX_MapPtrTemplate<FX_DWORD, CPDF_CountedImage*> CPDF_ImageMap;
typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedICCProfile*> CPDF_IccProfileMap;
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index be54747285..81cfd00fe3 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -126,14 +126,12 @@ void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj)
}
CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc)
: m_pPDFDoc(pPDFDoc),
- m_ColorSpaceMap(),
m_PatternMap(),
m_ImageMap(),
m_IccProfileMap(),
m_FontFileMap(),
m_bForceClear(FALSE)
{
- m_ColorSpaceMap.InitHashTable(32);
m_PatternMap.InitHashTable(16);
m_ImageMap.InitHashTable(64);
m_IccProfileMap.InitHashTable(16);
@@ -158,15 +156,9 @@ CPDF_DocPageData::~CPDF_DocPageData()
delete it.second;
m_FontMap.clear();
- pos = m_ColorSpaceMap.GetStartPosition();
- while (pos)
- {
- CPDF_Object* csKey;
- CPDF_CountedObject<CPDF_ColorSpace*>* csData;
- m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
- delete csData;
- }
- m_ColorSpaceMap.RemoveAll();
+ for (auto& it : m_ColorSpaceMap)
+ delete it.second;
+ m_ColorSpaceMap.clear();
}
void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
@@ -199,20 +191,17 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
}
}
- pos = m_ColorSpaceMap.GetStartPosition();
- while (pos) {
- CPDF_Object* csKey;
- CPDF_CountedObject<CPDF_ColorSpace*>* csData;
- m_ColorSpaceMap.GetNextAssoc(pos, csKey, csData);
- if (!csData->m_Obj) {
+ for (auto& it : m_ColorSpaceMap) {
+ CPDF_CountedColorSpace* csData = it.second;
+ if (!csData->m_Obj)
continue;
- }
+
if (bForceRelease || csData->m_nCount < 2) {
- // csData->m_Obj is deleted in the function of ReleaseCS().
csData->m_Obj->ReleaseCS();
- csData->m_Obj = NULL;
+ csData->m_Obj = nullptr;
}
}
+
pos = m_IccProfileMap.GetStartPosition();
while (pos) {
CPDF_Stream* ipKey;
@@ -415,69 +404,71 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(CPDF_Object* pCSObj, CPDF_Dicti
}
return GetColorSpace(pDefaultCS, NULL);
}
- if (pCSObj->GetType() != PDFOBJ_ARRAY) {
- return NULL;
- }
+
+ if (pCSObj->GetType() != PDFOBJ_ARRAY)
+ return nullptr;
CPDF_Array* pArray = (CPDF_Array*)pCSObj;
- if (pArray->GetCount() == 0) {
- return NULL;
- }
- if (pArray->GetCount() == 1) {
+ if (pArray->GetCount() == 0)
+ return nullptr;
+ if (pArray->GetCount() == 1)
return GetColorSpace(pArray->GetElementValue(0), pResources);
- }
- CPDF_CountedObject<CPDF_ColorSpace*>* csData = NULL;
- if (m_ColorSpaceMap.Lookup(pCSObj, csData)) {
+
+ CPDF_CountedColorSpace* csData = nullptr;
+ auto it = m_ColorSpaceMap.find(pCSObj);
+ if (it != m_ColorSpaceMap.end()) {
+ csData = it->second;
if (csData->m_Obj) {
csData->m_nCount++;
return csData->m_Obj;
}
}
- FX_BOOL bNew = FALSE;
- if (!csData) {
- csData = new CPDF_CountedObject<CPDF_ColorSpace*>;
- bNew = TRUE;
- }
+
CPDF_ColorSpace* pCS = CPDF_ColorSpace::Load(m_pPDFDoc, pArray);
- if (!pCS) {
- if (bNew) {
- delete csData;
- }
- return NULL;
+ if (!pCS)
+ return nullptr;
+
+ if (!csData) {
+ csData = new CPDF_CountedColorSpace;
+ m_ColorSpaceMap[pCSObj] = csData;
}
csData->m_nCount = 2;
csData->m_Obj = pCS;
- m_ColorSpaceMap.SetAt(pCSObj, csData);
return pCS;
}
+
CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj)
{
- if (!pCSObj) {
- return NULL;
- }
- CPDF_CountedObject<CPDF_ColorSpace*>* csData;
- if (!m_ColorSpaceMap.Lookup(pCSObj, csData)) {
- return NULL;
- }
- if (!csData->m_Obj) {
- return NULL;
- }
- csData->m_nCount ++;
+ if (!pCSObj)
+ return nullptr;
+
+ auto it = m_ColorSpaceMap.find(pCSObj);
+ if (it == m_ColorSpaceMap.end())
+ return nullptr;
+
+ CPDF_CountedColorSpace* csData = it->second;
+ if (!csData->m_Obj)
+ return nullptr;
+
+ csData->m_nCount++;
return csData->m_Obj;
}
+
void CPDF_DocPageData::ReleaseColorSpace(CPDF_Object* pColorSpace)
{
- if (!pColorSpace) {
+ if (!pColorSpace)
return;
- }
- CPDF_CountedObject<CPDF_ColorSpace*>* csData;
- if (!m_ColorSpaceMap.Lookup(pColorSpace, csData)) {
+
+ auto it = m_ColorSpaceMap.find(pColorSpace);
+ if (it == m_ColorSpaceMap.end())
return;
- }
+
+ CPDF_CountedColorSpace* csData = it->second;
if (csData->m_Obj && --csData->m_nCount == 0) {
csData->m_Obj->ReleaseCS();
- csData->m_Obj = NULL;
+ csData->m_Obj = nullptr;
}
}
+
CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_AffineMatrix* matrix)
{
if (!pPatternObj) {
@@ -638,16 +629,16 @@ void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
}
PDF_DocPageData_Release<CPDF_Stream*, CPDF_StreamAcc*>(m_FontFileMap, pFontStream, NULL, bForce);
}
+
CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(CPDF_Object* pCSObj) const
{
- if (!pCSObj) return NULL;
- CPDF_CountedObject<CPDF_ColorSpace*>* csData;
- if (m_ColorSpaceMap.Lookup(pCSObj, csData))
- {
- return csData;
- }
- return NULL;
+ if (!pCSObj)
+ return nullptr;
+
+ auto it = m_ColorSpaceMap.find(pCSObj);
+ return it != m_ColorSpaceMap.end() ? it->second : nullptr;
}
+
CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj) const
{
if (!pPatternObj) return NULL;
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index 815e146ef8..e994576da5 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -388,7 +388,6 @@ class CPDF_DocPageData
CPDF_CountedPattern* FindPatternPtr(CPDF_Object* pPatternObj) const;
CPDF_Document* m_pPDFDoc;
- CPDF_ColorSpaceMap m_ColorSpaceMap;
CPDF_PatternMap m_PatternMap;
CPDF_ImageMap m_ImageMap;
CPDF_IccProfileMap m_IccProfileMap;
@@ -398,8 +397,11 @@ class CPDF_DocPageData
private:
using CPDF_CountedFont = CPDF_CountedObject<CPDF_Font*>;
+
+ using CPDF_ColorSpaceMap = std::map<CPDF_Object*, CPDF_CountedColorSpace*>;
using CPDF_FontMap = std::map<CPDF_Dictionary*, CPDF_CountedFont*>;
+ CPDF_ColorSpaceMap m_ColorSpaceMap;
CPDF_FontMap m_FontMap;
};