Documentation ¶
Overview ¶
Package tinysvg has structs and functions for creating and rendering TinySVG images
Package tinysvg supports generating and writing TinySVG 1.2 images ¶
Some function names are suffixed with "2" if they take structs instead of ints/floats, "i" if they take ints and "f" if they take floats. Using generics might be an option.
Index ¶
- Constants
- Variables
- func ColorBytes(r, g, b int) []byte
- func ColorBytesAlpha(r, g, b int, a float64) []byte
- func NewTinySVG(w, h int) (*Document, *Tag)
- func NewTinySVG2(p *Pos, s *Size) (*Document, *Tag)
- func NewTinySVGf(x, y, w, h float64) (*Document, *Tag)
- func NewTinySVGi(x, y, w, h int) (*Document, *Tag)
- func RGBABytes(r, g, b int, a float64) []byte
- func RGBBytes(r, g, b int) []byte
- type Color
- type Document
- func (image *Document) AddContent(content []byte) (*Tag, error)
- func (image *Document) Bytes() []byte
- func (image *Document) GetRoot() *Tag
- func (image *Document) GetTag(name []byte) (*Tag, error)
- func (image *Document) SaveSVG(filename string) error
- func (image *Document) String() string
- func (image *Document) WriteTo(w io.Writer) (int64, error)
- type Font
- type Pos
- type Radius
- type Size
- type Tag
- func (tag *Tag) AddAttrib(attrName string, attrValue []byte)
- func (tag *Tag) AddAttribMap(attrMap map[string][]byte)
- func (tag *Tag) AddChild(child *Tag)
- func (svg *Tag) AddCircle(x, y, radius int) *Tag
- func (svg *Tag) AddCirclef(x, y, radius float64) *Tag
- func (tag *Tag) AddContent(content []byte)
- func (svg *Tag) AddEllipse(x, y, rx, ry int) *Tag
- func (svg *Tag) AddEllipsef(x, y, rx, ry float64) *Tag
- func (tag *Tag) AddLastContent(content []byte)
- func (tag *Tag) AddNewTag(name []byte) *Tag
- func (svg *Tag) AddRect(x, y, w, h int) *Tag
- func (svg *Tag) AddRectf(x, y, w, h float64) *Tag
- func (svg *Tag) AddRoundedRect(x, y, rx, ry, w, h int) *Tag
- func (svg *Tag) AddRoundedRectf(x, y, rx, ry, w, h float64) *Tag
- func (tag *Tag) AddSingularAttrib(attrName string)
- func (tag *Tag) AddTag(child *Tag)
- func (svg *Tag) AddText(x, y, fontSize int, fontFamily, text string) *Tag
- func (svg *Tag) AlphaDot(x, y, r, g, b int, a float32) *Tag
- func (tag *Tag) AppendContent(content []byte)
- func (svg *Tag) Box(x, y, w, h int, color string) *Tag
- func (tag *Tag) Bytes() []byte
- func (svg *Tag) Circle(x, y, radius int, color string) *Tag
- func (svg *Tag) Circle2(p *Pos, radius int, c *Color) *Tag
- func (svg *Tag) Circlef(p *Pos, radius float64, c *Color) *Tag
- func (tag *Tag) CountChildren() int
- func (tag *Tag) CountSiblings() int
- func (svg *Tag) Describe(description string)
- func (svg *Tag) Dot(x, y, r, g, b int) *Tag
- func (svg *Tag) Ellipse(x, y, xr, yr int, color string) *Tag
- func (svg *Tag) Ellipse2(p *Pos, r *Radius, c *Color) *Tag
- func (svg *Tag) Fill(color string)
- func (svg *Tag) Fill2(c *Color)
- func (svg *Tag) Focusable(yes bool, auto bool)
- func (tag *Tag) GetAttrString() []byte
- func (tag *Tag) GetChildren() []*Tag
- func (tag *Tag) GetTag(name []byte) (*Tag, error)
- func (tag *Tag) LastChild() *Tag
- func (svg *Tag) Line(x1, y1, x2, y2, thickness int, color string) *Tag
- func (svg *Tag) Line2(p1, p2 *Pos, thickness int, c *Color) *Tag
- func (svg *Tag) Pixel(x, y, r, g, b int) *Tag
- func (svg *Tag) Poly2(p1, p2, p3, p4 *Pos, c *Color) *Tag
- func (svg *Tag) Poly4(x1, y1, x2, y2, x3, y3, x4, y4 int, color string) *Tag
- func (svg *Tag) Polygon(points []*Pos, c *Color) *Tag
- func (svg *Tag) Polyline(points []*Pos, c *Color) *Tag
- func (svg *Tag) Rect2(p *Pos, s *Size, c *Color) *Tag
- func (svg *Tag) RoundedRect2(p *Pos, r *Radius, s *Size, c *Color) *Tag
- func (tag *Tag) ShallowCopy() *Tag
- func (tag *Tag) String() string
- func (svg *Tag) Stroke2(c *Color)
- func (svg *Tag) Text(x, y, fontSize int, fontFamily, text, color string) *Tag
- func (svg *Tag) Text2(p *Pos, f *Font, message string, c *Color) *Tag
- func (svg *Tag) Thickness(thickness int)
- func (svg *Tag) Triangle(x1, y1, x2, y2, x3, y3 int, color string) *Tag
- func (svg *Tag) Triangle2(p1, p2, p3 *Pos, c *Color) *Tag
- func (tag *Tag) WriteTo(w io.Writer) (n int64, err error)
- type Vec2
- type YesNoAuto
Constants ¶
const ( TRANSPARENT = 0.0 OPAQUE = 1.0 NO = iota YES AUTO )
Variables ¶
var (
ErrPair = errors.New("position pairs must be exactly two comma separated numbers")
)
Functions ¶
func ColorBytes ¶
ColorBytes converts r, g and b (integers in the range 0..255) to a color string on the form "#nnnnnn".
func ColorBytesAlpha ¶
ColorBytesAlpha converts integers r, g and b (the color) and also a given alpha (opacity) to a color-string on the form "rgba(255, 255, 255, 1.0)".
func NewTinySVG ¶
NewTinySVG will create a new TinySVG document, where the width and height is defined in pixels, using the "px" suffix.
func NewTinySVG2 ¶
NewTinySVG2 creates new TinySVG 1.2 image. Pos and Size defines the viewbox
func NewTinySVGf ¶
func NewTinySVGi ¶
Types ¶
type Color ¶
type Color struct {
R, G, B int // red, green, blue (0..255)
A float64 // alpha, 0.0..1.0
N string // name (optional, will override the above values)
}
func ColorByName ¶
ColorByName creates a new Color with a given name, like "blue"
func RGB ¶
RGB creates a new Color with the given red, green and blue values. The colors are in the range 0..255.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is an XML document, with a title and a root tag
func NewDocument ¶
NewDocument creates a new XML/HTML/SVG image, with a root tag. If rootTagName contains "<" or ">", it can be used for preceding declarations, like <!DOCTYPE html> or <?xml version=\"1.0\"?>. Returns a pointer to a Document.
func (*Document) AddContent ¶
AddContent adds content to the body tag. Returns the body tag and nil if successful. Returns and an error if no body tag is found, else nil.
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
Tag represents an XML tag, as part of a larger XML document
func NewTag ¶
NewTag creates a new tag based on the given name. "name" is what will appear right after "<" when rendering as XML/HTML/SVG.
func (*Tag) AddAttribMap ¶ added in v1.0.2
AddAttribMap adds attributes based on a given map
func (*Tag) AddCircle ¶
AddCircle adds a circle Add a circle, given a position (x, y) and a radius. No color is being set.
func (*Tag) AddCirclef ¶
AddCirclef adds a circle Add a circle, given a position (x, y) and a radius. No color is being set.
func (*Tag) AddContent ¶
AddContent adds text to a tag. This is what will appear between two tag markers, for example: <tag>content</tag> If the tag contains child tags, they will be rendered after this content.
func (*Tag) AddEllipse ¶
AddEllipse adds an ellipse with a given position (x,y) and radius (rx, ry). No color is being set.
func (*Tag) AddEllipsef ¶
AddEllipsef adds an ellipse with a given position (x,y) and radius (rx, ry). No color is being set.
func (*Tag) AddLastContent ¶
AddLastContent appends content to the end of the existing content of a tag. Deprecated.
func (*Tag) AddNewTag ¶
AddNewTag adds a new tag to another tag. This will place it one step lower in the hierarchy of tags. You can for example add a body tag to an html tag.
func (*Tag) AddRect ¶
AddRect adds a rectangle, given x and y position, width and height. No color is being set.
func (*Tag) AddRectf ¶
AddRectf adds a rectangle, given x and y position, width and height. No color is being set.
func (*Tag) AddRoundedRect ¶
AddRoundedRect adds a rectangle, given x and y position, radius x, radius y, width and height. No color is being set.
func (*Tag) AddRoundedRectf ¶
AddRoundedRectf adds a rectangle, given x and y position, radius x, radius y, width and height. No color is being set.
func (*Tag) AddSingularAttrib ¶
AddSingularAttrib adds attribute without a value
func (*Tag) AlphaDot ¶
AlphaDot creates a small circle that can be transparent. Takes a position (x, y) and a color (r, g, b, a).
func (*Tag) AppendContent ¶
AppendContent appends content to the end of the existing content of a tag
func (*Tag) Bytes ¶
Bytes (previously getXMLRecursively) renders XML for a tag, recursively. The generated XML is returned as a []byte.
func (*Tag) CountChildren ¶
CountChildren returns the number of children a tag has
func (*Tag) CountSiblings ¶
CountSiblings returns the number of siblings a tag has
func (*Tag) Focusable ¶
Focusable sets the "focusable" attribute to either true, false or auto If "auto" is true, it overrides the value of "yes".
func (*Tag) GetAttrString ¶
GetAttrString returns a []byte that represents all the attribute keys and values of a tag. This can be used when generating XML, SVG or HTML.
func (*Tag) GetChildren ¶
GetChildren returns all children for a given tag. Returns a slice of pointers to tags.
func (*Tag) GetTag ¶
GetTag finds a tag by name and returns an error if not found. Returns the first tag that matches.
func (*Tag) Pixel ¶
Pixel creates a rectangle that is 1 wide with the given color. Note that the size of the "pixel" depends on how large the viewBox is.
func (*Tag) Rect2 ¶
Rect2 creates a rectangle, given x and y position, width and height. No color is being set.
func (*Tag) RoundedRect2 ¶
RoundedRect2 a rectangle, given x and y position, width and height. No color is being set.
func (*Tag) ShallowCopy ¶ added in v1.1.0
ShallowCopy creates a copy of a tag, but uses the same attribute map!