svgparse

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package svgparse parses SVG path data and basic shapes into a vector IR of move/line/cubic/close segments, ready to emit as PDF path operators. It parses geometry only (not rasterizing); presentation attributes and the wider SVG document model are handled by the SVG renderer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Op

type Op int

Op is a path segment operator.

const (
	MoveTo Op = iota
	LineTo
	CubicTo // Args: c1x, c1y, c2x, c2y, x, y
	Close
)

type Path

type Path []Segment

Path is a sequence of segments in absolute user coordinates.

func Circle

func Circle(cx, cy, r float64) Path

Circle returns the path for a circle.

func Ellipse

func Ellipse(cx, cy, rx, ry float64) Path

Ellipse returns the path for an ellipse as four cubic arcs.

func Line

func Line(x1, y1, x2, y2 float64) Path

Line returns the path for a line segment.

func ParsePath

func ParsePath(d string) (Path, error)

ParsePath parses an SVG path "d" string. Quadratic curves are converted to cubics; smooth curves (S/T) reflect the previous control point. Arcs (A/a) are approximated by a line to the endpoint for now (proper arc→cubic is a TODO).

func Polygon

func Polygon(pts []float64) Path

Polygon returns a closed path through the given points.

func Polyline

func Polyline(pts []float64) Path

Polyline returns an open path through the given [x0,y0,x1,y1,…] points.

func Rect

func Rect(x, y, w, h, rx, ry float64) Path

Rect returns the path for a rectangle. rx/ry round the corners with cubic arcs (each clamped to half the corresponding side).

type Segment

type Segment struct {
	Op   Op
	Args [6]float64
}

Segment is one path operation. MoveTo/LineTo use Args[0:2]; CubicTo uses all six.

Jump to

Keyboard shortcuts

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