-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgallant_test.go
More file actions
50 lines (45 loc) · 994 Bytes
/
Copy pathgallant_test.go
File metadata and controls
50 lines (45 loc) · 994 Bytes
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 gallant
import (
"image"
"image/draw"
"image/png"
"os"
"testing"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
)
func runeRange(t *testing.T, from, count int) string {
t.Helper()
b := make([]rune, count)
for i := 0; i < count; i++ {
b[i] = rune(from + i)
}
return string(b)
}
func writeImage(t *testing.T, name string, img image.Image) {
t.Helper()
out, err := os.Create(name)
if err != nil {
t.Fatal(err)
}
defer out.Close()
if err := png.Encode(out, img); err != nil {
t.Fatal(err)
}
}
func TestPreview(t *testing.T) {
dst := image.NewRGBA(image.Rect(0, 0, 570, 270))
draw.Draw(dst, dst.Bounds(), image.White, image.Point{}, draw.Src)
d := &font.Drawer{
Dst: dst,
Src: image.Black,
Face: Gallant,
Dot: fixed.P(20, 25),
}
d.DrawString("The quick brown fox jumps over the lazy dog.")
for i := 0; i < 8; i++ {
d.Dot = fixed.P(20, 75+i*25)
d.DrawString(runeRange(t, i*0x20, 0x20))
}
writeImage(t, "img/preview.png", dst)
}