diff options
author | dsinclair <dsinclair@chromium.org> | 2016-11-08 06:55:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-08 06:55:40 -0800 |
commit | c59fa8895fa6fa8428b9b278eee6f05478ab8f56 (patch) | |
tree | 3216ee06e894144d578c07e5c655b7637bb6c59c /core/fpdfdoc/cpdf_dest.cpp | |
parent | 3c669a7fb05dfb602992a5d2333081daef6f002f (diff) | |
download | pdfium-c59fa8895fa6fa8428b9b278eee6f05478ab8f56.tar.xz |
Add FPDFDest_GetLocationInPage API
Add an API to get the value of the /XYZ destination parameter.
This CL was originally from https://codereview.chromium.org/1960193003/ by
halcanary@.
Review-Url: https://codereview.chromium.org/2481743004
Diffstat (limited to 'core/fpdfdoc/cpdf_dest.cpp')
-rw-r--r-- | core/fpdfdoc/cpdf_dest.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp index 312ef87346..51e2d0b534 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; |