Debian Codegraph @

writer/standard/image_qr_shape_test.go

raw
1 package standard
2
3 import (
4 "image"
5 "image/color"
6 "testing"
7
8 "github.com/fogleman/gg"
9 )
10
11 func Test_rectangle_Draw(t *testing.T) {
12 rect := image.Rect(0, 0, 100, 100)
13 rgba := image.NewRGBA(rect)
14 dc := gg.NewContextForRGBA(rgba)
15
16 dc.DrawRectangle(0, 0, 100, 100)
17 dc.SetColor(color.White)
18 dc.Fill()
19
20 ctx := &DrawContext{
21 Context: dc,
22 x: 0.0,
23 y: 0.0,
24 w: 50,
25 h: 50,
26 color: color.Black,
27 }
28 _shapeRectangle.Draw(ctx)
29
30 err := dc.SavePNG("./testdata/rectangle.png")
31 if err != nil {
32 t.Error(err)
33 t.FailNow()
34 }
35 }
36
37 func Test_circle_Draw(t *testing.T) {
38 rect := image.Rect(0, 0, 100, 100)
39 rgba := image.NewRGBA(rect)
40 dc := gg.NewContextForRGBA(rgba)
41
42 dc.DrawRectangle(0, 0, 100, 100)
43 dc.SetColor(color.White)
44 dc.Fill()
45
46 ctx := &DrawContext{
47 Context: dc,
48 x: 0.0,
49 y: 0.0,
50 w: 50,
51 h: 50,
52 color: color.Black,
53 }
54 _shapeCircle.Draw(ctx)
55
56 err := dc.SavePNG("./testdata/circle.png")
57 if err != nil {
58 t.Error(err)
59 t.FailNow()
60 }
61 }
62
63 func Test_gg(t *testing.T) {
64 rect := image.Rect(0, 0, 100, 100)
65 rgba := image.NewRGBA(rect)
66 dc := gg.NewContextForRGBA(rgba)
67
68 dc.DrawRectangle(0, 0, 100, 100)
69 dc.SetColor(color.White)
70 dc.Fill()
71
72 dc.DrawCircle(50, 50, 40)
73 dc.SetColor(color.Black)
74 dc.Fill()
75 _ = dc.SavePNG("./testdata/out.png")
76 }