1 Star 0 Fork 0

广州捷仓科技有限公司/gopdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
embedfont_obj.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
wanpat anantapan 提交于 2023-08-27 19:46 . clean io/util
package gopdf
import (
"fmt"
"io"
"os"
)
// EmbedFontObj is an embedded font object.
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 := os.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"
}
// SetFont sets the font of an embedded font object.
func (e *EmbedFontObj) SetFont(font IFont, zfontpath string) {
e.font = font
e.zfontpath = zfontpath
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jiecang-tech/gopdf.git
git@gitee.com:jiecang-tech/gopdf.git
jiecang-tech
gopdf
gopdf
master

搜索帮助