diff options
author | Lei Zhang <thestig@chromium.org> | 2018-05-08 19:20:57 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-08 19:20:57 +0000 |
commit | 9c6204fc6c23ab35ec234781df182da570f6faef (patch) | |
tree | 14170cb0685189648b99d6ca786029382d3384f9 | |
parent | 5de481e71bcde25d31452b23a017bb783163a204 (diff) | |
download | pdfium-9c6204fc6c23ab35ec234781df182da570f6faef.tar.xz |
Add APIs to work with a FPDF_PAGERANGE.
After getting a FPDF_PAGERANGE from FPDF_VIEWERREF_GetPrintPageRange(),
one can now use FPDF_VIEWERREF_GetPrintPageRangeCount() to get the
number of elements in the FPDF_PAGERANGE. One can then use
FPDF_VIEWERREF_GetPrintPageRangeElement() to read the elements.
Change-Id: I33eeff9026d01991ae1424e05b67f163245a35f9
Reviewed-on: https://pdfium-review.googlesource.com/32173
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fpdfsdk/fpdf_view.cpp | 15 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 2 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_embeddertest.cpp | 9 | ||||
-rw-r--r-- | public/fpdfview.h | 24 |
4 files changed, 50 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index f5eea66125..22cb62ea6e 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -1003,6 +1003,21 @@ FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { return FPDFPageRangeFromCPDFArray(viewRef.PrintPageRange()); } +FPDF_EXPORT size_t FPDF_CALLCONV +FPDF_VIEWERREF_GetPrintPageRangeCount(FPDF_PAGERANGE pagerange) { + const CPDF_Array* pArray = CPDFArrayFromFPDFPageRange(pagerange); + return pArray ? pArray->GetCount() : 0; +} + +FPDF_EXPORT int FPDF_CALLCONV +FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange, + size_t index) { + const CPDF_Array* pArray = CPDFArrayFromFPDFPageRange(pagerange); + if (!pArray || index >= pArray->GetCount()) + return -1; + return pArray->GetIntegerAt(index); +} + FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index 792acbe439..782d35d702 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -363,6 +363,8 @@ int CheckPDFiumCApi() { CHK(FPDF_VIEWERREF_GetPrintScaling); CHK(FPDF_VIEWERREF_GetNumCopies); CHK(FPDF_VIEWERREF_GetPrintPageRange); + CHK(FPDF_VIEWERREF_GetPrintPageRangeCount); + CHK(FPDF_VIEWERREF_GetPrintPageRangeElement); CHK(FPDF_VIEWERREF_GetDuplex); CHK(FPDF_VIEWERREF_GetName); CHK(FPDF_CountNamedDests); diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 9ba406a41c..580ba76e31 100644 --- a/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/fpdfsdk/fpdf_view_embeddertest.cpp @@ -136,6 +136,9 @@ TEST_F(FPDFViewEmbeddertest, ViewerRefDummy) { FPDF_PAGERANGE page_range = FPDF_VIEWERREF_GetPrintPageRange(document()); EXPECT_FALSE(page_range); + EXPECT_EQ(0U, FPDF_VIEWERREF_GetPrintPageRangeCount(page_range)); + EXPECT_EQ(-1, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 0)); + EXPECT_EQ(-1, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 1)); } TEST_F(FPDFViewEmbeddertest, ViewerRef) { @@ -178,6 +181,12 @@ TEST_F(FPDFViewEmbeddertest, ViewerRef) { FPDF_PAGERANGE page_range = FPDF_VIEWERREF_GetPrintPageRange(document()); EXPECT_TRUE(page_range); + EXPECT_EQ(4U, FPDF_VIEWERREF_GetPrintPageRangeCount(page_range)); + EXPECT_EQ(0, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 0)); + EXPECT_EQ(2, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 1)); + EXPECT_EQ(4, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 2)); + EXPECT_EQ(4, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 3)); + EXPECT_EQ(-1, FPDF_VIEWERREF_GetPrintPageRangeElement(page_range, 4)); } TEST_F(FPDFViewEmbeddertest, NamedDests) { diff --git a/public/fpdfview.h b/public/fpdfview.h index f8d6026292..7758facc39 100644 --- a/public/fpdfview.h +++ b/public/fpdfview.h @@ -10,6 +10,8 @@ #ifndef PUBLIC_FPDFVIEW_H_ #define PUBLIC_FPDFVIEW_H_ +#include <stddef.h> + #if defined(_WIN32) && !defined(__WINDOWS__) #include <windows.h> #endif @@ -1014,6 +1016,28 @@ FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document); FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document); +// Function: FPDF_VIEWERREF_GetPrintPageRangeCount +// Returns the number of elements in a FPDF_PAGERANGE. +// Experimental API. +// Parameters: +// pagerange - Handle to the page range. +// Return value: +// The number of elements in the page range. Returns 0 on error. +FPDF_EXPORT size_t FPDF_CALLCONV +FPDF_VIEWERREF_GetPrintPageRangeCount(FPDF_PAGERANGE pagerange); + +// Function: FPDF_VIEWERREF_GetPrintPageRangeElement +// Returns an element from a FPDF_PAGERANGE. +// Experimental API. +// Parameters: +// pagerange - Handle to the page range. +// index - Index of the element. +// Return value: +// The value of the element in the page range at a given index. +// Returns -1 on error. +FPDF_EXPORT int FPDF_CALLCONV +FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange, size_t index); + // Function: FPDF_VIEWERREF_GetDuplex // Returns the paper handling option to be used when printing from // the print dialog. |