svg

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Default = DPI{
		// contains filtered or unexported fields
	}
)
View Source
var (
	ZeroPoint = NewPoint(0, 0)
)

Functions

This section is empty.

Types

type Circle

type Circle struct {
	CenterX float64 `xml:"cx,attr"`
	CenterY float64 `xml:"cy,attr"`
	Radius  float64 `xml:"r,attr"`
	// contains filtered or unexported fields
}

func (*Circle) Draw

func (c *Circle) Draw() (sdf.SDF2, error)

type ClosePath

type ClosePath struct{}

func NewClosePath

func NewClosePath() *ClosePath

func (*ClosePath) DrawTo

func (m *ClosePath) DrawTo(b *sdf.Bezier)

func (*ClosePath) MM

func (m *ClosePath) MM(dpi DPI)

func (*ClosePath) Matrix

func (m *ClosePath) Matrix(matrix *Matrix)

type CubicBezier

type CubicBezier struct {
	Start Point
	Mid   Point
	End   Point
}

func NewCubicBezier

func NewCubicBezier(start, mid, end Point) *CubicBezier

func (*CubicBezier) DrawTo

func (cb *CubicBezier) DrawTo(b *sdf.Bezier)

func (*CubicBezier) MM

func (cb *CubicBezier) MM(dpi DPI)

func (*CubicBezier) Matrix

func (cb *CubicBezier) Matrix(matrix *Matrix)

type DPI

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

func NewDPI

func NewDPI(dpi float64) DPI

func NewDPIWithSize

func NewDPIWithSize(pixel, mm float64) DPI

func (DPI) DPI

func (d DPI) DPI() float64

func (DPI) MM

func (d DPI) MM(pixel float64) float64

MM transforms pixel to mm.

func (DPI) Pixel

func (d DPI) Pixel(mm float64) float64

Pixel transforms mm to pixel.

func (DPI) String

func (d DPI) String() string

type Drawable

type Drawable interface {
	Matrix(matrix *Matrix)
	MM(dpi DPI)
	DrawTo(b *sdf.Bezier)
}

type Graphic

type Graphic struct {
	ID     string
	Matrix *Matrix

	Paths    []*Path
	Rects    []*Rect
	Circles  []*Circle
	Graphics []*Graphic
	// contains filtered or unexported fields
}

func (*Graphic) Draw

func (gr *Graphic) Draw() (sdf.SDF2, error)

func (*Graphic) Find

func (gr *Graphic) Find(id string) *Graphic

func (*Graphic) UnmarshalXML

func (gr *Graphic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type LineTo

type LineTo struct {
	Point Point
}

func NewLineTo

func NewLineTo(p Point) *LineTo

func (*LineTo) DrawTo

func (l *LineTo) DrawTo(b *sdf.Bezier)

func (*LineTo) MM

func (l *LineTo) MM(dpi DPI)

func (*LineTo) Matrix

func (l *LineTo) Matrix(matrix *Matrix)

type Matrix

type Matrix struct {
	A float64
	B float64
	C float64
	D float64
	E float64
	F float64
}

Matrix is equivalent to applying the transform matrix: | A C E | | B D F | | 0 0 1 |

func NewMatrix

func NewMatrix(a, b, c, d, e, f float64) *Matrix

func (*Matrix) Dot

func (m *Matrix) Dot(matrix *Matrix) *Matrix

Dot multiply 2 matrix: | A C E | | a c e | | Aa+Cb Ac+Cd Ae+Cf+E | | B D F | * | b d f | = | Ba+Db Bc+Dd Be+Df+F | | 0 0 1 | | 0 0 1 | | 0 0 1 |

type MoveTo

type MoveTo struct {
	Point Point
}

func NewMoveTo

func NewMoveTo(p Point) *MoveTo

func (*MoveTo) DrawTo

func (m *MoveTo) DrawTo(b *sdf.Bezier)

func (*MoveTo) MM

func (m *MoveTo) MM(dpi DPI)

func (*MoveTo) Matrix

func (m *MoveTo) Matrix(matrix *Matrix)

type NotFoundError

type NotFoundError string

func (NotFoundError) Error

func (err NotFoundError) Error() string

type Option

type Option struct {
	DPI DPI
}

type Path

type Path struct {
	Drawables      []Drawable
	Stroke         string
	StrokeLinecap  string
	StrokeLineJoin string
	// contains filtered or unexported fields
}

func (*Path) ToBeziers

func (pa *Path) ToBeziers(m *Matrix) ([]*sdf.Bezier, error)

func (*Path) UnmarshalXML

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

type Point

type Point struct {
	X float64
	Y float64
}

func NewPoint

func NewPoint(x float64, y float64) Point

func (Point) Add

func (pt Point) Add(point Point) Point

func (Point) MM

func (pt Point) MM(dpi DPI) Point

func (Point) Matrix

func (pt Point) Matrix(m *Matrix) Point

Matrix transforms coordinates from a previous coordinate system into a new coordinate system by following matrix equalities: | A C E | | X | | AX+CY+E | | B D F | * | Y | = | BX+DY+F | | 0 0 1 | | 1 | | 1 |

type Rect

type Rect struct {
	X      float64 `xml:"x,attr"`
	Y      float64 `xml:"y,attr"`
	Width  float64 `xml:"width,attr"`
	Height float64 `xml:"height,attr"`
	// contains filtered or unexported fields
}

func (*Rect) Draw

func (r *Rect) Draw() (sdf.SDF2, error)

type SVG

type SVG struct {
	Width    string     `xml:"width,attr"`
	Height   string     `xml:"height,attr"`
	ViewBox  string     `xml:"viewBox,attr"`
	Fill     string     `xml:"fill,attr"`
	XMLNS    string     `xml:"xmlns,attr"`
	Graphics []*Graphic `xml:"g"`
	// contains filtered or unexported fields
}

func New

func New(r io.Reader, option *Option) (*SVG, error)

func (*SVG) Find

func (svg *SVG) Find(id string) (*Graphic, error)

Jump to

Keyboard shortcuts

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