gg icon indicating copy to clipboard operation
gg copied to clipboard

Multi-line text not working

Open petric3 opened this issue 2 years ago • 1 comments

Thank you for the great package. I try to study it and make some multi-line text, but it seems I cannot make it work. This is my code:

func main() {
        text := "Hello, World! \nHello, World! \nHello, World!"
	
	// const S = 1024
	const W, H = 1024, 1024
	dc := gg.NewContext(W, H)
	dc.SetRGB(1, 1, 1)
	dc.Clear()
	dc.SetRGB(0, 0, 0)
	if err := dc.LoadFontFace("/home/oem/Downloads/Verdana.ttf", 39); err != nil {
		panic(err)
	}
	dc.DrawStringAnchored(text, W/2, H/2, 0.5, 0.5)
	dc.SavePNG("out.png")
}

And this is the result: out

I also tried for example:

text := `Hello, World! 
Hello, World! 
Hello, World! 
`

but the result is the same. Is there any other way that I don't know of? Thank you!

petric3 avatar Aug 02 '23 00:08 petric3

you can use dc.DrawStringWrapped

web-xiaxia avatar Aug 20 '23 14:08 web-xiaxia