Documentation
¶
Index ¶
- Constants
- type AnchorDef
- type CircleDef
- type DefsDef
- type GroupDef
- type NumberAttr
- type PathDef
- type RectDef
- type SVG
- func (S *SVG) AddBackground(colorDef string)
- func (S *SVG) FindGroupsById(id any, findFirst bool) ([]*GroupDef, error)
- func (S *SVG) FindPathsById(id any, findFirst bool) ([]*PathDef, error)
- func (S *SVG) GetViewBox() (ViewBoxDef, error)
- func (S *SVG) GetXml() ([]byte, error)
- func (S *SVG) GetXmlIndented(indentPrefix, indentString string) ([]byte, error)
- func (S *SVG) SetViewBox(box ViewBoxDef)
- func (S *SVG) WriteFile(filename string) error
- type TSpanDef
- type TextDef
- type ViewBoxDef
Constants ¶
const ( FindFirst = true FindAll = false )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnchorDef ¶
type AnchorDef struct {
Id string `xml:"id,attr"`
Download string `xml:"Download,attr"`
Href string `xml:"href,attr"`
HrefLang string `xml:"hreflang,attr"`
ReferrerPolicy string `xml:"referrerpolicy,attr"`
Rel string `xml:"rel,attr"`
Target string `xml:"target,attr"`
Type string `xml:"type,attr"`
Xform string `xml:"transform,attr,omitempty"`
G []GroupDef `xml:"g"`
Rect []RectDef `xml:"rect"`
Circle []CircleDef `xml:"circle"`
}
<a> SVG/XML element
type CircleDef ¶
type CircleDef struct {
Id string `xml:"id,attr"`
CX string `xml:"cx,attr"`
CY string `xml:"cy,attr"`
Radius string `xml:"r,attr"`
Style string `xml:"style,attr,omitempty"`
Xform string `xml:"transform,attr,omitempty"`
}
<circle> SVG/XML element
type GroupDef ¶
type GroupDef struct {
G []GroupDef `xml:"g,omitempty"`
Id string `xml:"id,attr,omitempty"`
Xform string `xml:"transform,attr,omitempty"`
Style string `xml:"style,attr,omitempty"`
A []AnchorDef `xml:"a"`
Path []PathDef `xml:"path"`
Text []TextDef `xml:"text"`
Rect []RectDef `xml:"rect"`
Circle []CircleDef `xml:"circle"`
}
<g> SVG/XML element
func (*GroupDef) FindPathsById ¶
FindGroupsById traverses a GroupDef object and returns a slice of PathDef with matching ids.
The supplied id may be a string or a compiled regular expression from the regexp package.
Use the FindFirst or FindAll constant as the second parameter to direct cause the method to return only the first matching element or all matching elements, respectively.
type NumberAttr ¶ added in v0.0.3
type PathDef ¶
type PathDef struct {
Id string `xml:"id,attr"`
D string `xml:"d,attr"`
Xform string `xml:"transform,attr,omitempty"`
Style string `xml:"style,attr,omitempty"`
Title string `xml:"title,omitempty"`
}
<path> SVG/XML element
type RectDef ¶
type RectDef struct {
Id string `xml:"id,attr"`
X string `xml:"x,attr"`
Y string `xml:"y,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
Style string `xml:"style,attr,omitempty"`
Xform string `xml:"transform,attr,omitempty"`
}
<rect> SVG/XML element
type SVG ¶
type SVG struct {
Id string `xml:"id,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
ViewBox string `xml:"viewBox,attr"`
Title string `xml:"title,attr,omitempty"`
Version string `xml:"version,attr"`
XMLNS string `xml:"xmlns,attr"`
XMLName xml.Name `xml:"svg"`
Defs DefsDef `xml:"defs"`
G []GroupDef `xml:"g"`
A []AnchorDef `xml:"a"`
Path []PathDef `xml:"path"`
Text []TextDef `xml:"text"`
Rect []RectDef `xml:"rect"`
Circle []CircleDef `xml:"circle"`
}
SVG is the base struct of an SVG image. The array fields of the struct are the supported tags and will be rendered in first-to-last order (e. g., any circle defined in SVG.Circle will visually cover any other elements within its bounds).
func NewFromBytes ¶
NewFromBytes accepts a byte slice of SVG XML data and returns an SVG object pointer or an error.
func NewFromFile ¶
NewFromFile accepts a filename containing SVG XML data and returns an object pointer or an error.
This method calls NewFromBytes after successfully reading from the file named in the filename parameter.
func (*SVG) AddBackground ¶
AddBackground takes a color definition, such as "#<hex>" or a name like "red", and creates a group containing a rect matching the image size and specified color.
The new group is prepended to the top-level G slice to ensure that it is the bottom-most visual element in the image.
func (*SVG) FindGroupsById ¶
FindGroupsById traverses a GroupDef object and returns a slice of GroupDef with matching ids.
The supplied id may be a string or a compiled regular expression from the regexp package.
Use the FindFirst or FindAll constant as the second parameter to direct cause the method to return only the first matching element or all matching elements, respectively.
func (*SVG) FindPathsById ¶
FindPathsById traverses an SVG object and returns a slice of PathDef with matching ids.
The supplied id may be a string or a compiled regular expression from the regexp package.
Use the FindFirst or FindAll constant as the second parameter to direct cause the method to return only the first matching element or all matching elements, respectively.
func (*SVG) GetViewBox ¶
func (S *SVG) GetViewBox() (ViewBoxDef, error)
GetViewBox returns the value of the "viewBox" XML attribute as a ViewBoxDef struct of float64 values.
func (*SVG) GetXmlIndented ¶
GetXmlIndented returns the current object as a byte slice, using xml.MarshalIndent.
The indentPrefix and indentString parameters are passed directly to xml.MarshalIndent.
func (*SVG) SetViewBox ¶
func (S *SVG) SetViewBox(box ViewBoxDef)
GetViewBox sets the image's "viewBox" XML attribute from the values in the supplied ViewBoxDef struct.
type TSpanDef ¶
type TSpanDef struct {
Id string `xml:"id,attr"`
X string `xml:"x,attr"`
Y string `xml:"y,attr"`
Xform string `xml:"transform,attr,omitempty"`
Label string `xml:",chardata"`
}
<tspan> SVG/XML element
type TextDef ¶
type TextDef struct {
Id string `xml:"id,attr"`
X string `xml:"x,attr"`
Y string `xml:"y,attr"`
Style string `xml:"style,attr,omitempty"`
Xform string `xml:"transform,attr,omitempty"`
TextLength string `xml:",attr,omitempty"`
Label string `xml:",chardata"`
TSpan []TSpanDef `xml:"tspan"`
}
<text> SVG/XML element