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 { | 9 { |
10 if (m_pDict == NULL) { | 10 if (m_pDict == NULL) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 csURI = pURI->GetString("Base") + csURI; | 87 csURI = pURI->GetString("Base") + csURI; |
88 } | 88 } |
89 } | 89 } |
90 return csURI; | 90 return csURI; |
91 } | 91 } |
92 FX_DWORD CPDF_ActionFields::GetFieldsCount() const | 92 FX_DWORD CPDF_ActionFields::GetFieldsCount() const |
93 { | 93 { |
94 if (m_pAction == NULL) { | 94 if (m_pAction == NULL) { |
95 return 0; | 95 return 0; |
96 } | 96 } |
97 CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction); | 97 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
98 if (pDict == NULL) { | 98 if (pDict == NULL) { |
99 return 0; | 99 return 0; |
100 } | 100 } |
101 CFX_ByteString csType = pDict->GetString("S"); | 101 CFX_ByteString csType = pDict->GetString("S"); |
102 CPDF_Object* pFields = NULL; | 102 CPDF_Object* pFields = NULL; |
103 if (csType == "Hide") { | 103 if (csType == "Hide") { |
104 pFields = pDict->GetElementValue("T"); | 104 pFields = pDict->GetElementValue("T"); |
105 } else { | 105 } else { |
106 pFields = pDict->GetArray("Fields"); | 106 pFields = pDict->GetArray("Fields"); |
107 } | 107 } |
108 if (pFields == NULL) { | 108 if (pFields == NULL) { |
109 return 0; | 109 return 0; |
110 } | 110 } |
111 int iType = pFields->GetType(); | 111 int iType = pFields->GetType(); |
112 if (iType == PDFOBJ_DICTIONARY) { | 112 if (iType == PDFOBJ_DICTIONARY) { |
113 return 1; | 113 return 1; |
114 } else if (iType == PDFOBJ_STRING) { | 114 } else if (iType == PDFOBJ_STRING) { |
115 return 1; | 115 return 1; |
116 } else if (iType == PDFOBJ_ARRAY) { | 116 } else if (iType == PDFOBJ_ARRAY) { |
117 return ((CPDF_Array*)pFields)->GetCount(); | 117 return ((CPDF_Array*)pFields)->GetCount(); |
118 } | 118 } |
119 return 0; | 119 return 0; |
120 } | 120 } |
121 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const | 121 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const |
122 { | 122 { |
123 fieldObjects.RemoveAll(); | 123 fieldObjects.RemoveAll(); |
124 if (m_pAction == NULL) { | 124 if (m_pAction == NULL) { |
125 return; | 125 return; |
126 } | 126 } |
127 CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction); | 127 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
128 if (pDict == NULL) { | 128 if (pDict == NULL) { |
129 return; | 129 return; |
130 } | 130 } |
131 CFX_ByteString csType = pDict->GetString("S"); | 131 CFX_ByteString csType = pDict->GetString("S"); |
132 CPDF_Object* pFields = NULL; | 132 CPDF_Object* pFields = NULL; |
133 if (csType == "Hide") { | 133 if (csType == "Hide") { |
134 pFields = pDict->GetElementValue("T"); | 134 pFields = pDict->GetElementValue("T"); |
135 } else { | 135 } else { |
136 pFields = pDict->GetArray("Fields"); | 136 pFields = pDict->GetArray("Fields"); |
137 } | 137 } |
(...skipping 12 matching lines...) Expand all Loading... |
150 fieldObjects.Add(pObj); | 150 fieldObjects.Add(pObj); |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 } | 154 } |
155 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const | 155 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const |
156 { | 156 { |
157 if (m_pAction == NULL) { | 157 if (m_pAction == NULL) { |
158 return NULL; | 158 return NULL; |
159 } | 159 } |
160 CPDF_Dictionary* pDict = (CPDF_Dictionary*)(*m_pAction); | 160 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
161 if (pDict == NULL) { | 161 if (pDict == NULL) { |
162 return NULL; | 162 return NULL; |
163 } | 163 } |
164 CFX_ByteString csType = pDict->GetString("S"); | 164 CFX_ByteString csType = pDict->GetString("S"); |
165 CPDF_Object* pFields = NULL; | 165 CPDF_Object* pFields = NULL; |
166 if (csType == "Hide") { | 166 if (csType == "Hide") { |
167 pFields = pDict->GetElementValue("T"); | 167 pFields = pDict->GetElementValue("T"); |
168 } else { | 168 } else { |
169 pFields = pDict->GetArray("Fields"); | 169 pFields = pDict->GetArray("Fields"); |
170 } | 170 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 return 1; | 253 return 1; |
254 } | 254 } |
255 if (iObjType == PDFOBJ_ARRAY) { | 255 if (iObjType == PDFOBJ_ARRAY) { |
256 return ((CPDF_Array*)pNext)->GetCount(); | 256 return ((CPDF_Array*)pNext)->GetCount(); |
257 } | 257 } |
258 return 0; | 258 return 0; |
259 } | 259 } |
260 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const | 260 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const |
261 { | 261 { |
262 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { | 262 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { |
263 return NULL; | 263 return CPDF_Action(); |
264 } | 264 } |
265 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 265 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); |
266 int iObjType = pNext->GetType(); | 266 int iObjType = pNext->GetType(); |
267 if (iObjType == PDFOBJ_DICTIONARY) { | 267 if (iObjType == PDFOBJ_DICTIONARY) { |
| 268 CPDF_Dictionary *pDict = static_cast<CPDF_Dictionary*>(pNext); |
268 if (iIndex == 0) { | 269 if (iIndex == 0) { |
269 return (CPDF_Dictionary*)pNext; | 270 return CPDF_Action(pDict); |
270 } | 271 } |
| 272 } else if (iObjType == PDFOBJ_ARRAY) { |
| 273 CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext); |
| 274 return CPDF_Action(pArray->GetDict(iIndex)); |
271 } | 275 } |
272 if (iObjType == PDFOBJ_ARRAY) { | 276 return CPDF_Action(); |
273 return ((CPDF_Array*)pNext)->GetDict(iIndex); | |
274 } | |
275 return NULL; | |
276 } | 277 } |
277 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", "PV",
"PI", | 278 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", "PV",
"PI", |
278 "O", "C", | 279 "O", "C", |
279 "K", "F", "V", "C", | 280 "K", "F", "V", "C", |
280 "WC", "WS", "DS", "WP", "DP", | 281 "WC", "WS", "DS", "WP", "DP", |
281 "" | 282 "" |
282 }; | 283 }; |
283 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const | 284 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const |
284 { | 285 { |
285 if (m_pDict == NULL) { | 286 if (m_pDict == NULL) { |
286 return FALSE; | 287 return FALSE; |
287 } | 288 } |
288 return m_pDict->KeyExist(g_sAATypes[(int)eType]); | 289 return m_pDict->KeyExist(g_sAATypes[(int)eType]); |
289 } | 290 } |
290 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const | 291 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const |
291 { | 292 { |
292 if (m_pDict == NULL) { | 293 if (!m_pDict) { |
293 return NULL; | 294 return CPDF_Action(); |
294 } | 295 } |
295 return m_pDict->GetDict(g_sAATypes[(int)eType]); | 296 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType])); |
296 } | 297 } |
297 FX_POSITION CPDF_AAction::GetStartPos() const | 298 FX_POSITION CPDF_AAction::GetStartPos() const |
298 { | 299 { |
299 if (m_pDict == NULL) { | 300 if (m_pDict == NULL) { |
300 return NULL; | 301 return NULL; |
301 } | 302 } |
302 return m_pDict->GetStartPos(); | 303 return m_pDict->GetStartPos(); |
303 } | 304 } |
304 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, AActionType& eType) co
nst | 305 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, AActionType& eType) co
nst |
305 { | 306 { |
306 if (m_pDict == NULL) { | 307 if (m_pDict == NULL) { |
307 return NULL; | 308 return CPDF_Action(); |
308 } | 309 } |
309 CFX_ByteString csKey; | 310 CFX_ByteString csKey; |
310 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); | 311 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); |
311 if (pObj != NULL) { | 312 if (!pObj) { |
312 CPDF_Object* pDirect = pObj->GetDirect(); | 313 return CPDF_Action(); |
313 if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) { | 314 } |
314 int i = 0; | 315 CPDF_Object* pDirect = pObj->GetDirect(); |
315 while (g_sAATypes[i][0] != '\0') { | 316 if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) { |
316 if (csKey == g_sAATypes[i]) { | 317 return CPDF_Action(); |
317 break; | 318 } |
318 } | 319 int i = 0; |
319 i ++; | 320 while (g_sAATypes[i][0] != '\0') { |
320 } | 321 if (csKey == g_sAATypes[i]) { |
321 eType = (AActionType)i; | 322 break; |
322 return (CPDF_Dictionary*)pDirect; | |
323 } | 323 } |
| 324 i++; |
324 } | 325 } |
325 return NULL; | 326 eType = (AActionType)i; |
| 327 return CPDF_Action(static_cast<CPDF_Dictionary*>(pDirect)); |
326 } | 328 } |
327 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) | 329 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) |
328 { | 330 { |
329 m_pDocument = pDoc; | 331 m_pDocument = pDoc; |
330 } | 332 } |
331 int CPDF_DocJSActions::CountJSActions() const | 333 int CPDF_DocJSActions::CountJSActions() const |
332 { | 334 { |
333 ASSERT(m_pDocument != NULL); | 335 ASSERT(m_pDocument != NULL); |
334 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 336 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
335 return name_tree.GetCount(); | 337 return name_tree.GetCount(); |
336 } | 338 } |
337 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, CFX_ByteString& csName) co
nst | 339 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, CFX_ByteString& csName) co
nst |
338 { | 340 { |
339 ASSERT(m_pDocument != NULL); | 341 ASSERT(m_pDocument != NULL); |
340 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 342 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
341 CPDF_Object *pAction = name_tree.LookupValue(index, csName); | 343 CPDF_Object *pAction = name_tree.LookupValue(index, csName); |
342 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { | 344 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { |
343 return NULL; | 345 return CPDF_Action(); |
344 } | 346 } |
345 return pAction->GetDict(); | 347 return CPDF_Action(pAction->GetDict()); |
346 } | 348 } |
347 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const | 349 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const |
348 { | 350 { |
349 ASSERT(m_pDocument != NULL); | 351 ASSERT(m_pDocument != NULL); |
350 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 352 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
351 CPDF_Object *pAction = name_tree.LookupValue(csName); | 353 CPDF_Object *pAction = name_tree.LookupValue(csName); |
352 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { | 354 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { |
353 return NULL; | 355 return CPDF_Action(); |
354 } | 356 } |
355 return pAction->GetDict(); | 357 return CPDF_Action(pAction->GetDict()); |
356 } | 358 } |
357 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const | 359 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const |
358 { | 360 { |
359 ASSERT(m_pDocument != NULL); | 361 ASSERT(m_pDocument != NULL); |
360 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 362 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
361 return name_tree.GetIndex(csName); | 363 return name_tree.GetIndex(csName); |
362 } | 364 } |
OLD | NEW |