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 "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { | 8 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { |
9 if (!m_pDict) { | 9 if (!m_pDict) { |
10 return CPDF_Dest(); | 10 return CPDF_Dest(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 if (iObjType == PDFOBJ_ARRAY) { | 244 if (iObjType == PDFOBJ_ARRAY) { |
245 return ((CPDF_Array*)pNext)->GetCount(); | 245 return ((CPDF_Array*)pNext)->GetCount(); |
246 } | 246 } |
247 return 0; | 247 return 0; |
248 } | 248 } |
249 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { | 249 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { |
250 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { | 250 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { |
251 return CPDF_Action(); | 251 return CPDF_Action(); |
252 } | 252 } |
253 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 253 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); |
254 int iObjType = pNext->GetType(); | 254 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { |
255 if (iObjType == PDFOBJ_DICTIONARY) { | 255 if (iIndex == 0) |
256 CPDF_Dictionary* pDict = static_cast<CPDF_Dictionary*>(pNext); | |
257 if (iIndex == 0) { | |
258 return CPDF_Action(pDict); | 256 return CPDF_Action(pDict); |
259 } | 257 } else if (pNext->GetType() == PDFOBJ_ARRAY) { |
260 } else if (iObjType == PDFOBJ_ARRAY) { | |
261 CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext); | 258 CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext); |
262 return CPDF_Action(pArray->GetDict(iIndex)); | 259 return CPDF_Action(pArray->GetDict(iIndex)); |
263 } | 260 } |
264 return CPDF_Action(); | 261 return CPDF_Action(); |
265 } | 262 } |
266 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", | 263 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", |
267 "PV", "PI", "O", "C", "K", "F", "V", "C", | 264 "PV", "PI", "O", "C", "K", "F", "V", "C", |
268 "WC", "WS", "DS", "WP", "DP", ""}; | 265 "WC", "WS", "DS", "WP", "DP", ""}; |
269 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { | 266 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { |
270 if (m_pDict == NULL) { | 267 if (m_pDict == NULL) { |
(...skipping 17 matching lines...) Expand all Loading... |
288 AActionType& eType) const { | 285 AActionType& eType) const { |
289 if (m_pDict == NULL) { | 286 if (m_pDict == NULL) { |
290 return CPDF_Action(); | 287 return CPDF_Action(); |
291 } | 288 } |
292 CFX_ByteString csKey; | 289 CFX_ByteString csKey; |
293 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); | 290 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); |
294 if (!pObj) { | 291 if (!pObj) { |
295 return CPDF_Action(); | 292 return CPDF_Action(); |
296 } | 293 } |
297 CPDF_Object* pDirect = pObj->GetDirect(); | 294 CPDF_Object* pDirect = pObj->GetDirect(); |
298 if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) { | 295 CPDF_Dictionary* pDict = ToDictionary(pDirect); |
| 296 if (!pDict) |
299 return CPDF_Action(); | 297 return CPDF_Action(); |
300 } | 298 |
301 int i = 0; | 299 int i = 0; |
302 while (g_sAATypes[i][0] != '\0') { | 300 while (g_sAATypes[i][0] != '\0') { |
303 if (csKey == g_sAATypes[i]) { | 301 if (csKey == g_sAATypes[i]) { |
304 break; | 302 break; |
305 } | 303 } |
306 i++; | 304 i++; |
307 } | 305 } |
308 eType = (AActionType)i; | 306 eType = (AActionType)i; |
309 return CPDF_Action(static_cast<CPDF_Dictionary*>(pDirect)); | 307 return CPDF_Action(pDict); |
310 } | 308 } |
311 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { | 309 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { |
312 m_pDocument = pDoc; | 310 m_pDocument = pDoc; |
313 } | 311 } |
314 int CPDF_DocJSActions::CountJSActions() const { | 312 int CPDF_DocJSActions::CountJSActions() const { |
315 ASSERT(m_pDocument != NULL); | 313 ASSERT(m_pDocument != NULL); |
316 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 314 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
317 return name_tree.GetCount(); | 315 return name_tree.GetCount(); |
318 } | 316 } |
319 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, | 317 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, |
320 CFX_ByteString& csName) const { | 318 CFX_ByteString& csName) const { |
321 ASSERT(m_pDocument != NULL); | 319 ASSERT(m_pDocument != NULL); |
322 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 320 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
323 CPDF_Object* pAction = name_tree.LookupValue(index, csName); | 321 CPDF_Object* pAction = name_tree.LookupValue(index, csName); |
324 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { | 322 if (!ToDictionary(pAction)) { |
325 return CPDF_Action(); | 323 return CPDF_Action(); |
326 } | 324 } |
327 return CPDF_Action(pAction->GetDict()); | 325 return CPDF_Action(pAction->GetDict()); |
328 } | 326 } |
329 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { | 327 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { |
330 ASSERT(m_pDocument != NULL); | 328 ASSERT(m_pDocument != NULL); |
331 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 329 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
332 CPDF_Object* pAction = name_tree.LookupValue(csName); | 330 CPDF_Object* pAction = name_tree.LookupValue(csName); |
333 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { | 331 if (!ToDictionary(pAction)) { |
334 return CPDF_Action(); | 332 return CPDF_Action(); |
335 } | 333 } |
336 return CPDF_Action(pAction->GetDict()); | 334 return CPDF_Action(pAction->GetDict()); |
337 } | 335 } |
338 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { | 336 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { |
339 ASSERT(m_pDocument != NULL); | 337 ASSERT(m_pDocument != NULL); |
340 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 338 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
341 return name_tree.GetIndex(csName); | 339 return name_tree.GetIndex(csName); |
342 } | 340 } |
OLD | NEW |