summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-11-09 22:41:21 -0800
committerLei Zhang <thestig@chromium.org>2015-11-09 22:41:21 -0800
commit8deeacd23872ecc132a0a678e344a018b5114a3a (patch)
treeeba48ec898f8b6454f4e29caa4bf0a6f75519056 /core
parent6d9979dc685e3b67b0a6d9946376e026d75d3e47 (diff)
downloadpdfium-8deeacd23872ecc132a0a678e344a018b5114a3a.tar.xz
Remove CFX_PtrArray usage in fpdfsdk.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1430213002 .
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfdoc/fpdf_doc.h50
-rw-r--r--core/src/fpdfdoc/doc_action.cpp42
-rw-r--r--core/src/fpdfdoc/doc_form.cpp173
3 files changed, 126 insertions, 139 deletions
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h
index cffb32bc20..ac7b0cf774 100644
--- a/core/include/fpdfdoc/fpdf_doc.h
+++ b/core/include/fpdfdoc/fpdf_doc.h
@@ -44,7 +44,7 @@ class CXML_Element;
class CPDF_NameTree {
public:
- CPDF_NameTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; }
+ explicit CPDF_NameTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; }
CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& category);
@@ -66,7 +66,7 @@ class CPDF_NameTree {
};
class CPDF_BookmarkTree {
public:
- CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {}
+ explicit CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {}
CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const;
@@ -130,7 +130,7 @@ class CPDF_OCContext : public IPDF_OCContext {
public:
enum UsageType { View = 0, Design, Print, Export };
- CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType = View);
+ explicit CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType = View);
~CPDF_OCContext() override;
CPDF_Document* GetDocument() const { return m_pDocument; }
@@ -165,15 +165,17 @@ class CPDF_OCContext : public IPDF_OCContext {
class CPDF_ActionFields {
public:
+ // TODO(thestig): Examine why this cannot be explicit.
CPDF_ActionFields(const CPDF_Action* pAction) {
m_pAction = (CPDF_Action*)pAction;
}
+ // TODO(thestig): Replace this.
operator CPDF_Action*() const { return m_pAction; }
FX_DWORD GetFieldsCount() const;
- void GetAllFields(CFX_PtrArray& fieldObjects) const;
+ std::vector<CPDF_Object*> GetAllFields() const;
CPDF_Object* GetField(FX_DWORD iIndex) const;
@@ -263,6 +265,7 @@ class CPDF_Action {
};
class CPDF_AAction {
public:
+ // TODO(thestig): Examine why this cannot be explicit.
CPDF_AAction(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; }
operator CPDF_Dictionary*() const { return m_pDict; }
@@ -303,7 +306,7 @@ class CPDF_AAction {
};
class CPDF_DocJSActions {
public:
- CPDF_DocJSActions(CPDF_Document* pDoc);
+ explicit CPDF_DocJSActions(CPDF_Document* pDoc);
int CountJSActions() const;
@@ -316,13 +319,13 @@ class CPDF_DocJSActions {
CPDF_Document* GetDocument() const { return m_pDocument; }
protected:
- CPDF_Document* m_pDocument;
+ CPDF_Document* const m_pDocument;
};
class CPDF_FileSpec {
public:
CPDF_FileSpec();
- CPDF_FileSpec(CPDF_Object* pObj) { m_pObj = pObj; }
+ explicit CPDF_FileSpec(CPDF_Object* pObj) { m_pObj = pObj; }
operator CPDF_Object*() const { return m_pObj; }
@@ -473,6 +476,7 @@ class CPDF_AnnotList {
#define COLORTYPE_CMYK 3
class CPDF_DefaultAppearance {
public:
+ // TODO(thestig): Examine why this cannot be explicit.
CPDF_DefaultAppearance(const CFX_ByteString& csDA = "") { m_csDA = csDA; }
CPDF_DefaultAppearance(const CPDF_DefaultAppearance& cDA) {
@@ -579,8 +583,6 @@ class CPDF_InterForm : public CFX_PrivateData {
void GetAllFieldNames(CFX_WideStringArray& allFieldNames);
- FX_BOOL IsValidFormField(const void* pField);
-
CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const;
CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage,
@@ -644,24 +646,25 @@ class CPDF_InterForm : public CFX_PrivateData {
int GetFormAlignment();
- CPDF_FormField* CheckRequiredFields(const CFX_PtrArray* fields = NULL,
- FX_BOOL bIncludeOrExclude = TRUE) const;
+ CPDF_FormField* CheckRequiredFields(
+ const std::vector<CPDF_FormField*>* fields,
+ bool bIncludeOrExclude) const;
CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path,
- FX_BOOL bSimpleFileSpec = FALSE) const;
+ bool bSimpleFileSpec = false) const;
CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path,
- CFX_PtrArray& fields,
- FX_BOOL bIncludeOrExclude = TRUE,
- FX_BOOL bSimpleFileSpec = FALSE) const;
+ const std::vector<CPDF_FormField*>& fields,
+ bool bIncludeOrExclude = true,
+ bool bSimpleFileSpec = false) const;
FX_BOOL ImportFromFDF(const CFDF_Document* pFDFDoc, FX_BOOL bNotify = FALSE);
- FX_BOOL ResetForm(const CFX_PtrArray& fields,
- FX_BOOL bIncludeOrExclude = TRUE,
- FX_BOOL bNotify = FALSE);
+ bool ResetForm(const std::vector<CPDF_FormField*>& fields,
+ bool bIncludeOrExclude = true,
+ bool bNotify = false);
- FX_BOOL ResetForm(FX_BOOL bNotify = FALSE);
+ bool ResetForm(bool bNotify = false);
CPDF_FormNotify* GetFormNotify() const { return m_pFormNotify; }
@@ -885,6 +888,7 @@ CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict,
int nLevel = 0);
class CPDF_IconFit {
public:
+ // TODO(thestig): Examine why this cannot be explicit.
CPDF_IconFit(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; }
operator CPDF_Dictionary*() const { return m_pDict; }
@@ -1058,7 +1062,7 @@ class CPDF_FormNotify {
FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
class CPDF_PageLabel {
public:
- CPDF_PageLabel(CPDF_Document* pDocument) { m_pDocument = pDocument; }
+ explicit CPDF_PageLabel(CPDF_Document* pDocument) { m_pDocument = pDocument; }
CFX_WideString GetLabel(int nPage) const;
@@ -1083,7 +1087,7 @@ class CPDF_Metadata {
class CPDF_ViewerPreferences {
public:
- CPDF_ViewerPreferences(CPDF_Document* pDoc);
+ explicit CPDF_ViewerPreferences(CPDF_Document* pDoc);
~CPDF_ViewerPreferences();
@@ -1098,10 +1102,12 @@ class CPDF_ViewerPreferences {
CFX_ByteString Duplex() const;
protected:
- CPDF_Document* m_pDoc;
+ CPDF_Document* const m_pDoc;
};
+
class CPDF_ApSettings {
public:
+ // TODO(thestig): Examine why this cannot be explicit.
CPDF_ApSettings(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; }
operator CPDF_Dictionary*() const { return m_pDict; }
diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp
index d685f64cae..3d439ff570 100644
--- a/core/src/fpdfdoc/doc_action.cpp
+++ b/core/src/fpdfdoc/doc_action.cpp
@@ -111,37 +111,39 @@ FX_DWORD CPDF_ActionFields::GetFieldsCount() const {
return pArray->GetCount();
return 0;
}
-void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const {
- fieldObjects.RemoveAll();
- if (m_pAction == NULL) {
- return;
- }
+
+std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const {
+ std::vector<CPDF_Object*> fields;
+ if (!m_pAction)
+ return fields;
+
CPDF_Dictionary* pDict = m_pAction->GetDict();
- if (pDict == NULL) {
- return;
- }
+ if (!pDict)
+ return fields;
+
CFX_ByteString csType = pDict->GetString("S");
- CPDF_Object* pFields = NULL;
- if (csType == "Hide") {
+ CPDF_Object* pFields;
+ if (csType == "Hide")
pFields = pDict->GetElementValue("T");
- } else {
+ else
pFields = pDict->GetArray("Fields");
- }
if (!pFields)
- return;
+ return fields;
if (pFields->IsDictionary() || pFields->IsString()) {
- fieldObjects.Add(pFields);
+ fields.push_back(pFields);
} else if (CPDF_Array* pArray = pFields->AsArray()) {
FX_DWORD iCount = pArray->GetCount();
- for (FX_DWORD i = 0; i < iCount; i++) {
+ for (FX_DWORD i = 0; i < iCount; ++i) {
CPDF_Object* pObj = pArray->GetElementValue(i);
- if (pObj != NULL) {
- fieldObjects.Add(pObj);
+ if (pObj) {
+ fields.push_back(pObj);
}
}
}
+ return fields;
}
+
CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const {
if (m_pAction == NULL) {
return NULL;
@@ -291,9 +293,9 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos,
eType = (AActionType)i;
return CPDF_Action(pDict);
}
-CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) {
- m_pDocument = pDoc;
-}
+
+CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {}
+
int CPDF_DocJSActions::CountJSActions() const {
ASSERT(m_pDocument != NULL);
CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 5cc2a66a89..8d8a836cab 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -9,9 +9,9 @@
const int nMaxRecursion = 32;
-class _CFieldNameExtractor {
+class CFieldNameExtractor {
public:
- _CFieldNameExtractor(const CFX_WideString& full_name) {
+ explicit CFieldNameExtractor(const CFX_WideString& full_name) {
m_pStart = full_name.c_str();
m_pEnd = m_pStart + full_name.GetLength();
m_pCur = m_pStart;
@@ -151,7 +151,7 @@ void CFieldTree::SetField(const CFX_WideString& full_name,
if (full_name == L"") {
return;
}
- _CFieldNameExtractor name_extractor(full_name);
+ CFieldNameExtractor name_extractor(full_name);
const FX_WCHAR* pName;
FX_STRSIZE nLength;
name_extractor.GetNext(pName, nLength);
@@ -173,7 +173,7 @@ CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) {
if (full_name == L"") {
return NULL;
}
- _CFieldNameExtractor name_extractor(full_name);
+ CFieldNameExtractor name_extractor(full_name);
const FX_WCHAR* pName;
FX_STRSIZE nLength;
name_extractor.GetNext(pName, nLength);
@@ -190,7 +190,7 @@ CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) {
if (full_name == L"") {
return NULL;
}
- _CFieldNameExtractor name_extractor(full_name);
+ CFieldNameExtractor name_extractor(full_name);
const FX_WCHAR* pName;
FX_STRSIZE nLength;
name_extractor.GetNext(pName, nLength);
@@ -219,7 +219,7 @@ CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) {
if (full_name == L"") {
return NULL;
}
- _CFieldNameExtractor name_extractor(full_name);
+ CFieldNameExtractor name_extractor(full_name);
const FX_WCHAR* pName;
FX_STRSIZE nLength;
name_extractor.GetNext(pName, nLength);
@@ -765,19 +765,7 @@ void CPDF_InterForm::GetAllFieldNames(CFX_WideStringArray& allFieldNames) {
}
}
}
-FX_BOOL CPDF_InterForm::IsValidFormField(const void* pField) {
- if (pField == NULL) {
- return FALSE;
- }
- int nCount = m_pFieldTree->m_Root.CountFields();
- for (int i = 0; i < nCount; i++) {
- CPDF_FormField* pFormField = m_pFieldTree->m_Root.GetField(i);
- if (pField == pFormField) {
- return TRUE;
- }
- }
- return FALSE;
-}
+
CPDF_FormField* CPDF_InterForm::GetFieldByDict(
CPDF_Dictionary* pFieldDict) const {
if (pFieldDict == NULL) {
@@ -946,58 +934,45 @@ int CPDF_InterForm::GetFormAlignment() {
}
return m_pFormDict->GetInteger("Q", 0);
}
-FX_BOOL CPDF_InterForm::ResetForm(const CFX_PtrArray& fields,
- FX_BOOL bIncludeOrExclude,
- FX_BOOL bNotify) {
- if (bNotify && m_pFormNotify != NULL) {
- int iRet = m_pFormNotify->BeforeFormReset(this);
- if (iRet < 0) {
- return FALSE;
- }
- }
+
+bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
+ bool bIncludeOrExclude,
+ bool bNotify) {
+ if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0)
+ return false;
+
int nCount = m_pFieldTree->m_Root.CountFields();
- for (int i = 0; i < nCount; i++) {
+ for (int i = 0; i < nCount; ++i) {
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
- if (pField == NULL) {
+ if (!pField)
continue;
- }
- FX_BOOL bFind = FALSE;
- int iCount = fields.GetSize();
- for (int i = 0; i < iCount; i++) {
- if (pField == (CPDF_FormField*)fields[i]) {
- bFind = TRUE;
- break;
- }
- }
- if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) {
+
+ auto it = std::find(fields.begin(), fields.end(), pField);
+ if (bIncludeOrExclude == (it != fields.end()))
pField->ResetField(bNotify);
- }
}
- if (bNotify && m_pFormNotify != NULL) {
+ if (bNotify && m_pFormNotify)
m_pFormNotify->AfterFormReset(this);
- }
- return TRUE;
+ return true;
}
-FX_BOOL CPDF_InterForm::ResetForm(FX_BOOL bNotify) {
- if (bNotify && m_pFormNotify != NULL) {
- int iRet = m_pFormNotify->BeforeFormReset(this);
- if (iRet < 0) {
- return FALSE;
- }
- }
+
+bool CPDF_InterForm::ResetForm(bool bNotify) {
+ if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0)
+ return false;
+
int nCount = m_pFieldTree->m_Root.CountFields();
- for (int i = 0; i < nCount; i++) {
+ for (int i = 0; i < nCount; ++i) {
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
- if (pField == NULL) {
+ if (!pField)
continue;
- }
+
pField->ResetField(bNotify);
}
- if (bNotify && m_pFormNotify != NULL) {
+ if (bNotify && m_pFormNotify)
m_pFormNotify->AfterFormReset(this);
- }
- return TRUE;
+ return true;
}
+
void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
if (nLevel > nMaxRecursion) {
return;
@@ -1126,52 +1101,58 @@ CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField,
((CPDF_FormField*)pField)->m_ControlList.Add(pControl);
return pControl;
}
+
CPDF_FormField* CPDF_InterForm::CheckRequiredFields(
- const CFX_PtrArray* fields,
- FX_BOOL bIncludeOrExclude) const {
+ const std::vector<CPDF_FormField*>* fields,
+ bool bIncludeOrExclude) const {
int nCount = m_pFieldTree->m_Root.CountFields();
- for (int i = 0; i < nCount; i++) {
+ for (int i = 0; i < nCount; ++i) {
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
- if (pField == NULL) {
+ if (!pField)
continue;
- }
+
int32_t iType = pField->GetType();
if (iType == CPDF_FormField::PushButton ||
iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) {
continue;
}
FX_DWORD dwFlags = pField->GetFieldFlags();
- if (dwFlags & 0x04) {
+ // TODO(thestig): Look up these magic numbers and add constants for them.
+ if (dwFlags & 0x04)
continue;
+
+ bool bFind = true;
+ if (fields) {
+ auto it = std::find(fields->begin(), fields->end(), pField);
+ bFind = (it != fields->end());
}
- FX_BOOL bFind = TRUE;
- if (fields != NULL) {
- bFind = fields->Find(pField, 0) >= 0;
- }
- if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) {
+ if (bIncludeOrExclude == bFind) {
CPDF_Dictionary* pFieldDict = pField->m_pDict;
if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) {
return pField;
}
}
}
- return NULL;
+ return nullptr;
}
+
CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
- FX_BOOL bSimpleFileSpec) const {
- CFX_PtrArray fields;
+ bool bSimpleFileSpec) const {
+ std::vector<CPDF_FormField*> fields;
int nCount = m_pFieldTree->m_Root.CountFields();
- for (int i = 0; i < nCount; i++) {
- CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
- fields.Add(pField);
- }
- return ExportToFDF(pdf_path, fields, TRUE, bSimpleFileSpec);
+ for (int i = 0; i < nCount; ++i)
+ fields.push_back(m_pFieldTree->m_Root.GetField(i));
+ return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
}
+
+// TODO(thestig): Fix this.
CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath);
-CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
- CFX_PtrArray& fields,
- FX_BOOL bIncludeOrExclude,
- FX_BOOL bSimpleFileSpec) const {
+
+CFDF_Document* CPDF_InterForm::ExportToFDF(
+ const CFX_WideStringC& pdf_path,
+ const std::vector<CPDF_FormField*>& fields,
+ bool bIncludeOrExclude,
+ bool bSimpleFileSpec) const {
CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
if (pDoc == NULL) {
return NULL;
@@ -1201,23 +1182,23 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
continue;
}
FX_DWORD dwFlags = pField->GetFieldFlags();
- if (dwFlags & 0x04) {
+ if (dwFlags & 0x04)
continue;
- }
- FX_BOOL bFind = fields.Find(pField, 0) >= 0;
- if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) {
- if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) {
+
+ auto it = std::find(fields.begin(), fields.end(), pField);
+ if (bIncludeOrExclude == (it != fields.end())) {
+ if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty())
continue;
- }
+
CFX_WideString fullname = GetFullName(pField->GetFieldDict());
CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create();
- if (pFieldDict == NULL) {
- return NULL;
- }
+ if (!pFieldDict)
+ return nullptr;
+
CPDF_String* pString = CPDF_String::Create(fullname);
- if (pString == NULL) {
+ if (!pString) {
pFieldDict->Release();
- return NULL;
+ return nullptr;
}
pFieldDict->SetAt("T", pString);
if (pField->GetType() == CPDF_FormField::CheckBox ||
@@ -1225,16 +1206,14 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
CFX_WideString csExport = pField->GetCheckValue(FALSE);
CFX_ByteString csBExport = PDF_EncodeText(csExport);
CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt");
- if (pOpt == NULL) {
- pFieldDict->SetAtName("V", csBExport);
- } else {
+ if (pOpt)
pFieldDict->SetAtString("V", csBExport);
- }
+ else
+ pFieldDict->SetAtName("V", csBExport);
} else {
CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V");
- if (pV != NULL) {
+ if (pV)
pFieldDict->SetAt("V", pV->Clone(TRUE));
- }
}
pFields->Add(pFieldDict);
}