diff options
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r-- | core/src/fpdfdoc/doc_action.cpp | 42 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 173 |
2 files changed, 98 insertions, 117 deletions
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); } |