surrender

package module
v0.0.0-...-cda09a3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

README

! THIS IS A WORK IN PROGRESS !

Surrender

The early beginnings of a pure-go non-antialiased TinySVG 1.2 renderer.

The goal is to be able to render TinySVG 1.2 files.

Currently supported elements (sorta):

  • svg
  • path (some of it)
  • circle
  • rect

TODO

  • Be able to render SVG images that are produced by png2svg.
  • Be able to render g elements.
  • More robust path data and coordinate parsing.

General info

  • Version: -0.-0.-0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawLine

func DrawLine(img *image.RGBA, p1, p2 image.Point, clr color.Color)

DrawLine function to draw a line on an image

func GetColor

func GetColor(colorStr string) color.Color

func GetSVGDimensions

func GetSVGDimensions(filename string) (int, int, error)

GetSVGDimensions reads the specified TinySVG 1.2 file and returns its width and height if declared

func NewColoredImage

func NewColoredImage(width, height int, clr color.Color) *image.RGBA

Create new colored image

func ParseCoordinates

func ParseCoordinates(coords string) (int, int, error)

ParseCoordinates tries to parse a TinySVG 1.2 path attribute coordinate

func Render

func Render(elements []SvgElement, img *image.RGBA)

Render function takes SVG elements and an image, and renders the elements onto the image

func RenderAndSaveSVG

func RenderAndSaveSVG(elements []SvgElement, filename string, bgColor color.Color) error

RenderAndSaveSVG takes SVG elements and a background color, creates an image, renders the elements onto the image and saves it as PNG

func SavePNG

func SavePNG(img *image.RGBA, filename string) error

SavePNG function to save image as PNG

Types

type PathCommand

type PathCommand struct {
	Type   string
	Points []image.Point
}

type SVG

type SVG struct {
	XMLName xml.Name `xml:"svg"`
	Width   string   `xml:"width,attr"`
	Height  string   `xml:"height,attr"`
}

SVG represents the structure of the SVG file

type SvgCircle

type SvgCircle struct {
	Cx, Cy, R int
	Fill      color.Color
}

SvgCircle struct

func (SvgCircle) Color

func (c SvgCircle) Color() color.Color

func (SvgCircle) Draw

func (c SvgCircle) Draw(img *image.RGBA, clr color.Color)

Draw method for SvgCircle

type SvgElement

type SvgElement interface {
	Draw(img *image.RGBA, color color.Color)
	Color() color.Color
}

func ParseFile

func ParseFile(filename string) ([]SvgElement, error)

ParseFile will try to parse the given TinySVG 1.2 file into a slice of SvgElements

type SvgGroup

type SvgGroup struct {
	Elements []SvgElement
	Fill     color.Color
}

New structure for SvgGroup

func (SvgGroup) Color

func (g SvgGroup) Color() color.Color

func (SvgGroup) Draw

func (g SvgGroup) Draw(img *image.RGBA, _ color.Color)

Draw method for SvgGroup

type SvgLine

type SvgLine struct {
	X1, Y1, X2, Y2 int
	Stroke         color.Color
}

SvgLine struct

func (SvgLine) Color

func (l SvgLine) Color() color.Color

func (SvgLine) Draw

func (l SvgLine) Draw(img *image.RGBA, clr color.Color)

Draw method for SvgLine

type SvgPath

type SvgPath struct {
	Commands []PathCommand
	Fill     color.Color
}

SvgPath struct

func ParsePath

func ParsePath(d string) (SvgPath, error)

ParsePath can parse TinySVG 1.2 path attributes

func (SvgPath) Color

func (p SvgPath) Color() color.Color

func (SvgPath) Draw

func (p SvgPath) Draw(img *image.RGBA, clr color.Color)

Draw method for SvgPath

type SvgRectangle

type SvgRectangle struct {
	X, Y, Width, Height int
	Fill                color.Color
}

SvgRectangle struct

func (SvgRectangle) Color

func (r SvgRectangle) Color() color.Color

func (SvgRectangle) Draw

func (r SvgRectangle) Draw(img *image.RGBA, clr color.Color)

Draw method for SvgRectangle

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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