mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
text/v2: bug fix: given options were unexpectedly modified
Closes #2954
This commit is contained in:
parent
4d268f5ce4
commit
106f3e1a57
@ -105,16 +105,18 @@ func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) {
|
||||
options = &DrawOptions{}
|
||||
}
|
||||
|
||||
geoM := options.GeoM
|
||||
// Copy the options to avoid modifying the original options (#2954).
|
||||
drawOp := options.DrawImageOptions
|
||||
geoM := drawOp.GeoM
|
||||
|
||||
for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) {
|
||||
if g.Image == nil {
|
||||
continue
|
||||
}
|
||||
op := &options.DrawImageOptions
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(g.X, g.Y)
|
||||
op.GeoM.Concat(geoM)
|
||||
dst.DrawImage(g.Image, op)
|
||||
drawOp.GeoM.Reset()
|
||||
drawOp.GeoM.Translate(g.X, g.Y)
|
||||
drawOp.GeoM.Concat(geoM)
|
||||
dst.DrawImage(g.Image, &drawOp)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user