forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transparency_xobject_group.go
92 lines (74 loc) · 2.11 KB
/
transparency_xobject_group.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
package gopdf
import (
"fmt"
"io"
)
type TransparencyXObjectGroup struct {
Index int
BBox [4]float64
Matrix [6]float64
ExtGStateIndexes []int
XObjects []cacheContentImage
getRoot func() *GoPdf
pdfProtection *PDFProtection
}
type TransparencyXObjectGroupOptions struct {
Protection *PDFProtection
ExtGStateIndexes []int
BBox [4]float64
XObjects []cacheContentImage
}
func GetCachedTransparencyXObjectGroup(opts TransparencyXObjectGroupOptions, gp *GoPdf) (TransparencyXObjectGroup, error) {
group := TransparencyXObjectGroup{
BBox: opts.BBox,
XObjects: opts.XObjects,
pdfProtection: opts.Protection,
ExtGStateIndexes: opts.ExtGStateIndexes,
}
group.Index = gp.addObj(group)
group.init(func() *GoPdf {
return gp
})
return group, nil
}
func (s TransparencyXObjectGroup) init(funcGetRoot func() *GoPdf) {
s.getRoot = funcGetRoot
}
func (s *TransparencyXObjectGroup) setProtection(p *PDFProtection) {
s.pdfProtection = p
}
func (s TransparencyXObjectGroup) protection() *PDFProtection {
return s.pdfProtection
}
func (s TransparencyXObjectGroup) getType() string {
return "XObject"
}
func (s TransparencyXObjectGroup) write(w io.Writer, objId int) error {
streamBuff := GetBuffer()
defer PutBuffer(streamBuff)
for _, XObject := range s.XObjects {
if err := XObject.write(streamBuff, nil); err != nil {
return err
}
}
content := "<<\n"
content += "\t/FormType 1\n"
content += "\t/Subtype /Form\n"
content += fmt.Sprintf("\t/Type /%s\n", s.getType())
content += fmt.Sprintf("\t/Matrix [1 0 0 1 0 0]\n")
content += fmt.Sprintf("\t/BBox [%.3F %.3F %.3F %.3F]\n", s.BBox[0], s.BBox[1], s.BBox[2], s.BBox[3])
content += "\t/Group<</CS /DeviceGray /S /Transparency>>\n"
content += fmt.Sprintf("\t/Length %d\n", len(streamBuff.Bytes()))
content += ">>\n"
content += "stream\n"
if _, err := io.WriteString(w, content); err != nil {
return err
}
if _, err := w.Write(streamBuff.Bytes()); err != nil {
return err
}
if _, err := io.WriteString(w, "endstream\n"); err != nil {
return err
}
return nil
}