draw2d/samples
Stani b1e17999b6 fix gopher drawing in gopher2 2015-07-13 00:33:03 +02:00
..
android add android sample 2015-07-10 02:12:22 +02:00
appengine add sample: appengine 2015-07-10 02:12:40 +02:00
frameimage add sample: frameimage 2015-07-10 02:13:27 +02:00
geometry fix SetFontData for pdf 2015-07-12 02:36:44 +02:00
gopher fix typo 2015-07-11 18:41:38 +02:00
gopher2 fix gopher drawing in gopher2 2015-07-13 00:33:03 +02:00
helloworld add extra lines to check baseline 2015-07-12 20:47:35 +02:00
helloworldgl add sample: helloworldgl 2015-07-10 02:14:14 +02:00
line get 100% test coverage for draw2dpdf 2015-07-10 21:50:07 +02:00
linecapjoin previous fix makes Save and Restore for line caps join unnecessary 2015-07-11 01:13:39 +02:00
postscript add sample: postscript 2015-07-10 02:15:13 +02:00
postscriptgl add sample: postscriptgl 2015-07-10 02:15:23 +02:00
README.md add license to README 2015-07-10 12:45:52 +02:00
samples.go redirect curve tests results to output.curve folder 2015-07-10 17:20:23 +02:00

README.md

draw2d samples

Various samples for using draw2d

Using the image backend

The following Go code draws the android sample on a png image:

import (
	"image"

	"github.com/llgcode/draw2d"
	"github.com/llgcode/draw2d/samples/android"
)

function main(){}
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2d.NewGraphicContext(dest)
	// Draw Android logo
	fn, err := android.Main(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", fn, err)
		return
	}
	// Save to png
	err = draw2d.SaveToPngFile(fn, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", fn, err)
	}
}

Using the pdf backend

The following Go code draws the android sample on a pdf document:

import (
	"image"

	"github.com/llgcode/draw2d/draw2dpdf"
	"github.com/llgcode/draw2d/samples/android"
)

function main(){}
	// Initialize the graphic context on a pdf document
	dest := draw2dpdf.NewPdf("L", "mm", "A4")
	gc := draw2dpdf.NewGraphicContext(dest)
	// Draw Android logo
	fn, err := android.Main(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", fn, err)
		return
	}
	// Save to pdf
	err = draw2dpdf.SaveToPdfFile(fn, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", fn, err)
	}
}

Testing

These 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"

The following files are responsible to run the image tests:

draw2d/test_test.go
draw2d/samples_test.go

The following files are responsible to run the pdf tests:

draw2d/pdf/test_test.go
draw2dpdf/samples_test.go