fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.34k stars 352 forks source link

Multi-line text not working #189

Open petric3 opened 11 months ago

petric3 commented 11 months ago

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!

web-xiaxia commented 11 months ago

you can use dc.DrawStringWrapped