Remove unused parameter from FPDFDest_GetView().

Fix a bunch of nits as well.

Change-Id: I874f9b1d4676823635aad8986fcf23a11ae6efd9
Reviewed-on: https://pdfium-review.googlesource.com/22473
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index cb15bf1..0098f73 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -22,7 +22,11 @@
                                     "FitV",    "FitR", "FitB", "FitBH",
                                     "FitBV",   nullptr};
 
-const int g_sZoomModeMaxParamCount[] = {0, 3, 0, 1, 1, 4, 0, 1, 1, 0};
+const uint8_t g_sZoomModeMaxParamCount[] = {0, 3, 0, 1, 1, 4, 0, 1, 1, 0};
+
+static_assert(FX_ArraySize(g_sZoomModes) ==
+                  FX_ArraySize(g_sZoomModeMaxParamCount),
+              "Zoom mode count Mismatch");
 
 }  // namespace
 
@@ -34,7 +38,7 @@
 
 CPDF_Dest::~CPDF_Dest() {}
 
-int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
+int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) const {
   CPDF_Array* pArray = ToArray(m_pObj.Get());
   if (!pArray)
     return 0;
@@ -49,7 +53,7 @@
   return pDoc->GetPageIndex(pPage->GetObjNum());
 }
 
-uint32_t CPDF_Dest::GetPageObjNum() {
+uint32_t CPDF_Dest::GetPageObjNum() const {
   CPDF_Array* pArray = ToArray(m_pObj.Get());
   if (!pArray)
     return 0;
@@ -64,7 +68,7 @@
   return 0;
 }
 
-int CPDF_Dest::GetZoomMode() {
+int CPDF_Dest::GetZoomMode() const {
   CPDF_Array* pArray = ToArray(m_pObj.Get());
   if (!pArray)
     return 0;
@@ -129,21 +133,21 @@
   return true;
 }
 
-unsigned int CPDF_Dest::GetNumParams() {
+unsigned long CPDF_Dest::GetNumParams() const {
   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;
+  unsigned long maxParamsForFitType = g_sZoomModeMaxParamCount[GetZoomMode()];
+  unsigned long numParamsInArray = pArray->GetCount() - 2;
   return std::min(maxParamsForFitType, numParamsInArray);
 }
 
-float CPDF_Dest::GetParam(int index) {
+float CPDF_Dest::GetParam(int index) const {
   CPDF_Array* pArray = ToArray(m_pObj.Get());
   return pArray ? pArray->GetNumberAt(2 + index) : 0;
 }
 
-ByteString CPDF_Dest::GetRemoteName() {
+ByteString CPDF_Dest::GetRemoteName() const {
   return m_pObj ? m_pObj->GetString() : ByteString();
 }
diff --git a/core/fpdfdoc/cpdf_dest.h b/core/fpdfdoc/cpdf_dest.h
index 4959901..584669a 100644
--- a/core/fpdfdoc/cpdf_dest.h
+++ b/core/fpdfdoc/cpdf_dest.h
@@ -22,15 +22,15 @@
   ~CPDF_Dest();
 
   CPDF_Object* GetObject() const { return m_pObj.Get(); }
-  ByteString GetRemoteName();
-  int GetPageIndex(CPDF_Document* pDoc);
-  uint32_t GetPageObjNum();
+  ByteString GetRemoteName() const;
+  int GetPageIndex(CPDF_Document* pDoc) const;
+  uint32_t GetPageObjNum() const;
 
   // Returns the zoom mode, as one of the PDFDEST_VIEW_* values in fpdf_doc.h.
-  int GetZoomMode();
+  int GetZoomMode() const;
 
-  unsigned int GetNumParams();
-  float GetParam(int index);
+  unsigned long GetNumParams() const;
+  float GetParam(int index) const;
 
   bool GetXYZ(bool* pHasX,
               bool* pHasY,
diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp
index 14e4361..47ecf42 100644
--- a/fpdfsdk/fpdfdoc.cpp
+++ b/fpdfsdk/fpdfdoc.cpp
@@ -211,26 +211,20 @@
 }
 
 FPDF_EXPORT unsigned long FPDF_CALLCONV
-FPDFDest_GetView(FPDF_DOCUMENT document,
-                 FPDF_DEST pDict,
-                 unsigned long* outNumParams,
-                 FS_FLOAT* outParams) {
+FPDFDest_GetView(FPDF_DEST pDict,
+                 unsigned long* pNumParams,
+                 FS_FLOAT* pParams) {
   if (!pDict) {
-    *outNumParams = 0;
-    return 0;
-  }
-
-  CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
-  if (!pDoc) {
-    *outNumParams = 0;
+    *pNumParams = 0;
     return 0;
   }
 
   CPDF_Dest dest(static_cast<CPDF_Array*>(pDict));
-
-  *outNumParams = dest.GetNumParams();
-  for (unsigned long i = 0; i < *outNumParams; ++i)
-    outParams[i] = dest.GetParam(i);
+  unsigned long nParams = dest.GetNumParams();
+  ASSERT(nParams <= 4);
+  *pNumParams = nParams;
+  for (unsigned long i = 0; i < nParams; ++i)
+    pParams[i] = dest.GetParam(i);
   return dest.GetZoomMode();
 }
 
diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp
index 24414a1..d346330 100644
--- a/fpdfsdk/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/fpdfdoc_embeddertest.cpp
@@ -51,7 +51,7 @@
   numParams = 42;
   std::fill_n(params, 4, 42.4242f);
   EXPECT_EQ(static_cast<unsigned long>(PDFDEST_VIEW_UNKNOWN_MODE),
-            FPDFDest_GetView(document(), nullptr, &numParams, params));
+            FPDFDest_GetView(nullptr, &numParams, params));
   EXPECT_EQ(0U, numParams);
   EXPECT_FLOAT_EQ(42.4242f, params[0]);
 
@@ -60,7 +60,7 @@
   FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First");
   EXPECT_TRUE(dest);
   EXPECT_EQ(static_cast<unsigned long>(PDFDEST_VIEW_XYZ),
-            FPDFDest_GetView(document(), dest, &numParams, params));
+            FPDFDest_GetView(dest, &numParams, params));
   EXPECT_EQ(3U, numParams);
   EXPECT_FLOAT_EQ(0, params[0]);
   EXPECT_FLOAT_EQ(0, params[1]);
@@ -72,7 +72,7 @@
   dest = FPDF_GetNamedDestByName(document(), "Next");
   EXPECT_TRUE(dest);
   EXPECT_EQ(static_cast<unsigned long>(PDFDEST_VIEW_FIT),
-            FPDFDest_GetView(document(), dest, &numParams, params));
+            FPDFDest_GetView(dest, &numParams, params));
   EXPECT_EQ(0U, numParams);
   EXPECT_FLOAT_EQ(42.4242f, params[0]);
 
@@ -81,7 +81,7 @@
   dest = FPDF_GetNamedDestByName(document(), "FirstAlternate");
   EXPECT_TRUE(dest);
   EXPECT_EQ(static_cast<unsigned long>(PDFDEST_VIEW_XYZ),
-            FPDFDest_GetView(document(), dest, &numParams, params));
+            FPDFDest_GetView(dest, &numParams, params));
   EXPECT_EQ(3U, numParams);
   EXPECT_FLOAT_EQ(200, params[0]);
   EXPECT_FLOAT_EQ(400, params[1]);
@@ -93,7 +93,7 @@
   dest = FPDF_GetNamedDestByName(document(), "LastAlternate");
   EXPECT_TRUE(dest);
   EXPECT_EQ(static_cast<unsigned long>(PDFDEST_VIEW_XYZ),
-            FPDFDest_GetView(document(), dest, &numParams, params));
+            FPDFDest_GetView(dest, &numParams, params));
   EXPECT_EQ(3U, numParams);
   EXPECT_FLOAT_EQ(0, params[0]);
   EXPECT_FLOAT_EQ(0, params[1]);
diff --git a/public/fpdf_doc.h b/public/fpdf_doc.h
index 93efa7a..b523575 100644
--- a/public/fpdf_doc.h
+++ b/public/fpdf_doc.h
@@ -189,18 +189,14 @@
 // Get the view (fit type) specified by |dest|.
 // Experimental API. Subject to change.
 //
-//   document     - handle to the document.
 //   dest         - handle to the destination.
-//   outNumParams - buffer to write the number of view parameters.
-//   outParams -    buffer to write the view parameters. Must be at least 4
+//   pNumParams   - receives the number of view parameters, which is at most 4.
+//   pParams      - buffer to write the view parameters. Must be at least 4
 //                  FS_FLOATs long.
 // Returns one of the PDFDEST_VIEW_* constants, PDFDEST_VIEW_UNKNOWN_MODE if
 // |dest| does not specify a view.
 FPDF_EXPORT unsigned long FPDF_CALLCONV
-FPDFDest_GetView(FPDF_DOCUMENT document,
-                 FPDF_DEST dest,
-                 unsigned long* outNumParams,
-                 FS_FLOAT* outParams);
+FPDFDest_GetView(FPDF_DEST dest, unsigned long* pNumParams, FS_FLOAT* pParams);
 
 // Get the (x, y, zoom) location of |dest| in the destination page, if the
 // destination is in [page /XYZ x y zoom] syntax.