1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const
10 if (m_pDict == NULL) {
13 CFX_ByteString type = m_pDict->GetString("S");
14 if (type != "GoTo" && type != "GoToR") {
17 CPDF_Object* pDest = m_pDict->GetElementValue("D");
21 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
22 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
23 CFX_ByteStringC name = pDest->GetString();
24 return name_tree.LookupNamedDest(pDoc, name);
25 } else if (pDest->GetType() == PDFOBJ_ARRAY) {
26 return (CPDF_Array*)pDest;
30 const FX_CHAR* g_sATypes[] = {"Unknown", "GoTo", "GoToR", "GoToE", "Launch", "Thread", "URI", "Sound", "Movie",
31 "Hide", "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", "SetOCGState",
32 "Rendition", "Trans", "GoTo3DView", ""
34 CPDF_Action::ActionType CPDF_Action::GetType() const
36 ActionType eType = Unknown;
37 if (m_pDict != NULL) {
38 CFX_ByteString csType = m_pDict->GetString("S");
39 if (!csType.IsEmpty()) {
41 while (g_sATypes[i][0] != '\0') {
42 if (csType == g_sATypes[i]) {
51 CFX_WideString CPDF_Action::GetFilePath() const
53 CFX_ByteString type = m_pDict->GetString("S");
54 if (type != "GoToR" && type != "Launch" &&
55 type != "SubmitForm" && type != "ImportData") {
56 return CFX_WideString();
58 CPDF_Object* pFile = m_pDict->GetElementValue("F");
61 if (type == "Launch") {
62 CPDF_Dictionary* pWinDict = m_pDict->GetDict(FX_BSTRC("Win"));
64 return CFX_WideString::FromLocal(pWinDict->GetString(FX_BSTRC("F")));
69 CPDF_FileSpec filespec(pFile);
70 filespec.GetFileName(path);
73 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const
76 if (m_pDict == NULL) {
79 if (m_pDict->GetString("S") != "URI") {
82 csURI = m_pDict->GetString("URI");
83 CPDF_Dictionary* pRoot = pDoc->GetRoot();
84 CPDF_Dictionary* pURI = pRoot->GetDict("URI");
86 if (csURI.Find(FX_BSTRC(":"), 0) < 1) {
87 csURI = pURI->GetString("Base") + csURI;
92 FX_DWORD CPDF_ActionFields::GetFieldsCount() const
94 if (m_pAction == NULL) {
97 CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction);
101 CFX_ByteString csType = pDict->GetString("S");
102 CPDF_Object* pFields = NULL;
103 if (csType == "Hide") {
104 pFields = pDict->GetElementValue("T");
106 pFields = pDict->GetArray("Fields");
108 if (pFields == NULL) {
111 int iType = pFields->GetType();
112 if (iType == PDFOBJ_DICTIONARY) {
114 } else if (iType == PDFOBJ_STRING) {
116 } else if (iType == PDFOBJ_ARRAY) {
117 return ((CPDF_Array*)pFields)->GetCount();
121 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const
123 fieldObjects.RemoveAll();
124 if (m_pAction == NULL) {
127 CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction);
131 CFX_ByteString csType = pDict->GetString("S");
132 CPDF_Object* pFields = NULL;
133 if (csType == "Hide") {
134 pFields = pDict->GetElementValue("T");
136 pFields = pDict->GetArray("Fields");
138 if (pFields == NULL) {
141 int iType = pFields->GetType();
142 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
143 fieldObjects.Add(pFields);
144 } else if (iType == PDFOBJ_ARRAY) {
145 CPDF_Array* pArray = (CPDF_Array*)pFields;
146 FX_DWORD iCount = pArray->GetCount();
147 for (FX_DWORD i = 0; i < iCount; i ++) {
148 CPDF_Object* pObj = pArray->GetElementValue(i);
150 fieldObjects.Add(pObj);
155 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const
157 if (m_pAction == NULL) {
160 CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction);
164 CFX_ByteString csType = pDict->GetString("S");
165 CPDF_Object* pFields = NULL;
166 if (csType == "Hide") {
167 pFields = pDict->GetElementValue("T");
169 pFields = pDict->GetArray("Fields");
171 if (pFields == NULL) {
174 CPDF_Object* pFindObj = NULL;
175 int iType = pFields->GetType();
176 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
180 } else if (iType == PDFOBJ_ARRAY) {
181 pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex);
185 CPDF_LWinParam CPDF_Action::GetWinParam() const
187 if (m_pDict == NULL) {
190 if (m_pDict->GetString("S") != "Launch") {
193 return m_pDict->GetDict("Win");
195 CFX_WideString CPDF_Action::GetJavaScript() const
198 if (m_pDict == NULL) {
201 CPDF_Object* pJS = m_pDict->GetElementValue("JS");
203 return pJS->GetUnicodeText();
207 CPDF_Dictionary* CPDF_Action::GetAnnot() const
209 if (m_pDict == NULL) {
212 CFX_ByteString csType = m_pDict->GetString("S");
213 if (csType == FX_BSTRC("Rendition")) {
214 return m_pDict->GetDict("AN");
215 } else if (csType == FX_BSTRC("Movie")) {
216 return m_pDict->GetDict("Annotation");
220 FX_INT32 CPDF_Action::GetOperationType() const
222 if (m_pDict == NULL) {
225 CFX_ByteString csType = m_pDict->GetString("S");
226 if (csType == FX_BSTRC("Rendition")) {
227 return m_pDict->GetInteger("OP");
228 } else if (csType == FX_BSTRC("Movie")) {
229 CFX_ByteString csOP = m_pDict->GetString("Operation");
230 if (csOP == FX_BSTRC("Play")) {
232 } else if (csOP == FX_BSTRC("Stop")) {
234 } else if (csOP == FX_BSTRC("Pause")) {
236 } else if (csOP == FX_BSTRC("Resume")) {
242 FX_DWORD CPDF_Action::GetSubActionsCount() const
244 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
247 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
251 int iObjType = pNext->GetType();
252 if (iObjType == PDFOBJ_DICTIONARY) {
255 if (iObjType == PDFOBJ_ARRAY) {
256 return ((CPDF_Array*)pNext)->GetCount();
260 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const
262 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
265 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
266 int iObjType = pNext->GetType();
267 if (iObjType == PDFOBJ_DICTIONARY) {
269 return (CPDF_Dictionary*)pNext;
272 if (iObjType == PDFOBJ_ARRAY) {
273 return ((CPDF_Array*)pNext)->GetDict(iIndex);
277 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", "PV", "PI",
280 "WC", "WS", "DS", "WP", "DP",
283 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const
285 if (m_pDict == NULL) {
288 return m_pDict->KeyExist(g_sAATypes[(int)eType]);
290 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const
292 if (m_pDict == NULL) {
295 return m_pDict->GetDict(g_sAATypes[(int)eType]);
297 FX_POSITION CPDF_AAction::GetStartPos() const
299 if (m_pDict == NULL) {
302 return m_pDict->GetStartPos();
304 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, AActionType& eType) const
306 if (m_pDict == NULL) {
309 CFX_ByteString csKey;
310 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey);
312 CPDF_Object* pDirect = pObj->GetDirect();
313 if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) {
315 while (g_sAATypes[i][0] != '\0') {
316 if (csKey == g_sAATypes[i]) {
321 eType = (AActionType)i;
322 return (CPDF_Dictionary*)pDirect;
327 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc)
331 int CPDF_DocJSActions::CountJSActions() const
333 ASSERT(m_pDocument != NULL);
334 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
335 return name_tree.GetCount();
337 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, CFX_ByteString& csName) const
339 ASSERT(m_pDocument != NULL);
340 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
341 CPDF_Object *pAction = name_tree.LookupValue(index, csName);
342 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) {
345 return pAction->GetDict();
347 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const
349 ASSERT(m_pDocument != NULL);
350 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
351 CPDF_Object *pAction = name_tree.LookupValue(csName);
352 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) {
355 return pAction->GetDict();
357 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const
359 ASSERT(m_pDocument != NULL);
360 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
361 return name_tree.GetIndex(csName);