summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorOliver Chang <ochang@chromium.org>2016-01-11 08:45:31 -0800
committerOliver Chang <ochang@chromium.org>2016-01-11 08:45:31 -0800
commit3f1c71f5a6ea058e3eec611c9dcc759b374dcb80 (patch)
treeb4ef8de26360979381c441cbdfaba94e493b09f6 /fpdfsdk/src
parentc909ce872d999a17ffd44afdc88caf2de43e6cba (diff)
downloadpdfium-3f1c71f5a6ea058e3eec611c9dcc759b374dcb80.tar.xz
Merge to XFA: Use std::map as CPDF_Dictionary's underlying store.
Replaces CFX_CMapByteStringToPtr. XFA still uses CFX_CMapByteStringToPtr so it's not completely removed just yet. Adds begin()/end() to CPDF_Dictionary and removes the GetStartPos()/GetNextElement() functions to traverse the dictionary. Callers are changed accordingly. AddValue() is also removed. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1541703003 . (cherry picked from commit 14f39950451bb9c2a11fbc7173fd47367410f80f) Review URL: https://codereview.chromium.org/1576033002 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp8
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp7
-rw-r--r--fpdfsdk/src/fpdf_transformpage.cpp8
-rw-r--r--fpdfsdk/src/fpdfedit_embeddertest.cpp11
-rw-r--r--fpdfsdk/src/fpdfppo.cpp15
-rw-r--r--fpdfsdk/src/fpdfview.cpp26
-rw-r--r--fpdfsdk/src/javascript/Document.cpp7
7 files changed, 41 insertions, 41 deletions
diff --git a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
index 1649eaf35d..9253563c38 100644
--- a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
+++ b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
@@ -118,11 +118,9 @@ CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
CPDF_Font* pFind = NULL;
- FX_POSITION pos = pFonts->GetStartPos();
- while (pos) {
- CPDF_Object* pObj = NULL;
- CFX_ByteString csKey;
- pObj = pFonts->GetNextElement(pos, csKey);
+ for (const auto& it : *pFonts) {
+ const CFX_ByteString& csKey = it.first;
+ CPDF_Object* pObj = it.second;
if (!pObj)
continue;
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index 76ffec3e26..2a0c2d947c 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -440,10 +440,9 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
if (!sAnnotState.IsEmpty()) {
pAPStream = pAPDic->GetStream(sAnnotState);
} else {
- FX_POSITION pos = pAPDic->GetStartPos();
- if (pos) {
- CFX_ByteString sKey;
- CPDF_Object* pFirstObj = pAPDic->GetNextElement(pos, sKey);
+ auto it = pAPDic->begin();
+ if (it != pAPDic->end()) {
+ CPDF_Object* pFirstObj = it->second;
if (pFirstObj) {
if (pFirstObj->IsReference())
pFirstObj = pFirstObj->GetDirect();
diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp
index 3f6ab972c8..3e2c7b1151 100644
--- a/fpdfsdk/src/fpdf_transformpage.cpp
+++ b/fpdfsdk/src/fpdf_transformpage.cpp
@@ -160,14 +160,12 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
if (pRes) {
CPDF_Dictionary* pPattenDict = pRes->GetDict("Pattern");
if (pPattenDict) {
- FX_POSITION pos = pPattenDict->GetStartPos();
- while (pos) {
- CPDF_Dictionary* pDict = nullptr;
- CFX_ByteString key;
- CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key);
+ for (const auto& it : *pPattenDict) {
+ CPDF_Object* pObj = it.second;
if (pObj->IsReference())
pObj = pObj->GetDirect();
+ CPDF_Dictionary* pDict = nullptr;
if (pObj->IsDictionary())
pDict = pObj->AsDictionary();
else if (CPDF_Stream* pStream = pObj->AsStream())
diff --git a/fpdfsdk/src/fpdfedit_embeddertest.cpp b/fpdfsdk/src/fpdfedit_embeddertest.cpp
index 1cd28cff45..480ef51dbd 100644
--- a/fpdfsdk/src/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfedit_embeddertest.cpp
@@ -22,20 +22,21 @@ TEST_F(FPDFEditEmbeddertest, EmptyCreation) {
"%PDF-1.7\r\n"
"%\xA1\xB3\xC5\xD7\r\n"
"1 0 obj\r\n"
- "<</Type/Catalog/Pages 2 0 R >>\r\n"
+ "<</Pages 2 0 R /Type/Catalog>>\r\n"
"endobj\r\n"
"2 0 obj\r\n"
- "<</Type/Pages/Count 1/Kids\\[ 4 0 R \\]>>\r\n"
+ "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n"
"endobj\r\n"
"3 0 obj\r\n"
"<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n"
"endobj\r\n"
"4 0 obj\r\n"
- "<</Type/Page/Parent 2 0 R /MediaBox\\[ 0 0 640 "
- "480\\]/Rotate 0/Resources<<>>/Contents 5 0 R >>\r\n"
+ "<</Contents 5 0 R /MediaBox\\[ 0 0 640 480\\]"
+ "/Parent 2 0 R /Resources<<>>/Rotate 0/Type/Page"
+ ">>\r\n"
"endobj\r\n"
"5 0 obj\r\n"
- "<</Length 8/Filter/FlateDecode>>stream\r\n"
+ "<</Filter/FlateDecode/Length 8>>stream\r\n"
"x\x9C\x3\0\0\0\0\x1\r\n"
"endstream\r\n"
"endobj\r\n"
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index 50ef262560..dac548131e 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -101,10 +101,9 @@ FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc,
return FALSE;
// Clone the page dictionary
- FX_POSITION SrcPos = pSrcPageDict->GetStartPos();
- while (SrcPos) {
- CFX_ByteString cbSrcKeyStr;
- CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr);
+ for (const auto& it : *pSrcPageDict) {
+ const CFX_ByteString& cbSrcKeyStr = it.first;
+ CPDF_Object* pObj = it.second;
if (cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent"))) {
if (pCurPageDict->KeyExist(cbSrcKeyStr))
pCurPageDict->RemoveAt(cbSrcKeyStr);
@@ -214,11 +213,9 @@ FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
}
case PDFOBJ_DICTIONARY: {
CPDF_Dictionary* pDict = pObj->AsDictionary();
-
- FX_POSITION pos = pDict->GetStartPos();
- while (pos) {
- CFX_ByteString key("");
- CPDF_Object* pNextObj = pDict->GetNextElement(pos, key);
+ for (const auto& it : *pDict) {
+ const CFX_ByteString& key = it.first;
+ CPDF_Object* pNextObj = it.second;
if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") ||
!FXSYS_strcmp(key, "First")) {
continue;
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index e047b50846..a6c14206ce 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -1049,11 +1049,15 @@ DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
return 0;
CPDF_NameTree nameTree(pDoc, "Dests");
- int count = nameTree.GetCount();
+ pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount();
CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
if (pDest)
count += pDest->GetCount();
- return count;
+
+ if (!count.IsValid())
+ return 0;
+
+ return count.ValueOrDie();
}
DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
@@ -1141,21 +1145,25 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
if (!pRoot)
return nullptr;
- CPDF_Object* pDestObj = NULL;
+ CPDF_Object* pDestObj = nullptr;
CFX_ByteString bsName;
CPDF_NameTree nameTree(pDoc, "Dests");
int count = nameTree.GetCount();
if (index >= count) {
CPDF_Dictionary* pDest = pRoot->GetDict("Dests");
if (!pDest)
- return NULL;
- if (index >= count + pDest->GetCount())
- return NULL;
+ return nullptr;
+
+ pdfium::base::CheckedNumeric<int> checked_count = count;
+ checked_count += pDest->GetCount();
+ if (!checked_count.IsValid() || index >= checked_count.ValueOrDie())
+ return nullptr;
+
index -= count;
- FX_POSITION pos = pDest->GetStartPos();
int i = 0;
- while (pos) {
- pDestObj = pDest->GetNextElement(pos, bsName);
+ for (const auto& it : *pDest) {
+ bsName = it.first;
+ pDestObj = it.second;
if (!pDestObj)
continue;
if (i == index)
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index db98fcc5e4..1040c34770 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -790,10 +790,9 @@ FX_BOOL Document::info(IJS_Context* cc,
FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
// It's to be compatible to non-standard info dictionary.
- FX_POSITION pos = pDictionary->GetStartPos();
- while (pos) {
- CFX_ByteString bsKey;
- CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
+ for (const auto& it : *pDictionary) {
+ const CFX_ByteString& bsKey = it.first;
+ CPDF_Object* pValueObj = it.second;
CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
if (pValueObj->IsString() || pValueObj->IsName()) {