-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathannotations.go
More file actions
64 lines (54 loc) · 1.34 KB
/
Copy pathannotations.go
File metadata and controls
64 lines (54 loc) · 1.34 KB
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
package pdf
import "io"
type null struct{}
func (n null) write(w io.Writer) {
_, _ = w.Write([]byte("null "))
}
type linkAnnotation struct {
dictionaryObject
targetName string
}
func newLinkAnnotation(seq, gen int, rect rectangle) *linkAnnotation {
a := new(linkAnnotation)
a.dictionaryObject.init(seq, gen)
a.dict["Type"] = name("Annot")
a.dict["Subtype"] = name("Link")
a.dict["Rect"] = &rect
a.dict["Border"] = array{integer(0), integer(0), integer(0)}
return a
}
func (a *linkAnnotation) setDestination(page *page, x, y float64) {
delete(a.dict, "Dest")
// Use an explicit GoTo action rather than a bare /Dest entry because it has
// been more consistently honored across Preview, Chromium viewers, and PDF.js.
a.dict["A"] = dictionary{
"S": name("GoTo"),
"D": destinationArray(page, x, y),
}
a.targetName = ""
}
func (a *linkAnnotation) setTarget(name string) {
delete(a.dict, "A")
delete(a.dict, "Dest")
a.targetName = name
}
func (a *linkAnnotation) setURI(uri string) {
delete(a.dict, "Dest")
a.dict["A"] = dictionary{
"S": name("URI"),
"URI": str(uri),
}
a.targetName = ""
}
func (a *linkAnnotation) setStructParent(key int) {
a.dict["StructParent"] = integer(key)
}
func destinationArray(page *page, x, y float64) array {
return array{
&indirectObjectRef{page},
name("XYZ"),
number{x},
number{y},
null{},
}
}