8000 GitHub - qAison/svgo at log
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

qAison/svgo

 
 

Repository files navigation

=A Go library for SVG generation=

The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification (http://www.w3.org/TR/SVG11/).  Output is to a specified io.Writer

== Supported SVG elements ==

 circle, ellipse, polygon, polyline, rect (including roundrects), paths (arc,
 cubic and quadratic bezier paths), line, image, text, 

== Metadata elements ==

 desc, defs, g (style, transform, id), title, (a)ddress, use

== Building and Usage ==

See svgdef.[svg|png|pdf] for a graphical view of the function calls

Usage: (where $GC and $GL are the Go compiler and linker for your targer architecture, $A)

  $ $GC svg.go  = compile the library
  $ $GC svgdef.go && $GL -o svgdef svgdef.$A  # compile a client program
  $ ./svgdef    = run the client program

a minimal program:

package main

import (
  svglib "./svg"
  "os"
)

var (
  width = 500
  height = 500
  svg = svglib.New(os.Stdout)
)

func main() {
  svg.Start(width, height)
  svg.Circle(width/2, height/2, 100)
  svg.Text(width/2, height/2, "Hello, SVG", "text-anchor;font-size:30;fill:white")
  svg.End()
}


You may view the SVG output with a browser that supports SVG (tested on Chrome, Opera, Firefox and Safari), or any other SVG user-agent such as Batik Squiggle.  The test-svgo script tries to use reasonable defaults based on the GOOS and GOARCH environment variables

The command:

   $ ./newsvg foo.go
   
creates a template Go source file ready for your code, using $EDITOR

== Package contents ==

svg.go        Library
test-svgo     Compiles the library, builds the clients and displays the results
newsvg        Coding template command
svgdef.go     Creates a SVG representation of the API
flower.go     Random "flowers"
funnel.go     Funnel from transparent circles
imfade.go     Show image fading
lewitt.go     Version of Sol Lewitt's Wall Drawing 91
planets.go    Show the scale of the Solar system
randcomp.go   Compare random number generators
richter.go    Gerhard Richter's 256 colors
rl.go         Random lines (port of a Processing demo)
vismem.go     Visualize data from files
images/*      Images used by the client programs


== Functions ==

Many functions use x, y to specify an object's location, and w, h to specify the object's width and height.
Where applicable, a final optional argument specifies the style to be applied to the object. 
The style strings follow the SVG standard; name:value pairs delimited by semicolons.
For example:"fill:none; opacity:0.3" (see: http://www.w3.org/TR/SVG11/styling.html)


=== Structure, Metadata and Links ===

New(w io.Writer) *SVG
  Constructor, Specify the output destination
  
Start(w int, h int)
  begin the SVG document with the width w and height h
  http://www.w3.org/TR/SVG11/struct.html#SVGElement

End()
  end the SVG document         

Gstyle(s string)
  begin a group, with the specified style
  http://www.w3.org/TR/SVG11/struct.html#GElement

Gtransform(s string)
  begin a group, with the specified transform

Gid(s string)
  begin a group, with the specified id

Gend()
  end the group (must be paired with Gstyle, Gtransform, Gid)

Def()
  begin a definition block
  http://www.w3.org/TR/SVG11/struct.html#DefsElement

DefEnd()
  end a definition block

Desc(s string)
  specify the text of the description
  http://www.w3.org/TR/SVG11/struct.html#DescElement

Title(s string)
  specify the text of the title
  http://www.w3.org/TR/SVG11/struct.html#Titl
7060
eElement

Link(name string, title string)
  begin a link named "name", with the specified title
  http://www.w3.org/TR/SVG11/linking.html#Links

LinkEnd()
  end the link

Use(x int, y int, link string, s ...string)
  place the object referenced at link at the location x, y
  http://www.w3.org/TR/SVG11/struct.html#UseElement

=== Shapes ===

Circle(x int, y int, r int, s ...string)
  draw a circle, centered at x,y with radius r
  http://www.w3.org/TR/SVG11/shapes.html#CircleElement
  
Ellipse(x int, y int, w int, h int, s ...string)
  draw an ellipse, centered at x,y with radii w, and h
  http://www.w3.org/TR/SVG11/shapes.html#EllipseElement

Polygon(x []int, y []int, s ...string)
  draw a series of line segments using an array of x, y coordinates
  http://www.w3.org/TR/SVG11/shapes.html#PolygonElement

Rect(x int, y int, w int, h int, s ...string)
  draw a rectangle with upper left-hand corner at x,y, with width w, and height h
  http://www.w3.org/TR/SVG11/shapes.html#RectElement

Roundrect(x int, y int, w int, h int, rx int, ry int, s ...string)
  draw a rounded rectangle with upper the left-hand corner at x,y, 
  with width w, and height h. The radii for the rounded portion 
  is specified by rx (width), and ry (height)
  
Square(x int, y int, s int, style ...string)
  draw a square with upper left corner at x,y with sides of length s

=== Paths ===

Arc(sx int, sy int, ax int, ay int, r int, large bool, sweep bool, ex int, ey int, s ...string)
  draw an elliptical arc beginning coordinate at sx,sy, ending coordinate at ex, ey
  width and height of the arc are specified by ax, ay, the x axis rotation is r
  if sweep is true, then the arc will be drawn in a "positive-angle" direction (clockwise), if false,
  the arc is drawn counterclockwise.
  if large is true, the arc sweep angle is greater than or equal to 180 degrees, 
  otherwise the arc sweep is less than 180 degrees
  http://www.w3.org/TR/SVG11/paths.html#PathDataEllipticalArcCommands

Bezier(sx int, sy int, cx int, cy int, px int, py int, ex int, ey int, s ...string)
  draw a cubic bezier curve, beginning at sx,sy, ending at ex,ey
  with control points at cx,cy and px,py
  http://www.w3.org/TR/SVG11/paths.html#PathDataCubicBezierCommands

Qbezier(sx int, sy int, cx int, cy int, ex int, ey int, tx int, ty int, s ...string)
  draw a quadratic bezier curve, beginning at sx, sy, ending at tx,ty
  with control points are at cx,cy, ex,ey
  http://www.w3.org/TR/SVG11/paths.html#PathDataQuadraticBezierCommands

=== Lines ===

Line(x1 int, y1 int, x2 int, y2 int, s ...string)
  draw a line segment between x1,y1 and x2,y2
  http://www.w3.org/TR/SVG11/shapes.html#LineElement
  
Polyline(x []int, y []int, s ...string)
  draw a polygon using coordinates specified in x,y arrays
  http://www.w3.org/TR/SVG11/shapes.html#PolylineElement

=== Image and Text ===

Image(x int, y int, w int, h int, link string, s ...string) 
  place at x,y (upper left hand corner), the image with width w, and height h, referenced at link
  http://www.w3.org/TR/SVG11/struct.html#ImageElement

Text(x int, y int, t string, s ...string)
  Place the specified text, t at x,y according to the style specified in s
  http://www.w3.org/TR/SVG11/text.html#TextElement

=== Color ===

RGB(r int, g int, b int) string 
  creates a style string for the fill color designated 
  by the (r)ed, g(reen), (b)lue components
  http://www.w3.org/TR/css3-color/
  
RGBA(r int, g int, b int, a float) string
  as above, but includes the color's opacity as a value
  between 0.0 (fully transparent) and 1.0 (opaque)

=== Utility ===

Grid(x int, y int, w int, h int, n int, s ...string)
  draws a grid of straight lines starting at x,y, with a width w, and height h, and a size of n

About

Go Language Library for SVG generation

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-link.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 97.1%
  • HTML 2.1%
  • Other 0.8%
0