examples: Use golang.org/x/image/font/opentype

Updates #484
This commit is contained in:
Hajime Hoshi 2020-10-03 15:11:51 +09:00
parent 774eb0ea82
commit 3f1d0788f5
2 changed files with 16 additions and 7 deletions

View File

@ -27,8 +27,8 @@ import (
"math/rand"
"time"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/audio"
@ -92,21 +92,27 @@ func init() {
}
func init() {
tt, err := truetype.Parse(fonts.ArcadeN_ttf)
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
if err != nil {
log.Fatal(err)
}
const dpi = 72
arcadeFont = truetype.NewFace(tt, &truetype.Options{
arcadeFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: fontSize,
DPI: dpi,
Hinting: font.HintingFull,
})
smallArcadeFont = truetype.NewFace(tt, &truetype.Options{
if err != nil {
log.Fatal(err)
}
smallArcadeFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: smallFontSize,
DPI: dpi,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
}
var (

View File

@ -22,8 +22,8 @@ import (
"log"
"math"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/audio"
@ -38,7 +38,7 @@ var (
)
func init() {
tt, err := truetype.Parse(fonts.ArcadeN_ttf)
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
if err != nil {
log.Fatal(err)
}
@ -47,11 +47,14 @@ func init() {
arcadeFontSize = 8
dpi = 72
)
arcadeFont = truetype.NewFace(tt, &truetype.Options{
arcadeFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: arcadeFontSize,
DPI: dpi,
Hinting: font.HintingFull,
})
if err != nil {
log.Fatal(err)
}
}
const (