OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #include "core/fpdfdoc/include/cpdf_dest.h" |
| 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const FX_CHAR* const g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", |
| 15 "FitB", "FitBH", "FitBV", nullptr}; |
| 16 |
| 17 } // namespace |
| 18 |
| 19 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { |
| 20 CPDF_Array* pArray = ToArray(m_pObj); |
| 21 if (!pArray) |
| 22 return 0; |
| 23 |
| 24 CPDF_Object* pPage = pArray->GetDirectObjectAt(0); |
| 25 if (!pPage) |
| 26 return 0; |
| 27 if (pPage->IsNumber()) |
| 28 return pPage->GetInteger(); |
| 29 if (!pPage->IsDictionary()) |
| 30 return 0; |
| 31 return pDoc->GetPageIndex(pPage->GetObjNum()); |
| 32 } |
| 33 |
| 34 uint32_t CPDF_Dest::GetPageObjNum() { |
| 35 CPDF_Array* pArray = ToArray(m_pObj); |
| 36 if (!pArray) |
| 37 return 0; |
| 38 |
| 39 CPDF_Object* pPage = pArray->GetDirectObjectAt(0); |
| 40 if (!pPage) |
| 41 return 0; |
| 42 if (pPage->IsNumber()) |
| 43 return pPage->GetInteger(); |
| 44 if (pPage->IsDictionary()) |
| 45 return pPage->GetObjNum(); |
| 46 return 0; |
| 47 } |
| 48 |
| 49 int CPDF_Dest::GetZoomMode() { |
| 50 CPDF_Array* pArray = ToArray(m_pObj); |
| 51 if (!pArray) |
| 52 return 0; |
| 53 |
| 54 CPDF_Object* pObj = pArray->GetDirectObjectAt(1); |
| 55 if (!pObj) |
| 56 return 0; |
| 57 |
| 58 CFX_ByteString mode = pObj->GetString(); |
| 59 for (int i = 0; g_sZoomModes[i]; ++i) { |
| 60 if (mode == g_sZoomModes[i]) |
| 61 return i + 1; |
| 62 } |
| 63 |
| 64 return 0; |
| 65 } |
| 66 |
| 67 FX_FLOAT CPDF_Dest::GetParam(int index) { |
| 68 CPDF_Array* pArray = ToArray(m_pObj); |
| 69 return pArray ? pArray->GetNumberAt(2 + index) : 0; |
| 70 } |
| 71 |
| 72 CFX_ByteString CPDF_Dest::GetRemoteName() { |
| 73 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); |
| 74 } |
OLD | NEW |