summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_dest.cpp26
-rw-r--r--core/fpdfdoc/cpdf_dest.h4
2 files changed, 26 insertions, 4 deletions
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index ebe3834e91..cb15bf1c33 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfdoc/cpdf_dest.h"
+#include <algorithm>
+
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_name.h"
@@ -13,8 +15,14 @@
namespace {
-const char* const g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR",
- "FitB", "FitBH", "FitBV", nullptr};
+// These arrays are indexed by the PDFDEST_VIEW_* constants.
+
+// Last element is a sentinel.
+const char* const g_sZoomModes[] = {"Unknown", "XYZ", "Fit", "FitH",
+ "FitV", "FitR", "FitB", "FitBH",
+ "FitBV", nullptr};
+
+const int g_sZoomModeMaxParamCount[] = {0, 3, 0, 1, 1, 4, 0, 1, 1, 0};
} // namespace
@@ -66,9 +74,9 @@ int CPDF_Dest::GetZoomMode() {
return 0;
ByteString mode = pObj->GetString();
- for (int i = 0; g_sZoomModes[i]; ++i) {
+ for (int i = 1; g_sZoomModes[i]; ++i) {
if (mode == g_sZoomModes[i])
- return i + 1;
+ return i;
}
return 0;
@@ -121,6 +129,16 @@ bool CPDF_Dest::GetXYZ(bool* pHasX,
return true;
}
+unsigned int CPDF_Dest::GetNumParams() {
+ CPDF_Array* pArray = ToArray(m_pObj.Get());
+ if (!pArray || pArray->GetCount() < 2)
+ return 0;
+
+ size_t maxParamsForFitType = g_sZoomModeMaxParamCount[GetZoomMode()];
+ size_t numParamsInArray = pArray->GetCount() - 2;
+ return std::min(maxParamsForFitType, numParamsInArray);
+}
+
float CPDF_Dest::GetParam(int index) {
CPDF_Array* pArray = ToArray(m_pObj.Get());
return pArray ? pArray->GetNumberAt(2 + index) : 0;
diff --git a/core/fpdfdoc/cpdf_dest.h b/core/fpdfdoc/cpdf_dest.h
index 2836ebb471..4959901972 100644
--- a/core/fpdfdoc/cpdf_dest.h
+++ b/core/fpdfdoc/cpdf_dest.h
@@ -25,7 +25,11 @@ class CPDF_Dest {
ByteString GetRemoteName();
int GetPageIndex(CPDF_Document* pDoc);
uint32_t GetPageObjNum();
+
+ // Returns the zoom mode, as one of the PDFDEST_VIEW_* values in fpdf_doc.h.
int GetZoomMode();
+
+ unsigned int GetNumParams();
float GetParam(int index);
bool GetXYZ(bool* pHasX,