-
Notifications
You must be signed in to change notification settings - Fork 36
/
tiles.go
36 lines (31 loc) · 817 Bytes
/
tiles.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
package main
import (
"fmt"
"github.com/unidoc/unidoc/pdf/creator"
"math"
)
// Watermarkable is a common interface for watermarkable image or paragraph
type Watermarkable interface {
creator.VectorDrawable
SetPos(x, y float64)
}
func repeatTiles(watermark Watermarkable, c *creator.Creator) {
w := watermark.Width()
h := watermark.Height()
pw := c.Context().PageWidth
ph := c.Context().PageHeight
nw := math.Ceil(pw / w)
nh := math.Ceil(ph / h)
debugInfo(fmt.Sprintf("Settings tiles of %v x %v", nw, nh))
for i := 0; i < int(nw); i++ {
x := w * float64(i)
for j := 0; j < int(nh); j++ {
y := h * float64(j)
watermark.SetPos(x + spacing * float64(i), y + spacing * float64(j))
err := c.Draw(watermark)
if err != nil {
fatalIfError(err, fmt.Sprintf("Error %s", err))
}
}
}
}