From 8ce58f522e046ae3b1561d592ca7b3cd7c894731 Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Thu, 29 Jun 2017 13:40:22 -0400 Subject: 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 Reviewed-by: Lei Zhang --- fpdfsdk/fpdfannot_embeddertest.cpp | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp') 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); +} -- cgit v1.2.3