summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-03-26 21:46:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-26 21:46:00 +0000
commit5098b252848734ac69e0851f7bd116d93311a57e (patch)
tree8f221ab1bf47c9b624974907b8ee74f92a528cb4 /fpdfsdk
parentac3e57eee888904d39a07b58ca7d57f8f8b0e51a (diff)
downloadpdfium-5098b252848734ac69e0851f7bd116d93311a57e.tar.xz
Reland "Add FPDFAnnot_CountAttachmentPoints"
This reverts commit ac3e57eee888904d39a07b58ca7d57f8f8b0e51a. Reason for revert: Tried to reproduce on win bot, 10/10 passed. Relanding, hopefully it was just a hiccup. Original change's description: > Revert "Add FPDFAnnot_CountAttachmentPoints" > > This reverts commit ca28cb636331de447125de476decbec333fe613b. > > Reason for revert: broke Windows embeddertests > > https://build.chromium.org/p/client.pdfium/builders/windows/builds/4622 > > I got it when landing my CL, which is unrelated. Since this CL passed the bot, I'm guessing it's a flaky test? > > Original change's description: > > Add FPDFAnnot_CountAttachmentPoints > > > > This CL adds a function to the API that returns the number of quadpoint > > sets. > > > > Change-Id: I999bc567a4c98f6c32e87810e7ecfbb634c7b677 > > Reviewed-on: https://pdfium-review.googlesource.com/29130 > > Reviewed-by: Lei Zhang <thestig@chromium.org> > > Commit-Queue: Lei Zhang <thestig@chromium.org> > > TBR=thestig@chromium.org,dsinclair@chromium.org,ralf.sippl@gmail.com > > Change-Id: Id96b5d4e18be2184c9d24f77bda7499aad0ed211 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://pdfium-review.googlesource.com/29190 > Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> > Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> TBR=thestig@chromium.org,dsinclair@chromium.org,ralf.sippl@gmail.com,hnakashima@chromium.org Change-Id: Ie586552b355ef1f040ae162a539a6b9ebf50d125 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://pdfium-review.googlesource.com/29210 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfannot.cpp15
-rw-r--r--fpdfsdk/fpdfannot_embeddertest.cpp21
-rw-r--r--fpdfsdk/fpdfview_c_api_test.c1
3 files changed, 34 insertions, 3 deletions
diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp
index b5dccaade1..c52807148e 100644
--- a/fpdfsdk/fpdfannot.cpp
+++ b/fpdfsdk/fpdfannot.cpp
@@ -583,7 +583,7 @@ FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot) {
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot,
const FS_QUADPOINTSF* quad_points) {
- if (!annot || !quad_points || !FPDFAnnot_HasAttachmentPoints(annot))
+ if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points)
return false;
CPDF_Dictionary* pAnnotDict =
@@ -621,10 +621,21 @@ FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot,
return true;
}
+FPDF_EXPORT size_t FPDF_CALLCONV
+FPDFAnnot_CountAttachmentPoints(FPDF_ANNOTATION annot) {
+ if (!FPDFAnnot_HasAttachmentPoints(annot))
+ return 0;
+
+ CPDF_Dictionary* pAnnotDict =
+ CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict();
+ const CPDF_Array* pArray = GetQuadPointsArrayFromDictionary(pAnnotDict);
+ return pArray ? pArray->GetCount() / 8 : 0;
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot,
FS_QUADPOINTSF* quad_points) {
- if (!annot || !quad_points || !FPDFAnnot_HasAttachmentPoints(annot))
+ if (!FPDFAnnot_HasAttachmentPoints(annot) || !quad_points)
return false;
return GetQuadPointsFromDictionary(
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp
index b96460a395..552398c41f 100644
--- a/fpdfsdk/fpdfannot_embeddertest.cpp
+++ b/fpdfsdk/fpdfannot_embeddertest.cpp
@@ -47,7 +47,7 @@ TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) {
TEST_F(FPDFAnnotEmbeddertest, RenderMultilineMarkupAnnotWithoutAP) {
const char md5_hash[] = "76512832d88017668d9acc7aacd13dae";
- // Open a file with two multiline markup annotations.
+ // Open a file with multiline markup annotations.
ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
@@ -471,6 +471,25 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
UnloadPage(page);
}
+TEST_F(FPDFAnnotEmbeddertest, CountAttachmentPoints) {
+ // Open a file with multiline markup annotations.
+ ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ {
+ std::unique_ptr<void, FPDFAnnotationDeleter> annot(
+ FPDFPage_GetAnnot(page, 0));
+ ASSERT_TRUE(annot);
+
+ // This is a three line annotation.
+ EXPECT_EQ(3u, FPDFAnnot_CountAttachmentPoints(annot.get()));
+ }
+ UnloadPage(page);
+
+ // null annotation should return 0
+ EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(nullptr));
+}
+
TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
// Open a file with 3 annotations on its first page.
ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index 2a0b230ca5..201fd90669 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -55,6 +55,7 @@ int CheckPDFiumCApi() {
CHK(FPDFAnnot_GetColor);
CHK(FPDFAnnot_HasAttachmentPoints);
CHK(FPDFAnnot_SetAttachmentPoints);
+ CHK(FPDFAnnot_CountAttachmentPoints);
CHK(FPDFAnnot_GetAttachmentPoints);
CHK(FPDFAnnot_SetRect);
CHK(FPDFAnnot_GetRect);