forked from signintech/pdft
/
embedfont_obj.go
60 lines (52 loc) · 1.22 KB
/
embedfont_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
package gopdf
import (
"bytes"
"io/ioutil"
"strconv"
)
type EmbedFontObj struct {
buffer bytes.Buffer
Data string
zfontpath string
font IFont
getRoot func() *GoPdf
}
func (e *EmbedFontObj) init(funcGetRoot func() *GoPdf) {
e.getRoot = funcGetRoot
}
func (e *EmbedFontObj) protection() *PDFProtection {
return e.getRoot().protection()
}
func (e *EmbedFontObj) build(objID int) error {
b, err := ioutil.ReadFile(e.zfontpath)
if err != nil {
return err
}
e.buffer.WriteString("<</Length " + strconv.Itoa(len(b)) + "\n")
e.buffer.WriteString("/Filter /FlateDecode\n")
e.buffer.WriteString("/Length1 " + strconv.Itoa(e.font.GetOriginalsize()) + "\n")
e.buffer.WriteString(">>\n")
e.buffer.WriteString("stream\n")
if e.protection() != nil {
tmp, err := rc4Cip(e.protection().objectkey(objID), b)
if err != nil {
return err
}
e.buffer.Write(tmp)
e.buffer.WriteString("\n")
} else {
e.buffer.Write(b)
}
e.buffer.WriteString("\nendstream\n")
return nil
}
func (e *EmbedFontObj) getType() string {
return "EmbedFont"
}
func (e *EmbedFontObj) getObjBuff() *bytes.Buffer {
return &(e.buffer)
}
func (e *EmbedFontObj) SetFont(font IFont, zfontpath string) {
e.font = font
e.zfontpath = zfontpath
}