svg

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeText

func EncodeText(raw string, alignment HAlignment) string

EncodeText applies proper xml escaping and svg line breaking at each newline in the raw text and returns a section ready for inclusion in a <text> element. NOTE: Line breaking is kind of hacky, since we cannot actually measure text in SVG, and assume that all characters are 1ex wide.

Types

type HAlignment

type HAlignment string

HAlignment is the type for the horizontal alignment constants

const (
	HAlignStart  HAlignment = "start"
	HAlignMiddle HAlignment = "middle"
	HAlignEnd    HAlignment = "end"
)

Horizontal text alignment constants

type SVG

type SVG struct {
	// contains filtered or unexported fields
}

SVG builds SVG format images using a small subset of the standard

func New

func New(width int, height int, background string) *SVG

New - SVG constructor

func (*SVG) Alignment

func (svg *SVG) Alignment(horizontal HAlignment, vertical VAlignment) *SVG

Alignment sets current text alignment

func (*SVG) Child

func (svg *SVG) Child(x, y float64) *SVG

Child adds a sub-SVG at x, y

func (*SVG) Close

func (svg *SVG) Close() *SVG

Close closes a child SVG and returns the parent. If the current SVG is not a child, this is a noop.

func (*SVG) Color

func (svg *SVG) Color(color string) *SVG

Color sets current stroke and fill

func (*SVG) Fill

func (svg *SVG) Fill(fill string) *SVG

Fill sets current fill style

func (*SVG) Font

func (svg *SVG) Font(font string, size string) *SVG

Font sets current font family and size

func (*SVG) FontStyle

func (svg *SVG) FontStyle(style Style, weight Weight) *SVG

FontStyle sets the current font style and weight

func (*SVG) Marker

func (svg *SVG) Marker(marker string) *SVG

Marker adds start, mid and end markers to all following strokes. The specified marker has to be one of "circle" and "square". Setting the marker to the empty string clears the marker.

func (*SVG) Path

func (svg *SVG) Path(path string) *SVG

Path adds a SVG style path

func (*SVG) Polyline

func (svg *SVG) Polyline(points ...struct{ X, Y float64 }) *SVG

Polyline adds a polyline from a list of points

func (*SVG) Rect

func (svg *SVG) Rect(x, y, width, height float64) *SVG

Rect adds a rect defined by x, y, width and height

func (*SVG) Render

func (svg *SVG) Render() string

Render generates SVG code for the current image, and clears the canvas

func (*SVG) SetSize added in v0.3.0

func (svg *SVG) SetSize(width, height int)

SetSize of SVG, redefining the value given during construction.

func (*SVG) Stroke

func (svg *SVG) Stroke(stroke string) *SVG

Stroke sets current stroke

func (*SVG) StrokeWidth

func (svg *SVG) StrokeWidth(width string) *SVG

StrokeWidth sets current stroke width

func (*SVG) Text

func (svg *SVG) Text(x, y float64, txt string) *SVG

Text draws text at x, y

func (*SVG) Transform

func (svg *SVG) Transform(transforms ...Transform) *SVG

Transform sets the current list of transforms that will be used by the next set of drawing operations. Specifying no transforms resets the transformation matrix to identity.

type Style

type Style string

Style is the type for the text style constants

const (
	StyleNormal Style = "normal"
	StyleItalic Style = "italic"
)

Text style constants

type Transform

type Transform struct {
	// contains filtered or unexported fields
}

Transform represents a transform function

func Rotation

func Rotation(angle, x, y float64) Transform

Rotation rotates by angle degrees clockwise around (x, y)

func Scaling

func Scaling(xScale, yScale float64) Transform

Scaling scales by (xScale, yScale)

func Translation

func Translation(x, y float64) Transform

Translation moves by (x, y)

type VAlignment

type VAlignment string

VAlignment is the type for the vertical alignment constants

const (
	VAlignTop     VAlignment = "hanging"
	VAlignCentral VAlignment = "middle"
	VAlignBottom  VAlignment = "baseline"
)

Vertical text alignment constants

type Weight

type Weight string

Weight is the type for the text weight constants

const (
	WeightNormal  Weight = "normal"
	WeightBold    Weight = "bold"
	WeightLighter Weight = "lighter"
)

Text weight constants

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL