svgdata

package module
v0.0.0-...-5926790 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2018 License: Apache-2.0 Imports: 9 Imported by: 1

README

svgdata-go

WARNING: This is very early library that I wrote for myself and anything may change at any time.

A go library for representing SVG data and then writing it out. This isn't the best API but it is useful.

The one thing this does well is collect a set of path segment and then construct a Path from those by looking for the segments that match up. This is useful for CAD applications where often times you'll get a collection of path segments and need to assemble continuous paths from those segments.

Documentation

Index

Constants

View Source
const (
	SvgNs = "http://www.w3.org/2000/svg"
)

Variables

This section is empty.

Functions

func MakeStartElement

func MakeStartElement(name string, am AttrMap) xml.StartElement

func Marshal

func Marshal(r *Root, pretty bool) ([]byte, error)

func RegisterNodeCreator

func RegisterNodeCreator(n string, c nodeCreator)

func SavePathString

func SavePathString(sps []SubPath) string

Types

type AttrMap

type AttrMap map[string]string

func (AttrMap) ExtractValue

func (am AttrMap) ExtractValue(k string) (float64, error)

ExtractValue will pull a value out of the AttrMap. It will convert it to a float and delete it from the map. If it is not in the map 0.0 will be returned. An error will be returned if this is not a parsable value.

func (AttrMap) ExtractValueNoDefault

func (am AttrMap) ExtractValueNoDefault(k string) (float64, error)

ExtractValue will pull a value out of the AttrMap. It will convert it to a float and delete it from the map. If it is not in the map an error will be returned. An error will be returned if this is not a parsable value.

type Circle

type Circle struct {
	Center geom.Coord
	Radius float64
	// contains filtered or unexported fields
}

Circle is an SVG element that has no specialized code or representation.

func NewCircle

func NewCircle(c geom.Coord, r float64) *Circle

func (*Circle) AddChild

func (n *Circle) AddChild(c Node)

func (*Circle) Attrs

func (n *Circle) Attrs() AttrMap

func (*Circle) Children

func (n *Circle) Children() *[]Node

func (*Circle) GetText

func (n *Circle) GetText() string

func (*Circle) MarshalXML

func (n *Circle) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Circle) Name

func (n *Circle) Name() string

func (*Circle) SetText

func (n *Circle) SetText(t string)

func (*Circle) UnmarshalXML

func (n *Circle) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Node

type Node interface {
	xml.Unmarshaler
	xml.Marshaler

	Name() string

	Attrs() AttrMap

	Children() *[]Node
	AddChild(n Node)

	GetText() string
	SetText(t string)
}

func CreateNodeFromName

func CreateNodeFromName(n xml.Name) Node

func CreatePolygon

func CreatePolygon() Node

func CreatePolyline

func CreatePolyline() Node

func NewGroup

func NewGroup() Node

func NewStyle

func NewStyle() Node

type Path

type Path struct {
	SubPaths []SubPath
	// contains filtered or unexported fields
}

func NewPath

func NewPath() *Path

func (*Path) AddChild

func (n *Path) AddChild(c Node)

func (*Path) Attrs

func (n *Path) Attrs() AttrMap

func (*Path) Children

func (n *Path) Children() *[]Node

func (*Path) GetText

func (n *Path) GetText() string

func (*Path) MarshalXML

func (n *Path) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Path) Name

func (n *Path) Name() string

func (*Path) SetText

func (n *Path) SetText(t string)

func (*Path) UnmarshalXML

func (n *Path) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type PathCommand

type PathCommand struct {
	Command byte      // The single character command
	Params  []float64 // The parameters to the command
	// contains filtered or unexported fields
}

type Polyshape

type Polyshape struct {

	// TODO: Handle Points
	Points []geom.Coord
	// contains filtered or unexported fields
}

Polyshape is an SVG element is a shape specified with a list of straight lines.

func (*Polyshape) AddChild

func (n *Polyshape) AddChild(c Node)

func (*Polyshape) Attrs

func (n *Polyshape) Attrs() AttrMap

func (*Polyshape) Children

func (n *Polyshape) Children() *[]Node

func (*Polyshape) GetText

func (n *Polyshape) GetText() string

func (*Polyshape) MarshalXML

func (n *Polyshape) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Polyshape) Name

func (n *Polyshape) Name() string

func (*Polyshape) SetText

func (n *Polyshape) SetText(t string)

func (*Polyshape) UnmarshalXML

func (n *Polyshape) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Rect

type Rect struct {
	R geom.Rect
	// contains filtered or unexported fields
}

Circle is an SVG element that has no specialized code or representation.

func NewRect

func NewRect(r geom.Rect) *Rect

func NewRectXYWH

func NewRectXYWH(x, y, w, h float64) *Rect

func (*Rect) AddChild

func (n *Rect) AddChild(c Node)

func (*Rect) Attrs

func (n *Rect) Attrs() AttrMap

func (*Rect) Children

func (n *Rect) Children() *[]Node

func (*Rect) GetText

func (n *Rect) GetText() string

func (*Rect) MarshalXML

func (n *Rect) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Rect) Name

func (n *Rect) Name() string

func (*Rect) SetText

func (n *Rect) SetText(t string)

func (*Rect) UnmarshalXML

func (n *Rect) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Root

type Root struct {
	// contains filtered or unexported fields
}

Root represents the root <svg> element.

func CreateRoot

func CreateRoot() *Root

func Unmarshal

func Unmarshal(data []byte) (*Root, error)

func (*Root) AddChild

func (n *Root) AddChild(c Node)

func (*Root) Attrs

func (n *Root) Attrs() AttrMap

func (*Root) Children

func (n *Root) Children() *[]Node

func (*Root) GetText

func (n *Root) GetText() string

func (*Root) MarshalXML

func (n *Root) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Root) Name

func (n *Root) Name() string

func (*Root) SetText

func (n *Root) SetText(t string)

func (*Root) UnmarshalXML

func (n *Root) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type SubPath

type SubPath struct {
	Commands []PathCommand
	// contains filtered or unexported fields
}

func ParsePathString

func ParsePathString(d string) ([]SubPath, error)

ParsePathString parses an SVG path string. Each command represents a single instance of the command. This is to enable easier further processing.

type Unknown

type Unknown struct {
	// contains filtered or unexported fields
}

Unknown is an SVG element that has no specialized code or representation.

func (*Unknown) AddChild

func (n *Unknown) AddChild(c Node)

func (*Unknown) Attrs

func (n *Unknown) Attrs() AttrMap

func (*Unknown) Children

func (n *Unknown) Children() *[]Node

func (*Unknown) GetText

func (n *Unknown) GetText() string

func (*Unknown) MarshalXML

func (n *Unknown) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Unknown) Name

func (n *Unknown) Name() string

func (*Unknown) SetText

func (n *Unknown) SetText(t string)

func (*Unknown) UnmarshalXML

func (n *Unknown) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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