text: Remove 'lineHeight' argument

This commit is contained in:
Hajime Hoshi 2017-07-17 06:42:48 +09:00
parent e0d0f477dc
commit 20a43a88e8
2 changed files with 7 additions and 15 deletions

View File

@ -22,6 +22,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand" "math/rand"
"strings"
"time" "time"
"github.com/golang/freetype/truetype" "github.com/golang/freetype/truetype"
@ -150,9 +151,11 @@ func update(screen *ebiten.Image) error {
msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()) msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())
const x = 20 const x = 20
text.Draw(screen, mplusNormalFont, msg, x, 40, 30, color.White) text.Draw(screen, mplusNormalFont, msg, x, 40, color.White)
text.Draw(screen, mplusNormalFont, sampleText, x, 80, 30, color.White) text.Draw(screen, mplusNormalFont, sampleText, x, 80, color.White)
text.Draw(screen, mplusBigFont, string(kanjiText), x, 160, 54, codeToColor(kanjiText[0])) for i, line := range strings.Split(string(kanjiText), "\n") {
text.Draw(screen, mplusBigFont, line, x, 160+54*i, codeToColor(kanjiText[0]))
}
return nil return nil
} }

View File

@ -256,35 +256,24 @@ var textM sync.Mutex
// //
// face is the font for text rendering. // face is the font for text rendering.
// (x, y) represents a 'dot' position. Be careful that this doesn't represent left-upper corner position. // (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. // clr is the color for text rendering.
// //
// Glyphs used for rendering are cached in least-recently-used way. // 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. // It is OK to call this function with a same text and a same face at every frame.
// //
// This function is concurrent-safe. // 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() textM.Lock()
n := now() n := now()
fx := fixed.I(x) fx := fixed.I(x)
ofx := fx
prevC := rune(-1) prevC := rune(-1)
runes := []rune(text) runes := []rune(text)
for _, c := range runes { for _, c := range runes {
// TODO: What if c is '\r'?
if c == '\n' {
fx = ofx
y += lineHeight
prevC = rune(-1)
continue
}
if prevC >= 0 { if prevC >= 0 {
fx += face.Kern(prevC, c) fx += face.Kern(prevC, c)
} }
if g := getGlyphFromCache(face, c, n); g != nil { if g := getGlyphFromCache(face, c, n); g != nil {
if !g.empty() { if !g.empty() {
g.draw(dst, fx.Ceil(), y, clr) g.draw(dst, fx.Ceil(), y, clr)