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

Side by Side Diff: core/fpdfdoc/cpdf_dest.cpp

Issue 2481743004: Add FPDFDest_GetLocationInPage API (Closed)
Patch Set: Review feedback Created 4 years, 1 month 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
« no previous file with comments | « core/fpdfdoc/cpdf_dest.h ('k') | core/fpdfdoc/cpdf_dest_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 59
58 CFX_ByteString mode = pObj->GetString(); 60 CFX_ByteString mode = pObj->GetString();
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::GetXYZ(bool* pHasX,
70 bool* pHasY,
71 bool* pHasZoom,
72 float* pX,
73 float* pY,
74 float* pZoom) const {
75 *pHasX = false;
76 *pHasY = false;
77 *pHasZoom = false;
78
79 CPDF_Array* pArray = ToArray(m_pObj);
80 if (!pArray)
81 return false;
82
83 if (pArray->GetCount() < 5)
84 return false;
85
86 const CPDF_Name* xyz = ToName(pArray->GetDirectObjectAt(1));
87 if (!xyz || xyz->GetString() != "XYZ")
88 return false;
89
90 const CPDF_Number* numX = ToNumber(pArray->GetDirectObjectAt(2));
91 const CPDF_Number* numY = ToNumber(pArray->GetDirectObjectAt(3));
92 const CPDF_Number* numZoom = ToNumber(pArray->GetDirectObjectAt(4));
93
94 // If the value is a CPDF_Null then ToNumber will return nullptr.
95 *pHasX = !!numX;
96 *pHasY = !!numY;
97 *pHasZoom = !!numZoom;
98
99 if (numX)
100 *pX = numX->GetNumber();
101 if (numY)
102 *pY = numY->GetNumber();
103
104 // A zoom value of 0 is equivalent to a null value, so treat it as a null.
105 if (numZoom) {
106 float num = numZoom->GetNumber();
107 if (num == 0.0)
108 *pHasZoom = false;
109 else
110 *pZoom = num;
111 }
112
113 return true;
114 }
115
67 FX_FLOAT CPDF_Dest::GetParam(int index) { 116 FX_FLOAT CPDF_Dest::GetParam(int index) {
68 CPDF_Array* pArray = ToArray(m_pObj); 117 CPDF_Array* pArray = ToArray(m_pObj);
69 return pArray ? pArray->GetNumberAt(2 + index) : 0; 118 return pArray ? pArray->GetNumberAt(2 + index) : 0;
70 } 119 }
71 120
72 CFX_ByteString CPDF_Dest::GetRemoteName() { 121 CFX_ByteString CPDF_Dest::GetRemoteName() {
73 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); 122 return m_pObj ? m_pObj->GetString() : CFX_ByteString();
74 } 123 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_dest.h ('k') | core/fpdfdoc/cpdf_dest_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698