diff options
author | dsinclair <dsinclair@chromium.org> | 2016-08-02 11:25:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-02 11:25:49 -0700 |
commit | 02e6f5957a56ea492961aef71b3c16cf42ea5998 (patch) | |
tree | 065375d976a97f6b127368f665f24fca1fe994fe /core/fpdfdoc/cpdf_actionfields.cpp | |
parent | 0690c35fec9c320bdc69b4a8678677fe143cee54 (diff) | |
download | pdfium-02e6f5957a56ea492961aef71b3c16cf42ea5998.tar.xz |
Splitting fpdfdoc/doc_* part I
The first of several CLs to split the core/fpdfdoc/doc_* files up to individual
class files.
Review-Url: https://codereview.chromium.org/2192823002
Diffstat (limited to 'core/fpdfdoc/cpdf_actionfields.cpp')
-rw-r--r-- | core/fpdfdoc/cpdf_actionfields.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpdf_actionfields.cpp b/core/fpdfdoc/cpdf_actionfields.cpp new file mode 100644 index 0000000000..1ad1eb4673 --- /dev/null +++ b/core/fpdfdoc/cpdf_actionfields.cpp @@ -0,0 +1,96 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/include/cpdf_actionfields.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfdoc/include/cpdf_action.h" + +size_t CPDF_ActionFields::GetFieldsCount() const { + if (!m_pAction) + return 0; + + CPDF_Dictionary* pDict = m_pAction->GetDict(); + if (!pDict) + return 0; + + CFX_ByteString csType = pDict->GetStringBy("S"); + CPDF_Object* pFields = nullptr; + if (csType == "Hide") + pFields = pDict->GetDirectObjectBy("T"); + else + pFields = pDict->GetArrayBy("Fields"); + + if (!pFields) + return 0; + if (pFields->IsDictionary()) + return 1; + if (pFields->IsString()) + return 1; + if (CPDF_Array* pArray = pFields->AsArray()) + return pArray->GetCount(); + return 0; +} + +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) + return fields; + + CFX_ByteString csType = pDict->GetStringBy("S"); + CPDF_Object* pFields; + if (csType == "Hide") + pFields = pDict->GetDirectObjectBy("T"); + else + pFields = pDict->GetArrayBy("Fields"); + + if (!pFields) + return fields; + + if (pFields->IsDictionary() || pFields->IsString()) { + fields.push_back(pFields); + } else if (CPDF_Array* pArray = pFields->AsArray()) { + for (size_t i = 0; i < pArray->GetCount(); ++i) { + CPDF_Object* pObj = pArray->GetDirectObjectAt(i); + if (pObj) + fields.push_back(pObj); + } + } + return fields; +} + +CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { + if (!m_pAction) + return nullptr; + + CPDF_Dictionary* pDict = m_pAction->GetDict(); + if (!pDict) + return nullptr; + + CFX_ByteString csType = pDict->GetStringBy("S"); + CPDF_Object* pFields = nullptr; + if (csType == "Hide") + pFields = pDict->GetDirectObjectBy("T"); + else + pFields = pDict->GetArrayBy("Fields"); + + if (!pFields) + return nullptr; + + CPDF_Object* pFindObj = nullptr; + if (pFields->IsDictionary() || pFields->IsString()) { + if (iIndex == 0) + pFindObj = pFields; + } else if (CPDF_Array* pArray = pFields->AsArray()) { + pFindObj = pArray->GetDirectObjectAt(iIndex); + } + return pFindObj; +} |