-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_cache_content.go
More file actions
88 lines (74 loc) · 1.76 KB
/
list_cache_content.go
File metadata and controls
88 lines (74 loc) · 1.76 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gopdf
import "bytes"
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
_, err := cacheFont.text.WriteString(text)
if err != nil {
return x, y, err
}
//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) toStream(protection *PDFProtection) (*bytes.Buffer, error) {
var buff bytes.Buffer
for _, cache := range l.caches {
stream, err := cache.toStream(protection)
if err != nil {
return nil, err
}
_, err = stream.WriteTo(&buff)
if err != nil {
return nil, err
}
}
return &buff, nil
}
/*
func (l *listCacheContent) debug() string {
var buff bytes.Buffer
for _, cache := range l.caches {
buff.WriteString(cache.text.String())
buff.WriteString("\n")
}
return buff.String()
}*/