summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_dest.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-01-04 11:54:18 -0500
committerChromium commit bot <commit-bot@chromium.org>2018-01-04 19:45:11 +0000
commitde3f3fc5e16a2ee4fad2bdc0cda9e2ce73fd4fe3 (patch)
treedebf6885600821ca264fb69957258fdbf767bb43 /core/fpdfdoc/cpdf_dest.cpp
parentcb6c8d4ec4781c7db8448f2b4d9a8af879cf014e (diff)
downloadpdfium-de3f3fc5e16a2ee4fad2bdc0cda9e2ce73fd4fe3.tar.xz
Open FPDFDest_GetView API.
FPDFDest_GetView returns the view fit type and the parameters of the view for a given destination. This is useful to have more precise internal links and bookmarks that are able to manipulate the viewport position and zoom level to focus on the part of the PDF that it links to. Bug: 55776, 535978, 748852 Change-Id: Ibf7df40a852030d75ec78cec7662380319569850 Reviewed-on: https://pdfium-review.googlesource.com/21790 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpdf_dest.cpp')
-rw-r--r--core/fpdfdoc/cpdf_dest.cpp26
1 files changed, 22 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;