Add API for removing an inklist for an ink annotation.
There is no API to remove/edit an inklist for an ink annotation.
With this API, user can edit an inklist by removing it and adding it
again with edited ink points.
This CL adds API and relevant tests for removing an inklist for an
ink annotation.
Bug: pdfium:1512
Change-Id: I62fc232928ea720c8cef36adfb81fa20c0b10773
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68613
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Shikha Walia <shwali@microsoft.com>
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 61956a6..6bb583f 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -461,6 +461,18 @@
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFAnnot_RemoveInkList(FPDF_ANNOTATION annot) {
+ if (FPDFAnnot_GetSubtype(annot) != FPDF_ANNOT_INK)
+ return false;
+
+ CPDF_Dictionary* annot_dict =
+ CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict();
+ annot_dict->RemoveFor("InkList");
+
+ return true;
+}
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFAnnot_AppendObject(FPDF_ANNOTATION annot, FPDF_PAGEOBJECT obj) {
CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot);
CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(obj);
diff --git a/fpdfsdk/fpdf_annot_unittest.cpp b/fpdfsdk/fpdf_annot_unittest.cpp
index e961541..fd4d702 100644
--- a/fpdfsdk/fpdf_annot_unittest.cpp
+++ b/fpdfsdk/fpdf_annot_unittest.cpp
@@ -219,3 +219,49 @@
EXPECT_EQ(3u, inklist->size());
EXPECT_EQ((kThirdStrokePointCount - 1) * 2, inklist->GetArrayAt(2)->size());
}
+
+TEST_F(PDFAnnotTest, RemoveInkList) {
+ ScopedFPDFDocument doc(FPDF_CreateNewDocument());
+ ASSERT_TRUE(doc);
+ ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
+ ASSERT_TRUE(page);
+
+ // Negative test: |annot| is passed as nullptr.
+ EXPECT_FALSE(FPDFAnnot_RemoveInkList(nullptr));
+
+ // Negative test: |annot| is not ink annotation.
+ // Create a new highlight annotation.
+ ScopedFPDFAnnotation highlight_annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_HIGHLIGHT));
+ ASSERT_TRUE(highlight_annot);
+ EXPECT_FALSE(FPDFAnnot_RemoveInkList(highlight_annot.get()));
+
+ // Create a new ink annotation.
+ ScopedFPDFAnnotation ink_annot(
+ FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK));
+ ASSERT_TRUE(ink_annot);
+ CPDF_AnnotContext* context =
+ CPDFAnnotContextFromFPDFAnnotation(ink_annot.get());
+ ASSERT_TRUE(context);
+ CPDF_Dictionary* annot_dict = context->GetAnnotDict();
+ ASSERT_TRUE(annot_dict);
+
+ static constexpr FS_POINTF kInkStroke[] = {{80.0f, 90.0f}, {81.0f, 91.0f},
+ {82.0f, 92.0f}, {83.0f, 93.0f},
+ {84.0f, 94.0f}, {85.0f, 95.0f}};
+ static constexpr size_t kPointCount = FX_ArraySize(kInkStroke);
+
+ // InkStroke should get added to ink annotation. Also inklist should get
+ // created.
+ EXPECT_EQ(0,
+ FPDFAnnot_AddInkStroke(ink_annot.get(), kInkStroke, kPointCount));
+
+ CPDF_Array* inklist = annot_dict->GetArrayFor("InkList");
+ ASSERT_TRUE(inklist);
+ ASSERT_EQ(1u, inklist->size());
+ EXPECT_EQ(kPointCount * 2, inklist->GetArrayAt(0)->size());
+
+ // Remove inklist.
+ EXPECT_TRUE(FPDFAnnot_RemoveInkList(ink_annot.get()));
+ EXPECT_FALSE(annot_dict->KeyExist("InkList"));
+}
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 38f302d..26b433f 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -70,6 +70,7 @@
CHK(FPDFAnnot_IsChecked);
CHK(FPDFAnnot_IsObjectSupportedSubtype);
CHK(FPDFAnnot_IsSupportedSubtype);
+ CHK(FPDFAnnot_RemoveInkList);
CHK(FPDFAnnot_RemoveObject);
CHK(FPDFAnnot_SetAP);
CHK(FPDFAnnot_SetAttachmentPoints);
diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h
index 531a97f..27f5eba 100644
--- a/public/fpdf_annot.h
+++ b/public/fpdf_annot.h
@@ -211,6 +211,17 @@
size_t point_count);
// Experimental API.
+// Removes an InkList in |annot|.
+// This API works only for ink annotations.
+//
+// annot - handle to an annotation.
+//
+// Return true on successful removal of /InkList entry from context of the
+// non-null ink |annot|. Returns false on failure.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFAnnot_RemoveInkList(FPDF_ANNOTATION annot);
+
+// Experimental API.
// Add |obj| to |annot|. |obj| must have been created by
// FPDFPageObj_CreateNew{Path|Rect}() or FPDFPageObj_New{Text|Image}Obj(), and
// will be owned by |annot|. Note that an |obj| cannot belong to more than one