svg

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateYAML

func GenerateYAML(canvas *Canvas) ([]byte, error)

GenerateYAML generates YAML from a Canvas

func RenderSVG

func RenderSVG(canvas *Canvas) (string, error)

RenderSVG renders the SVG based on the Canvas configuration

Types

type Background

type Background struct {
	Color string `yaml:"color,omitempty"`
	Image string `yaml:"image,omitempty"`
}

Background represents the canvas background.

type Canvas

type Canvas struct {
	Width      int              `yaml:"width"`
	Height     int              `yaml:"height"`
	Background Background       `yaml:"background"`
	Elements   []ElementWrapper `yaml:"elements"`
}

Canvas represents the SVG canvas configuration.

func ParseYAML

func ParseYAML(input []byte) (*Canvas, error)

ParseYAML parses the YAML input and returns a Canvas

func (*Canvas) GetElements

func (c *Canvas) GetElements() []Element

GetElements converts []ElementWrapper to []Element.

type Circle

type Circle struct {
	Type        string     `yaml:"type"`
	ID          string     `yaml:"id,omitempty"`
	CX          int        `yaml:"cx"`
	CY          int        `yaml:"cy"`
	R           int        `yaml:"r"`
	Fill        string     `yaml:"fill,omitempty"`
	Stroke      string     `yaml:"stroke,omitempty"`
	StrokeWidth int        `yaml:"stroke_width,omitempty"`
	Transform   *Transform `yaml:"transform,omitempty"`
}

Circle represents an SVG circle.

func (*Circle) Render

func (c *Circle) Render(canvas *svg.SVG)

Render renders the circle onto the SVG canvas.

type Element

type Element interface {
	Render(canvas *svg.SVG)
}

Element is the interface that all SVG elements implement.

type ElementWrapper

type ElementWrapper struct {
	Element
}

ElementWrapper is a proxy for unmarshaling different Element types.

func (ElementWrapper) MarshalYAML

func (ew ElementWrapper) MarshalYAML() (interface{}, error)

MarshalYAML implements custom marshaling for the Element interface.

func (*ElementWrapper) UnmarshalYAML

func (ew *ElementWrapper) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements custom unmarshaling for the Element interface.

type Ellipse

type Ellipse struct {
	Type        string     `yaml:"type"`
	ID          string     `yaml:"id,omitempty"`
	CX          int        `yaml:"cx"`
	CY          int        `yaml:"cy"`
	RX          int        `yaml:"rx"`
	RY          int        `yaml:"ry"`
	Fill        string     `yaml:"fill,omitempty"`
	Stroke      string     `yaml:"stroke,omitempty"`
	StrokeWidth int        `yaml:"stroke_width,omitempty"`
	Transform   *Transform `yaml:"transform,omitempty"`
}

Ellipse represents an SVG ellipse.

func (*Ellipse) Render

func (e *Ellipse) Render(canvas *svg.SVG)

Render renders the ellipse onto the SVG canvas.

type Group

type Group struct {
	Type      string     `yaml:"type"`
	ID        string     `yaml:"id,omitempty"`
	Transform *Transform `yaml:"transform,omitempty"`
	Elements  []Element  `yaml:"elements"`
}

Group represents an SVG group, which can contain nested elements.

func (*Group) GetElements

func (g *Group) GetElements() []Element

func (*Group) MarshalYAML

func (g *Group) MarshalYAML() (interface{}, error)

func (*Group) Render

func (g *Group) Render(canvas *svg.SVG)

Render renders the group and its nested elements onto the SVG canvas.

func (*Group) UnmarshalYAML

func (g *Group) UnmarshalYAML(value *yaml.Node) error

type Image

type Image struct {
	Type      string     `yaml:"type"`
	ID        string     `yaml:"id,omitempty"`
	Href      string     `yaml:"href"`
	X         int        `yaml:"x"`
	Y         int        `yaml:"y"`
	Width     int        `yaml:"width"`
	Height    int        `yaml:"height"`
	Transform *Transform `yaml:"transform,omitempty"`
}

Image represents an SVG image.

func (*Image) Render

func (img *Image) Render(canvas *svg.SVG)

Render renders the image onto the SVG canvas.

type Line

type Line struct {
	Type        string     `yaml:"type"`
	ID          string     `yaml:"id,omitempty"`
	X1          int        `yaml:"x1"`
	Y1          int        `yaml:"y1"`
	X2          int        `yaml:"x2"`
	Y2          int        `yaml:"y2"`
	Stroke      string     `yaml:"stroke,omitempty"`
	StrokeWidth int        `yaml:"stroke_width,omitempty"`
	Transform   *Transform `yaml:"transform,omitempty"`
}

Line represents an SVG line.

func (*Line) Render

func (l *Line) Render(canvas *svg.SVG)

Render renders the line onto the SVG canvas.

type Polygon

type Polygon struct {
	Type        string     `yaml:"type"`
	ID          string     `yaml:"id,omitempty"`
	Points      [][2]int   `yaml:"points"`
	Fill        string     `yaml:"fill,omitempty"`
	Stroke      string     `yaml:"stroke,omitempty"`
	StrokeWidth int        `yaml:"stroke_width,omitempty"`
	Transform   *Transform `yaml:"transform,omitempty"`
}

Polygon represents an SVG polygon.

func (*Polygon) Render

func (p *Polygon) Render(canvas *svg.SVG)

Render renders the polygon onto the SVG canvas.

type Rectangle

type Rectangle struct {
	Type        string     `yaml:"type"`
	ID          string     `yaml:"id,omitempty"`
	X           int        `yaml:"x"`
	Y           int        `yaml:"y"`
	Width       int        `yaml:"width"`
	Height      int        `yaml:"height"`
	Fill        string     `yaml:"fill,omitempty"`
	Stroke      string     `yaml:"stroke,omitempty"`
	StrokeWidth int        `yaml:"stroke_width,omitempty"`
	Transform   *Transform `yaml:"transform,omitempty"`
}

Rectangle represents an SVG rectangle.

func (*Rectangle) Render

func (r *Rectangle) Render(canvas *svg.SVG)

Render renders the rectangle onto the SVG canvas.

type SVGDSL

type SVGDSL struct {
	SVG Canvas `yaml:"svg"`
}

SVGDSL represents the root of the YAML DSL.

type Text

type Text struct {
	Type       string     `yaml:"type"`
	ID         string     `yaml:"id,omitempty"`
	X          int        `yaml:"x"`
	Y          int        `yaml:"y"`
	Content    string     `yaml:"content"`
	FontSize   string     `yaml:"font_size,omitempty"`
	FontFamily string     `yaml:"font_family,omitempty"`
	Fill       string     `yaml:"fill,omitempty"`
	TextAnchor string     `yaml:"text_anchor,omitempty"`
	Transform  *Transform `yaml:"transform,omitempty"`
}

Text represents an SVG text element.

func (*Text) Render

func (t *Text) Render(canvas *svg.SVG)

Render renders the text onto the SVG canvas.

type Transform

type Transform struct {
	Translate []int     `yaml:"translate,omitempty"` // [x, y]
	Rotate    float64   `yaml:"rotate,omitempty"`    // degrees
	Scale     []float64 `yaml:"scale,omitempty"`     // [x, y]
}

Transform represents transformations applied to SVG elements.

type Triangle

type Triangle struct {
	Type        string     `yaml:"type"`
	ID          string     `yaml:"id,omitempty"`
	Points      [][2]int   `yaml:"points"`
	Fill        string     `yaml:"fill,omitempty"`
	Stroke      string     `yaml:"stroke,omitempty"`
	StrokeWidth int        `yaml:"stroke_width,omitempty"`
	Transform   *Transform `yaml:"transform,omitempty"`
}

Triangle represents an SVG triangle.

func (*Triangle) Render

func (t *Triangle) Render(canvas *svg.SVG)

Render renders the triangle onto the SVG canvas.

Jump to

Keyboard shortcuts

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