diff options
author | Jane Liu <janeliulwq@google.com> | 2017-06-29 13:40:22 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-29 20:11:24 +0000 |
commit | 8ce58f522e046ae3b1561d592ca7b3cd7c894731 (patch) | |
tree | 571c245639b8321dae3c3a1254e317d59ee2b8bc /fpdfsdk/fpdfannot_embeddertest.cpp | |
parent | f1eae2c37cb4bbf7a536cf251706147bbac51880 (diff) | |
download | pdfium-8ce58f522e046ae3b1561d592ca7b3cd7c894731.tar.xz |
Added FPDFAnnot_RemoveAnnot()
Added an API for removing annotation and an embedder test for it.
Bug=pdfium:737
Change-Id: I6f01625e8103078b83967a57a5c1a7a26bc0c70a
Reviewed-on: https://pdfium-review.googlesource.com/7039
Commit-Queue: Jane Liu <janeliulwq@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdfannot_embeddertest.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp index 9d9e2d365f..85fe1326bc 100644 --- a/fpdfsdk/fpdfannot_embeddertest.cpp +++ b/fpdfsdk/fpdfannot_embeddertest.cpp @@ -392,3 +392,72 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { FPDFPage_CloseAnnot(annot); UnloadPage(page); } + +TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) { + // Open a file with 3 annotations on its first page. + ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); + + // Check that the annotations have the expected rectangle coordinates. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(86.1971f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(page, 1); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(149.8127f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(page, 2); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(351.8204f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + // Check that nothing happens when attempting to remove an annotation with an + // out-of-bound index. + EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4)); + EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1)); + EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); + + // Remove the second annotation. + EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1)); + EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); + EXPECT_FALSE(FPDFPage_GetAnnot(page, 2)); + + // Save the document, closing the page and document. + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + FPDF_ClosePage(page); + + // Open the saved document. + std::string new_file = GetString(); + FPDF_FILEACCESS file_access; + memset(&file_access, 0, sizeof(file_access)); + file_access.m_FileLen = new_file.size(); + file_access.m_GetBlock = GetBlockFromString; + file_access.m_Param = &new_file; + FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); + ASSERT_TRUE(new_doc); + FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); + ASSERT_TRUE(new_page); + + // Check that the saved document has 2 annotations on the first page. + EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page)); + + // Check that the remaining 2 annotations are the original 1st and 3rd ones by + // verifying their rectangle coordinates. + annot = FPDFPage_GetAnnot(new_page, 0); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(86.1971f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(new_page, 1); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(351.8204f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + FPDF_ClosePage(new_page); + FPDF_CloseDocument(new_doc); +} |