| 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 "core/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 8 | 8 |
| 9 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { | 9 CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { |
| 10 if (!m_pDict) { | 10 if (!m_pDict) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return eType; | 49 return eType; |
| 50 } | 50 } |
| 51 CFX_WideString CPDF_Action::GetFilePath() const { | 51 CFX_WideString CPDF_Action::GetFilePath() const { |
| 52 CFX_ByteString type = m_pDict->GetString("S"); | 52 CFX_ByteString type = m_pDict->GetString("S"); |
| 53 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && | 53 if (type != "GoToR" && type != "Launch" && type != "SubmitForm" && |
| 54 type != "ImportData") { | 54 type != "ImportData") { |
| 55 return CFX_WideString(); | 55 return CFX_WideString(); |
| 56 } | 56 } |
| 57 CPDF_Object* pFile = m_pDict->GetElementValue("F"); | 57 CPDF_Object* pFile = m_pDict->GetElementValue("F"); |
| 58 CFX_WideString path; | 58 CFX_WideString path; |
| 59 if (pFile == NULL) { | 59 if (!pFile) { |
| 60 if (type == "Launch") { | 60 if (type == "Launch") { |
| 61 CPDF_Dictionary* pWinDict = m_pDict->GetDict("Win"); | 61 CPDF_Dictionary* pWinDict = m_pDict->GetDict("Win"); |
| 62 if (pWinDict) { | 62 if (pWinDict) { |
| 63 return CFX_WideString::FromLocal(pWinDict->GetString("F")); | 63 return CFX_WideString::FromLocal(pWinDict->GetString("F")); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 return path; | 66 return path; |
| 67 } | 67 } |
| 68 CPDF_FileSpec filespec(pFile); | 68 CPDF_FileSpec filespec(pFile); |
| 69 filespec.GetFileName(path); | 69 filespec.GetFileName(path); |
| 70 return path; | 70 return path; |
| 71 } | 71 } |
| 72 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const { | 72 CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const { |
| 73 CFX_ByteString csURI; | 73 CFX_ByteString csURI; |
| 74 if (m_pDict == NULL) { | 74 if (!m_pDict) { |
| 75 return csURI; | 75 return csURI; |
| 76 } | 76 } |
| 77 if (m_pDict->GetString("S") != "URI") { | 77 if (m_pDict->GetString("S") != "URI") { |
| 78 return csURI; | 78 return csURI; |
| 79 } | 79 } |
| 80 csURI = m_pDict->GetString("URI"); | 80 csURI = m_pDict->GetString("URI"); |
| 81 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 81 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
| 82 CPDF_Dictionary* pURI = pRoot->GetDict("URI"); | 82 CPDF_Dictionary* pURI = pRoot->GetDict("URI"); |
| 83 if (pURI) { | 83 if (pURI) { |
| 84 if (csURI.Find(":", 0) < 1) { | 84 if (csURI.Find(":", 0) < 1) { |
| 85 csURI = pURI->GetString("Base") + csURI; | 85 csURI = pURI->GetString("Base") + csURI; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 return csURI; | 88 return csURI; |
| 89 } | 89 } |
| 90 FX_DWORD CPDF_ActionFields::GetFieldsCount() const { | 90 FX_DWORD CPDF_ActionFields::GetFieldsCount() const { |
| 91 if (m_pAction == NULL) { | 91 if (!m_pAction) { |
| 92 return 0; | 92 return 0; |
| 93 } | 93 } |
| 94 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 94 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
| 95 if (pDict == NULL) { | 95 if (!pDict) { |
| 96 return 0; | 96 return 0; |
| 97 } | 97 } |
| 98 CFX_ByteString csType = pDict->GetString("S"); | 98 CFX_ByteString csType = pDict->GetString("S"); |
| 99 CPDF_Object* pFields = NULL; | 99 CPDF_Object* pFields = NULL; |
| 100 if (csType == "Hide") { | 100 if (csType == "Hide") { |
| 101 pFields = pDict->GetElementValue("T"); | 101 pFields = pDict->GetElementValue("T"); |
| 102 } else { | 102 } else { |
| 103 pFields = pDict->GetArray("Fields"); | 103 pFields = pDict->GetArray("Fields"); |
| 104 } | 104 } |
| 105 if (!pFields) | 105 if (!pFields) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 CPDF_Object* pObj = pArray->GetElementValue(i); | 139 CPDF_Object* pObj = pArray->GetElementValue(i); |
| 140 if (pObj) { | 140 if (pObj) { |
| 141 fields.push_back(pObj); | 141 fields.push_back(pObj); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 return fields; | 145 return fields; |
| 146 } | 146 } |
| 147 | 147 |
| 148 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { | 148 CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { |
| 149 if (m_pAction == NULL) { | 149 if (!m_pAction) { |
| 150 return NULL; | 150 return NULL; |
| 151 } | 151 } |
| 152 CPDF_Dictionary* pDict = m_pAction->GetDict(); | 152 CPDF_Dictionary* pDict = m_pAction->GetDict(); |
| 153 if (pDict == NULL) { | 153 if (!pDict) { |
| 154 return NULL; | 154 return NULL; |
| 155 } | 155 } |
| 156 CFX_ByteString csType = pDict->GetString("S"); | 156 CFX_ByteString csType = pDict->GetString("S"); |
| 157 CPDF_Object* pFields = NULL; | 157 CPDF_Object* pFields = NULL; |
| 158 if (csType == "Hide") { | 158 if (csType == "Hide") { |
| 159 pFields = pDict->GetElementValue("T"); | 159 pFields = pDict->GetElementValue("T"); |
| 160 } else { | 160 } else { |
| 161 pFields = pDict->GetArray("Fields"); | 161 pFields = pDict->GetArray("Fields"); |
| 162 } | 162 } |
| 163 if (pFields == NULL) { | 163 if (!pFields) { |
| 164 return NULL; | 164 return NULL; |
| 165 } | 165 } |
| 166 CPDF_Object* pFindObj = NULL; | 166 CPDF_Object* pFindObj = NULL; |
| 167 if (pFields->IsDictionary() || pFields->IsString()) { | 167 if (pFields->IsDictionary() || pFields->IsString()) { |
| 168 if (iIndex == 0) | 168 if (iIndex == 0) |
| 169 pFindObj = pFields; | 169 pFindObj = pFields; |
| 170 } else if (CPDF_Array* pArray = pFields->AsArray()) { | 170 } else if (CPDF_Array* pArray = pFields->AsArray()) { |
| 171 pFindObj = pArray->GetElementValue(iIndex); | 171 pFindObj = pArray->GetElementValue(iIndex); |
| 172 } | 172 } |
| 173 return pFindObj; | 173 return pFindObj; |
| 174 } | 174 } |
| 175 | 175 |
| 176 CFX_WideString CPDF_Action::GetJavaScript() const { | 176 CFX_WideString CPDF_Action::GetJavaScript() const { |
| 177 CFX_WideString csJS; | 177 CFX_WideString csJS; |
| 178 if (m_pDict == NULL) { | 178 if (!m_pDict) { |
| 179 return csJS; | 179 return csJS; |
| 180 } | 180 } |
| 181 CPDF_Object* pJS = m_pDict->GetElementValue("JS"); | 181 CPDF_Object* pJS = m_pDict->GetElementValue("JS"); |
| 182 return pJS ? pJS->GetUnicodeText() : csJS; | 182 return pJS ? pJS->GetUnicodeText() : csJS; |
| 183 } | 183 } |
| 184 CPDF_Dictionary* CPDF_Action::GetAnnot() const { | 184 CPDF_Dictionary* CPDF_Action::GetAnnot() const { |
| 185 if (!m_pDict) { | 185 if (!m_pDict) { |
| 186 return nullptr; | 186 return nullptr; |
| 187 } | 187 } |
| 188 CFX_ByteString csType = m_pDict->GetString("S"); | 188 CFX_ByteString csType = m_pDict->GetString("S"); |
| 189 if (csType == "Rendition") { | 189 if (csType == "Rendition") { |
| 190 return m_pDict->GetDict("AN"); | 190 return m_pDict->GetDict("AN"); |
| 191 } | 191 } |
| 192 if (csType == "Movie") { | 192 if (csType == "Movie") { |
| 193 return m_pDict->GetDict("Annotation"); | 193 return m_pDict->GetDict("Annotation"); |
| 194 } | 194 } |
| 195 return nullptr; | 195 return nullptr; |
| 196 } | 196 } |
| 197 int32_t CPDF_Action::GetOperationType() const { | 197 int32_t CPDF_Action::GetOperationType() const { |
| 198 if (m_pDict == NULL) { | 198 if (!m_pDict) { |
| 199 return 0; | 199 return 0; |
| 200 } | 200 } |
| 201 CFX_ByteString csType = m_pDict->GetString("S"); | 201 CFX_ByteString csType = m_pDict->GetString("S"); |
| 202 if (csType == "Rendition") { | 202 if (csType == "Rendition") { |
| 203 return m_pDict->GetInteger("OP"); | 203 return m_pDict->GetInteger("OP"); |
| 204 } | 204 } |
| 205 if (csType == "Movie") { | 205 if (csType == "Movie") { |
| 206 CFX_ByteString csOP = m_pDict->GetString("Operation"); | 206 CFX_ByteString csOP = m_pDict->GetString("Operation"); |
| 207 if (csOP == "Play") { | 207 if (csOP == "Play") { |
| 208 return 0; | 208 return 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 226 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 226 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); |
| 227 if (!pNext) | 227 if (!pNext) |
| 228 return 0; | 228 return 0; |
| 229 if (pNext->IsDictionary()) | 229 if (pNext->IsDictionary()) |
| 230 return 1; | 230 return 1; |
| 231 if (CPDF_Array* pArray = pNext->AsArray()) | 231 if (CPDF_Array* pArray = pNext->AsArray()) |
| 232 return pArray->GetCount(); | 232 return pArray->GetCount(); |
| 233 return 0; | 233 return 0; |
| 234 } | 234 } |
| 235 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { | 235 CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const { |
| 236 if (m_pDict == NULL || !m_pDict->KeyExist("Next")) { | 236 if (!m_pDict || !m_pDict->KeyExist("Next")) { |
| 237 return CPDF_Action(); | 237 return CPDF_Action(); |
| 238 } | 238 } |
| 239 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); | 239 CPDF_Object* pNext = m_pDict->GetElementValue("Next"); |
| 240 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { | 240 if (CPDF_Dictionary* pDict = ToDictionary(pNext)) { |
| 241 if (iIndex == 0) | 241 if (iIndex == 0) |
| 242 return CPDF_Action(pDict); | 242 return CPDF_Action(pDict); |
| 243 } else if (CPDF_Array* pArray = ToArray(pNext)) { | 243 } else if (CPDF_Array* pArray = ToArray(pNext)) { |
| 244 return CPDF_Action(pArray->GetDict(iIndex)); | 244 return CPDF_Action(pArray->GetDict(iIndex)); |
| 245 } | 245 } |
| 246 return CPDF_Action(); | 246 return CPDF_Action(); |
| 247 } | 247 } |
| 248 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", |
| 249 "PV", "PI", "O", "C", "K", "F", "V", "C", | 249 "PV", "PI", "O", "C", "K", "F", "V", "C", |
| 250 "WC", "WS", "DS", "WP", "DP", ""}; | 250 "WC", "WS", "DS", "WP", "DP", ""}; |
| 251 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { | 251 FX_BOOL CPDF_AAction::ActionExist(AActionType eType) const { |
| 252 if (m_pDict == NULL) { | 252 return m_pDict && m_pDict->KeyExist(g_sAATypes[(int)eType]); |
| 253 return FALSE; | |
| 254 } | |
| 255 return m_pDict->KeyExist(g_sAATypes[(int)eType]); | |
| 256 } | 253 } |
| 257 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { | 254 CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { |
| 258 if (!m_pDict) { | 255 if (!m_pDict) { |
| 259 return CPDF_Action(); | 256 return CPDF_Action(); |
| 260 } | 257 } |
| 261 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType])); | 258 return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType])); |
| 262 } | 259 } |
| 263 FX_POSITION CPDF_AAction::GetStartPos() const { | 260 FX_POSITION CPDF_AAction::GetStartPos() const { |
| 264 if (m_pDict == NULL) { | 261 if (!m_pDict) { |
| 265 return NULL; | 262 return NULL; |
| 266 } | 263 } |
| 267 return m_pDict->GetStartPos(); | 264 return m_pDict->GetStartPos(); |
| 268 } | 265 } |
| 269 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, | 266 CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, |
| 270 AActionType& eType) const { | 267 AActionType& eType) const { |
| 271 if (m_pDict == NULL) { | 268 if (!m_pDict) { |
| 272 return CPDF_Action(); | 269 return CPDF_Action(); |
| 273 } | 270 } |
| 274 CFX_ByteString csKey; | 271 CFX_ByteString csKey; |
| 275 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); | 272 CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); |
| 276 if (!pObj) { | 273 if (!pObj) { |
| 277 return CPDF_Action(); | 274 return CPDF_Action(); |
| 278 } | 275 } |
| 279 CPDF_Object* pDirect = pObj->GetDirect(); | 276 CPDF_Object* pDirect = pObj->GetDirect(); |
| 280 CPDF_Dictionary* pDict = ToDictionary(pDirect); | 277 CPDF_Dictionary* pDict = ToDictionary(pDirect); |
| 281 if (!pDict) | 278 if (!pDict) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 if (!ToDictionary(pAction)) { | 313 if (!ToDictionary(pAction)) { |
| 317 return CPDF_Action(); | 314 return CPDF_Action(); |
| 318 } | 315 } |
| 319 return CPDF_Action(pAction->GetDict()); | 316 return CPDF_Action(pAction->GetDict()); |
| 320 } | 317 } |
| 321 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { | 318 int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { |
| 322 ASSERT(m_pDocument); | 319 ASSERT(m_pDocument); |
| 323 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); | 320 CPDF_NameTree name_tree(m_pDocument, "JavaScript"); |
| 324 return name_tree.GetIndex(csName); | 321 return name_tree.GetIndex(csName); |
| 325 } | 322 } |
| OLD | NEW |