svg

package
v0.9.14 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: BSD-3-Clause Imports: 30 Imported by: 11

Documentation

Overview

Package svg provides SVG rendering classes, I/O parsing: full SVG rendering

SVG currently supports most of SVG, but not:

  • Flow
  • Filter Effects
  • 3D Perspective transforms

See gi/examples/svg for a basic SVG viewer app, using the svg.Editor, which will ultimately be expanded to support more advanced editing. Also in that directory are a number of test files that stress different aspects of rendering.

svg.NodeBase is the base type for all SVG elements -- unlike Widget nodes, SVG nodes do not use layout logic, and just draw directly into a parent SVG viewport, with cumulative transforms determining drawing position, etc. The BBox values are only valid after rendering for these nodes.

It uses srwiley/rasterx for SVG-compatible rasterization, and the gi.Paint interface for drawing.

The Path element uses a compiled bytecode version of the Data path for increased speed.

Index

Constants

This section is empty.

Variables

View Source
var EditorProps = ki.Props{
	"EnumType:Flag": gi.KiT_VpFlags,
}
View Source
var IconAutoOpen = true

IconAutoOpen controls auto-loading of icons -- can turn this off for debugging etc

View Source
var IconProps = ki.Props{
	"EnumType:Flag":    gi.KiT_VpFlags,
	"background-color": color.Transparent,
}
View Source
var KiT_Circle = kit.Types.AddType(&Circle{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_ClipPath = kit.Types.AddType(&ClipPath{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Editor = kit.Types.AddType(&Editor{}, EditorProps)
View Source
var KiT_Ellipse = kit.Types.AddType(&Ellipse{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Filter = kit.Types.AddType(&Filter{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Flow = kit.Types.AddType(&Flow{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Group = kit.Types.AddType(&Group{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Icon = kit.Types.AddType(&Icon{}, IconProps)
View Source
var KiT_Line = kit.Types.AddType(&Line{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Marker = kit.Types.AddType(&Marker{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_MarkerUnits = kit.Enums.AddEnumAltLower(MarkerUnitsN, kit.NotBitFlag, gi.StylePropProps, "")
View Source
var KiT_NodeBase = kit.Types.AddType(&NodeBase{}, NodeBaseProps)
View Source
var KiT_Path = kit.Types.AddType(&Path{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_PathCmds = kit.Enums.AddEnumAltLower(PcErr, kit.NotBitFlag, nil, "Pc")
View Source
var KiT_Polygon = kit.Types.AddType(&Polygon{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_Polyline = kit.Types.AddType(&Polyline{}, nil)
View Source
var KiT_Rect = kit.Types.AddType(&Rect{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_SVG = kit.Types.AddType(&SVG{}, SVGProps)
View Source
var KiT_Text = kit.Types.AddType(&Text{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
View Source
var KiT_ViewBoxMeetOrSlice = kit.Enums.AddEnumAltLower(ViewBoxMeetOrSliceN, kit.NotBitFlag, gi.StylePropProps, "")
View Source
var NodeBaseProps = ki.Props{
	"base-type":     true,
	"EnumType:Flag": gi.KiT_NodeFlags,
}
View Source
var PathCmdMap = map[rune]PathCmds{
	'M': PcM,
	'm': Pcm,
	'L': PcL,
	'l': Pcl,
	'H': PcH,
	'h': Pch,
	'V': PcV,
	'v': Pcv,
	'C': PcC,
	'c': Pcc,
	'S': PcS,
	's': Pcs,
	'Q': PcQ,
	'q': Pcq,
	'T': PcT,
	't': Pct,
	'A': PcA,
	'a': Pca,
	'Z': PcZ,
	'z': Pcz,
}

PathCmdMap maps rune to path command

View Source
var PathCmdNMap = map[PathCmds]int{
	PcM: 2,
	Pcm: 2,
	PcL: 2,
	Pcl: 2,
	PcH: 1,
	Pch: 1,
	PcV: 1,
	Pcv: 1,
	PcC: 6,
	Pcc: 6,
	PcS: 4,
	Pcs: 4,
	PcQ: 4,
	Pcq: 4,
	PcT: 2,
	Pct: 2,
	PcA: 7,
	Pca: 7,
	PcZ: 0,
	Pcz: 0,
}

PathCmdNMap gives the number of points per each command

View Source
var SVGProps = ki.Props{
	"EnumType:Flag": gi.KiT_VpFlags,
}

Functions

func ApplyCSSSVG

func ApplyCSSSVG(node gi.Node2D, key string, css ki.Props) bool

ApplyCSSSVG applies css styles to given node, using key to select sub-props from overall properties list

func Asset added in v0.9.9

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir added in v0.9.9

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo added in v0.9.9

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames added in v0.9.9

func AssetNames() []string

AssetNames returns the names of the assets. nolint: deadcode

func MustAsset added in v0.9.9

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables. nolint: deadcode

func PathDataEnd

func PathDataEnd(data []PathData) (vec mat32.Vec2, ang float32)

PathDataEnd gets the ending coords and angle from the path

func PathDataIterFunc

func PathDataIterFunc(data []PathData, fun func(idx int, cmd PathCmds, ptIdx int, cx, cy float32) bool)

PathDataIterFunc traverses the path data and calls given function on each coordinate point, passing overall starting index of coords in data stream, command, index of the points within that command, and coord values (absolute, not relative, regardless of the command type) -- if function returns false, then traversal is aborted

func PathDataMinMax

func PathDataMinMax(data []PathData) (min, max mat32.Vec2)

PathDataMinMax traverses the path data and extracts the min and max point coords

func PathDataNext

func PathDataNext(data []PathData, i *int) float32

PathDataNext gets the next path data point, incrementing the index -- ++ not an expression so its clunky

func PathDataRender

func PathDataRender(data []PathData, pc *gi.Paint, rs *gi.RenderState)

PathDataRender traverses the path data and renders it using paint and render state -- we assume all the data has been validated and that n's are sufficient, etc

func PathDataStart

func PathDataStart(data []PathData) (vec mat32.Vec2, ang float32)

PathDataStart gets the starting coords and angle from the path

func PathDataValidate

func PathDataValidate(pc *gi.Paint, data *[]PathData, errstr string) error

PathDataValidate validates the path data and emits error messages on log

func RestoreAsset added in v0.9.9

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets added in v0.9.9

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func StyleCSS

func StyleCSS(node gi.Node2D, css ki.Props)

StyleCSS applies css style properties to given SVG node, parsing out type, .class, and #name selectors

func StyleSVG

func StyleSVG(gii gi.Node2D)

StyleSVG styles the Paint values directly from node properties -- no relevant default styling here -- parents can just set props directly as needed

Types

type Circle

type Circle struct {
	NodeBase
	Pos    mat32.Vec2 `xml:"{cx,cy}" desc:"position of the center of the circle"`
	Radius float32    `xml:"r" desc:"radius of the circle"`
}

Circle is a SVG circle

func AddNewCircle added in v0.9.7

func AddNewCircle(parent ki.Ki, name string, x, y, radius float32) *Circle

AddNewCircle adds a new button to given parent node, with given name, x,y pos, and radius.

func (*Circle) CopyFieldsFrom added in v0.9.8

func (g *Circle) CopyFieldsFrom(frm interface{})

func (*Circle) Render2D

func (g *Circle) Render2D()

type ClipPath

type ClipPath struct {
	NodeBase
}

ClipPath is used for holding a path that renders as a clip path

func AddNewClipPath added in v0.9.7

func AddNewClipPath(parent ki.Ki, name string) *ClipPath

AddNewClipPath adds a new clippath to given parent node, with given name.

func (*ClipPath) CopyFieldsFrom added in v0.9.8

func (g *ClipPath) CopyFieldsFrom(frm interface{})

type Editor

type Editor struct {
	SVG
	Trans         mat32.Vec2 `desc:"view translation offset (from dragging)"`
	Scale         float32    `desc:"view scaling (from zooming)"`
	SetDragCursor bool       `view:"-" desc:"has dragging cursor been set yet?"`
}

Editor supports editing of SVG elements

func AddNewEditor added in v0.9.7

func AddNewEditor(parent ki.Ki, name string) *Editor

AddNewEditor adds a new editor to given parent node, with given name.

func (*Editor) ConnectEvents2D added in v0.9.8

func (svg *Editor) ConnectEvents2D()

func (*Editor) CopyFieldsFrom added in v0.9.8

func (g *Editor) CopyFieldsFrom(frm interface{})

func (*Editor) EditorEvents

func (svg *Editor) EditorEvents()

EditorEvents handles svg editing events

func (*Editor) InitScale

func (svg *Editor) InitScale()

InitScale ensures that Scale is initialized and non-zero

func (*Editor) Render2D

func (svg *Editor) Render2D()

func (*Editor) SetTransform

func (svg *Editor) SetTransform()

SetTransform sets the transform based on Trans and Scale values

type Ellipse

type Ellipse struct {
	NodeBase
	Pos   mat32.Vec2 `xml:"{cx,cy}" desc:"position of the center of the ellipse"`
	Radii mat32.Vec2 `xml:"{rx,ry}" desc:"radii of the ellipse in the horizontal, vertical axes"`
}

Ellipse is a SVG ellipse

func AddNewEllipse added in v0.9.7

func AddNewEllipse(parent ki.Ki, name string, x, y, rx, ry float32) *Ellipse

AddNewEllipse adds a new button to given parent node, with given name, pos and radii.

func (*Ellipse) CopyFieldsFrom added in v0.9.8

func (g *Ellipse) CopyFieldsFrom(frm interface{})

func (*Ellipse) Render2D

func (g *Ellipse) Render2D()

type Filter

type Filter struct {
	NodeBase
	FilterType string
}

Filter represents SVG filter* elements

func AddNewFilter added in v0.9.7

func AddNewFilter(parent ki.Ki, name string) *Filter

AddNewFilter adds a new filter to given parent node, with given name.

func (*Filter) CopyFieldsFrom added in v0.9.8

func (g *Filter) CopyFieldsFrom(frm interface{})

type Flow

type Flow struct {
	NodeBase
	FlowType string
}

Flow represents SVG flow* elements

func AddNewFlow added in v0.9.7

func AddNewFlow(parent ki.Ki, name string) *Flow

AddNewFlow adds a new flow to given parent node, with given name.

func (*Flow) CopyFieldsFrom added in v0.9.8

func (g *Flow) CopyFieldsFrom(frm interface{})

type Group

type Group struct {
	NodeBase
}

Group groups together SVG elements -- doesn't do much but provide a locus for properties etc

func AddNewGroup added in v0.9.7

func AddNewGroup(parent ki.Ki, name string) *Group

AddNewGroup adds a new group to given parent node, with given name.

func (*Group) BBox2D

func (g *Group) BBox2D() image.Rectangle

func (*Group) BBoxFromChildren

func (g *Group) BBoxFromChildren() image.Rectangle

BBoxFromChildren sets the Group BBox from children

func (*Group) CopyFieldsFrom added in v0.9.8

func (g *Group) CopyFieldsFrom(frm interface{})

func (*Group) Render2D

func (g *Group) Render2D()

type Icon

type Icon struct {
	SVG
	Filename string      `desc:"file name with full path for icon if loaded from file"`
	Rendered bool        `` /* 169-byte string literal not displayed */
	RendSize image.Point `copy:"-" json:"-" xml:"-" desc:"size at which we previously rendered"`
}

svg.Icon is the actual SVG for a gi.Icon -- it should contain no color information -- it should just be a filled shape where the fill and stroke colors come from the surrounding context / paint settings. The rendered version is cached for a given size. Icons are always copied from an original source icon and then can be customized from there.

func AddNewIcon added in v0.9.7

func AddNewIcon(parent ki.Ki, name string) *Icon

AddNewIcon adds a new icon to given parent node, with given name.

func (*Icon) CopyFieldsFrom added in v0.9.8

func (ic *Icon) CopyFieldsFrom(frm interface{})

func (*Icon) CopyFromIcon

func (ic *Icon) CopyFromIcon(cp *Icon)

CopyFromIcon copies from a source icon, typically one from a library -- preserves all the existing render state etc for the current icon, so that only a new render is required

func (*Icon) Init2D

func (ic *Icon) Init2D()

func (*Icon) Layout2D

func (ic *Icon) Layout2D(parBBox image.Rectangle, iter int) bool

func (*Icon) NeedsReRender

func (ic *Icon) NeedsReRender() bool

NeedsReRender tests whether the last render parameters (size, color) have changed or not

func (*Icon) Render2D

func (ic *Icon) Render2D()

func (*Icon) Size2D

func (ic *Icon) Size2D(iter int)

type IconMgr

type IconMgr struct {
}

svg.IconMgr is THE implementation of the gi.IconMgr interface

func (*IconMgr) IconByName

func (im *IconMgr) IconByName(name string) (*Icon, error)

IconByName is main function to get icon by name -- looks in CurIconSet and falls back to DefaultIconSet if not found there -- returns error and logs a message if not found

func (*IconMgr) IconList

func (im *IconMgr) IconList(alphaSort bool) []gi.IconName

func (*IconMgr) IsValid

func (im *IconMgr) IsValid(iconName string) bool

func (*IconMgr) SetIcon

func (im *IconMgr) SetIcon(ic *gi.Icon, iconName string) error

type IconSet

type IconSet map[string]*Icon

IconSet is a collection of icons

var CurIconSet *IconSet

CurIconSet is the current icon set -- defaults to default but can be changed to whatever you want

var DefaultIconSet *IconSet

DefaultIconSet is the default icon set, initialized by default

func MakeDefaultIcons

func MakeDefaultIcons() *IconSet

func (*IconSet) IconList

func (iset *IconSet) IconList(alphaSort bool) []gi.IconName

IconList returns a list of names of icons in the icon set

func (*IconSet) OpenDefaultIcons

func (iset *IconSet) OpenDefaultIcons() error

func (*IconSet) OpenIconsFromAssetDir added in v0.9.9

func (iset *IconSet) OpenIconsFromAssetDir(path string, dirFunc func(path string) ([]string, error), assetFunc func(name string) ([]byte, error)) error

OpenIconsFromAssetDir loads icons using Asset and AssetDir funcs as generated by e.g., https://github.com/shuLhan/go-bindata or similar such forks of go-bindata

func (*IconSet) OpenIconsFromPath

func (iset *IconSet) OpenIconsFromPath(path string) error

OpenIconsFromPath scans for .svg icon files in given path, adding them to the given IconSet, just storing the filename for later lazy loading

type Line

type Line struct {
	NodeBase
	Start mat32.Vec2 `xml:"{x1,y1}" desc:"position of the start of the line"`
	End   mat32.Vec2 `xml:"{x2,y2}" desc:"position of the end of the line"`
}

Line is a SVG line

func AddNewLine added in v0.9.7

func AddNewLine(parent ki.Ki, name string, sx, sy, ex, ey float32) *Line

AddNewLine adds a new line to given parent node, with given name, st and end.

func (*Line) CopyFieldsFrom added in v0.9.8

func (g *Line) CopyFieldsFrom(frm interface{})

func (*Line) Render2D

func (g *Line) Render2D()

type Marker

type Marker struct {
	NodeBase
	RefPos      mat32.Vec2  `xml:"{refX,refY}" desc:"reference position to align the vertex position with, specified in ViewBox coordinates"`
	Size        mat32.Vec2  `xml:"{markerWidth,markerHeight}" desc:"size of marker to render, in Units units"`
	Units       MarkerUnits `xml:"markerUnits" desc:"units to use"`
	ViewBox     ViewBox     `desc:"viewbox defines the internal coordinate system for the drawing elements within the marker"`
	Orient      string      `xml:"orient" desc:"orientation of the marker -- either 'auto' or an angle"`
	VertexPos   mat32.Vec2  `desc:"current vertex position"`
	VertexAngle float32     `desc:"current vertex angle in radians"`
	StrokeWidth float32     `desc:"current stroke width"`
	XForm       mat32.Mat2  `desc:"net transform computed from settings and current values -- applied prior to rendering"`
	EffSize     mat32.Vec2  `desc:"effective size for actual rendering"`
}

Marker represents marker elements that can be drawn along paths (arrow heads, etc)

func AddNewMarker added in v0.9.7

func AddNewMarker(parent ki.Ki, name string) *Marker

AddNewMarker adds a new marker to given parent node, with given name.

func (*Marker) CopyFieldsFrom added in v0.9.8

func (g *Marker) CopyFieldsFrom(frm interface{})

func (*Marker) RenderMarker

func (mrk *Marker) RenderMarker(vertexPos mat32.Vec2, vertexAng, strokeWidth float32)

RenderMarker renders the marker using given vertex position, angle (in radians), and stroke width

type MarkerUnits

type MarkerUnits int32

MarkerUnits specifies units to use for svg marker elements

const (
	StrokeWidth MarkerUnits = iota
	UserSpaceOnUse
	MarkerUnitsN
)

func (*MarkerUnits) FromString

func (i *MarkerUnits) FromString(s string) error

func (MarkerUnits) MarshalJSON

func (ev MarkerUnits) MarshalJSON() ([]byte, error)

func (MarkerUnits) String

func (i MarkerUnits) String() string

func (*MarkerUnits) UnmarshalJSON

func (ev *MarkerUnits) UnmarshalJSON(b []byte) error

type NodeBase

type NodeBase struct {
	gi.Node2DBase
	Pnt gi.Paint `json:"-" xml:"-" desc:"full paint information for this node"`
}

svg.NodeBase is an element within the SVG sub-scenegraph -- does not use layout logic -- just renders into parent SVG viewport

func (*NodeBase) AsSVGNode

func (g *NodeBase) AsSVGNode() *NodeBase

func (*NodeBase) BBox2D

func (g *NodeBase) BBox2D() image.Rectangle

func (*NodeBase) ChildrenBBox2D

func (g *NodeBase) ChildrenBBox2D() image.Rectangle

func (*NodeBase) ComputeBBox2D

func (g *NodeBase) ComputeBBox2D(parBBox image.Rectangle, delta image.Point)

func (*NodeBase) ComputeBBoxSVG

func (g *NodeBase) ComputeBBoxSVG()

ComputeBBoxSVG is called by default in render to compute bounding boxes for gui interaction -- can only be done in rendering because that is when all the proper xforms are all in place -- VpBBox is intersected with parent SVG

func (*NodeBase) CopyFieldsFrom added in v0.9.8

func (g *NodeBase) CopyFieldsFrom(frm interface{})

func (*NodeBase) FindSVGURL

func (g *NodeBase) FindSVGURL(url string) gi.Node2D

FindSVGURL finds a url element in the parent SVG -- returns nil if not found -- can pass full 'url(#Name)' string

func (*NodeBase) Init2D

func (g *NodeBase) Init2D()

func (*NodeBase) Init2DBase

func (g *NodeBase) Init2DBase()

Init2DBase handles basic node initialization -- Init2D can then do special things

func (*NodeBase) Layout2D

func (g *NodeBase) Layout2D(parBBox image.Rectangle, iter int) bool

func (*NodeBase) Marker

func (g *NodeBase) Marker(marker string) *Marker

Marker checks for a marker property of given name, or generic "marker" type, and if set, attempts to find that marker and return it

func (*NodeBase) Move2D

func (g *NodeBase) Move2D(delta image.Point, parBBox image.Rectangle)

func (*NodeBase) Paint

func (g *NodeBase) Paint() *gi.Paint

Paint satisfies the painter interface

func (*NodeBase) ParentSVG

func (g *NodeBase) ParentSVG() *SVG

ParentSVG returns the parent SVG viewport

func (*NodeBase) Render2D

func (g *NodeBase) Render2D()

func (*NodeBase) Size2D

func (g *NodeBase) Size2D(iter int)

func (*NodeBase) Style2D

func (g *NodeBase) Style2D()

type Path

type Path struct {
	NodeBase
	Data     []PathData `` /* 171-byte string literal not displayed */
	DataStr  string     `xml:"d" desc:"string version of the path data"`
	MinCoord mat32.Vec2 `desc:"minimum coord in path -- computed in BBox2D"`
	MaxCoord mat32.Vec2 `desc:"maximum coord in path -- computed in BBox2D"`
}

Path renders SVG data sequences that can render just about anything

func AddNewPath added in v0.9.7

func AddNewPath(parent ki.Ki, name string, data string) *Path

AddNewPath adds a new button to given parent node, with given name and path data.

func (*Path) CopyFieldsFrom added in v0.9.8

func (g *Path) CopyFieldsFrom(frm interface{})

func (*Path) Render2D

func (g *Path) Render2D()

func (*Path) SetData

func (g *Path) SetData(data string) error

SetData sets the path data to given string, parsing it into an optimized form used for rendering

type PathCmds

type PathCmds byte

PathCmds are the commands within the path SVG drawing data type

const (
	// move pen, abs coords
	PcM PathCmds = iota
	// move pen, rel coords
	Pcm
	// lineto, abs
	PcL
	// lineto, rel
	Pcl
	// horizontal lineto, abs
	PcH
	// relative lineto, rel
	Pch
	// vertical lineto, abs
	PcV
	// vertical lineto, rel
	Pcv
	// Bezier curveto, abs
	PcC
	// Bezier curveto, rel
	Pcc
	// smooth Bezier curveto, abs
	PcS
	// smooth Bezier curveto, rel
	Pcs
	// quadratic Bezier curveto, abs
	PcQ
	// quadratic Bezier curveto, rel
	Pcq
	// smooth quadratic Bezier curveto, abs
	PcT
	// smooth quadratic Bezier curveto, rel
	Pct
	// elliptical arc, abs
	PcA
	// elliptical arc, rel
	Pca
	// close path
	PcZ
	// close path
	Pcz
	// error -- invalid command
	PcErr
)

func PathDataNextCmd

func PathDataNextCmd(data []PathData, i *int) (PathCmds, int)

PathDataNextCmd gets the next path data command, incrementing the index -- ++ not an expression so its clunky

func PathDecodeCmd

func PathDecodeCmd(r rune) PathCmds

PathDecodeCmd decodes rune into corresponding command

func (PathCmds) EncCmd

func (pc PathCmds) EncCmd(n int) PathData

EncCmd encodes command and n into PathData

func (*PathCmds) FromString

func (i *PathCmds) FromString(s string) error

func (PathCmds) MarshalJSON

func (ev PathCmds) MarshalJSON() ([]byte, error)

func (PathCmds) String

func (i PathCmds) String() string

func (*PathCmds) UnmarshalJSON

func (ev *PathCmds) UnmarshalJSON(b []byte) error

type PathData

type PathData float32

PathData encodes the svg path data, using 32-bit floats which are converted into uint32 for path commands, and contain the command as the first 5 bits, and the remaining 27 bits are the number of data points following the path command to interpret as numbers.

func PathDataParse

func PathDataParse(d string) ([]PathData, error)

PathDataParse parses a string representation of the path data into compiled path data

func (PathData) Cmd

func (pd PathData) Cmd() (PathCmds, int)

Cmd decodes path data as a command and a number of subsequent values for that command

type Polygon

type Polygon struct {
	NodeBase
	Points []mat32.Vec2 `` /* 137-byte string literal not displayed */
}

Polygon is a SVG polygon

func AddNewPolygon added in v0.9.7

func AddNewPolygon(parent ki.Ki, name string, points []mat32.Vec2) *Polygon

AddNewPolygon adds a new polygon to given parent node, with given name and points.

func (*Polygon) CopyFieldsFrom added in v0.9.8

func (g *Polygon) CopyFieldsFrom(frm interface{})

func (*Polygon) Render2D

func (g *Polygon) Render2D()

type Polyline

type Polyline struct {
	NodeBase
	Points []mat32.Vec2 `xml:"points" desc:"the coordinates to draw -- does a moveto on the first, then lineto for all the rest"`
}

Polyline is a SVG multi-line shape

func AddNewPolyline added in v0.9.7

func AddNewPolyline(parent ki.Ki, name string, points []mat32.Vec2) *Polyline

AddNewPolyline adds a new polyline to given parent node, with given name and points.

func (*Polyline) CopyFieldsFrom added in v0.9.8

func (g *Polyline) CopyFieldsFrom(frm interface{})

func (*Polyline) Render2D

func (g *Polyline) Render2D()

type Rect

type Rect struct {
	NodeBase
	Pos    mat32.Vec2 `xml:"{x,y}" desc:"position of the top-left of the rectangle"`
	Size   mat32.Vec2 `xml:"{width,height}" desc:"size of the rectangle"`
	Radius mat32.Vec2 `xml:"{rx,ry}" desc:"radii for curved corners, as a proportion of width, height"`
}

Rect is a SVG rectangle, optionally with rounded corners

func AddNewRect added in v0.9.7

func AddNewRect(parent ki.Ki, name string, x, y, sx, sy float32) *Rect

AddNewRect adds a new rectangle to given parent node, with given name, pos, and size.

func (*Rect) CopyFieldsFrom added in v0.9.8

func (g *Rect) CopyFieldsFrom(frm interface{})

func (*Rect) Render2D

func (g *Rect) Render2D()

type SVG

type SVG struct {
	gi.Viewport2D
	ViewBox ViewBox  `desc:"viewbox defines the coordinate system for the drawing"`
	Norm    bool     `` /* 130-byte string literal not displayed */
	InvertY bool     `` /* 181-byte string literal not displayed */
	Pnt     gi.Paint `json:"-" xml:"-" desc:"paint styles -- inherited by nodes"`
	Defs    Group    `desc:"all defs defined elements go here (gradients, symbols, etc)"`
	Title   string   `xml:"title" desc:"the title of the svg"`
	Desc    string   `xml:"desc" desc:"the description of the svg"`
}

SVG is a viewport for containing SVG drawing objects, corresponding to the svg tag in html -- it provides its own bitmap for drawing into. To trigger a full re-render of SVG, do SetNeedsFullRender() in UpdateStart / End loop.

func AddNewSVG added in v0.9.7

func AddNewSVG(parent ki.Ki, name string) *SVG

AddNewSVG adds a new svg viewport to given parent node, with given name.

func (*SVG) CopyFieldsFrom added in v0.9.8

func (svg *SVG) CopyFieldsFrom(frm interface{})

func (*SVG) DeleteAll

func (svg *SVG) DeleteAll()

DeleteAll deletes any existing elements in this svg

func (*SVG) FindNamedElement

func (svg *SVG) FindNamedElement(name string) gi.Node2D

func (*SVG) Init2D

func (svg *SVG) Init2D()

func (*SVG) Layout2D

func (svg *SVG) Layout2D(parBBox image.Rectangle, iter int) bool

func (*SVG) OpenXML

func (svg *SVG) OpenXML(filename string) error

OpenXML Opens XML-formatted SVG input from given file

func (*SVG) Paint

func (svg *SVG) Paint() *gi.Paint

Paint satisfies the painter interface

func (*SVG) ReadXML

func (svg *SVG) ReadXML(reader io.Reader) error

ReadXML reads XML-formatted SVG input from io.Reader, and uses xml.Decoder to create the SVG scenegraph for corresponding SVG drawing. Removes any existing content in SVG first. To process a byte slice, pass: bytes.NewReader([]byte(str)) -- all errors are logged and also returned. If this is being read into a live scenegraph, then you MUST call

svg.FullInit2DTree() after to initialize it for rendering.

func (*SVG) Render2D

func (svg *SVG) Render2D()

func (*SVG) SetDPIXForm

func (svg *SVG) SetDPIXForm()

SetDPIXForm sets a scaling transform to compensate for the dpi -- svg rendering is done within a 96 DPI context

func (*SVG) SetNormXForm

func (svg *SVG) SetNormXForm()

SetNormXForm sets a scaling transform to make the entire viewbox to fit the viewport

func (*SVG) Size2D

func (svg *SVG) Size2D(iter int)

func (*SVG) Style2D

func (svg *SVG) Style2D()

func (*SVG) StyleSVG

func (svg *SVG) StyleSVG()

func (*SVG) UnmarshalXML

func (svg *SVG) UnmarshalXML(decoder *xml.Decoder, se xml.StartElement) error

UnmarshalXML unmarshals the svg using xml.Decoder

type Text

type Text struct {
	NodeBase
	Pos          mat32.Vec2    `xml:"{x,y}" desc:"position of the left, baseline of the text"`
	Width        float32       `xml:"width" desc:"width of text to render if using word-wrapping"`
	Text         string        `xml:"text" desc:"text string to render"`
	Render       gi.TextRender `xml:"-" json:"-" desc:"render version of text"`
	CharPosX     []float32     `desc:"character positions along X axis, if specified"`
	CharPosY     []float32     `desc:"character positions along Y axis, if specified"`
	CharPosDX    []float32     `desc:"character delta-positions along X axis, if specified"`
	CharPosDY    []float32     `desc:"character delta-positions along Y axis, if specified"`
	CharRots     []float32     `desc:"character rotations, if specified"`
	TextLength   float32       `desc:"author's computed text length, if specified -- we attempt to match"`
	AdjustGlyphs bool          `desc:"in attempting to match TextLength, should we adjust glyphs in addition to spacing?"`
}

Text renders SVG text-- it handles both text and tspan elements (a tspan is just nested under a parent text)

func AddNewText added in v0.9.7

func AddNewText(parent ki.Ki, name string, x, y float32, text string) *Text

AddNewText adds a new text to given parent node, with given name, pos and text.

func (*Text) BBox2D

func (g *Text) BBox2D() image.Rectangle

func (*Text) CopyFieldsFrom added in v0.9.8

func (g *Text) CopyFieldsFrom(frm interface{})

func (*Text) Render2D

func (g *Text) Render2D()

type ViewBox

type ViewBox struct {
	Min                 mat32.Vec2                 `desc:"offset or starting point in parent Viewport2D"`
	Size                mat32.Vec2                 `desc:"size of viewbox within parent Viewport2D"`
	PreserveAspectRatio ViewBoxPreserveAspectRatio `desc:"how to scale the view box within parent Viewport2D"`
}

ViewBox is used in SVG to define the coordinate system

func (*ViewBox) Defaults

func (vb *ViewBox) Defaults()

Defaults returns viewbox to defaults

type ViewBoxAlign

type ViewBoxAlign int32

ViewBoxAlign defines values for the PreserveAspectRatio alignment factor

const (
	NoAlign ViewBoxAlign = 1 << iota          // do not preserve uniform scaling
	XMin                                      // align ViewBox.Min with smallest values of Viewport
	XMid                                      // align ViewBox.Min with midpoint values of Viewport
	XMax                                      // align ViewBox.Min+Size with maximum values of Viewport
	XMask   ViewBoxAlign = XMin + XMid + XMax // mask for X values -- clear all X before setting new one
	YMin    ViewBoxAlign = 1 << iota          // align ViewBox.Min with smallest values of Viewport
	YMid                                      // align ViewBox.Min with midpoint values of Viewport
	YMax                                      // align ViewBox.Min+Size with maximum values of Viewport
	YMask   ViewBoxAlign = YMin + YMid + YMax // mask for Y values -- clear all Y before setting new one
)

type ViewBoxMeetOrSlice

type ViewBoxMeetOrSlice int32

ViewBoxMeetOrSlice defines values for the PreserveAspectRatio meet or slice factor

const (
	// Meet means the entire ViewBox is visible within Viewport, and it is
	// scaled up as much as possible to meet the align constraints
	Meet ViewBoxMeetOrSlice = iota

	// Slice means the entire ViewBox is covered by the ViewBox, and the
	// ViewBox is scaled down as much as possible, while still meeting the
	// align constraints
	Slice

	ViewBoxMeetOrSliceN
)

func (*ViewBoxMeetOrSlice) FromString

func (i *ViewBoxMeetOrSlice) FromString(s string) error

func (ViewBoxMeetOrSlice) MarshalJSON added in v0.9.10

func (ev ViewBoxMeetOrSlice) MarshalJSON() ([]byte, error)

func (ViewBoxMeetOrSlice) String

func (i ViewBoxMeetOrSlice) String() string

func (*ViewBoxMeetOrSlice) UnmarshalJSON added in v0.9.10

func (ev *ViewBoxMeetOrSlice) UnmarshalJSON(b []byte) error

type ViewBoxPreserveAspectRatio

type ViewBoxPreserveAspectRatio struct {
	Align       ViewBoxAlign       `svg:"align" desc:"how to align x,y coordinates within viewbox"`
	MeetOrSlice ViewBoxMeetOrSlice `svg:"meetOrSlice" desc:"how to scale the view box relative to the viewport"`
}

ViewBoxPreserveAspectRatio determines how to scale the view box within parent Viewport2D

Jump to

Keyboard shortcuts

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