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 ¶
- Variables
- func ApplyCSSSVG(node gi.Node2D, key string, css ki.Props) bool
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func MustAsset(name string) []byte
- func PathDataEnd(data []PathData) (vec mat32.Vec2, ang float32)
- func PathDataIterFunc(data []PathData, ...)
- func PathDataMinMax(data []PathData) (min, max mat32.Vec2)
- func PathDataNext(data []PathData, i *int) float32
- func PathDataRender(data []PathData, pc *gi.Paint, rs *gi.RenderState)
- func PathDataStart(data []PathData) (vec mat32.Vec2, ang float32)
- func PathDataValidate(pc *gi.Paint, data *[]PathData, errstr string) error
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func StyleCSS(node gi.Node2D, css ki.Props)
- func StyleSVG(gii gi.Node2D)
- type Circle
- type ClipPath
- type Editor
- type Ellipse
- type Filter
- type Flow
- type Group
- type Icon
- type IconMgr
- type IconSet
- type Line
- type Marker
- type MarkerUnits
- type NodeBase
- func (g *NodeBase) AsSVGNode() *NodeBase
- func (g *NodeBase) BBox2D() image.Rectangle
- func (g *NodeBase) ChildrenBBox2D() image.Rectangle
- func (g *NodeBase) ComputeBBox2D(parBBox image.Rectangle, delta image.Point)
- func (g *NodeBase) ComputeBBoxSVG()
- func (g *NodeBase) CopyFieldsFrom(frm interface{})
- func (g *NodeBase) FindSVGURL(url string) gi.Node2D
- func (g *NodeBase) Init2D()
- func (g *NodeBase) Init2DBase()
- func (g *NodeBase) Layout2D(parBBox image.Rectangle, iter int) bool
- func (g *NodeBase) Marker(marker string) *Marker
- func (g *NodeBase) Move2D(delta image.Point, parBBox image.Rectangle)
- func (g *NodeBase) Paint() *gi.Paint
- func (g *NodeBase) ParentSVG() *SVG
- func (g *NodeBase) Render2D()
- func (g *NodeBase) Size2D(iter int)
- func (g *NodeBase) Style2D()
- type Path
- type PathCmds
- type PathData
- type Polygon
- type Polyline
- type Rect
- type SVG
- func (svg *SVG) CopyFieldsFrom(frm interface{})
- func (svg *SVG) DeleteAll()
- func (svg *SVG) FindNamedElement(name string) gi.Node2D
- func (svg *SVG) Init2D()
- func (svg *SVG) Layout2D(parBBox image.Rectangle, iter int) bool
- func (svg *SVG) OpenXML(filename string) error
- func (svg *SVG) Paint() *gi.Paint
- func (svg *SVG) ReadXML(reader io.Reader) error
- func (svg *SVG) Render2D()
- func (svg *SVG) SetDPIXForm()
- func (svg *SVG) SetNormXForm()
- func (svg *SVG) Size2D(iter int)
- func (svg *SVG) Style2D()
- func (svg *SVG) StyleSVG()
- func (svg *SVG) UnmarshalXML(decoder *xml.Decoder, se xml.StartElement) error
- type Text
- type ViewBox
- type ViewBoxAlign
- type ViewBoxMeetOrSlice
- type ViewBoxPreserveAspectRatio
Constants ¶
This section is empty.
Variables ¶
var EditorProps = ki.Props{ "EnumType:Flag": gi.KiT_VpFlags, }
var IconAutoOpen = true
IconAutoOpen controls auto-loading of icons -- can turn this off for debugging etc
var IconProps = ki.Props{ "EnumType:Flag": gi.KiT_VpFlags, "background-color": color.Transparent, }
var KiT_Circle = kit.Types.AddType(&Circle{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_ClipPath = kit.Types.AddType(&ClipPath{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Editor = kit.Types.AddType(&Editor{}, EditorProps)
var KiT_Ellipse = kit.Types.AddType(&Ellipse{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Filter = kit.Types.AddType(&Filter{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Flow = kit.Types.AddType(&Flow{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Group = kit.Types.AddType(&Group{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Icon = kit.Types.AddType(&Icon{}, IconProps)
var KiT_Line = kit.Types.AddType(&Line{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Marker = kit.Types.AddType(&Marker{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_MarkerUnits = kit.Enums.AddEnumAltLower(MarkerUnitsN, kit.NotBitFlag, gi.StylePropProps, "")
var KiT_NodeBase = kit.Types.AddType(&NodeBase{}, NodeBaseProps)
var KiT_Path = kit.Types.AddType(&Path{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_PathCmds = kit.Enums.AddEnumAltLower(PcErr, kit.NotBitFlag, nil, "Pc")
var KiT_Polygon = kit.Types.AddType(&Polygon{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_Polyline = kit.Types.AddType(&Polyline{}, nil)
var KiT_Rect = kit.Types.AddType(&Rect{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_SVG = kit.Types.AddType(&SVG{}, SVGProps)
var KiT_Text = kit.Types.AddType(&Text{}, ki.Props{"EnumType:Flag": gi.KiT_NodeFlags})
var KiT_ViewBoxMeetOrSlice = kit.Enums.AddEnumAltLower(ViewBoxMeetOrSliceN, kit.NotBitFlag, gi.StylePropProps, "")
var NodeBaseProps = ki.Props{ "base-type": true, "EnumType:Flag": gi.KiT_NodeFlags, }
var PathCmdMap = map[rune]PathCmds{ 'M': PcM, 'm': Pcm, 'L': PcL, 'l': Pcl, 'H': PcH, 'h': Pch, 'V': PcV, 'v': Pcv, 'C': PcC, 'c': Pcc, 'S': PcS, 's': Pcs, 'Q': PcQ, 'q': Pcq, 'T': PcT, 't': Pct, 'A': PcA, 'a': Pca, 'Z': PcZ, 'z': Pcz, }
PathCmdMap maps rune to path command
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
var SVGProps = ki.Props{ "EnumType:Flag": gi.KiT_VpFlags, }
Functions ¶
func ApplyCSSSVG ¶
ApplyCSSSVG applies css styles to given node, using key to select sub-props from overall properties list
func Asset ¶ added in v0.9.9
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶ added in v0.9.9
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶ added in v0.9.9
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetNames ¶ added in v0.9.9
func AssetNames() []string
AssetNames returns the names of the assets. nolint: deadcode
func MustAsset ¶ added in v0.9.9
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables. nolint: deadcode
func PathDataEnd ¶
PathDataEnd gets the ending coords and angle from the path
func PathDataIterFunc ¶
func PathDataIterFunc(data []PathData, fun func(idx int, cmd PathCmds, ptIdx int, cx, cy float32) bool)
PathDataIterFunc traverses the path data and calls given function on each coordinate point, passing overall starting index of coords in data stream, command, index of the points within that command, and coord values (absolute, not relative, regardless of the command type) -- if function returns false, then traversal is aborted
func PathDataMinMax ¶
PathDataMinMax traverses the path data and extracts the min and max point coords
func PathDataNext ¶
PathDataNext gets the next path data point, incrementing the index -- ++ not an expression so its clunky
func PathDataRender ¶
func PathDataRender(data []PathData, pc *gi.Paint, rs *gi.RenderState)
PathDataRender traverses the path data and renders it using paint and render state -- we assume all the data has been validated and that n's are sufficient, etc
func PathDataStart ¶
PathDataStart gets the starting coords and angle from the path
func PathDataValidate ¶
PathDataValidate validates the path data and emits error messages on log
func RestoreAsset ¶ added in v0.9.9
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶ added in v0.9.9
RestoreAssets restores an asset under the given directory recursively
Types ¶
type Circle ¶
type Circle struct { NodeBase Pos mat32.Vec2 `xml:"{cx,cy}" desc:"position of the center of the circle"` Radius float32 `xml:"r" desc:"radius of the circle"` }
Circle is a SVG circle
func AddNewCircle ¶ added in v0.9.7
AddNewCircle adds a new button to given parent node, with given name, x,y pos, and radius.
func (*Circle) CopyFieldsFrom ¶ added in v0.9.8
func (g *Circle) CopyFieldsFrom(frm interface{})
type ClipPath ¶
type ClipPath struct {
NodeBase
}
ClipPath is used for holding a path that renders as a clip path
func AddNewClipPath ¶ added in v0.9.7
AddNewClipPath adds a new clippath to given parent node, with given name.
func (*ClipPath) CopyFieldsFrom ¶ added in v0.9.8
func (g *ClipPath) CopyFieldsFrom(frm interface{})
type Editor ¶
type Editor struct { SVG Trans mat32.Vec2 `desc:"view translation offset (from dragging)"` Scale float32 `desc:"view scaling (from zooming)"` SetDragCursor bool `view:"-" desc:"has dragging cursor been set yet?"` }
Editor supports editing of SVG elements
func AddNewEditor ¶ added in v0.9.7
AddNewEditor adds a new editor to given parent node, with given name.
func (*Editor) ConnectEvents2D ¶ added in v0.9.8
func (svg *Editor) ConnectEvents2D()
func (*Editor) CopyFieldsFrom ¶ added in v0.9.8
func (g *Editor) CopyFieldsFrom(frm interface{})
func (*Editor) EditorEvents ¶
func (svg *Editor) EditorEvents()
EditorEvents handles svg editing events
func (*Editor) InitScale ¶
func (svg *Editor) InitScale()
InitScale ensures that Scale is initialized and non-zero
func (*Editor) SetTransform ¶
func (svg *Editor) SetTransform()
SetTransform sets the transform based on Trans and Scale values
type Ellipse ¶
type Ellipse struct { NodeBase Pos mat32.Vec2 `xml:"{cx,cy}" desc:"position of the center of the ellipse"` Radii mat32.Vec2 `xml:"{rx,ry}" desc:"radii of the ellipse in the horizontal, vertical axes"` }
Ellipse is a SVG ellipse
func AddNewEllipse ¶ added in v0.9.7
AddNewEllipse adds a new button to given parent node, with given name, pos and radii.
func (*Ellipse) CopyFieldsFrom ¶ added in v0.9.8
func (g *Ellipse) CopyFieldsFrom(frm interface{})
type Filter ¶
Filter represents SVG filter* elements
func AddNewFilter ¶ added in v0.9.7
AddNewFilter adds a new filter to given parent node, with given name.
func (*Filter) CopyFieldsFrom ¶ added in v0.9.8
func (g *Filter) CopyFieldsFrom(frm interface{})
type Flow ¶
Flow represents SVG flow* elements
func AddNewFlow ¶ added in v0.9.7
AddNewFlow adds a new flow to given parent node, with given name.
func (*Flow) CopyFieldsFrom ¶ added in v0.9.8
func (g *Flow) CopyFieldsFrom(frm interface{})
type Group ¶
type Group struct {
NodeBase
}
Group groups together SVG elements -- doesn't do much but provide a locus for properties etc
func AddNewGroup ¶ added in v0.9.7
AddNewGroup adds a new group to given parent node, with given name.
func (*Group) BBoxFromChildren ¶
BBoxFromChildren sets the Group BBox from children
func (*Group) CopyFieldsFrom ¶ added in v0.9.8
func (g *Group) CopyFieldsFrom(frm interface{})
type Icon ¶
type Icon struct { SVG Filename string `desc:"file name with full path for icon if loaded from file"` Rendered bool `` /* 169-byte string literal not displayed */ RendSize image.Point `copy:"-" json:"-" xml:"-" desc:"size at which we previously rendered"` }
svg.Icon is the actual SVG for a gi.Icon -- it should contain no color information -- it should just be a filled shape where the fill and stroke colors come from the surrounding context / paint settings. The rendered version is cached for a given size. Icons are always copied from an original source icon and then can be customized from there.
func AddNewIcon ¶ added in v0.9.7
AddNewIcon adds a new icon to given parent node, with given name.
func (*Icon) CopyFieldsFrom ¶ added in v0.9.8
func (ic *Icon) CopyFieldsFrom(frm interface{})
func (*Icon) CopyFromIcon ¶
CopyFromIcon copies from a source icon, typically one from a library -- preserves all the existing render state etc for the current icon, so that only a new render is required
func (*Icon) NeedsReRender ¶
NeedsReRender tests whether the last render parameters (size, color) have changed or not
type IconMgr ¶
type IconMgr struct { }
svg.IconMgr is THE implementation of the gi.IconMgr interface
func (*IconMgr) IconByName ¶
IconByName is main function to get icon by name -- looks in CurIconSet and falls back to DefaultIconSet if not found there -- returns error and logs a message if not found
type IconSet ¶
IconSet is a collection of icons
var CurIconSet *IconSet
CurIconSet is the current icon set -- defaults to default but can be changed to whatever you want
var DefaultIconSet *IconSet
DefaultIconSet is the default icon set, initialized by default
func MakeDefaultIcons ¶
func MakeDefaultIcons() *IconSet
func (*IconSet) OpenDefaultIcons ¶
func (*IconSet) OpenIconsFromAssetDir ¶ added in v0.9.9
func (iset *IconSet) OpenIconsFromAssetDir(path string, dirFunc func(path string) ([]string, error), assetFunc func(name string) ([]byte, error)) error
OpenIconsFromAssetDir loads icons using Asset and AssetDir funcs as generated by e.g., https://github.com/shuLhan/go-bindata or similar such forks of go-bindata
func (*IconSet) OpenIconsFromPath ¶
OpenIconsFromPath scans for .svg icon files in given path, adding them to the given IconSet, just storing the filename for later lazy loading
type Line ¶
type Line struct { NodeBase Start mat32.Vec2 `xml:"{x1,y1}" desc:"position of the start of the line"` End mat32.Vec2 `xml:"{x2,y2}" desc:"position of the end of the line"` }
Line is a SVG line
func AddNewLine ¶ added in v0.9.7
AddNewLine adds a new line to given parent node, with given name, st and end.
func (*Line) CopyFieldsFrom ¶ added in v0.9.8
func (g *Line) CopyFieldsFrom(frm interface{})
type Marker ¶
type Marker struct { NodeBase RefPos mat32.Vec2 `xml:"{refX,refY}" desc:"reference position to align the vertex position with, specified in ViewBox coordinates"` Size mat32.Vec2 `xml:"{markerWidth,markerHeight}" desc:"size of marker to render, in Units units"` Units MarkerUnits `xml:"markerUnits" desc:"units to use"` ViewBox ViewBox `desc:"viewbox defines the internal coordinate system for the drawing elements within the marker"` Orient string `xml:"orient" desc:"orientation of the marker -- either 'auto' or an angle"` VertexPos mat32.Vec2 `desc:"current vertex position"` VertexAngle float32 `desc:"current vertex angle in radians"` StrokeWidth float32 `desc:"current stroke width"` XForm mat32.Mat2 `desc:"net transform computed from settings and current values -- applied prior to rendering"` EffSize mat32.Vec2 `desc:"effective size for actual rendering"` }
Marker represents marker elements that can be drawn along paths (arrow heads, etc)
func AddNewMarker ¶ added in v0.9.7
AddNewMarker adds a new marker to given parent node, with given name.
func (*Marker) CopyFieldsFrom ¶ added in v0.9.8
func (g *Marker) CopyFieldsFrom(frm interface{})
type MarkerUnits ¶
type MarkerUnits int32
MarkerUnits specifies units to use for svg marker elements
const ( StrokeWidth MarkerUnits = iota UserSpaceOnUse MarkerUnitsN )
func (*MarkerUnits) FromString ¶
func (i *MarkerUnits) FromString(s string) error
func (MarkerUnits) MarshalJSON ¶
func (ev MarkerUnits) MarshalJSON() ([]byte, error)
func (MarkerUnits) String ¶
func (i MarkerUnits) String() string
func (*MarkerUnits) UnmarshalJSON ¶
func (ev *MarkerUnits) UnmarshalJSON(b []byte) error
type NodeBase ¶
type NodeBase struct { gi.Node2DBase Pnt gi.Paint `json:"-" xml:"-" desc:"full paint information for this node"` }
svg.NodeBase is an element within the SVG sub-scenegraph -- does not use layout logic -- just renders into parent SVG viewport
func (*NodeBase) ChildrenBBox2D ¶
func (*NodeBase) ComputeBBox2D ¶
func (*NodeBase) ComputeBBoxSVG ¶
func (g *NodeBase) ComputeBBoxSVG()
ComputeBBoxSVG is called by default in render to compute bounding boxes for gui interaction -- can only be done in rendering because that is when all the proper xforms are all in place -- VpBBox is intersected with parent SVG
func (*NodeBase) CopyFieldsFrom ¶ added in v0.9.8
func (g *NodeBase) CopyFieldsFrom(frm interface{})
func (*NodeBase) FindSVGURL ¶
FindSVGURL finds a url element in the parent SVG -- returns nil if not found -- can pass full 'url(#Name)' string
func (*NodeBase) Init2DBase ¶
func (g *NodeBase) Init2DBase()
Init2DBase handles basic node initialization -- Init2D can then do special things
func (*NodeBase) Marker ¶
Marker checks for a marker property of given name, or generic "marker" type, and if set, attempts to find that marker and return it
type Path ¶
type Path struct { NodeBase Data []PathData `` /* 171-byte string literal not displayed */ DataStr string `xml:"d" desc:"string version of the path data"` MinCoord mat32.Vec2 `desc:"minimum coord in path -- computed in BBox2D"` MaxCoord mat32.Vec2 `desc:"maximum coord in path -- computed in BBox2D"` }
Path renders SVG data sequences that can render just about anything
func AddNewPath ¶ added in v0.9.7
AddNewPath adds a new button to given parent node, with given name and path data.
func (*Path) CopyFieldsFrom ¶ added in v0.9.8
func (g *Path) CopyFieldsFrom(frm interface{})
type PathCmds ¶
type PathCmds byte
PathCmds are the commands within the path SVG drawing data type
const ( // move pen, abs coords PcM PathCmds = iota // move pen, rel coords Pcm // lineto, abs PcL // lineto, rel Pcl // horizontal lineto, abs PcH // relative lineto, rel Pch // vertical lineto, abs PcV // vertical lineto, rel Pcv // Bezier curveto, abs PcC // Bezier curveto, rel Pcc // smooth Bezier curveto, abs PcS // smooth Bezier curveto, rel Pcs // quadratic Bezier curveto, abs PcQ // quadratic Bezier curveto, rel Pcq // smooth quadratic Bezier curveto, abs PcT // smooth quadratic Bezier curveto, rel Pct // elliptical arc, abs PcA // elliptical arc, rel Pca // close path PcZ // close path Pcz // error -- invalid command PcErr )
func PathDataNextCmd ¶
PathDataNextCmd gets the next path data command, incrementing the index -- ++ not an expression so its clunky
func PathDecodeCmd ¶
PathDecodeCmd decodes rune into corresponding command
func (*PathCmds) FromString ¶
func (PathCmds) MarshalJSON ¶
func (*PathCmds) UnmarshalJSON ¶
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 ¶
PathDataParse parses a string representation of the path data into compiled path data
type Polygon ¶
Polygon is a SVG polygon
func AddNewPolygon ¶ added in v0.9.7
AddNewPolygon adds a new polygon to given parent node, with given name and points.
func (*Polygon) CopyFieldsFrom ¶ added in v0.9.8
func (g *Polygon) CopyFieldsFrom(frm interface{})
type Polyline ¶
type Polyline struct { NodeBase Points []mat32.Vec2 `xml:"points" desc:"the coordinates to draw -- does a moveto on the first, then lineto for all the rest"` }
Polyline is a SVG multi-line shape
func AddNewPolyline ¶ added in v0.9.7
AddNewPolyline adds a new polyline to given parent node, with given name and points.
func (*Polyline) CopyFieldsFrom ¶ added in v0.9.8
func (g *Polyline) CopyFieldsFrom(frm interface{})
type Rect ¶
type Rect struct { NodeBase Pos mat32.Vec2 `xml:"{x,y}" desc:"position of the top-left of the rectangle"` Size mat32.Vec2 `xml:"{width,height}" desc:"size of the rectangle"` Radius mat32.Vec2 `xml:"{rx,ry}" desc:"radii for curved corners, as a proportion of width, height"` }
Rect is a SVG rectangle, optionally with rounded corners
func AddNewRect ¶ added in v0.9.7
AddNewRect adds a new rectangle to given parent node, with given name, pos, and size.
func (*Rect) CopyFieldsFrom ¶ added in v0.9.8
func (g *Rect) CopyFieldsFrom(frm interface{})
type SVG ¶
type SVG struct { gi.Viewport2D ViewBox ViewBox `desc:"viewbox defines the coordinate system for the drawing"` Norm bool `` /* 130-byte string literal not displayed */ InvertY bool `` /* 181-byte string literal not displayed */ Pnt gi.Paint `json:"-" xml:"-" desc:"paint styles -- inherited by nodes"` Defs Group `desc:"all defs defined elements go here (gradients, symbols, etc)"` Title string `xml:"title" desc:"the title of the svg"` Desc string `xml:"desc" desc:"the description of the svg"` }
SVG is a viewport for containing SVG drawing objects, corresponding to the svg tag in html -- it provides its own bitmap for drawing into. To trigger a full re-render of SVG, do SetNeedsFullRender() in UpdateStart / End loop.
func AddNewSVG ¶ added in v0.9.7
AddNewSVG adds a new svg viewport to given parent node, with given name.
func (*SVG) CopyFieldsFrom ¶ added in v0.9.8
func (svg *SVG) CopyFieldsFrom(frm interface{})
func (*SVG) DeleteAll ¶
func (svg *SVG) DeleteAll()
DeleteAll deletes any existing elements in this svg
func (*SVG) ReadXML ¶
ReadXML reads XML-formatted SVG input from io.Reader, and uses xml.Decoder to create the SVG scenegraph for corresponding SVG drawing. Removes any existing content in SVG first. To process a byte slice, pass: bytes.NewReader([]byte(str)) -- all errors are logged and also returned. If this is being read into a live scenegraph, then you MUST call
svg.FullInit2DTree() after to initialize it for rendering.
func (*SVG) SetDPIXForm ¶
func (svg *SVG) SetDPIXForm()
SetDPIXForm sets a scaling transform to compensate for the dpi -- svg rendering is done within a 96 DPI context
func (*SVG) SetNormXForm ¶
func (svg *SVG) SetNormXForm()
SetNormXForm sets a scaling transform to make the entire viewbox to fit the viewport
func (*SVG) UnmarshalXML ¶
UnmarshalXML unmarshals the svg using xml.Decoder
type Text ¶
type Text struct { NodeBase Pos mat32.Vec2 `xml:"{x,y}" desc:"position of the left, baseline of the text"` Width float32 `xml:"width" desc:"width of text to render if using word-wrapping"` Text string `xml:"text" desc:"text string to render"` Render gi.TextRender `xml:"-" json:"-" desc:"render version of text"` CharPosX []float32 `desc:"character positions along X axis, if specified"` CharPosY []float32 `desc:"character positions along Y axis, if specified"` CharPosDX []float32 `desc:"character delta-positions along X axis, if specified"` CharPosDY []float32 `desc:"character delta-positions along Y axis, if specified"` CharRots []float32 `desc:"character rotations, if specified"` TextLength float32 `desc:"author's computed text length, if specified -- we attempt to match"` AdjustGlyphs bool `desc:"in attempting to match TextLength, should we adjust glyphs in addition to spacing?"` }
Text renders SVG text-- it handles both text and tspan elements (a tspan is just nested under a parent text)
func AddNewText ¶ added in v0.9.7
AddNewText adds a new text to given parent node, with given name, pos and text.
func (*Text) CopyFieldsFrom ¶ added in v0.9.8
func (g *Text) CopyFieldsFrom(frm interface{})
type ViewBox ¶
type ViewBox struct { Min mat32.Vec2 `desc:"offset or starting point in parent Viewport2D"` Size mat32.Vec2 `desc:"size of viewbox within parent Viewport2D"` PreserveAspectRatio ViewBoxPreserveAspectRatio `desc:"how to scale the view box within parent Viewport2D"` }
ViewBox is used in SVG to define the coordinate system
type ViewBoxAlign ¶
type ViewBoxAlign int32
ViewBoxAlign defines values for the PreserveAspectRatio alignment factor
const ( NoAlign ViewBoxAlign = 1 << iota // do not preserve uniform scaling XMin // align ViewBox.Min with smallest values of Viewport XMid // align ViewBox.Min with midpoint values of Viewport XMax // align ViewBox.Min+Size with maximum values of Viewport XMask ViewBoxAlign = XMin + XMid + XMax // mask for X values -- clear all X before setting new one YMin ViewBoxAlign = 1 << iota // align ViewBox.Min with smallest values of Viewport YMid // align ViewBox.Min with midpoint values of Viewport YMax // align ViewBox.Min+Size with maximum values of Viewport YMask ViewBoxAlign = YMin + YMid + YMax // mask for Y values -- clear all Y before setting new one )
type ViewBoxMeetOrSlice ¶
type ViewBoxMeetOrSlice int32
ViewBoxMeetOrSlice defines values for the PreserveAspectRatio meet or slice factor
const ( // Meet means the entire ViewBox is visible within Viewport, and it is // scaled up as much as possible to meet the align constraints Meet ViewBoxMeetOrSlice = iota // Slice means the entire ViewBox is covered by the ViewBox, and the // ViewBox is scaled down as much as possible, while still meeting the // align constraints Slice ViewBoxMeetOrSliceN )
func (*ViewBoxMeetOrSlice) FromString ¶
func (i *ViewBoxMeetOrSlice) FromString(s string) error
func (ViewBoxMeetOrSlice) MarshalJSON ¶ added in v0.9.10
func (ev ViewBoxMeetOrSlice) MarshalJSON() ([]byte, error)
func (ViewBoxMeetOrSlice) String ¶
func (i ViewBoxMeetOrSlice) String() string
func (*ViewBoxMeetOrSlice) UnmarshalJSON ¶ added in v0.9.10
func (ev *ViewBoxMeetOrSlice) UnmarshalJSON(b []byte) error
type ViewBoxPreserveAspectRatio ¶
type ViewBoxPreserveAspectRatio struct { Align ViewBoxAlign `svg:"align" desc:"how to align x,y coordinates within viewbox"` MeetOrSlice ViewBoxMeetOrSlice `svg:"meetOrSlice" desc:"how to scale the view box relative to the viewport"` }
ViewBoxPreserveAspectRatio determines how to scale the view box within parent Viewport2D