diff options
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 20 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpage.cpp | 41 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 1 | ||||
-rw-r--r-- | public/fpdf_edit.h | 10 |
4 files changed, 60 insertions, 12 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 0c0776f9d7..227e5c9ef5 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -1769,6 +1769,26 @@ TEST_F(FPDFEditEmbeddertest, TestFormGetObjects) { ASSERT_EQ(-1, FPDFFormObj_CountObjects(nullptr)); ASSERT_EQ(2, FPDFFormObj_CountObjects(form)); + // FPDFFormObj_GetObject() positive testing. + FPDF_PAGEOBJECT text1 = FPDFFormObj_GetObject(form, 0); + ASSERT_TRUE(text1); + float left = 0; + float bottom = 0; + float right = 0; + float top = 0; + ASSERT_TRUE(FPDFPageObj_GetBounds(text1, &left, &bottom, &right, &top)); + ASSERT_EQ(271, static_cast<int>(top)); + + FPDF_PAGEOBJECT text2 = FPDFFormObj_GetObject(form, 1); + ASSERT_TRUE(text2); + ASSERT_TRUE(FPDFPageObj_GetBounds(text2, &left, &bottom, &right, &top)); + ASSERT_EQ(221, static_cast<int>(top)); + + // FPDFFormObj_GetObject() negative testing. + ASSERT_EQ(nullptr, FPDFFormObj_GetObject(nullptr, 0)); + ASSERT_EQ(nullptr, FPDFFormObj_GetObject(form, -1)); + ASSERT_EQ(nullptr, FPDFFormObj_GetObject(form, 2)); + UnloadPage(page); } diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index ded55b9bef..f1dbf70192 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -140,6 +140,23 @@ unsigned int GetUnsignedAlpha(float alpha) { return static_cast<unsigned int>(alpha * 255.f + 0.5f); } +const CPDF_PageObjectList* CPDFPageObjListFromFPDFFormObject( + FPDF_PAGEOBJECT page_object) { + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + if (!pPageObj) + return nullptr; + + CPDF_FormObject* pFormObject = pPageObj->AsForm(); + if (!pFormObject) + return nullptr; + + const CPDF_Form* pForm = pFormObject->form(); + if (!pForm) + return nullptr; + + return pForm->GetPageObjectList(); +} + } // namespace FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { @@ -812,21 +829,21 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) { FPDF_EXPORT int FPDF_CALLCONV FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) { - auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); - if (!pPageObj) - return -1; - - CPDF_FormObject* pFormObject = pPageObj->AsForm(); - if (!pFormObject) + const CPDF_PageObjectList* pObjectList = + CPDFPageObjListFromFPDFFormObject(page_object); + if (!pObjectList) return -1; - const CPDF_Form* pForm = pFormObject->form(); - if (!pForm) - return -1; + return pObjectList->size(); +} - const CPDF_PageObjectList* pObjectList = pForm->GetPageObjectList(); +FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV +FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index) { + const CPDF_PageObjectList* pObjectList = + CPDFPageObjListFromFPDFFormObject(form_object); if (!pObjectList) - return -1; + return nullptr; - return pObjectList->size(); + return FPDFPageObjectFromCPDFPageObject( + pObjectList->GetPageObjectByIndex(index)); } diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index d4c812f7a5..114a6b0024 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -127,6 +127,7 @@ int CheckPDFiumCApi() { // fpdf_edit.h CHK(FPDFFont_Close); CHK(FPDFFormObj_CountObjects); + CHK(FPDFFormObj_GetObject); CHK(FPDFImageObj_GetBitmap); CHK(FPDFImageObj_GetImageDataDecoded); CHK(FPDFImageObj_GetImageDataRaw); diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h index fdd8c97d05..b97a7adbd9 100644 --- a/public/fpdf_edit.h +++ b/public/fpdf_edit.h @@ -1265,6 +1265,16 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text); FPDF_EXPORT int FPDF_CALLCONV FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object); +// Experimental API. +// Get page object in |form_object| at |index|. +// +// form_object - handle to a form object. +// index - the 0-based index of a page object. +// +// Returns the handle to the page object, or NULL on error. +FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV +FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus |