1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
From 30f45a6f043fc1bbd19eb4820261c45ad68cf1cc Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Fri, 4 Dec 2020 19:12:31 +0000
Subject: [PATCH] Add FPDFAnnot_GetLine() API
This is similar to FPDFAnnot_GetVertices() for polygon/polyline
annotations, but this one is for line annotations and the point list has
a fixed size of 2.
Change-Id: If910caaef8c41a9965f2ba47f87c34ea33355f99
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/76730
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
---
constants/annotation_common.h | 3 ++
fpdfsdk/fpdf_annot.cpp | 26 +++++++++++++
fpdfsdk/fpdf_annot_embeddertest.cpp | 45 ++++++++++++++++++++++
fpdfsdk/fpdf_view_c_api_test.c | 1 +
public/fpdf_annot.h | 13 +++++++
testing/resources/line_annot.in | 48 +++++++++++++++++++++++
testing/resources/line_annot.pdf | 60 +++++++++++++++++++++++++++++
7 files changed, 196 insertions(+)
create mode 100644 testing/resources/line_annot.in
create mode 100644 testing/resources/line_annot.pdf
diff --git a/constants/annotation_common.h b/constants/annotation_common.h
index be6420651..656842bb5 100644
--- a/constants/annotation_common.h
+++ b/constants/annotation_common.h
@@ -32,6 +32,9 @@ constexpr char kVertices[] = "Vertices";
// Entries for ink annotations
constexpr char kInkList[] = "InkList";
+// Entries for line annotations
+constexpr char kL[] = "L";
+
} // namespace annotation
} // namespace pdfium
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 51b4332c2..85f86e547 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -887,6 +887,32 @@ FPDFAnnot_GetInkListPath(FPDF_ANNOTATION annot,
return points_len;
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetLine(FPDF_ANNOTATION annot,
+ FS_POINTF* start,
+ FS_POINTF* end) {
+ if (!start || !end)
+ return false;
+
+ FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot);
+ if (subtype != FPDF_ANNOT_LINE)
+ return false;
+
+ CPDF_Dictionary* annot_dict = GetAnnotDictFromFPDFAnnotation(annot);
+ if (!annot_dict)
+ return false;
+
+ CPDF_Array* line = annot_dict->GetArrayFor(pdfium::annotation::kL);
+ if (!line || line->size() < 4)
+ return false;
+
+ start->x = line->GetNumberAt(0);
+ start->y = line->GetNumberAt(1);
+ end->x = line->GetNumberAt(2);
+ end->y = line->GetNumberAt(3);
+
+ return true;
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_HasKey(FPDF_ANNOTATION annot,
FPDF_BYTESTRING key) {
CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot);
diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h
index d121344f7..6c8a237e7 100644
--- a/public/fpdf_annot.h
+++ b/public/fpdf_annot.h
@@ -439,6 +439,19 @@ FPDFAnnot_GetInkListPath(FPDF_ANNOTATION annot,
FS_POINTF* buffer,
unsigned long length);
+// Experimental API.
+// Get the starting and ending coordinates of a line annotation.
+//
+// annot - handle to an annotation, as returned by e.g. FPDFPage_GetAnnot()
+// start - starting point
+// end - ending point
+//
+// Returns true if the annotation is of type line, |start| and |end| are not
+// NULL, false otherwise.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetLine(FPDF_ANNOTATION annot,
+ FS_POINTF* start,
+ FS_POINTF* end);
+
// Experimental API.
// Check if |annot|'s dictionary has |key| as a key.
//
--
2.26.2
|