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
|
package document
import (
"github.com/scrotadamus/ghligh/go-poppler"
)
type AnnotJSON struct {
Type poppler.AnnotType `json:"type,omitempty"`
Index int `json:"index,omitempty"`
Date string `json:"date,omitempty"`
Rect poppler.Rectangle `json:"rect,omitempty"`
Color poppler.Color `json:"color,omitempty"`
Name string `json:"name,omitempty"`
Contents string `json:"contents,omitempty"`
Flags poppler.AnnotFlag `json:"flags,omitempty"`
Quads []poppler.Quad `json:"quads,omitempty"`
}
func annotToJson(a poppler.Annot) (AnnotJSON) {
var aj AnnotJSON
aj.Type = a.Type()
aj.Index = a.Index()
aj.Date = a.Date()
aj.Rect = a.Rect()
aj.Color = a.Color()
aj.Name = a.Name()
aj.Contents = a.Contents()
aj.Flags = a.Flags()
aj.Quads = a.Quads()
return aj
}
func (d *GhlighDoc) jsonToAnnot(aJson AnnotJSON) *poppler.Annot {
annot, _ := d.doc.NewAnnot(poppler.AnnotHighlight, aJson.Rect, aJson.Quads)
annot.SetColor(aJson.Color)
annot.SetContents(aJson.Contents)
annot.SetFlags(aJson.Flags)
return &annot
}
func popplerAnnotsMatch(a *poppler.Annot, b *poppler.Annot) bool {
aRect := a.Rect()
bRect := b.Rect()
aQuads := a.Quads()
bQuads := b.Quads()
if aRect.X1 != bRect.X1 ||
aRect.Y1 != bRect.Y1 ||
aRect.X2 != bRect.X2 ||
aRect.Y2 != bRect.Y2 {
return false
}
if len(aQuads) != len(bQuads) {
return false
}
for i := range aQuads {
q1 := aQuads[i]
q2 := bQuads[i]
if q1.P1.X != q2.P1.X || q1.P1.Y != q2.P1.Y ||
q1.P2.X != q2.P2.X || q1.P2.Y != q2.P2.Y ||
q1.P3.X != q2.P3.X || q1.P3.Y != q2.P3.Y ||
q1.P4.X != q2.P4.X || q1.P4.Y != q2.P4.Y {
return false
}
}
return true
}
|