diff --git a/text/v2/layout.go b/text/v2/layout.go index f99757f65..efe1d0b5d 100644 --- a/text/v2/layout.go +++ b/text/v2/layout.go @@ -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) } } diff --git a/text/v2/text_test.go b/text/v2/text_test.go index 707f1b1dd..46acf1106 100644 --- a/text/v2/text_test.go +++ b/text/v2/text_test.go @@ -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) + } +}