1 Star 0 Fork 0

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

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
list_cache_content.go 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
Simon Green 提交于 2017-09-25 12:52 . More bytes.Buffer removal
package gopdf
import "io"
type listCacheContent struct {
caches []iCacheContent
}
func (l *listCacheContent) last() iCacheContent {
max := len(l.caches)
if max > 0 {
return l.caches[max-1]
}
return nil
}
func (l *listCacheContent) append(cache iCacheContent) {
l.caches = append(l.caches, cache)
}
func (l *listCacheContent) appendContentText(cache cacheContentText, text string) (float64, float64, error) {
x := cache.x
y := cache.y
mustMakeNewCache := true
var cacheFont *cacheContentText
var ok bool
last := l.last()
if cacheFont, ok = last.(*cacheContentText); ok {
if cacheFont != nil {
if cacheFont.isSame(cache) {
mustMakeNewCache = false
}
}
}
if mustMakeNewCache { //make new cell
l.caches = append(l.caches, &cache)
cacheFont = &cache
}
//start add text
cacheFont.text += text
//re-create contnet
textWidthPdfUnit, textHeightPdfUnit, err := cacheFont.createContent()
if err != nil {
return x, y, err
}
if cacheFont.cellOpt.Float == 0 || cacheFont.cellOpt.Float&Right == Right || cacheFont.contentType == ContentTypeText {
x += textWidthPdfUnit
}
if cacheFont.cellOpt.Float&Bottom == Bottom {
y += textHeightPdfUnit
}
return x, y, nil
}
func (l *listCacheContent) write(w io.Writer, protection *PDFProtection) error {
for _, cache := range l.caches {
if err := cache.write(w, protection); err != nil {
return err
}
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jiecang-tech/gopdf.git
git@gitee.com:jiecang-tech/gopdf.git
jiecang-tech
gopdf
gopdf
v0.8.0

搜索帮助