ajstarks / svgo

Go Language Library for SVG generation
Other
2.14k stars 169 forks source link

Help drawing a vertical text? #72

Closed decentral1se closed 9 months ago

decentral1se commented 9 months ago

I am unsure whether to use transform=rotate(...), TextPath (only example I can find uses bezier which I don't need) or RotateTranslate? Tried searching around for issues/examples but nothing that cleared it up for me. Just trying to do something like this:

image

ajstarks commented 9 months ago

Try this program, which uses TranslateRotate to change the origin to (250,250) (the middle of the canvas), and then rotate the text (now centered at the origin), 90 degrees. See also: https://speakerdeck.com/ajstarks/svgo-code-plus-picture-examples?slide=37

package main

import (
    "os"
    "github.com/ajstarks/svgo"
)

func main() {
    canvas := svg.New(os.Stdout)
    width := 500
    height := 500
    style := "font-size:48pt;fill:white;text-anchor:middle"

    canvas.Start(width, height)
    canvas.Rect(0,0,width,height)
    canvas.Circle(250,250,10,"fill:red")
    canvas.TranslateRotate(250,250,90)
    canvas.Text(0,0, "hello, world", style)
    canvas.Gend()
    canvas.End()
}

Produces: image

decentral1se commented 9 months ago

tysm @ajstarks :heart_decoration: