Draw2d changed to use our own freetype fork
Go to file
Laurent Le Goff 04427cabf5 Merge with master 2015-07-09 18:06:14 +02:00
draw2dbase Merge with master 2015-07-09 18:06:14 +02:00
draw2dgl Merge with master 2015-07-09 18:06:14 +02:00
draw2dimg Merge with master 2015-07-09 18:06:14 +02:00
draw2dkit Merge with master 2015-07-09 18:06:14 +02:00
draw2dpdf Merge with master 2015-07-09 18:06:14 +02:00
raster migrating to new curve package 2015-04-23 10:05:48 +02:00
resource remove unecessary folder 2015-04-22 11:08:18 +02:00
.gitignore update gitignore 2015-07-01 15:38:14 +02:00
AUTHORS Remove oldies 2011-04-27 10:06:14 +02:00
LICENSE Remove oldies 2011-04-27 10:06:14 +02:00
README.md improve README.md 2015-07-09 16:03:05 +02:00
draw2d.go Merge with master 2015-07-09 18:06:14 +02:00
font.go fixed the SetFontData method 2015-06-27 19:41:34 +02:00
gc.go Merge with master 2015-07-09 18:06:14 +02:00
matrix.go Rename MatrixTransform to Matrix 2015-04-30 14:11:23 +02:00
path.go Merge with master 2015-07-09 18:06:14 +02:00
samples_test.go updated repository names 2015-07-07 00:07:44 +02:00
test_test.go make sample interface private 2015-07-07 23:35:03 +02:00

README.md

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 (draw2dopengl), which can also be used on the google app engine. It can be used as a pure go Cairo alternative.

See the documentation for more details.

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).

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(fn, 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(fn, dest)

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

Drawing on opengl is provided by the draw2dgl package.

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