svgg

package module
v0.0.0-...-2e7b110 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: BSD-3-Clause Imports: 6 Imported by: 1

README

svgg

svgg is an automated SVG path string parser and rendering tool. It is based on the package srwiley/oksvg but modified to draw directly to an SVG context using the fogleman/gg rendering engine.

Warning: This is a work in progress. Only M line commands are currently implemented.

Installation

go get github.com/engelsjk/svgg

Usage

Note: svgg does not include an SVG/XML parser, so you'll need a way to first extract a path string.


dc := gg.NewContext(150, 200)

parser := svgg.NewParser(dc)

dpath := "M75 0, 0 200, 150 200 Z"

parser.CompilePath(dpath)

dc.SetRGB(0, 0, 0)
dc.Fill()

dc.SavePNG("image.png")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorMode

type ErrorMode uint8

ErrorMode sets how the parser reacts to unparsed elements

const (
	//IgnoreErrorMode skips unparsed SVG elements
	IgnoreErrorMode ErrorMode = iota
	//WarnErrorMode outputs a warning when an unparsed SVG element is found
	WarnErrorMode
	//StrictErrorMode causes a error when an unparsed SVG element is found
	StrictErrorMode
)

type Parser

type Parser struct {
	ErrorMode ErrorMode
	// contains filtered or unexported fields
}

Parser is used to parse SVG strings into drawing commands

func NewParser

func NewParser(dc *gg.Context) *Parser

func (*Parser) AddArcFromA

func (p *Parser) AddArcFromA(points []float64)

AddArcFromA adds a path of an arc element to the Parser

func (*Parser) CompilePath

func (p *Parser) CompilePath(svgPath string) error

CompilePath translates the svgPath description string and draws to the context. All valid SVG path elements are interpreted to fogleman/gg drawing commands.

func (*Parser) EllipseAt

func (p *Parser) EllipseAt(cx, cy, rx, ry float64)

EllipseAt adds a path of an elipse centered at cx, cy of radius rx and ry to the Parser

func (*Parser) GetPoints

func (p *Parser) GetPoints(dataPoints string) error

GetPoints reads a set of floating point values from the SVG format number string, and add them to the cursor's points slice.

func (*Parser) ReadFloat

func (p *Parser) ReadFloat(numStr string) error

ReadFloat reads a floating point value and adds it to the cursor's points slice.

Jump to

Keyboard shortcuts

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