ajstarks / svgo

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

Feature request: comments #27

Closed tjim closed 8 years ago

tjim commented 8 years ago

I'd like to able to place comments in the generated SVG.

ajstarks commented 8 years ago

You have access to the io.Writer, so you can use it to place your comments:

package main

import (
    "fmt"
    "io"
    "os"

    "github.com/ajstarks/svgo"
)

func comment(w io.Writer, s string) {
    fmt.Fprintf(w, "<!-- %s -->\n", s)
}

func main() {
    f, err := os.Create("foo.svg")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    canvas := svg.New(f)
    canvas.Start(100, 100)
    comment(f, "This is a comment")
    canvas.Rect(50, 50, 20, 30)
    canvas.End()
}