svg

package module
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: BSD-3-Clause Imports: 38 Imported by: 2

README

svg

SVG implements the Scalable Vector Graphics standard, rendering onto a Go standard image bitmap.

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

View Source
const (
	// Version is the version of this package being used
	Version = "v0.1.28"
	// GitCommit is the commit just before the latest version commit
	GitCommit = "b0c8aa8"
	// VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04')
	VersionDate = "2023-12-26 23:35"
)
View Source
const SVGRefCountKey = "SVGRefCount"

Variables

View Source
var CircleType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Circle",
	ShortName:  "svg.Circle",
	IDName:     "circle",
	Doc:        "Circle is a SVG circle",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Pos", &gti.Field{Name: "Pos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the center of the circle", Directives: gti.Directives{}, Tag: "xml:\"{cx,cy}\" set:\"-\""}},
		{"Radius", &gti.Field{Name: "Radius", Type: "float32", LocalType: "float32", Doc: "radius of the circle", Directives: gti.Directives{}, Tag: "xml:\"r\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Circle{},
})

CircleType is the gti.Type for Circle

View Source
var ClipPathType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.ClipPath",
	ShortName:  "svg.ClipPath",
	IDName:     "clip-path",
	Doc:        "ClipPath is used for holding a path that renders as a clip path",
	Directives: gti.Directives{},
	Fields:     ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &ClipPath{},
})

ClipPathType is the gti.Type for ClipPath

View Source
var EllipseType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Ellipse",
	ShortName:  "svg.Ellipse",
	IDName:     "ellipse",
	Doc:        "Ellipse is a SVG ellipse",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Pos", &gti.Field{Name: "Pos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the center of the ellipse", Directives: gti.Directives{}, Tag: "xml:\"{cx,cy}\" set:\"-\""}},
		{"Radii", &gti.Field{Name: "Radii", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "radii of the ellipse in the horizontal, vertical axes", Directives: gti.Directives{}, Tag: "xml:\"{rx,ry}\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Ellipse{},
})

EllipseType is the gti.Type for Ellipse

View Source
var FilterType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Filter",
	ShortName:  "svg.Filter",
	IDName:     "filter",
	Doc:        "Filter represents SVG filter* elements",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"FilterType", &gti.Field{Name: "FilterType", Type: "string", LocalType: "string", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Filter{},
})

FilterType is the gti.Type for Filter

View Source
var FlowType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Flow",
	ShortName:  "svg.Flow",
	IDName:     "flow",
	Doc:        "Flow represents SVG flow* elements",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"FlowType", &gti.Field{Name: "FlowType", Type: "string", LocalType: "string", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Flow{},
})

FlowType is the gti.Type for Flow

View Source
var GradientType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Gradient",
	ShortName:  "svg.Gradient",
	IDName:     "gradient",
	Doc:        "Gradient is used for holding a specified color gradient.\nThe name is the id for lookup in url",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Grad", &gti.Field{Name: "Grad", Type: "goki.dev/colors/gradient.Gradient", LocalType: "gradient.Gradient", Doc: "the color gradient", Directives: gti.Directives{}, Tag: ""}},
		{"StopsName", &gti.Field{Name: "StopsName", Type: "string", LocalType: "string", Doc: "name of another gradient to get stops from", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Gradient{},
})

GradientType is the gti.Type for Gradient

View Source
var GroupType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Group",
	ShortName:  "svg.Group",
	IDName:     "group",
	Doc:        "Group groups together SVG elements.\nProvides a common transform for all group elements\nand shared style properties.",
	Directives: gti.Directives{},
	Fields:     ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Group{},
})

GroupType is the gti.Type for Group

View Source
var ImageType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Image",
	ShortName:  "svg.Image",
	IDName:     "image",
	Doc:        "Image is an SVG image (bitmap)",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Pos", &gti.Field{Name: "Pos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the top-left of the image", Directives: gti.Directives{}, Tag: "xml:\"{x,y}\""}},
		{"Size", &gti.Field{Name: "Size", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "rendered size of the image (imposes a scaling on image when it is rendered)", Directives: gti.Directives{}, Tag: "xml:\"{width,height}\""}},
		{"PreserveAspectRatio", &gti.Field{Name: "PreserveAspectRatio", Type: "bool", LocalType: "bool", Doc: "directs resize operations to preserve aspect ratio", Directives: gti.Directives{}, Tag: "xml:\"preserveAspectRatio\""}},
		{"Filename", &gti.Field{Name: "Filename", Type: "string", LocalType: "string", Doc: "file name of image loaded -- set by OpenImage", Directives: gti.Directives{}, Tag: ""}},
		{"Pixels", &gti.Field{Name: "Pixels", Type: "*image.RGBA", LocalType: "*image.RGBA", Doc: "the image pixels", Directives: gti.Directives{}, Tag: "copy:\"-\" xml:\"-\" json:\"-\" view:\"-\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Image{},
})

ImageType is the gti.Type for Image

View Source
var InkscapeProps = map[string]bool{
	"isstock": true,
	"stockid": true,
}

InkscapeProps are property keys that should be prefixed with "inkscape:"

View Source
var LineType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Line",
	ShortName:  "svg.Line",
	IDName:     "line",
	Doc:        "Line is a SVG line",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Start", &gti.Field{Name: "Start", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the start of the line", Directives: gti.Directives{}, Tag: "xml:\"{x1,y1}\""}},
		{"End", &gti.Field{Name: "End", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the end of the line", Directives: gti.Directives{}, Tag: "xml:\"{x2,y2}\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Line{},
})

LineType is the gti.Type for Line

View Source
var MarkerType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Marker",
	ShortName:  "svg.Marker",
	IDName:     "marker",
	Doc:        "Marker represents marker elements that can be drawn along paths (arrow heads, etc)",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"RefPos", &gti.Field{Name: "RefPos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "reference position to align the vertex position with, specified in ViewBox coordinates", Directives: gti.Directives{}, Tag: "xml:\"{refX,refY}\""}},
		{"Size", &gti.Field{Name: "Size", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "size of marker to render, in Units units", Directives: gti.Directives{}, Tag: "xml:\"{markerWidth,markerHeight}\""}},
		{"Units", &gti.Field{Name: "Units", Type: "goki.dev/svg.MarkerUnits", LocalType: "MarkerUnits", Doc: "units to use", Directives: gti.Directives{}, Tag: "xml:\"markerUnits\""}},
		{"ViewBox", &gti.Field{Name: "ViewBox", Type: "goki.dev/svg.ViewBox", LocalType: "ViewBox", Doc: "viewbox defines the internal coordinate system for the drawing elements within the marker", Directives: gti.Directives{}, Tag: ""}},
		{"Orient", &gti.Field{Name: "Orient", Type: "string", LocalType: "string", Doc: "orientation of the marker -- either 'auto' or an angle", Directives: gti.Directives{}, Tag: "xml:\"orient\""}},
		{"VertexPos", &gti.Field{Name: "VertexPos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "current vertex position", Directives: gti.Directives{}, Tag: ""}},
		{"VertexAngle", &gti.Field{Name: "VertexAngle", Type: "float32", LocalType: "float32", Doc: "current vertex angle in radians", Directives: gti.Directives{}, Tag: ""}},
		{"StrokeWidth", &gti.Field{Name: "StrokeWidth", Type: "float32", LocalType: "float32", Doc: "current stroke width", Directives: gti.Directives{}, Tag: ""}},
		{"Transform", &gti.Field{Name: "Transform", Type: "goki.dev/mat32/v2.Mat2", LocalType: "mat32.Mat2", Doc: "net transform computed from settings and current values -- applied prior to rendering", Directives: gti.Directives{}, Tag: ""}},
		{"EffSize", &gti.Field{Name: "EffSize", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "effective size for actual rendering", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Marker{},
})

MarkerType is the gti.Type for Marker

View Source
var MetaDataType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.MetaData",
	ShortName:  "svg.MetaData",
	IDName:     "meta-data",
	Doc:        "MetaData is used for holding meta data info",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"MetaData", &gti.Field{Name: "MetaData", Type: "string", LocalType: "string", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &MetaData{},
})

MetaDataType is the gti.Type for MetaData

View Source
var NodeBaseType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.NodeBase",
	ShortName:  "svg.NodeBase",
	IDName:     "node-base",
	Doc:        "svg.NodeBase is the base type for elements within the SVG scenegraph",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Class", &gti.Field{Name: "Class", Type: "string", LocalType: "string", Doc: "user-defined class name(s) used primarily for attaching CSS styles to different display elements -- multiple class names can be used to combine properties: use spaces to separate per css standard", Directives: gti.Directives{}, Tag: ""}},
		{"CSS", &gti.Field{Name: "CSS", Type: "goki.dev/ki/v2.Props", LocalType: "ki.Props", Doc: "cascading style sheet at this level -- these styles apply here and to everything below, until superceded -- use .class and #name Props elements to apply entire styles to given elements, and type for element type", Directives: gti.Directives{}, Tag: "xml:\"css\" set:\"-\""}},
		{"CSSAgg", &gti.Field{Name: "CSSAgg", Type: "goki.dev/ki/v2.Props", LocalType: "ki.Props", Doc: "aggregated css properties from all higher nodes down to me", Directives: gti.Directives{}, Tag: "copy:\"-\" json:\"-\" xml:\"-\" set:\"-\" view:\"no-inline\""}},
		{"BBox", &gti.Field{Name: "BBox", Type: "image.Rectangle", LocalType: "image.Rectangle", Doc: "bounding box for the node within the SVG Pixels image -- this one can be outside the visible range of the SVG image -- VpBBox is intersected and only shows visible portion.", Directives: gti.Directives{}, Tag: "copy:\"-\" json:\"-\" xml:\"-\" set:\"-\""}},
		{"VisBBox", &gti.Field{Name: "VisBBox", Type: "image.Rectangle", LocalType: "image.Rectangle", Doc: "visible bounding box for the node intersected with the SVG image geometry", Directives: gti.Directives{}, Tag: "copy:\"-\" json:\"-\" xml:\"-\" set:\"-\""}},
		{"Paint", &gti.Field{Name: "Paint", Type: "goki.dev/girl/styles.Paint", LocalType: "styles.Paint", Doc: "paint style information for this node", Directives: gti.Directives{}, Tag: "json:\"-\" xml:\"-\" set:\"-\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Node", &gti.Field{Name: "Node", Type: "goki.dev/ki/v2.Node", LocalType: "ki.Node", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &NodeBase{},
})

NodeBaseType is the gti.Type for NodeBase

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 PathCmdToRune = map[PathCmds]rune{}

PathCmdToRune maps command to rune

View Source
var PathRuneToCmd = 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,
}

PathRuneToCmd maps rune to path command

View Source
var PathType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Path",
	ShortName:  "svg.Path",
	IDName:     "path",
	Doc:        "Path renders SVG data sequences that can render just about anything",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Data", &gti.Field{Name: "Data", Type: "[]goki.dev/svg.PathData", LocalType: "[]PathData", Doc: "the path data to render -- path commands and numbers are serialized, with each command specifying the number of floating-point coord data points that follow", Directives: gti.Directives{}, Tag: "xml:\"-\" set:\"-\""}},
		{"DataStr", &gti.Field{Name: "DataStr", Type: "string", LocalType: "string", Doc: "string version of the path data", Directives: gti.Directives{}, Tag: "xml:\"d\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Path{},
})

PathType is the gti.Type for Path

View Source
var PolygonType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Polygon",
	ShortName:  "svg.Polygon",
	IDName:     "polygon",
	Doc:        "Polygon is a SVG polygon",
	Directives: gti.Directives{},
	Fields:     ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Polyline", &gti.Field{Name: "Polyline", Type: "goki.dev/svg.Polyline", LocalType: "Polyline", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Polygon{},
})

PolygonType is the gti.Type for Polygon

View Source
var PolylineType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Polyline",
	ShortName:  "svg.Polyline",
	IDName:     "polyline",
	Doc:        "Polyline is a SVG multi-line shape",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Points", &gti.Field{Name: "Points", Type: "[]goki.dev/mat32/v2.Vec2", LocalType: "[]mat32.Vec2", Doc: "the coordinates to draw -- does a moveto on the first, then lineto for all the rest", Directives: gti.Directives{}, Tag: "xml:\"points\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Polyline{},
})

PolylineType is the gti.Type for Polyline

View Source
var RectType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Rect",
	ShortName:  "svg.Rect",
	IDName:     "rect",
	Doc:        "Rect is a SVG rectangle, optionally with rounded corners",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Pos", &gti.Field{Name: "Pos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the top-left of the rectangle", Directives: gti.Directives{}, Tag: "xml:\"{x,y}\""}},
		{"Size", &gti.Field{Name: "Size", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "size of the rectangle", Directives: gti.Directives{}, Tag: "xml:\"{width,height}\""}},
		{"Radius", &gti.Field{Name: "Radius", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "radii for curved corners, as a proportion of width, height", Directives: gti.Directives{}, Tag: "xml:\"{rx,ry}\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Rect{},
})

RectType is the gti.Type for Rect

View Source
var SVGNodeType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.SVGNode",
	ShortName:  "svg.SVGNode",
	IDName:     "svg-node",
	Doc:        "SVGNode represents the root of an SVG tree",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"ViewBox", &gti.Field{Name: "ViewBox", Type: "goki.dev/svg.ViewBox", LocalType: "ViewBox", Doc: "viewbox defines the coordinate system for the drawing -- these units are mapped into the screen space allocated for the SVG during rendering", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Group", &gti.Field{Name: "Group", Type: "goki.dev/svg.Group", LocalType: "Group", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &SVGNode{},
})

SVGNodeType is the gti.Type for SVGNode

View Source
var StyleSheetType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.StyleSheet",
	ShortName:  "svg.StyleSheet",
	IDName:     "style-sheet",
	Doc:        "StyleSheet is a Node2D node that contains a stylesheet -- property values\ncontained in this sheet can be transformed into ki.Props and set in CSS\nfield of appropriate node",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Sheet", &gti.Field{Name: "Sheet", Type: "*github.com/aymerick/douceur/css.Stylesheet", LocalType: "*css.Stylesheet", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &StyleSheet{},
})

StyleSheetType is the gti.Type for StyleSheet

View Source
var TextType = gti.AddType(&gti.Type{
	Name:       "goki.dev/svg.Text",
	ShortName:  "svg.Text",
	IDName:     "text",
	Doc:        "Text renders SVG text, handling both text and tspan elements.\ntspan is nested under a parent text -- text has empty Text string.",
	Directives: gti.Directives{},
	Fields: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"Pos", &gti.Field{Name: "Pos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "position of the left, baseline of the text", Directives: gti.Directives{}, Tag: "xml:\"{x,y}\" set:\"-\""}},
		{"Width", &gti.Field{Name: "Width", Type: "float32", LocalType: "float32", Doc: "width of text to render if using word-wrapping", Directives: gti.Directives{}, Tag: "xml:\"width\""}},
		{"Text", &gti.Field{Name: "Text", Type: "string", LocalType: "string", Doc: "text string to render", Directives: gti.Directives{}, Tag: "xml:\"text\""}},
		{"TextRender", &gti.Field{Name: "TextRender", Type: "goki.dev/girl/paint.Text", LocalType: "paint.Text", Doc: "render version of text", Directives: gti.Directives{}, Tag: "xml:\"-\" json:\"-\""}},
		{"CharPosX", &gti.Field{Name: "CharPosX", Type: "[]float32", LocalType: "[]float32", Doc: "character positions along X axis, if specified", Directives: gti.Directives{}, Tag: ""}},
		{"CharPosY", &gti.Field{Name: "CharPosY", Type: "[]float32", LocalType: "[]float32", Doc: "character positions along Y axis, if specified", Directives: gti.Directives{}, Tag: ""}},
		{"CharPosDX", &gti.Field{Name: "CharPosDX", Type: "[]float32", LocalType: "[]float32", Doc: "character delta-positions along X axis, if specified", Directives: gti.Directives{}, Tag: ""}},
		{"CharPosDY", &gti.Field{Name: "CharPosDY", Type: "[]float32", LocalType: "[]float32", Doc: "character delta-positions along Y axis, if specified", Directives: gti.Directives{}, Tag: ""}},
		{"CharRots", &gti.Field{Name: "CharRots", Type: "[]float32", LocalType: "[]float32", Doc: "character rotations, if specified", Directives: gti.Directives{}, Tag: ""}},
		{"TextLength", &gti.Field{Name: "TextLength", Type: "float32", LocalType: "float32", Doc: "author's computed text length, if specified -- we attempt to match", Directives: gti.Directives{}, Tag: ""}},
		{"AdjustGlyphs", &gti.Field{Name: "AdjustGlyphs", Type: "bool", LocalType: "bool", Doc: "in attempting to match TextLength, should we adjust glyphs in addition to spacing?", Directives: gti.Directives{}, Tag: ""}},
		{"LastPos", &gti.Field{Name: "LastPos", Type: "goki.dev/mat32/v2.Vec2", LocalType: "mat32.Vec2", Doc: "last text render position -- lower-left baseline of start", Directives: gti.Directives{}, Tag: "xml:\"-\" json:\"-\""}},
		{"LastBBox", &gti.Field{Name: "LastBBox", Type: "goki.dev/mat32/v2.Box2", LocalType: "mat32.Box2", Doc: "last actual bounding box in display units (dots)", Directives: gti.Directives{}, Tag: "xml:\"-\" json:\"-\""}},
	}),
	Embeds: ordmap.Make([]ordmap.KeyVal[string, *gti.Field]{
		{"NodeBase", &gti.Field{Name: "NodeBase", Type: "goki.dev/svg.NodeBase", LocalType: "NodeBase", Doc: "", Directives: gti.Directives{}, Tag: ""}},
	}),
	Methods:  ordmap.Make([]ordmap.KeyVal[string, *gti.Method]{}),
	Instance: &Text{},
})

TextType is the gti.Type for Text

Functions

func AggCSS

func AggCSS(agg *ki.Props, css ki.Props)

AggCSS aggregates css properties

func BBoxFromChildren

func BBoxFromChildren(gi Node) image.Rectangle

BBoxFromChildren sets the Group BBox from children

func EscapeText

func EscapeText(w io.Writer, s []byte, escapeNewline bool) error

XMLEscapeText writes to w the properly escaped XML equivalent of the plain text data s. If escapeNewline is true, newline XMLcharacters will be escaped.

func GradientReadPts

func GradientReadPts(gr gradient.Gradient, dat []float32)

GradientReadPoints reads the gradient points from a slice of floating point numbers, reading from the end.

func GradientWritePts

func GradientWritePts(gr gradient.Gradient, dat *[]float32)

GradientWritePoints writes the gradient points to a slice of floating point numbers, appending to end of slice.

func IncRefCount

func IncRefCount(k ki.Ki)

func NameFromURL

func NameFromURL(url string) string

NameFromURL returns just the name referred to in a url(#name) if it is not a url(#) format then returns empty string.

func NameId

func NameId(nm string, id int) string

NameId returns the name with given unique id. returns plain name if id == 0

func NameToURL

func NameToURL(nm string) string

NameToURL returns url as: url(#name)

func NodePropURL

func NodePropURL(gi Node, prop string) string

NodePropURL returns a url(#name) url from given prop name on node, or empty string if none. Returned value is just the 'name' part of the url, not the full string.

func PathCmdIsRel

func PathCmdIsRel(pc PathCmds) bool

PathCmdIsRel returns true if the path command is relative, false for absolute

func PathDataBBox

func PathDataBBox(data []PathData) mat32.Box2

PathDataBBox traverses the path data and extracts the local bounding box

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, cp mat32.Vec2, ctrls []mat32.Vec2) 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), including special control points for path commands that have them (else nil). If function returns false (use ki.Break vs. ki.Continue) then traversal is aborted. For Control points, order is in same order as in standard path stream when multiple, e.g., C,S. For A: order is: nc, prv, rad, mat32.Vec2{X: ang}, mat32.V2(laf, sf)}

func PathDataNext

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

PathDataNext gets the next path data point, incrementing the index

func PathDataNextRel

func PathDataNextRel(data []PathData, i *int, cp mat32.Vec2) mat32.Vec2

PathDataNextRel gets the next 2 path data points as a relative vector and returns that relative vector added to current point

func PathDataNextVec

func PathDataNextVec(data []PathData, i *int) mat32.Vec2

PathDataNextVec gets the next 2 path data points as a vector

func PathDataRender

func PathDataRender(data []PathData, pc *paint.Context)

PathDataRender traverses the path data and renders it using paint. 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 PathDataString

func PathDataString(data []PathData) string

PathDataString returns the string representation of the path data

func PathDataTransformAbs added in v0.1.18

func PathDataTransformAbs(data []PathData, i *int, xf mat32.Mat2, lpt mat32.Vec2) mat32.Vec2

PathDataTransformAbs does the transform of next two data points as absolute coords

func PathDataTransformRel added in v0.1.18

func PathDataTransformRel(data []PathData, i *int, xf mat32.Mat2, cp mat32.Vec2) mat32.Vec2

PathDataTransformRel does the transform of next two data points as relative coords compared to given cp coordinate. returns new *absolute* coordinate

func PathDataValidate

func PathDataValidate(data *[]PathData, errstr string) error

PathDataValidate validates the path data and emits error messages on log

func SVGNodeMarshalXML

func SVGNodeMarshalXML(itm ki.Ki, enc *XMLEncoder, setName string) string

SVGNodeMarshalXML encodes just the given node under SVG to XML. returns name of node, for end tag -- if empty, then children will not be output.

func SVGNodeTreeMarshalXML

func SVGNodeTreeMarshalXML(itm Node, enc *XMLEncoder, setName string) (string, error)

SVGNodeTreeMarshalXML encodes item and any children to XML. returns any error, and name of element that enc.WriteEnd() should be called with -- allows for extra elements to be added at end of list.

func SVGNodeXMLGrad

func SVGNodeXMLGrad(nd *Gradient, name string, enc *XMLEncoder)

SVGNodeXMLGrad adds the XML for the given gradient to the given encoder. This is not in goki.dev/colors/gradient because it uses a lot of SVG and XML infrastructure defined here.

func SVGWalkPre added in v0.1.26

func SVGWalkPre(n Node, fun func(kni Node, knb *NodeBase) bool)

SVGWalkPre does ki WalkPre on given node using given walk function with SVG Node parameters. Automatically filters nil or deleted items. Return ki.Continue (true) to continue, and ki.Break (false) to terminate.

func SetFloat32SliceLen

func SetFloat32SliceLen(dat *[]float32, sz int)

SetFloat32SliceLen is a utility function to set given slice of float32 values to given length, reusing existing where possible and making a new one as needed. For use in WriteGeom routines.

func SetStdXMLAttr

func SetStdXMLAttr(ni Node, name, val string) bool

SetStdXMLAttr sets standard attributes of node given XML-style name / attribute values (e.g., from parsing XML / SVG files) -- returns true if handled

func SplitNameId

func SplitNameId(elnm, nm string) (bool, int)

SplitNameId splits name after the element name (e.g., 'rect') returning true if it starts with element name, and numerical id part after that element. if numerical id part is 0, then it didn't parse. SVG object names are element names + numerical id

func SplitNameIdDig

func SplitNameIdDig(nm string) (string, int)

SplitNameIdDig splits name into numerical end part and preceding name, based on string of digits from end of name. If Id == 0 then it was not specified or didn't parse. SVG object names are element names + numerical id

func XMLAddAttr

func XMLAddAttr(attr *[]xml.Attr, name, val string)

Types

type Circle

type Circle struct {
	NodeBase

	// position of the center of the circle
	Pos mat32.Vec2 `xml:"{cx,cy}" set:"-"`

	// radius of the circle
	Radius float32 `xml:"r"`
}

Circle is a SVG circle

func NewCircle

func NewCircle(par ki.Ki, name ...string) *Circle

NewCircle adds a new Circle with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Circle) ApplyDeltaTransform added in v0.1.18

func (g *Circle) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Circle) ApplyTransform added in v0.1.18

func (g *Circle) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Circle) CopyFieldsFrom

func (g *Circle) CopyFieldsFrom(frm any)

func (*Circle) KiType added in v0.1.2

func (t *Circle) KiType() *gti.Type

KiType returns the *gti.Type of Circle

func (*Circle) LocalBBox

func (g *Circle) LocalBBox() mat32.Box2

func (*Circle) New

func (t *Circle) New() ki.Ki

New returns a new *Circle value

func (*Circle) OnInit added in v0.1.18

func (g *Circle) OnInit()

func (*Circle) ReadGeom

func (g *Circle) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Circle) Render

func (g *Circle) Render(sv *SVG)

func (*Circle) SVGName

func (g *Circle) SVGName() string

func (*Circle) SetClass added in v0.1.18

func (t *Circle) SetClass(v string) *Circle

SetClass sets the [Circle.Class]

func (*Circle) SetPos

func (g *Circle) SetPos(pos mat32.Vec2) *Circle

func (*Circle) SetRadius added in v0.1.18

func (t *Circle) SetRadius(v float32) *Circle

SetRadius sets the [Circle.Radius]: radius of the circle

func (*Circle) SetSize

func (g *Circle) SetSize(sz mat32.Vec2) *Circle

func (*Circle) WriteGeom

func (g *Circle) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type ClipPath

type ClipPath struct {
	NodeBase
}

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

func NewClipPath

func NewClipPath(par ki.Ki, name ...string) *ClipPath

NewClipPath adds a new ClipPath with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*ClipPath) CopyFieldsFrom

func (g *ClipPath) CopyFieldsFrom(frm any)

func (*ClipPath) KiType added in v0.1.2

func (t *ClipPath) KiType() *gti.Type

KiType returns the *gti.Type of ClipPath

func (*ClipPath) New

func (t *ClipPath) New() ki.Ki

New returns a new *ClipPath value

func (*ClipPath) SVGName

func (g *ClipPath) SVGName() string

func (*ClipPath) SetClass added in v0.1.18

func (t *ClipPath) SetClass(v string) *ClipPath

SetClass sets the [ClipPath.Class]

type Ellipse

type Ellipse struct {
	NodeBase

	// position of the center of the ellipse
	Pos mat32.Vec2 `xml:"{cx,cy}" set:"-"`

	// radii of the ellipse in the horizontal, vertical axes
	Radii mat32.Vec2 `xml:"{rx,ry}"`
}

Ellipse is a SVG ellipse

func NewEllipse

func NewEllipse(par ki.Ki, name ...string) *Ellipse

NewEllipse adds a new Ellipse with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Ellipse) ApplyDeltaTransform added in v0.1.18

func (g *Ellipse) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Ellipse) ApplyTransform added in v0.1.18

func (g *Ellipse) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Ellipse) CopyFieldsFrom

func (g *Ellipse) CopyFieldsFrom(frm any)

func (*Ellipse) KiType added in v0.1.2

func (t *Ellipse) KiType() *gti.Type

KiType returns the *gti.Type of Ellipse

func (*Ellipse) LocalBBox

func (g *Ellipse) LocalBBox() mat32.Box2

func (*Ellipse) New

func (t *Ellipse) New() ki.Ki

New returns a new *Ellipse value

func (*Ellipse) OnInit added in v0.1.18

func (g *Ellipse) OnInit()

func (*Ellipse) ReadGeom

func (g *Ellipse) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Ellipse) Render

func (g *Ellipse) Render(sv *SVG)

func (*Ellipse) SVGName

func (g *Ellipse) SVGName() string

func (*Ellipse) SetClass added in v0.1.18

func (t *Ellipse) SetClass(v string) *Ellipse

SetClass sets the [Ellipse.Class]

func (*Ellipse) SetPos

func (g *Ellipse) SetPos(pos mat32.Vec2) *Ellipse

func (*Ellipse) SetRadii added in v0.1.18

func (t *Ellipse) SetRadii(v mat32.Vec2) *Ellipse

SetRadii sets the [Ellipse.Radii]: radii of the ellipse in the horizontal, vertical axes

func (*Ellipse) SetSize

func (g *Ellipse) SetSize(sz mat32.Vec2) *Ellipse

func (*Ellipse) WriteGeom

func (g *Ellipse) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type Filter

type Filter struct {
	NodeBase
	FilterType string
}

Filter represents SVG filter* elements

func NewFilter

func NewFilter(par ki.Ki, name ...string) *Filter

NewFilter adds a new Filter with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Filter) CopyFieldsFrom

func (g *Filter) CopyFieldsFrom(frm any)

func (*Filter) KiType added in v0.1.2

func (t *Filter) KiType() *gti.Type

KiType returns the *gti.Type of Filter

func (*Filter) New

func (t *Filter) New() ki.Ki

New returns a new *Filter value

func (*Filter) SVGName

func (g *Filter) SVGName() string

func (*Filter) SetClass added in v0.1.18

func (t *Filter) SetClass(v string) *Filter

SetClass sets the [Filter.Class]

func (*Filter) SetFilterType added in v0.1.18

func (t *Filter) SetFilterType(v string) *Filter

SetFilterType sets the [Filter.FilterType]

type Flow

type Flow struct {
	NodeBase
	FlowType string
}

Flow represents SVG flow* elements

func NewFlow

func NewFlow(par ki.Ki, name ...string) *Flow

NewFlow adds a new Flow with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Flow) CopyFieldsFrom

func (g *Flow) CopyFieldsFrom(frm any)

func (*Flow) KiType added in v0.1.2

func (t *Flow) KiType() *gti.Type

KiType returns the *gti.Type of Flow

func (*Flow) New

func (t *Flow) New() ki.Ki

New returns a new *Flow value

func (*Flow) SVGName

func (g *Flow) SVGName() string

func (*Flow) SetClass added in v0.1.18

func (t *Flow) SetClass(v string) *Flow

SetClass sets the [Flow.Class]

func (*Flow) SetFlowType added in v0.1.18

func (t *Flow) SetFlowType(v string) *Flow

SetFlowType sets the [Flow.FlowType]

type Gradient

type Gradient struct {
	NodeBase

	// the color gradient
	Grad gradient.Gradient

	// name of another gradient to get stops from
	StopsName string
}

Gradient is used for holding a specified color gradient. The name is the id for lookup in url

func NewGradient

func NewGradient(par ki.Ki, name ...string) *Gradient

NewGradient adds a new Gradient with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Gradient) CopyFieldsFrom

func (gr *Gradient) CopyFieldsFrom(frm any)

func (*Gradient) GradientTypeName

func (gr *Gradient) GradientTypeName() string

GradientTypeName returns the SVG-style type name of gradient: linearGradient or radialGradient

func (*Gradient) KiType added in v0.1.2

func (t *Gradient) KiType() *gti.Type

KiType returns the *gti.Type of Gradient

func (*Gradient) New

func (t *Gradient) New() ki.Ki

New returns a new *Gradient value

func (*Gradient) SetClass added in v0.1.18

func (t *Gradient) SetClass(v string) *Gradient

SetClass sets the [Gradient.Class]

func (*Gradient) SetGrad added in v0.1.18

func (t *Gradient) SetGrad(v gradient.Gradient) *Gradient

SetGrad sets the [Gradient.Grad]: the color gradient

func (*Gradient) SetStopsName added in v0.1.18

func (t *Gradient) SetStopsName(v string) *Gradient

SetStopsName sets the [Gradient.StopsName]: name of another gradient to get stops from

type Group

type Group struct {
	NodeBase
}

Group groups together SVG elements. Provides a common transform for all group elements and shared style properties.

func NewGroup

func NewGroup(par ki.Ki, name ...string) *Group

NewGroup adds a new Group with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Group) ApplyDeltaTransform added in v0.1.18

func (g *Group) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Group) ApplyTransform added in v0.1.18

func (g *Group) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Group) CopyFieldsFrom added in v0.1.26

func (g *Group) CopyFieldsFrom(frm any)

func (*Group) EnforceSVGName

func (g *Group) EnforceSVGName() bool

func (*Group) KiType added in v0.1.2

func (t *Group) KiType() *gti.Type

KiType returns the *gti.Type of Group

func (*Group) New

func (t *Group) New() ki.Ki

New returns a new *Group value

func (*Group) NodeBBox

func (g *Group) NodeBBox(sv *SVG) image.Rectangle

func (*Group) ReadGeom

func (g *Group) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Group) Render

func (g *Group) Render(sv *SVG)

func (*Group) SVGName

func (g *Group) SVGName() string

func (*Group) SetClass added in v0.1.18

func (t *Group) SetClass(v string) *Group

SetClass sets the [Group.Class]

func (*Group) WriteGeom

func (g *Group) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type Image

type Image struct {
	NodeBase

	// position of the top-left of the image
	Pos mat32.Vec2 `xml:"{x,y}"`

	// rendered size of the image (imposes a scaling on image when it is rendered)
	Size mat32.Vec2 `xml:"{width,height}"`

	// directs resize operations to preserve aspect ratio
	PreserveAspectRatio bool `xml:"preserveAspectRatio"`

	// file name of image loaded -- set by OpenImage
	Filename string

	// the image pixels
	Pixels *image.RGBA `copy:"-" xml:"-" json:"-" view:"-"`
}

Image is an SVG image (bitmap)

func NewImage

func NewImage(par ki.Ki, name ...string) *Image

NewImage adds a new Image with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Image) ApplyDeltaTransform added in v0.1.18

func (g *Image) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Image) ApplyTransform added in v0.1.18

func (g *Image) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Image) CopyFieldsFrom

func (g *Image) CopyFieldsFrom(frm any)

func (*Image) DrawImage

func (g *Image) DrawImage(sv *SVG)

func (*Image) KiType added in v0.1.2

func (t *Image) KiType() *gti.Type

KiType returns the *gti.Type of Image

func (*Image) LocalBBox

func (g *Image) LocalBBox() mat32.Box2

func (*Image) New

func (t *Image) New() ki.Ki

New returns a new *Image value

func (*Image) NodeBBox

func (g *Image) NodeBBox(sv *SVG) image.Rectangle

func (*Image) OpenImage

func (g *Image) OpenImage(filename string, width, height float32) error

OpenImage opens an image for the bitmap, and resizes to the size of the image or the specified size -- pass 0 for width and/or height to use the actual image size for that dimension

func (*Image) ReadGeom

func (g *Image) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Image) Render

func (g *Image) Render(sv *SVG)

func (*Image) SVGName

func (g *Image) SVGName() string

func (*Image) SaveImage

func (g *Image) SaveImage(filename string) error

SaveImage saves current image to a file

func (*Image) SetClass added in v0.1.18

func (t *Image) SetClass(v string) *Image

SetClass sets the [Image.Class]

func (*Image) SetFilename added in v0.1.18

func (t *Image) SetFilename(v string) *Image

SetFilename sets the [Image.Filename]: file name of image loaded -- set by OpenImage

func (*Image) SetImage

func (g *Image) SetImage(img image.Image, width, height float32)

SetImage sets an image for the bitmap, and resizes to the size of the image or the specified size -- pass 0 for width and/or height to use the actual image size for that dimension. Copies from given image into internal image for this bitmap.

func (*Image) SetImageSize

func (g *Image) SetImageSize(nwsz image.Point)

SetImageSize sets size of the bitmap image. This does not resize any existing image, just makes a new image if the size is different

func (*Image) SetPixels added in v0.1.18

func (t *Image) SetPixels(v *image.RGBA) *Image

SetPixels sets the [Image.Pixels]: the image pixels

func (*Image) SetPos

func (t *Image) SetPos(v mat32.Vec2) *Image

SetPos sets the [Image.Pos]: position of the top-left of the image

func (*Image) SetPreserveAspectRatio added in v0.1.18

func (t *Image) SetPreserveAspectRatio(v bool) *Image

SetPreserveAspectRatio sets the [Image.PreserveAspectRatio]: directs resize operations to preserve aspect ratio

func (*Image) SetSize

func (t *Image) SetSize(v mat32.Vec2) *Image

SetSize sets the [Image.Size]: rendered size of the image (imposes a scaling on image when it is rendered)

func (*Image) WriteGeom

func (g *Image) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type Line

type Line struct {
	NodeBase

	// position of the start of the line
	Start mat32.Vec2 `xml:"{x1,y1}"`

	// position of the end of the line
	End mat32.Vec2 `xml:"{x2,y2}"`
}

Line is a SVG line

func NewLine

func NewLine(par ki.Ki, name ...string) *Line

NewLine adds a new Line with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Line) ApplyDeltaTransform added in v0.1.18

func (g *Line) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Line) ApplyTransform added in v0.1.18

func (g *Line) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Line) CopyFieldsFrom

func (g *Line) CopyFieldsFrom(frm any)

func (*Line) KiType added in v0.1.2

func (t *Line) KiType() *gti.Type

KiType returns the *gti.Type of Line

func (*Line) LocalBBox

func (g *Line) LocalBBox() mat32.Box2

func (*Line) New

func (t *Line) New() ki.Ki

New returns a new *Line value

func (*Line) OnInit added in v0.1.18

func (g *Line) OnInit()

func (*Line) ReadGeom

func (g *Line) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Line) Render

func (g *Line) Render(sv *SVG)

func (*Line) SVGName

func (g *Line) SVGName() string

func (*Line) SetClass added in v0.1.18

func (t *Line) SetClass(v string) *Line

SetClass sets the [Line.Class]

func (*Line) SetEnd added in v0.1.18

func (t *Line) SetEnd(v mat32.Vec2) *Line

SetEnd sets the [Line.End]: position of the end of the line

func (*Line) SetPos

func (g *Line) SetPos(pos mat32.Vec2)

func (*Line) SetSize

func (g *Line) SetSize(sz mat32.Vec2)

func (*Line) SetStart added in v0.1.18

func (t *Line) SetStart(v mat32.Vec2) *Line

SetStart sets the [Line.Start]: position of the start of the line

func (*Line) WriteGeom

func (g *Line) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type Marker

type Marker struct {
	NodeBase

	// reference position to align the vertex position with, specified in ViewBox coordinates
	RefPos mat32.Vec2 `xml:"{refX,refY}"`

	// size of marker to render, in Units units
	Size mat32.Vec2 `xml:"{markerWidth,markerHeight}"`

	// units to use
	Units MarkerUnits `xml:"markerUnits"`

	// viewbox defines the internal coordinate system for the drawing elements within the marker
	ViewBox ViewBox

	// orientation of the marker -- either 'auto' or an angle
	Orient string `xml:"orient"`

	// current vertex position
	VertexPos mat32.Vec2

	// current vertex angle in radians
	VertexAngle float32

	// current stroke width
	StrokeWidth float32

	// net transform computed from settings and current values -- applied prior to rendering
	Transform mat32.Mat2

	// effective size for actual rendering
	EffSize mat32.Vec2
}

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

func NewMarker

func NewMarker(par ki.Ki, name ...string) *Marker

NewMarker adds a new Marker with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Marker) BBoxes

func (g *Marker) BBoxes(sv *SVG)

func (*Marker) CopyFieldsFrom

func (g *Marker) CopyFieldsFrom(frm any)

func (*Marker) EnforceSVGName

func (g *Marker) EnforceSVGName() bool

func (*Marker) KiType added in v0.1.2

func (t *Marker) KiType() *gti.Type

KiType returns the *gti.Type of Marker

func (*Marker) New

func (t *Marker) New() ki.Ki

New returns a new *Marker value

func (*Marker) Render

func (g *Marker) Render(sv *SVG)

func (*Marker) RenderMarker

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

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

func (*Marker) SVGName

func (g *Marker) SVGName() string

func (*Marker) SetClass added in v0.1.18

func (t *Marker) SetClass(v string) *Marker

SetClass sets the [Marker.Class]

func (*Marker) SetEffSize added in v0.1.18

func (t *Marker) SetEffSize(v mat32.Vec2) *Marker

SetEffSize sets the [Marker.EffSize]: effective size for actual rendering

func (*Marker) SetOrient added in v0.1.18

func (t *Marker) SetOrient(v string) *Marker

SetOrient sets the [Marker.Orient]: orientation of the marker -- either 'auto' or an angle

func (*Marker) SetRefPos added in v0.1.18

func (t *Marker) SetRefPos(v mat32.Vec2) *Marker

SetRefPos sets the [Marker.RefPos]: reference position to align the vertex position with, specified in ViewBox coordinates

func (*Marker) SetSize added in v0.1.18

func (t *Marker) SetSize(v mat32.Vec2) *Marker

SetSize sets the [Marker.Size]: size of marker to render, in Units units

func (*Marker) SetStrokeWidth added in v0.1.18

func (t *Marker) SetStrokeWidth(v float32) *Marker

SetStrokeWidth sets the [Marker.StrokeWidth]: current stroke width

func (*Marker) SetTransform added in v0.1.18

func (t *Marker) SetTransform(v mat32.Mat2) *Marker

SetTransform sets the [Marker.Transform]: net transform computed from settings and current values -- applied prior to rendering

func (*Marker) SetUnits added in v0.1.18

func (t *Marker) SetUnits(v MarkerUnits) *Marker

SetUnits sets the [Marker.Units]: units to use

func (*Marker) SetVertexAngle added in v0.1.18

func (t *Marker) SetVertexAngle(v float32) *Marker

SetVertexAngle sets the [Marker.VertexAngle]: current vertex angle in radians

func (*Marker) SetVertexPos added in v0.1.18

func (t *Marker) SetVertexPos(v mat32.Vec2) *Marker

SetVertexPos sets the [Marker.VertexPos]: current vertex position

func (*Marker) SetViewBox added in v0.1.18

func (t *Marker) SetViewBox(v ViewBox) *Marker

SetViewBox sets the [Marker.ViewBox]: viewbox defines the internal coordinate system for the drawing elements within the marker

type MarkerUnits

type MarkerUnits int32 //enum: enum

MarkerUnits specifies units to use for svg marker elements

const (
	StrokeWidth MarkerUnits = iota
	UserSpaceOnUse
	MarkerUnitsN
)

type MetaData

type MetaData struct {
	NodeBase
	MetaData string
}

MetaData is used for holding meta data info

func NewMetaData

func NewMetaData(par ki.Ki, name ...string) *MetaData

NewMetaData adds a new MetaData with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*MetaData) CopyFieldsFrom

func (g *MetaData) CopyFieldsFrom(frm any)

func (*MetaData) KiType added in v0.1.2

func (t *MetaData) KiType() *gti.Type

KiType returns the *gti.Type of MetaData

func (*MetaData) New

func (t *MetaData) New() ki.Ki

New returns a new *MetaData value

func (*MetaData) SetClass added in v0.1.18

func (t *MetaData) SetClass(v string) *MetaData

SetClass sets the [MetaData.Class]

func (*MetaData) SetMetaData added in v0.1.18

func (t *MetaData) SetMetaData(v string) *MetaData

SetMetaData sets the [MetaData.MetaData]

type Node

type Node interface {
	ki.Ki

	// AsNodeBase returns a generic svg.NodeBase for our node -- gives generic
	// access to all the base-level data structures without requiring
	// interface methods.
	AsNodeBase() *NodeBase

	// PaintStyle returns the SVG Paint style object for this node
	PaintStyle() *styles.Paint

	// Style updates the Paint style for this node
	Style(sv *SVG)

	// Render draws the node to the svg image
	Render(sv *SVG)

	// BBoxes computes BBox and VisBBox during Render
	BBoxes(sv *SVG)

	// LocalBBox returns the bounding box of node in local dimensions
	LocalBBox() mat32.Box2

	// NodeBBox returns the bounding box in image coordinates for this node
	NodeBBox(sv *SVG) image.Rectangle

	// ApplyTransform applies the given 2D transform to the geometry of this node
	// this just does a direct transform multiplication on coordinates.
	ApplyTransform(sv *SVG, xf mat32.Mat2)

	// ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node
	// relative to given point.  Trans translation and point are in top-level coordinates,
	// so must be transformed into local coords first.
	// Point is upper left corner of selection box that anchors the translation and scaling,
	// and for rotation it is the center point around which to rotate
	ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

	// WriteGeom writes the geometry of the node to a slice of floating point numbers
	// the length and ordering of which is specific to each node type.
	// Slice must be passed and will be resized if not the correct length.
	WriteGeom(sv *SVG, dat *[]float32)

	// ReadGeom reads the geometry of the node from a slice of floating point numbers
	// the length and ordering of which is specific to each node type.
	ReadGeom(sv *SVG, dat []float32)

	// SVGName returns the SVG element name (e.g., "rect", "path" etc)
	SVGName() string

	// EnforceSVGName returns true if in general this element should
	// be named with its SVGName plus a unique id.
	// Groups and Markers are false.
	EnforceSVGName() bool
}

Node is the interface for all SVG nodes

func FirstNonGroupNode

func FirstNonGroupNode(n Node) Node

FirstNonGroupNode returns the first item that is not a group recursing into groups until a non-group item is found.

func NodesContainingPoint added in v0.1.26

func NodesContainingPoint(n Node, pt image.Point, leavesOnly bool) []Node

NodesContainingPoint returns all Nodes with Bounding Box that contains given point, optionally only those that are terminal nodes (no leaves). Excludes the starting node.

type NodeBase

type NodeBase struct {
	ki.Node

	// user-defined class name(s) used primarily for attaching CSS styles to different display elements -- multiple class names can be used to combine properties: use spaces to separate per css standard
	Class string

	// cascading style sheet at this level -- these styles apply here and to everything below, until superceded -- use .class and #name Props elements to apply entire styles to given elements, and type for element type
	CSS ki.Props `xml:"css" set:"-"`

	// aggregated css properties from all higher nodes down to me
	CSSAgg ki.Props `copy:"-" json:"-" xml:"-" set:"-" view:"no-inline"`

	// bounding box for the node within the SVG Pixels image -- this one can be outside the visible range of the SVG image -- VpBBox is intersected and only shows visible portion.
	BBox image.Rectangle `copy:"-" json:"-" xml:"-" set:"-"`

	// visible bounding box for the node intersected with the SVG image geometry
	VisBBox image.Rectangle `copy:"-" json:"-" xml:"-" set:"-"`

	// paint style information for this node
	Paint styles.Paint `json:"-" xml:"-" set:"-"`
}

svg.NodeBase is the base type for elements within the SVG scenegraph

func NewNodeBase

func NewNodeBase(par ki.Ki, name ...string) *NodeBase

NewNodeBase adds a new NodeBase with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*NodeBase) ApplyCSS

func (g *NodeBase) ApplyCSS(sv *SVG, key string, css ki.Props) bool

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

func (*NodeBase) ApplyDeltaTransform added in v0.1.18

func (g *NodeBase) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*NodeBase) ApplyTransform added in v0.1.18

func (g *NodeBase) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node this just does a direct transform multiplication on coordinates.

func (*NodeBase) AsNodeBase

func (g *NodeBase) AsNodeBase() *NodeBase

func (*NodeBase) BBoxes

func (g *NodeBase) BBoxes(sv *SVG)

ComputeBBox 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 transforms are all in place -- VpBBox is intersected with parent SVG

func (*NodeBase) BaseIface

func (n *NodeBase) BaseIface() reflect.Type

func (*NodeBase) CopyFieldsFrom

func (g *NodeBase) CopyFieldsFrom(frm any)

func (*NodeBase) DeltaTransform added in v0.1.18

func (g *NodeBase) DeltaTransform(trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2, self bool) (mat32.Mat2, mat32.Vec2)

DeltaTransform computes the net transform matrix for given delta transform parameters and the transformed version of the reference point. If self is true, then include the current node self transform, otherwise don't. Groups do not but regular rendering nodes do.

func (*NodeBase) EnforceSVGName

func (g *NodeBase) EnforceSVGName() bool

func (*NodeBase) GradientApplyTransform added in v0.1.18

func (g *NodeBase) GradientApplyTransform(sv *SVG, xf mat32.Mat2)

GradientApplyTransform applies the given transform to any gradients for this node, that are using specific coordinates (not bounding box which is automatic)

func (*NodeBase) GradientApplyTransformPt added in v0.1.18

func (g *NodeBase) GradientApplyTransformPt(sv *SVG, xf mat32.Mat2, pt mat32.Vec2)

GradientApplyTransformPt applies the given transform with ctr point to any gradients for this node, that are using specific coordinates (not bounding box which is automatic)

func (*NodeBase) GradientReadPts

func (g *NodeBase) GradientReadPts(sv *SVG, dat []float32)

GradientReadPts reads the geometry of the gradients for this node from a slice of floating point numbers, reading from the end.

func (*NodeBase) GradientWritePts

func (g *NodeBase) GradientWritePts(sv *SVG, dat *[]float32)

GradientWritePts writes the geometry of the gradients for this node to a slice of floating point numbers, appending to end of slice.

func (*NodeBase) Init

func (g *NodeBase) Init()

Init does any needed initialization

func (*NodeBase) IsDefs

func (g *NodeBase) IsDefs() bool

IsDefs returns true if is in the Defs of parent SVG

func (*NodeBase) KiType added in v0.1.2

func (t *NodeBase) KiType() *gti.Type

KiType returns the *gti.Type of NodeBase

func (*NodeBase) LocalBBox

func (g *NodeBase) LocalBBox() mat32.Box2

func (*NodeBase) LocalBBoxToWin

func (g *NodeBase) LocalBBoxToWin(bb mat32.Box2) image.Rectangle

LocalBBoxToWin converts a local bounding box to SVG coordinates

func (*NodeBase) LocalLineWidth

func (g *NodeBase) LocalLineWidth() float32

LocalLineWidth returns the line width in local coordinates

func (*NodeBase) New

func (t *NodeBase) New() ki.Ki

New returns a new *NodeBase value

func (*NodeBase) NodeBBox

func (g *NodeBase) NodeBBox(sv *SVG) image.Rectangle

func (*NodeBase) PaintStyle

func (g *NodeBase) PaintStyle() *styles.Paint

func (*NodeBase) ParTransform added in v0.1.18

func (g *NodeBase) ParTransform(self bool) mat32.Mat2

ParTransform returns the full compounded 2D transform matrix for all of the parents of this node. If self is true, then include our own transform too.

func (*NodeBase) PushTransform added in v0.1.18

func (g *NodeBase) PushTransform(sv *SVG) (bool, *paint.Context)

PushTransform checks our bounding box and visibility, returning false if out of bounds. If visible, pushes our transform. Must be called as first step in Render.

func (*NodeBase) ReadGeom

func (g *NodeBase) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*NodeBase) ReadTransform added in v0.1.18

func (g *NodeBase) ReadTransform(dat []float32, idx int)

ReadTransform reads the node transform from slice at starting index.

func (*NodeBase) Render

func (g *NodeBase) Render(sv *SVG)

func (*NodeBase) RenderChildren

func (g *NodeBase) RenderChildren(sv *SVG)

func (*NodeBase) SVGName

func (g *NodeBase) SVGName() string

func (*NodeBase) SetClass added in v0.1.18

func (t *NodeBase) SetClass(v string) *NodeBase

SetClass sets the [NodeBase.Class]: user-defined class name(s) used primarily for attaching CSS styles to different display elements -- multiple class names can be used to combine properties: use spaces to separate per css standard

func (*NodeBase) SetColorProps

func (g *NodeBase) SetColorProps(prop, color string)

SetColorProps sets color property from a string representation. It breaks color alpha out as opacity. prop is either "stroke" or "fill"

func (*NodeBase) SetPos

func (g *NodeBase) SetPos(pos mat32.Vec2)

func (*NodeBase) SetSize

func (g *NodeBase) SetSize(sz mat32.Vec2)

func (*NodeBase) Style

func (g *NodeBase) Style(sv *SVG)

Style styles the Paint values directly from node properties

func (*NodeBase) StyleCSS

func (g *NodeBase) StyleCSS(sv *SVG, css ki.Props)

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

func (*NodeBase) WriteGeom

func (g *NodeBase) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

func (*NodeBase) WriteTransform added in v0.1.18

func (g *NodeBase) WriteTransform(dat []float32, idx int)

WriteTransform writes the node transform to slice at starting index. slice must already be allocated sufficiently.

type NodeFlags

type NodeFlags ki.Flags //enums:bitflag

NodeFlags extend ki.Flags to hold SVG node state

const (
	// Rendering means that the SVG is currently redrawing
	// Can be useful to check for animations etc to decide whether to
	// drive another update
	IsDef NodeFlags = NodeFlags(ki.FlagsN) + iota
)
const NodeFlagsN NodeFlags = 8

NodeFlagsN is the highest valid value for type NodeFlags, plus one.

func NodeFlagsValues

func NodeFlagsValues() []NodeFlags

NodeFlagsValues returns all possible values for the type NodeFlags.

func (NodeFlags) BitIndexString

func (i NodeFlags) BitIndexString() string

BitIndexString returns the string representation of this NodeFlags value if it is a bit index value (typically an enum constant), and not an actual bit flag value.

func (NodeFlags) Desc

func (i NodeFlags) Desc() string

Desc returns the description of the NodeFlags value.

func (NodeFlags) HasFlag

func (i NodeFlags) HasFlag(f enums.BitFlag) bool

HasFlag returns whether these bit flags have the given bit flag set.

func (NodeFlags) Int64

func (i NodeFlags) Int64() int64

Int64 returns the NodeFlags value as an int64.

func (NodeFlags) IsValid

func (i NodeFlags) IsValid() bool

IsValid returns whether the value is a valid option for type NodeFlags.

func (NodeFlags) MarshalText

func (i NodeFlags) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*NodeFlags) SetFlag

func (i *NodeFlags) SetFlag(on bool, f ...enums.BitFlag)

SetFlag sets the value of the given flags in these flags to the given value.

func (*NodeFlags) SetInt64

func (i *NodeFlags) SetInt64(in int64)

SetInt64 sets the NodeFlags value from an int64.

func (*NodeFlags) SetString

func (i *NodeFlags) SetString(s string) error

SetString sets the NodeFlags value from its string representation, and returns an error if the string is invalid.

func (*NodeFlags) SetStringOr

func (i *NodeFlags) SetStringOr(s string) error

SetStringOr sets the NodeFlags value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.

func (NodeFlags) String

func (i NodeFlags) String() string

String returns the string representation of this NodeFlags value.

func (*NodeFlags) UnmarshalText

func (i *NodeFlags) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (NodeFlags) Values

func (i NodeFlags) Values() []enums.Enum

Values returns all possible values for the type NodeFlags.

type Path

type Path struct {
	NodeBase

	// the path data to render -- path commands and numbers are serialized, with each command specifying the number of floating-point coord data points that follow
	Data []PathData `xml:"-" set:"-"`

	// string version of the path data
	DataStr string `xml:"d"`
}

Path renders SVG data sequences that can render just about anything

func NewPath

func NewPath(par ki.Ki, name ...string) *Path

NewPath adds a new Path with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Path) ApplyDeltaTransform added in v0.1.18

func (g *Path) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Path) ApplyTransform added in v0.1.18

func (g *Path) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Path) ApplyTransformImpl added in v0.1.18

func (g *Path) ApplyTransformImpl(xf mat32.Mat2, lpt mat32.Vec2)

ApplyTransformImpl does the implementation of applying a transform to all points

func (*Path) CopyFieldsFrom

func (g *Path) CopyFieldsFrom(frm any)

func (*Path) KiType added in v0.1.2

func (t *Path) KiType() *gti.Type

KiType returns the *gti.Type of Path

func (*Path) LocalBBox

func (g *Path) LocalBBox() mat32.Box2

func (*Path) New

func (t *Path) New() ki.Ki

New returns a new *Path value

func (*Path) ReadGeom

func (g *Path) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Path) Render

func (g *Path) Render(sv *SVG)

func (*Path) SVGName

func (g *Path) SVGName() string

func (*Path) SetClass added in v0.1.18

func (t *Path) SetClass(v string) *Path

SetClass sets the [Path.Class]

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

func (*Path) SetDataStr added in v0.1.18

func (t *Path) SetDataStr(v string) *Path

SetDataStr sets the [Path.DataStr]: string version of the path data

func (*Path) SetPos

func (g *Path) SetPos(pos mat32.Vec2)

func (*Path) SetSize

func (g *Path) SetSize(sz mat32.Vec2)

func (*Path) WriteGeom

func (g *Path) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type PathCmds

type PathCmds byte //enum: enum

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

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 {
	Polyline
}

Polygon is a SVG polygon

func NewPolygon

func NewPolygon(par ki.Ki, name ...string) *Polygon

NewPolygon adds a new Polygon with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Polygon) KiType added in v0.1.2

func (t *Polygon) KiType() *gti.Type

KiType returns the *gti.Type of Polygon

func (*Polygon) New

func (t *Polygon) New() ki.Ki

New returns a new *Polygon value

func (*Polygon) Render

func (g *Polygon) Render(sv *SVG)

func (*Polygon) SVGName

func (g *Polygon) SVGName() string

func (*Polygon) SetClass added in v0.1.18

func (t *Polygon) SetClass(v string) *Polygon

SetClass sets the [Polygon.Class]

func (*Polygon) SetPoints added in v0.1.18

func (t *Polygon) SetPoints(v []mat32.Vec2) *Polygon

SetPoints sets the [Polygon.Points]

type Polyline

type Polyline struct {
	NodeBase

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

Polyline is a SVG multi-line shape

func NewPolyline

func NewPolyline(par ki.Ki, name ...string) *Polyline

NewPolyline adds a new Polyline with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Polyline) ApplyDeltaTransform added in v0.1.18

func (g *Polyline) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Polyline) ApplyTransform added in v0.1.18

func (g *Polyline) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Polyline) CopyFieldsFrom

func (g *Polyline) CopyFieldsFrom(frm any)

func (*Polyline) KiType added in v0.1.2

func (t *Polyline) KiType() *gti.Type

KiType returns the *gti.Type of Polyline

func (*Polyline) LocalBBox

func (g *Polyline) LocalBBox() mat32.Box2

func (*Polyline) New

func (t *Polyline) New() ki.Ki

New returns a new *Polyline value

func (*Polyline) ReadGeom

func (g *Polyline) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Polyline) Render

func (g *Polyline) Render(sv *SVG)

func (*Polyline) SVGName

func (g *Polyline) SVGName() string

func (*Polyline) SetClass added in v0.1.18

func (t *Polyline) SetClass(v string) *Polyline

SetClass sets the [Polyline.Class]

func (*Polyline) SetPoints added in v0.1.18

func (t *Polyline) SetPoints(v []mat32.Vec2) *Polyline

SetPoints sets the [Polyline.Points]: the coordinates to draw -- does a moveto on the first, then lineto for all the rest

func (*Polyline) SetPos

func (g *Polyline) SetPos(pos mat32.Vec2)

func (*Polyline) SetSize

func (g *Polyline) SetSize(sz mat32.Vec2)

func (*Polyline) WriteGeom

func (g *Polyline) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type Rect

type Rect struct {
	NodeBase

	// position of the top-left of the rectangle
	Pos mat32.Vec2 `xml:"{x,y}"`

	// size of the rectangle
	Size mat32.Vec2 `xml:"{width,height}"`

	// radii for curved corners, as a proportion of width, height
	Radius mat32.Vec2 `xml:"{rx,ry}"`
}

Rect is a SVG rectangle, optionally with rounded corners

func NewRect

func NewRect(par ki.Ki, name ...string) *Rect

NewRect adds a new Rect with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Rect) ApplyDeltaTransform added in v0.1.18

func (g *Rect) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Rect) ApplyTransform added in v0.1.18

func (g *Rect) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Rect) CopyFieldsFrom

func (g *Rect) CopyFieldsFrom(frm any)

func (*Rect) KiType added in v0.1.2

func (t *Rect) KiType() *gti.Type

KiType returns the *gti.Type of Rect

func (*Rect) LocalBBox

func (g *Rect) LocalBBox() mat32.Box2

func (*Rect) New

func (t *Rect) New() ki.Ki

New returns a new *Rect value

func (*Rect) OnInit added in v0.1.18

func (g *Rect) OnInit()

func (*Rect) ReadGeom

func (g *Rect) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Rect) Render

func (g *Rect) Render(sv *SVG)

func (*Rect) SVGName

func (g *Rect) SVGName() string

func (*Rect) SetClass added in v0.1.18

func (t *Rect) SetClass(v string) *Rect

SetClass sets the [Rect.Class]

func (*Rect) SetPos

func (t *Rect) SetPos(v mat32.Vec2) *Rect

SetPos sets the [Rect.Pos]: position of the top-left of the rectangle

func (*Rect) SetRadius added in v0.1.18

func (t *Rect) SetRadius(v mat32.Vec2) *Rect

SetRadius sets the [Rect.Radius]: radii for curved corners, as a proportion of width, height

func (*Rect) SetSize

func (t *Rect) SetSize(v mat32.Vec2) *Rect

SetSize sets the [Rect.Size]: size of the rectangle

func (*Rect) WriteGeom

func (g *Rect) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type SVG

type SVG struct {
	// Name is the name of the SVG -- e.g., the filename if loaded
	Name string

	// the title of the svg
	Title string `xml:"title"`

	// the description of the svg
	Desc string `xml:"desc"`

	// fill the viewport with Background
	Fill bool

	// image/color to fill background with if Fill is on
	Background image.Image

	// Color can be set to provide a default Fill and Stroke Color value
	Color image.Image

	// Size is size of image, Pos is offset within any parent viewport.
	// Node bounding boxes are based on 0 Pos offset within Pixels image
	Geom mat32.Geom2DInt

	// physical width of the drawing, e.g., when printed -- does not affect rendering -- metadata
	PhysWidth units.Value

	// physical height of the drawing, e.g., when printed -- does not affect rendering -- metadata
	PhysHeight units.Value

	// Norm installs a transform that renormalizes so that the specified
	// ViewBox exactly fits within the allocated SVG size.
	Norm bool

	// InvertY, when doing Norm transform, also flip the Y axis so that
	// the smallest Y value is at the bottom of the SVG box,
	// instead of being at the top as it is by default.
	InvertY bool

	// Translate specifies a translation to apply beyond what is specified in the SVG,
	// and in addition to the effects of Norm if active.
	Translate mat32.Vec2

	// Scale specifies a zoom scale factor to apply beyond what is specified in the SVG,
	// and in addition to the effects of Norm if active.
	Scale float32

	// render state for rendering
	RenderState paint.State `copy:"-" json:"-" xml:"-" edit:"-"`

	// live pixels that we render into
	Pixels *image.RGBA `copy:"-" json:"-" xml:"-" edit:"-"`

	// all defs defined elements go here (gradients, symbols, etc)
	Defs Group

	// root of the svg tree -- top-level viewbox and paint style here
	Root SVGNode

	// map of def names to index -- uses starting index to find element -- always updated after each search
	DefIdxs map[string]int `view:"-" json:"-" xml:"-"`

	// map of unique numeric ids for all elements -- used for allocating new unique id numbers, appended to end of elements -- see NewUniqueId, GatherIds
	UniqueIds map[int]struct{} `view:"-" json:"-" xml:"-"`

	// mutex for protecting rendering
	RenderMu sync.Mutex `view:"-" json:"-" xml:"-"`
}

SVG is an SVG object.

func NewSVG

func NewSVG(width, height int) *SVG

NewSVG creates a SVG with Pixels Image of the specified width and height

func (*SVG) Base added in v0.1.6

func (sv *SVG) Base() color.RGBA

Base returns the current Color activated in the context. Color has support for special color names that are relative to this current color.

func (*SVG) Config

func (sv *SVG) Config(width, height int)

Config configures the SVG, setting image to given size and initializing all relevant fields.

func (*SVG) CopyFrom

func (sv *SVG) CopyFrom(fr *SVG)

func (*SVG) DeleteAll

func (sv *SVG) DeleteAll()

DeleteAll deletes any existing elements in this svg

func (*SVG) FillViewport

func (sv *SVG) FillViewport()

func (*SVG) FindDefByName

func (sv *SVG) FindDefByName(defnm string) Node

FindDefByName finds Defs item by name, using cached indexes for speed

func (*SVG) FindNamedElement

func (sv *SVG) FindNamedElement(name string) Node

func (*SVG) GatherIds

func (sv *SVG) GatherIds()

GatherIds gathers all the numeric id suffixes currently in use. It automatically renames any that are not unique or empty.

func (*SVG) GradientByName

func (sv *SVG) GradientByName(n Node, grnm string) *Gradient

GradientByName returns the gradient of given name, stored on SVG node

func (*SVG) GradientCloneNodeProp

func (sv *SVG) GradientCloneNodeProp(n Node, prop string) *Gradient

GradientCloneNodeProp creates a new clone of the existing gradient for node if set for given property key ("fill" or "stroke"). returns new gradient.

func (*SVG) GradientDeleteForNode

func (sv *SVG) GradientDeleteForNode(n Node, grnm string) bool

GradientDeleteForNode deletes the node-specific gradient on given node of given name, which can be a full url(# name or just the bare name. Returns true if deleted.

func (*SVG) GradientDeleteNodeProp

func (sv *SVG) GradientDeleteNodeProp(n Node, prop string) bool

GradientDeleteNodeProp deletes any existing gradient for node if set for given property key ("fill" or "stroke"). Returns true if deleted.

func (*SVG) GradientNew

func (sv *SVG) GradientNew(radial bool) (*Gradient, string)

GradientNew adds a new gradient, either linear or radial, with a new unique id

func (*SVG) GradientNewForNode

func (sv *SVG) GradientNewForNode(n Node, radial bool, stops string) (*Gradient, string)

GradientNewForNode adds a new gradient specific to given node that points to given stops name. returns the new gradient and the url that points to it (nil if parent svg cannot be found). Initializes gradient to use bounding box of object, but using userSpaceOnUse setting

func (*SVG) GradientUpdateAllStops

func (sv *SVG) GradientUpdateAllStops()

GradientUpdateAllStops removes any items from Defs that are not actually referred to by anything in the current SVG tree. Returns true if items were removed. Does not remove gradients with StopsName = "" with extant stops -- these should be removed manually, as they are not automatically generated.

func (*SVG) GradientUpdateNodePoints

func (sv *SVG) GradientUpdateNodePoints(n Node, prop string)

GradientUpdateNodePoints updates the points for node based on current bbox

func (*SVG) GradientUpdateNodeProp

func (sv *SVG) GradientUpdateNodeProp(n Node, prop string, radial bool, stops string) (*Gradient, string)

GradientUpdateNodeProp ensures that node has a gradient property of given type

func (*SVG) GradientUpdateStops

func (sv *SVG) GradientUpdateStops(gr *Gradient)

GradientUpdateStops copies stops from StopsName gradient if it is set

func (*SVG) ImageByURL added in v0.1.26

func (sv *SVG) ImageByURL(url string) image.Image

ImageByURL finds a Node by an element name (URL-like path), and attempts to convert it to an image.Image. Used for color styling based on url() value.

func (*SVG) MarkerByName

func (sv *SVG) MarkerByName(gi Node, marker string) *Marker

MarkerByName finds marker property of given name, or generic "marker" type, and if set, attempts to find that marker and return it

func (*SVG) MarshalXMLx

func (sv *SVG) MarshalXMLx(enc *XMLEncoder, se xml.StartElement) error

MarshalXMLx marshals the svg using XMLEncoder

func (*SVG) NewUniqueId

func (sv *SVG) NewUniqueId() int

NewUniqueId returns a new unique numerical id number, for naming an object

func (*SVG) NodeEnsureUniqueId

func (sv *SVG) NodeEnsureUniqueId(ni Node)

NodeEnsureUniqueId ensures that the given node has a unique Id Call this on any newly-created nodes.

func (*SVG) NodeFindURL

func (sv *SVG) NodeFindURL(gi Node, url string) Node

NodeFindURL finds a url element in the parent SVG of given node. Returns nil if not found. Works with full 'url(#Name)' string or plain name or "none"

func (*SVG) OpenFS added in v0.1.6

func (sv *SVG) OpenFS(fsys fs.FS, fname string) error

OpenFS Opens XML-formatted SVG input from given file, filesystem FS

func (*SVG) OpenXML

func (sv *SVG) OpenXML(fname string) error

OpenXML Opens XML-formatted SVG input from given file

func (*SVG) ReadXML

func (sv *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.

func (*SVG) RemoveOrphanedDefs

func (sv *SVG) RemoveOrphanedDefs() bool

RemoveOrphanedDefs removes any items from Defs that are not actually referred to by anything in the current SVG tree. Returns true if items were removed. Does not remove gradients with StopsName = "" with extant stops -- these should be removed manually, as they are not automatically generated.

func (*SVG) Render

func (sv *SVG) Render()

func (*SVG) Resize

func (sv *SVG) Resize(nwsz image.Point)

Resize resizes the viewport, creating a new image -- updates Geom Size

func (*SVG) SavePNG added in v0.1.26

func (sv *SVG) SavePNG(fname string) error

SavePNG saves the Pixels to a PNG file

func (*SVG) SaveXML

func (sv *SVG) SaveXML(fname string) error

SaveXML saves the svg to a XML-encoded file, using WriteXML

func (*SVG) SetDPITransform added in v0.1.18

func (sv *SVG) SetDPITransform(logicalDPI float32)

SetDPITransform sets a scaling transform to compensate for a given LogicalDPI factor. svg rendering is done within a 96 DPI context.

func (*SVG) SetRootTransform added in v0.1.26

func (sv *SVG) SetRootTransform()

SetRootTransform sets the Root node transform based on Norm, Translate, Scale parameters set on the SVG object.

func (*SVG) SetUnitContext

func (sv *SVG) SetUnitContext(pc *styles.Paint, el, par mat32.Vec2)

SetUnitContext sets the unit context based on size of viewport, element, and parent element (from bbox) and then caches everything out in terms of raw pixel dots for rendering -- call at start of render

func (*SVG) Style

func (sv *SVG) Style()

func (*SVG) UnmarshalXML

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

UnmarshalXML unmarshals the svg using xml.Decoder

func (*SVG) WriteXML

func (sv *SVG) WriteXML(wr io.Writer, indent bool) error

WriteXML writes XML-formatted SVG output to io.Writer, and uses XMLEncoder

type SVGNode

type SVGNode struct {
	Group

	// viewbox defines the coordinate system for the drawing -- these units are mapped into the screen space allocated for the SVG during rendering
	ViewBox ViewBox
}

SVGNode represents the root of an SVG tree

func NewSVGNode

func NewSVGNode(par ki.Ki, name ...string) *SVGNode

NewSVGNode adds a new SVGNode with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*SVGNode) CopyFieldsFrom

func (g *SVGNode) CopyFieldsFrom(frm any)

func (*SVGNode) EnforceSVGName

func (g *SVGNode) EnforceSVGName() bool

func (*SVGNode) KiType added in v0.1.2

func (t *SVGNode) KiType() *gti.Type

KiType returns the *gti.Type of SVGNode

func (*SVGNode) New

func (t *SVGNode) New() ki.Ki

New returns a new *SVGNode value

func (*SVGNode) NodeBBox

func (g *SVGNode) NodeBBox(sv *SVG) image.Rectangle

func (*SVGNode) SVGName

func (g *SVGNode) SVGName() string

func (*SVGNode) SetClass added in v0.1.18

func (t *SVGNode) SetClass(v string) *SVGNode

SetClass sets the [SVGNode.Class]

func (*SVGNode) SetViewBox added in v0.1.18

func (t *SVGNode) SetViewBox(v ViewBox) *SVGNode

SetViewBox sets the [SVGNode.ViewBox]: viewbox defines the coordinate system for the drawing -- these units are mapped into the screen space allocated for the SVG during rendering

type StyleSheet

type StyleSheet struct {
	NodeBase
	Sheet *css.Stylesheet
}

StyleSheet is a Node2D node that contains a stylesheet -- property values contained in this sheet can be transformed into ki.Props and set in CSS field of appropriate node

func AddNewStyleSheet

func AddNewStyleSheet(parent ki.Ki, name string) *StyleSheet

AddNewStyleSheet adds a new CSS stylesheet to given parent node, with given name.

func NewStyleSheet

func NewStyleSheet(par ki.Ki, name ...string) *StyleSheet

NewStyleSheet adds a new StyleSheet with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*StyleSheet) CSSProps

func (ss *StyleSheet) CSSProps() ki.Props

CSSProps returns the properties for each of the rules in this style sheet, suitable for setting the CSS value of a node -- returns nil if empty sheet

func (*StyleSheet) CopyFieldsFrom

func (ss *StyleSheet) CopyFieldsFrom(frm any)

func (*StyleSheet) KiType added in v0.1.2

func (t *StyleSheet) KiType() *gti.Type

KiType returns the *gti.Type of StyleSheet

func (*StyleSheet) New

func (t *StyleSheet) New() ki.Ki

New returns a new *StyleSheet value

func (*StyleSheet) ParseString

func (ss *StyleSheet) ParseString(str string) error

ParseString parses the string into a StyleSheet of rules, which can then be used for extracting properties

func (*StyleSheet) SetClass added in v0.1.18

func (t *StyleSheet) SetClass(v string) *StyleSheet

SetClass sets the [StyleSheet.Class]

func (*StyleSheet) SetSheet added in v0.1.18

func (t *StyleSheet) SetSheet(v *css.Stylesheet) *StyleSheet

SetSheet sets the [StyleSheet.Sheet]

type Text

type Text struct {
	NodeBase

	// position of the left, baseline of the text
	Pos mat32.Vec2 `xml:"{x,y}" set:"-"`

	// width of text to render if using word-wrapping
	Width float32 `xml:"width"`

	// text string to render
	Text string `xml:"text"`

	// render version of text
	TextRender paint.Text `xml:"-" json:"-"`

	// character positions along X axis, if specified
	CharPosX []float32

	// character positions along Y axis, if specified
	CharPosY []float32

	// character delta-positions along X axis, if specified
	CharPosDX []float32

	// character delta-positions along Y axis, if specified
	CharPosDY []float32

	// character rotations, if specified
	CharRots []float32

	// author's computed text length, if specified -- we attempt to match
	TextLength float32

	// in attempting to match TextLength, should we adjust glyphs in addition to spacing?
	AdjustGlyphs bool

	// last text render position -- lower-left baseline of start
	LastPos mat32.Vec2 `xml:"-" json:"-"`

	// last actual bounding box in display units (dots)
	LastBBox mat32.Box2 `xml:"-" json:"-"`
}

Text renders SVG text, handling both text and tspan elements. tspan is nested under a parent text -- text has empty Text string.

func NewText

func NewText(par ki.Ki, name ...string) *Text

NewText adds a new Text with the given name to the given parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the ki.Ki.NumLifetimeChildren of the given parent.

func (*Text) ApplyDeltaTransform added in v0.1.18

func (g *Text) ApplyDeltaTransform(sv *SVG, trans mat32.Vec2, scale mat32.Vec2, rot float32, pt mat32.Vec2)

ApplyDeltaTransform applies the given 2D delta transforms to the geometry of this node relative to given point. Trans translation and point are in top-level coordinates, so must be transformed into local coords first. Point is upper left corner of selection box that anchors the translation and scaling, and for rotation it is the center point around which to rotate

func (*Text) ApplyTransform added in v0.1.18

func (g *Text) ApplyTransform(sv *SVG, xf mat32.Mat2)

ApplyTransform applies the given 2D transform to the geometry of this node each node must define this for itself

func (*Text) CopyFieldsFrom

func (g *Text) CopyFieldsFrom(frm any)

func (*Text) IsParText

func (g *Text) IsParText() bool

IsParText returns true if this element serves as a parent text element to tspan elements within it. This is true if NumChildren() > 0 and Text == ""

func (*Text) KiType added in v0.1.2

func (t *Text) KiType() *gti.Type

KiType returns the *gti.Type of Text

func (*Text) LocalBBox

func (g *Text) LocalBBox() mat32.Box2

func (*Text) New

func (t *Text) New() ki.Ki

New returns a new *Text value

func (*Text) NodeBBox

func (g *Text) NodeBBox(sv *SVG) image.Rectangle

func (*Text) ReadGeom

func (g *Text) ReadGeom(sv *SVG, dat []float32)

ReadGeom reads the geometry of the node from a slice of floating point numbers the length and ordering of which is specific to each node type.

func (*Text) Render

func (g *Text) Render(sv *SVG)

func (*Text) RenderText

func (g *Text) RenderText(sv *SVG)

RenderText renders the text in full coords

func (*Text) SVGName

func (g *Text) SVGName() string

func (*Text) SetAdjustGlyphs added in v0.1.18

func (t *Text) SetAdjustGlyphs(v bool) *Text

SetAdjustGlyphs sets the [Text.AdjustGlyphs]: in attempting to match TextLength, should we adjust glyphs in addition to spacing?

func (*Text) SetCharPosDx added in v0.1.18

func (t *Text) SetCharPosDx(v []float32) *Text

SetCharPosDx sets the [Text.CharPosDX]: character delta-positions along X axis, if specified

func (*Text) SetCharPosDy added in v0.1.18

func (t *Text) SetCharPosDy(v []float32) *Text

SetCharPosDy sets the [Text.CharPosDY]: character delta-positions along Y axis, if specified

func (*Text) SetCharPosX added in v0.1.18

func (t *Text) SetCharPosX(v []float32) *Text

SetCharPosX sets the [Text.CharPosX]: character positions along X axis, if specified

func (*Text) SetCharPosY added in v0.1.18

func (t *Text) SetCharPosY(v []float32) *Text

SetCharPosY sets the [Text.CharPosY]: character positions along Y axis, if specified

func (*Text) SetCharRots added in v0.1.18

func (t *Text) SetCharRots(v []float32) *Text

SetCharRots sets the [Text.CharRots]: character rotations, if specified

func (*Text) SetClass added in v0.1.18

func (t *Text) SetClass(v string) *Text

SetClass sets the [Text.Class]

func (*Text) SetLastBbox added in v0.1.18

func (t *Text) SetLastBbox(v mat32.Box2) *Text

SetLastBbox sets the [Text.LastBBox]: last actual bounding box in display units (dots)

func (*Text) SetLastPos added in v0.1.18

func (t *Text) SetLastPos(v mat32.Vec2) *Text

SetLastPos sets the [Text.LastPos]: last text render position -- lower-left baseline of start

func (*Text) SetPos

func (g *Text) SetPos(pos mat32.Vec2) *Text

func (*Text) SetSize

func (g *Text) SetSize(sz mat32.Vec2) *Text

func (*Text) SetText added in v0.1.18

func (t *Text) SetText(v string) *Text

SetText sets the [Text.Text]: text string to render

func (*Text) SetTextLength added in v0.1.18

func (t *Text) SetTextLength(v float32) *Text

SetTextLength sets the [Text.TextLength]: author's computed text length, if specified -- we attempt to match

func (*Text) SetTextRender added in v0.1.18

func (t *Text) SetTextRender(v paint.Text) *Text

SetTextRender sets the [Text.TextRender]: render version of text

func (*Text) SetWidth added in v0.1.18

func (t *Text) SetWidth(v float32) *Text

SetWidth sets the [Text.Width]: width of text to render if using word-wrapping

func (*Text) TextBBox

func (g *Text) TextBBox() mat32.Box2

TextBBox returns the bounding box in local coordinates

func (*Text) WriteGeom

func (g *Text) WriteGeom(sv *SVG, dat *[]float32)

WriteGeom writes the geometry of the node to a slice of floating point numbers the length and ordering of which is specific to each node type. Slice must be passed and will be resized if not the correct length.

type ViewBox

type ViewBox struct {

	// offset or starting point in parent Viewport2D
	Min mat32.Vec2

	// size of viewbox within parent Viewport2D
	Size mat32.Vec2

	// how to scale the view box within parent
	PreserveAspectRatio ViewBoxPreserveAspectRatio
}

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 //enums:enum

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
)
const ViewBoxMeetOrSliceN ViewBoxMeetOrSlice = 2

ViewBoxMeetOrSliceN is the highest valid value for type ViewBoxMeetOrSlice, plus one.

func ViewBoxMeetOrSliceValues

func ViewBoxMeetOrSliceValues() []ViewBoxMeetOrSlice

ViewBoxMeetOrSliceValues returns all possible values for the type ViewBoxMeetOrSlice.

func (ViewBoxMeetOrSlice) Desc

func (i ViewBoxMeetOrSlice) Desc() string

Desc returns the description of the ViewBoxMeetOrSlice value.

func (ViewBoxMeetOrSlice) Int64

func (i ViewBoxMeetOrSlice) Int64() int64

Int64 returns the ViewBoxMeetOrSlice value as an int64.

func (ViewBoxMeetOrSlice) IsValid

func (i ViewBoxMeetOrSlice) IsValid() bool

IsValid returns whether the value is a valid option for type ViewBoxMeetOrSlice.

func (ViewBoxMeetOrSlice) MarshalText

func (i ViewBoxMeetOrSlice) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*ViewBoxMeetOrSlice) SetInt64

func (i *ViewBoxMeetOrSlice) SetInt64(in int64)

SetInt64 sets the ViewBoxMeetOrSlice value from an int64.

func (*ViewBoxMeetOrSlice) SetString

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

SetString sets the ViewBoxMeetOrSlice value from its string representation, and returns an error if the string is invalid.

func (ViewBoxMeetOrSlice) String

func (i ViewBoxMeetOrSlice) String() string

String returns the string representation of this ViewBoxMeetOrSlice value.

func (*ViewBoxMeetOrSlice) UnmarshalText

func (i *ViewBoxMeetOrSlice) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (ViewBoxMeetOrSlice) Values

func (i ViewBoxMeetOrSlice) Values() []enums.Enum

Values returns all possible values for the type ViewBoxMeetOrSlice.

type ViewBoxPreserveAspectRatio

type ViewBoxPreserveAspectRatio struct {

	// how to align x,y coordinates within viewbox
	Align ViewBoxAlign `svg:"align"`

	// how to scale the view box relative to the viewport
	MeetOrSlice ViewBoxMeetOrSlice `svg:"meetOrSlice"`
}

ViewBoxPreserveAspectRatio determines how to scale the view box within parent Viewport2D

type XMLEncoder

type XMLEncoder struct {
	Writer      io.Writer
	DoIndent    bool
	IndBytes    []byte
	PreBytes    []byte
	CurIndent   int
	CurStart    string
	NoEndIndent bool
}

XMLEncoder is a minimal XML encoder that formats output with Attr each on a new line, using same API as xml.Encoder

func NewXMLEncoder

func NewXMLEncoder(wr io.Writer) *XMLEncoder

func (*XMLEncoder) EncodeToken

func (xe *XMLEncoder) EncodeToken(t xml.Token) error

func (*XMLEncoder) EscapeString

func (xe *XMLEncoder) EscapeString(s string, escapeNewline bool)

EscapeString writes to p the properly escaped XML equivalent of the plain text data s.

func (*XMLEncoder) Flush

func (xe *XMLEncoder) Flush()

func (*XMLEncoder) Indent

func (xe *XMLEncoder) Indent(prefix, indent string)

func (*XMLEncoder) WriteEOL

func (xe *XMLEncoder) WriteEOL()

func (*XMLEncoder) WriteEnd

func (xe *XMLEncoder) WriteEnd(name string) error

func (*XMLEncoder) WriteIndent

func (xe *XMLEncoder) WriteIndent()

func (*XMLEncoder) WriteStart

func (xe *XMLEncoder) WriteStart(start *xml.StartElement) error

func (*XMLEncoder) WriteString

func (xe *XMLEncoder) WriteString(str string)

Jump to

Keyboard shortcuts

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