diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 14 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpage.cpp | 21 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 1 |
3 files changed, 36 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index be872ee186..e169c46b6d 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -1573,6 +1573,20 @@ TEST_F(FPDFEditEmbeddertest, TestGetTextRenderMode) { UnloadPage(page); } +TEST_F(FPDFEditEmbeddertest, TestFormGetObjects) { + EXPECT_TRUE(OpenDocument("form_object.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + ASSERT_EQ(1, FPDFPage_CountObjects(page)); + + FPDF_PAGEOBJECT form = FPDFPage_GetObject(page, 0); + EXPECT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(form)); + ASSERT_EQ(-1, FPDFFormObj_CountObjects(nullptr)); + ASSERT_EQ(2, FPDFFormObj_CountObjects(form)); + + UnloadPage(page); +} + // Tests adding text from standard font using FPDFText_LoadStandardFont. TEST_F(FPDFEditEmbeddertest, AddStandardFontText2) { // Start with a blank page diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 8a1200885a..4151de5dfd 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -751,3 +751,24 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) { pPageObj->SetDirty(true); return true; } + +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) + return -1; + + const CPDF_Form* pForm = pFormObject->form(); + if (!pForm) + return -1; + + const CPDF_PageObjectList* pObjectList = pForm->GetPageObjectList(); + if (!pObjectList) + return -1; + + return pObjectList->size(); +} diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index 53d5a77cfd..c0021fc7c0 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -126,6 +126,7 @@ int CheckPDFiumCApi() { // fpdf_edit.h CHK(FPDFFont_Close); + CHK(FPDFFormObj_CountObjects); CHK(FPDFImageObj_GetBitmap); CHK(FPDFImageObj_GetImageDataDecoded); CHK(FPDFImageObj_GetImageDataRaw); |