-
Notifications
You must be signed in to change notification settings - Fork 31
/
annot.go
183 lines (147 loc) · 3.2 KB
/
annot.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package poppler
// #cgo pkg-config: poppler-glib
// #include <poppler.h>
// #include <glib.h>
// #include <cairo.h>
//
// /* macro wrappings */
// gboolean wrap_POPPLER_IS_ANNOT_TEXT_MARKUP(PopplerAnnot *annot){
// return POPPLER_IS_ANNOT_TEXT_MARKUP(annot);
// }
// PopplerAnnotTextMarkup *wrap_POPPLER_ANNOT_TEXT_MARKUP(PopplerAnnot *annot) {
// return POPPLER_ANNOT_TEXT_MARKUP(annot);
// }
import "C"
import "unsafe"
//import "github.com/ungerik/go-cairo"
//import "fmt"
type Point struct {
X, Y float64
}
type Quad struct {
P1, P2, P3, P4 Point
}
type Annot struct {
am *C.struct__PopplerAnnotMapping
}
type AnnotType int
const (
AnnotUnknown AnnotType = iota
AnnotText
AnnotLink
AnnotFreeText
AnnotLine
AnnotSquare
AnnotCircle
AnnotPolygon
AnnotPolyLine
AnnotHighlight
AnnotUnderline
AnnotSquiggly
AnnotStrikeOut
AnnotStamp
AnnotCaret
AnnotInk
AnnotPopup
AnnotFileAttachment
AnnotSound
AnnotMovie
AnnotWidget
AnnotScreen
AnnotPrinterMark
AnnotTrapNet
AnnotWatermark
Annot3D
)
type AnnotFlag int
const (
AnnotFlagUnknown AnnotFlag = 1 << iota
AnnotFlagInvisible
AnnotFlagHidden
AnnotFlagPrint
AnnotFlagNoZoom
AnnotFlagNoRotate
AnnotFlagNoView
AnnotFlagReadOnly
AnnotFlagLocked
AnnotFlagToggleNoView
AnnotFlagLockedContents
)
func (a *Annot) Type() AnnotType {
t := C.poppler_annot_get_annot_type(a.am.annot)
return AnnotType(t)
}
func (a *Annot) Index() int {
i := C.poppler_annot_get_page_index(a.am.annot)
return int(i)
}
func (a *Annot) Date() string {
cText := C.poppler_annot_get_modified(a.am.annot)
return C.GoString(cText)
}
func (a *Annot) Rect() Rectangle {
var r C.PopplerRectangle
C.poppler_annot_get_rectangle(a.am.annot, &r)
rect := Rectangle{
X1: float64(r.x1),
Y1: float64(r.y1),
X2: float64(r.x2),
Y2: float64(r.y2),
}
return rect
}
func (a *Annot) Color() Color {
c := C.poppler_annot_get_color(a.am.annot)
defer C.poppler_color_free(c)
color := Color{
R: int(c.red),
G: int(c.green),
B: int(c.blue),
}
return color
}
func (a *Annot) Name() string {
cText := C.poppler_annot_get_name(a.am.annot)
return C.GoString(cText)
}
func (a *Annot) Contents() string {
cText := C.poppler_annot_get_contents(a.am.annot)
return C.GoString(cText)
}
func (a *Annot) Flags() AnnotFlag {
f := C.poppler_annot_get_flags(a.am.annot)
return AnnotFlag(f)
}
func (a *Annot) Quads() []Quad {
if C.wrap_POPPLER_IS_ANNOT_TEXT_MARKUP(a.am.annot) == C.FALSE {
return nil
}
textMarkup := C.wrap_POPPLER_ANNOT_TEXT_MARKUP(a.am.annot)
q := C.poppler_annot_text_markup_get_quadrilaterals(textMarkup)
quads := gArrayToQuads(q)
C.g_array_free(q, 1)
return quads
}
func (a *Annot) Close() {
if a.am != nil {
C.poppler_annot_mapping_free(a.am)
a.am = nil
}
}
func (a *Annot) SetColor(c Color){
pColor := C.poppler_color_new()
pColor.red = C.ushort(c.R)
pColor.green = C.ushort(c.G)
pColor.blue = C.ushort(c.B)
defer gFree(pColor)
C.poppler_annot_set_color(a.am.annot, pColor )
}
func (a *Annot) SetContents(c string){
cStr := C.CString(c)
defer C.free(unsafe.Pointer(cStr))
C.poppler_annot_set_contents(a.am.annot, cStr)
}
func (a *Annot) SetFlags(f AnnotFlag){
pFlags := C.PopplerAnnotFlag(f)
C.poppler_annot_set_flags(a.am.annot, pFlags)
}