text/v2: rename LineSpaceInPixels -> LineSpace for consistency

Updates #2454
This commit is contained in:
Hajime Hoshi 2023-12-24 15:06:16 +09:00
parent f0396ba915
commit f57703175e
14 changed files with 34 additions and 33 deletions

View File

@ -48,7 +48,7 @@ func drawTextWithShadow(rt *ebiten.Image, str string, x, y, scale int, clr color
op := &text.DrawOptions{}
op.GeoM.Translate(float64(x)+1, float64(y)+1)
op.ColorScale.ScaleWithColor(shadowColor)
op.LineSpacingInPixels = arcadeFontBaseSize * float64(scale)
op.LineSpacing = arcadeFontBaseSize * float64(scale)
op.PrimaryAlign = primaryAlign
op.SecondaryAlign = secondaryAlign
text.Draw(rt, str, &text.GoTextFace{

View File

@ -277,7 +277,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(screenWidth/2, 3*titleFontSize)
op.ColorScale.ScaleWithColor(color.White)
op.LineSpacingInPixels = titleFontSize
op.LineSpacing = titleFontSize
op.PrimaryAlign = text.AlignCenter
text.Draw(screen, titleTexts, &text.GoTextFace{
Source: arcadeFaceSource,
@ -287,7 +287,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op = &text.DrawOptions{}
op.GeoM.Translate(screenWidth/2, 3*titleFontSize)
op.ColorScale.ScaleWithColor(color.White)
op.LineSpacingInPixels = fontSize
op.LineSpacing = fontSize
op.PrimaryAlign = text.AlignCenter
text.Draw(screen, texts, &text.GoTextFace{
Source: arcadeFaceSource,
@ -300,7 +300,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(screenWidth/2, screenHeight-smallFontSize/2)
op.ColorScale.ScaleWithColor(color.White)
op.LineSpacingInPixels = smallFontSize
op.LineSpacing = smallFontSize
op.PrimaryAlign = text.AlignCenter
op.SecondaryAlign = text.AlignEnd
text.Draw(screen, msg, &text.GoTextFace{
@ -312,7 +312,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op = &text.DrawOptions{}
op.GeoM.Translate(screenWidth, 0)
op.ColorScale.ScaleWithColor(color.White)
op.LineSpacingInPixels = fontSize
op.LineSpacing = fontSize
op.PrimaryAlign = text.AlignEnd
text.Draw(screen, fmt.Sprintf("%04d", g.score()), &text.GoTextFace{
Source: arcadeFaceSource,

View File

@ -155,7 +155,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op = &text.DrawOptions{}
op.GeoM.Translate(x, 110)
op.ColorScale.ScaleWithColor(g.kanjiTextColor)
op.LineSpacingInPixels = bigFontSize * 1.2
op.LineSpacing = bigFontSize * 1.2
text.Draw(screen, g.kanjiText, &text.GoTextFace{
Source: mplusFaceSource,
Size: bigFontSize,

View File

@ -102,7 +102,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
[Z] 'zero' (Slashed Zero) (%d)`, g.liga, g.tnum, g.smcp, g.zero)
op := &text.DrawOptions{}
op.GeoM.Translate(20, 20)
op.LineSpacingInPixels = 30
op.LineSpacing = 30
text.Draw(screen, inst, &text.GoTextFace{
Source: firaSansFaceSource,
Size: 20,
@ -115,7 +115,7 @@ ffi
2.71`
op = &text.DrawOptions{}
op.GeoM.Translate(20, screenHeight/2)
op.LineSpacingInPixels = 50
op.LineSpacing = 50
f := &text.GoTextFace{
Source: firaSansFaceSource,
Size: 40,

View File

@ -116,7 +116,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
[Z, X]: slnt (Slant): %0.0f [%d-%d]`, g.wght, minWght, maxWght, g.wdth, minWdth, maxWdth, g.slnt, minSlnt, maxSlnt)
op := &text.DrawOptions{}
op.GeoM.Translate(20, 20)
op.LineSpacingInPixels = 30
op.LineSpacing = 30
text.Draw(screen, inst, &text.GoTextFace{
Source: robotoFlexFaceSource,
Size: 20,
@ -127,7 +127,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
over the lazy dog.`
op = &text.DrawOptions{}
op.GeoM.Translate(20, screenHeight/2)
op.LineSpacingInPixels = 50
op.LineSpacing = 50
f := &text.GoTextFace{
Source: robotoFlexFaceSource,
Size: 40,

View File

@ -59,7 +59,7 @@ func (g *Game) Update() error {
return err
}
op := &text.LayoutOptions{}
op.LineSpacingInPixels = 110
op.LineSpacing = 110
text.AppendVectorPath(&g.path, "ABCEDFG\nabcdefg\nあいうえお\nかきくけこ", &text.GoTextFace{
Source: s,
Size: 90,

View File

@ -99,7 +99,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
textOp := &text.DrawOptions{}
textOp.GeoM.Translate(50*scale, 50*scale)
textOp.ColorScale.ScaleWithColor(color.White)
textOp.LineSpacingInPixels = 12 * ebiten.DeviceScaleFactor() * 1.5
textOp.LineSpacing = 12 * ebiten.DeviceScaleFactor() * 1.5
text.Draw(screen, msg, &text.GoTextFace{
Source: mplusFaceSource,
Size: 12 * ebiten.DeviceScaleFactor(),

View File

@ -93,7 +93,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Use bitmapfont.Face instead of ebitenutil.DebugPrint, since some key names might not be printed with DebugPrint.
textOp := &text.DrawOptions{}
textOp.LineSpacingInPixels = fontFace.Metrics().HLineGap + fontFace.Metrics().HAscent + fontFace.Metrics().HDescent
textOp.LineSpacing = fontFace.Metrics().HLineGap + fontFace.Metrics().HAscent + fontFace.Metrics().HDescent
text.Draw(screen, strings.Join(keyStrs, ", ")+"\n"+strings.Join(keyNames, ", "), fontFace, textOp)
}

View File

@ -86,7 +86,7 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(20, 20)
op.LineSpacingInPixels = 48
op.LineSpacing = 48
text.Draw(screen, "HelloこんにちはWorld世界\n日本語とEnglish…", g.face, op)
}

View File

@ -68,7 +68,7 @@ func (g *Game) Update() error {
// Initialize the glyphs for special (colorful) rendering.
if len(g.glyphs) == 0 {
op := &text.LayoutOptions{}
op.LineSpacingInPixels = mplusNormalFace.Size * 1.5
op.LineSpacing = mplusNormalFace.Size * 1.5
g.glyphs = text.AppendGlyphs(g.glyphs, sampleText, mplusNormalFace, op)
}
return nil
@ -83,7 +83,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
op := &text.DrawOptions{}
op.GeoM.Translate(x, y)
op.LineSpacingInPixels = mplusNormalFace.Size * 1.5
op.LineSpacing = mplusNormalFace.Size * 1.5
text.Draw(screen, sampleText, mplusNormalFace, op)
}
{
@ -92,7 +92,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
op := &text.DrawOptions{}
op.GeoM.Translate(x, y)
op.LineSpacingInPixels = mplusBigFace.Size * 1.5
op.LineSpacing = mplusBigFace.Size * 1.5
text.Draw(screen, sampleText, mplusBigFace, op)
}
{
@ -101,7 +101,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op.GeoM.Rotate(math.Pi / 4)
op.GeoM.Translate(x, y)
op.Filter = ebiten.FilterLinear
op.LineSpacingInPixels = mplusNormalFace.Size * 1.5
op.LineSpacing = mplusNormalFace.Size * 1.5
text.Draw(screen, sampleText, mplusNormalFace, op)
}
{
@ -113,7 +113,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Add the width as the text rendering region's upper-right position comes to (0, 0)
// when the horizontal alignment is right. The alignment is specified later (PrimaryAlign).
op.GeoM.Translate(x+w, y)
op.LineSpacingInPixels = lineSpacingInPixels
op.LineSpacing = lineSpacingInPixels
// The primary alignment for the left-to-right direction is a horizontal alignment, and the end means the right.
op.PrimaryAlign = text.AlignEnd
text.Draw(screen, sampleText, mplusBigFace, op)

View File

@ -195,7 +195,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
vector.DrawFilledRect(screen, float32(x), float32(y), float32(w), float32(h), gray, false)
op := &text.DrawOptions{}
op.GeoM.Translate(float64(x), float64(y))
op.LineSpacingInPixels = lineSpacing
op.LineSpacing = lineSpacing
text.Draw(screen, mongolianText, f, op)
}
{
@ -213,7 +213,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
vector.DrawFilledRect(screen, float32(x)-float32(w), float32(y), float32(w), float32(h), gray, false)
op := &text.DrawOptions{}
op.GeoM.Translate(float64(x), float64(y))
op.LineSpacingInPixels = lineSpacing
op.LineSpacing = lineSpacing
text.Draw(screen, japaneseText, f, op)
}
}

View File

@ -288,7 +288,7 @@ func (t *TextField) Draw(screen *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(float64(tx), float64(ty))
op.ColorScale.ScaleWithColor(color.Black)
op.LineSpacingInPixels = fontFace.Metrics().HLineGap + fontFace.Metrics().HAscent + fontFace.Metrics().HDescent
op.LineSpacing = fontFace.Metrics().HLineGap + fontFace.Metrics().HAscent + fontFace.Metrics().HDescent
text.Draw(screen, shownText, fontFace, op)
}

View File

@ -180,7 +180,7 @@ func (b *Button) Draw(dst *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(float64(b.Rect.Min.X+b.Rect.Max.X)/2, float64(b.Rect.Min.Y+b.Rect.Max.Y)/2)
op.ColorScale.ScaleWithColor(color.Black)
op.LineSpacingInPixels = lineSpacingInPixels
op.LineSpacing = lineSpacingInPixels
op.PrimaryAlign = text.AlignCenter
op.SecondaryAlign = text.AlignCenter
text.Draw(dst, b.Text, &text.GoTextFace{
@ -340,7 +340,7 @@ func (t *TextBox) Draw(dst *ebiten.Image) {
textOp.GeoM.Translate(x, y)
textOp.GeoM.Translate(float64(t.Rect.Min.X), float64(t.Rect.Min.Y))
textOp.ColorScale.ScaleWithColor(color.Black)
textOp.LineSpacingInPixels = lineSpacingInPixels
textOp.LineSpacing = lineSpacingInPixels
text.Draw(dst.SubImage(t.Rect).(*ebiten.Image), t.Text, &text.GoTextFace{
Source: uiFaceSource,
Size: uiFontSize,
@ -409,7 +409,7 @@ func (c *CheckBox) Draw(dst *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(float64(x), float64(y))
op.ColorScale.ScaleWithColor(color.Black)
op.LineSpacingInPixels = lineSpacingInPixels
op.LineSpacing = lineSpacingInPixels
op.PrimaryAlign = text.AlignStart
op.SecondaryAlign = text.AlignCenter
text.Draw(dst, c.Text, &text.GoTextFace{

View File

@ -46,8 +46,9 @@ type DrawOptions struct {
// PrimaryAlign and SecondaryAlign determine where to put the text in the given region at Draw.
// Draw might render the text outside of the specified image bounds, so you might have to specify GeoM to make the text visible.
type LayoutOptions struct {
// LineSpacingInPixels is a distance between two adjacent lines's baselines.
LineSpacingInPixels float64
// LineSpacing is a distance between two adjacent lines's baselines.
// The unit is in pixels.
LineSpacing float64
// PrimaryAlign is an alignment of the primary direction, in which a text in one line is rendered.
// The primary direction is the horizontal direction for a horizontal-direction face,
@ -184,10 +185,10 @@ func forEachLine(text string, face Face, options *LayoutOptions, f func(text str
var boundaryWidth, boundaryHeight float64
if d.isHorizontal() {
boundaryWidth = longestAdvance
boundaryHeight = float64(lineCount-1)*options.LineSpacingInPixels + m.HAscent + m.HDescent
boundaryHeight = float64(lineCount-1)*options.LineSpacing + m.HAscent + m.HDescent
} else {
// TODO: Perhaps HAscent and HDescent should be used for sideways glyphs.
boundaryWidth = float64(lineCount-1)*options.LineSpacingInPixels + m.VAscent + m.VDescent
boundaryWidth = float64(lineCount-1)*options.LineSpacing + m.VAscent + m.VDescent
boundaryHeight = longestAdvance
}
@ -267,13 +268,13 @@ func forEachLine(text string, face Face, options *LayoutOptions, f func(text str
// Advance the origin position in the secondary direction.
switch face.direction() {
case DirectionLeftToRight:
originY += options.LineSpacingInPixels
originY += options.LineSpacing
case DirectionRightToLeft:
originY += options.LineSpacingInPixels
originY += options.LineSpacing
case DirectionTopToBottomAndLeftToRight:
originX += options.LineSpacingInPixels
originX += options.LineSpacing
case DirectionTopToBottomAndRightToLeft:
originX -= options.LineSpacingInPixels
originX -= options.LineSpacing
}
}
}