Add experimental FPDFAnnot_SetBorder() API.
Compliments FPDFAnnot_GetBorder(). Can be used with the upcoming
FPDFAnnot_SetURI() API to create border-less links.
Change-Id: Id85c1c57ab202cc63a6e2d39773c5108105912e6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79231
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 5b40c46..338ea96 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -914,6 +914,22 @@
return true;
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetBorder(FPDF_ANNOTATION annot,
+ float horizontal_radius,
+ float vertical_radius,
+ float border_width) {
+ CPDF_Dictionary* annot_dict = GetAnnotDictFromFPDFAnnotation(annot);
+ if (!annot_dict)
+ return false;
+
+ CPDF_Array* border =
+ annot_dict->SetNewFor<CPDF_Array>(pdfium::annotation::kBorder);
+ border->AppendNew<CPDF_Number>(horizontal_radius);
+ border->AppendNew<CPDF_Number>(vertical_radius);
+ border->AppendNew<CPDF_Number>(border_width);
+ return true;
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFAnnot_GetBorder(FPDF_ANNOTATION annot,
float* horizontal_radius,
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index c7d8e65..198bbe2 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -3462,6 +3462,22 @@
float border_width;
EXPECT_FALSE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
&vertical_radius, &border_width));
+
+ // FPDFAnnot_SetBorder() positive testing.
+ EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), /*horizontal_radius=*/2.0f,
+ /*vertical_radius=*/3.5f,
+ /*border_width=*/4.0f));
+
+ EXPECT_TRUE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
+ &vertical_radius, &border_width));
+ EXPECT_FLOAT_EQ(2.0f, horizontal_radius);
+ EXPECT_FLOAT_EQ(3.5f, vertical_radius);
+ EXPECT_FLOAT_EQ(4.0f, border_width);
+
+ // FPDFAnnot_SetBorder() negative testing.
+ EXPECT_FALSE(FPDFAnnot_SetBorder(nullptr, /*horizontal_radius=*/1.0f,
+ /*vertical_radius=*/2.5f,
+ /*border_width=*/3.0f));
}
UnloadPage(page);
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 9fdbc63..bb92322 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -85,6 +85,7 @@
CHK(FPDFAnnot_RemoveObject);
CHK(FPDFAnnot_SetAP);
CHK(FPDFAnnot_SetAttachmentPoints);
+ CHK(FPDFAnnot_SetBorder);
CHK(FPDFAnnot_SetColor);
CHK(FPDFAnnot_SetFlags);
CHK(FPDFAnnot_SetFocusableSubtypes);
diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h
index 2b708af..06b1de3 100644
--- a/public/fpdf_annot.h
+++ b/public/fpdf_annot.h
@@ -453,12 +453,26 @@
FS_POINTF* end);
// Experimental API.
+// Set the characteristics of the annotation's border (rounded rectangle).
+//
+// annot - handle to an annotation
+// horizontal_radius - horizontal corner radius, in default user space units
+// vertical_radius - vertical corner radius, in default user space units
+// border_width - border width, in default user space units
+//
+// Returns true if |annot| is valid, false otherwise.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetBorder(FPDF_ANNOTATION annot,
+ float horizontal_radius,
+ float vertical_radius,
+ float border_width);
+
+// Experimental API.
// Get the characteristics of the annotation's border (rounded rectangle).
//
-// annot - handle to an annotation, as returned by e.g. FPDFPage_GetAnnot()
-// horizontal_radius - horizontal corner radius, in default user space units
-// vertical_radius - vertical corner radius, in default user space units
-// border_width - border width, in default user space units
+// annot - handle to an annotation
+// horizontal_radius - horizontal corner radius, in default user space units
+// vertical_radius - vertical corner radius, in default user space units
+// border_width - border width, in default user space units
//
// Returns true if |horizontal_radius|, |vertical_radius| and |border_width| are
// not NULL, false otherwise.