-
Notifications
You must be signed in to change notification settings - Fork 280
/
cache_content_rectangle.go
50 lines (40 loc) · 1.12 KB
/
cache_content_rectangle.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
package gopdf
import (
"fmt"
"io"
)
type cacheContentRectangle struct {
pageHeight float64
x float64
y float64
width float64
height float64
style PaintStyle
extGStateIndexes []int
}
func NewCacheContentRectangle(pageHeight float64, rectOpts DrawableRectOptions) ICacheContent {
if rectOpts.PaintStyle == "" {
rectOpts.PaintStyle = DrawPaintStyle
}
return cacheContentRectangle{
x: rectOpts.X,
y: rectOpts.Y,
width: rectOpts.W,
height: rectOpts.H,
pageHeight: pageHeight,
style: rectOpts.PaintStyle,
extGStateIndexes: rectOpts.extGStateIndexes,
}
}
func (c cacheContentRectangle) write(w io.Writer, protection *PDFProtection) error {
stream := "q\n"
for _, extGStateIndex := range c.extGStateIndexes {
stream += fmt.Sprintf("/GS%d gs\n", extGStateIndex)
}
stream += fmt.Sprintf("%0.2f %0.2f %0.2f %0.2f re %s\n", c.x, c.pageHeight-c.y, c.width, c.height, c.style)
stream += "Q\n"
if _, err := io.WriteString(w, stream); err != nil {
return err
}
return nil
}