Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: core/src/fpdfdoc/doc_action.cpp

Issue 1417893003: Add type cast definitions for CPDF_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp ('k') | core/src/fpdfdoc/doc_ap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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();
11 } 11 }
12 CFX_ByteString type = m_pDict->GetString("S"); 12 CFX_ByteString type = m_pDict->GetString("S");
13 if (type != "GoTo" && type != "GoToR") { 13 if (type != "GoTo" && type != "GoToR") {
14 return CPDF_Dest(); 14 return CPDF_Dest();
15 } 15 }
16 CPDF_Object* pDest = m_pDict->GetElementValue("D"); 16 CPDF_Object* pDest = m_pDict->GetElementValue("D");
17 if (!pDest) { 17 if (!pDest) {
18 return CPDF_Dest(); 18 return CPDF_Dest();
19 } 19 }
20 if (pDest->IsString() || pDest->IsName()) { 20 if (pDest->IsString() || pDest->IsName()) {
21 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 21 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
22 CFX_ByteStringC name = pDest->GetString(); 22 CFX_ByteStringC name = pDest->GetString();
23 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); 23 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name));
24 } 24 }
25 if (pDest->GetType() == PDFOBJ_ARRAY) { 25 if (CPDF_Array* pArray = pDest->AsArray())
26 return CPDF_Dest((CPDF_Array*)pDest); 26 return CPDF_Dest(pArray);
27 }
28 return CPDF_Dest(); 27 return CPDF_Dest();
29 } 28 }
30 const FX_CHAR* g_sATypes[] = { 29 const FX_CHAR* g_sATypes[] = {
31 "Unknown", "GoTo", "GoToR", "GoToE", "Launch", 30 "Unknown", "GoTo", "GoToR", "GoToE", "Launch",
32 "Thread", "URI", "Sound", "Movie", "Hide", 31 "Thread", "URI", "Sound", "Movie", "Hide",
33 "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript", 32 "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript",
34 "SetOCGState", "Rendition", "Trans", "GoTo3DView", ""}; 33 "SetOCGState", "Rendition", "Trans", "GoTo3DView", ""};
35 CPDF_Action::ActionType CPDF_Action::GetType() const { 34 CPDF_Action::ActionType CPDF_Action::GetType() const {
36 ActionType eType = Unknown; 35 ActionType eType = Unknown;
37 if (m_pDict != NULL) { 36 if (m_pDict != NULL) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 pFields = pDict->GetElementValue("T"); 100 pFields = pDict->GetElementValue("T");
102 } else { 101 } else {
103 pFields = pDict->GetArray("Fields"); 102 pFields = pDict->GetArray("Fields");
104 } 103 }
105 if (!pFields) 104 if (!pFields)
106 return 0; 105 return 0;
107 if (pFields->IsDictionary()) 106 if (pFields->IsDictionary())
108 return 1; 107 return 1;
109 if (pFields->IsString()) 108 if (pFields->IsString())
110 return 1; 109 return 1;
111 if (pFields->GetType() == PDFOBJ_ARRAY) 110 if (CPDF_Array* pArray = pFields->AsArray())
112 return ((CPDF_Array*)pFields)->GetCount(); 111 return pArray->GetCount();
113 return 0; 112 return 0;
114 } 113 }
115 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const { 114 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const {
116 fieldObjects.RemoveAll(); 115 fieldObjects.RemoveAll();
117 if (m_pAction == NULL) { 116 if (m_pAction == NULL) {
118 return; 117 return;
119 } 118 }
120 CPDF_Dictionary* pDict = m_pAction->GetDict(); 119 CPDF_Dictionary* pDict = m_pAction->GetDict();
121 if (pDict == NULL) { 120 if (pDict == NULL) {
122 return; 121 return;
123 } 122 }
124 CFX_ByteString csType = pDict->GetString("S"); 123 CFX_ByteString csType = pDict->GetString("S");
125 CPDF_Object* pFields = NULL; 124 CPDF_Object* pFields = NULL;
126 if (csType == "Hide") { 125 if (csType == "Hide") {
127 pFields = pDict->GetElementValue("T"); 126 pFields = pDict->GetElementValue("T");
128 } else { 127 } else {
129 pFields = pDict->GetArray("Fields"); 128 pFields = pDict->GetArray("Fields");
130 } 129 }
131 if (!pFields) 130 if (!pFields)
132 return; 131 return;
133 132
134 if (pFields->IsDictionary() || pFields->IsString()) { 133 if (pFields->IsDictionary() || pFields->IsString()) {
135 fieldObjects.Add(pFields); 134 fieldObjects.Add(pFields);
136 } else if (pFields->GetType() == PDFOBJ_ARRAY) { 135 } else if (CPDF_Array* pArray = pFields->AsArray()) {
137 CPDF_Array* pArray = (CPDF_Array*)pFields;
138 FX_DWORD iCount = pArray->GetCount(); 136 FX_DWORD iCount = pArray->GetCount();
139 for (FX_DWORD i = 0; i < iCount; i++) { 137 for (FX_DWORD i = 0; i < iCount; i++) {
140 CPDF_Object* pObj = pArray->GetElementValue(i); 138 CPDF_Object* pObj = pArray->GetElementValue(i);
141 if (pObj != NULL) { 139 if (pObj != NULL) {
142 fieldObjects.Add(pObj); 140 fieldObjects.Add(pObj);
143 } 141 }
144 } 142 }
145 } 143 }
146 } 144 }
147 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { 145 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const {
(...skipping 11 matching lines...) Expand all
159 } else { 157 } else {
160 pFields = pDict->GetArray("Fields"); 158 pFields = pDict->GetArray("Fields");
161 } 159 }
162 if (pFields == NULL) { 160 if (pFields == NULL) {
163 return NULL; 161 return NULL;
164 } 162 }
165 CPDF_Object* pFindObj = NULL; 163 CPDF_Object* pFindObj = NULL;
166 if (pFields->IsDictionary() || pFields->IsString()) { 164 if (pFields->IsDictionary() || pFields->IsString()) {
167 if (iIndex == 0) 165 if (iIndex == 0)
168 pFindObj = pFields; 166 pFindObj = pFields;
169 } else if (pFields->GetType() == PDFOBJ_ARRAY) { 167 } else if (CPDF_Array* pArray = pFields->AsArray()) {
170 pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex); 168 pFindObj = pArray->GetElementValue(iIndex);
171 } 169 }
172 return pFindObj; 170 return pFindObj;
173 } 171 }
174 172
175 CFX_WideString CPDF_Action::GetJavaScript() const { 173 CFX_WideString CPDF_Action::GetJavaScript() const {
176 CFX_WideString csJS; 174 CFX_WideString csJS;
177 if (m_pDict == NULL) { 175 if (m_pDict == NULL) {
178 return csJS; 176 return csJS;
179 } 177 }
180 CPDF_Object* pJS = m_pDict->GetElementValue("JS"); 178 CPDF_Object* pJS = m_pDict->GetElementValue("JS");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (csOP == FX_BSTRC("Pause")) { 213 if (csOP == FX_BSTRC("Pause")) {
216 return 2; 214 return 2;
217 } 215 }
218 if (csOP == FX_BSTRC("Resume")) { 216 if (csOP == FX_BSTRC("Resume")) {
219 return 3; 217 return 3;
220 } 218 }
221 } 219 }
222 return 0; 220 return 0;
223 } 221 }
224 FX_DWORD CPDF_Action::GetSubActionsCount() const { 222 FX_DWORD CPDF_Action::GetSubActionsCount() const {
225 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { 223 if (!m_pDict || !m_pDict->KeyExist("Next"))
226 return 0; 224 return 0;
227 } 225
228 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); 226 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
229 if (!pNext) { 227 if (!pNext)
230 return 0; 228 return 0;
231 } 229 if (pNext->IsDictionary())
232 int iObjType = pNext->GetType();
233 if (iObjType == PDFOBJ_DICTIONARY) {
234 return 1; 230 return 1;
235 } 231 if (CPDF_Array* pArray = pNext->AsArray())
236 if (iObjType == PDFOBJ_ARRAY) { 232 return pArray->GetCount();
237 return ((CPDF_Array*)pNext)->GetCount();
238 }
239 return 0; 233 return 0;
240 } 234 }
241 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { 235 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const {
242 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { 236 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
243 return CPDF_Action(); 237 return CPDF_Action();
244 } 238 }
245 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); 239 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
246 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { 240 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
247 if (iIndex == 0) 241 if (iIndex == 0)
248 return CPDF_Action(pDict); 242 return CPDF_Action(pDict);
249 } else if (pNext->GetType() == PDFOBJ_ARRAY) { 243 } else if (CPDF_Array* pArray = ToArray(pNext)) {
250 CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext);
251 return CPDF_Action(pArray->GetDict(iIndex)); 244 return CPDF_Action(pArray->GetDict(iIndex));
252 } 245 }
253 return CPDF_Action(); 246 return CPDF_Action();
254 } 247 }
255 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", 248 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC",
256 "PV", "PI", "O", "C", "K", "F", "V", "C", 249 "PV", "PI", "O", "C", "K", "F", "V", "C",
257 "WC", "WS", "DS", "WP", "DP", ""}; 250 "WC", "WS", "DS", "WP", "DP", ""};
258 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { 251 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const {
259 if (m_pDict == NULL) { 252 if (m_pDict == NULL) {
260 return FALSE; 253 return FALSE;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (!ToDictionary(pAction)) { 316 if (!ToDictionary(pAction)) {
324 return CPDF_Action(); 317 return CPDF_Action();
325 } 318 }
326 return CPDF_Action(pAction->GetDict()); 319 return CPDF_Action(pAction->GetDict());
327 } 320 }
328 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { 321 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const {
329 ASSERT(m_pDocument != NULL); 322 ASSERT(m_pDocument != NULL);
330 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); 323 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
331 return name_tree.GetIndex(csName); 324 return name_tree.GetIndex(csName);
332 } 325 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp ('k') | core/src/fpdfdoc/doc_ap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698