summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-06-10 23:19:42 -0700
committerLei Zhang <thestig@chromium.org>2015-06-10 23:19:42 -0700
commit461bb6aea17b573983476a78c64e77eb2e30aebf (patch)
tree024d395d2918cf605b223e5a392d9f6f0d33a578 /core/src/fpdfapi
parent4de48f764fd8369ecae258b410801b88925c0990 (diff)
downloadpdfium-461bb6aea17b573983476a78c64e77eb2e30aebf.tar.xz
Merge to XFA: Convert CPDF_PatternMap to std::map.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1162123004. (cherry picked from commit b3aa96cbee31e81d0a72a61027467a2713654499) Review URL: https://codereview.chromium.org/1181573005.
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp92
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h3
2 files changed, 42 insertions, 53 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index a5ca976182..e00e6cb01c 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -126,13 +126,11 @@ void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj)
}
CPDF_DocPageData::CPDF_DocPageData(CPDF_Document *pPDFDoc)
: m_pPDFDoc(pPDFDoc),
- m_PatternMap(),
m_ImageMap(),
m_IccProfileMap(),
m_FontFileMap(),
m_bForceClear(FALSE)
{
- m_PatternMap.InitHashTable(16);
m_ImageMap.InitHashTable(64);
m_IccProfileMap.InitHashTable(16);
m_FontFileMap.InitHashTable(32);
@@ -142,15 +140,10 @@ CPDF_DocPageData::~CPDF_DocPageData()
{
Clear(FALSE);
Clear(TRUE);
- FX_POSITION pos = m_PatternMap.GetStartPosition();
- while (pos)
- {
- CPDF_Object* ptObj;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
- delete ptData;
- }
- m_PatternMap.RemoveAll();
+
+ for (auto& it : m_PatternMap)
+ delete it.second;
+ m_PatternMap.clear();
for (auto& it : m_FontMap)
delete it.second;
@@ -163,20 +156,17 @@ CPDF_DocPageData::~CPDF_DocPageData()
void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
{
- FX_POSITION pos;
m_bForceClear = bForceRelease;
- pos = m_PatternMap.GetStartPosition();
- while (pos) {
- CPDF_Object* ptObj;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- m_PatternMap.GetNextAssoc(pos, ptObj, ptData);
- if (!ptData->m_Obj) {
+
+ for (auto& it : m_PatternMap) {
+ CPDF_CountedPattern* ptData = it.second;
+ if (!ptData->m_Obj)
continue;
- }
+
if (bForceRelease || ptData->m_nCount < 2) {
ptData->m_Obj->SetForceClear(bForceRelease);
delete ptData->m_Obj;
- ptData->m_Obj = NULL;
+ ptData->m_Obj = nullptr;
}
}
@@ -202,7 +192,7 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease)
}
}
- pos = m_IccProfileMap.GetStartPosition();
+ FX_POSITION pos = m_IccProfileMap.GetStartPosition();
while (pos) {
CPDF_Stream* ipKey;
CPDF_CountedObject<CPDF_IccProfile*>* ipData;
@@ -471,26 +461,23 @@ void CPDF_DocPageData::ReleaseColorSpace(CPDF_Object* pColorSpace)
CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_AffineMatrix* matrix)
{
- if (!pPatternObj) {
- return NULL;
- }
- CPDF_CountedObject<CPDF_Pattern*>* ptData = NULL;
- if (m_PatternMap.Lookup(pPatternObj, ptData)) {
+ if (!pPatternObj)
+ return nullptr;
+
+ CPDF_CountedPattern* ptData = nullptr;
+ auto it = m_PatternMap.find(pPatternObj);
+ if (it != m_PatternMap.end()) {
+ ptData = it->second;
if (ptData->m_Obj) {
ptData->m_nCount++;
return ptData->m_Obj;
}
}
- FX_BOOL bNew = FALSE;
- if (!ptData) {
- ptData = new CPDF_CountedObject<CPDF_Pattern*>;
- bNew = TRUE;
- }
- CPDF_Pattern* pPattern = NULL;
+ CPDF_Pattern* pPattern = nullptr;
if (bShading) {
pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, matrix);
} else {
- CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : NULL;
+ CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr;
if (pDict) {
int type = pDict->GetInteger(FX_BSTRC("PatternType"));
if (type == 1) {
@@ -500,31 +487,34 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bSh
}
}
}
- if (!pPattern) {
- if (bNew) {
- delete ptData;
- }
- return NULL;
+ if (!pPattern)
+ return nullptr;
+
+ if (!ptData) {
+ ptData = new CPDF_CountedPattern;
+ m_PatternMap[pPatternObj] = ptData;
}
ptData->m_nCount = 2;
ptData->m_Obj = pPattern;
- m_PatternMap.SetAt(pPatternObj, ptData);
return pPattern;
}
+
void CPDF_DocPageData::ReleasePattern(CPDF_Object* pPatternObj)
{
- if (!pPatternObj) {
+ if (!pPatternObj)
return;
- }
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- if (!m_PatternMap.Lookup(pPatternObj, ptData)) {
+
+ auto it = m_PatternMap.find(pPatternObj);
+ if (it == m_PatternMap.end())
return;
- }
+
+ CPDF_CountedPattern* ptData = it->second;
if (ptData->m_Obj && --ptData->m_nCount == 0) {
delete ptData->m_Obj;
- ptData->m_Obj = NULL;
+ ptData->m_Obj = nullptr;
}
}
+
CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream)
{
if (!pImageStream) {
@@ -641,11 +631,9 @@ CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(CPDF_Object* pCSObj)
CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj) const
{
- if (!pPatternObj) return NULL;
- CPDF_CountedObject<CPDF_Pattern*>* ptData;
- if (m_PatternMap.Lookup(pPatternObj, ptData))
- {
- return ptData;
- }
- return NULL;
+ if (!pPatternObj)
+ return nullptr;
+
+ auto it = m_PatternMap.find(pPatternObj);
+ return it != m_PatternMap.end() ? it->second : nullptr;
}
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index 68e1a4bf36..70b4624e7e 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_PatternMap m_PatternMap;
CPDF_ImageMap m_ImageMap;
CPDF_IccProfileMap m_IccProfileMap;
CFX_MapByteStringToPtr m_HashProfileMap;
@@ -400,9 +399,11 @@ class CPDF_DocPageData
using CPDF_ColorSpaceMap = std::map<CPDF_Object*, CPDF_CountedColorSpace*>;
using CPDF_FontMap = std::map<CPDF_Dictionary*, CPDF_CountedFont*>;
+ using CPDF_PatternMap = std::map<CPDF_Object*, CPDF_CountedPattern*>;
CPDF_ColorSpaceMap m_ColorSpaceMap;
CPDF_FontMap m_FontMap;
+ CPDF_PatternMap m_PatternMap;
};
class CPDF_Function