svg

package
v0.0.0-...-91a30e5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package svg parses Gerber to SVG.

Package svg parses Gerber to SVG.

Example
gbr := `G04 Ucamco ex. 1: Two square boxes*
%MOMM*%
%FSLAX26Y26*%
%LPD*%
%ADD10C,0.010*%
D10*
X0Y0D02*
G01*
X5000000Y0D01*
Y5000000D01*
X0D01*
Y0D01*
X6000000D02*
X11000000D01*
Y5000000D01*
X6000000D01*
Y0D01*
M02*`

svgP, err := SVG(bytes.NewBufferString(gbr))
if err != nil {
	log.Fatalf("%+v", err)
}
svgP.PanZoom = false
buf := bytes.NewBuffer(nil)
if err := svgP.Write(buf); err != nil {
	log.Fatalf("%+v", err)
}
fmt.Printf("%s", buf.Bytes())
Output:

<svg viewBox="0 -5000000 11000000 5000000" style="background-color: black;" xmlns="http://www.w3.org/2000/svg">
<line x1="0" y1="-0" x2="5000000" y2="-0" stroke-width="10000" stroke-linecap="round" stroke="white" line="8"/>
<line x1="5000000" y1="-0" x2="5000000" y2="-5000000" stroke-width="10000" stroke-linecap="round" stroke="white" line="9"/>
<line x1="5000000" y1="-5000000" x2="0" y2="-5000000" stroke-width="10000" stroke-linecap="round" stroke="white" line="10"/>
<line x1="0" y1="-5000000" x2="0" y2="-0" stroke-width="10000" stroke-linecap="round" stroke="white" line="11"/>
<line x1="6000000" y1="-0" x2="11000000" y2="-0" stroke-width="10000" stroke-linecap="round" stroke="white" line="13"/>
<line x1="11000000" y1="-0" x2="11000000" y2="-5000000" stroke-width="10000" stroke-linecap="round" stroke="white" line="14"/>
<line x1="11000000" y1="-5000000" x2="6000000" y2="-5000000" stroke-width="10000" stroke-linecap="round" stroke="white" line="15"/>
<line x1="6000000" y1="-5000000" x2="6000000" y2="-0" stroke-width="10000" stroke-linecap="round" stroke="white" line="16"/>
</svg>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bounds

func Bounds(element interface{}) (image.Rectangle, error)

Types

type Arc

type Arc struct {
	Type        ElementType
	Line        int
	XS          int
	YS          int
	RadiusX     int
	RadiusY     int
	LargeArc    int
	Sweep       int
	XE          int
	YE          int
	StrokeWidth int

	CenterX int
	CenterY int
	Stroke  string
	Attr    map[string]string
}

An Arc is a SVG Arc.

func (Arc) Bounds

func (e Arc) Bounds() image.Rectangle

func (Arc) MarshalJSON

func (e Arc) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Arc) SetAttr

func (e Arc) SetAttr(k, v string) Arc

type Circle

type Circle struct {
	Type   ElementType
	Line   int
	X      int
	Y      int
	Radius int
	Fill   string
	Attr   map[string]string
}

A Circle is a circle.

func (Circle) Bounds

func (e Circle) Bounds() image.Rectangle

func (Circle) MarshalJSON

func (e Circle) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Circle) SetAttr

func (e Circle) SetAttr(k, v string) Circle

type ElementType

type ElementType string

An ElementType is a SVG element type.

const (
	ElementTypeCircle    ElementType = "Circle"
	ElementTypeRectangle ElementType = "Rect"
	ElementTypePath      ElementType = "Path"
	ElementTypeLine      ElementType = "Line"
	ElementTypeArc       ElementType = "Arc"
)

type Line

type Line struct {
	Type        ElementType
	Line        int
	X1          int
	Y1          int
	X2          int
	Y2          int
	StrokeWidth int
	Cap         string

	Stroke string
	Attr   map[string]string
}

A Line is a SVG line.

func (Line) Bounds

func (e Line) Bounds() image.Rectangle

func (Line) MarshalJSON

func (e Line) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Line) SetAttr

func (e Line) SetAttr(k, v string) Line

type Path

type Path struct {
	Type     ElementType
	Line     int
	X        int
	Y        int
	Commands []interface{}
	Fill     string
	Attr     map[string]string
}

A Path is a SVG path.

func (Path) Bounds

func (e Path) Bounds() (image.Rectangle, error)

func (Path) MarshalJSON

func (e Path) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Path) SetAttr

func (e Path) SetAttr(k, v string) Path

type PathArc

type PathArc struct {
	Type     ElementType
	RadiusX  int
	RadiusY  int
	LargeArc int
	Sweep    int
	X        int
	Y        int

	CenterX int
	CenterY int
}

A PathArc is an arc in a SVG path.

func (PathArc) MarshalJSON

func (e PathArc) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type PathLine

type PathLine struct {
	Type ElementType
	X    int
	Y    int
}

A PathLine is a line in a SVG path.

func (PathLine) MarshalJSON

func (e PathLine) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type Processor

type Processor struct {
	// Data contains SVG elements.
	Data []interface{}

	// Viewbox of Gerber image.
	MinX int
	MaxX int
	MinY int
	MaxY int

	// Decimal is the multiplier to convert millimeters to coordinates.
	// It is defined in the gerber file.
	Decimal float64

	// Color for Gerber polarities, defaults to black and white.
	PolarityDark  string
	PolarityClear string

	// Optional scaling factor of coordinates when writing SVG image.
	Scale float64

	// Optional width and height of output SVG image.
	Width  string
	Height string

	// Whether to output javascript for interactive panning and zooming in SVG.
	PanZoom bool
}

A Processor is a performer of Gerber graphic operations.

func NewProcessor

func NewProcessor() *Processor

NewProcessor creates a Processor.

func SVG

func SVG(r io.Reader) (*Processor, error)

SVG parses Gerber input into SVG.

func (*Processor) Arc

func (p *Processor) Arc(lineIdx, xs, ys, xe, ye, xc, yc int, interpolation gerber.Interpolation, diameter int) error

func (*Processor) Circle

func (p *Processor) Circle(lineIdx, x, y, diameter int, polarity bool)

func (*Processor) Contour

func (p *Processor) Contour(contour gerber.Contour) error

func (*Processor) Line

func (p *Processor) Line(lineIdx, x0, y0, x1, y1, diameter int, linecap gerber.LineCap)

func (*Processor) Obround

func (p *Processor) Obround(lineIdx, x, y, width, height int, polarity bool)

func (*Processor) Rectangle

func (p *Processor) Rectangle(lineIdx, x, y, width, height int, polarity bool)

func (*Processor) SetDecimal

func (p *Processor) SetDecimal(decimal float64)

func (*Processor) SetViewbox

func (p *Processor) SetViewbox(minX, maxX, minY, maxY int)

func (*Processor) UnmarshalJSON

func (p *Processor) UnmarshalJSON(b []byte) error

func (*Processor) UnmarshalJSON_1

func (p *Processor) UnmarshalJSON_1(b []byte) error

func (*Processor) Write

func (p *Processor) Write(w io.Writer) error

Write writes Gerber graphics operations as SVG.

type Rectangle

type Rectangle struct {
	Type     ElementType
	Line     int
	Aperture string
	X        int
	Y        int
	Width    int
	Height   int
	RX       int
	RY       int
	Fill     string
	Attr     map[string]string
}

A Rectangle is a rectangle.

func (Rectangle) Bounds

func (e Rectangle) Bounds() image.Rectangle

func (Rectangle) MarshalJSON

func (e Rectangle) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Rectangle) SetAttr

func (e Rectangle) SetAttr(k, v string) Rectangle

Jump to

Keyboard shortcuts

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