Add function to get FPDF_ANNOTATION from FPDF_LINK

This change enables us to get FPDF_ANNOTATION from an FPDF_LINK. It is
required to use FPDFPage_GetAnnotIndex() for FPDF_LINK also. The CL adds
a function FPDFLink_GetAnnot() for the conversion.

Bug: pdfium:1542

Change-Id: I77cd4949f5aa01528bea08f355235063d68659b2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70610
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp
index a17ec82..e85e530 100644
--- a/fpdfsdk/fpdf_doc.cpp
+++ b/fpdfsdk/fpdf_doc.cpp
@@ -10,6 +10,7 @@
 #include <set>
 #include <utility>
 
+#include "core/fpdfapi/page/cpdf_annotcontext.h"
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -357,6 +358,20 @@
   return false;
 }
 
+FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV
+FPDFLink_GetAnnot(FPDF_PAGE page, FPDF_LINK link_annot) {
+  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+  CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot);
+  if (!pPage || !pAnnotDict)
+    return nullptr;
+
+  auto pAnnotContext = std::make_unique<CPDF_AnnotContext>(
+      pAnnotDict, IPDFPageFromFPDFPage(page));
+
+  // Caller takes the ownership of the object.
+  return FPDFAnnotationFromCPDFAnnotContext(pAnnotContext.release());
+}
+
 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot,
                                                           FS_RECTF* rect) {
   if (!link_annot || !rect)