doc.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Package svg generates SVG as defined by the Scalable Vector Graphics 1.1 Specification (<http://www.w3.org/TR/SVG11/>).
  3. Output goes to the specified io.Writer.
  4. Supported SVG elements and functions
  5. Shapes, lines, text
  6. circle, ellipse, polygon, polyline, rect (including roundrects), line, text
  7. Paths
  8. general, arc, cubic and quadratic bezier paths,
  9. Image and Gradients
  10. image, linearGradient, radialGradient,
  11. Transforms
  12. translate, rotate, scale, skewX, skewY
  13. Filter Effects
  14. filter, feBlend, feColorMatrix, feColorMatrix, feComponentTransfer, feComposite, feConvolveMatrix, feDiffuseLighting,
  15. feDisplacementMap, feDistantLight, feFlood, feGaussianBlur, feImage, feMerge, feMorphology, feOffset, fePointLight,
  16. feSpecularLighting, feSpotLight,feTile, feTurbulence
  17. Metadata elements
  18. desc, defs, g (style, transform, id), mask, marker, pattern, title, (a)ddress, link, script, style, use
  19. Usage: (assuming GOPATH is set)
  20. go get github.com/ajstarks/svgo
  21. go install github.com/ajstarks/svgo/...
  22. You can use godoc to browse the documentation from the command line:
  23. $ godoc github.com/ajstarks/svgo
  24. a minimal program, to generate SVG to standard output.
  25. package main
  26. import (
  27. "github.com/ajstarks/svgo"
  28. "os"
  29. )
  30. func main() {
  31. width := 500
  32. height := 500
  33. canvas := svg.New(os.Stdout)
  34. canvas.Start(width, height)
  35. canvas.Circle(width/2, height/2, 100)
  36. canvas.Text(width/2, height/2, "Hello, SVG", "text-anchor:middle;font-size:30px;fill:white")
  37. canvas.End()
  38. }
  39. Drawing in a web server: (http://localhost:2003/circle)
  40. package main
  41. import (
  42. "log"
  43. "github.com/ajstarks/svgo"
  44. "net/http"
  45. )
  46. func main() {
  47. http.Handle("/circle", http.HandlerFunc(circle))
  48. err := http.ListenAndServe(":2003", nil)
  49. if err != nil {
  50. log.Fatal("ListenAndServe:", err)
  51. }
  52. }
  53. func circle(w http.ResponseWriter, req *http.Request) {
  54. w.Header().Set("Content-Type", "image/svg+xml")
  55. s := svg.New(w)
  56. s.Start(500, 500)
  57. s.Circle(250, 250, 125, "fill:none;stroke:black")
  58. s.End()
  59. }
  60. Functions and types
  61. Many functions use x, y to specify an object's location, and w, h to specify the object's width and height.
  62. Where applicable, a final optional argument specifies the style to be applied to the object.
  63. The style strings follow the SVG standard; name:value pairs delimited by semicolons, or a
  64. series of name="value" pairs. For example: `"fill:none; opacity:0.3"` or `fill="none" opacity="0.3"` (see: <http://www.w3.org/TR/SVG11/styling.html>)
  65. The SVG type:
  66. type SVG struct {
  67. Writer io.Writer
  68. }
  69. Most operations are methods on this type, specifying the destination io.Writer.
  70. The Offcolor type:
  71. type Offcolor struct {
  72. Offset uint8
  73. Color string
  74. Opacity float64
  75. }
  76. is used to specify the offset, color, and opacity of stop colors in linear and radial gradients
  77. The Filterspec type:
  78. type Filterspec struct {
  79. In string
  80. In2 string
  81. Result string
  82. }
  83. is used to specify inputs and results for filter effects
  84. */
  85. package svg