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

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

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 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
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 { 9 if (!m_pDict) {
10 if (!m_pDict) {
11 return CPDF_Dest();
12 }
13 CFX_ByteString type = m_pDict->GetString("S");
14 if (type != "GoTo" && type != "GoToR") {
15 return CPDF_Dest();
16 }
17 CPDF_Object* pDest = m_pDict->GetElementValue("D");
18 if (!pDest) {
19 return CPDF_Dest();
20 }
21 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
22 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
23 CFX_ByteStringC name = pDest->GetString();
24 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name));
25 }
26 if (pDest->GetType() == PDFOBJ_ARRAY) {
27 return CPDF_Dest((CPDF_Array*)pDest);
28 }
29 return CPDF_Dest(); 10 return CPDF_Dest();
30 } 11 }
31 const FX_CHAR* g_sATypes[] = {"Unknown", "GoTo", "GoToR", "GoToE", "Launch", "Th read", "URI", "Sound", "Movie", 12 CFX_ByteString type = m_pDict->GetString("S");
32 "Hide",» "Named", "SubmitForm", "ResetForm", "Imp ortData", "JavaScript", "SetOCGState", 13 if (type != "GoTo" && type != "GoToR") {
33 "Rendition", "Trans", "GoTo3DView", "" 14 return CPDF_Dest();
34 }; 15 }
35 CPDF_Action::ActionType CPDF_Action::GetType() const 16 CPDF_Object* pDest = m_pDict->GetElementValue("D");
36 { 17 if (!pDest) {
37 ActionType eType = Unknown; 18 return CPDF_Dest();
38 if (m_pDict != NULL) { 19 }
39 CFX_ByteString csType = m_pDict->GetString("S"); 20 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
40 if (!csType.IsEmpty()) { 21 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
41 int i = 0; 22 CFX_ByteStringC name = pDest->GetString();
42 while (g_sATypes[i][0] != '\0') { 23 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name));
43 if (csType == g_sATypes[i]) { 24 }
44 return (ActionType)i; 25 if (pDest->GetType() == PDFOBJ_ARRAY) {
45 } 26 return CPDF_Dest((CPDF_Array*)pDest);
46 i ++; 27 }
47 } 28 return CPDF_Dest();
48 } 29 }
49 } 30 const FX_CHAR* g_sATypes[] = {
50 return eType; 31 "Unknown", "GoTo", "GoToR", "GoToE", "Launch",
51 } 32 "Thread", "URI", "Sound", "Movie", "Hide",
52 CFX_WideString CPDF_Action::GetFilePath() const 33 "Named", "SubmitForm", "ResetForm", "ImportData", "JavaScript",
53 { 34 "SetOCGState", "Rendition", "Trans", "GoTo3DView", ""};
54 CFX_ByteString type = m_pDict->GetString("S"); 35 CPDF_Action::ActionType CPDF_Action::GetType() const {
55 if (type != "GoToR" && type != "Launch" && 36 ActionType eType = Unknown;
56 type != "SubmitForm" && type != "ImportData") { 37 if (m_pDict != NULL) {
57 return CFX_WideString();
58 }
59 CPDF_Object* pFile = m_pDict->GetElementValue("F");
60 CFX_WideString path;
61 if (pFile == NULL) {
62 if (type == "Launch") {
63 CPDF_Dictionary* pWinDict = m_pDict->GetDict(FX_BSTRC("Win"));
64 if (pWinDict) {
65 return CFX_WideString::FromLocal(pWinDict->GetString(FX_BSTRC("F ")));
66 }
67 }
68 return path;
69 }
70 CPDF_FileSpec filespec(pFile);
71 filespec.GetFileName(path);
72 return path;
73 }
74 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const
75 {
76 CFX_ByteString csURI;
77 if (m_pDict == NULL) {
78 return csURI;
79 }
80 if (m_pDict->GetString("S") != "URI") {
81 return csURI;
82 }
83 csURI = m_pDict->GetString("URI");
84 CPDF_Dictionary* pRoot = pDoc->GetRoot();
85 CPDF_Dictionary* pURI = pRoot->GetDict("URI");
86 if (pURI != NULL) {
87 if (csURI.Find(FX_BSTRC(":"), 0) < 1) {
88 csURI = pURI->GetString("Base") + csURI;
89 }
90 }
91 return csURI;
92 }
93 FX_DWORD CPDF_ActionFields::GetFieldsCount() const
94 {
95 if (m_pAction == NULL) {
96 return 0;
97 }
98 CPDF_Dictionary* pDict = m_pAction->GetDict();
99 if (pDict == NULL) {
100 return 0;
101 }
102 CFX_ByteString csType = pDict->GetString("S");
103 CPDF_Object* pFields = NULL;
104 if (csType == "Hide") {
105 pFields = pDict->GetElementValue("T");
106 } else {
107 pFields = pDict->GetArray("Fields");
108 }
109 if (pFields == NULL) {
110 return 0;
111 }
112 int iType = pFields->GetType();
113 if (iType == PDFOBJ_DICTIONARY) {
114 return 1;
115 }
116 if (iType == PDFOBJ_STRING) {
117 return 1;
118 }
119 if (iType == PDFOBJ_ARRAY) {
120 return ((CPDF_Array*)pFields)->GetCount();
121 }
122 return 0;
123 }
124 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const
125 {
126 fieldObjects.RemoveAll();
127 if (m_pAction == NULL) {
128 return;
129 }
130 CPDF_Dictionary* pDict = m_pAction->GetDict();
131 if (pDict == NULL) {
132 return;
133 }
134 CFX_ByteString csType = pDict->GetString("S");
135 CPDF_Object* pFields = NULL;
136 if (csType == "Hide") {
137 pFields = pDict->GetElementValue("T");
138 } else {
139 pFields = pDict->GetArray("Fields");
140 }
141 if (pFields == NULL) {
142 return;
143 }
144 int iType = pFields->GetType();
145 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
146 fieldObjects.Add(pFields);
147 } else if (iType == PDFOBJ_ARRAY) {
148 CPDF_Array* pArray = (CPDF_Array*)pFields;
149 FX_DWORD iCount = pArray->GetCount();
150 for (FX_DWORD i = 0; i < iCount; i ++) {
151 CPDF_Object* pObj = pArray->GetElementValue(i);
152 if (pObj != NULL) {
153 fieldObjects.Add(pObj);
154 }
155 }
156 }
157 }
158 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const
159 {
160 if (m_pAction == NULL) {
161 return NULL;
162 }
163 CPDF_Dictionary* pDict = m_pAction->GetDict();
164 if (pDict == NULL) {
165 return NULL;
166 }
167 CFX_ByteString csType = pDict->GetString("S");
168 CPDF_Object* pFields = NULL;
169 if (csType == "Hide") {
170 pFields = pDict->GetElementValue("T");
171 } else {
172 pFields = pDict->GetArray("Fields");
173 }
174 if (pFields == NULL) {
175 return NULL;
176 }
177 CPDF_Object* pFindObj = NULL;
178 int iType = pFields->GetType();
179 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
180 if (iIndex == 0) {
181 pFindObj = pFields;
182 }
183 } else if (iType == PDFOBJ_ARRAY) {
184 pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex);
185 }
186 return pFindObj;
187 }
188 CPDF_LWinParam CPDF_Action::GetWinParam() const
189 {
190 if (m_pDict == NULL) {
191 return NULL;
192 }
193 if (m_pDict->GetString("S") != "Launch") {
194 return NULL;
195 }
196 return m_pDict->GetDict("Win");
197 }
198 CFX_WideString CPDF_Action::GetJavaScript() const
199 {
200 CFX_WideString csJS;
201 if (m_pDict == NULL) {
202 return csJS;
203 }
204 CPDF_Object* pJS = m_pDict->GetElementValue("JS");
205 if (pJS != NULL) {
206 return pJS->GetUnicodeText();
207 }
208 return csJS;
209 }
210 CPDF_Dictionary* CPDF_Action::GetAnnot() const
211 {
212 if (!m_pDict) {
213 return nullptr;
214 }
215 CFX_ByteString csType = m_pDict->GetString("S"); 38 CFX_ByteString csType = m_pDict->GetString("S");
216 if (csType == FX_BSTRC("Rendition")) { 39 if (!csType.IsEmpty()) {
217 return m_pDict->GetDict("AN"); 40 int i = 0;
218 } 41 while (g_sATypes[i][0] != '\0') {
219 if (csType == FX_BSTRC("Movie")) { 42 if (csType == g_sATypes[i]) {
220 return m_pDict->GetDict("Annotation"); 43 return (ActionType)i;
221 }
222 return nullptr;
223 }
224 int32_t CPDF_Action::GetOperationType() const
225 {
226 if (m_pDict == NULL) {
227 return 0;
228 }
229 CFX_ByteString csType = m_pDict->GetString("S");
230 if (csType == FX_BSTRC("Rendition")) {
231 return m_pDict->GetInteger("OP");
232 }
233 if (csType == FX_BSTRC("Movie")) {
234 CFX_ByteString csOP = m_pDict->GetString("Operation");
235 if (csOP == FX_BSTRC("Play")) {
236 return 0;
237 }
238 if (csOP == FX_BSTRC("Stop")) {
239 return 1;
240 }
241 if (csOP == FX_BSTRC("Pause")) {
242 return 2;
243 }
244 if (csOP == FX_BSTRC("Resume")) {
245 return 3;
246 }
247 }
248 return 0;
249 }
250 FX_DWORD CPDF_Action::GetSubActionsCount() const
251 {
252 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
253 return 0;
254 }
255 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
256 if (!pNext) {
257 return 0;
258 }
259 int iObjType = pNext->GetType();
260 if (iObjType == PDFOBJ_DICTIONARY) {
261 return 1;
262 }
263 if (iObjType == PDFOBJ_ARRAY) {
264 return ((CPDF_Array*)pNext)->GetCount();
265 }
266 return 0;
267 }
268 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const
269 {
270 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
271 return CPDF_Action();
272 }
273 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
274 int iObjType = pNext->GetType();
275 if (iObjType == PDFOBJ_DICTIONARY) {
276 CPDF_Dictionary *pDict = static_cast<CPDF_Dictionary*>(pNext);
277 if (iIndex == 0) {
278 return CPDF_Action(pDict);
279 }
280 } else if (iObjType == PDFOBJ_ARRAY) {
281 CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext);
282 return CPDF_Action(pArray->GetDict(iIndex));
283 }
284 return CPDF_Action();
285 }
286 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC", "PV", "PI",
287 "O", "C",
288 "K", "F", "V", "C",
289 "WC", "WS", "DS", "WP", "DP",
290 ""
291 };
292 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const
293 {
294 if (m_pDict == NULL) {
295 return FALSE;
296 }
297 return m_pDict->KeyExist(g_sAATypes[(int)eType]);
298 }
299 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const
300 {
301 if (!m_pDict) {
302 return CPDF_Action();
303 }
304 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType]));
305 }
306 FX_POSITION CPDF_AAction::GetStartPos() const
307 {
308 if (m_pDict == NULL) {
309 return NULL;
310 }
311 return m_pDict->GetStartPos();
312 }
313 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, AActionType& eType) co nst
314 {
315 if (m_pDict == NULL) {
316 return CPDF_Action();
317 }
318 CFX_ByteString csKey;
319 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey);
320 if (!pObj) {
321 return CPDF_Action();
322 }
323 CPDF_Object* pDirect = pObj->GetDirect();
324 if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) {
325 return CPDF_Action();
326 }
327 int i = 0;
328 while (g_sAATypes[i][0] != '\0') {
329 if (csKey == g_sAATypes[i]) {
330 break;
331 } 44 }
332 i++; 45 i++;
333 } 46 }
334 eType = (AActionType)i; 47 }
335 return CPDF_Action(static_cast<CPDF_Dictionary*>(pDirect)); 48 }
336 } 49 return eType;
337 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) 50 }
338 { 51 CFX_WideString CPDF_Action::GetFilePath() const {
339 m_pDocument = pDoc; 52 CFX_ByteString type = m_pDict->GetString("S");
340 } 53 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" &&
341 int CPDF_DocJSActions::CountJSActions() const 54 type != "ImportData") {
342 { 55 return CFX_WideString();
343 ASSERT(m_pDocument != NULL); 56 }
344 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); 57 CPDF_Object* pFile = m_pDict->GetElementValue("F");
345 return name_tree.GetCount(); 58 CFX_WideString path;
346 } 59 if (pFile == NULL) {
347 CPDF_Action CPDF_DocJSActions::GetJSAction(int index, CFX_ByteString& csName) co nst 60 if (type == "Launch") {
348 { 61 CPDF_Dictionary* pWinDict = m_pDict->GetDict(FX_BSTRC("Win"));
349 ASSERT(m_pDocument != NULL); 62 if (pWinDict) {
350 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); 63 return CFX_WideString::FromLocal(pWinDict->GetString(FX_BSTRC("F")));
351 CPDF_Object *pAction = name_tree.LookupValue(index, csName); 64 }
352 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { 65 }
353 return CPDF_Action(); 66 return path;
354 } 67 }
355 return CPDF_Action(pAction->GetDict()); 68 CPDF_FileSpec filespec(pFile);
356 } 69 filespec.GetFileName(path);
357 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const 70 return path;
358 { 71 }
359 ASSERT(m_pDocument != NULL); 72 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
360 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); 73 CFX_ByteString csURI;
361 CPDF_Object *pAction = name_tree.LookupValue(csName); 74 if (m_pDict == NULL) {
362 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) { 75 return csURI;
363 return CPDF_Action(); 76 }
364 } 77 if (m_pDict->GetString("S") != "URI") {
365 return CPDF_Action(pAction->GetDict()); 78 return csURI;
366 } 79 }
367 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const 80 csURI = m_pDict->GetString("URI");
368 { 81 CPDF_Dictionary* pRoot = pDoc->GetRoot();
369 ASSERT(m_pDocument != NULL); 82 CPDF_Dictionary* pURI = pRoot->GetDict("URI");
370 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); 83 if (pURI != NULL) {
371 return name_tree.GetIndex(csName); 84 if (csURI.Find(FX_BSTRC(":"), 0) < 1) {
372 } 85 csURI = pURI->GetString("Base") + csURI;
86 }
87 }
88 return csURI;
89 }
90 FX_DWORD CPDF_ActionFields::GetFieldsCount() const {
91 if (m_pAction == NULL) {
92 return 0;
93 }
94 CPDF_Dictionary* pDict = m_pAction->GetDict();
95 if (pDict == NULL) {
96 return 0;
97 }
98 CFX_ByteString csType = pDict->GetString("S");
99 CPDF_Object* pFields = NULL;
100 if (csType == "Hide") {
101 pFields = pDict->GetElementValue("T");
102 } else {
103 pFields = pDict->GetArray("Fields");
104 }
105 if (pFields == NULL) {
106 return 0;
107 }
108 int iType = pFields->GetType();
109 if (iType == PDFOBJ_DICTIONARY) {
110 return 1;
111 }
112 if (iType == PDFOBJ_STRING) {
113 return 1;
114 }
115 if (iType == PDFOBJ_ARRAY) {
116 return ((CPDF_Array*)pFields)->GetCount();
117 }
118 return 0;
119 }
120 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const {
121 fieldObjects.RemoveAll();
122 if (m_pAction == NULL) {
123 return;
124 }
125 CPDF_Dictionary* pDict = m_pAction->GetDict();
126 if (pDict == NULL) {
127 return;
128 }
129 CFX_ByteString csType = pDict->GetString("S");
130 CPDF_Object* pFields = NULL;
131 if (csType == "Hide") {
132 pFields = pDict->GetElementValue("T");
133 } else {
134 pFields = pDict->GetArray("Fields");
135 }
136 if (pFields == NULL) {
137 return;
138 }
139 int iType = pFields->GetType();
140 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
141 fieldObjects.Add(pFields);
142 } else if (iType == PDFOBJ_ARRAY) {
143 CPDF_Array* pArray = (CPDF_Array*)pFields;
144 FX_DWORD iCount = pArray->GetCount();
145 for (FX_DWORD i = 0; i < iCount; i++) {
146 CPDF_Object* pObj = pArray->GetElementValue(i);
147 if (pObj != NULL) {
148 fieldObjects.Add(pObj);
149 }
150 }
151 }
152 }
153 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const {
154 if (m_pAction == NULL) {
155 return NULL;
156 }
157 CPDF_Dictionary* pDict = m_pAction->GetDict();
158 if (pDict == NULL) {
159 return NULL;
160 }
161 CFX_ByteString csType = pDict->GetString("S");
162 CPDF_Object* pFields = NULL;
163 if (csType == "Hide") {
164 pFields = pDict->GetElementValue("T");
165 } else {
166 pFields = pDict->GetArray("Fields");
167 }
168 if (pFields == NULL) {
169 return NULL;
170 }
171 CPDF_Object* pFindObj = NULL;
172 int iType = pFields->GetType();
173 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
174 if (iIndex == 0) {
175 pFindObj = pFields;
176 }
177 } else if (iType == PDFOBJ_ARRAY) {
178 pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex);
179 }
180 return pFindObj;
181 }
182 CPDF_LWinParam CPDF_Action::GetWinParam() const {
183 if (m_pDict == NULL) {
184 return NULL;
185 }
186 if (m_pDict->GetString("S") != "Launch") {
187 return NULL;
188 }
189 return m_pDict->GetDict("Win");
190 }
191 CFX_WideString CPDF_Action::GetJavaScript() const {
192 CFX_WideString csJS;
193 if (m_pDict == NULL) {
194 return csJS;
195 }
196 CPDF_Object* pJS = m_pDict->GetElementValue("JS");
197 if (pJS != NULL) {
198 return pJS->GetUnicodeText();
199 }
200 return csJS;
201 }
202 CPDF_Dictionary* CPDF_Action::GetAnnot() const {
203 if (!m_pDict) {
204 return nullptr;
205 }
206 CFX_ByteString csType = m_pDict->GetString("S");
207 if (csType == FX_BSTRC("Rendition")) {
208 return m_pDict->GetDict("AN");
209 }
210 if (csType == FX_BSTRC("Movie")) {
211 return m_pDict->GetDict("Annotation");
212 }
213 return nullptr;
214 }
215 int32_t CPDF_Action::GetOperationType() const {
216 if (m_pDict == NULL) {
217 return 0;
218 }
219 CFX_ByteString csType = m_pDict->GetString("S");
220 if (csType == FX_BSTRC("Rendition")) {
221 return m_pDict->GetInteger("OP");
222 }
223 if (csType == FX_BSTRC("Movie")) {
224 CFX_ByteString csOP = m_pDict->GetString("Operation");
225 if (csOP == FX_BSTRC("Play")) {
226 return 0;
227 }
228 if (csOP == FX_BSTRC("Stop")) {
229 return 1;
230 }
231 if (csOP == FX_BSTRC("Pause")) {
232 return 2;
233 }
234 if (csOP == FX_BSTRC("Resume")) {
235 return 3;
236 }
237 }
238 return 0;
239 }
240 FX_DWORD CPDF_Action::GetSubActionsCount() const {
241 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
242 return 0;
243 }
244 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
245 if (!pNext) {
246 return 0;
247 }
248 int iObjType = pNext->GetType();
249 if (iObjType == PDFOBJ_DICTIONARY) {
250 return 1;
251 }
252 if (iObjType == PDFOBJ_ARRAY) {
253 return ((CPDF_Array*)pNext)->GetCount();
254 }
255 return 0;
256 }
257 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const {
258 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) {
259 return CPDF_Action();
260 }
261 CPDF_Object* pNext = m_pDict->GetElementValue("Next");
262 int iObjType = pNext->GetType();
263 if (iObjType == PDFOBJ_DICTIONARY) {
264 CPDF_Dictionary* pDict = static_cast<CPDF_Dictionary*>(pNext);
265 if (iIndex == 0) {
266 return CPDF_Action(pDict);
267 }
268 } else if (iObjType == PDFOBJ_ARRAY) {
269 CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext);
270 return CPDF_Action(pArray->GetDict(iIndex));
271 }
272 return CPDF_Action();
273 }
274 const FX_CHAR* g_sAATypes[] = {"E", "X", "D", "U", "Fo", "Bl", "PO", "PC",
275 "PV", "PI", "O", "C", "K", "F", "V", "C",
276 "WC", "WS", "DS", "WP", "DP", ""};
277 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const {
278 if (m_pDict == NULL) {
279 return FALSE;
280 }
281 return m_pDict->KeyExist(g_sAATypes[(int)eType]);
282 }
283 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const {
284 if (!m_pDict) {
285 return CPDF_Action();
286 }
287 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType]));
288 }
289 FX_POSITION CPDF_AAction::GetStartPos() const {
290 if (m_pDict == NULL) {
291 return NULL;
292 }
293 return m_pDict->GetStartPos();
294 }
295 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos,
296 AActionType& eType) const {
297 if (m_pDict == NULL) {
298 return CPDF_Action();
299 }
300 CFX_ByteString csKey;
301 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey);
302 if (!pObj) {
303 return CPDF_Action();
304 }
305 CPDF_Object* pDirect = pObj->GetDirect();
306 if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) {
307 return CPDF_Action();
308 }
309 int i = 0;
310 while (g_sAATypes[i][0] != '\0') {
311 if (csKey == g_sAATypes[i]) {
312 break;
313 }
314 i++;
315 }
316 eType = (AActionType)i;
317 return CPDF_Action(static_cast<CPDF_Dictionary*>(pDirect));
318 }
319 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) {
320 m_pDocument = pDoc;
321 }
322 int CPDF_DocJSActions::CountJSActions() const {
323 ASSERT(m_pDocument != NULL);
324 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
325 return name_tree.GetCount();
326 }
327 CPDF_Action CPDF_DocJSActions::GetJSAction(int index,
328 CFX_ByteString& csName) const {
329 ASSERT(m_pDocument != NULL);
330 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
331 CPDF_Object* pAction = name_tree.LookupValue(index, csName);
332 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) {
333 return CPDF_Action();
334 }
335 return CPDF_Action(pAction->GetDict());
336 }
337 CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const {
338 ASSERT(m_pDocument != NULL);
339 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
340 CPDF_Object* pAction = name_tree.LookupValue(csName);
341 if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) {
342 return CPDF_Action();
343 }
344 return CPDF_Action(pAction->GetDict());
345 }
346 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const {
347 ASSERT(m_pDocument != NULL);
348 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
349 return name_tree.GetIndex(csName);
350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698