skpath

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package skpath is a port of the parts of tiny-skia-path 0.11 (Skia's SkPath, SkStroke and SkDashPath) the icon transform needs: path building, affine transforms, stroking into fill outlines, and dashing. Arithmetic stays in float32 with the same operation order as the Rust code so the emitted coordinates match it.

Index

Constants

This section is empty.

Variables

View Source
var Identity = Transform{SX: 1, SY: 1}

Identity is the identity transform.

Functions

func ComputeResolutionScale

func ComputeResolutionScale(t Transform) float32

ComputeResolutionScale is PathStroker::compute_resolution_scale.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder accumulates a path (tiny-skia's PathBuilder, i.e. SkPath).

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns an empty builder.

func (*Builder) Close

func (b *Builder) Close()

Close closes the contour (never twice, never first).

func (*Builder) CubicTo

func (b *Builder) CubicTo(x1, y1, x2, y2, x, y float32)

CubicTo adds a cubic.

func (*Builder) Finish

func (b *Builder) Finish() (*Path, bool)

Finish builds the path; false for fewer than two verbs or unbounded points.

func (*Builder) IsEmpty

func (b *Builder) IsEmpty() bool

IsEmpty reports no verbs.

func (*Builder) LastPoint

func (b *Builder) LastPoint() (Point, bool)

LastPoint is the last point added.

func (*Builder) Len

func (b *Builder) Len() int

Len is the verb count.

func (*Builder) LineTo

func (b *Builder) LineTo(x, y float32)

LineTo adds a line.

func (*Builder) MoveTo

func (b *Builder) MoveTo(x, y float32)

MoveTo starts a contour (replacing a trailing move).

func (*Builder) QuadTo

func (b *Builder) QuadTo(x1, y1, x, y float32)

QuadTo adds a quadratic.

type LineCap

type LineCap uint8

LineCap is a stroke's end cap.

const (
	CapButt LineCap = iota
	CapRound
	CapSquare
)

The caps.

type LineJoin

type LineJoin uint8

LineJoin is a stroke's corner join.

const (
	JoinMiter LineJoin = iota
	JoinMiterClip
	JoinRound
	JoinBevel
)

The joins.

type Path

type Path struct {
	// contains filtered or unexported fields
}

Path is an immutable path with at least two verbs (tiny-skia's Path).

func FromRect

func FromRect(r Rect) *Path

FromRect is PathBuilder::from_rect.

func (*Path) Bounds

func (p *Path) Bounds() Rect

Bounds is the control-point bounds.

func (*Path) ComputeTightBounds

func (p *Path) ComputeTightBounds() (Rect, bool)

ComputeTightBounds is Path::compute_tight_bounds.

func (*Path) DashPath

func (p *Path) DashPath(d *StrokeDash, resScale float32) (*Path, bool)

DashPath is Path::dash.

func (*Path) Len

func (p *Path) Len() int

Len is the verb count.

func (*Path) Segments

func (p *Path) Segments() *segmentsIter

Segments iterates the path.

func (*Path) StrokePath

func (p *Path) StrokePath(s Stroke, resScale float32) (*Path, bool)

StrokePath is Path::stroke: the fill outline of the stroke.

func (*Path) Transform

func (p *Path) Transform(ts Transform) (*Path, bool)

Transform maps the path through ts; false when the result has no finite bounds.

type Point

type Point struct{ X, Y float32 }

Point is a 2D point (tiny-skia's Point).

func Pt

func Pt(x, y float32) Point

Pt builds a point.

type Rect

type Rect struct{ Left, Top, Right, Bottom float32 }

Rect is a finite rectangle with left <= right and top <= bottom.

func RectFromLTRB

func RectFromLTRB(l, t, r, b float32) (Rect, bool)

RectFromLTRB validates and builds a rect.

func RectFromXYWH

func RectFromXYWH(x, y, w, h float32) (Rect, bool)

RectFromXYWH is RectFromLTRB(x, y, w+x, h+y).

func (Rect) Height

func (r Rect) Height() float32

Height is bottom - top.

func (Rect) Width

func (r Rect) Width() float32

Width is right - left.

type Segment

type Segment struct {
	Kind SegmentKind
	P    [3]Point
}

Segment is one iterated path segment; P holds its points (the target last).

type SegmentKind

type SegmentKind uint8

SegmentKind tags a Segment.

const (
	SegMove SegmentKind = iota
	SegLine
	SegQuad
	SegCubic
	SegClose
)

The segment kinds.

type Stroke

type Stroke struct {
	Width      float32
	MiterLimit float32
	LineCap    LineCap
	LineJoin   LineJoin
	Dash       *StrokeDash
}

Stroke describes a stroke to outline.

type StrokeDash

type StrokeDash struct {
	// contains filtered or unexported fields
}

StrokeDash is a validated dash pattern.

func NewStrokeDash

func NewStrokeDash(array []float32, offset float32) (*StrokeDash, bool)

NewStrokeDash is StrokeDash::new: an even-length, non-negative array with a positive sum and a finite offset.

type Transform

type Transform struct {
	SX, KY, KX, SY, TX, TY float32
}

Transform is an affine matrix (tiny-skia's Transform): x' = sx*x + kx*y + tx, y' = ky*x + sy*y + ty.

func FromRow

func FromRow(sx, ky, kx, sy, tx, ty float32) Transform

FromRow builds a transform from its row-major components.

func FromScale

func FromScale(sx, sy float32) Transform

FromScale is a scale.

func FromTranslate

func FromTranslate(tx, ty float32) Transform

FromTranslate is a translation.

func (Transform) IsIdentity

func (t Transform) IsIdentity() bool

IsIdentity reports the identity.

func (Transform) IsValid

func (t Transform) IsValid() bool

IsValid reports a finite transform whose scale is not degenerate.

func (Transform) MapPoints

func (t Transform) MapPoints(points []Point)

MapPoints transforms points in place.

func (Transform) PostConcat

func (t Transform) PostConcat(o Transform) Transform

PostConcat is other * self.

func (Transform) PreConcat

func (t Transform) PreConcat(o Transform) Transform

PreConcat is self * other.

func (Transform) PreScale

func (t Transform) PreScale(sx, sy float32) Transform

PreScale is self * scale(sx, sy).

func (Transform) PreTranslate

func (t Transform) PreTranslate(tx, ty float32) Transform

PreTranslate is self * translate(tx, ty).

func (Transform) Scale

func (t Transform) Scale() (float32, float32)

Scale is get_scale: the lengths of the transformed unit axes.

type Verb

type Verb uint8

Verb is one path command.

const (
	VerbMove Verb = iota
	VerbLine
	VerbQuad
	VerbCubic
	VerbClose
)

The verbs.

Jump to

Keyboard shortcuts

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