-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.go
102 lines (85 loc) · 1.86 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
package main
import (
"log"
"github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
const fontDPI = 96.0
func loadFonts() {
var err error
/* Mono font */
fontData := getFont("Hack-Regular.ttf")
collection, err := opentype.ParseCollection(fontData)
if err != nil {
log.Fatal(err)
}
mono, err := collection.Font(0)
if err != nil {
log.Fatal(err)
}
/* Game font */
fontData = getFont("KomikaAxis.otf")
collection, err = opentype.ParseCollection(fontData)
if err != nil {
log.Fatal(err)
}
tt, err := collection.Font(0)
if err != nil {
log.Fatal(err)
}
/*
* Font DPI
* Changes how large the font is for a given point value
*/
/* Mono font */
monoFont, err = opentype.NewFace(mono, &opentype.FaceOptions{
Size: 8,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
/* Small General font */
smallGeneralFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 10,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
/* General font */
generalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 14,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
/* Large general font */
largeGeneralFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 20,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
/* Large general font */
hugeGeneralFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 32,
DPI: fontDPI,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
}
const sizingText = "!@#$%^&*()_+-=[]{}|;':,.<>?`~qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
func getFontHeight(font font.Face) int {
tRect := text.BoundString(font, sizingText)
return tRect.Dy()
}