diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfannot.cpp | 24 | ||||
-rw-r--r-- | fpdfsdk/fpdfannot_embeddertest.cpp | 3 | ||||
-rw-r--r-- | fpdfsdk/fpdfview_c_api_test.c | 1 |
3 files changed, 28 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index ec748e66ec..8c62ecf311 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -241,6 +241,30 @@ FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_GetAnnot(FPDF_PAGE page, return pNewAnnot.release(); } +FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotIndex(FPDF_PAGE page, + FPDF_ANNOTATION annot) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + if (!pPage || !pPage->m_pFormDict || !pAnnot || !pAnnot->GetAnnotDict()) + return -1; + + CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayFor("Annots"); + if (!pAnnots) + return -1; + + CPDF_Dictionary* pDict = pAnnot->GetAnnotDict(); + auto it = + std::find_if(pAnnots->begin(), pAnnots->end(), + [pDict](const std::unique_ptr<CPDF_Object>& candidate) { + return candidate->GetDirect() == pDict; + }); + + if (it == pAnnots->end()) + return -1; + + return it - pAnnots->begin(); +} + FPDF_EXPORT void FPDF_CALLCONV FPDFPage_CloseAnnot(FPDF_ANNOTATION annot) { delete CPDFAnnotContextFromFPDFAnnotation(annot); } diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp index 47b71667b2..6c0cdedab5 100644 --- a/fpdfsdk/fpdfannot_embeddertest.cpp +++ b/fpdfsdk/fpdfannot_embeddertest.cpp @@ -919,11 +919,13 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) { ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); FPDF_PAGE page = FPDF_LoadPage(document(), 0); ASSERT_TRUE(page); + EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr)); // Retrieve the highlight annotation which has its popup defined. FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); + EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot)); std::unique_ptr<unsigned short, pdfium::FreeDeleter> popup_key = GetFPDFWideString(L"Popup"); ASSERT_TRUE(FPDFAnnot_HasKey(annot, popup_key.get())); @@ -934,6 +936,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) { FPDF_ANNOTATION popup = FPDFAnnot_GetLinkedAnnot(annot, popup_key.get()); ASSERT_TRUE(popup); EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup)); + EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup)); FS_RECTF rect; ASSERT_TRUE(FPDFAnnot_GetRect(popup, &rect)); EXPECT_NEAR(612.0f, rect.left, 0.001f); diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c index b42dc160da..5bad9c8e7b 100644 --- a/fpdfsdk/fpdfview_c_api_test.c +++ b/fpdfsdk/fpdfview_c_api_test.c @@ -40,6 +40,7 @@ int CheckPDFiumCApi() { CHK(FPDFPage_CreateAnnot); CHK(FPDFPage_GetAnnotCount); CHK(FPDFPage_GetAnnot); + CHK(FPDFPage_GetAnnotIndex); CHK(FPDFPage_CloseAnnot); CHK(FPDFPage_RemoveAnnot); CHK(FPDFAnnot_GetSubtype); |