ivgconv

package module
v0.0.0-...-3b74244 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 7 Imported by: 1

README

ivgconv

GoDoc Go Report Card License

ivgconv implements conversion between SVG and IconVG format.

Limitations

Only a subset of SVG is supported, and only a subset of IconVG is generated.

If the conversion fails, an error is returned.

Credits

The IconVG converter is based on gen.go which is licensed under the APACHE LICENSE, VERSION 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContent

func FromContent(content []byte, options ...Option) ([]byte, error)

FromContent encodes the SVG file content as IconVG.

func FromFile

func FromFile(filepath string, options ...Option) ([]byte, error)

FromFile encodes the SVG file as IconVG.

Types

type Circle

type Circle struct {
	Cx float32 `xml:"cx,attr"`
	Cy float32 `xml:"cy,attr"`
	R  float32 `xml:"r,attr"`
}

type ConverterOptions

type ConverterOptions struct {
	// OutputSize is the size of the IconVG output image.
	OutputSize float32
	// ExcludePath is a list of paths to exclude from the IconVG image.
	ExcludePath []Path
}

ConverterOptions contains options for the SVG to IconVG converter.

type Option

type Option func(*ConverterOptions)

Option is a function that configures a ConverterOptions.

func WithExcludePath

func WithExcludePath(excludePath []Path) Option

WithExcludePath sets the list of paths to exclude from the IconVG image.

func WithOutputSize

func WithOutputSize(outputSize float32) Option

WithOutputSize sets the size of the IconVG image.

type Path

type Path struct {
	D           string   `xml:"d,attr"`
	Fill        string   `xml:"fill,attr"`
	FillOpacity *float32 `xml:"fill-opacity,attr"`
	Opacity     *float32 `xml:"opacity,attr"`
}

type SVG

type SVG struct {
	Width   float32 `xml:"width,attr"`
	Height  float32 `xml:"height,attr"`
	ViewBox ViewBox `xml:"viewBox,attr"`
	Paths   []Path  `xml:"path"`
	// Some of the SVG files contain <circle> elements, not just <path>
	// elements. IconVG doesn't have circles per se. Instead, we convert such
	// circles to be paired arcTo commands, tacked on to the first path.
	//
	// In general, this isn't correct if the circles and the path overlap, but
	// that doesn't happen in the specific case of the Material Design icons.
	Circles []Circle `xml:"circle"`
}

func (*SVG) Validate

func (s *SVG) Validate() error

type ViewBox

type ViewBox struct {
	MinX   float32 `xml:"min-x,attr"`
	MinY   float32 `xml:"min-y,attr"`
	Width  float32 `xml:"width,attr"`
	Height float32 `xml:"height,attr"`
}

func (*ViewBox) UnmarshalXMLAttr

func (vb *ViewBox) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr implements the xml.UnmarshalerAttr interface.

Jump to

Keyboard shortcuts

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