| 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 const int nMaxRecursion = 32; | 8 const int nMaxRecursion = 32; |
| 9 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { | 9 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { |
| 10 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 10 CPDF_Array* pArray = ToArray(m_pObj); |
| 11 if (!pArray) |
| 11 return 0; | 12 return 0; |
| 12 } | 13 |
| 13 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); | 14 CPDF_Object* pPage = pArray->GetElementValue(0); |
| 14 if (!pPage) | 15 if (!pPage) |
| 15 return 0; | 16 return 0; |
| 16 if (pPage->IsNumber()) | 17 if (pPage->IsNumber()) |
| 17 return pPage->GetInteger(); | 18 return pPage->GetInteger(); |
| 18 if (!pPage->IsDictionary()) | 19 if (!pPage->IsDictionary()) |
| 19 return 0; | 20 return 0; |
| 20 return pDoc->GetPageIndex(pPage->GetObjNum()); | 21 return pDoc->GetPageIndex(pPage->GetObjNum()); |
| 21 } | 22 } |
| 22 FX_DWORD CPDF_Dest::GetPageObjNum() { | 23 FX_DWORD CPDF_Dest::GetPageObjNum() { |
| 23 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 24 CPDF_Array* pArray = ToArray(m_pObj); |
| 25 if (!pArray) |
| 24 return 0; | 26 return 0; |
| 25 } | 27 |
| 26 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); | 28 CPDF_Object* pPage = pArray->GetElementValue(0); |
| 27 if (!pPage) | 29 if (!pPage) |
| 28 return 0; | 30 return 0; |
| 29 if (pPage->IsNumber()) | 31 if (pPage->IsNumber()) |
| 30 return pPage->GetInteger(); | 32 return pPage->GetInteger(); |
| 31 if (pPage->IsDictionary()) | 33 if (pPage->IsDictionary()) |
| 32 return pPage->GetObjNum(); | 34 return pPage->GetObjNum(); |
| 33 return 0; | 35 return 0; |
| 34 } | 36 } |
| 35 const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", | 37 const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", |
| 36 "FitB", "FitBH", "FitBV", ""}; | 38 "FitB", "FitBH", "FitBV", ""}; |
| 37 int CPDF_Dest::GetZoomMode() { | 39 int CPDF_Dest::GetZoomMode() { |
| 38 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 40 CPDF_Array* pArray = ToArray(m_pObj); |
| 41 if (!pArray) |
| 39 return 0; | 42 return 0; |
| 40 } | 43 |
| 41 CFX_ByteString mode; | 44 CFX_ByteString mode; |
| 42 CPDF_Object* pObj = ((CPDF_Array*)m_pObj)->GetElementValue(1); | 45 CPDF_Object* pObj = pArray->GetElementValue(1); |
| 43 mode = pObj ? pObj->GetString() : CFX_ByteString(); | 46 mode = pObj ? pObj->GetString() : CFX_ByteString(); |
| 44 int i = 0; | 47 int i = 0; |
| 45 while (g_sZoomModes[i][0] != '\0') { | 48 while (g_sZoomModes[i][0] != '\0') { |
| 46 if (mode == g_sZoomModes[i]) { | 49 if (mode == g_sZoomModes[i]) { |
| 47 return i + 1; | 50 return i + 1; |
| 48 } | 51 } |
| 49 i++; | 52 i++; |
| 50 } | 53 } |
| 51 return 0; | 54 return 0; |
| 52 } | 55 } |
| 53 FX_FLOAT CPDF_Dest::GetParam(int index) { | 56 FX_FLOAT CPDF_Dest::GetParam(int index) { |
| 54 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 57 CPDF_Array* pArray = ToArray(m_pObj); |
| 55 return 0; | 58 return pArray ? pArray->GetNumber(2 + index) : 0; |
| 56 } | |
| 57 return ((CPDF_Array*)m_pObj)->GetNumber(2 + index); | |
| 58 } | 59 } |
| 59 CFX_ByteString CPDF_Dest::GetRemoteName() { | 60 CFX_ByteString CPDF_Dest::GetRemoteName() { |
| 60 if (m_pObj == NULL) { | 61 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); |
| 61 return CFX_ByteString(); | |
| 62 } | |
| 63 return m_pObj->GetString(); | |
| 64 } | 62 } |
| 65 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, | 63 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, |
| 66 const CFX_ByteStringC& category) { | 64 const CFX_ByteStringC& category) { |
| 67 if (pDoc->GetRoot() && pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))) | 65 if (pDoc->GetRoot() && pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))) |
| 68 m_pRoot = pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))->GetDict(category); | 66 m_pRoot = pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))->GetDict(category); |
| 69 else | 67 else |
| 70 m_pRoot = NULL; | 68 m_pRoot = NULL; |
| 71 } | 69 } |
| 72 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, | 70 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, |
| 73 const CFX_ByteString& csName, | 71 const CFX_ByteString& csName, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { | 215 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { |
| 218 if (m_pRoot == NULL) { | 216 if (m_pRoot == NULL) { |
| 219 return NULL; | 217 return NULL; |
| 220 } | 218 } |
| 221 int nIndex = 0; | 219 int nIndex = 0; |
| 222 return SearchNameNode(m_pRoot, csName, nIndex, NULL); | 220 return SearchNameNode(m_pRoot, csName, nIndex, NULL); |
| 223 } | 221 } |
| 224 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, | 222 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, |
| 225 const CFX_ByteStringC& sName) { | 223 const CFX_ByteStringC& sName) { |
| 226 CPDF_Object* pValue = LookupValue(sName); | 224 CPDF_Object* pValue = LookupValue(sName); |
| 227 if (pValue == NULL) { | 225 if (!pValue) { |
| 228 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict(FX_BSTRC("Dests")); | 226 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict(FX_BSTRC("Dests")); |
| 229 if (pDests == NULL) { | 227 if (!pDests) |
| 230 return NULL; | 228 return nullptr; |
| 231 } | |
| 232 pValue = pDests->GetElementValue(sName); | 229 pValue = pDests->GetElementValue(sName); |
| 233 } | 230 } |
| 234 if (pValue == NULL) { | 231 if (!pValue) |
| 235 return NULL; | 232 return nullptr; |
| 236 } | 233 if (CPDF_Array* pArray = pValue->AsArray()) |
| 237 if (pValue->GetType() == PDFOBJ_ARRAY) { | 234 return pArray; |
| 238 return (CPDF_Array*)pValue; | 235 if (CPDF_Dictionary* pDict = pValue->AsDictionary()) |
| 239 } | |
| 240 if (CPDF_Dictionary* pDict = pValue->AsDictionary()) { | |
| 241 return pDict->GetArray(FX_BSTRC("D")); | 236 return pDict->GetArray(FX_BSTRC("D")); |
| 242 } | 237 return nullptr; |
| 243 return NULL; | |
| 244 } | 238 } |
| 245 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 239 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
| 246 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 240 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 247 static CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { | 241 static CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { |
| 248 CFX_WideString result; | 242 CFX_WideString result; |
| 249 while (*str) { | 243 while (*str) { |
| 250 if (*str == '/') { | 244 if (*str == '/') { |
| 251 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 245 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 252 result += ':'; | 246 result += ':'; |
| 253 #else | 247 #else |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 int nPage = FXSYS_atoi(bsLbl); | 530 int nPage = FXSYS_atoi(bsLbl); |
| 537 if (nPage > 0 && nPage <= nPages) { | 531 if (nPage > 0 && nPage <= nPages) { |
| 538 return nPage; | 532 return nPage; |
| 539 } | 533 } |
| 540 return -1; | 534 return -1; |
| 541 } | 535 } |
| 542 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { | 536 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
| 543 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); | 537 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); |
| 544 return GetPageByLabel(bsLabel); | 538 return GetPageByLabel(bsLabel); |
| 545 } | 539 } |
| OLD | NEW |