summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-08-02 11:25:48 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-02 11:25:49 -0700
commit02e6f5957a56ea492961aef71b3c16cf42ea5998 (patch)
tree065375d976a97f6b127368f665f24fca1fe994fe
parent0690c35fec9c320bdc69b4a8678677fe143cee54 (diff)
downloadpdfium-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
-rw-r--r--BUILD.gn15
-rw-r--r--core/fpdfdoc/cpdf_aaction.cpp24
-rw-r--r--core/fpdfdoc/cpdf_action.cpp137
-rw-r--r--core/fpdfdoc/cpdf_actionfields.cpp96
-rw-r--r--core/fpdfdoc/cpdf_bookmark.cpp (renamed from core/fpdfdoc/doc_bookmark.cpp)49
-rw-r--r--core/fpdfdoc/cpdf_bookmarktree.cpp34
-rw-r--r--core/fpdfdoc/cpdf_docjsactions.cpp40
-rw-r--r--core/fpdfdoc/cpdf_link.cpp32
-rw-r--r--core/fpdfdoc/cpdf_linklist.cpp (renamed from core/fpdfdoc/doc_link.cpp)28
-rw-r--r--core/fpdfdoc/cpdf_metadata.cpp (renamed from core/fpdfdoc/doc_metadata.cpp)2
-rw-r--r--core/fpdfdoc/cpdf_viewerpreferences.cpp (renamed from core/fpdfdoc/doc_viewerPreferences.cpp)2
-rw-r--r--core/fpdfdoc/doc_action.cpp271
-rw-r--r--core/fpdfdoc/include/cpdf_actionfields.h2
-rw-r--r--pdfium.gyp15
14 files changed, 397 insertions, 350 deletions
diff --git a/BUILD.gn b/BUILD.gn
index f7a6007e0c..f482a5b4c9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -202,11 +202,21 @@ static_library("fpdfdoc") {
sources = [
"core/fpdfdoc/clines.cpp",
"core/fpdfdoc/clines.h",
+ "core/fpdfdoc/cpdf_aaction.cpp",
+ "core/fpdfdoc/cpdf_action.cpp",
+ "core/fpdfdoc/cpdf_actionfields.cpp",
"core/fpdfdoc/cpdf_annot.cpp",
"core/fpdfdoc/cpdf_annotlist.cpp",
"core/fpdfdoc/cpdf_apsettings.h",
+ "core/fpdfdoc/cpdf_bookmark.cpp",
+ "core/fpdfdoc/cpdf_bookmarktree.cpp",
+ "core/fpdfdoc/cpdf_docjsactions.cpp",
+ "core/fpdfdoc/cpdf_link.cpp",
+ "core/fpdfdoc/cpdf_linklist.cpp",
+ "core/fpdfdoc/cpdf_metadata.cpp",
"core/fpdfdoc/cpdf_pagelabel.h",
"core/fpdfdoc/cpdf_variabletext.cpp",
+ "core/fpdfdoc/cpdf_viewerpreferences.cpp",
"core/fpdfdoc/cpvt_color.cpp",
"core/fpdfdoc/cpvt_color.h",
"core/fpdfdoc/cpvt_dash.h",
@@ -224,18 +234,13 @@ static_library("fpdfdoc") {
"core/fpdfdoc/csection.h",
"core/fpdfdoc/ctypeset.cpp",
"core/fpdfdoc/ctypeset.h",
- "core/fpdfdoc/doc_action.cpp",
"core/fpdfdoc/doc_basic.cpp",
- "core/fpdfdoc/doc_bookmark.cpp",
"core/fpdfdoc/doc_form.cpp",
"core/fpdfdoc/doc_formcontrol.cpp",
"core/fpdfdoc/doc_formfield.cpp",
- "core/fpdfdoc/doc_link.cpp",
- "core/fpdfdoc/doc_metadata.cpp",
"core/fpdfdoc/doc_ocg.cpp",
"core/fpdfdoc/doc_utils.cpp",
"core/fpdfdoc/doc_utils.h",
- "core/fpdfdoc/doc_viewerPreferences.cpp",
"core/fpdfdoc/doc_vt.cpp",
"core/fpdfdoc/include/cpdf_aaction.h",
"core/fpdfdoc/include/cpdf_action.h",
diff --git a/core/fpdfdoc/cpdf_aaction.cpp b/core/fpdfdoc/cpdf_aaction.cpp
new file mode 100644
index 0000000000..c2d77cf083
--- /dev/null
+++ b/core/fpdfdoc/cpdf_aaction.cpp
@@ -0,0 +1,24 @@
+// 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_aaction.h"
+
+namespace {
+
+const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC",
+ "PV", "PI", "O", "C", "K", "F", "V", "C",
+ "WC", "WS", "DS", "WP", "DP", ""};
+
+} // namespace
+
+FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const {
+ return m_pDict && m_pDict->KeyExist(g_sAATypes[eType]);
+}
+
+CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
+ return m_pDict ? CPDF_Action(m_pDict->GetDictBy(g_sAATypes[eType]))
+ : CPDF_Action();
+}
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
new file mode 100644
index 0000000000..86fc20ef2f
--- /dev/null
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -0,0 +1,137 @@
+// 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_action.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/fpdfdoc/include/cpdf_filespec.h"
+#include "core/fpdfdoc/include/cpdf_nametree.h"
+
+namespace {
+
+const FX_CHAR* const g_sATypes[] = {
+ "Unknown", "GoTo", "GoToR", "GoToE", "Launch",
+ "Thread", "URI", "Sound", "Movie", "Hide",
+ "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript",
+ "SetOCGState", "Rendition", "Trans", "GoTo3DView", nullptr};
+
+} // namespace
+
+CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
+ if (!m_pDict)
+ return CPDF_Dest();
+
+ CFX_ByteString type = m_pDict->GetStringBy("S");
+ if (type != "GoTo" && type != "GoToR")
+ return CPDF_Dest();
+
+ CPDF_Object* pDest = m_pDict->GetDirectObjectBy("D");
+ if (!pDest)
+ return CPDF_Dest();
+ if (pDest->IsString() || pDest->IsName()) {
+ CPDF_NameTree name_tree(pDoc, "Dests");
+ return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString()));
+ }
+ if (CPDF_Array* pArray = pDest->AsArray())
+ return CPDF_Dest(pArray);
+
+ return CPDF_Dest();
+}
+
+CPDF_Action::ActionType CPDF_Action::GetType() const {
+ if (!m_pDict)
+ return Unknown;
+
+ CFX_ByteString csType = m_pDict->GetStringBy("S");
+ if (csType.IsEmpty())
+ return Unknown;
+
+ for (int i = 0; g_sATypes[i]; ++i) {
+ if (csType == g_sATypes[i])
+ return static_cast<ActionType>(i);
+ }
+ return Unknown;
+}
+
+CFX_WideString CPDF_Action::GetFilePath() const {
+ CFX_ByteString type = m_pDict->GetStringBy("S");
+ if (type != "GoToR" && type != "Launch" && type != "SubmitForm" &&
+ type != "ImportData") {
+ return CFX_WideString();
+ }
+
+ CPDF_Object* pFile = m_pDict->GetDirectObjectBy("F");
+ CFX_WideString path;
+ if (!pFile) {
+ if (type == "Launch") {
+ CPDF_Dictionary* pWinDict = m_pDict->GetDictBy("Win");
+ if (pWinDict) {
+ return CFX_WideString::FromLocal(
+ pWinDict->GetStringBy("F").AsStringC());
+ }
+ }
+ return path;
+ }
+
+ CPDF_FileSpec filespec(pFile);
+ filespec.GetFileName(&path);
+ return path;
+}
+
+CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
+ CFX_ByteString csURI;
+ if (!m_pDict)
+ return csURI;
+ if (m_pDict->GetStringBy("S") != "URI")
+ return csURI;
+
+ csURI = m_pDict->GetStringBy("URI");
+ CPDF_Dictionary* pRoot = pDoc->GetRoot();
+ CPDF_Dictionary* pURI = pRoot->GetDictBy("URI");
+ if (pURI) {
+ if (csURI.Find(":", 0) < 1)
+ csURI = pURI->GetStringBy("Base") + csURI;
+ }
+ return csURI;
+}
+
+CFX_WideString CPDF_Action::GetJavaScript() const {
+ CFX_WideString csJS;
+ if (!m_pDict)
+ return csJS;
+
+ CPDF_Object* pJS = m_pDict->GetDirectObjectBy("JS");
+ return pJS ? pJS->GetUnicodeText() : csJS;
+}
+
+size_t CPDF_Action::GetSubActionsCount() const {
+ if (!m_pDict || !m_pDict->KeyExist("Next"))
+ return 0;
+
+ CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next");
+ if (!pNext)
+ return 0;
+ if (pNext->IsDictionary())
+ return 1;
+ if (CPDF_Array* pArray = pNext->AsArray())
+ return pArray->GetCount();
+ return 0;
+}
+
+CPDF_Action CPDF_Action::GetSubAction(size_t iIndex) const {
+ if (!m_pDict || !m_pDict->KeyExist("Next"))
+ return CPDF_Action();
+
+ CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next");
+ if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
+ if (iIndex == 0)
+ return CPDF_Action(pDict);
+ } else if (CPDF_Array* pArray = ToArray(pNext)) {
+ return CPDF_Action(pArray->GetDictAt(iIndex));
+ }
+ return CPDF_Action();
+}
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;
+}
diff --git a/core/fpdfdoc/doc_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp
index 8a0054e98c..c9a2199750 100644
--- a/core/fpdfdoc/doc_bookmark.cpp
+++ b/core/fpdfdoc/cpdf_bookmark.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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.
@@ -6,43 +6,11 @@
#include "core/fpdfdoc/include/cpdf_bookmark.h"
-#include <memory>
-#include <vector>
-
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
-#include "core/fpdfdoc/include/cpdf_bookmarktree.h"
#include "core/fpdfdoc/include/cpdf_nametree.h"
#include "core/fxge/include/fx_dib.h"
-CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(
- const CPDF_Bookmark& parent) const {
- CPDF_Dictionary* pParentDict = parent.GetDict();
- if (pParentDict)
- return CPDF_Bookmark(pParentDict->GetDictBy("First"));
-
- CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
- if (!pRoot)
- return CPDF_Bookmark();
-
- CPDF_Dictionary* pOutlines = pRoot->GetDictBy("Outlines");
- if (!pOutlines)
- return CPDF_Bookmark();
-
- return CPDF_Bookmark(pOutlines->GetDictBy("First"));
-}
-
-CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(
- const CPDF_Bookmark& bookmark) const {
- CPDF_Dictionary* pDict = bookmark.GetDict();
- if (!pDict)
- return CPDF_Bookmark();
-
- CPDF_Dictionary* pNext = pDict->GetDictBy("Next");
- return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext);
-}
-
uint32_t CPDF_Bookmark::GetColorRef() const {
if (!m_pDict)
return FXSYS_RGB(0, 0, 0);
@@ -62,18 +30,18 @@ uint32_t CPDF_Bookmark::GetFontStyle() const {
}
CFX_WideString CPDF_Bookmark::GetTitle() const {
- if (!m_pDict) {
+ if (!m_pDict)
return CFX_WideString();
- }
+
CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title"));
if (!pString)
return CFX_WideString();
CFX_WideString title = pString->GetUnicodeText();
int len = title.GetLength();
- if (!len) {
+ if (!len)
return CFX_WideString();
- }
+
std::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]);
for (int i = 0; i < len; i++) {
FX_WCHAR w = title[i];
@@ -81,6 +49,7 @@ CFX_WideString CPDF_Bookmark::GetTitle() const {
}
return CFX_WideString(buf.get(), len);
}
+
CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const {
if (!m_pDict)
return CPDF_Dest();
@@ -96,9 +65,7 @@ CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const {
return CPDF_Dest(pArray);
return CPDF_Dest();
}
+
CPDF_Action CPDF_Bookmark::GetAction() const {
- if (!m_pDict) {
- return CPDF_Action();
- }
- return CPDF_Action(m_pDict->GetDictBy("A"));
+ return m_pDict ? CPDF_Action(m_pDict->GetDictBy("A")) : CPDF_Action();
}
diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp
new file mode 100644
index 0000000000..5ebb317a06
--- /dev/null
+++ b/core/fpdfdoc/cpdf_bookmarktree.cpp
@@ -0,0 +1,34 @@
+// 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_bookmarktree.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+
+CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(
+ const CPDF_Bookmark& parent) const {
+ CPDF_Dictionary* pParentDict = parent.GetDict();
+ if (pParentDict)
+ return CPDF_Bookmark(pParentDict->GetDictBy("First"));
+
+ CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
+ if (!pRoot)
+ return CPDF_Bookmark();
+
+ CPDF_Dictionary* pOutlines = pRoot->GetDictBy("Outlines");
+ return pOutlines ? CPDF_Bookmark(pOutlines->GetDictBy("First"))
+ : CPDF_Bookmark();
+}
+
+CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(
+ const CPDF_Bookmark& bookmark) const {
+ CPDF_Dictionary* pDict = bookmark.GetDict();
+ if (!pDict)
+ return CPDF_Bookmark();
+
+ CPDF_Dictionary* pNext = pDict->GetDictBy("Next");
+ return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext);
+}
diff --git a/core/fpdfdoc/cpdf_docjsactions.cpp b/core/fpdfdoc/cpdf_docjsactions.cpp
new file mode 100644
index 0000000000..897cdac610
--- /dev/null
+++ b/core/fpdfdoc/cpdf_docjsactions.cpp
@@ -0,0 +1,40 @@
+// 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_docjsactions.h"
+
+#include "core/fpdfdoc/include/cpdf_nametree.h"
+
+CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {}
+
+int CPDF_DocJSActions::CountJSActions() const {
+ ASSERT(m_pDocument);
+ CPDF_NameTree name_tree(m_pDocument, "JavaScript");
+ return name_tree.GetCount();
+}
+
+CPDF_Action CPDF_DocJSActions::GetJSAction(int index,
+ CFX_ByteString& csName) const {
+ ASSERT(m_pDocument);
+ CPDF_NameTree name_tree(m_pDocument, "JavaScript");
+ CPDF_Object* pAction = name_tree.LookupValue(index, csName);
+ return ToDictionary(pAction) ? CPDF_Action(pAction->GetDict())
+ : CPDF_Action();
+}
+
+CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const {
+ ASSERT(m_pDocument);
+ CPDF_NameTree name_tree(m_pDocument, "JavaScript");
+ CPDF_Object* pAction = name_tree.LookupValue(csName);
+ return ToDictionary(pAction) ? CPDF_Action(pAction->GetDict())
+ : CPDF_Action();
+}
+
+int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const {
+ ASSERT(m_pDocument);
+ CPDF_NameTree name_tree(m_pDocument, "JavaScript");
+ return name_tree.GetIndex(csName);
+}
diff --git a/core/fpdfdoc/cpdf_link.cpp b/core/fpdfdoc/cpdf_link.cpp
new file mode 100644
index 0000000000..4859881198
--- /dev/null
+++ b/core/fpdfdoc/cpdf_link.cpp
@@ -0,0 +1,32 @@
+// 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_link.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
+#include "core/fpdfdoc/include/cpdf_nametree.h"
+
+CFX_FloatRect CPDF_Link::GetRect() {
+ return m_pDict->GetRectBy("Rect");
+}
+
+CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) {
+ CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest");
+ if (!pDest)
+ return CPDF_Dest();
+
+ if (pDest->IsString() || pDest->IsName()) {
+ CPDF_NameTree name_tree(pDoc, "Dests");
+ return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString()));
+ }
+ if (CPDF_Array* pArray = pDest->AsArray())
+ return CPDF_Dest(pArray);
+ return CPDF_Dest();
+}
+
+CPDF_Action CPDF_Link::GetAction() {
+ return CPDF_Action(m_pDict->GetDictBy("A"));
+}
diff --git a/core/fpdfdoc/doc_link.cpp b/core/fpdfdoc/cpdf_linklist.cpp
index aa4e761f6d..5ef8f39da6 100644
--- a/core/fpdfdoc/doc_link.cpp
+++ b/core/fpdfdoc/cpdf_linklist.cpp
@@ -1,17 +1,13 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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_link.h"
-
-#include <vector>
+#include "core/fpdfdoc/include/cpdf_linklist.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
-#include "core/fpdfdoc/include/cpdf_linklist.h"
-#include "core/fpdfdoc/include/cpdf_nametree.h"
CPDF_LinkList::CPDF_LinkList() {}
@@ -72,23 +68,3 @@ void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage,
pList->push_back(add_link ? pAnnot : nullptr);
}
}
-
-CFX_FloatRect CPDF_Link::GetRect() {
- return m_pDict->GetRectBy("Rect");
-}
-CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) {
- CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest");
- if (!pDest)
- return CPDF_Dest();
-
- if (pDest->IsString() || pDest->IsName()) {
- CPDF_NameTree name_tree(pDoc, "Dests");
- return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString()));
- }
- if (CPDF_Array* pArray = pDest->AsArray())
- return CPDF_Dest(pArray);
- return CPDF_Dest();
-}
-CPDF_Action CPDF_Link::GetAction() {
- return CPDF_Action(m_pDict->GetDictBy("A"));
-}
diff --git a/core/fpdfdoc/doc_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp
index 6273a62bef..b53da07652 100644
--- a/core/fpdfdoc/doc_metadata.cpp
+++ b/core/fpdfdoc/cpdf_metadata.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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.
diff --git a/core/fpdfdoc/doc_viewerPreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index 3fe638d4f5..4951e5ff5d 100644
--- a/core/fpdfdoc/doc_viewerPreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// 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.
diff --git a/core/fpdfdoc/doc_action.cpp b/core/fpdfdoc/doc_action.cpp
deleted file mode 100644
index 30d4006b54..0000000000
--- a/core/fpdfdoc/doc_action.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-// Copyright 2014 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_action.h"
-
-#include <vector>
-
-#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-#include "core/fpdfdoc/include/cpdf_aaction.h"
-#include "core/fpdfdoc/include/cpdf_actionfields.h"
-#include "core/fpdfdoc/include/cpdf_docjsactions.h"
-#include "core/fpdfdoc/include/cpdf_filespec.h"
-#include "core/fpdfdoc/include/cpdf_nametree.h"
-
-namespace {
-
-const FX_CHAR* const g_sATypes[] = {
- "Unknown", "GoTo", "GoToR", "GoToE", "Launch",
- "Thread", "URI", "Sound", "Movie", "Hide",
- "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript",
- "SetOCGState", "Rendition", "Trans", "GoTo3DView", nullptr};
-
-const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC",
- "PV", "PI", "O", "C", "K", "F", "V", "C",
- "WC", "WS", "DS", "WP", "DP", ""};
-
-} // namespace
-
-CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
- if (!m_pDict) {
- return CPDF_Dest();
- }
- CFX_ByteString type = m_pDict->GetStringBy("S");
- if (type != "GoTo" && type != "GoToR") {
- return CPDF_Dest();
- }
- CPDF_Object* pDest = m_pDict->GetDirectObjectBy("D");
- if (!pDest) {
- return CPDF_Dest();
- }
- if (pDest->IsString() || pDest->IsName()) {
- CPDF_NameTree name_tree(pDoc, "Dests");
- return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString()));
- }
- if (CPDF_Array* pArray = pDest->AsArray())
- return CPDF_Dest(pArray);
- return CPDF_Dest();
-}
-
-CPDF_Action::ActionType CPDF_Action::GetType() const {
- if (!m_pDict)
- return Unknown;
-
- CFX_ByteString csType = m_pDict->GetStringBy("S");
- if (csType.IsEmpty())
- return Unknown;
-
- for (int i = 0; g_sATypes[i]; ++i) {
- if (csType == g_sATypes[i])
- return static_cast<ActionType>(i);
- }
- return Unknown;
-}
-
-CFX_WideString CPDF_Action::GetFilePath() const {
- CFX_ByteString type = m_pDict->GetStringBy("S");
- if (type != "GoToR" && type != "Launch" && type != "SubmitForm" &&
- type != "ImportData") {
- return CFX_WideString();
- }
- CPDF_Object* pFile = m_pDict->GetDirectObjectBy("F");
- CFX_WideString path;
- if (!pFile) {
- if (type == "Launch") {
- CPDF_Dictionary* pWinDict = m_pDict->GetDictBy("Win");
- if (pWinDict) {
- return CFX_WideString::FromLocal(
- pWinDict->GetStringBy("F").AsStringC());
- }
- }
- return path;
- }
- CPDF_FileSpec filespec(pFile);
- filespec.GetFileName(&path);
- return path;
-}
-CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
- CFX_ByteString csURI;
- if (!m_pDict) {
- return csURI;
- }
- if (m_pDict->GetStringBy("S") != "URI") {
- return csURI;
- }
- csURI = m_pDict->GetStringBy("URI");
- CPDF_Dictionary* pRoot = pDoc->GetRoot();
- CPDF_Dictionary* pURI = pRoot->GetDictBy("URI");
- if (pURI) {
- if (csURI.Find(":", 0) < 1) {
- csURI = pURI->GetStringBy("Base") + csURI;
- }
- }
- return csURI;
-}
-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;
-}
-
-CFX_WideString CPDF_Action::GetJavaScript() const {
- CFX_WideString csJS;
- if (!m_pDict) {
- return csJS;
- }
- CPDF_Object* pJS = m_pDict->GetDirectObjectBy("JS");
- return pJS ? pJS->GetUnicodeText() : csJS;
-}
-
-size_t CPDF_Action::GetSubActionsCount() const {
- if (!m_pDict || !m_pDict->KeyExist("Next"))
- return 0;
-
- CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next");
- if (!pNext)
- return 0;
- if (pNext->IsDictionary())
- return 1;
- if (CPDF_Array* pArray = pNext->AsArray())
- return pArray->GetCount();
- return 0;
-}
-CPDF_Action CPDF_Action::GetSubAction(size_t iIndex) const {
- if (!m_pDict || !m_pDict->KeyExist("Next")) {
- return CPDF_Action();
- }
- CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next");
- if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
- if (iIndex == 0)
- return CPDF_Action(pDict);
- } else if (CPDF_Array* pArray = ToArray(pNext)) {
- return CPDF_Action(pArray->GetDictAt(iIndex));
- }
- return CPDF_Action();
-}
-
-FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const {
- return m_pDict && m_pDict->KeyExist(g_sAATypes[eType]);
-}
-
-CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
- if (!m_pDict)
- return CPDF_Action();
-
- return CPDF_Action(m_pDict->GetDictBy(g_sAATypes[eType]));
-}
-
-CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {}
-
-int CPDF_DocJSActions::CountJSActions() const {
- ASSERT(m_pDocument);
- CPDF_NameTree name_tree(m_pDocument, "JavaScript");
- return name_tree.GetCount();
-}
-CPDF_Action CPDF_DocJSActions::GetJSAction(int index,
- CFX_ByteString& csName) const {
- ASSERT(m_pDocument);
- CPDF_NameTree name_tree(m_pDocument, "JavaScript");
- CPDF_Object* pAction = name_tree.LookupValue(index, csName);
- if (!ToDictionary(pAction)) {
- return CPDF_Action();
- }
- return CPDF_Action(pAction->GetDict());
-}
-CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const {
- ASSERT(m_pDocument);
- CPDF_NameTree name_tree(m_pDocument, "JavaScript");
- CPDF_Object* pAction = name_tree.LookupValue(csName);
- if (!ToDictionary(pAction)) {
- return CPDF_Action();
- }
- return CPDF_Action(pAction->GetDict());
-}
-int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const {
- ASSERT(m_pDocument);
- CPDF_NameTree name_tree(m_pDocument, "JavaScript");
- return name_tree.GetIndex(csName);
-}
diff --git a/core/fpdfdoc/include/cpdf_actionfields.h b/core/fpdfdoc/include/cpdf_actionfields.h
index ad7962b761..0f38e1d469 100644
--- a/core/fpdfdoc/include/cpdf_actionfields.h
+++ b/core/fpdfdoc/include/cpdf_actionfields.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFDOC_INCLUDE_CPDF_ACTIONFIELDS_H_
#define CORE_FPDFDOC_INCLUDE_CPDF_ACTIONFIELDS_H_
+#include <stddef.h>
+
#include <vector>
class CPDF_Action;
diff --git a/pdfium.gyp b/pdfium.gyp
index fe2d176318..d0d23b97d7 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -184,11 +184,21 @@
'sources': [
'core/fpdfdoc/clines.cpp',
'core/fpdfdoc/clines.h',
+ 'core/fpdfdoc/cpdf_aaction.cpp',
+ 'core/fpdfdoc/cpdf_action.cpp',
+ 'core/fpdfdoc/cpdf_actionfields.cpp',
'core/fpdfdoc/cpdf_apsettings.h',
'core/fpdfdoc/cpdf_annot.cpp',
'core/fpdfdoc/cpdf_annotlist.cpp',
+ 'core/fpdfdoc/cpdf_bookmark.cpp',
+ 'core/fpdfdoc/cpdf_bookmarktree.cpp',
+ 'core/fpdfdoc/cpdf_docjsactions.cpp',
+ 'core/fpdfdoc/cpdf_link.cpp',
+ 'core/fpdfdoc/cpdf_linklist.cpp',
+ 'core/fpdfdoc/cpdf_metadata.cpp',
'core/fpdfdoc/cpdf_pagelabel.h',
'core/fpdfdoc/cpdf_variabletext.cpp',
+ 'core/fpdfdoc/cpdf_viewerpreferences.cpp',
'core/fpdfdoc/cpvt_color.cpp',
'core/fpdfdoc/cpvt_color.h',
'core/fpdfdoc/cpvt_dash.h',
@@ -206,18 +216,13 @@
'core/fpdfdoc/csection.h',
'core/fpdfdoc/ctypeset.cpp',
'core/fpdfdoc/ctypeset.h',
- 'core/fpdfdoc/doc_action.cpp',
'core/fpdfdoc/doc_basic.cpp',
- 'core/fpdfdoc/doc_bookmark.cpp',
'core/fpdfdoc/doc_form.cpp',
'core/fpdfdoc/doc_formcontrol.cpp',
'core/fpdfdoc/doc_formfield.cpp',
- 'core/fpdfdoc/doc_link.cpp',
- 'core/fpdfdoc/doc_metadata.cpp',
'core/fpdfdoc/doc_ocg.cpp',
'core/fpdfdoc/doc_utils.cpp',
'core/fpdfdoc/doc_utils.h',
- 'core/fpdfdoc/doc_viewerPreferences.cpp',
'core/fpdfdoc/doc_vt.cpp',
'core/fpdfdoc/include/cpdf_aaction.h',
'core/fpdfdoc/include/cpdf_action.h',