| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { | 27 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { |
| 28 if (!m_pDict) { | 28 if (!m_pDict) { |
| 29 return CPDF_Dest(); | 29 return CPDF_Dest(); |
| 30 } | 30 } |
| 31 CFX_ByteString type = m_pDict->GetStringBy("S"); | 31 CFX_ByteString type = m_pDict->GetStringBy("S"); |
| 32 if (type != "GoTo" && type != "GoToR") { | 32 if (type != "GoTo" && type != "GoToR") { |
| 33 return CPDF_Dest(); | 33 return CPDF_Dest(); |
| 34 } | 34 } |
| 35 CPDF_Object* pDest = m_pDict->GetElementValue("D"); | 35 CPDF_Object* pDest = m_pDict->GetDirectObjectBy("D"); |
| 36 if (!pDest) { | 36 if (!pDest) { |
| 37 return CPDF_Dest(); | 37 return CPDF_Dest(); |
| 38 } | 38 } |
| 39 if (pDest->IsString() || pDest->IsName()) { | 39 if (pDest->IsString() || pDest->IsName()) { |
| 40 CPDF_NameTree name_tree(pDoc, "Dests"); | 40 CPDF_NameTree name_tree(pDoc, "Dests"); |
| 41 CFX_ByteStringC name = pDest->GetString(); | 41 CFX_ByteStringC name = pDest->GetString(); |
| 42 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); | 42 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); |
| 43 } | 43 } |
| 44 if (CPDF_Array* pArray = pDest->AsArray()) | 44 if (CPDF_Array* pArray = pDest->AsArray()) |
| 45 return CPDF_Dest(pArray); | 45 return CPDF_Dest(pArray); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 60 } | 60 } |
| 61 return Unknown; | 61 return Unknown; |
| 62 } | 62 } |
| 63 | 63 |
| 64 CFX_WideString CPDF_Action::GetFilePath() const { | 64 CFX_WideString CPDF_Action::GetFilePath() const { |
| 65 CFX_ByteString type = m_pDict->GetStringBy("S"); | 65 CFX_ByteString type = m_pDict->GetStringBy("S"); |
| 66 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && | 66 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && |
| 67 type != "ImportData") { | 67 type != "ImportData") { |
| 68 return CFX_WideString(); | 68 return CFX_WideString(); |
| 69 } | 69 } |
| 70 CPDF_Object* pFile = m_pDict->GetElementValue("F"); | 70 CPDF_Object* pFile = m_pDict->GetDirectObjectBy("F"); |
| 71 CFX_WideString path; | 71 CFX_WideString path; |
| 72 if (!pFile) { | 72 if (!pFile) { |
| 73 if (type == "Launch") { | 73 if (type == "Launch") { |
| 74 CPDF_Dictionary* pWinDict = m_pDict->GetDictBy("Win"); | 74 CPDF_Dictionary* pWinDict = m_pDict->GetDictBy("Win"); |
| 75 if (pWinDict) { | 75 if (pWinDict) { |
| 76 return CFX_WideString::FromLocal(pWinDict->GetStringBy("F")); | 76 return CFX_WideString::FromLocal(pWinDict->GetStringBy("F")); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 return path; | 79 return path; |
| 80 } | 80 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 104 if (!m_pAction) { | 104 if (!m_pAction) { |
| 105 return 0; | 105 return 0; |
| 106 } | 106 } |
| 107 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 107 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
| 108 if (!pDict) { | 108 if (!pDict) { |
| 109 return 0; | 109 return 0; |
| 110 } | 110 } |
| 111 CFX_ByteString csType = pDict->GetStringBy("S"); | 111 CFX_ByteString csType = pDict->GetStringBy("S"); |
| 112 CPDF_Object* pFields = NULL; | 112 CPDF_Object* pFields = NULL; |
| 113 if (csType == "Hide") { | 113 if (csType == "Hide") { |
| 114 pFields = pDict->GetElementValue("T"); | 114 pFields = pDict->GetDirectObjectBy("T"); |
| 115 } else { | 115 } else { |
| 116 pFields = pDict->GetArrayBy("Fields"); | 116 pFields = pDict->GetArrayBy("Fields"); |
| 117 } | 117 } |
| 118 if (!pFields) | 118 if (!pFields) |
| 119 return 0; | 119 return 0; |
| 120 if (pFields->IsDictionary()) | 120 if (pFields->IsDictionary()) |
| 121 return 1; | 121 return 1; |
| 122 if (pFields->IsString()) | 122 if (pFields->IsString()) |
| 123 return 1; | 123 return 1; |
| 124 if (CPDF_Array* pArray = pFields->AsArray()) | 124 if (CPDF_Array* pArray = pFields->AsArray()) |
| 125 return pArray->GetCount(); | 125 return pArray->GetCount(); |
| 126 return 0; | 126 return 0; |
| 127 } | 127 } |
| 128 | 128 |
| 129 std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { | 129 std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { |
| 130 std::vector<CPDF_Object*> fields; | 130 std::vector<CPDF_Object*> fields; |
| 131 if (!m_pAction) | 131 if (!m_pAction) |
| 132 return fields; | 132 return fields; |
| 133 | 133 |
| 134 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 134 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
| 135 if (!pDict) | 135 if (!pDict) |
| 136 return fields; | 136 return fields; |
| 137 | 137 |
| 138 CFX_ByteString csType = pDict->GetStringBy("S"); | 138 CFX_ByteString csType = pDict->GetStringBy("S"); |
| 139 CPDF_Object* pFields; | 139 CPDF_Object* pFields; |
| 140 if (csType == "Hide") | 140 if (csType == "Hide") |
| 141 pFields = pDict->GetElementValue("T"); | 141 pFields = pDict->GetDirectObjectBy("T"); |
| 142 else | 142 else |
| 143 pFields = pDict->GetArrayBy("Fields"); | 143 pFields = pDict->GetArrayBy("Fields"); |
| 144 if (!pFields) | 144 if (!pFields) |
| 145 return fields; | 145 return fields; |
| 146 | 146 |
| 147 if (pFields->IsDictionary() || pFields->IsString()) { | 147 if (pFields->IsDictionary() || pFields->IsString()) { |
| 148 fields.push_back(pFields); | 148 fields.push_back(pFields); |
| 149 } else if (CPDF_Array* pArray = pFields->AsArray()) { | 149 } else if (CPDF_Array* pArray = pFields->AsArray()) { |
| 150 uint32_t iCount = pArray->GetCount(); | 150 uint32_t iCount = pArray->GetCount(); |
| 151 for (uint32_t i = 0; i < iCount; ++i) { | 151 for (uint32_t i = 0; i < iCount; ++i) { |
| 152 CPDF_Object* pObj = pArray->GetElementValue(i); | 152 CPDF_Object* pObj = pArray->GetDirectObjectAt(i); |
| 153 if (pObj) { | 153 if (pObj) { |
| 154 fields.push_back(pObj); | 154 fields.push_back(pObj); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 return fields; | 158 return fields; |
| 159 } | 159 } |
| 160 | 160 |
| 161 CPDF_Object* CPDF_ActionFields::GetField(uint32_t iIndex) const { | 161 CPDF_Object* CPDF_ActionFields::GetField(uint32_t iIndex) const { |
| 162 if (!m_pAction) { | 162 if (!m_pAction) { |
| 163 return NULL; | 163 return NULL; |
| 164 } | 164 } |
| 165 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 165 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
| 166 if (!pDict) { | 166 if (!pDict) { |
| 167 return NULL; | 167 return NULL; |
| 168 } | 168 } |
| 169 CFX_ByteString csType = pDict->GetStringBy("S"); | 169 CFX_ByteString csType = pDict->GetStringBy("S"); |
| 170 CPDF_Object* pFields = NULL; | 170 CPDF_Object* pFields = NULL; |
| 171 if (csType == "Hide") { | 171 if (csType == "Hide") { |
| 172 pFields = pDict->GetElementValue("T"); | 172 pFields = pDict->GetDirectObjectBy("T"); |
| 173 } else { | 173 } else { |
| 174 pFields = pDict->GetArrayBy("Fields"); | 174 pFields = pDict->GetArrayBy("Fields"); |
| 175 } | 175 } |
| 176 if (!pFields) { | 176 if (!pFields) { |
| 177 return NULL; | 177 return NULL; |
| 178 } | 178 } |
| 179 CPDF_Object* pFindObj = NULL; | 179 CPDF_Object* pFindObj = NULL; |
| 180 if (pFields->IsDictionary() || pFields->IsString()) { | 180 if (pFields->IsDictionary() || pFields->IsString()) { |
| 181 if (iIndex == 0) | 181 if (iIndex == 0) |
| 182 pFindObj = pFields; | 182 pFindObj = pFields; |
| 183 } else if (CPDF_Array* pArray = pFields->AsArray()) { | 183 } else if (CPDF_Array* pArray = pFields->AsArray()) { |
| 184 pFindObj = pArray->GetElementValue(iIndex); | 184 pFindObj = pArray->GetDirectObjectAt(iIndex); |
| 185 } | 185 } |
| 186 return pFindObj; | 186 return pFindObj; |
| 187 } | 187 } |
| 188 | 188 |
| 189 CFX_WideString CPDF_Action::GetJavaScript() const { | 189 CFX_WideString CPDF_Action::GetJavaScript() const { |
| 190 CFX_WideString csJS; | 190 CFX_WideString csJS; |
| 191 if (!m_pDict) { | 191 if (!m_pDict) { |
| 192 return csJS; | 192 return csJS; |
| 193 } | 193 } |
| 194 CPDF_Object* pJS = m_pDict->GetElementValue("JS"); | 194 CPDF_Object* pJS = m_pDict->GetDirectObjectBy("JS"); |
| 195 return pJS ? pJS->GetUnicodeText() : csJS; | 195 return pJS ? pJS->GetUnicodeText() : csJS; |
| 196 } | 196 } |
| 197 CPDF_Dictionary* CPDF_Action::GetAnnot() const { | 197 CPDF_Dictionary* CPDF_Action::GetAnnot() const { |
| 198 if (!m_pDict) { | 198 if (!m_pDict) { |
| 199 return nullptr; | 199 return nullptr; |
| 200 } | 200 } |
| 201 CFX_ByteString csType = m_pDict->GetStringBy("S"); | 201 CFX_ByteString csType = m_pDict->GetStringBy("S"); |
| 202 if (csType == "Rendition") { | 202 if (csType == "Rendition") { |
| 203 return m_pDict->GetDictBy("AN"); | 203 return m_pDict->GetDictBy("AN"); |
| 204 } | 204 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 229 if (csOP == "Resume") { | 229 if (csOP == "Resume") { |
| 230 return 3; | 230 return 3; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 return 0; | 233 return 0; |
| 234 } | 234 } |
| 235 uint32_t CPDF_Action::GetSubActionsCount() const { | 235 uint32_t CPDF_Action::GetSubActionsCount() const { |
| 236 if (!m_pDict || !m_pDict->KeyExist("Next")) | 236 if (!m_pDict || !m_pDict->KeyExist("Next")) |
| 237 return 0; | 237 return 0; |
| 238 | 238 |
| 239 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 239 CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next"); |
| 240 if (!pNext) | 240 if (!pNext) |
| 241 return 0; | 241 return 0; |
| 242 if (pNext->IsDictionary()) | 242 if (pNext->IsDictionary()) |
| 243 return 1; | 243 return 1; |
| 244 if (CPDF_Array* pArray = pNext->AsArray()) | 244 if (CPDF_Array* pArray = pNext->AsArray()) |
| 245 return pArray->GetCount(); | 245 return pArray->GetCount(); |
| 246 return 0; | 246 return 0; |
| 247 } | 247 } |
| 248 CPDF_Action CPDF_Action::GetSubAction(uint32_t iIndex) const { | 248 CPDF_Action CPDF_Action::GetSubAction(uint32_t iIndex) const { |
| 249 if (!m_pDict || !m_pDict->KeyExist("Next")) { | 249 if (!m_pDict || !m_pDict->KeyExist("Next")) { |
| 250 return CPDF_Action(); | 250 return CPDF_Action(); |
| 251 } | 251 } |
| 252 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 252 CPDF_Object* pNext = m_pDict->GetDirectObjectBy("Next"); |
| 253 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { | 253 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { |
| 254 if (iIndex == 0) | 254 if (iIndex == 0) |
| 255 return CPDF_Action(pDict); | 255 return CPDF_Action(pDict); |
| 256 } else if (CPDF_Array* pArray = ToArray(pNext)) { | 256 } else if (CPDF_Array* pArray = ToArray(pNext)) { |
| 257 return CPDF_Action(pArray->GetDictAt(iIndex)); | 257 return CPDF_Action(pArray->GetDictAt(iIndex)); |
| 258 } | 258 } |
| 259 return CPDF_Action(); | 259 return CPDF_Action(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { | 262 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 if (!ToDictionary(pAction)) { | 294 if (!ToDictionary(pAction)) { |
| 295 return CPDF_Action(); | 295 return CPDF_Action(); |
| 296 } | 296 } |
| 297 return CPDF_Action(pAction->GetDict()); | 297 return CPDF_Action(pAction->GetDict()); |
| 298 } | 298 } |
| 299 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { | 299 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { |
| 300 ASSERT(m_pDocument); | 300 ASSERT(m_pDocument); |
| 301 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); | 301 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); |
| 302 return name_tree.GetIndex(csName); | 302 return name_tree.GetIndex(csName); |
| 303 } | 303 } |
| OLD | NEW |