forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_cache_content.go
71 lines (58 loc) · 1.41 KB
/
list_cache_content.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
61
62
63
64
65
66
67
68
69
70
71
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 content
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 = cacheFont.x + textWidthPdfUnit
}
if cacheFont.cellOpt.Float&Bottom == Bottom {
y = cacheFont.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
}