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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (!pFields) | 104 if (!pFields) |
105 return 0; | 105 return 0; |
106 if (pFields->IsDictionary()) | 106 if (pFields->IsDictionary()) |
107 return 1; | 107 return 1; |
108 if (pFields->IsString()) | 108 if (pFields->IsString()) |
109 return 1; | 109 return 1; |
110 if (CPDF_Array* pArray = pFields->AsArray()) | 110 if (CPDF_Array* pArray = pFields->AsArray()) |
111 return pArray->GetCount(); | 111 return pArray->GetCount(); |
112 return 0; | 112 return 0; |
113 } | 113 } |
114 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const { | 114 |
115 fieldObjects.RemoveAll(); | 115 std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { |
116 if (m_pAction == NULL) { | 116 std::vector<CPDF_Object*> fields; |
117 return; | 117 if (!m_pAction) |
118 } | 118 return fields; |
| 119 |
119 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 120 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
120 if (pDict == NULL) { | 121 if (!pDict) |
121 return; | 122 return fields; |
122 } | 123 |
123 CFX_ByteString csType = pDict->GetString("S"); | 124 CFX_ByteString csType = pDict->GetString("S"); |
124 CPDF_Object* pFields = NULL; | 125 CPDF_Object* pFields; |
125 if (csType == "Hide") { | 126 if (csType == "Hide") |
126 pFields = pDict->GetElementValue("T"); | 127 pFields = pDict->GetElementValue("T"); |
127 } else { | 128 else |
128 pFields = pDict->GetArray("Fields"); | 129 pFields = pDict->GetArray("Fields"); |
129 } | |
130 if (!pFields) | 130 if (!pFields) |
131 return; | 131 return fields; |
132 | 132 |
133 if (pFields->IsDictionary() || pFields->IsString()) { | 133 if (pFields->IsDictionary() || pFields->IsString()) { |
134 fieldObjects.Add(pFields); | 134 fields.push_back(pFields); |
135 } else if (CPDF_Array* pArray = pFields->AsArray()) { | 135 } else if (CPDF_Array* pArray = pFields->AsArray()) { |
136 FX_DWORD iCount = pArray->GetCount(); | 136 FX_DWORD iCount = pArray->GetCount(); |
137 for (FX_DWORD i = 0; i < iCount; i++) { | 137 for (FX_DWORD i = 0; i < iCount; ++i) { |
138 CPDF_Object* pObj = pArray->GetElementValue(i); | 138 CPDF_Object* pObj = pArray->GetElementValue(i); |
139 if (pObj != NULL) { | 139 if (pObj) { |
140 fieldObjects.Add(pObj); | 140 fields.push_back(pObj); |
141 } | 141 } |
142 } | 142 } |
143 } | 143 } |
| 144 return fields; |
144 } | 145 } |
| 146 |
145 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { | 147 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { |
146 if (m_pAction == NULL) { | 148 if (m_pAction == NULL) { |
147 return NULL; | 149 return NULL; |
148 } | 150 } |
149 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 151 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
150 if (pDict == NULL) { | 152 if (pDict == NULL) { |
151 return NULL; | 153 return NULL; |
152 } | 154 } |
153 CFX_ByteString csType = pDict->GetString("S"); | 155 CFX_ByteString csType = pDict->GetString("S"); |
154 CPDF_Object* pFields = NULL; | 156 CPDF_Object* pFields = NULL; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 int i = 0; | 286 int i = 0; |
285 while (g_sAATypes[i][0] != '\0') { | 287 while (g_sAATypes[i][0] != '\0') { |
286 if (csKey == g_sAATypes[i]) { | 288 if (csKey == g_sAATypes[i]) { |
287 break; | 289 break; |
288 } | 290 } |
289 i++; | 291 i++; |
290 } | 292 } |
291 eType = (AActionType)i; | 293 eType = (AActionType)i; |
292 return CPDF_Action(pDict); | 294 return CPDF_Action(pDict); |
293 } | 295 } |
294 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { | 296 |
295 m_pDocument = pDoc; | 297 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} |
296 } | 298 |
297 int CPDF_DocJSActions::CountJSActions() const { | 299 int CPDF_DocJSActions::CountJSActions() const { |
298 ASSERT(m_pDocument != NULL); | 300 ASSERT(m_pDocument != NULL); |
299 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 301 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
300 return name_tree.GetCount(); | 302 return name_tree.GetCount(); |
301 } | 303 } |
302 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, | 304 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, |
303 CFX_ByteString& csName) const { | 305 CFX_ByteString& csName) const { |
304 ASSERT(m_pDocument != NULL); | 306 ASSERT(m_pDocument != NULL); |
305 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 307 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
306 CPDF_Object* pAction = name_tree.LookupValue(index, csName); | 308 CPDF_Object* pAction = name_tree.LookupValue(index, csName); |
307 if (!ToDictionary(pAction)) { | 309 if (!ToDictionary(pAction)) { |
308 return CPDF_Action(); | 310 return CPDF_Action(); |
309 } | 311 } |
310 return CPDF_Action(pAction->GetDict()); | 312 return CPDF_Action(pAction->GetDict()); |
311 } | 313 } |
312 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { | 314 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { |
313 ASSERT(m_pDocument != NULL); | 315 ASSERT(m_pDocument != NULL); |
314 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 316 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
315 CPDF_Object* pAction = name_tree.LookupValue(csName); | 317 CPDF_Object* pAction = name_tree.LookupValue(csName); |
316 if (!ToDictionary(pAction)) { | 318 if (!ToDictionary(pAction)) { |
317 return CPDF_Action(); | 319 return CPDF_Action(); |
318 } | 320 } |
319 return CPDF_Action(pAction->GetDict()); | 321 return CPDF_Action(pAction->GetDict()); |
320 } | 322 } |
321 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { | 323 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { |
322 ASSERT(m_pDocument != NULL); | 324 ASSERT(m_pDocument != NULL); |
323 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); | 325 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); |
324 return name_tree.GetIndex(csName); | 326 return name_tree.GetIndex(csName); |
325 } | 327 } |
OLD | NEW |