From de3f3fc5e16a2ee4fad2bdc0cda9e2ce73fd4fe3 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Thu, 4 Jan 2018 11:54:18 -0500 Subject: 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 Reviewed-by: Ryan Harrison --- fpdfsdk/fpdfdoc.cpp | 24 ++++++++++++++++ fpdfsdk/fpdfdoc_embeddertest.cpp | 59 ++++++++++++++++++++++++++++++++++++++++ fpdfsdk/fpdfview_c_api_test.c | 1 + 3 files changed, 84 insertions(+) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp index 4d2942fb31..51a1c61e77 100644 --- a/fpdfsdk/fpdfdoc.cpp +++ b/fpdfsdk/fpdfdoc.cpp @@ -210,6 +210,30 @@ FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST pDict) { return dest.GetPageIndex(pDoc); } +FPDF_EXPORT unsigned long FPDF_CALLCONV +FPDFDest_GetView(FPDF_DOCUMENT document, + FPDF_DEST pDict, + unsigned long* outNumParams, + FS_FLOAT* outParams) { + if (!pDict) { + *outNumParams = 0; + return 0; + } + + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc) { + *outNumParams = 0; + return 0; + } + + CPDF_Dest dest(static_cast(pDict)); + + *outNumParams = dest.GetNumParams(); + for (unsigned long i = 0; i < *outNumParams; ++i) + outParams[i] = dest.GetParam(i); + return dest.GetZoomMode(); +} + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFDest_GetLocationInPage(FPDF_DEST pDict, FPDF_BOOL* hasXVal, diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp index c691a17a11..24414a1c33 100644 --- a/fpdfsdk/fpdfdoc_embeddertest.cpp +++ b/fpdfsdk/fpdfdoc_embeddertest.cpp @@ -42,6 +42,65 @@ TEST_F(FPDFDocEmbeddertest, DestGetPageIndex) { EXPECT_EQ(0U, FPDFDest_GetPageIndex(document(), dest)); } +TEST_F(FPDFDocEmbeddertest, DestGetView) { + EXPECT_TRUE(OpenDocument("named_dests.pdf")); + + unsigned long numParams; + FS_FLOAT params[4]; + + numParams = 42; + std::fill_n(params, 4, 42.4242f); + EXPECT_EQ(static_cast(PDFDEST_VIEW_UNKNOWN_MODE), + FPDFDest_GetView(document(), nullptr, &numParams, params)); + EXPECT_EQ(0U, numParams); + EXPECT_FLOAT_EQ(42.4242f, params[0]); + + numParams = 42; + std::fill_n(params, 4, 42.4242f); + FPDF_DEST dest = FPDF_GetNamedDestByName(document(), "First"); + EXPECT_TRUE(dest); + EXPECT_EQ(static_cast(PDFDEST_VIEW_XYZ), + FPDFDest_GetView(document(), dest, &numParams, params)); + EXPECT_EQ(3U, numParams); + EXPECT_FLOAT_EQ(0, params[0]); + EXPECT_FLOAT_EQ(0, params[1]); + EXPECT_FLOAT_EQ(1, params[2]); + EXPECT_FLOAT_EQ(42.4242f, params[3]); + + numParams = 42; + std::fill_n(params, 4, 42.4242f); + dest = FPDF_GetNamedDestByName(document(), "Next"); + EXPECT_TRUE(dest); + EXPECT_EQ(static_cast(PDFDEST_VIEW_FIT), + FPDFDest_GetView(document(), dest, &numParams, params)); + EXPECT_EQ(0U, numParams); + EXPECT_FLOAT_EQ(42.4242f, params[0]); + + numParams = 42; + std::fill_n(params, 4, 42.4242f); + dest = FPDF_GetNamedDestByName(document(), "FirstAlternate"); + EXPECT_TRUE(dest); + EXPECT_EQ(static_cast(PDFDEST_VIEW_XYZ), + FPDFDest_GetView(document(), dest, &numParams, params)); + EXPECT_EQ(3U, numParams); + EXPECT_FLOAT_EQ(200, params[0]); + EXPECT_FLOAT_EQ(400, params[1]); + EXPECT_FLOAT_EQ(800, params[2]); + EXPECT_FLOAT_EQ(42.4242f, params[3]); + + numParams = 42; + std::fill_n(params, 4, 42.4242f); + dest = FPDF_GetNamedDestByName(document(), "LastAlternate"); + EXPECT_TRUE(dest); + EXPECT_EQ(static_cast(PDFDEST_VIEW_XYZ), + FPDFDest_GetView(document(), dest, &numParams, params)); + EXPECT_EQ(3U, numParams); + EXPECT_FLOAT_EQ(0, params[0]); + EXPECT_FLOAT_EQ(0, params[1]); + EXPECT_FLOAT_EQ(-200, params[2]); + EXPECT_FLOAT_EQ(42.4242f, params[3]); +} + TEST_F(FPDFDocEmbeddertest, DestGetLocationInPage) { EXPECT_TRUE(OpenDocument("named_dests.pdf")); diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c index de4fa1c564..199c383ae5 100644 --- a/fpdfsdk/fpdfview_c_api_test.c +++ b/fpdfsdk/fpdfview_c_api_test.c @@ -107,6 +107,7 @@ int CheckPDFiumCApi() { CHK(FPDFAction_GetURIPath); CHK(FPDFDest_GetPageIndex); CHK(FPDFDest_GetLocationInPage); + CHK(FPDFDest_GetView); CHK(FPDFLink_GetLinkAtPoint); CHK(FPDFLink_GetLinkZOrderAtPoint); CHK(FPDFLink_GetDest); -- cgit v1.2.3