Skip to content

Commit 1bdc717

Browse files
committed
Add support for Caret annotation.
1 parent df5e3c7 commit 1bdc717

18 files changed

+316
-165
lines changed

pkg/api/test/annotation_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ var textAnn model.AnnotationRenderer = model.NewTextAnnotation(
4040
nil, // ca
4141
"", // rc
4242
"", // subject
43+
0, // borderRadX
44+
0, // borderRadY
45+
2, // borderWidth
4346
false, // displayOpen
4447
"Comment") // name
4548

@@ -55,6 +58,9 @@ var textAnnCJK model.AnnotationRenderer = model.NewTextAnnotation(
5558
nil, // ca
5659
"RC", // rc
5760
"", // subject
61+
0, // borderRadX
62+
0, // borderRadY
63+
2, // borderWidth
5864
true, // displayOpen
5965
"Comment") // name
6066

@@ -703,6 +709,9 @@ func TestPopupAnnotation(t *testing.T) {
703709
"", // modDate
704710
0, // f
705711
&color.Green, // col
712+
0, // borderRadX
713+
0, // borderRadY
714+
2, // borderWidth
706715
parentIndRef, // parentIndRef,
707716
false, // displayOpen
708717
)
@@ -775,6 +784,9 @@ func TestHighlightAnnotation(t *testing.T) {
775784
"", // modDate
776785
model.AnnLocked, // f
777786
&color.Yellow, // col
787+
0, // borderRadX
788+
0, // borderRadY
789+
2, // borderWidth
778790
"Comment by Horst", // title
779791
nil, // popupIndRef
780792
nil, // ca
@@ -808,6 +820,9 @@ func TestUnderlineAnnotation(t *testing.T) {
808820
"", // modDate
809821
model.AnnLocked, // f
810822
&color.Yellow, // col
823+
0, // borderRadX
824+
0, // borderRadY
825+
2, // borderWidth
811826
"Title1", // title
812827
nil, // popupIndRef
813828
nil, // ca
@@ -841,6 +856,9 @@ func TestSquigglyAnnotation(t *testing.T) {
841856
"", // modDate
842857
model.AnnLocked, // f
843858
&color.Yellow, // col
859+
0, // borderRadX
860+
0, // borderRadY
861+
2, // borderWidth
844862
"Title1", // title
845863
nil, // popupIndRef
846864
nil, // ca
@@ -874,6 +892,9 @@ func TestStrikeOutAnnotation(t *testing.T) {
874892
"", // modDate
875893
model.AnnLocked, // f
876894
&color.Yellow, // col
895+
0, // borderRadX
896+
0, // borderRadY
897+
2, // borderWidth
877898
"Title1", // title
878899
nil, // popupIndRef
879900
nil, // ca
@@ -1022,3 +1043,35 @@ func TestLineAnnotation(t *testing.T) {
10221043
t.Fatalf("%s add: %v\n", msg, err)
10231044
}
10241045
}
1046+
1047+
func TestCaretAnnotation(t *testing.T) {
1048+
msg := "TestCaretAnnotation"
1049+
1050+
// Best viewed with Adobe Reader.
1051+
1052+
inFile := filepath.Join(inDir, "test.pdf")
1053+
outFile := filepath.Join(samplesDir, "annotations", "CaretAnnotation.pdf")
1054+
1055+
caretAnn := model.NewCaretAnnotation(
1056+
*types.NewRectangle(30, 30, 110, 110), // rect
1057+
"Caret Annotation", // contents
1058+
"IDCaret", // id
1059+
"", // modDate
1060+
0, // f,
1061+
nil, // col
1062+
0, // borderRadX
1063+
0, // borderRadY
1064+
0, // borderWidth
1065+
"Title1", // title
1066+
nil, // popupIndRef
1067+
nil, // ca
1068+
"", // rc
1069+
"", // subject
1070+
types.NewRectangle(20, 20, 20, 20), // RD
1071+
true) // paragraph symbol
1072+
1073+
// Add line annotation.
1074+
if err := api.AddAnnotationsFile(inFile, outFile, nil, caretAnn, nil, false); err != nil {
1075+
t.Fatalf("%s add: %v\n", msg, err)
1076+
}
1077+
}

pkg/pdfcpu/annotation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func Annotation(xRefTable *model.XRefTable, d types.Dict) (model.AnnotationRende
178178

179179
case "Text":
180180
popupIndRef := d.IndirectRefEntry("Popup")
181-
ann = model.NewTextAnnotation(*r, contents, nm, "", f, nil, "", popupIndRef, nil, "", "", true, "")
181+
ann = model.NewTextAnnotation(*r, contents, nm, "", f, nil, "", popupIndRef, nil, "", "", 0, 0, 0, true, "")
182182

183183
case "Link":
184184
var uri string
@@ -202,12 +202,12 @@ func Annotation(xRefTable *model.XRefTable, d types.Dict) (model.AnnotationRende
202202

203203
case "Popup":
204204
parentIndRef := d.IndirectRefEntry("Parent")
205-
ann = model.NewPopupAnnotation(*r, contents, nm, "", f, nil, parentIndRef, false)
205+
ann = model.NewPopupAnnotation(*r, contents, nm, "", f, nil, 0, 0, 0, parentIndRef, false)
206206

207207
// TODO handle remaining annotation types.
208208

209209
default:
210-
ann = model.NewAnnotationForRawType(*subtype, *r, contents, nm, "", f, nil)
210+
ann = model.NewAnnotationForRawType(*subtype, *r, contents, nm, "", f, nil, 0, 0, 0)
211211

212212
}
213213

0 commit comments

Comments
 (0)