diff options
author | Jane Liu <janeliulwq@google.com> | 2017-08-21 14:37:53 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-22 16:43:35 +0000 |
commit | 300bb27bf4a9a84fcd3f1348a4c0076d68a305ce (patch) | |
tree | eecf41fa5ac9c130e6643afa5bb3a34b5e638489 /fpdfsdk/fpdfannot_embeddertest.cpp | |
parent | 878b27de2fa8e5bdc3b910c98846f4b43185d4aa (diff) | |
download | pdfium-300bb27bf4a9a84fcd3f1348a4c0076d68a305ce.tar.xz |
Added FPDFAnnot_GetLinkedAnnot()
Added FPDFAnnot_GetLinkedAnnot() to retrieve annotations linked to other
annotations through a specified key.
Bug=pdfium:863,pdfium:737
Change-Id: If81f41178fb4c40f6561bd392215c709722c4000
Reviewed-on: https://pdfium-review.googlesource.com/11491
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
Diffstat (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdfannot_embeddertest.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp index 4aca839226..47b71667b2 100644 --- a/fpdfsdk/fpdfannot_embeddertest.cpp +++ b/fpdfsdk/fpdfannot_embeddertest.cpp @@ -914,6 +914,51 @@ TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) { CloseSaved(); } +TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) { + // Open a file with annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // 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)); + std::unique_ptr<unsigned short, pdfium::FreeDeleter> popup_key = + GetFPDFWideString(L"Popup"); + ASSERT_TRUE(FPDFAnnot_HasKey(annot, popup_key.get())); + ASSERT_EQ(FPDF_OBJECT_REFERENCE, + FPDFAnnot_GetValueType(annot, popup_key.get())); + + // Retrieve and verify the popup of the highlight annotation. + FPDF_ANNOTATION popup = FPDFAnnot_GetLinkedAnnot(annot, popup_key.get()); + ASSERT_TRUE(popup); + EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup)); + FS_RECTF rect; + ASSERT_TRUE(FPDFAnnot_GetRect(popup, &rect)); + EXPECT_NEAR(612.0f, rect.left, 0.001f); + EXPECT_NEAR(578.792, rect.bottom, 0.001f); + + // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail, since + // "IRT" is not a key in |annot|'s dictionary. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> irt_key = + GetFPDFWideString(L"IRT"); + ASSERT_FALSE(FPDFAnnot_HasKey(annot, irt_key.get())); + EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, irt_key.get())); + + // Attempting to retrieve |annot|'s parent dictionary as an annotation would + // fail, since its parent is not an annotation. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> p_key = + GetFPDFWideString(L"P"); + ASSERT_TRUE(FPDFAnnot_HasKey(annot, p_key.get())); + EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, p_key.get())); + EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, p_key.get())); + + FPDFPage_CloseAnnot(popup); + FPDFPage_CloseAnnot(annot); + UnloadPage(page); +} + TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) { // Open file with form text fields. ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); |