draw2d

package module
v0.0.0-...-994e11c Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2015 License: BSD-2-Clause Imports: 15 Imported by: 0

README

draw2d

Package draw2d is a pure go 2D vector graphics library with support for multiple output devices such as images (draw2d), pdf documents (draw2dpdf) and opengl (draw2dgl), which can also be used on the google app engine. It can be used as a pure go Cairo alternative. draw2d is released under the BSD license. See the documentation for more details.

geometrypostscript

Click on an image above to get the pdf, generated with exactly the same draw2d code. The first image is the output of samples/geometry. The second image is the result of samples/postcript, which demonstrates that draw2d can draw postscript files into images or pdf documents with the ps package.

Features

Operations in draw2d include stroking and filling polygons, arcs, Bézier curves, drawing images and text rendering with truetype fonts. All drawing operations can be transformed by affine transformations (scale, rotation, translation).

Package draw2d follows the conventions of the HTML Canvas 2D Context for coordinate system, angles, etc...

Installation

Install golang. To install or update the package draw2d on your system, run:

go get -u github.com/llgcode/draw2d

Quick Start

The following Go code generates a simple drawing and saves it to an image file with package draw2d:

// Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2d.NewGraphicContext(dest)

// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)

// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()

// Save to file
draw2d.SaveToPngFile("hello.png", dest)

The same Go code can also generate a pdf document with package draw2dpdf:

// Initialize the graphic context on an RGBA image
dest := draw2dpdf.NewPdf("L", "mm", "A4")
gc := draw2d.NewGraphicContext(dest)

// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)

// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()

// Save to file
draw2dpdf.SaveToPdfFile("hello.pdf", dest)

There are more examples here: https://github.com/llgcode/draw2d/tree/master/samples

Drawing on opengl is provided by the draw2dgl package.

Testing

The samples are run as tests from the root package folder draw2d by:

go test ./...

Or if you want to run with test coverage:

go test -cover ./... | grep -v "no test"

This will generate output by the different backends in the output folder.

Acknowledgments

Laurent Le Goff wrote this library, inspired by Postscript and HTML5 canvas. He implemented the image and opengl backend with the freetype-go package. Also he created a pure go Postscript interpreter, which can read postscript images and draw to a draw2d graphic context. Stani Michiels implemented the pdf backend with the gofpdf package.

Packages using draw2d

  • ps: Postscript interpreter written in Go
  • gonum/plot: drawing plots in Go
  • go.uik: a concurrent UI kit written in pure go.
  • smartcrop: content aware image cropping
  • karta: drawing Voronoi diagrams
  • chart: basic charts in Go

References

Documentation

Overview

Package draw2d is a pure go 2D vector graphics library with support for multiple output devices such as images (draw2d), pdf documents (draw2dpdf) and opengl (draw2dgl), which can also be used on the google app engine. It can be used as a pure go Cairo alternative. draw2d is released under the BSD license.

Features

Operations in draw2d include stroking and filling polygons, arcs, Bézier curves, drawing images and text rendering with truetype fonts. All drawing operations can be transformed by affine transformations (scale, rotation, translation).

Package draw2d follows the conventions of http://www.w3.org/TR/2dcontext for coordinate system, angles, etc...

Installation

To install or update the package draw2d on your system, run:

go get -u github.com/llgcode/draw2d

Quick Start

Package draw2d itself provides a graphic context that can draw vector graphics and text on an image canvas. The following Go code generates a simple drawing and saves it to an image file:

// Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2d.NewGraphicContext(dest)

// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)

// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()

// Save to file
draw2d.SaveToPngFile("hello.png", dest)

There are more examples here: https://github.com/llgcode/draw2d/tree/master/samples

Drawing on pdf documents is provided by the draw2dpdf package. Drawing on opengl is provided by the draw2dgl package. See subdirectories at the bottom of this page.

Testing

The samples are run as tests from the root package folder `draw2d` by:

go test ./...

Or if you want to run with test coverage:

go test -cover ./... | grep -v "no test"

This will generate output by the different backends in the output folder.

Acknowledgments

Laurent Le Goff wrote this library, inspired by Postscript and HTML5 canvas. He implemented the image and opengl backend with the freetype-go package. Also he created a pure go Postscript interpreter, which can read postscript images and draw to a draw2d graphic context (https://github.com/llgcode/ps). Stani Michiels implemented the pdf backend with the gofpdf package.

Packages using draw2d

- https://github.com/llgcode/ps: Postscript interpreter written in Go

- https://github.com/gonum/plot: drawing plots in Go

- https://github.com/muesli/smartcrop: content aware image cropping

- https://github.com/peterhellberg/karta: drawing Voronoi diagrams

- https://github.com/vdobler/chart: basic charts in Go

Index

Constants

View Source
const M = 1<<16 - 1

Variables

View Source
var (
	CurveRecursionLimit        = 32
	CurveCollinearityEpsilon   = 1e-30
	CurveAngleToleranceEpsilon = 0.01
)

Functions

func Circle

func Circle(path Path, cx, cy, radius float64)

Circle is drawn with center (cx,cy) and radius

func DrawImage

func DrawImage(src image.Image, dest draw.Image, tr MatrixTransform, op draw.Op, filter ImageFilter)

DrawImage draws a source image on an destination image.

func Ellipse

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

Ellipse is drawn with center (cx,cy) and radius (rx,ry)

func FontFileName

func FontFileName(fontData FontData) string

func GetFont

func GetFont(fontData FontData) *truetype.Font

func GetFontFolder

func GetFontFolder() string

func LoadFromPngFile

func LoadFromPngFile(filePath string) (image.Image, error)

LoadFromPngFile Open a png file

func Rect

func Rect(path Path, x1, y1, x2, y2 float64)

Rect draws a rectangle between (x1,y1) and (x2,y2)

func RegisterFont

func RegisterFont(fontData FontData, font *truetype.Font)

func RoundRect

func RoundRect(path Path, x1, y1, x2, y2, arcWidth, arcHeight float64)

RoundRect draws a rectangle between (x1,y1) and (x2,y2) with rounded corners

func SaveToPngFile

func SaveToPngFile(filePath string, m image.Image) error

SaveToPngFile create and save an image to a file using PNG format

func SetFontFolder

func SetFontFolder(folder string)

Types

type Cap

type Cap int
const (
	RoundCap Cap = iota
	ButtCap
	SquareCap
)

func (Cap) Convert

func (c Cap) Convert() raster.Capper

type ContextStack

type ContextStack struct {
	Tr          MatrixTransform
	Path        *PathStorage
	LineWidth   float64
	Dash        []float64
	DashOffset  float64
	StrokeColor color.Color
	FillColor   color.Color
	FillRule    FillRule
	Cap         Cap
	Join        Join
	FontSize    float64
	FontData    FontData

	Font *truetype.Font
	// fontSize and dpi are used to calculate scale. scale is the number of
	// 26.6 fixed point units in 1 em.
	Scale float64
	// contains filtered or unexported fields
}

type DashVertexConverter

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

func NewDashConverter

func NewDashConverter(dash []float64, dashOffset float64, converter VertexConverter) *DashVertexConverter

func (*DashVertexConverter) NextCommand

func (dasher *DashVertexConverter) NextCommand(cmd VertexCommand)

func (*DashVertexConverter) Vertex

func (dasher *DashVertexConverter) Vertex(x, y float64)

type DemuxConverter

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

func NewDemuxConverter

func NewDemuxConverter(converters ...VertexConverter) *DemuxConverter

func (*DemuxConverter) NextCommand

func (dc *DemuxConverter) NextCommand(cmd VertexCommand)

func (*DemuxConverter) Vertex

func (dc *DemuxConverter) Vertex(x, y float64)

type FillRule

type FillRule int

FillRule defines the type for fill rules

const (
	// FillRuleEvenOdd defines the even odd filling rule
	FillRuleEvenOdd FillRule = iota
	// FillRuleWinding defines the non zero winding rule
	FillRuleWinding
)

func (FillRule) UseNonZeroWinding

func (f FillRule) UseNonZeroWinding() bool

type FontData

type FontData struct {
	Name   string
	Family FontFamily
	Style  FontStyle
}

type FontFamily

type FontFamily byte
const (
	FontFamilySans FontFamily = iota
	FontFamilySerif
	FontFamilyMono
)

type FontStyle

type FontStyle byte
const (
	FontStyleNormal FontStyle = iota
	FontStyleBold
	FontStyleItalic
)

type GraphicContext

type GraphicContext interface {
	Path
	// Create a new path
	BeginPath()
	GetMatrixTransform() MatrixTransform
	SetMatrixTransform(tr MatrixTransform)
	ComposeMatrixTransform(tr MatrixTransform)
	Rotate(angle float64)
	Translate(tx, ty float64)
	Scale(sx, sy float64)
	SetStrokeColor(c color.Color)
	SetFillColor(c color.Color)
	SetFillRule(f FillRule)
	SetLineWidth(lineWidth float64)
	SetLineCap(cap Cap)
	SetLineJoin(join Join)
	SetLineDash(dash []float64, dashOffset float64)
	SetFontSize(fontSize float64)
	GetFontSize() float64
	SetFontData(fontData FontData)
	GetFontData() FontData
	DrawImage(image image.Image)
	Save()
	Restore()
	Clear()
	ClearRect(x1, y1, x2, y2 int)
	SetDPI(dpi int)
	GetDPI() int
	GetStringBounds(s string) (left, top, right, bottom float64)
	CreateStringPath(text string, x, y float64) (cursor float64)
	FillString(text string) (cursor float64)
	FillStringAt(text string, x, y float64) (cursor float64)
	StrokeString(text string) (cursor float64)
	StrokeStringAt(text string, x, y float64) (cursor float64)
	Stroke(paths ...*PathStorage)
	Fill(paths ...*PathStorage)
	FillStroke(paths ...*PathStorage)
}

GraphicContext describes the interface for the various backends (images, pdf, opengl, ...)

type ImageFilter

type ImageFilter int

ImageFilter defines sampling filter (linear, bilinear or bicubic)

const (
	// LinearFilter uses linear interpolation
	LinearFilter ImageFilter = iota
	// BilinearFilter uses bilinear interpolation
	BilinearFilter
	// BicubicFilter uses bicubic interpolation
	BicubicFilter
)

type ImageGraphicContext

type ImageGraphicContext struct {
	*StackGraphicContext

	DPI int
	// contains filtered or unexported fields
}

func NewGraphicContext

func NewGraphicContext(img draw.Image) *ImageGraphicContext

NewGraphicContext creates a new Graphic context from an image.

func NewGraphicContextWithPainter

func NewGraphicContextWithPainter(img draw.Image, painter Painter) *ImageGraphicContext

NewGraphicContextWithPainter creates a new Graphic context from an image and a Painter (see Freetype-go)

func (*ImageGraphicContext) Clear

func (gc *ImageGraphicContext) Clear()

func (*ImageGraphicContext) ClearRect

func (gc *ImageGraphicContext) ClearRect(x1, y1, x2, y2 int)

func (*ImageGraphicContext) CreateStringPath

func (gc *ImageGraphicContext) CreateStringPath(s string, x, y float64) float64

CreateStringPath creates a path from the string s at x, y, and returns the string width. The text is placed so that the left edge of the em square of the first character of s and the baseline intersect at x, y. The majority of the affected pixels will be above and to the right of the point, but some may be below or to the left. For example, drawing a string that starts with a 'J' in an italic font may affect pixels below and left of the point.

func (*ImageGraphicContext) DrawImage

func (gc *ImageGraphicContext) DrawImage(img image.Image)

func (*ImageGraphicContext) Fill

func (gc *ImageGraphicContext) Fill(paths ...*PathStorage)

Fill fills the paths with the color specified by SetFillColor

func (*ImageGraphicContext) FillString

func (gc *ImageGraphicContext) FillString(text string) (cursor float64)

func (*ImageGraphicContext) FillStringAt

func (gc *ImageGraphicContext) FillStringAt(text string, x, y float64) (cursor float64)

func (*ImageGraphicContext) FillStroke

func (gc *ImageGraphicContext) FillStroke(paths ...*PathStorage)

FillStroke first fills the paths and than strokes them

func (*ImageGraphicContext) GetDPI

func (gc *ImageGraphicContext) GetDPI() int

func (*ImageGraphicContext) GetStringBounds

func (gc *ImageGraphicContext) GetStringBounds(s string) (left, top, right, bottom float64)

GetStringBounds returns the approximate pixel bounds of the string s at x, y. The left edge of the em square of the first character of s and the baseline intersect at 0, 0 in the returned coordinates. Therefore the top and left coordinates may well be negative.

func (*ImageGraphicContext) SetDPI

func (gc *ImageGraphicContext) SetDPI(dpi int)

SetDPI sets the screen resolution in dots per inch.

func (*ImageGraphicContext) SetFont

func (gc *ImageGraphicContext) SetFont(font *truetype.Font)

SetFont sets the font used to draw text.

func (*ImageGraphicContext) SetFontSize

func (gc *ImageGraphicContext) SetFontSize(fontSize float64)

SetFontSize sets the font size in points (as in “a 12 point font”).

func (*ImageGraphicContext) Stroke

func (gc *ImageGraphicContext) Stroke(paths ...*PathStorage)

Stroke strokes the paths with the color specified by SetStrokeColor

func (*ImageGraphicContext) StrokeString

func (gc *ImageGraphicContext) StrokeString(text string) (cursor float64)

func (*ImageGraphicContext) StrokeStringAt

func (gc *ImageGraphicContext) StrokeStringAt(text string, x, y float64) (cursor float64)

type Join

type Join int
const (
	BevelJoin Join = iota
	RoundJoin
	MiterJoin
)

func (Join) Convert

func (j Join) Convert() raster.Joiner

type LineStroker

type LineStroker struct {
	Next          VertexConverter
	HalfLineWidth float64
	Cap           Cap
	Join          Join
	// contains filtered or unexported fields
}

func NewLineStroker

func NewLineStroker(c Cap, j Join, converter VertexConverter) *LineStroker

func (*LineStroker) NextCommand

func (l *LineStroker) NextCommand(command VertexCommand)

func (*LineStroker) Vertex

func (l *LineStroker) Vertex(x, y float64)

type MatrixTransform

type MatrixTransform [6]float64

func NewIdentityMatrix

func NewIdentityMatrix() MatrixTransform

* Creates an identity transformation.

func NewMatrixTransform

func NewMatrixTransform(rectangle1, rectangle2 [4]float64) MatrixTransform

*

  • Creates a transformation, combining a scale and a translation, that transform rectangle1 into rectangle2.

func NewRotationMatrix

func NewRotationMatrix(angle float64) MatrixTransform

*

  • Creates a rotation transformation.

func NewScaleMatrix

func NewScaleMatrix(sx, sy float64) MatrixTransform

*

  • Creates a transformation with a sx, sy scale factor

func NewTranslationMatrix

func NewTranslationMatrix(tx, ty float64) MatrixTransform

*

  • Creates a transformation with a translation, that,
  • transform point1 into point2.

func (MatrixTransform) Determinant

func (tr MatrixTransform) Determinant() float64

func (MatrixTransform) Equals

func (tr1 MatrixTransform) Equals(tr2 MatrixTransform) bool

*

  • Tests if a two transformation are equal. A tolerance is applied when
  • comparing matrix elements.

func (MatrixTransform) GetInverseTransformation

func (tr MatrixTransform) GetInverseTransformation() MatrixTransform

*

  • Returns a transformation that is the inverse of the given transformation.

func (MatrixTransform) GetMaxAbsScaling

func (tr MatrixTransform) GetMaxAbsScaling() (s float64)

func (MatrixTransform) GetMinAbsScaling

func (tr MatrixTransform) GetMinAbsScaling() (s float64)

func (MatrixTransform) GetScale

func (tr MatrixTransform) GetScale() float64

func (MatrixTransform) GetScaling

func (tr MatrixTransform) GetScaling() (x, y float64)

func (MatrixTransform) GetTranslation

func (tr MatrixTransform) GetTranslation() (x, y float64)

func (MatrixTransform) InverseTransform

func (tr MatrixTransform) InverseTransform(points ...*float64)

func (MatrixTransform) IsIdentity

func (tr MatrixTransform) IsIdentity() bool

*

  • Tests if a transformation is the identity transformation. A tolerance
  • is applied when comparing matrix elements.

func (MatrixTransform) IsTranslation

func (tr MatrixTransform) IsTranslation() bool

*

  • Tests if a transformation is is a pure translation. A tolerance
  • is applied when comparing matrix elements.

func (MatrixTransform) Multiply

func (*MatrixTransform) Rotate

func (tr *MatrixTransform) Rotate(angle float64) *MatrixTransform

func (*MatrixTransform) Scale

func (tr *MatrixTransform) Scale(sx, sy float64) *MatrixTransform

func (MatrixTransform) Transform

func (tr MatrixTransform) Transform(points ...*float64)

func (MatrixTransform) TransformArray

func (tr MatrixTransform) TransformArray(points []float64)

func (MatrixTransform) TransformRasterPoint

func (tr MatrixTransform) TransformRasterPoint(points ...*raster.Point)

func (MatrixTransform) TransformRectangle

func (tr MatrixTransform) TransformRectangle(x0, y0, x2, y2 *float64)

func (*MatrixTransform) Translate

func (tr *MatrixTransform) Translate(tx, ty float64) *MatrixTransform

func (MatrixTransform) VectorTransform

func (tr MatrixTransform) VectorTransform(points ...*float64)

type MatrixTransformAdder

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

this adder apply a Matrix transformation to points

func NewMatrixTransformAdder

func NewMatrixTransformAdder(tr MatrixTransform, adder raster.Adder) *MatrixTransformAdder

func (MatrixTransformAdder) Add1

func (mta MatrixTransformAdder) Add1(b raster.Point)

Add1 adds a linear segment to the current curve.

func (MatrixTransformAdder) Add2

func (mta MatrixTransformAdder) Add2(b, c raster.Point)

Add2 adds a quadratic segment to the current curve.

func (MatrixTransformAdder) Add3

func (mta MatrixTransformAdder) Add3(b, c, d raster.Point)

Add3 adds a cubic segment to the current curve.

func (MatrixTransformAdder) Start

func (mta MatrixTransformAdder) Start(a raster.Point)

Start starts a new curve at the given point.

type Painter

type Painter interface {
	raster.Painter
	SetColor(color color.Color)
}

type Path

type Path interface {
	// LastPoint returns the current point of the path
	LastPoint() (x, y float64)
	// MoveTo creates a new subpath that start at the specified point
	MoveTo(x, y float64)
	// RMoveTo creates a new subpath that start at the specified point
	// relative to the current point
	RMoveTo(dx, dy float64)
	// LineTo adds a line to the current subpath
	LineTo(x, y float64)
	// RLineTo adds a line to the current subpath
	// relative to the current point
	RLineTo(dx, dy float64)
	// QuadCurveTo adds a quadratic Bézier curve to the current subpath
	QuadCurveTo(cx, cy, x, y float64)
	// QuadCurveTo adds a quadratic Bézier curve to the current subpath
	// relative to the current point
	RQuadCurveTo(dcx, dcy, dx, dy float64)
	// CubicCurveTo adds a cubic Bézier curve to the current subpath
	CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)
	// RCubicCurveTo adds a cubic Bézier curve to the current subpath
	// relative to the current point
	RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64)
	// ArcTo adds an arc to the current subpath
	ArcTo(cx, cy, rx, ry, startAngle, angle float64)
	// RArcTo adds an arc to the current subpath
	// relative to the current point
	RArcTo(dcx, dcy, rx, ry, startAngle, angle float64)
	// Close creates a line from the current point to the last MoveTo
	// point (if not the same) and mark the path as closed so the
	// first and last lines join nicely.
	Close()
}

Path describes the interface for path drawing.

type PathAdder

type PathAdder struct {
	ApproximationScale float64
	// contains filtered or unexported fields
}

func NewPathAdder

func NewPathAdder(adder raster.Adder) *PathAdder

func (*PathAdder) Convert

func (pathAdder *PathAdder) Convert(paths ...*PathStorage)

type PathCmd

type PathCmd int
const (
	MoveTo PathCmd = iota
	LineTo
	QuadCurveTo
	CubicCurveTo
	ArcTo
	Close
)

type PathConverter

type PathConverter struct {
	ApproximationScale, AngleTolerance, CuspLimit float64
	// contains filtered or unexported fields
}

func NewPathConverter

func NewPathConverter(converter VertexConverter) *PathConverter

func (*PathConverter) ArcTo

func (c *PathConverter) ArcTo(cx, cy, rx, ry, startAngle, angle float64) *PathConverter

func (*PathConverter) Close

func (c *PathConverter) Close() *PathConverter

func (*PathConverter) Convert

func (c *PathConverter) Convert(paths ...*PathStorage)

func (*PathConverter) ConvertCommand

func (c *PathConverter) ConvertCommand(cmd PathCmd, vertices ...float64) int

func (*PathConverter) CubicCurveTo

func (c *PathConverter) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) *PathConverter

func (*PathConverter) LineTo

func (c *PathConverter) LineTo(x, y float64) *PathConverter

func (*PathConverter) MoveTo

func (c *PathConverter) MoveTo(x, y float64) *PathConverter

func (*PathConverter) QuadCurveTo

func (c *PathConverter) QuadCurveTo(cx, cy, x, y float64) *PathConverter

func (*PathConverter) RArcTo

func (c *PathConverter) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64) *PathConverter

func (*PathConverter) RCubicCurveTo

func (c *PathConverter) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64) *PathConverter

func (*PathConverter) RLineTo

func (c *PathConverter) RLineTo(dx, dy float64) *PathConverter

func (*PathConverter) RMoveTo

func (c *PathConverter) RMoveTo(dx, dy float64) *PathConverter

func (*PathConverter) RQuadCurveTo

func (c *PathConverter) RQuadCurveTo(dcx, dcy, dx, dy float64) *PathConverter

type PathStorage

type PathStorage struct {
	Commands []PathCmd
	Vertices []float64
	// contains filtered or unexported fields
}

func NewPathStorage

func NewPathStorage() (p *PathStorage)

func (*PathStorage) ArcTo

func (p *PathStorage) ArcTo(cx, cy, rx, ry, startAngle, angle float64) *PathStorage

func (*PathStorage) Close

func (p *PathStorage) Close() *PathStorage

func (*PathStorage) Copy

func (src *PathStorage) Copy() (dest *PathStorage)

func (*PathStorage) CubicCurveTo

func (p *PathStorage) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) *PathStorage

func (*PathStorage) IsEmpty

func (p *PathStorage) IsEmpty() bool

func (*PathStorage) LastPoint

func (p *PathStorage) LastPoint() (x, y float64)

func (*PathStorage) LineTo

func (p *PathStorage) LineTo(x, y float64) *PathStorage

func (*PathStorage) MoveTo

func (p *PathStorage) MoveTo(x, y float64) *PathStorage

func (*PathStorage) QuadCurveTo

func (p *PathStorage) QuadCurveTo(cx, cy, x, y float64) *PathStorage

func (*PathStorage) RArcTo

func (p *PathStorage) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64) *PathStorage

func (*PathStorage) RCubicCurveTo

func (p *PathStorage) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64) *PathStorage

func (*PathStorage) RLineTo

func (p *PathStorage) RLineTo(dx, dy float64) *PathStorage

func (*PathStorage) RMoveTo

func (p *PathStorage) RMoveTo(dx, dy float64) *PathStorage

func (*PathStorage) RQuadCurveTo

func (p *PathStorage) RQuadCurveTo(dcx, dcy, dx, dy float64) *PathStorage

func (*PathStorage) String

func (p *PathStorage) String() string

type StackGraphicContext

type StackGraphicContext struct {
	Current *ContextStack
}

func NewStackGraphicContext

func NewStackGraphicContext() *StackGraphicContext

*

  • Create a new Graphic context from an image

func (*StackGraphicContext) ArcTo

func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, angle float64)

func (*StackGraphicContext) BeginPath

func (gc *StackGraphicContext) BeginPath()

func (*StackGraphicContext) Close

func (gc *StackGraphicContext) Close()

func (*StackGraphicContext) ComposeMatrixTransform

func (gc *StackGraphicContext) ComposeMatrixTransform(Tr MatrixTransform)

func (*StackGraphicContext) CubicCurveTo

func (gc *StackGraphicContext) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)

func (*StackGraphicContext) GetFontData

func (gc *StackGraphicContext) GetFontData() FontData

func (*StackGraphicContext) GetFontSize

func (gc *StackGraphicContext) GetFontSize() float64

func (*StackGraphicContext) GetMatrixTransform

func (gc *StackGraphicContext) GetMatrixTransform() MatrixTransform

func (*StackGraphicContext) IsEmpty

func (gc *StackGraphicContext) IsEmpty() bool

func (*StackGraphicContext) LastPoint

func (gc *StackGraphicContext) LastPoint() (float64, float64)

func (*StackGraphicContext) LineTo

func (gc *StackGraphicContext) LineTo(x, y float64)

func (*StackGraphicContext) MoveTo

func (gc *StackGraphicContext) MoveTo(x, y float64)

func (*StackGraphicContext) QuadCurveTo

func (gc *StackGraphicContext) QuadCurveTo(cx, cy, x, y float64)

func (*StackGraphicContext) RArcTo

func (gc *StackGraphicContext) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64)

func (*StackGraphicContext) RCubicCurveTo

func (gc *StackGraphicContext) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64)

func (*StackGraphicContext) RLineTo

func (gc *StackGraphicContext) RLineTo(dx, dy float64)

func (*StackGraphicContext) RMoveTo

func (gc *StackGraphicContext) RMoveTo(dx, dy float64)

func (*StackGraphicContext) RQuadCurveTo

func (gc *StackGraphicContext) RQuadCurveTo(dcx, dcy, dx, dy float64)

func (*StackGraphicContext) Restore

func (gc *StackGraphicContext) Restore()

func (*StackGraphicContext) Rotate

func (gc *StackGraphicContext) Rotate(angle float64)

func (*StackGraphicContext) Save

func (gc *StackGraphicContext) Save()

func (*StackGraphicContext) Scale

func (gc *StackGraphicContext) Scale(sx, sy float64)

func (*StackGraphicContext) SetFillColor

func (gc *StackGraphicContext) SetFillColor(c color.Color)

func (*StackGraphicContext) SetFillRule

func (gc *StackGraphicContext) SetFillRule(f FillRule)

func (*StackGraphicContext) SetFontData

func (gc *StackGraphicContext) SetFontData(FontData FontData)

func (*StackGraphicContext) SetFontSize

func (gc *StackGraphicContext) SetFontSize(FontSize float64)

func (*StackGraphicContext) SetLineCap

func (gc *StackGraphicContext) SetLineCap(Cap Cap)

func (*StackGraphicContext) SetLineDash

func (gc *StackGraphicContext) SetLineDash(Dash []float64, DashOffset float64)

func (*StackGraphicContext) SetLineJoin

func (gc *StackGraphicContext) SetLineJoin(Join Join)

func (*StackGraphicContext) SetLineWidth

func (gc *StackGraphicContext) SetLineWidth(LineWidth float64)

func (*StackGraphicContext) SetMatrixTransform

func (gc *StackGraphicContext) SetMatrixTransform(Tr MatrixTransform)

func (*StackGraphicContext) SetStrokeColor

func (gc *StackGraphicContext) SetStrokeColor(c color.Color)

func (*StackGraphicContext) Translate

func (gc *StackGraphicContext) Translate(tx, ty float64)

type VertexAdder

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

func NewVertexAdder

func NewVertexAdder(adder raster.Adder) *VertexAdder

func (*VertexAdder) NextCommand

func (vertexAdder *VertexAdder) NextCommand(cmd VertexCommand)

func (*VertexAdder) Vertex

func (vertexAdder *VertexAdder) Vertex(x, y float64)

type VertexCommand

type VertexCommand byte

VertexCommand defines different commands to describe the vertex of a path.

const (
	// VertexNoCommand does nothing
	VertexNoCommand VertexCommand = iota
	// VertexStartCommand starts a (sub)path
	VertexStartCommand
	// VertexJoinCommand joins the two edges at the vertex
	VertexJoinCommand
	// VertexCloseCommand closes the subpath
	VertexCloseCommand
	// VertexStopCommand is the endpoint of the path.
	VertexStopCommand
)

type VertexConverter

type VertexConverter interface {
	NextCommand(cmd VertexCommand)
	Vertex(x, y float64)
}

VertexConverter allows to convert vertices.

type VertexMatrixTransform

type VertexMatrixTransform struct {
	Next VertexConverter
	// contains filtered or unexported fields
}

this VertexConverter apply the Matrix transformation tr

func NewVertexMatrixTransform

func NewVertexMatrixTransform(tr MatrixTransform, converter VertexConverter) *VertexMatrixTransform

func (*VertexMatrixTransform) NextCommand

func (vmt *VertexMatrixTransform) NextCommand(command VertexCommand)

Vertex Matrix Transform

func (*VertexMatrixTransform) Vertex

func (vmt *VertexMatrixTransform) Vertex(x, y float64)

Directories

Path Synopsis
Package draw2dgl provides a graphic context that can draw vector graphics and text on OpenGL.
Package draw2dgl provides a graphic context that can draw vector graphics and text on OpenGL.
Package draw2dpdf provides a graphic context that can draw vector graphics and text on pdf file with the gofpdf package.
Package draw2dpdf provides a graphic context that can draw vector graphics and text on pdf file with the gofpdf package.
Package samples provides examples which can be used with different backends.
Package samples provides examples which can be used with different backends.
android
Package android draws an android avatar.
Package android draws an android avatar.
frameimage
Package frameimage centers a png image and rotates it.
Package frameimage centers a png image and rotates it.
geometry
Package geometry draws some geometric tests.
Package geometry draws some geometric tests.
gopher
Package gopher draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
Package gopher draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
gopher2
Package gopher2 draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
Package gopher2 draws a gopher avatar based on a svg of: https://github.com/golang-samples/gopher-vector/
helloworld
Package helloworld displays multiple "Hello World" (one rotated) in a rounded rectangle.
Package helloworld displays multiple "Hello World" (one rotated) in a rounded rectangle.
helloworldgl
Open an OpenGl window and display a rectangle using a OpenGl GraphicContext
Open an OpenGl window and display a rectangle using a OpenGl GraphicContext
line
Package line draws vertically spaced lines.
Package line draws vertically spaced lines.
linecapjoin
Package linecapjoin demonstrates the different line caps and joins.
Package linecapjoin demonstrates the different line caps and joins.
postscript
Package postscript reads the tiger.ps file and draws it to a backend.
Package postscript reads the tiger.ps file and draws it to a backend.
postscriptgl
Open a OpenGL window and display a tiger interpreting a postscript file
Open a OpenGL window and display a tiger interpreting a postscript file

Jump to

Keyboard shortcuts

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