-
Notifications
You must be signed in to change notification settings - Fork 0
/
smask_obj.go
62 lines (52 loc) · 1.07 KB
/
smask_obj.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
package gopdf
import (
"bytes"
"fmt"
)
//SMask smask
type SMask struct {
buffer bytes.Buffer
imgInfo
data []byte
//getRoot func() *GoPdf
pdfProtection *PDFProtection
}
func (s *SMask) init(funcGetRoot func() *GoPdf) {
//s.getRoot = funcGetRoot
}
func (s *SMask) setProtection(p *PDFProtection) {
s.pdfProtection = p
}
func (s *SMask) protection() *PDFProtection {
return s.pdfProtection
}
func (s *SMask) getType() string {
return "smask"
}
func (s *SMask) getObjBuff() *bytes.Buffer {
return &s.buffer
}
func (s *SMask) build(objID int) error {
buff, err := buildImgProp(s.imgInfo)
if err != nil {
return err
}
_, err = buff.WriteTo(&s.buffer)
if err != nil {
return err
}
s.buffer.WriteString(fmt.Sprintf("/Length %d\n>>\n", len(s.data))) // /Length 62303>>\n
s.buffer.WriteString("stream\n")
if s.protection() != nil {
tmp, err := rc4Cip(s.protection().objectkey(objID), s.data)
if err != nil {
return err
}
s.buffer.Write(tmp)
s.buffer.WriteString("\n")
} else {
s.buffer.Write(s.data)
}
s.buffer.WriteString("\nendstream\n")
return nil
}