rasterx

package module
v0.0.0-...-108a568 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

README

rasterx

Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing.

  • Paths can be explicity closed or left open, resulting in a line join or end caps.
  • Arc joins are supported, which causes the extending edge from a Bezier curve to follow the radius of curvature at the end point rather than a straight line miter, resulting in a more fliud looking join.
  • Not specified in the SVG2.0 spec., but supported in rasterx is the arc-clip join, which is the arc join analog of a miter-clip join, both of which end the miter at a specified distance, rather than all or nothing.
  • Several cap and gap functions in addition to those specified by SVG2.0 are implemented, specifically quad and cubic caps and gaps.
  • Line start and end capping functions can be different.

rasterx example

The above image shows the effect of using different join modes for a stroked curving path. The top stroked path uses miter (green) or arc (red, yellow, orange) join functions with high miter limit. The middle and lower path shows the effect of using the miter-clip and arc-clip joins, repectively, with different miter-limit values. The black chevrons at the top show different cap and gap functions.

Scanner interface

Rasterx takes the path description of lines, bezier curves, and drawing parameters, and converts them into a set of straight line segments before rasterizing the lines to an image using some method of antialiasing. Rasterx abstracts this last step through the Scanner interface. There are two different structs that satisfy the Scanner interface; ScannerGV and ScannerFT. ScannerGV wraps the rasterizer found in the golang.org/x/image/vector package. ScannerFT contains a modified version of the antialiaser found in the golang freetype translation. These use different functions to connect an image to the antialiaser. ScannerFT uses a Painter to translate the raster onto the image, and ScannerGV uses the vector's Draw method with a source image and uses the path as an alpha mask. Please see the test files for examples. At this time, the ScannerFT is a bit faster as compared to ScannerGV for larger and less complicated images, while ScannerGV can be faster for smaller and more complex images. Also ScannerGV does not allow for using the even-odd winding rule, which is something the SVG specification uses. Since ScannerFT is subject to freetype style licensing rules, it lives here in a separate repository and must be imported into your project seperately. ScannerGV is included in the rasterx package, and has more go-friendly licensing.

Below are the results of some benchmarks performed on a sample shape (the letter Q ). The first test is the time it takes to scan the image after all the curves have been flattened. The second test is the time it takes to flatten, and scan a simple filled image. The last test is the time it takes to flatten a stroked and dashed outline of the shape and scan it. Results for three different image sizes are shown.

128x128 Image
Test                        Rep       Time
BenchmarkScanGV-16          5000      287180 ns/op
BenchmarkFillGV-16          5000      339831 ns/op
BenchmarkDashGV-16          2000      968265 ns/op

BenchmarkScanFT-16    	   20000       88118 ns/op
BenchmarkFillFT-16    	    5000      214370 ns/op
BenchmarkDashFT-16    	    1000     2063797 ns/op

256x256 Image
Test                        Rep       Time
BenchmarkScanGV-16          2000     1188452 ns/op
BenchmarkFillGV-16          1000     1277268 ns/op
BenchmarkDashGV-16          500      2238169 ns/op

BenchmarkScanFT-16    	    5000      290685 ns/op
BenchmarkFillFT-16    	    3000      446329 ns/op
BenchmarkDashFT-16    	     500     2923512 ns/op

512x512 Image
Test                        Rep       Time
BenchmarkScanGV-16           500     3341038 ns/op
BenchmarkFillGV-16           500     4032213 ns/op
BenchmarkDashGV-16           200     6003355 ns/op

BenchmarkScanFT-16    	    5000      292884 ns/op
BenchmarkFillFT-16    	    3000      449582 ns/op
BenchmarkDashFT-16    	     500     2800493 ns/op

The package uses an interface called Rasterx, which is satisfied by three structs, Filler, Stroker and Dasher. The Filler flattens Bezier curves into lines and uses an anonymously composed Scanner for the antialiasing step. The Stroker embeds a Filler and adds path stroking, and the Dasher embedds a Stroker and adds the ability to create dashed stroked curves.

rasterx Scheme

Each of the Filler, Dasher, and Stroker can function on their own and each implement the Rasterx interface, so if you need just the curve filling but no stroking capability, you only need a Filler. On the other hand if you have created a Dasher and want to use it to Fill, you can just do this:

filler := &dasher.Filler

Now filler is a filling rasterizer. Please see rasterx_test.go for examples.

Non-standard library dependencies

rasterx requires the following imports which are not included in the go standard library:

  • golang.org/x/image/math/fixed
  • golang.org/x/image/vector

These can be included in your gopath by the following 'get' commands:

  • "go get golang.org/x/image/vector"
  • "go get golang.org/x/image/math/fixed"

If you want to use the freetype style antialiaser, 'go get' or clone into your workspace the scanFT package:

  • github.com/srwiley/scanFT

Documentation

Overview

Package rasterx implements a rasterizer in go. By default rasterx uses ScannerGV to render images which uses the rasterizer in the golang.org/x/image/vector package. The freetype rasterizer under the GNU license can also be used, by downloading the scanFT package.

Copyright 2018 All rights reserved. Created: 5/12/2018 by S.R.Wiley

Index

Constants

View Source
const MaxDx float64 = math.Pi / 8

MaxDx is the Maximum radians a cubic splice is allowed to span in ellipse parametric when approximating an off-axis ellipse.

Variables

View Source
var (
	// ButtCap caps lines with a straight line
	ButtCap CapFunc = func(p Adder, a, eNorm fixed.Point26_6) {
		p.Start(a.Add(eNorm))
		p.Line(a.Sub(eNorm))
	}
	// SquareCap caps lines with a square which is slightly longer than ButtCap
	SquareCap CapFunc = func(p Adder, a, eNorm fixed.Point26_6) {
		tpt := a.Add(turnStarboard90(eNorm))
		p.Start(a.Add(eNorm))
		p.Line(tpt.Add(eNorm))
		p.Line(tpt.Sub(eNorm))
		p.Line(a.Sub(eNorm))
	}
	// RoundCap caps lines with a half-circle
	RoundCap CapFunc = func(p Adder, a, eNorm fixed.Point26_6) {
		GapToCap(p, a, eNorm, RoundGap)
	}
	// CubicCap caps lines with a cubic bezier
	CubicCap CapFunc = func(p Adder, a, eNorm fixed.Point26_6) {
		GapToCap(p, a, eNorm, CubicGap)
	}
	// QuadraticCap caps lines with a quadratic bezier
	QuadraticCap CapFunc = func(p Adder, a, eNorm fixed.Point26_6) {
		GapToCap(p, a, eNorm, QuadraticGap)
	}

	//FlatGap bridges miter-limit gaps with a straight line
	FlatGap GapFunc = func(p Adder, a, tNorm, lNorm fixed.Point26_6) {
		p.Line(a.Add(lNorm))
	}
	// RoundGap bridges miter-limit gaps with a circular arc
	RoundGap GapFunc = func(p Adder, a, tNorm, lNorm fixed.Point26_6) {
		strokeArc(p, a, a.Add(tNorm), a.Add(lNorm), true, 0, 0, p.Line)
		p.Line(a.Add(lNorm))

	}
	// CubicGap bridges miter-limit gaps with a cubic bezier
	CubicGap GapFunc = func(p Adder, a, tNorm, lNorm fixed.Point26_6) {
		p.CubeBezier(a.Add(tNorm).Add(turnStarboard90(tNorm)), a.Add(lNorm).Add(turnPort90(lNorm)), a.Add(lNorm))
	}
	// QuadraticGap bridges miter-limit gaps with a quadratic bezier
	QuadraticGap GapFunc = func(p Adder, a, tNorm, lNorm fixed.Point26_6) {
		c1, c2 := a.Add(tNorm).Add(turnStarboard90(tNorm)), a.Add(lNorm).Add(turnPort90(lNorm))
		cm := c1.Add(c2).Mul(fixed.Int26_6(1 << 5))
		p.QuadBezier(cm, a.Add(lNorm))
	}
)
View Source
var Identity = Matrix2D{1, 0, 0, 1, 0, 0}

Identity is the identity matrix

Functions

func AddArc

func AddArc(points []float64, cx, cy, px, py float64, p Adder) (lx, ly float64)

AddArc adds an arc to the adder p

func AddCircle

func AddCircle(cx, cy, r float64, p Adder)

AddCircle adds a circle to the Adder p

func AddEllipse

func AddEllipse(cx, cy, rx, ry, rot float64, p Adder)

AddEllipse adds an elipse with center at cx,cy, with the indicated x and y radius, (rx, ry), rotated around the center by rot degrees.

func AddRect

func AddRect(minX, minY, maxX, maxY, rot float64, p Adder)

AddRect adds a rectangle of the indicated size, rotated around the center by rot degrees.

func AddRoundRect

func AddRoundRect(minX, minY, maxX, maxY, rx, ry, rot float64, gf GapFunc, p Adder)

AddRoundRect adds a rectangle of the indicated size, rotated around the center by rot degrees with rounded corners of radius rx in the x axis and ry in the y axis. gf specifes the shape of the filleting function. Valid values are RoundGap, QuadraticGap, CubicGap, FlatGap, or nil which defaults to a flat gap.

func ApplyOpacity

func ApplyOpacity(c color.Color, opacity float64) color.NRGBA

ApplyOpacity sets the color's alpha channel to the given value

func CalcIntersect

func CalcIntersect(a1, a2, b1, b2 fixed.Point26_6) (x fixed.Point26_6)

CalcIntersect calculates the points of intersection of two fixed point lines and panics if the determinate is zero. You have been warned.

func CircleCircleIntersection

func CircleCircleIntersection(ct, cl fixed.Point26_6, rt, rl fixed.Int26_6) (xt1, xt2 fixed.Point26_6, intersects bool)

CircleCircleIntersection calculates the points of intersection of two circles or returns with intersects == false if no such points exist.

func ClosestPortside

func ClosestPortside(bow, stern, p1, p2 fixed.Point26_6, isIntersecting bool) (xt fixed.Point26_6, intersects bool)

ClosestPortside returns the closest of p1 or p2 on the port side of the line from the bow to the stern. (port means left side of the direction you are heading) isIntersecting is just convienice to reduce code, and if false returns false, because p1 and p2 are not valid

func CubeTo

func CubeTo(ax, ay, bx, by, cx, cy, dx, dy float32, LineTo func(ex, ey float32))

CubeTo flattens the cubic Bezier curve into lines through the LineTo func This functions is adapted from the version found in golang.org/x/image/vector

func DotProd

DotProd returns the inner product of p and q

func FindEllipseCenter

func FindEllipseCenter(ra, rb *float64, rotX, startX, startY, endX, endY float64, sweep, smallArc bool) (cx, cy float64)

FindEllipseCenter locates the center of the Ellipse if it exists. If it does not exist, the radius values will be increased minimally for a solution to be possible while preserving the ra to rb ratio. ra and rb arguments are pointers that can be checked after the call to see if the values changed. This method uses coordinate transformations to reduce the problem to finding the center of a circle that includes the origin and an arbitrary point. The center of the circle is then transformed back to the original coordinates and returned.

func GapToCap

func GapToCap(p Adder, a, eNorm fixed.Point26_6, gf GapFunc)

GapToCap is a utility that converts a CapFunc to GapFunc

func Invert

func Invert(v fixed.Point26_6) fixed.Point26_6

Invert returns the point inverted around the origin

func Length

func Length(v fixed.Point26_6) fixed.Int26_6

Length is the distance from the origin of the point

func QuadTo

func QuadTo(ax, ay, bx, by, cx, cy float32, LineTo func(dx, dy float32))

QuadTo flattens the quadratic Bezier curve into lines through the LineTo func This functions is adapted from the version found in golang.org/x/image/vector

func RadCurvature

func RadCurvature(p0, p1, p2 fixed.Point26_6, dm fixed.Int52_12) fixed.Int26_6

RadCurvature returns the curvature of a Bezier curve end point, given an end point, the two adjacent control points and the degree. The sign of the value indicates if the center of the osculating circle is left or right (port or starboard) of the curve in the forward direction.

func RayCircleIntersection

func RayCircleIntersection(s1, s2, c fixed.Point26_6, r fixed.Int26_6) (x fixed.Point26_6, intersects bool)

RayCircleIntersection calculates the points of intersection of a ray starting at s2 passing through s1 and a circle in fixed point. Returns intersects == false if no solution is possible. If two solutions are possible, the point closest to s2 is returned

func RayCircleIntersectionF

func RayCircleIntersectionF(s1X, s1Y, s2X, s2Y, cX, cY, r float64) (x, y float64, intersects bool)

RayCircleIntersectionF calculates in floating point the points of intersection of a ray starting at s2 passing through s1 and a circle in fixed point. Returns intersects == false if no solution is possible. If two solutions are possible, the point closest to s2 is returned

func ToFixedP

func ToFixedP(x, y float64) (p fixed.Point26_6)

ToFixedP converts two floats to a fixed point.

func ToLength

func ToLength(p fixed.Point26_6, ln fixed.Int26_6) (q fixed.Point26_6)

ToLength scales the point to the length indicated by ln

Types

type Adder

type Adder interface {
	// Start starts a new curve at the given point.
	Start(a fixed.Point26_6)
	// Line adds a line segment to the path
	Line(b fixed.Point26_6)
	// QuadBezier adds a quadratic bezier curve to the path
	QuadBezier(b, c fixed.Point26_6)
	// CubeBezier adds a cubic bezier curve to the path
	CubeBezier(b, c, d fixed.Point26_6)
	// Closes the path to the start point if closeLoop is true
	Stop(closeLoop bool)
}

Adder interface for types that can accumlate path commands

type C2Point

type C2Point struct {
	P, TTan, LTan, TNorm, LNorm fixed.Point26_6
	RT, RL                      fixed.Int26_6
}

C2Point represents a point that connects two stroke segments and holds the tangent, normal and radius of curvature of the trailing and leading segments in fixed point values.

type CapFunc

type CapFunc func(p Adder, a, eNorm fixed.Point26_6)

CapFunc defines a function that draws caps on the ends of lines

type ClipImage

type ClipImage struct {
	ColorFuncImage
	// contains filtered or unexported fields
}

ClipImage is a clipable ColorFuncImage

func (*ClipImage) At

func (c *ClipImage) At(x, y int) color.Color

At returns the color of the ClipImage at the point x,y

type ColorFunc

type ColorFunc func(x, y int) color.Color

ColorFunc maps a color to x y coordinates

type ColorFuncImage

type ColorFuncImage struct {
	image.Uniform
	// contains filtered or unexported fields
}

ColorFuncImage implements and image using the provided colorFunc

func (*ColorFuncImage) At

func (c *ColorFuncImage) At(x, y int) color.Color

At returns the color at the point x,y

type Dasher

type Dasher struct {
	Stroker
	Dashes []fixed.Int26_6

	DashOffset fixed.Int26_6
	// contains filtered or unexported fields
}

Dasher struct extends the Stroker and can draw dashed lines with end capping

func NewDasher

func NewDasher(width, height int, scanner Scanner) *Dasher

NewDasher returns a Dasher ptr with default values. A Dasher has all of the capabilities of a Stroker, Filler, and Scanner, plus the ability to stroke curves with solid lines. Use SetStroke to configure with non-default values.

func (*Dasher) CubeBezier

func (r *Dasher) CubeBezier(b, c, d fixed.Point26_6)

CubeBezier starts a stroked cubic bezier. It is a low level function exposed for the purposes of callbacks and debugging.

func (*Dasher) Line

func (r *Dasher) Line(b fixed.Point26_6)

Line for Dasher is here to pass the dasher sgm to LineP

func (*Dasher) QuadBezier

func (r *Dasher) QuadBezier(b, c fixed.Point26_6)

QuadBezier for dashing

func (*Dasher) SetStroke

func (r *Dasher) SetStroke(width, miterLimit fixed.Int26_6, capL, capT CapFunc, gp GapFunc, jm JoinMode, dashes []float64, dashOffset float64)

SetStroke set the parameters for stroking a line. width is the width of the line, miterlimit is the miter cutoff value for miter, arc, miterclip and arcClip joinModes. CapL and CapT are the capping functions for leading and trailing line ends. If one is nil, the other function is used at both ends. gp is the gap function that determines how a gap on the convex side of two lines joining is filled. jm is the JoinMode for curve segments. Dashes is the values for the dash pattern. Pass in nil or an empty slice for no dashes. dashoffset is the starting offset into the dash array.

func (*Dasher) Start

func (r *Dasher) Start(a fixed.Point26_6)

Start starts a dashed line

func (*Dasher) Stop

func (r *Dasher) Stop(isClosed bool)

Stop terminates a dashed line

type Filler

type Filler struct {
	Scanner
	// contains filtered or unexported fields
}

Filler satisfies Rasterx

func NewFiller

func NewFiller(width, height int, scanner Scanner) *Filler

NewFiller returns a Filler ptr with default values. A Filler in addition to rasterizing lines like a Scann, can also rasterize quadratic and cubic bezier curves. If Scanner is nil default scanner ScannerGV is used

func (*Filler) Clear

func (r *Filler) Clear()

Clear resets the filler

func (*Filler) CubeBezier

func (r *Filler) CubeBezier(b, c, d fixed.Point26_6)

CubeBezier adds a cubic bezier to the curve

func (*Filler) CubeBezierF

func (r *Filler) CubeBezierF(sgm Rasterx, b, c, d fixed.Point26_6)

CubeBezierF adds a cubic bezier to the curve. sending the line calls the the sgm Rasterizer

func (*Filler) Line

func (r *Filler) Line(b fixed.Point26_6)

Line for a filling rasterizer is just the line call in scan

func (*Filler) QuadBezier

func (r *Filler) QuadBezier(b, c fixed.Point26_6)

QuadBezier adds a quadratic segment to the current curve.

func (*Filler) QuadBezierF

func (r *Filler) QuadBezierF(sgm Rasterx, b, c fixed.Point26_6)

QuadBezierF adds a quadratic segment to the sgm Rasterizer.

func (*Filler) SetBounds

func (r *Filler) SetBounds(width, height int)

SetBounds sets the maximum width and height of the rasterized image and calls Clear. The width and height are in pixels, not fixed.Int26_6 units.

func (*Filler) Start

func (r *Filler) Start(a fixed.Point26_6)

Start starts a new path at the given point.

func (*Filler) Stop

func (r *Filler) Stop(isClosed bool)

Stop sends a path at the given point.

type GapFunc

type GapFunc func(p Adder, a, tNorm, lNorm fixed.Point26_6)

GapFunc defines a function to bridge gaps when the miter limit is exceeded

type GradStop

type GradStop struct {
	StopColor color.Color
	Offset    float64
	Opacity   float64
}

GradStop represents a stop in the SVG 2.0 gradient specification

type Gradient

type Gradient struct {
	Points   [5]float64
	Stops    []GradStop
	Bounds   struct{ X, Y, W, H float64 }
	Matrix   Matrix2D
	Spread   SpreadMethod
	Units    GradientUnits
	IsRadial bool
}

Gradient holds a description of an SVG 2.0 gradient

func (*Gradient) GetColorFunction

func (g *Gradient) GetColorFunction(opacity float64) interface{}

GetColorFunction returns the color function

func (*Gradient) GetColorFunctionUS

func (g *Gradient) GetColorFunctionUS(opacity float64, objMatrix Matrix2D) interface{}

GetColorFunctionUS returns the color function using the User Space objMatrix

type GradientUnits

type GradientUnits byte

GradientUnits is the type for gradient units

const (
	ObjectBoundingBox GradientUnits = iota
	UserSpaceOnUse
)

SVG bounds paremater constants

type JoinMode

type JoinMode uint8

JoinMode type to specify how segments join.

const (
	Arc JoinMode = iota
	ArcClip
	Miter
	MiterClip
	Bevel
	Round
)

JoinMode constants determine how stroke segments bridge the gap at a join ArcClip mode is like MiterClip applied to arcs, and is not part of the SVG2.0 standard.

type Matrix2D

type Matrix2D struct {
	A, B, C, D, E, F float64
}

Matrix2D represents an SVG style matrix

func (Matrix2D) Invert

func (a Matrix2D) Invert() Matrix2D

Invert returns the inverse matrix

func (Matrix2D) Mult

func (a Matrix2D) Mult(b Matrix2D) Matrix2D

Mult returns a*b

func (Matrix2D) Rotate

func (a Matrix2D) Rotate(theta float64) Matrix2D

Rotate rotate the matrix by theta

func (Matrix2D) Scale

func (a Matrix2D) Scale(x, y float64) Matrix2D

Scale matrix in x and y dimensions

func (Matrix2D) SkewX

func (a Matrix2D) SkewX(theta float64) Matrix2D

SkewX skews the matrix in the X dimension

func (Matrix2D) SkewY

func (a Matrix2D) SkewY(theta float64) Matrix2D

SkewY skews the matrix in the Y dimension

func (Matrix2D) TFixed

func (a Matrix2D) TFixed(x fixed.Point26_6) (y fixed.Point26_6)

TFixed transforms a fixed.Point26_6 by the matrix

func (Matrix2D) Transform

func (a Matrix2D) Transform(x1, y1 float64) (x2, y2 float64)

Transform multiples the input vector by matrix m and outputs the results vector components.

func (Matrix2D) TransformVector

func (a Matrix2D) TransformVector(x1, y1 float64) (x2, y2 float64)

TransformVector is a modidifed version of Transform that ignores the translation components.

func (Matrix2D) Translate

func (a Matrix2D) Translate(x, y float64) Matrix2D

Translate translates the matrix to the x , y point

type MatrixAdder

type MatrixAdder struct {
	Adder
	M Matrix2D
}

MatrixAdder is an adder that applies matrix M to all points

func (*MatrixAdder) CubeBezier

func (t *MatrixAdder) CubeBezier(b, c, d fixed.Point26_6)

CubeBezier adds a cubic segment to the current curve.

func (*MatrixAdder) Line

func (t *MatrixAdder) Line(b fixed.Point26_6)

Line adds a linear segment to the current curve.

func (*MatrixAdder) QuadBezier

func (t *MatrixAdder) QuadBezier(b, c fixed.Point26_6)

QuadBezier adds a quadratic segment to the current curve.

func (*MatrixAdder) Reset

func (t *MatrixAdder) Reset()

Reset sets the matrix M to identity

func (*MatrixAdder) Start

func (t *MatrixAdder) Start(a fixed.Point26_6)

Start starts a new path

type Path

type Path []fixed.Int26_6

A Path starts with a PathCommand value followed by zero to three fixed int points.

func (Path) AddTo

func (p Path) AddTo(q Adder)

AddTo adds the Path p to q.

func (*Path) Clear

func (p *Path) Clear()

Clear zeros the path slice

func (*Path) CubeBezier

func (p *Path) CubeBezier(b, c, d fixed.Point26_6)

CubeBezier adds a cubic segment to the current curve.

func (*Path) Line

func (p *Path) Line(b fixed.Point26_6)

Line adds a linear segment to the current curve.

func (*Path) QuadBezier

func (p *Path) QuadBezier(b, c fixed.Point26_6)

QuadBezier adds a quadratic segment to the current curve.

func (*Path) Start

func (p *Path) Start(a fixed.Point26_6)

Start starts a new curve at the given point.

func (*Path) Stop

func (p *Path) Stop(closeLoop bool)

Stop joins the ends of the path

func (Path) String

func (p Path) String() string

String returns a readable representation of a Path.

func (Path) ToSVGPath

func (p Path) ToSVGPath() string

ToSVGPath returns a string representation of the path

type PathCommand

type PathCommand fixed.Int26_6

PathCommand is the type for the path command token

const (
	PathMoveTo PathCommand = iota
	PathLineTo
	PathQuadTo
	PathCubicTo
	PathClose
)

Human readable path constants

type Rasterx

type Rasterx interface {
	Adder
	// contains filtered or unexported methods
}

Rasterx extends the adder interface to include lineF and joinF functions

type Scanner

type Scanner interface {
	Start(a fixed.Point26_6)
	Line(b fixed.Point26_6)
	Draw()
	GetPathExtent() fixed.Rectangle26_6
	SetBounds(w, h int)
	SetColor(color interface{})
	SetWinding(useNonZeroWinding bool)
	Clear()

	// SetClip sets an optional clipping rectangle to restrict rendering
	// only to that region -- if size is 0 then ignored (set to image.ZR
	// to clear)
	SetClip(rect image.Rectangle)
}

Scanner interface for path generating types

type ScannerGV

type ScannerGV struct {

	//a, first fixed.Point26_6
	Dest draw.Image
	Targ image.Rectangle

	Source image.Image
	Offset image.Point
	// contains filtered or unexported fields
}

ScannerGV uses the google vector rasterizer

func NewScannerGV

func NewScannerGV(width, height int, dest draw.Image,
	targ image.Rectangle) *ScannerGV

NewScannerGV creates a new Scanner with the given bounds.

func (*ScannerGV) Clear

func (s *ScannerGV) Clear()

Clear cancels any previous accumulated scans

func (*ScannerGV) Draw

func (s *ScannerGV) Draw()

Draw renders the accumulate scan to the desination

func (*ScannerGV) GetPathExtent

func (s *ScannerGV) GetPathExtent() fixed.Rectangle26_6

GetPathExtent returns the extent of the path

func (*ScannerGV) Line

func (s *ScannerGV) Line(b fixed.Point26_6)

Line adds a linear segment to the current curve.

func (*ScannerGV) SetBounds

func (s *ScannerGV) SetBounds(width, height int)

SetBounds sets the maximum width and height of the rasterized image and calls Clear. The width and height are in pixels, not fixed.Int26_6 units.

func (*ScannerGV) SetClip

func (s *ScannerGV) SetClip(rect image.Rectangle)

SetClip sets an optional clipping rectangle to restrict rendering only to that region -- if size is 0 then ignored (set to image.ZR to clear)

func (*ScannerGV) SetColor

func (s *ScannerGV) SetColor(clr interface{})

SetColor set the color type for the scanner

func (*ScannerGV) SetWinding

func (s *ScannerGV) SetWinding(useNonZeroWinding bool)

SetWinding set the winding rule for the scanner

func (*ScannerGV) Start

func (s *ScannerGV) Start(a fixed.Point26_6)

Start starts a new path at the given point.

type SpreadMethod

type SpreadMethod byte

SpreadMethod is the type for spread parameters

const (
	PadSpread SpreadMethod = iota
	ReflectSpread
	RepeatSpread
)

SVG spread parameter constants

type Stroker

type Stroker struct {
	Filler
	CapT, CapL CapFunc // Trailing and leading cap funcs may be set separately
	JoinGap    GapFunc // When gap appears between segments, this function is called

	JoinMode JoinMode
	// contains filtered or unexported fields
}

Stroker does everything a Filler does, but also allows for stroking and dashed stroking in addition to filling

func NewStroker

func NewStroker(width, height int, scanner Scanner) *Stroker

NewStroker returns a ptr to a Stroker with default values. A Stroker has all of the capabilities of a Filler and Scanner, plus the ability to stroke curves with solid lines. Use SetStroke to configure with non-default values.

func (*Stroker) CalcEndCurvature

func (r *Stroker) CalcEndCurvature(p0, p1, p2, q0, q1, q2 fixed.Point26_6,
	dm fixed.Int52_12, calcRadCuve bool)

CalcEndCurvature calculates the radius of curvature given the control points of a bezier curve. It is a low level function exposed for the purposes of callbacks and debugging.

func (*Stroker) CubeBezier

func (r *Stroker) CubeBezier(b, c, d fixed.Point26_6)

CubeBezier starts a stroked quadratic bezier.

func (*Stroker) Joiner

func (r *Stroker) Joiner(p C2Point)

Joiner is called when two segments of a stroke are joined. it is exposed so that if can be wrapped to generate callbacks for the join points.

func (*Stroker) Line

func (r *Stroker) Line(b fixed.Point26_6)

Line adds a line segment to the rasterizer

func (*Stroker) LineSeg

func (r *Stroker) LineSeg(sgm Rasterx, b fixed.Point26_6)

LineSeg is called by both the Stroker and Dasher

func (*Stroker) QuadBezier

func (r *Stroker) QuadBezier(b, c fixed.Point26_6)

QuadBezier starts a stroked quadratic bezier.

func (*Stroker) SetStroke

func (r *Stroker) SetStroke(width, miterLimit fixed.Int26_6, capL, capT CapFunc, gp GapFunc, jm JoinMode)

SetStroke set the parameters for stroking a line. width is the width of the line, miterlimit is the miter cutoff value for miter, arc, miterclip and arcClip joinModes. CapL and CapT are the capping functions for leading and trailing line ends. If one is nil, the other function is used at both ends. If both are nil, both ends are ButtCapped. gp is the gap function that determines how a gap on the convex side of two joining lines is filled. jm is the JoinMode for curve segments.

func (*Stroker) Start

func (r *Stroker) Start(a fixed.Point26_6)

Start iniitates a stroked path

func (*Stroker) Stop

func (r *Stroker) Stop(isClosed bool)

Stop a stroked line. The line will close is isClosed is true. Otherwise end caps will be drawn at both ends.

Jump to

Keyboard shortcuts

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