Compare commits

..

3 Commits

Author SHA1 Message Date
Hajime Hoshi
229a8d6cfd all: update PureGo 2024-04-08 02:24:25 +09:00
Hajime Hoshi
c9a3ef28eb text/v2: avoid creating an option struct when the given option is nil 2024-04-07 22:28:21 +09:00
Hajime Hoshi
2b9e307ec2 text/v2: bug fix: given options were unexpectedly modified
Closes #2954
2024-04-07 22:16:17 +09:00
4 changed files with 31 additions and 12 deletions

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8 github.com/ebitengine/gomobile v0.0.0-20240329170434-1771503ff0a8
github.com/ebitengine/hideconsole v1.0.0 github.com/ebitengine/hideconsole v1.0.0
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 github.com/ebitengine/oto/v3 v3.3.0-alpha.1
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393 github.com/ebitengine/purego v0.8.0-alpha.0.20240407111646-0e6302132b78
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 github.com/hajimehoshi/bitmapfont/v3 v3.0.0
github.com/hajimehoshi/go-mp3 v0.3.4 github.com/hajimehoshi/go-mp3 v0.3.4

4
go.sum
View File

@ -4,8 +4,8 @@ github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A= github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk= github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg= github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393 h1:8mFaXjlt/DLC5MlrnsR71EpK196kVYvPTC2soh06rGU= github.com/ebitengine/purego v0.8.0-alpha.0.20240407111646-0e6302132b78 h1:9uNVUYEdJkmroySbiQL0sfhZvCYeZaF3os6WuLY1PEQ=
github.com/ebitengine/purego v0.8.0-alpha.0.20240404024320-d0aedd0f4393/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM= github.com/ebitengine/purego v0.8.0-alpha.0.20240407111646-0e6302132b78/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM=
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog= github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog=
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I= github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY= github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=

View File

@ -101,20 +101,24 @@ type LayoutOptions struct {
// If the vertical alignment is center, the rendering region's middle Y comes to the origin. // If the vertical alignment is center, the rendering region's middle Y comes to the origin.
// If the vertical alignment is bottom, the rendering region's bottom Y comes to the origin. // If the vertical alignment is bottom, the rendering region's bottom Y comes to the origin.
func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) { func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) {
if options == nil { var layoutOp LayoutOptions
options = &DrawOptions{} var drawOp ebiten.DrawImageOptions
if options != nil {
layoutOp = options.LayoutOptions
drawOp = options.DrawImageOptions
} }
geoM := options.GeoM geoM := drawOp.GeoM
for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) {
for _, g := range AppendGlyphs(nil, text, face, &layoutOp) {
if g.Image == nil { if g.Image == nil {
continue continue
} }
op := &options.DrawImageOptions drawOp.GeoM.Reset()
op.GeoM.Reset() drawOp.GeoM.Translate(g.X, g.Y)
op.GeoM.Translate(g.X, g.Y) drawOp.GeoM.Concat(geoM)
op.GeoM.Concat(geoM) dst.DrawImage(g.Image, &drawOp)
dst.DrawImage(g.Image, op)
} }
} }

View File

@ -356,3 +356,18 @@ func TestConvertToFloat(t *testing.T) {
} }
} }
} }
// Issue #2954
func TestDrawOptionsNotModified(t *testing.T) {
img := ebiten.NewImage(30, 30)
op := &text.DrawOptions{}
text.Draw(img, "Hello", text.NewGoXFace(bitmapfont.Face), op)
if got, want := op.GeoM, (ebiten.GeoM{}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
if got, want := op.ColorScale, (ebiten.ColorScale{}); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}