Closed JasonkayZK closed 3 years ago
Rotation occurs about the origin. You can try the RotateAbout function to rotate about a different location.
This does solve the problem. But new problem occurred when I was trying to create two different string:
F := 40.0
dc := gg.NewContext(500, 500)
dc.Clear()
str1 := "Hello 1"
if err := dc.LoadFontFace("Deng.ttf", F); err != nil {
panic(err)
}
dc.SetRGB(1, 0, 0)
dc.SetLineWidth(4)
w, h := dc.MeasureString(str1)
dc.RotateAbout(gg.Radians(30), 200-w/2, 200 - h/2)
dc.DrawString(str1, 200, 200)
dc.RotateAbout(gg.Radians(30), 200-w/2, 200 - h/2)
dc.DrawString("Hello 2", 200, 200)
dc.Fill()
_ = dc.SavePNG("out.png")
The result is below:
It seems that the second string is influenced by the first drawing. So i was wondering if there has any API that could draw the second string without being influenced by the frist RotateAbout
?
Use dc.Identity() to reset the transformation function. Alternatively, nest the transformations within dc.Push(), dc.Pop()
thanks, problem solved!
I try to draw two text in different rotation degrees, but i found it wrong that the text is not in the exact x, y which has been given:
The result img below:
Even the "Hello 2" is not in the image?!