svg

package
v0.0.0-...-b82900a Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Package svg holds SVG object creation and manipulation methods.

Index

Constants

View Source
const (
	// EvenOdd is the fill rule "evenodd"
	EvenOdd = "evenodd"
	// NonZero is the fill rule "NonZero"
	NonZero = "nonzero"

	// Butt is the stroke line cap constant for "butt"
	Butt = "butt"
	// Square is the stroke line cap constant for "square"
	Square = "square"
	// Round is the stroke line cap or stroke line join constant for "round"
	Round = "round"
	// Miter is the stroke line join constant for "miter"
	Miter = "miter"
	// Bevel is the stroke line join constant for "bevel"
	Bevel = "bevel"

	// Normal is the normal constant for font-weight or font-style
	Normal = "normal"
	// Bold is the bold font-weight constant.
	Bold = "bold"
	// Italic is the italic font-style constant.
	Italic = "italic"
	// Underline is the underline text-decoration constant.
	Underline = "underline"
	// Overline is the overline text-decoration constant.
	Overline = "overline"
	// LineThrough is the line-through text-decoration constant.
	LineThrough = "line-through"
)

Variables

This section is empty.

Functions

func Convert

func Convert(input, output string)

Convert uses ImageMagick convert to convert an image from one format to another.

func ConvertToSize

func ConvertToSize(input, output string, width, height int)

ConvertToSize uses rsvg-convert to convert an svg to a png with a given size

func LoadStyle

func LoadStyle(path string) string

LoadStyle loads an external stylesheet and returns the content.

func Round3

func Round3(val float64) float64

Round3 rounds a number down to 3 decimals.

Types

type Circle

type Circle struct {
	GraphicElement
	XMLName xml.Name `xml:"circle"`
	Cx      float64  `xml:"cx,attr"`
	Cy      float64  `xml:"cy,attr"`
	Radius  float64  `xml:"r,attr"`
}

Circle creates a new Circle object.

func NewCircle

func NewCircle(x, y, r float64) *Circle

NewCircle creates a new Circle object.

type Defs

type Defs struct {
	Style         []*StyleSheet
	FilterEffects []*FilterEffect
	Groups        []*Group
}

Defs holds styles, etc.

type Element

type Element interface {
	IsElement() bool

	SetFillColor(color.Color)
	SetFillRGB(int, int, int)
	SetFillOpacity(float64)
	NoFill()

	SetStrokeColor(color.Color)
	SetStrokeRGB(int, int, int)
	SetStrokeWidth(float64)
	SetStrokeOpacity(float64)
	SetStrokeDash(...int)
	NoStroke()

	SetStyle(string)
}

Element is an interface defining an SVG Element.

type Ellipse

type Ellipse struct {
	GraphicElement
	XMLName xml.Name `xml:"ellipse"`
	Cx      float64  `xml:"cx,attr"`
	Cy      float64  `xml:"cy,attr"`
	Rx      float64  `xml:"rx,attr"`
	Ry      float64  `xml:"ry,attr"`
}

Ellipse creates a new Ellipse object.

func NewEllipse

func NewEllipse(x, y, rx, ry float64) *Ellipse

NewEllipse creates a new Ellipse object.

type FilterEffect

type FilterEffect struct {
	XMLName xml.Name `xml:"filter"`
	ID      string   `xml:"id,attr"`
	Filter  string   `xml:",innerxml"`
	X       string   `xml:"x,attr,omitempty"`
	Y       string   `xml:"y,attr,omitempty"`
	Width   string   `xml:"width,attr,omitempty"`
	Height  string   `xml:"height,attr,omitempty"`
}

FilterEffect defines a filter effect.

func NewBlurFilter

func NewBlurFilter(id string, blur float64) *FilterEffect

NewBlurFilter creates a new drop shadow filter effect

func NewDropShadow

func NewDropShadow(id string, blur, strength, dx, dy float64) *FilterEffect

NewDropShadow creates a new drop shadow filter effect

func NewGlowFilter

func NewGlowFilter(id string, blur, r, g, b, a float64) *FilterEffect

NewGlowFilter creates a new glow filter effect rgba values are float64s in the range of 0.0 to 1.0.

func (*FilterEffect) SetBoundPercent

func (fe *FilterEffect) SetBoundPercent(percent int)

SetBoundPercent sets the bounds of the filter in terms of percent of the object's bounding box. Sets all bounds with a single value. The default values would be equivalent to passing 10 here, allowing for 10% more on each side.

func (*FilterEffect) SetBoundPercents

func (fe *FilterEffect) SetBoundPercents(x, y, w, h int)

SetBoundPercents sets the bounds of the filter in terms of percent of the object's bounding box. Allows for setting the bounds on each edge separately. The default values would be equivalent to passing 10, 10, 120, 120 here, allowing for 10% more on each side.

type GraphicElement

type GraphicElement struct {
	ID            string  `xml:"id,attr,omitempty"`
	Stroke        string  `xml:"stroke,attr,omitempty"`
	Fill          string  `xml:"fill,attr,omitempty"`
	FillOpacity   float64 `xml:"fill-opacity,attr,omitempty"`
	StrokeWidth   float64 `xml:"stroke-width,attr,omitempty"`
	StrokeOpacity float64 `xml:"stroke-opacity,attr,omitempty"`
	StrokeDash    string  `xml:"stroke-dasharray,attr,omitempty"`
	Style         string  `xml:"style,attr,omitempty"`
	Class         string  `xml:"class,attr,omitempty"`
	LineCap       string  `xml:"stroke-linecap,attr,omitempty"`
	LineJoin      string  `xml:"stroke-linejoin,attr,omitempty"`
	MiterLimit    float64 `xml:"stroke-miterlimit,attr,omitempty"`
	Filters       string  `xml:"filter,attr,omitempty"`
	Transform     string  `xml:"transform,attr,omitempty"`
}

GraphicElement represents an SVG Node.

func NewGraphicElement

func NewGraphicElement() *GraphicElement

NewGraphicElement returns a new GraphicElement

func (*GraphicElement) IsElement

func (ge *GraphicElement) IsElement() bool

IsElement returns true for Elements.

func (*GraphicElement) NoFill

func (ge *GraphicElement) NoFill()

NoFill sets the fill of the element to "none".

func (*GraphicElement) NoStroke

func (ge *GraphicElement) NoStroke()

NoStroke sets the element to render without a stroke.

func (*GraphicElement) RotateDeg

func (ge *GraphicElement) RotateDeg(deg float64)

RotateDeg rotates the element the given number of degrees.

func (*GraphicElement) RotateRad

func (ge *GraphicElement) RotateRad(rad float64)

RotateRad rotates the element the given number of radians.

func (*GraphicElement) Scale

func (ge *GraphicElement) Scale(x, y float64)

Scale scales the element the given percent.

func (*GraphicElement) SetFillColor

func (ge *GraphicElement) SetFillColor(c color.Color)

SetFillColor sets the fill attribute using a blgo Color

func (*GraphicElement) SetFillOpacity

func (ge *GraphicElement) SetFillOpacity(opacity float64)

SetFillOpacity sets the opacity of the stroke on this element.

func (*GraphicElement) SetFillRGB

func (ge *GraphicElement) SetFillRGB(r, g, b int)

SetFillRGB sets the fill color of this element with rgb integer values and full opacity.

func (*GraphicElement) SetFillRandom

func (ge *GraphicElement) SetFillRandom()

SetFillRandom sets the fill to a random color.

func (*GraphicElement) SetFilters

func (ge *GraphicElement) SetFilters(filters ...string)

SetFilters sets a list of filters to use on this element.

func (*GraphicElement) SetID

func (ge *GraphicElement) SetID(id string)

SetID sets the id of the element.

func (*GraphicElement) SetLineCap

func (ge *GraphicElement) SetLineCap(cap string)

SetLineCap sets the line cap of this element.

func (*GraphicElement) SetLineJoin

func (ge *GraphicElement) SetLineJoin(cap string)

SetLineJoin sets the line join of this polygon.

func (*GraphicElement) SetMiterLimit

func (ge *GraphicElement) SetMiterLimit(limit float64)

SetMiterLimit sets the miter limit of this polygon.

func (*GraphicElement) SetStrokeColor

func (ge *GraphicElement) SetStrokeColor(c color.Color)

SetStrokeColor sets the stroke attribute using a blgo Color

func (*GraphicElement) SetStrokeDash

func (ge *GraphicElement) SetStrokeDash(dash ...int)

SetStrokeDash sets the dash values for a stroke.

func (*GraphicElement) SetStrokeOpacity

func (ge *GraphicElement) SetStrokeOpacity(width float64)

SetStrokeOpacity sets the width of the stroke on this element.

func (*GraphicElement) SetStrokeRGB

func (ge *GraphicElement) SetStrokeRGB(r, g, b int)

SetStrokeRGB sets the stroke color of this element with rgb integer values and full opacity.

func (*GraphicElement) SetStrokeWidth

func (ge *GraphicElement) SetStrokeWidth(width float64)

SetStrokeWidth sets the width of the stroke on this element.

func (*GraphicElement) SetStyle

func (ge *GraphicElement) SetStyle(style string)

SetStyle sets an inline style.

func (*GraphicElement) Translate

func (ge *GraphicElement) Translate(x, y float64)

Translate rotates the element the given number of degrees.

func (*GraphicElement) Uniscale

func (ge *GraphicElement) Uniscale(s float64)

Uniscale scales the element the given percent.

type Group

type Group struct {
	GraphicElement
	XMLName  xml.Name `xml:"g"`
	Elements []Element
}

Group creates a new Circle object.

func NewGroup

func NewGroup() *Group

NewGroup creates a new Group object.

func (*Group) AddElement

func (g *Group) AddElement(e Element)

AddElement adds and element to the group.

type Line

type Line struct {
	GraphicElement
	XMLName xml.Name `xml:"line"`
	X1      float64  `xml:"x1,attr"`
	Y1      float64  `xml:"y1,attr"`
	X2      float64  `xml:"x2,attr"`
	Y2      float64  `xml:"y2,attr"`
}

Line creates a new Line object.

func NewLine

func NewLine(x1, y1, x2, y2 float64) *Line

NewLine creates a new Line object.

type Path

type Path struct {
	GraphicElement
	XMLName xml.Name `xml:"path"`
	D       string   `xml:"d,attr"`
}

Path creates a new Path object.

func NewPath

func NewPath() *Path

NewPath creates a new Path object.

func (*Path) Close

func (p *Path) Close()

Close draws a line back to the starting point.

func (*Path) CubicCurveTo

func (p *Path) CubicCurveTo(x1, y1, x2, y2, x3, y3 float64)

CubicCurveTo draws a quadratic bezier curve.

func (*Path) LineTo

func (p *Path) LineTo(x, y float64)

LineTo moves the drawing cursor to the x y point.

func (*Path) LineToRel

func (p *Path) LineToRel(dx, dy float64)

LineToRel moves the drawing cursor to the x y point.

func (*Path) MoveTo

func (p *Path) MoveTo(x, y float64)

MoveTo moves the drawing cursor to the x y point.

func (*Path) MoveToRel

func (p *Path) MoveToRel(dx, dy float64)

MoveToRel moves the drawing cursor relative to its current location.

func (*Path) QuadraticCurveTo

func (p *Path) QuadraticCurveTo(x1, y1, x2, y2 float64)

QuadraticCurveTo draws a quadratic bezier curve.

type Polygon

type Polygon struct {
	GraphicElement
	XMLName  xml.Name `xml:"polygon"`
	Points   string   `xml:"points,attr"`
	FillRule string   `xml:"fill-rule,attr,omitempty"`
}

Polygon creates a new Polygon object.

func NewPolygon

func NewPolygon(points ...float64) *Polygon

NewPolygon creates a new Polygon object.

func NewRegularPolygon

func NewRegularPolygon(x, y float64, numPoints int, radius, rotation float64) *Polygon

NewRegularPolygon creates a regular polygon with the given number of points, radius and rotation.

func NewStar

func NewStar(x, y float64, numPoints int, innerRadius, outerRadius, rotation float64) *Polygon

NewStar creates a star shape with the given number of points, inner and outer radii and rotation.

type Polyline

type Polyline struct {
	GraphicElement
	XMLName xml.Name `xml:"polyline"`
	Points  string   `xml:"points,attr"`
}

Polyline creates a new Polyline object.

func NewPolyline

func NewPolyline(points ...float64) *Polyline

NewPolyline creates a new Polyline object.

type Rect

type Rect struct {
	GraphicElement
	XMLName xml.Name `xml:"rect"`
	X       float64  `xml:"x,attr"`
	Y       float64  `xml:"y,attr"`
	Width   float64  `xml:"width,attr"`
	Height  float64  `xml:"height,attr"`
	Rx      float64  `xml:"rx,attr,omitempty"`
	Ry      float64  `xml:"ry,attr,omitempty"`
}

Rect creates a new Rect object.

func NewRect

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

NewRect creates a new Rect object.

type SVG

type SVG struct {
	XMLName        xml.Name `xml:"svg"`
	StyleSheet     string   `xml:"-"`
	Width          float64  `xml:"width,attr"`
	Height         float64  `xml:"height,attr"`
	Namespace      string   `xml:"xmlns,attr"`
	Title          string   `xml:"title"`
	Description    string   `xml:"desc,omitempty"`
	Style          string   `xml:"style,omitempty"`
	BackgroundRect *Rect    `xml:"rect"`
	Defs           *Defs    `xml:"defs,omitempty"`
	Elements       []Element
}

SVG is a struct representing an SVG object.

func NewSVG

func NewSVG(title string, width, height float64) *SVG

NewSVG creates a new SVG instance.

func (*SVG) AddCircle

func (s *SVG) AddCircle(x, y, r float64) *Circle

AddCircle adds a new Circle object to the SVG.

func (*SVG) AddElement

func (s *SVG) AddElement(element Element)

AddElement adds a new GraphicElement to the SVG.

func (*SVG) AddEllipse

func (s *SVG) AddEllipse(x, y, rx, ry float64) *Ellipse

AddEllipse adds a new Ellipse object to the SVG.

func (*SVG) AddFilter

func (s *SVG) AddFilter(fe *FilterEffect)

AddFilter adds an filter effect to the SVG.

func (*SVG) AddGroup

func (s *SVG) AddGroup() *Group

AddGroup adds a new Group object to the SVG.

func (*SVG) AddGroupDef

func (s *SVG) AddGroupDef() *Group

AddGroupDef adds a new Group object to the SVG.

func (*SVG) AddLine

func (s *SVG) AddLine(x1, y1, x2, y2 float64) *Line

AddLine adds a new Line object to the SVG.

func (*SVG) AddPath

func (s *SVG) AddPath() *Path

AddPath adds a new Path object to the SVG.

func (*SVG) AddPolygon

func (s *SVG) AddPolygon(points ...float64) *Polygon

AddPolygon adds a new Polygon object to the SVG.

func (*SVG) AddPolyline

func (s *SVG) AddPolyline(points ...float64) *Polyline

AddPolyline adds a new Polyline object to the SVG.

func (*SVG) AddRect

func (s *SVG) AddRect(x, y, w, h float64) *Rect

AddRect adds a new Rect object to the SVG.

func (*SVG) AddRegularPolygon

func (s *SVG) AddRegularPolygon(x, y float64, points int, radius, rotation float64) *Polygon

AddRegularPolygon adds a new Rect object to the SVG.

func (*SVG) AddStar

func (s *SVG) AddStar(x, y float64, points int, innerRadius, outerRadius, rotation float64) *Polygon

AddStar adds a new Star object to the SVG.

func (*SVG) AddStyleSheet

func (s *SVG) AddStyleSheet(path string)

AddStyleSheet adds an internal stylesheet to the SVG document, with the given path. The stylesheet is embedded in the SVG document at compile time. Imagemagick convert respects the styles set there, but not external stylesheets.

func (*SVG) AddText

func (s *SVG) AddText(x, y float64, text string) *Text

AddText adds a new Text object to the SVG.

func (*SVG) AddUse

func (s *SVG) AddUse(href string, x, y float64) *Use

AddUse adds a new Use object to the SVG.

func (*SVG) SetBackgroundRGB

func (s *SVG) SetBackgroundRGB(r, g, b int)

SetBackgroundRGB creates a background rect of the given color.

func (*SVG) WriteToFile

func (s *SVG) WriteToFile(filename string) error

WriteToFile saves this SVG object as an SVG file.

type StyleSheet

type StyleSheet struct {
	XMLName   xml.Name `xml:"style"`
	Type      string   `xml:"type,attr"`
	StyleData string   `xml:",cdata"`
}

StyleSheet respresents an internal stylesheet.

func NewStyleSheet

func NewStyleSheet(path string) *StyleSheet

NewStyleSheet creates a new StyleSheet with the given style data.

type Text

type Text struct {
	GraphicElement
	XMLName        xml.Name `xml:"text"`
	X              float64  `xml:"x,attr"`
	Y              float64  `xml:"y,attr"`
	Text           string   `xml:",innerxml"`
	FontSize       float64  `xml:"font-size,attr,omitempty"`
	FontFamily     string   `xml:"font-family,attr,omitempty"`
	FontWeight     string   `xml:"font-weight,attr,omitempty"`
	FontStyle      string   `xml:"font-style,attr,omitempty"`
	TextDecoration string   `xml:"text-decoration,attr,omitempty"`
}

Text creates a new Text object.

func NewText

func NewText(x, y float64, text string) *Text

NewText creates a new Text object.

func (*Text) SetFontFamily

func (t *Text) SetFontFamily(fontFamily string)

SetFontFamily sets the font family in this text.

func (*Text) SetFontSize

func (t *Text) SetFontSize(size float64)

SetFontSize sets the size of the font used in this text.

func (*Text) SetFontStyle

func (t *Text) SetFontStyle(fontStyle string)

SetFontStyle sets the font style in this text.

func (*Text) SetTextDecoration

func (t *Text) SetTextDecoration(textDecoration string)

SetTextDecoration sets the text decoration type of this text.

type Use

type Use struct {
	GraphicElement
	XMLName xml.Name `xml:"use"`
	Href    string   `xml:"href,attr"`
	X       float64  `xml:"x,attr"`
	Y       float64  `xml:"y,attr"`
}

Use creates a new Use object.

func NewUse

func NewUse(id string, x, y float64) *Use

NewUse creates a new Use object.

Jump to

Keyboard shortcuts

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