-
Notifications
You must be signed in to change notification settings - Fork 25
/
font.go
54 lines (47 loc) · 961 Bytes
/
font.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
package main
import (
"os"
"runtime"
"strconv"
"github.com/as/font"
"github.com/as/ui/tag"
)
type facer interface {
Face() font.Face
SetFont(font.Face)
}
var fontmap = make(map[facer]int)
var fontfuncs = [...]func(int) font.Face{
font.NewFace,
font.NewGoMedium,
font.NewGoRegular,
font.NewGoMono,
}
func nextFace(f facer) {
fontmap[f]++
fn := fontfuncs[fontmap[f]%len(fontfuncs)]
if f, ok := f.(*tag.Tag); ok {
f.Config.Facer = fn
}
f.SetFont(fn(f.Face().Height()))
}
func defaultFaceSize() int {
if s := os.Getenv("fontsize"); s != "" {
// user specified a font size, so let's
// just go with it
v, err := strconv.Atoi(s)
if err == nil {
return v
}
}
switch runtime.GOOS {
case "darwin":
// darwin begets a larger font; might not be enough;
// TODO(as): proper DPI-aware scaling
return 13
default:
// de-facto standard for best looking font size
// based on references I don't have anymore
return 11
}
}