Add FPDF_GetPageBoundingBox API.
This API returns the intersection of the media box and the crop box
of a page.
Bug: pdfium:973
Change-Id: I57a19ee526ea6d4cd621e1ad6019e51f69f92308
Reviewed-on: https://pdfium-review.googlesource.com/22810
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index aad2946..cec44a4 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -726,6 +726,19 @@
return pPage ? pPage->GetPageHeight() : 0.0;
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page,
+ FS_RECTF* rect) {
+ if (!rect)
+ return false;
+
+ CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+ if (!pPage)
+ return false;
+
+ FSRECTFFromCFXFloatRect(pPage->GetPageBBox(), rect);
+ return true;
+}
+
#if defined(_WIN32)
namespace {
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index ad1d8a7..53d8776 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -332,6 +332,7 @@
CHK(FPDF_LoadPage);
CHK(FPDF_GetPageWidth);
CHK(FPDF_GetPageHeight);
+ CHK(FPDF_GetPageBoundingBox);
CHK(FPDF_GetPageSizeByIndex);
#ifdef _WIN32
CHK(FPDF_RenderPage);
diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp
index 0055099..7e93574 100644
--- a/fpdfsdk/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/fpdfview_embeddertest.cpp
@@ -99,8 +99,17 @@
EXPECT_TRUE(OpenDocument("about_blank.pdf"));
FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
+
EXPECT_EQ(612.0, FPDF_GetPageWidth(page));
EXPECT_EQ(792.0, FPDF_GetPageHeight(page));
+
+ FS_RECTF rect;
+ EXPECT_TRUE(FPDF_GetPageBoundingBox(page, &rect));
+ EXPECT_EQ(0.0, rect.left);
+ EXPECT_EQ(0.0, rect.bottom);
+ EXPECT_EQ(612.0, rect.right);
+ EXPECT_EQ(792.0, rect.top);
+
UnloadPage(page);
EXPECT_EQ(nullptr, LoadPage(1));
}
diff --git a/public/fpdfview.h b/public/fpdfview.h
index 0898ec6..ffa4678 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -554,6 +554,19 @@
// One point is 1/72 inch (around 0.3528 mm)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page);
+// Experimental API.
+// Function: FPDF_GetPageBoundingBox
+// Get the bounding box of the page. This is the intersection between
+// its media box and its crop box.
+// Parameters:
+// page - Handle to the page. Returned by FPDF_LoadPage.
+// rect - Pointer to a rect to receive the page bounding box.
+// On an error, |rect| won't be filled.
+// Return value:
+// True for success.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page,
+ FS_RECTF* rect);
+
// Function: FPDF_GetPageSizeByIndex
// Get the size of the page at the given index.
// Parameters: