github.com/signintech/pdft@v0.5.0/minigopdf/embedfont_obj.go (about) 1 package gopdf 2 3 import ( 4 "bytes" 5 "io/ioutil" 6 "strconv" 7 ) 8 9 type EmbedFontObj struct { 10 buffer bytes.Buffer 11 Data string 12 zfontpath string 13 font IFont 14 getRoot func() *GoPdf 15 } 16 17 func (e *EmbedFontObj) init(funcGetRoot func() *GoPdf) { 18 e.getRoot = funcGetRoot 19 } 20 21 func (e *EmbedFontObj) protection() *PDFProtection { 22 return e.getRoot().protection() 23 } 24 25 func (e *EmbedFontObj) build(objID int) error { 26 b, err := ioutil.ReadFile(e.zfontpath) 27 if err != nil { 28 return err 29 } 30 e.buffer.WriteString("<</Length " + strconv.Itoa(len(b)) + "\n") 31 e.buffer.WriteString("/Filter /FlateDecode\n") 32 e.buffer.WriteString("/Length1 " + strconv.Itoa(e.font.GetOriginalsize()) + "\n") 33 e.buffer.WriteString(">>\n") 34 e.buffer.WriteString("stream\n") 35 if e.protection() != nil { 36 tmp, err := rc4Cip(e.protection().objectkey(objID), b) 37 if err != nil { 38 return err 39 } 40 e.buffer.Write(tmp) 41 e.buffer.WriteString("\n") 42 } else { 43 e.buffer.Write(b) 44 } 45 e.buffer.WriteString("\nendstream\n") 46 return nil 47 } 48 49 func (e *EmbedFontObj) getType() string { 50 return "EmbedFont" 51 } 52 53 func (e *EmbedFontObj) getObjBuff() *bytes.Buffer { 54 return &(e.buffer) 55 } 56 57 func (e *EmbedFontObj) SetFont(font IFont, zfontpath string) { 58 e.font = font 59 e.zfontpath = zfontpath 60 }