diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-24 17:31:01 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-24 17:31:01 +0000 |
commit | 866d688766dbfc01d69f586bfa197d57df0d9b96 (patch) | |
tree | 4a45f43f095c80ec88f8d8202b3e4e5570563ab9 | |
parent | cd11df62b64655c24d44a65b2a76d723fc214077 (diff) | |
download | pdfium-866d688766dbfc01d69f586bfa197d57df0d9b96.tar.xz |
Implement FPDFImageObj_GetMatrix().
BUG=pdfium:1183
Change-Id: I5b1051d8924264aa12534466ee51b2718b3eca67
Reviewed-on: https://pdfium-review.googlesource.com/c/44514
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 77 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editimg.cpp | 22 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editimg_unittest.cpp | 61 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 1 | ||||
-rw-r--r-- | public/fpdf_edit.h | 27 |
5 files changed, 187 insertions, 1 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 9cd7dbf86b..ae6e444a4e 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -2963,6 +2963,83 @@ TEST_F(FPDFEditEmbeddertest, GetImageData) { UnloadPage(page); } +TEST_F(FPDFEditEmbeddertest, GetImageMatrix) { + ASSERT_TRUE(OpenDocument("embedded_images.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + ASSERT_EQ(39, FPDFPage_CountObjects(page)); + + FPDF_PAGEOBJECT obj; + double a; + double b; + double c; + double d; + double e; + double f; + + obj = FPDFPage_GetObject(page, 33); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(obj, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(53.0, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(43.0, d); + EXPECT_DOUBLE_EQ(72.0, e); + EXPECT_DOUBLE_EQ(646.510009765625, f); + + obj = FPDFPage_GetObject(page, 34); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(obj, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(70.0, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(51.0, d); + EXPECT_DOUBLE_EQ(216.0, e); + EXPECT_DOUBLE_EQ(646.510009765625, f); + + obj = FPDFPage_GetObject(page, 35); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(obj, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(69.0, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(51.0, d); + EXPECT_DOUBLE_EQ(360.0, e); + EXPECT_DOUBLE_EQ(646.510009765625, f); + + obj = FPDFPage_GetObject(page, 36); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(obj, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(59.0, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(45.0, d); + EXPECT_DOUBLE_EQ(72.0, e); + EXPECT_DOUBLE_EQ(553.510009765625, f); + + obj = FPDFPage_GetObject(page, 37); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(obj, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(55.94000244140625, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(46.950000762939453, d); + EXPECT_DOUBLE_EQ(216.0, e); + EXPECT_DOUBLE_EQ(552.510009765625, f); + + obj = FPDFPage_GetObject(page, 38); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(obj, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(70.528999328613281, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(43.149997711181641, d); + EXPECT_DOUBLE_EQ(360.0, e); + EXPECT_DOUBLE_EQ(553.3599853515625, f); + + UnloadPage(page); +} + TEST_F(FPDFEditEmbeddertest, DestroyPageObject) { FPDF_PAGEOBJECT rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20); ASSERT_TRUE(rect); diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp index af4d125db0..21ed434d7f 100644 --- a/fpdfsdk/fpdf_editimg.cpp +++ b/fpdfsdk/fpdf_editimg.cpp @@ -118,6 +118,28 @@ FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages, } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFImageObj_GetMatrix(FPDF_PAGEOBJECT image_object, + double* a, + double* b, + double* c, + double* d, + double* e, + double* f) { + CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object); + if (!pImgObj || !a || !b || !c || !d || !e || !f) + return false; + + const CFX_Matrix& matrix = pImgObj->matrix(); + *a = matrix.a; + *b = matrix.b; + *c = matrix.c; + *d = matrix.d; + *e = matrix.e; + *f = matrix.f; + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, double a, double b, diff --git a/fpdfsdk/fpdf_editimg_unittest.cpp b/fpdfsdk/fpdf_editimg_unittest.cpp index 48bd7f146b..16e464d549 100644 --- a/fpdfsdk/fpdf_editimg_unittest.cpp +++ b/fpdfsdk/fpdf_editimg_unittest.cpp @@ -69,3 +69,64 @@ TEST_F(PDFEditImgTest, NewImageObjGenerateContent) { FPDF_ClosePage(page); FPDF_CloseDocument(doc); } + +TEST_F(PDFEditImgTest, GetSetImageMatrix) { + FPDF_DOCUMENT doc = FPDF_CreateNewDocument(); + FPDF_PAGEOBJECT image = FPDFPageObj_NewImageObj(doc); + + double a; + double b; + double c; + double d; + double e; + double f; + EXPECT_FALSE(FPDFImageObj_GetMatrix(nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(nullptr, &a, nullptr, nullptr, nullptr, + nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(nullptr, &a, &b, nullptr, nullptr, + nullptr, nullptr)); + EXPECT_FALSE( + FPDFImageObj_GetMatrix(nullptr, &a, &b, &c, nullptr, nullptr, nullptr)); + EXPECT_FALSE( + FPDFImageObj_GetMatrix(nullptr, &a, &b, &c, nullptr, nullptr, nullptr)); + EXPECT_FALSE( + FPDFImageObj_GetMatrix(nullptr, &a, &b, &c, &d, nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(nullptr, &a, &b, &c, &d, &e, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(nullptr, &a, &b, &c, &d, &e, &f)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(nullptr, &a, nullptr, &c, &d, &e, &f)); + + EXPECT_FALSE(FPDFImageObj_GetMatrix(image, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(image, &a, nullptr, nullptr, nullptr, + nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(image, &a, &b, nullptr, nullptr, nullptr, + nullptr)); + EXPECT_FALSE( + FPDFImageObj_GetMatrix(image, &a, &b, &c, nullptr, nullptr, nullptr)); + EXPECT_FALSE( + FPDFImageObj_GetMatrix(image, &a, &b, &c, nullptr, nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(image, &a, &b, &c, &d, nullptr, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(image, &a, &b, &c, &d, &e, nullptr)); + EXPECT_FALSE(FPDFImageObj_GetMatrix(image, &a, nullptr, &c, &d, &e, &f)); + + EXPECT_TRUE(FPDFImageObj_GetMatrix(image, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(1.0, a); + EXPECT_DOUBLE_EQ(0.0, b); + EXPECT_DOUBLE_EQ(0.0, c); + EXPECT_DOUBLE_EQ(1.0, d); + EXPECT_DOUBLE_EQ(0.0, e); + EXPECT_DOUBLE_EQ(0.0, f); + + EXPECT_TRUE(FPDFImageObj_SetMatrix(image, 1, 2, 3, 4, 5, 6)); + EXPECT_TRUE(FPDFImageObj_GetMatrix(image, &a, &b, &c, &d, &e, &f)); + EXPECT_DOUBLE_EQ(1.0, a); + EXPECT_DOUBLE_EQ(2.0, b); + EXPECT_DOUBLE_EQ(3.0, c); + EXPECT_DOUBLE_EQ(4.0, d); + EXPECT_DOUBLE_EQ(5.0, e); + EXPECT_DOUBLE_EQ(6.0, f); + + FPDFPageObj_Destroy(image); + FPDF_CloseDocument(doc); +} diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index f1a509b3fc..4b52d24247 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -134,6 +134,7 @@ int CheckPDFiumCApi() { CHK(FPDFImageObj_GetImageFilter); CHK(FPDFImageObj_GetImageFilterCount); CHK(FPDFImageObj_GetImageMetadata); + CHK(FPDFImageObj_GetMatrix); CHK(FPDFImageObj_LoadJpegFile); CHK(FPDFImageObj_LoadJpegFileInline); CHK(FPDFImageObj_SetBitmap); diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h index 42c654c3de..5d654ba305 100644 --- a/public/fpdf_edit.h +++ b/public/fpdf_edit.h @@ -565,6 +565,31 @@ FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages, FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess); +// Experimental API. +// Get the transform matrix of an image object. +// +// image_object - handle to an image object. +// a - matrix value. +// b - matrix value. +// c - matrix value. +// d - matrix value. +// e - matrix value. +// f - matrix value. +// +// The matrix is composed as: +// |a c e| +// |b d f| +// and used to scale, rotate, shear and translate the image. +// +// Returns TRUE on success. +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_GetMatrix(FPDF_PAGEOBJECT path, + double* a, + double* b, + double* c, + double* d, + double* e, + double* f); + // Set the transform matrix of |image_object|. // // image_object - handle to an image object. @@ -578,7 +603,7 @@ FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages, // The matrix is composed as: // |a c e| // |b d f| -// and can be used to scale, rotate, shear and translate the |page| annotations. +// and can be used to scale, rotate, shear and translate the |image_object|. // // Returns TRUE on success. FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |