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

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

Issue 1194933003: Make CPDF_Object::GetString() a virtual method. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 5 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 {
10 if (!m_pDict) { 10 if (!m_pDict) {
11 return CPDF_Dest(); 11 return CPDF_Dest();
12 } 12 }
13 CFX_ByteString type = m_pDict->GetString("S"); 13 CFX_ByteString type = m_pDict->GetStringAt("S");
14 if (type != "GoTo" && type != "GoToR") { 14 if (type != "GoTo" && type != "GoToR") {
15 return CPDF_Dest(); 15 return CPDF_Dest();
16 } 16 }
17 CPDF_Object* pDest = m_pDict->GetElementValue("D"); 17 CPDF_Object* pDest = m_pDict->GetElementValue("D");
18 if (!pDest) { 18 if (!pDest) {
19 return CPDF_Dest(); 19 return CPDF_Dest();
20 } 20 }
21 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { 21 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
22 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 22 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
23 CFX_ByteStringC name = pDest->GetString(); 23 CFX_ByteStringC name = pDest->GetString();
24 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); 24 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name));
25 } 25 }
26 if (pDest->GetType() == PDFOBJ_ARRAY) { 26 if (pDest->GetType() == PDFOBJ_ARRAY) {
27 return CPDF_Dest((CPDF_Array*)pDest); 27 return CPDF_Dest((CPDF_Array*)pDest);
28 } 28 }
29 return CPDF_Dest(); 29 return CPDF_Dest();
30 } 30 }
31 const FX_CHAR* g_sATypes[] = {"Unknown", "GoTo", "GoToR", "GoToE", "Launch", "Th read", "URI", "Sound", "Movie", 31 const FX_CHAR* g_sATypes[] = {"Unknown", "GoTo", "GoToR", "GoToE", "Launch", "Th read", "URI", "Sound", "Movie",
32 "Hide", "Named", "SubmitForm", "ResetForm", "Imp ortData", "JavaScript", "SetOCGState", 32 "Hide", "Named", "SubmitForm", "ResetForm", "Imp ortData", "JavaScript", "SetOCGState",
33 "Rendition", "Trans", "GoTo3DView", "" 33 "Rendition", "Trans", "GoTo3DView", ""
34 }; 34 };
35 CPDF_Action::ActionType CPDF_Action::GetType() const 35 CPDF_Action::ActionType CPDF_Action::GetType() const
36 { 36 {
37 ActionType eType = Unknown; 37 ActionType eType = Unknown;
38 if (m_pDict != NULL) { 38 if (m_pDict != NULL) {
39 CFX_ByteString csType = m_pDict->GetString("S"); 39 CFX_ByteString csType = m_pDict->GetStringAt("S");
40 if (!csType.IsEmpty()) { 40 if (!csType.IsEmpty()) {
41 int i = 0; 41 int i = 0;
42 while (g_sATypes[i][0] != '\0') { 42 while (g_sATypes[i][0] != '\0') {
43 if (csType == g_sATypes[i]) { 43 if (csType == g_sATypes[i]) {
44 return (ActionType)i; 44 return (ActionType)i;
45 } 45 }
46 i ++; 46 i ++;
47 } 47 }
48 } 48 }
49 } 49 }
50 return eType; 50 return eType;
51 } 51 }
52 CFX_WideString CPDF_Action::GetFilePath() const 52 CFX_WideString CPDF_Action::GetFilePath() const
53 { 53 {
54 CFX_ByteString type = m_pDict->GetString("S"); 54 CFX_ByteString type = m_pDict->GetStringAt("S");
55 if (type != "GoToR" && type != "Launch" && 55 if (type != "GoToR" && type != "Launch" &&
56 type != "SubmitForm" && type != "ImportData") { 56 type != "SubmitForm" && type != "ImportData") {
57 return CFX_WideString(); 57 return CFX_WideString();
58 } 58 }
59 CPDF_Object* pFile = m_pDict->GetElementValue("F"); 59 CPDF_Object* pFile = m_pDict->GetElementValue("F");
60 CFX_WideString path; 60 CFX_WideString path;
61 if (pFile == NULL) { 61 if (pFile == NULL) {
62 if (type == "Launch") { 62 if (type == "Launch") {
63 CPDF_Dictionary* pWinDict = m_pDict->GetDict(FX_BSTRC("Win")); 63 CPDF_Dictionary* pWinDict = m_pDict->GetDict(FX_BSTRC("Win"));
64 if (pWinDict) { 64 if (pWinDict) {
65 return CFX_WideString::FromLocal(pWinDict->GetString(FX_BSTRC("F "))); 65 return CFX_WideString::FromLocal(pWinDict->GetStringAt("F"));
66 } 66 }
67 } 67 }
68 return path; 68 return path;
69 } 69 }
70 CPDF_FileSpec filespec(pFile); 70 CPDF_FileSpec filespec(pFile);
71 filespec.GetFileName(path); 71 filespec.GetFileName(path);
72 return path; 72 return path;
73 } 73 }
74 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const 74 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const
75 { 75 {
76 CFX_ByteString csURI; 76 CFX_ByteString csURI;
77 if (m_pDict == NULL) { 77 if (m_pDict == NULL) {
78 return csURI; 78 return csURI;
79 } 79 }
80 if (m_pDict->GetString("S") != "URI") { 80 if (m_pDict->GetStringAt("S") != "URI") {
81 return csURI; 81 return csURI;
82 } 82 }
83 csURI = m_pDict->GetString("URI"); 83 csURI = m_pDict->GetStringAt("URI");
84 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 84 CPDF_Dictionary* pRoot = pDoc->GetRoot();
85 CPDF_Dictionary* pURI = pRoot->GetDict("URI"); 85 CPDF_Dictionary* pURI = pRoot->GetDict("URI");
86 if (pURI != NULL) { 86 if (pURI != NULL) {
87 if (csURI.Find(FX_BSTRC(":"), 0) < 1) { 87 if (csURI.Find(FX_BSTRC(":"), 0) < 1) {
88 csURI = pURI->GetString("Base") + csURI; 88 csURI = pURI->GetStringAt("Base") + csURI;
89 } 89 }
90 } 90 }
91 return csURI; 91 return csURI;
92 } 92 }
93 FX_DWORD CPDF_ActionFields::GetFieldsCount() const 93 FX_DWORD CPDF_ActionFields::GetFieldsCount() const
94 { 94 {
95 if (m_pAction == NULL) { 95 if (m_pAction == NULL) {
96 return 0; 96 return 0;
97 } 97 }
98 CPDF_Dictionary* pDict = m_pAction->GetDict(); 98 CPDF_Dictionary* pDict = m_pAction->GetDict();
99 if (pDict == NULL) { 99 if (pDict == NULL) {
100 return 0; 100 return 0;
101 } 101 }
102 CFX_ByteString csType = pDict->GetString("S"); 102 CFX_ByteString csType = pDict->GetStringAt("S");
103 CPDF_Object* pFields = NULL; 103 CPDF_Object* pFields = NULL;
104 if (csType == "Hide") { 104 if (csType == "Hide") {
105 pFields = pDict->GetElementValue("T"); 105 pFields = pDict->GetElementValue("T");
106 } else { 106 } else {
107 pFields = pDict->GetArray("Fields"); 107 pFields = pDict->GetArray("Fields");
108 } 108 }
109 if (pFields == NULL) { 109 if (pFields == NULL) {
110 return 0; 110 return 0;
111 } 111 }
112 int iType = pFields->GetType(); 112 int iType = pFields->GetType();
113 if (iType == PDFOBJ_DICTIONARY) { 113 if (iType == PDFOBJ_DICTIONARY) {
114 return 1; 114 return 1;
115 } else if (iType == PDFOBJ_STRING) { 115 } else if (iType == PDFOBJ_STRING) {
116 return 1; 116 return 1;
117 } else if (iType == PDFOBJ_ARRAY) { 117 } else if (iType == PDFOBJ_ARRAY) {
118 return ((CPDF_Array*)pFields)->GetCount(); 118 return ((CPDF_Array*)pFields)->GetCount();
119 } 119 }
120 return 0; 120 return 0;
121 } 121 }
122 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const 122 void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const
123 { 123 {
124 fieldObjects.RemoveAll(); 124 fieldObjects.RemoveAll();
125 if (m_pAction == NULL) { 125 if (m_pAction == NULL) {
126 return; 126 return;
127 } 127 }
128 CPDF_Dictionary* pDict = m_pAction->GetDict(); 128 CPDF_Dictionary* pDict = m_pAction->GetDict();
129 if (pDict == NULL) { 129 if (pDict == NULL) {
130 return; 130 return;
131 } 131 }
132 CFX_ByteString csType = pDict->GetString("S"); 132 CFX_ByteString csType = pDict->GetStringAt("S");
133 CPDF_Object* pFields = NULL; 133 CPDF_Object* pFields = NULL;
134 if (csType == "Hide") { 134 if (csType == "Hide") {
135 pFields = pDict->GetElementValue("T"); 135 pFields = pDict->GetElementValue("T");
136 } else { 136 } else {
137 pFields = pDict->GetArray("Fields"); 137 pFields = pDict->GetArray("Fields");
138 } 138 }
139 if (pFields == NULL) { 139 if (pFields == NULL) {
140 return; 140 return;
141 } 141 }
142 int iType = pFields->GetType(); 142 int iType = pFields->GetType();
(...skipping 12 matching lines...) Expand all
155 } 155 }
156 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const 156 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const
157 { 157 {
158 if (m_pAction == NULL) { 158 if (m_pAction == NULL) {
159 return NULL; 159 return NULL;
160 } 160 }
161 CPDF_Dictionary* pDict = m_pAction->GetDict(); 161 CPDF_Dictionary* pDict = m_pAction->GetDict();
162 if (pDict == NULL) { 162 if (pDict == NULL) {
163 return NULL; 163 return NULL;
164 } 164 }
165 CFX_ByteString csType = pDict->GetString("S"); 165 CFX_ByteString csType = pDict->GetStringAt("S");
166 CPDF_Object* pFields = NULL; 166 CPDF_Object* pFields = NULL;
167 if (csType == "Hide") { 167 if (csType == "Hide") {
168 pFields = pDict->GetElementValue("T"); 168 pFields = pDict->GetElementValue("T");
169 } else { 169 } else {
170 pFields = pDict->GetArray("Fields"); 170 pFields = pDict->GetArray("Fields");
171 } 171 }
172 if (pFields == NULL) { 172 if (pFields == NULL) {
173 return NULL; 173 return NULL;
174 } 174 }
175 CPDF_Object* pFindObj = NULL; 175 CPDF_Object* pFindObj = NULL;
176 int iType = pFields->GetType(); 176 int iType = pFields->GetType();
177 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) { 177 if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) {
178 if (iIndex == 0) { 178 if (iIndex == 0) {
179 pFindObj = pFields; 179 pFindObj = pFields;
180 } 180 }
181 } else if (iType == PDFOBJ_ARRAY) { 181 } else if (iType == PDFOBJ_ARRAY) {
182 pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex); 182 pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex);
183 } 183 }
184 return pFindObj; 184 return pFindObj;
185 } 185 }
186 CPDF_LWinParam CPDF_Action::GetWinParam() const 186 CPDF_LWinParam CPDF_Action::GetWinParam() const
187 { 187 {
188 if (m_pDict == NULL) { 188 if (m_pDict == NULL) {
189 return NULL; 189 return NULL;
190 } 190 }
191 if (m_pDict->GetString("S") != "Launch") { 191 if (m_pDict->GetStringAt("S") != "Launch") {
192 return NULL; 192 return NULL;
193 } 193 }
194 return m_pDict->GetDict("Win"); 194 return m_pDict->GetDict("Win");
195 } 195 }
196 CFX_WideString CPDF_Action::GetJavaScript() const 196 CFX_WideString CPDF_Action::GetJavaScript() const
197 { 197 {
198 CFX_WideString csJS; 198 CFX_WideString csJS;
199 if (m_pDict == NULL) { 199 if (m_pDict == NULL) {
200 return csJS; 200 return csJS;
201 } 201 }
202 CPDF_Object* pJS = m_pDict->GetElementValue("JS"); 202 CPDF_Object* pJS = m_pDict->GetElementValue("JS");
203 if (pJS != NULL) { 203 if (pJS != NULL) {
204 return pJS->GetUnicodeText(); 204 return pJS->GetUnicodeText();
205 } 205 }
206 return csJS; 206 return csJS;
207 } 207 }
208 CPDF_Dictionary* CPDF_Action::GetAnnot() const 208 CPDF_Dictionary* CPDF_Action::GetAnnot() const
209 { 209 {
210 if (m_pDict == NULL) { 210 if (m_pDict == NULL) {
211 return NULL; 211 return NULL;
212 } 212 }
213 CFX_ByteString csType = m_pDict->GetString("S"); 213 CFX_ByteString csType = m_pDict->GetStringAt("S");
214 if (csType == FX_BSTRC("Rendition")) { 214 if (csType == FX_BSTRC("Rendition")) {
215 return m_pDict->GetDict("AN"); 215 return m_pDict->GetDict("AN");
216 } else if (csType == FX_BSTRC("Movie")) { 216 } else if (csType == FX_BSTRC("Movie")) {
217 return m_pDict->GetDict("Annotation"); 217 return m_pDict->GetDict("Annotation");
218 } 218 }
219 return NULL; 219 return NULL;
220 } 220 }
221 int32_t CPDF_Action::GetOperationType() const 221 int32_t CPDF_Action::GetOperationType() const
222 { 222 {
223 if (m_pDict == NULL) { 223 if (m_pDict == NULL) {
224 return 0; 224 return 0;
225 } 225 }
226 CFX_ByteString csType = m_pDict->GetString("S"); 226 CFX_ByteString csType = m_pDict->GetStringAt("S");
227 if (csType == FX_BSTRC("Rendition")) { 227 if (csType == FX_BSTRC("Rendition")) {
228 return m_pDict->GetInteger("OP"); 228 return m_pDict->GetInteger("OP");
229 } else if (csType == FX_BSTRC("Movie")) { 229 } else if (csType == FX_BSTRC("Movie")) {
230 CFX_ByteString csOP = m_pDict->GetString("Operation"); 230 CFX_ByteString csOP = m_pDict->GetStringAt("Operation");
231 if (csOP == FX_BSTRC("Play")) { 231 if (csOP == FX_BSTRC("Play")) {
232 return 0; 232 return 0;
233 } else if (csOP == FX_BSTRC("Stop")) { 233 } else if (csOP == FX_BSTRC("Stop")) {
234 return 1; 234 return 1;
235 } else if (csOP == FX_BSTRC("Pause")) { 235 } else if (csOP == FX_BSTRC("Pause")) {
236 return 2; 236 return 2;
237 } else if (csOP == FX_BSTRC("Resume")) { 237 } else if (csOP == FX_BSTRC("Resume")) {
238 return 3; 238 return 3;
239 } 239 }
240 } 240 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return CPDF_Action(); 356 return CPDF_Action();
357 } 357 }
358 return CPDF_Action(pAction->GetDict()); 358 return CPDF_Action(pAction->GetDict());
359 } 359 }
360 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const 360 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const
361 { 361 {
362 ASSERT(m_pDocument != NULL); 362 ASSERT(m_pDocument != NULL);
363 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); 363 CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
364 return name_tree.GetIndex(csName); 364 return name_tree.GetIndex(csName);
365 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698