| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 11 #include "core/include/fpdfdoc/fpdf_doc.h" | 11 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 12 | 12 |
| 13 namespace { |
| 14 |
| 15 const FX_CHAR* const g_sATypes[] = { |
| 16 "Unknown", "GoTo", "GoToR", "GoToE", "Launch", |
| 17 "Thread", "URI", "Sound", "Movie", "Hide", |
| 18 "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", |
| 19 "SetOCGState", "Rendition", "Trans", "GoTo3DView", nullptr}; |
| 20 |
| 21 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", |
| 22 "PV", "PI", "O", "C", "K", "F", "V", "C", |
| 23 "WC", "WS", "DS", "WP", "DP", ""}; |
| 24 |
| 25 } // namespace |
| 26 |
| 13 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { | 27 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { |
| 14 if (!m_pDict) { | 28 if (!m_pDict) { |
| 15 return CPDF_Dest(); | 29 return CPDF_Dest(); |
| 16 } | 30 } |
| 17 CFX_ByteString type = m_pDict->GetStringBy("S"); | 31 CFX_ByteString type = m_pDict->GetStringBy("S"); |
| 18 if (type != "GoTo" && type != "GoToR") { | 32 if (type != "GoTo" && type != "GoToR") { |
| 19 return CPDF_Dest(); | 33 return CPDF_Dest(); |
| 20 } | 34 } |
| 21 CPDF_Object* pDest = m_pDict->GetElementValue("D"); | 35 CPDF_Object* pDest = m_pDict->GetElementValue("D"); |
| 22 if (!pDest) { | 36 if (!pDest) { |
| 23 return CPDF_Dest(); | 37 return CPDF_Dest(); |
| 24 } | 38 } |
| 25 if (pDest->IsString() || pDest->IsName()) { | 39 if (pDest->IsString() || pDest->IsName()) { |
| 26 CPDF_NameTree name_tree(pDoc, "Dests"); | 40 CPDF_NameTree name_tree(pDoc, "Dests"); |
| 27 CFX_ByteStringC name = pDest->GetString(); | 41 CFX_ByteStringC name = pDest->GetString(); |
| 28 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); | 42 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); |
| 29 } | 43 } |
| 30 if (CPDF_Array* pArray = pDest->AsArray()) | 44 if (CPDF_Array* pArray = pDest->AsArray()) |
| 31 return CPDF_Dest(pArray); | 45 return CPDF_Dest(pArray); |
| 32 return CPDF_Dest(); | 46 return CPDF_Dest(); |
| 33 } | 47 } |
| 34 const FX_CHAR* g_sATypes[] = { | 48 |
| 35 "Unknown", "GoTo", "GoToR", "GoToE", "Launch", | |
| 36 "Thread", "URI", "Sound", "Movie", "Hide", | |
| 37 "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", | |
| 38 "SetOCGState", "Rendition", "Trans", "GoTo3DView", ""}; | |
| 39 CPDF_Action::ActionType CPDF_Action::GetType() const { | 49 CPDF_Action::ActionType CPDF_Action::GetType() const { |
| 40 ActionType eType = Unknown; | 50 if (!m_pDict) |
| 41 if (m_pDict) { | 51 return Unknown; |
| 42 CFX_ByteString csType = m_pDict->GetStringBy("S"); | 52 |
| 43 if (!csType.IsEmpty()) { | 53 CFX_ByteString csType = m_pDict->GetStringBy("S"); |
| 44 int i = 0; | 54 if (csType.IsEmpty()) |
| 45 while (g_sATypes[i][0] != '\0') { | 55 return Unknown; |
| 46 if (csType == g_sATypes[i]) { | 56 |
| 47 return (ActionType)i; | 57 for (int i = 0; g_sATypes[i]; ++i) { |
| 48 } | 58 if (csType == g_sATypes[i]) |
| 49 i++; | 59 return static_cast<ActionType>(i); |
| 50 } | |
| 51 } | |
| 52 } | 60 } |
| 53 return eType; | 61 return Unknown; |
| 54 } | 62 } |
| 63 |
| 55 CFX_WideString CPDF_Action::GetFilePath() const { | 64 CFX_WideString CPDF_Action::GetFilePath() const { |
| 56 CFX_ByteString type = m_pDict->GetStringBy("S"); | 65 CFX_ByteString type = m_pDict->GetStringBy("S"); |
| 57 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && | 66 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && |
| 58 type != "ImportData") { | 67 type != "ImportData") { |
| 59 return CFX_WideString(); | 68 return CFX_WideString(); |
| 60 } | 69 } |
| 61 CPDF_Object* pFile = m_pDict->GetElementValue("F"); | 70 CPDF_Object* pFile = m_pDict->GetElementValue("F"); |
| 62 CFX_WideString path; | 71 CFX_WideString path; |
| 63 if (!pFile) { | 72 if (!pFile) { |
| 64 if (type == "Launch") { | 73 if (type == "Launch") { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 251 } |
| 243 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 252 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); |
| 244 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { | 253 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { |
| 245 if (iIndex == 0) | 254 if (iIndex == 0) |
| 246 return CPDF_Action(pDict); | 255 return CPDF_Action(pDict); |
| 247 } else if (CPDF_Array* pArray = ToArray(pNext)) { | 256 } else if (CPDF_Array* pArray = ToArray(pNext)) { |
| 248 return CPDF_Action(pArray->GetDictAt(iIndex)); | 257 return CPDF_Action(pArray->GetDictAt(iIndex)); |
| 249 } | 258 } |
| 250 return CPDF_Action(); | 259 return CPDF_Action(); |
| 251 } | 260 } |
| 252 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", | 261 |
| 253 "PV", "PI", "O", "C", "K", "F", "V", "C", | |
| 254 "WC", "WS", "DS", "WP", "DP", ""}; | |
| 255 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { | 262 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { |
| 256 return m_pDict && m_pDict->KeyExist(g_sAATypes[(int)eType]); | 263 return m_pDict && m_pDict->KeyExist(g_sAATypes[eType]); |
| 257 } | 264 } |
| 265 |
| 258 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { | 266 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { |
| 259 if (!m_pDict) { | 267 if (!m_pDict) |
| 260 return CPDF_Action(); | 268 return CPDF_Action(); |
| 261 } | 269 |
| 262 return CPDF_Action(m_pDict->GetDictBy(g_sAATypes[(int)eType])); | 270 return CPDF_Action(m_pDict->GetDictBy(g_sAATypes[eType])); |
| 263 } | 271 } |
| 264 | 272 |
| 265 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} | 273 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} |
| 266 | 274 |
| 267 int CPDF_DocJSActions::CountJSActions() const { | 275 int CPDF_DocJSActions::CountJSActions() const { |
| 268 ASSERT(m_pDocument); | 276 ASSERT(m_pDocument); |
| 269 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); | 277 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); |
| 270 return name_tree.GetCount(); | 278 return name_tree.GetCount(); |
| 271 } | 279 } |
| 272 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, | 280 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 286 if (!ToDictionary(pAction)) { | 294 if (!ToDictionary(pAction)) { |
| 287 return CPDF_Action(); | 295 return CPDF_Action(); |
| 288 } | 296 } |
| 289 return CPDF_Action(pAction->GetDict()); | 297 return CPDF_Action(pAction->GetDict()); |
| 290 } | 298 } |
| 291 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { | 299 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { |
| 292 ASSERT(m_pDocument); | 300 ASSERT(m_pDocument); |
| 293 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); | 301 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); |
| 294 return name_tree.GetIndex(csName); | 302 return name_tree.GetIndex(csName); |
| 295 } | 303 } |
| OLD | NEW |