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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfdoc/cpdf_dest.cpp
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index 312ef8734634167cf53f55b978549b692f27c1fc..51e2d0b53427974a5a70613135064a8c551eb72a 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -8,6 +8,8 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fpdfapi/parser/cpdf_number.h"
namespace {
@@ -64,6 +66,53 @@ int CPDF_Dest::GetZoomMode() {
return 0;
}
+bool CPDF_Dest::GetXYZ(bool* pHasX,
+ bool* pHasY,
+ bool* pHasZoom,
+ float* pX,
+ float* pY,
+ float* pZoom) const {
+ *pHasX = false;
+ *pHasY = false;
+ *pHasZoom = false;
+
+ CPDF_Array* pArray = ToArray(m_pObj);
+ if (!pArray)
+ return false;
+
+ if (pArray->GetCount() < 5)
+ return false;
+
+ const CPDF_Name* xyz = ToName(pArray->GetDirectObjectAt(1));
+ if (!xyz || xyz->GetString() != "XYZ")
+ return false;
+
+ const CPDF_Number* numX = ToNumber(pArray->GetDirectObjectAt(2));
+ const CPDF_Number* numY = ToNumber(pArray->GetDirectObjectAt(3));
+ const CPDF_Number* numZoom = ToNumber(pArray->GetDirectObjectAt(4));
+
+ // If the value is a CPDF_Null then ToNumber will return nullptr.
+ *pHasX = !!numX;
+ *pHasY = !!numY;
+ *pHasZoom = !!numZoom;
+
+ if (numX)
+ *pX = numX->GetNumber();
+ if (numY)
+ *pY = numY->GetNumber();
+
+ // A zoom value of 0 is equivalent to a null value, so treat it as a null.
+ if (numZoom) {
+ float num = numZoom->GetNumber();
+ if (num == 0.0)
+ *pHasZoom = false;
+ else
+ *pZoom = num;
+ }
+
+ return true;
+}
+
FX_FLOAT CPDF_Dest::GetParam(int index) {
CPDF_Array* pArray = ToArray(m_pObj);
return pArray ? pArray->GetNumberAt(2 + index) : 0;
« 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