summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfannot.cpp
diff options
context:
space:
mode:
authorJane Liu <janeliulwq@google.com>2017-08-24 12:31:10 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-28 20:13:02 +0000
commitd1ed1ce582efc877487c749924e21772e73df6a2 (patch)
tree83a13bf3423fd16de1b7c29d7004bbfac476c103 /fpdfsdk/fpdfannot.cpp
parent827f6ff220edea40252e52d128662d37a591fdb9 (diff)
downloadpdfium-d1ed1ce582efc877487c749924e21772e73df6a2.tar.xz
Added FPDFAnnot_GetAnnotIndex()
Added FPDFAnnot_GetAnnotIndex() to get the index of an annotation. This is useful if linked annotations are renedered together - then we need to know which ones in the annotation list we need to skip. Bug=pdfium:863,pdfium:737 Change-Id: I53482a15e0fd9a896b348b64d68e99f9c21da9f9 Reviewed-on: https://pdfium-review.googlesource.com/11970 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfannot.cpp')
-rw-r--r--fpdfsdk/fpdfannot.cpp24
1 files changed, 24 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);
}