Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: fpdfsdk/fpdfppo.cpp

Issue 2493283003: Fix nits in CPDF_PageOrganizer. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fpdfppo.cpp
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index f8b96de1f379ad00c5e277d0e589f2a8ff687c5f..7c839ad24bf8bf6e79a6cb4e3cbb6c7280591aa9 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -27,9 +27,9 @@ class CPDF_PageOrganizer {
~CPDF_PageOrganizer();
bool PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc);
- bool ExportPage(CPDF_Document* pSrcPDFDoc,
- std::vector<uint16_t>* pPageNums,
- CPDF_Document* pDestPDFDoc,
+ bool ExportPage(CPDF_Document* pDestPDFDoc,
+ CPDF_Document* pSrcPDFDoc,
+ const std::vector<uint16_t>& pageNums,
int nIndex);
CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict,
const CFX_ByteString& bsSrctag);
@@ -54,13 +54,13 @@ bool CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
if (!pNewRoot)
return false;
- CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo();
- if (!DInfoDict)
+ CPDF_Dictionary* pDocInfoDict = pDestPDFDoc->GetInfo();
+ if (!pDocInfoDict)
return false;
CFX_ByteString producerstr;
producerstr.Format("PDFium");
- DInfoDict->SetFor("Producer", new CPDF_String(producerstr, false));
+ pDocInfoDict->SetFor("Producer", new CPDF_String(producerstr, false));
CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", "");
if (cbRootType.IsEmpty())
@@ -76,9 +76,8 @@ bool CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
}
CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", "");
- if (cbPageType == "") {
+ if (cbPageType.IsEmpty())
pNewPages->SetFor("Type", new CPDF_Name("Pages"));
- }
if (!pNewPages->GetArrayFor("Kids")) {
pNewPages->SetIntegerFor("Count", 0);
@@ -89,16 +88,16 @@ bool CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
return true;
}
-bool CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc,
- std::vector<uint16_t>* pPageNums,
- CPDF_Document* pDestPDFDoc,
+bool CPDF_PageOrganizer::ExportPage(CPDF_Document* pDestPDFDoc,
+ CPDF_Document* pSrcPDFDoc,
+ const std::vector<uint16_t>& pageNums,
int nIndex) {
int curpage = nIndex;
- std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap);
- int nSize = pdfium::CollectionSize<int>(*pPageNums);
+ auto pObjNumberMap = pdfium::MakeUnique<ObjectNumberMap>();
+ int nSize = pdfium::CollectionSize<int>(pageNums);
for (int i = 0; i < nSize; ++i) {
CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
- CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1);
+ CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pageNums[i] - 1);
if (!pSrcPageDict || !pCurPageDict)
return false;
@@ -114,13 +113,15 @@ bool CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc,
}
// inheritable item
- CPDF_Object* pInheritable = nullptr;
- // 1 MediaBox //required
+ // 1 MediaBox - required
if (!pCurPageDict->KeyExist("MediaBox")) {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox");
- if (!pInheritable) {
- // Search the "CropBox" from source page dictionary,
- // if not exists,we take the letter size.
+ CPDF_Object* pInheritable =
+ PageDictGetInheritableTag(pSrcPageDict, "MediaBox");
+ if (pInheritable) {
+ pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release());
+ } else {
+ // Search for "CropBox" in the source page dictionary,
+ // if it does not exists, use the default letter size.
pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
if (pInheritable) {
pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release());
@@ -133,26 +134,27 @@ bool CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc,
pArray->AddNumber(792);
pCurPageDict->SetFor("MediaBox", pArray);
}
- } else {
- pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release());
}
}
- // 2 Resources //required
+ // 2 Resources - required
if (!pCurPageDict->KeyExist("Resources")) {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources");
+ CPDF_Object* pInheritable =
Tom Sepez 2016/11/14 17:31:35 Helper method?
Lei Zhang 2016/11/14 19:57:01 Done.
+ PageDictGetInheritableTag(pSrcPageDict, "Resources");
if (!pInheritable)
return false;
pCurPageDict->SetFor("Resources", pInheritable->Clone().release());
}
- // 3 CropBox //Optional
+ // 3 CropBox - optional
if (!pCurPageDict->KeyExist("CropBox")) {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
+ CPDF_Object* pInheritable =
+ PageDictGetInheritableTag(pSrcPageDict, "CropBox");
if (pInheritable)
pCurPageDict->SetFor("CropBox", pInheritable->Clone().release());
}
- // 4 Rotate //Optional
+ // 4 Rotate - optional
if (!pCurPageDict->KeyExist("Rotate")) {
- pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate");
+ CPDF_Object* pInheritable =
+ PageDictGetInheritableTag(pSrcPageDict, "Rotate");
if (pInheritable)
pCurPageDict->SetFor("Rotate", pInheritable->Clone().release());
}
@@ -242,12 +244,10 @@ bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
case CPDF_Object::STREAM: {
CPDF_Stream* pStream = pObj->AsStream();
CPDF_Dictionary* pDict = pStream->GetDict();
- if (pDict) {
- if (!UpdateReference(pDict, pDoc, pObjNumberMap))
- return false;
- } else {
+ if (!pDict)
+ return false;
+ if (!UpdateReference(pDict, pDoc, pObjNumberMap))
return false;
- }
break;
}
default:
@@ -297,49 +297,51 @@ uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring,
Tom Sepez 2016/11/14 17:31:35 nit: bool ?
Lei Zhang 2016/11/14 19:57:01 Done.
std::vector<uint16_t>* pageArray,
int nCount) {
- if (rangstring.GetLength() != 0) {
- rangstring.Remove(' ');
- int nLength = rangstring.GetLength();
- CFX_ByteString cbCompareString("0123456789-,");
- for (int i = 0; i < nLength; ++i) {
- if (cbCompareString.Find(rangstring[i]) == -1)
+ if (rangstring.IsEmpty())
+ return true;
+
+ rangstring.Remove(' ');
+ int nLength = rangstring.GetLength();
+ CFX_ByteString cbCompareString("0123456789-,");
+ for (int i = 0; i < nLength; ++i) {
+ if (cbCompareString.Find(rangstring[i]) == -1)
+ return false;
+ }
+
+ CFX_ByteString cbMidRange;
+ int nStringFrom = 0;
+ int nStringTo = 0;
+ while (nStringTo < nLength) {
+ nStringTo = rangstring.Find(',', nStringFrom);
+ if (nStringTo == -1)
+ nStringTo = nLength;
+ cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom);
+ int nMid = cbMidRange.Find('-');
+ if (nMid == -1) {
+ long lPageNum = atol(cbMidRange.c_str());
+ if (lPageNum <= 0 || lPageNum > nCount)
+ return false;
+ pageArray->push_back((uint16_t)lPageNum);
+ } else {
+ int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str());
+ if (nStartPageNum == 0)
return false;
- }
- CFX_ByteString cbMidRange;
- int nStringFrom = 0;
- int nStringTo = 0;
- while (nStringTo < nLength) {
- nStringTo = rangstring.Find(',', nStringFrom);
- if (nStringTo == -1)
- nStringTo = nLength;
- cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom);
- int nMid = cbMidRange.Find('-');
- if (nMid == -1) {
- long lPageNum = atol(cbMidRange.c_str());
- if (lPageNum <= 0 || lPageNum > nCount)
- return false;
- pageArray->push_back((uint16_t)lPageNum);
- } else {
- int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str());
- if (nStartPageNum == 0)
- return false;
- ++nMid;
- int nEnd = cbMidRange.GetLength() - nMid;
- if (nEnd == 0)
- return false;
+ ++nMid;
+ int nEnd = cbMidRange.GetLength() - nMid;
+ if (nEnd == 0)
+ return false;
- int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd).c_str());
- if (nStartPageNum < 0 || nStartPageNum > nEndPageNum ||
- nEndPageNum > nCount) {
- return false;
- }
- for (int i = nStartPageNum; i <= nEndPageNum; ++i) {
- pageArray->push_back(i);
- }
+ int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd).c_str());
+ if (nStartPageNum < 0 || nStartPageNum > nEndPageNum ||
+ nEndPageNum > nCount) {
+ return false;
+ }
+ for (int i = nStartPageNum; i <= nEndPageNum; ++i) {
+ pageArray->push_back(i);
}
- nStringFrom = nStringTo + 1;
}
+ nStringFrom = nStringTo + 1;
}
return true;
}
@@ -369,7 +371,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,
CPDF_PageOrganizer pageOrg;
pageOrg.PDFDocInit(pDestDoc, pSrcDoc);
- return pageOrg.ExportPage(pSrcDoc, &pageArray, pDestDoc, index);
+ return pageOrg.ExportPage(pDestDoc, pSrcDoc, pageArray, index);
}
DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698