OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfdoc/cpdf_dest.h" | 7 #include "core/fpdfdoc/cpdf_dest.h" |
8 | 8 |
9 #include "core/fpdfapi/parser/cpdf_array.h" | 9 #include "core/fpdfapi/parser/cpdf_array.h" |
10 #include "core/fpdfapi/parser/cpdf_document.h" | 10 #include "core/fpdfapi/parser/cpdf_document.h" |
11 #include "core/fpdfapi/parser/cpdf_name.h" | |
12 #include "core/fpdfapi/parser/cpdf_number.h" | |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 const FX_CHAR* const g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", | 16 const FX_CHAR* const g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", |
15 "FitB", "FitBH", "FitBV", nullptr}; | 17 "FitB", "FitBH", "FitBV", nullptr}; |
16 | 18 |
17 } // namespace | 19 } // namespace |
18 | 20 |
19 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { | 21 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { |
20 CPDF_Array* pArray = ToArray(m_pObj); | 22 CPDF_Array* pArray = ToArray(m_pObj); |
(...skipping 27 matching lines...) Expand all Loading... | |
48 | 50 |
49 int CPDF_Dest::GetZoomMode() { | 51 int CPDF_Dest::GetZoomMode() { |
50 CPDF_Array* pArray = ToArray(m_pObj); | 52 CPDF_Array* pArray = ToArray(m_pObj); |
51 if (!pArray) | 53 if (!pArray) |
52 return 0; | 54 return 0; |
53 | 55 |
54 CPDF_Object* pObj = pArray->GetDirectObjectAt(1); | 56 CPDF_Object* pObj = pArray->GetDirectObjectAt(1); |
55 if (!pObj) | 57 if (!pObj) |
56 return 0; | 58 return 0; |
57 | 59 |
58 CFX_ByteString mode = pObj->GetString(); | 60 CFX_ByteString mode = pObj->GetString(); |
Lei Zhang
2016/11/07 20:27:16
(For later) Should this also check and make sure |
dsinclair
2016/11/07 21:49:18
Acknowledged.
| |
59 for (int i = 0; g_sZoomModes[i]; ++i) { | 61 for (int i = 0; g_sZoomModes[i]; ++i) { |
60 if (mode == g_sZoomModes[i]) | 62 if (mode == g_sZoomModes[i]) |
61 return i + 1; | 63 return i + 1; |
62 } | 64 } |
63 | 65 |
64 return 0; | 66 return 0; |
65 } | 67 } |
66 | 68 |
69 bool CPDF_Dest::HasXYZ() const { | |
70 CPDF_Array* pArray = ToArray(m_pObj); | |
71 if (!pArray) | |
72 return false; | |
73 | |
74 if (pArray->GetCount() < 5) | |
75 return false; | |
76 | |
77 const CPDF_Name* xyz = ToName(pArray->GetDirectObjectAt(1)); | |
78 if (!xyz || xyz->GetString() != "XYZ") | |
79 return false; | |
80 return true; | |
81 } | |
82 | |
83 void CPDF_Dest::GetXYZ(bool* hasX, | |
84 bool* hasY, | |
85 bool* hasZoom, | |
86 float* x, | |
87 float* y, | |
88 float* zoom) const { | |
89 ASSERT(HasXYZ()); | |
90 | |
91 CPDF_Array* pArray = ToArray(m_pObj); | |
92 if (!pArray) { | |
93 *hasX = false; | |
94 *hasY = false; | |
95 *hasZoom = false; | |
96 return; | |
97 } | |
98 | |
99 const CPDF_Number* numX = ToNumber(pArray->GetDirectObjectAt(2)); | |
100 const CPDF_Number* numY = ToNumber(pArray->GetDirectObjectAt(3)); | |
101 const CPDF_Number* numZoom = ToNumber(pArray->GetDirectObjectAt(4)); | |
102 | |
103 // If the value is a CPDF_Null then ToNumber will return nullptr. | |
104 *hasX = !!numX; | |
105 *hasY = !!numY; | |
106 *hasZoom = !!numZoom; | |
107 | |
108 if (numX) | |
109 *x = numX->GetNumber(); | |
110 if (numY) | |
111 *y = numY->GetNumber(); | |
112 | |
113 // A zoom value of 0 is equivalent to a null value, so treat it as a null. | |
114 if (numZoom) { | |
115 if (numZoom->GetNumber() == 0.0) | |
Lei Zhang
2016/11/07 20:27:16
Call GetNumber() just once?
dsinclair
2016/11/07 21:49:18
Done.
| |
116 *hasZoom = false; | |
117 else | |
118 *zoom = numZoom->GetNumber(); | |
119 } | |
120 } | |
121 | |
67 FX_FLOAT CPDF_Dest::GetParam(int index) { | 122 FX_FLOAT CPDF_Dest::GetParam(int index) { |
68 CPDF_Array* pArray = ToArray(m_pObj); | 123 CPDF_Array* pArray = ToArray(m_pObj); |
69 return pArray ? pArray->GetNumberAt(2 + index) : 0; | 124 return pArray ? pArray->GetNumberAt(2 + index) : 0; |
70 } | 125 } |
71 | 126 |
72 CFX_ByteString CPDF_Dest::GetRemoteName() { | 127 CFX_ByteString CPDF_Dest::GetRemoteName() { |
73 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); | 128 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); |
74 } | 129 } |
OLD | NEW |