Documentation
¶
Overview ¶
Package vector draws paths into pixels on the CPU: fills with the nonzero or even-odd rule, strokes with joins, caps and dashes, solid colors and linear and radial gradients, clipping and group opacity. The ui package's Canvas and SVG are drawn with it, into an image the renderer shows.
Coordinates are float32 pixels, y down. Colors are straight (not premultiplied) R, G, B, A from 0 to 1; the image drawn into is premultiplied.
Index ¶
- Variables
- type Canvas
- func (c *Canvas) Clip(p *Path, rule FillRule)
- func (c *Canvas) Fill(p *Path, paint Paint, rule FillRule)
- func (c *Canvas) Image() *image.RGBA
- func (c *Canvas) Matrix() Matrix
- func (c *Canvas) PopLayer()
- func (c *Canvas) PushLayer(alpha float32)
- func (c *Canvas) Reset(w, h int)
- func (c *Canvas) Restore()
- func (c *Canvas) Save()
- func (c *Canvas) SetAlpha(a float32)
- func (c *Canvas) SetTransform(m Matrix)
- func (c *Canvas) Stroke(p *Path, paint Paint, s Stroke)
- func (c *Canvas) Transform(m Matrix)
- type Cap
- type Color
- type FillRule
- type Gradient
- type GradientKind
- type Join
- type Matrix
- type Paint
- type Path
- func (p *Path) Append(o *Path)
- func (p *Path) Arc(cx, cy, r, a0, a1 float32, ccw bool)
- func (p *Path) ArcTo(rx, ry, rotation float32, large, sweep bool, x, y float32)
- func (p *Path) Bounds() (x0, y0, x1, y1 float32, ok bool)
- func (p *Path) Close()
- func (p *Path) CubicTo(c1x, c1y, c2x, c2y, x, y float32)
- func (p *Path) Current() (Point, bool)
- func (p *Path) Ellipse(cx, cy, rx, ry float32)
- func (p *Path) Empty() bool
- func (p *Path) LineTo(x, y float32)
- func (p *Path) MoveTo(x, y float32)
- func (p *Path) QuadTo(cx, cy, x, y float32)
- func (p *Path) Rect(x, y, w, h float32)
- func (p *Path) RoundRect(x, y, w, h, rx, ry float32)
- func (p *Path) Transform(m Matrix) *Path
- type Point
- type Spread
- type Stop
- type Stroke
Constants ¶
This section is empty.
Variables ¶
var Identity = Matrix{A: 1, D: 1}
Identity is the transform that changes nothing.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
// Tolerance is how far, in pixels, flattened curves may stray; 0 means
// 0.05, which loses no visible area to the straight segments.
Tolerance float32
// contains filtered or unexported fields
}
Canvas draws into a premultiplied RGBA image. It keeps a stack of states, each with a transform, a clip and an opacity, and of layers, which group drawing so it is faded as a whole.
func (*Canvas) Clip ¶
Clip limits later drawing to the inside of p (in the current coordinates), within the current clip.
func (*Canvas) PopLayer ¶
func (c *Canvas) PopLayer()
PopLayer draws the innermost layer onto what is below it.
func (*Canvas) PushLayer ¶
PushLayer starts a layer: drawing goes into it until PopLayer (or the Restore of an earlier Save), which draws it onto what is below at opacity alpha.
func (*Canvas) Reset ¶
Reset clears the canvas to transparent at w x h pixels and drops the states and layers, keeping the buffers it can.
func (*Canvas) Restore ¶
func (c *Canvas) Restore()
Restore returns to the state of the matching Save. Layers pushed since it are drawn first.
func (*Canvas) Save ¶
func (c *Canvas) Save()
Save pushes a copy of the current state; Restore pops it.
func (*Canvas) SetTransform ¶
SetTransform replaces the current transform.
type Color ¶
type Color struct{ R, G, B, A float32 }
Color is a straight (not premultiplied) R, G, B, A color from 0 to 1.
type FillRule ¶
type FillRule uint8
FillRule decides which parts of a self-overlapping path are inside.
type Gradient ¶
type Gradient struct {
Kind GradientKind
// X0, Y0 to X1, Y1 is a linear gradient's line.
X0, Y0, X1, Y1 float32
// A radial gradient runs from the focal point FX, FY to the circle of
// radius R about CX, CY.
CX, CY, R, FX, FY float32
Stops []Stop
Spread Spread
Matrix Matrix
}
Gradient is a linear or radial gradient, in the coordinates of the shape it paints, transformed by Matrix (SVG's gradientTransform).
type GradientKind ¶
type GradientKind uint8
GradientKind is the shape of a gradient.
const ( Linear GradientKind = iota Radial )
type Matrix ¶
type Matrix struct{ A, B, C, D, E, F float32 }
Matrix is a 2D affine transform: a point x, y becomes A*x + C*y + E, B*x + D*y + F (the SVG and canvas matrix(a b c d e f)).
func Translate ¶
Translate, Scale and Rotate return the transforms that move by x, y, scale by sx, sy and rotate by angle radians (clockwise on screen).
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path is a sequence of subpaths made of lines and Bézier curves. The zero value is an empty path.
func (*Path) Arc ¶
Arc adds an arc of the circle centered on cx, cy, of radius r, from angle a0 to a1 in radians (0 is to the right, angles grow clockwise on screen), counterclockwise when ccw is set. As in the HTML canvas, a line joins the current point to the arc's start, and a sweep of a full turn or more draws the whole circle.
func (*Path) ArcTo ¶
ArcTo adds an elliptical arc to x, y, as the SVG path command A does: radii rx, ry, the ellipse rotated by rotation degrees, and the flags that pick one of the four arcs that join the points.
func (*Path) Bounds ¶
Bounds returns the box of the path's points, control points included, and false for an empty path.
func (*Path) QuadTo ¶
QuadTo adds a quadratic Bézier curve through the control point cx, cy to x, y.
type Stroke ¶
type Stroke struct {
Width float32
Cap Cap
Join Join
// MiterLimit is the longest miter, as a multiple of the width, before a
// miter join becomes a bevel; 0 means 4, as in SVG.
MiterLimit float32
// Dash alternates the lengths of dashes and gaps; empty draws a solid line.
// DashOffset is how far into the pattern the stroke starts.
Dash []float32
DashOffset float32
}
Stroke describes how a path's outline is drawn.