forked from centrifugal/centrifugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webfonts.go
62 lines (55 loc) · 1.36 KB
/
webfonts.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
// webfonts demo
// +build !appengine
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"github.com/centrifugal/centrifugo/Godeps/_workspace/src/github.com/ajstarks/svgo"
)
var (
canvas = svg.New(os.Stdout)
width = 500
height = 1100
fontlist = "Sue Ellen Francisco|Over the Rainbow|Pacifico|Inconsolata|Miltonian|Megrim|Monofett|Permanent Marker|Homemade Apple|Ultra"
)
const (
gwfURI = "http://fonts.googleapis.com/css?family="
fontfmt = "<style type=\"text/css\">\n<![CDATA[\n%s]]>\n</style>\n"
gfmt = "fill:white;font-size:36pt;text-anchor:middle"
)
func googlefont(f string) []string {
empty := []string{}
r, err := http.Get(gwfURI + url.QueryEscape(f))
if err != nil {
return empty
}
defer r.Body.Close()
b, rerr := ioutil.ReadAll(r.Body)
if rerr != nil || r.StatusCode != http.StatusOK {
return empty
}
canvas.Def()
fmt.Fprintf(canvas.Writer, fontfmt, b)
canvas.DefEnd()
return strings.Split(fontlist, "|")
}
func main() {
canvas.Start(width, height)
canvas.Title("Webfonts")
if len(os.Args) > 1 {
fontlist = os.Args[1]
}
fl := googlefont(fontlist)
canvas.Rect(0, 0, width, height)
canvas.Ellipse(width/2, height+50, width/2, height/5, "fill:rgb(44,77,232)")
canvas.Gstyle(gfmt)
for i, f := range fl {
canvas.Text(width/2, (i+1)*100, "Hello, World", "font-family:"+f)
}
canvas.Gend()
canvas.End()
}