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) error
- func (S *SVG) FindGroupsById(id any, findFirst bool) ([]*GroupDef, error)
- func (S *SVG) FindPathsById(id any, findFirst bool) ([]*PathDef, error)
- func (S *SVG) GetBackground() RectDef
- func (S *SVG) GetViewBox() (ViewBoxDef, error)
- func (S *SVG) GetXml() ([]byte, error)
- func (S *SVG) GetXmlIndented(indentPrefix, indentString string) ([]byte, error)
- func (S *SVG) RemoveBackground()
- func (S *SVG) SetViewBox(box ViewBoxDef)
- func (S *SVG) WriteFile(filename string) error
- func (S *SVG) WriteFileIndented(filename, indentPrefix, indentString 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 constraint for functions
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,omitempty"`
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"`
// contains filtered or unexported fields
}
SVG is the base struct of an SVG image, corresponding to the <svg>...</svg> tag pair and its attributes and contents. 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 rect matching the image's viewBox or x/y/width/height and with the specified fill color.
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) GetBackground ¶ added in v0.0.7
GetBackground returns the RectDef created with SVG.AddBackground. If no background has been defined, the return value will be a RectDef with all zero values.
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) GetXml ¶
GetXml returns the current object as an XML byte slice. If a background has been defined with SVG.AddBackground, it is inserted into a copy of S as the bottom-most visual element, and the copy is marshaled to XML; otherwise S is marshaled as-is.
func (*SVG) GetXmlIndented ¶
GetXmlIndented returns the current object as an XML byte slice. If a background has been defined with SVG.AddBackground, it is inserted into a copy of S as the bottom-most visual element, and the copy is marshaled to XML; otherwise S is marshaled as-is.
The indentPrefix and indentString parameters are passed directly to xml.MarshalIndent.
func (*SVG) RemoveBackground ¶ added in v0.0.7
func (S *SVG) RemoveBackground()
RemoveBackground clears any rect added by SVG.AddBackground
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.
func (*SVG) WriteFile ¶
WriteFile writes an XML representation of the current object to the supplied filename.
The method calls the SVG.GetXml method and writes the XML data to disk rather than returning a byte slice to the caller. The data is first written to a temporary file; if that succeeds, the file with the specified filename is unlinked and the temporary file renamed.
func (*SVG) WriteFileIndented ¶ added in v0.0.7
WriteFileIndented writes an XML representation of the current object to the supplied filename.
The method calls the SVG.GetXmlIndented method and writes the XML data to disk rather than returning a byte slice to the caller. The data is first written to a temporary file; if that succeeds, the file with the specified filename is unlinked and the temporary file renamed.
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