diff --git a/examples/font/main.go b/examples/font/main.go index 650648035..e2e159db5 100644 --- a/examples/font/main.go +++ b/examples/font/main.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "log" "math/rand" + "strings" "time" "github.com/golang/freetype/truetype" @@ -150,9 +151,11 @@ func update(screen *ebiten.Image) error { msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()) const x = 20 - text.Draw(screen, mplusNormalFont, msg, x, 40, 30, color.White) - text.Draw(screen, mplusNormalFont, sampleText, x, 80, 30, color.White) - text.Draw(screen, mplusBigFont, string(kanjiText), x, 160, 54, codeToColor(kanjiText[0])) + text.Draw(screen, mplusNormalFont, msg, x, 40, color.White) + text.Draw(screen, mplusNormalFont, sampleText, x, 80, color.White) + for i, line := range strings.Split(string(kanjiText), "\n") { + text.Draw(screen, mplusBigFont, line, x, 160+54*i, codeToColor(kanjiText[0])) + } return nil } diff --git a/text/text.go b/text/text.go index 0208b37c2..6b098c1cb 100644 --- a/text/text.go +++ b/text/text.go @@ -256,35 +256,24 @@ var textM sync.Mutex // // face is the font for text rendering. // (x, y) represents a 'dot' position. Be careful that this doesn't represent left-upper corner position. -// lineHeight is the Y offset for line spacing. // clr is the color for text rendering. // // Glyphs used for rendering are cached in least-recently-used way. // It is OK to call this function with a same text and a same face at every frame. // // This function is concurrent-safe. -func Draw(dst *ebiten.Image, face font.Face, text string, x, y int, lineHeight int, clr color.Color) { +func Draw(dst *ebiten.Image, face font.Face, text string, x, y int, clr color.Color) { textM.Lock() n := now() fx := fixed.I(x) - ofx := fx prevC := rune(-1) runes := []rune(text) for _, c := range runes { - // TODO: What if c is '\r'? - if c == '\n' { - fx = ofx - y += lineHeight - prevC = rune(-1) - continue - } - if prevC >= 0 { fx += face.Kern(prevC, c) } - if g := getGlyphFromCache(face, c, n); g != nil { if !g.empty() { g.draw(dst, fx.Ceil(), y, clr)