-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.go
114 lines (94 loc) · 2.03 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"log"
"github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
const fpx = 120.0
var (
fontDPI float64 = fpx
uiScale = 1.0
// Fonts
toolTipFont font.Face
monoFont font.Face
generalFont font.Face
largeGeneralFont font.Face
generalFontH int
)
func updateFonts() {
defer reportPanic("updateFonts")
newVal := fpx * uiScale
if newVal < 1 {
newVal = 1
}
fontDPI = newVal
var mono, tt *opentype.Font
var err error
fontData := getFont("Ubuntu-Mono.ttf")
collection, err := opentype.ParseCollection(fontData)
if err != nil {
log.Fatal(err)
}
tt, err = collection.Font(0)
if err != nil {
log.Fatal(err)
}
// Mono font
fontData = getFont("Ubuntu.ttf")
collection, err = opentype.ParseCollection(fontData)
if err != nil {
log.Fatal(err)
}
mono, err = collection.Font(0)
if err != nil {
log.Fatal(err)
}
/*
* Font DPI
* Changes how large the font is for a given point value
*/
// General font
generalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 10,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
generalFontH = getFontHeight(generalFont)
// Large General font
largeGeneralFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 20,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
// Tooltip font
toolTipFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 8,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
// Mono font
monoFont, err = opentype.NewFace(mono, &opentype.FaceOptions{
Size: 10,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
}
const sizingText = "!@#$%^&*()_+-=[]{}|;':,.<>?`~qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
func getFontHeight(font font.Face) int {
defer reportPanic("getFontHeight")
tRect := text.BoundString(font, sizingText)
return tRect.Dy()
}