/
text_test.go
71 lines (66 loc) · 1.62 KB
/
text_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ssvgc_test
import (
"strings"
"testing"
"github.com/llgcode/draw2d/draw2dimg"
"github.com/stephenwithav/ssvgc"
)
func TestTextRendering(t *testing.T) {
var tests = []StringMap{
{
"name": "textredbanana",
"text-value": `<svg width="200" height="200" fill="white">
<text ttf-font="/tmp/DejaVuSans.ttf" x="15" y="30">You are
<tspan fill="red">not</tspan>
a banana
</text>
</svg>`,
},
{
"name": "textbananashiftedright",
"text-value": `<svg width="200" height="200" fill="white">
<text ttf-font="/tmp/DejaVuSans.ttf" x="45" y="30">You are
<tspan>not</tspan>
a banana
</text>
</svg>`,
},
{
"name": "textbananashifteddown",
"text-value": `<svg width="200" height="200" fill="white">
<text ttf-font="/tmp/DejaVuSans.ttf" font-size="18" x="1" y="70">You are
<tspan>not</tspan>
a banana
</text>
</svg>`,
},
{
"name": "textbananaanchormiddle",
"text-value": `<svg width="500" height="200" fill="white">
<text ttf-font="/tmp/DejaVuSans.ttf" font-size="18" x="250" y="70" text-anchor="middle">You are
<tspan>not</tspan>
a banana
</text>
</svg>`,
},
{
"name": "textbananaanchorend",
"text-value": `<svg width="500" height="200" fill="white">
<text ttf-font="/tmp/DejaVuSans.ttf" font-size="18" x="250" y="70" text-anchor="end">You are
<tspan>not</tspan>
a banana
</text>
</svg>`,
},
}
for _, tt := range tests {
r := strings.NewReader(tt["text-value"])
p := ssvgc.NewParser(r)
svg, err := p.ParseSVG()
if err != nil {
t.Errorf("ParseSVG() failed => %s", err)
continue
}
draw2dimg.SaveToPngFile("output/"+tt["name"]+".png", svg.Draw())
}
}