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

Updates #484
This commit is contained in:
Hajime Hoshi 2020-10-03 15:32:06 +09:00
parent 3f1d0788f5
commit 584916c694
2 changed files with 9 additions and 6 deletions

View File

@ -28,9 +28,9 @@ import (
"path/filepath" "path/filepath"
"text/template" "text/template"
"github.com/golang/freetype/truetype"
"github.com/hajimehoshi/file2byteslice" "github.com/hajimehoshi/file2byteslice"
"golang.org/x/image/font" "golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/text" "github.com/hajimehoshi/ebiten/text"
@ -45,7 +45,7 @@ var (
) )
func init() { func init() {
f, err := os.Open(filepath.Join("..", "..", "resources", "fonts", "arcade_n.ttf")) f, err := os.Open(filepath.Join("..", "..", "resources", "fonts", "pressstart2p.ttf"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -56,17 +56,20 @@ func init() {
log.Fatal(err) log.Fatal(err)
} }
tt, err := truetype.Parse(b) tt, err := opentype.Parse(b)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
const dpi = 72 const dpi = 72
arcadeFont = truetype.NewFace(tt, &truetype.Options{ arcadeFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: arcadeFontSize, Size: arcadeFontSize,
DPI: dpi, DPI: dpi,
Hinting: font.HintingFull, Hinting: font.HintingFull,
}) })
if err != nil {
log.Fatal(err)
}
} }
var keyboardKeys = [][]string{ var keyboardKeys = [][]string{
@ -184,7 +187,7 @@ func drawKey(t *ebiten.Image, name string, x, y, width int) {
} }
img.ReplacePixels(p) img.ReplacePixels(p)
const offset = 4 const offset = 4
text.Draw(img, name, arcadeFont, offset, arcadeFontSize+offset, color.White) text.Draw(img, name, arcadeFont, offset, arcadeFontSize+offset+1, color.White)
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))

File diff suppressed because one or more lines are too long