diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfedit_embeddertest.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/fpdfeditimg.cpp | 45 | ||||
-rw-r--r-- | fpdfsdk/fpdfeditimg_unittest.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/fpdfview_c_api_test.c | 1 |
4 files changed, 33 insertions, 25 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index b21be2df1b..6d928597ff 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -220,7 +220,7 @@ TEST_F(FPDFEditEmbeddertest, RasterizePDF) { // Add the bitmap to an image object and add the image object to the output // page. - FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImgeObj(temp_doc); + FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImageObj(temp_doc); EXPECT_TRUE(FPDFImageObj_SetBitmap(&temp_page, 1, temp_img, orig_bitmap)); EXPECT_TRUE(FPDFImageObj_SetMatrix(temp_img, 612, 0, 0, 792, 0, 0)); FPDFPage_InsertObject(temp_page, temp_img); diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index ad5605011c..69151d1999 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -13,22 +13,13 @@ #include "fpdfsdk/fsdk_define.h" #include "third_party/base/ptr_util.h" -DLLEXPORT FPDF_PAGEOBJECT STDCALL -FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); - if (!pDoc) - return nullptr; +namespace { - CPDF_ImageObject* pImageObj = new CPDF_ImageObject; - pImageObj->SetOwnedImage(pdfium::MakeUnique<CPDF_Image>(pDoc)); - return pImageObj; -} - -FPDF_BOOL FPDFImageObj_LoadJpegHelper(FPDF_PAGE* pages, - int nCount, - FPDF_PAGEOBJECT image_object, - FPDF_FILEACCESS* fileAccess, - bool inlineJpeg) { +bool LoadJpegHelper(FPDF_PAGE* pages, + int nCount, + FPDF_PAGEOBJECT image_object, + FPDF_FILEACCESS* fileAccess, + bool inlineJpeg) { if (!image_object || !fileAccess || !pages) return false; @@ -49,13 +40,30 @@ FPDF_BOOL FPDFImageObj_LoadJpegHelper(FPDF_PAGE* pages, return true; } +} // namespace + +DLLEXPORT FPDF_PAGEOBJECT STDCALL +FPDFPageObj_NewImageObj(FPDF_DOCUMENT document) { + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc) + return nullptr; + + CPDF_ImageObject* pImageObj = new CPDF_ImageObject; + pImageObj->SetOwnedImage(pdfium::MakeUnique<CPDF_Image>(pDoc)); + return pImageObj; +} + +DLLEXPORT FPDF_PAGEOBJECT STDCALL +FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { + return FPDFPageObj_NewImageObj(document); +} + DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount, FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess) { - return FPDFImageObj_LoadJpegHelper(pages, nCount, image_object, fileAccess, - false); + return LoadJpegHelper(pages, nCount, image_object, fileAccess, false); } DLLEXPORT FPDF_BOOL STDCALL @@ -63,8 +71,7 @@ FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages, int nCount, FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess) { - return FPDFImageObj_LoadJpegHelper(pages, nCount, image_object, fileAccess, - true); + return LoadJpegHelper(pages, nCount, image_object, fileAccess, true); } DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, diff --git a/fpdfsdk/fpdfeditimg_unittest.cpp b/fpdfsdk/fpdfeditimg_unittest.cpp index ae4af2591e..da6930caed 100644 --- a/fpdfsdk/fpdfeditimg_unittest.cpp +++ b/fpdfsdk/fpdfeditimg_unittest.cpp @@ -27,7 +27,7 @@ TEST_F(PDFEditTest, InsertObjectWithInvalidPage) { FPDFPage_InsertObject(page, nullptr); EXPECT_EQ(0, FPDFPage_CountObject(page)); - FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImgeObj(doc); + FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImageObj(doc); FPDFPage_InsertObject(nullptr, page_image); EXPECT_EQ(0, FPDFPage_CountObject(page)); @@ -35,12 +35,12 @@ TEST_F(PDFEditTest, InsertObjectWithInvalidPage) { FPDF_CloseDocument(doc); } -TEST_F(PDFEditTest, NewImgeObj) { +TEST_F(PDFEditTest, NewImageObj) { FPDF_DOCUMENT doc = FPDF_CreateNewDocument(); FPDF_PAGE page = FPDFPage_New(doc, 0, 100, 100); EXPECT_EQ(0, FPDFPage_CountObject(page)); - FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImgeObj(doc); + FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImageObj(doc); FPDFPage_InsertObject(page, page_image); EXPECT_EQ(1, FPDFPage_CountObject(page)); EXPECT_TRUE(FPDFPage_GenerateContent(page)); @@ -49,7 +49,7 @@ TEST_F(PDFEditTest, NewImgeObj) { FPDF_CloseDocument(doc); } -TEST_F(PDFEditTest, NewImgeObjGenerateContent) { +TEST_F(PDFEditTest, NewImageObjGenerateContent) { FPDF_DOCUMENT doc = FPDF_CreateNewDocument(); FPDF_PAGE page = FPDFPage_New(doc, 0, 100, 100); EXPECT_EQ(0, FPDFPage_CountObject(page)); @@ -60,7 +60,7 @@ TEST_F(PDFEditTest, NewImgeObjGenerateContent) { EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(bitmap)); EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(bitmap)); - FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImgeObj(doc); + FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImageObj(doc); ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, page_image, bitmap)); ASSERT_TRUE( FPDFImageObj_SetMatrix(page_image, kBitmapSize, 0, 0, kBitmapSize, 0, 0)); diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c index df3ef19d64..b090319d86 100644 --- a/fpdfsdk/fpdfview_c_api_test.c +++ b/fpdfsdk/fpdfview_c_api_test.c @@ -81,6 +81,7 @@ int CheckPDFiumCApi() { CHK(FPDFPageObj_HasTransparency); CHK(FPDFPageObj_Transform); CHK(FPDFPage_TransformAnnots); + CHK(FPDFPageObj_NewImageObj); CHK(FPDFPageObj_NewImgeObj); CHK(FPDFImageObj_LoadJpegFile); CHK(FPDFImageObj_LoadJpegFileInline); |