-
Notifications
You must be signed in to change notification settings - Fork 25
/
recalculatefont.go
59 lines (51 loc) · 1.31 KB
/
recalculatefont.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
// +build !darwin
package renderer
import (
"fmt"
"os"
//"io/ioutil"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
"golang.org/x/image/font/gofont/gomono"
"golang.org/x/image/font/gofont/gomonobold"
// "golang.org/x/image/font/basicfont"
)
func RecalculateFontFace(dpi float64) {
if dpi == 0 {
// If called with the 0 value, continue to use our
// default.
return
}
ft, err := truetype.Parse(gomono.TTF)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not parse font: %s\n", err)
os.Exit(3)
}
MonoFontFace = truetype.NewFace(ft,
&truetype.Options{
Size: 12,
DPI: dpi,
Hinting: font.HintingNone})
if MonoFontFace == nil {
panic("Could not get font face.")
}
metrics := MonoFontFace.Metrics()
MonoFontHeight = metrics.Height
MonoFontAscent = metrics.Ascent
MonoFontAdvance, _ = MonoFontFace.GlyphAdvance('M')
_, MonoFontGlyphWidth, _ = MonoFontFace.GlyphBounds('a')
// Assume bold has the same metrics and just calculate the face.
ft, err = truetype.Parse(gomonobold.TTF)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not parse font: %s\n", err)
os.Exit(3)
}
MonoFontFaceBold = truetype.NewFace(ft,
&truetype.Options{
Size: 12,
DPI: dpi,
Hinting: font.HintingNone})
if MonoFontFaceBold == nil {
panic("Could not get bold font face.")
}
}