forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedfont_obj.go
55 lines (48 loc) · 1.06 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
package gopdf
import (
"fmt"
"io"
"io/ioutil"
)
type EmbedFontObj struct {
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) write(w io.Writer, objID int) error {
b, err := ioutil.ReadFile(e.zfontpath)
if err != nil {
return err
}
fmt.Fprintf(w, "<</Length %d\n", len(b))
io.WriteString(w, "/Filter /FlateDecode\n")
fmt.Fprintf(w, "/Length1 %d\n", e.font.GetOriginalsize())
io.WriteString(w, ">>\n")
io.WriteString(w, "stream\n")
if e.protection() != nil {
tmp, err := rc4Cip(e.protection().objectkey(objID), b)
if err != nil {
return err
}
w.Write(tmp)
io.WriteString(w, "\n")
} else {
w.Write(b)
}
io.WriteString(w, "\nendstream\n")
return nil
}
func (e *EmbedFontObj) getType() string {
return "EmbedFont"
}
func (e *EmbedFontObj) SetFont(font IFont, zfontpath string) {
e.font = font
e.zfontpath = zfontpath
}