svgxml

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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"`
}

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"`
}

type DefsDef

type DefsDef struct {
	Id string `xml:"id,attr"`
}

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"`
}

func (*GroupDef) FindPathsById

func (G *GroupDef) FindPathsById(id any, findFirst bool) ([]*PathDef, error)

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 and FindAll constants as the second parameter to direct cause the method to return only the first matching element or all matching elements, respectively.

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"`
}

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"`
}

func NewRect

func NewRect[N string | numberAttr](id, style string, x, y, width, height N) RectDef

NewRect returns a RectDef object with the supplied parameters. x, y, width, and height can all be string, int, or float.

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"`
	A       []AnchorDef `xml:"a"`
	G       []GroupDef  `xml:"g"`
	Path    []PathDef   `xml:"path"`
	Text    []TextDef   `xml:"text"`
	Rect    []RectDef   `xml:"rect"`
	Circle  []CircleDef `xml:"circle"`
}

func NewFromBytes

func NewFromBytes(xmlBytes []byte) (*SVG, error)

NewFromBytes() accepts a byte slice of SVG XML data and returns an SVG object pointer or an error.

func NewFromFile

func NewFromFile(filename string) (*SVG, error)

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

func (S *SVG) AddBackground(colorDef string)

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 element in the image.

func (*SVG) FindGroupsById

func (S *SVG) FindGroupsById(id any, findFirst bool) ([]*GroupDef, error)

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 and FindAll constants as the second parameter to direct cause the method to return only the first matching element or all matching elements, respectively.

func (*SVG) FindPathsById

func (S *SVG) FindPathsById(id any, findFirst bool) ([]*PathDef, error)

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 and FindAll constants 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)

func (*SVG) GetXml

func (S *SVG) GetXml() ([]byte, error)

GetXml() returns the current object as a byte slice.

func (*SVG) GetXmlIndented

func (S *SVG) GetXmlIndented(indentPrefix, indentString string) ([]byte, error)

GetXml() 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)

func (*SVG) WriteFile

func (S *SVG) WriteFile(filename string) error

WriteFile writes an XML representation of the current object to the supplied filename.

The method calls the GetXml() method and writes the XML data to disk rather than returning a byte slice to the caller.

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"`
}

type TextDef

type TextDef struct {
	//	svgElem
	Id         string     `xml:"id,attr"`
	X          string     `xml:"x,attr"`
	Y          string     `xml:"y,attr"`
	Width      string     `xml:"width,attr,omitempty"`
	Height     string     `xml:"height,attr,omitempty"`
	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"`
}

type ViewBoxDef

type ViewBoxDef struct {
	X, Y, Width, Height float64
}

Jump to

Keyboard shortcuts

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