From eb383240218d81dac63dd2f75836367a0a3c7515 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 3 Oct 2020 23:12:39 +0900 Subject: [PATCH] examples: Use golang.org/x/image/font/opentype Fixes #484 --- examples/2048/2048/tile.go | 19 ++++++++++++++----- examples/font/main.go | 14 ++++++++++---- examples/fullscreen/main.go | 9 ++++++--- examples/text/main.go | 14 ++++++++++---- examples/ui/main.go | 9 ++++++--- go.mod | 1 - go.sum | 2 -- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/examples/2048/2048/tile.go b/examples/2048/2048/tile.go index fb18c7808..b8a99dd06 100644 --- a/examples/2048/2048/tile.go +++ b/examples/2048/2048/tile.go @@ -22,8 +22,8 @@ import ( "sort" "strconv" - "github.com/golang/freetype/truetype" "golang.org/x/image/font" + "golang.org/x/image/font/opentype" "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/examples/resources/fonts" @@ -37,27 +37,36 @@ var ( ) func init() { - tt, err := truetype.Parse(fonts.MPlus1pRegular_ttf) + tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf) if err != nil { log.Fatal(err) } const dpi = 72 - mplusSmallFont = truetype.NewFace(tt, &truetype.Options{ + mplusSmallFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 24, DPI: dpi, Hinting: font.HintingFull, }) - mplusNormalFont = truetype.NewFace(tt, &truetype.Options{ + if err != nil { + log.Fatal(err) + } + mplusNormalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 32, DPI: dpi, Hinting: font.HintingFull, }) - mplusBigFont = truetype.NewFace(tt, &truetype.Options{ + if err != nil { + log.Fatal(err) + } + mplusBigFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 48, DPI: dpi, Hinting: font.HintingFull, }) + if err != nil { + log.Fatal(err) + } } // TileData represents a tile information like a value and a position. diff --git a/examples/font/main.go b/examples/font/main.go index 7793504b6..ac75e947b 100644 --- a/examples/font/main.go +++ b/examples/font/main.go @@ -24,8 +24,8 @@ import ( "strings" "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/examples/resources/fonts" @@ -90,22 +90,28 @@ func init() { } func init() { - tt, err := truetype.Parse(fonts.MPlus1pRegular_ttf) + tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf) if err != nil { log.Fatal(err) } const dpi = 72 - mplusNormalFont = truetype.NewFace(tt, &truetype.Options{ + mplusNormalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 24, DPI: dpi, Hinting: font.HintingFull, }) - mplusBigFont = truetype.NewFace(tt, &truetype.Options{ + if err != nil { + log.Fatal(err) + } + mplusBigFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 48, DPI: dpi, Hinting: font.HintingFull, }) + if err != nil { + log.Fatal(err) + } } func init() { diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index bc26d3dc8..ffbd88b4e 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -26,8 +26,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/examples/resources/fonts" @@ -59,17 +59,20 @@ func init() { } func initFont() { - tt, err := truetype.Parse(fonts.MPlus1pRegular_ttf) + tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf) if err != nil { log.Fatal(err) } const dpi = 72 - mplusFont = truetype.NewFace(tt, &truetype.Options{ + mplusFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 12 * ebiten.DeviceScaleFactor(), DPI: dpi, Hinting: font.HintingFull, }) + if err != nil { + log.Fatal(err) + } } type Game struct { diff --git a/examples/text/main.go b/examples/text/main.go index f5c5d470d..2b772c683 100644 --- a/examples/text/main.go +++ b/examples/text/main.go @@ -22,8 +22,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/ebitenutil" @@ -45,22 +45,28 @@ var ( ) func init() { - tt, err := truetype.Parse(fonts.MPlus1pRegular_ttf) + tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf) if err != nil { log.Fatal(err) } const dpi = 72 - mplusNormalFont = truetype.NewFace(tt, &truetype.Options{ + mplusNormalFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 24, DPI: dpi, Hinting: font.HintingFull, }) - mplusBigFont = truetype.NewFace(tt, &truetype.Options{ + if err != nil { + log.Fatal(err) + } + mplusBigFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 32, DPI: dpi, Hinting: font.HintingFull, }) + if err != nil { + log.Fatal(err) + } } func init() { diff --git a/examples/ui/main.go b/examples/ui/main.go index 36000b400..b16c27910 100644 --- a/examples/ui/main.go +++ b/examples/ui/main.go @@ -24,9 +24,9 @@ import ( "log" "strings" - "github.com/golang/freetype/truetype" "golang.org/x/image/font" "golang.org/x/image/font/gofont/goregular" + "golang.org/x/image/font/opentype" "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/examples/resources/images" @@ -60,15 +60,18 @@ func init() { } uiImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault) - tt, err := truetype.Parse(goregular.TTF) + tt, err := opentype.Parse(goregular.TTF) if err != nil { log.Fatal(err) } - uiFont = truetype.NewFace(tt, &truetype.Options{ + uiFont, err = opentype.NewFace(tt, &opentype.FaceOptions{ Size: 12, DPI: 72, Hinting: font.HintingFull, }) + if err != nil { + log.Fatal(err) + } b, _, _ := uiFont.GlyphBounds('M') uiFontMHeight = (b.Max.Y - b.Min.Y).Ceil() } diff --git a/go.mod b/go.mod index 49977c17b..5db6ed1e7 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.12 require ( github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2 github.com/gofrs/flock v0.8.0 - github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/hajimehoshi/bitmapfont/v2 v2.1.0 github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e github.com/hajimehoshi/go-mp3 v0.3.1 diff --git a/go.sum b/go.sum index 07a922e96..968dc18f7 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2 h1:Ac1OEHHkbA github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY= github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/hajimehoshi/bitmapfont/v2 v2.1.0 h1:Kit9SsNcnrU5Q/39zni2adUMTEm128/lkNnYxnP+v3A= github.com/hajimehoshi/bitmapfont/v2 v2.1.0/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs= github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e h1:4IP7CPObI35+mQShFOYg2JMHDJKciLTW5599inhFfkA=