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

Updates #484
This commit is contained in:
Hajime Hoshi 2020-09-28 02:20:09 +09:00
parent 567720ffb4
commit 7b3294064d
3 changed files with 13 additions and 7 deletions

View File

@ -24,8 +24,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/golang/freetype/truetype"
"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/examples/resources/fonts" "github.com/hajimehoshi/ebiten/examples/resources/fonts"
@ -90,22 +90,28 @@ func init() {
} }
func init() { func init() {
tt, err := truetype.Parse(fonts.MPlus1pRegular_ttf) tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
const dpi = 72 const dpi = 72
mplusNormalFont = truetype.NewFace(tt, &truetype.Options{ mplusNormalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 24, Size: 24,
DPI: dpi, DPI: dpi,
Hinting: font.HintingFull, Hinting: font.HintingFull,
}) })
mplusBigFont = truetype.NewFace(tt, &truetype.Options{ if err != nil {
log.Fatal(err)
}
mplusBigFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
Size: 48, Size: 48,
DPI: dpi, DPI: dpi,
Hinting: font.HintingFull, Hinting: font.HintingFull,
}) })
if err != nil {
log.Fatal(err)
}
} }
func init() { func init() {

2
go.mod
View File

@ -13,7 +13,7 @@ require (
github.com/jakecoffman/cp v1.0.0 github.com/jakecoffman/cp v1.0.0
github.com/jfreymuth/oggvorbis v1.0.1 github.com/jfreymuth/oggvorbis v1.0.1
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
golang.org/x/image v0.0.0-20200801110659-972c09e46d76 golang.org/x/image v0.0.0-20200927104501-e162460cd6b5
golang.org/x/mobile v0.0.0-20200801112145-973feb4309de golang.org/x/mobile v0.0.0-20200801112145-973feb4309de
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff golang.org/x/sys v0.0.0-20200918174421-af09f7315aff
golang.org/x/tools v0.0.0-20200918232735-d647fc253266 golang.org/x/tools v0.0.0-20200918232735-d647fc253266

4
go.sum
View File

@ -38,8 +38,8 @@ golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9t
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200801110659-972c09e46d76 h1:U7GPaoQyQmX+CBRWXKrvRzWTbd+slqeSh8uARsIyhAw= golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
golang.org/x/image v0.0.0-20200801110659-972c09e46d76/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20200801112145-973feb4309de h1:OVJ6QQUBAesB8CZijKDSsXX7xYVtUhrkY0gwMfbi4p4= golang.org/x/mobile v0.0.0-20200801112145-973feb4309de h1:OVJ6QQUBAesB8CZijKDSsXX7xYVtUhrkY0gwMfbi4p4=