Skip to content

Commit

Permalink
Merge branch 'master' into Clean-Up
Browse files Browse the repository at this point in the history
Conflicts:
	arc.go
	curve/curve_test.go
	draw2dgl/gc.go
	draw2dimg/rgba_interpolation.go
	draw2dpdf/gc.go
	draw2dpdf/path_converter.go
	path_adder.go
	path_storage.go
	raster/raster_test.go
	vertex2d.go
  • Loading branch information
llgcode committed Aug 14, 2015
2 parents 04427ca + ce9c7f7 commit 7ef94ce
Show file tree
Hide file tree
Showing 47 changed files with 1,608 additions and 216 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ _test*
**/*.dll
**/core*[0-9]
.private

3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Laurent Le Goff
Laurent Le Goff
Stani Michiels, gmail:stani.be
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
draw2d
======

Package draw2d is a pure [go](http://golang.org) 2D vector graphics library with support for multiple output devices such as [images](http://golang.org/pkg/image) (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](http://www.cairographics.org/) alternative.
Package draw2d is a pure [go](http://golang.org) 2D vector graphics library with support for multiple output devices such as [images](http://golang.org/pkg/image) (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](http://www.cairographics.org/) alternative. draw2d is released under the BSD license. See the [documentation](http://godoc.org/github.com/llgcode/draw2d) for more details.

See the [documentation](http://godoc.org/github.com/llgcode/draw2d) for more details.
[![geometry](https://raw.githubusercontent.com/llgcode/draw2d/master/output/samples/geometry.png)](https://raw.githubusercontent.com/llgcode/draw2d/master/resource/image/geometry.pdf)[![postscript](https://raw.githubusercontent.com/llgcode/draw2d/master/output/samples/postscript.png)](https://raw.githubusercontent.com/llgcode/draw2d/master/resource/image/postscript.pdf)

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](https://github.com/llgcode/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](http://www.w3.org/TR/2dcontext/) for coordinate system, angles, etc...

Installation
------------

Expand Down Expand Up @@ -42,7 +46,7 @@ gc.Close()
gc.FillStroke()

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

The same Go code can also generate a pdf document with package draw2dpdf:
Expand All @@ -65,13 +69,26 @@ gc.Close()
gc.FillStroke()

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

There are more examples here: https://github.com/llgcode/draw2d.samples
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
---------------

Expand All @@ -94,3 +111,4 @@ References

- [antigrain.com](http://www.antigrain.com)
- [freetype-go](http://code.google.com/p/freetype-go)
-
22 changes: 16 additions & 6 deletions draw2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

// 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
// (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
//
Expand All @@ -13,6 +14,8 @@
// 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:
Expand Down Expand Up @@ -40,15 +43,25 @@
// gc.FillStroke()
//
// // Save to file
// draw2d.SaveToPngFile(fn, dest)
// draw2d.SaveToPngFile("hello.png", dest)
//
// There are more examples here:
// https://github.com/llgcode/draw2d.samples
// 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
Expand All @@ -58,9 +71,6 @@
// graphic context (https://github.com/llgcode/ps). Stani Michiels
// implemented the pdf backend with the gofpdf package.
//
// The package depends on freetype-go package for its rasterization
// algorithm.
//
// Packages using draw2d
//
// - https://github.com/llgcode/ps: Postscript interpreter written in Go
Expand Down
12 changes: 6 additions & 6 deletions draw2dbase/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func SubdivideCubic(c, c1, c2 []float64) {
c2[0], c2[1] = c1[6], c1[7]
}

// TraceCubic generate lines subdividing the cubic curve using a Flattener
// TraceCubic generate lines subdividing the cubic curve using a Liner
// flattening_threshold helps determines the flattening expectation of the curve
func TraceCubic(t Flattener, cubic []float64, flatteningThreshold float64) {
func TraceCubic(t Liner, cubic []float64, flatteningThreshold float64) {
// Allocation curves
var curves [CurveRecursionLimit * 8]float64
copy(curves[0:8], cubic[0:8])
Expand Down Expand Up @@ -101,9 +101,9 @@ func SubdivideQuad(c, c1, c2 []float64) {
return
}

// TraceQuad generate lines subdividing the curve using a Flattener
// TraceQuad generate lines subdividing the curve using a Liner
// flattening_threshold helps determines the flattening expectation of the curve
func TraceQuad(t Flattener, quad []float64, flatteningThreshold float64) {
func TraceQuad(t Liner, quad []float64, flatteningThreshold float64) {
// Allocates curves stack
var curves [CurveRecursionLimit * 6]float64
copy(curves[0:6], quad[0:6])
Expand Down Expand Up @@ -131,8 +131,8 @@ func TraceQuad(t Flattener, quad []float64, flatteningThreshold float64) {
}
}

// TraceArc trace an arc using a Flattener
func TraceArc(t Flattener, x, y, rx, ry, start, angle, scale float64) (lastX, lastY float64) {
// TraceArc trace an arc using a Liner
func TraceArc(t Liner, x, y, rx, ry, start, angle, scale float64) (lastX, lastY float64) {
end := start + angle
clockWise := true
if angle < 0 {
Expand Down
6 changes: 3 additions & 3 deletions draw2dbase/curve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (

func init() {
os.Mkdir("test_results", 0666)
f, err := os.Create("test_results/_test.html")
f, err := os.Create("../output/curve/_test.html")
if err != nil {
log.Println(err)
os.Exit(1)
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestCubicCurve(t *testing.T) {
raster.PolylineBresenham(img, image.Black, p.Points...)
//drawPoints(img, image.NRGBAColor{0, 0, 0, 0xff}, curve[:]...)
drawPoints(img, color.NRGBA{0, 0, 0, 0xff}, p.Points...)
SaveToPngFile(fmt.Sprintf("test_results/_test%d.png", i/8), img)
SaveToPngFile(fmt.Sprintf("../output/curve/_test%d.png", i/8), img)
log.Printf("Num of points: %d\n", len(p.Points))
}
fmt.Println()
Expand All @@ -97,7 +97,7 @@ func TestQuadCurve(t *testing.T) {
raster.PolylineBresenham(img, image.Black, p.Points...)
//drawPoints(img, image.NRGBAColor{0, 0, 0, 0xff}, curve[:]...)
drawPoints(img, color.NRGBA{0, 0, 0, 0xff}, p.Points...)
SaveToPngFile(fmt.Sprintf("test_results/_testQuad%d.png", i), img)
SaveToPngFile(fmt.Sprintf("../output/curve/_testQuad%d.png", i), img)
log.Printf("Num of points: %d\n", len(p.Points))
}
fmt.Println()
Expand Down
6 changes: 6 additions & 0 deletions draw2dbase/flattener.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/llgcode/draw2d"
)

// Liner receive segment definition
type Liner interface {
// LineTo Draw a line from the current position to the point (x, y)
LineTo(x, y float64)
}

// Flattener receive segment definition
type Flattener interface {
// MoveTo Start a New line from the point (x, y)
Expand Down
80 changes: 0 additions & 80 deletions draw2dimg/drawer.go

This file was deleted.

42 changes: 42 additions & 0 deletions draw2dpdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
draw2d pdf
==========

Package draw2dpdf provides a graphic context that can draw vector graphics and text on pdf file with the [gofpdf](https://github.com/jung-kurt/gofpdf) package.

Quick Start
-----------

The following Go code generates a simple drawing and saves it to a pdf document:
```go
// 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

Alternative backends
--------------------

- Drawing on images is provided by the draw2d package.
- Drawing on opengl is provided by the draw2dgl package.

Acknowledgments
---------------

The pdf backend uses https://github.com/jung-kurt/gofpdf
8 changes: 5 additions & 3 deletions draw2dpdf/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// created: 26/06/2015 by Stani Michiels

// Package draw2dpdf provides a graphic context that can draw vector
// graphics and text on pdf file.
// graphics and text on pdf file with the gofpdf package.
//
// Quick Start
//
Expand All @@ -25,10 +25,12 @@
// gc.FillStroke()
//
// // Save to file
// draw2dpdf.SaveToPdfFile(fn, dest)
// draw2dpdf.SaveToPdfFile("hello.pdf", dest)
//
// There are more examples here:
// https://github.com/llgcode/draw2d.samples
// https://github.com/llgcode/draw2d/tree/master/samples
//
// Alternative backends
//
// Drawing on images is provided by the draw2d package.
// Drawing on opengl is provided by the draw2dgl package.
Expand Down
3 changes: 3 additions & 0 deletions draw2dpdf/fileutil.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2015 The draw2d Authors. All rights reserved.
// created: 26/06/2015 by Stani Michiels

package draw2dpdf

import "github.com/jung-kurt/gofpdf"
Expand Down
Loading

0 comments on commit 7ef94ce

Please sign in to comment.