Change FPDFPage_TransFormWithClip() to take const pointers.
In-params should be const. Also add some basic tests.
Change-Id: Ie0ab72270430e094087981b7443c32a97e84ccfa
Reviewed-on: https://pdfium-review.googlesource.com/c/47533
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 0a406cf..7b63e1a 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -158,8 +158,8 @@
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPage_TransFormWithClip(FPDF_PAGE page,
- FS_MATRIX* matrix,
- FS_RECTF* clipRect) {
+ const FS_MATRIX* matrix,
+ const FS_RECTF* clipRect) {
if (!matrix && !clipRect)
return false;
diff --git a/fpdfsdk/fpdf_transformpage_embeddertest.cpp b/fpdfsdk/fpdf_transformpage_embeddertest.cpp
index 8fa3370..2619747 100644
--- a/fpdfsdk/fpdf_transformpage_embeddertest.cpp
+++ b/fpdfsdk/fpdf_transformpage_embeddertest.cpp
@@ -208,3 +208,24 @@
FPDF_DestroyClipPath(clip);
UnloadPage(page);
}
+
+TEST_F(FPDFTransformEmbedderTest, TransFormWithClip) {
+ const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0};
+ const FS_RECTF clip_rect = {0.0f, 0.0f, 20.0f, 10.0f};
+
+ ASSERT_TRUE(OpenDocument("hello_world.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, nullptr, nullptr));
+ EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, &half_matrix, nullptr));
+ EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, nullptr, &clip_rect));
+ EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, &half_matrix, &clip_rect));
+ EXPECT_FALSE(FPDFPage_TransFormWithClip(page, nullptr, nullptr));
+ EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, nullptr));
+ EXPECT_TRUE(FPDFPage_TransFormWithClip(page, nullptr, &clip_rect));
+ EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, &clip_rect));
+
+ UnloadPage(page);
+}
diff --git a/public/fpdf_transformpage.h b/public/fpdf_transformpage.h
index 899e5c6..a2eb6b0 100644
--- a/public/fpdf_transformpage.h
+++ b/public/fpdf_transformpage.h
@@ -196,8 +196,8 @@
*/
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPage_TransFormWithClip(FPDF_PAGE page,
- FS_MATRIX* matrix,
- FS_RECTF* clipRect);
+ const FS_MATRIX* matrix,
+ const FS_RECTF* clipRect);
/**
* Transform (scale, rotate, shear, move) the clip path of page object.