/
annotation.go
128 lines (110 loc) · 2.78 KB
/
annotation.go
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package hpdf
/*
#cgo LDFLAGS: -lhpdf -lpng -lz
#include "hpdf.h"
*/
import "C"
import (
"unsafe"
)
func (page *Page) CreateTextAnnot(
rect *Rect, text string, encoder *Encoder,
) (*TextAnnotation, error) {
ctext := C.CString(text)
var cencoder C.HPDF_Encoder = nil
if encoder != nil {
cencoder = encoder.encoder
}
annotation := C.HPDF_Page_CreateTextAnnot(
page.page, rect.toHpdf(), ctext, cencoder,
)
C.free(unsafe.Pointer(ctext))
if annotation != nil {
return &TextAnnotation{Annotation{annotation, page.pdf}}, nil
} else {
return nil, page.pdf.GetLastError()
}
}
func (page *Page) CreateLinkAnnot(
rect *Rect, destination *Destination,
) (*LinkAnnotation, error) {
annotation := C.HPDF_Page_CreateLinkAnnot(
page.page, rect.toHpdf(), destination.destination,
)
if annotation != nil {
return &LinkAnnotation{Annotation{annotation, page.pdf}}, nil
} else {
return nil, page.pdf.GetLastError()
}
}
func (page *Page) CreateURILinkAnnot(
rect *Rect, uri string,
) (*URILinkAnnotation, error) {
curi := C.CString(uri)
annotation := C.HPDF_Page_CreateURILinkAnnot(
page.page, rect.toHpdf(), curi,
)
C.free(unsafe.Pointer(curi))
if annotation != nil {
return &URILinkAnnotation{Annotation{annotation, page.pdf}}, nil
} else {
return nil, page.pdf.GetLastError()
}
}
type Annotation struct {
annotation C.HPDF_Annotation
pdf *PDF
}
func (annotation *Annotation) SetBorderStyle(
subtype BSSubtype, width float32, dashOn, dashOff, dashPhase uint16,
) error {
C.HPDF_Annotation_SetBorderStyle(
annotation.annotation,
C.HPDF_BSSubtype(subtype),
C.HPDF_REAL(width),
C.HPDF_UINT16(dashOn), C.HPDF_UINT16(dashOff), C.HPDF_UINT16(dashPhase),
)
return annotation.pdf.GetLastError()
}
type TextAnnotation struct {
Annotation
}
func (annotation *TextAnnotation) SetIcon(icon AnnotIcon) error {
C.HPDF_TextAnnot_SetIcon(
annotation.annotation, C.HPDF_AnnotIcon(icon),
)
return annotation.pdf.GetLastError()
}
func (annotation *TextAnnotation) SetOpened(opened bool) error {
var copend C.HPDF_BOOL = C.HPDF_FALSE
if opened {
copend = C.HPDF_TRUE
}
C.HPDF_TextAnnot_SetOpened(
annotation.annotation, copend,
)
return annotation.pdf.GetLastError()
}
type LinkAnnotation struct {
Annotation
}
func (annotation *LinkAnnotation) SetHighlightMode(
annotHightlightMode AnnotHighlightMode,
) error {
C.HPDF_LinkAnnot_SetHighlightMode(
annotation.annotation, C.HPDF_AnnotHighlightMode(annotHightlightMode),
)
return annotation.pdf.GetLastError()
}
func (annotation *LinkAnnotation) SetBorderStyle(
width float32, dashOn, dashOff uint16,
) error {
C.HPDF_LinkAnnot_SetBorderStyle(
annotation.annotation,
C.HPDF_REAL(width), C.HPDF_UINT16(dashOn), C.HPDF_UINT16(dashOff),
)
return annotation.pdf.GetLastError()
}
type URILinkAnnotation struct {
Annotation
}