From 72c9be4ed0a135dad4f89e891fac12e22cc74300 Mon Sep 17 00:00:00 2001 From: Stani Date: Fri, 10 Jul 2015 15:11:19 +0200 Subject: [PATCH 1/3] add copyright information --- draw2dpdf/fileutil.go | 3 +++ draw2dpdf/gc.go | 4 ++-- draw2dpdf/samples_test.go | 2 ++ draw2dpdf/test_test.go | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/draw2dpdf/fileutil.go b/draw2dpdf/fileutil.go index c3c8e66..349545d 100644 --- a/draw2dpdf/fileutil.go +++ b/draw2dpdf/fileutil.go @@ -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" diff --git a/draw2dpdf/gc.go b/draw2dpdf/gc.go index 8c7c3aa..e1844fb 100644 --- a/draw2dpdf/gc.go +++ b/draw2dpdf/gc.go @@ -1,6 +1,6 @@ // Copyright 2015 The draw2d Authors. All rights reserved. // created: 26/06/2015 by Stani Michiels -// TODO: fonts, dpi +// TODO: dashed line package draw2dpdf @@ -88,7 +88,7 @@ func NewGraphicContext(pdf *gofpdf.Fpdf) *GraphicContext { // TODO: add type (tp) as parameter to argument list? func (gc *GraphicContext) DrawImage(image image.Image) { name := strconv.Itoa(int(imageCount)) - imageCount += 1 + imageCount++ tp := "PNG" // "JPG", "JPEG", "PNG" and "GIF" b := &bytes.Buffer{} png.Encode(b, image) diff --git a/draw2dpdf/samples_test.go b/draw2dpdf/samples_test.go index ac6a4ce..8da8b8d 100644 --- a/draw2dpdf/samples_test.go +++ b/draw2dpdf/samples_test.go @@ -1,3 +1,5 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels // See also test_test.go package draw2dpdf_test diff --git a/draw2dpdf/test_test.go b/draw2dpdf/test_test.go index 88e1f43..801ff36 100644 --- a/draw2dpdf/test_test.go +++ b/draw2dpdf/test_test.go @@ -1,3 +1,6 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels + // Package draw2dpdf_test gives test coverage with the command: // go test -cover ./... | grep -v "no test" // (It should be run from its parent draw2d directory.) From fb6189e2461346abd4279811656b962c809729a1 Mon Sep 17 00:00:00 2001 From: Stani Date: Fri, 10 Jul 2015 15:11:57 +0200 Subject: [PATCH 2/3] add test script --- test | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 test diff --git a/test b/test new file mode 100755 index 0000000..f643b46 --- /dev/null +++ b/test @@ -0,0 +1,8 @@ +echo golint +golint ./... | grep "draw2dpdf\|samples" +echo +echo go vet +go vet ./... +echo +echo go test +go test -cover ./... | grep -v "no test" \ No newline at end of file From bb793d237f7ff90813b3639d2c16474ba3ecaef2 Mon Sep 17 00:00:00 2001 From: Stani Date: Fri, 10 Jul 2015 15:24:23 +0200 Subject: [PATCH 3/3] go vet fixes --- arc.go | 10 ++++++---- path_adder.go | 37 ++++++++++++++++++++++++++++++------- raster/raster_test.go | 33 +++++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/arc.go b/arc.go index 1bfef06..9fb8352 100644 --- a/arc.go +++ b/arc.go @@ -35,7 +35,6 @@ func arc(t VertexConverter, x, y, rx, ry, start, angle, scale float64) (lastX, l angle += da t.Vertex(curX, curY) } - return curX, curY } func arcAdder(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) raster.Point { @@ -56,13 +55,16 @@ func arcAdder(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) ras if (angle < end-da/4) != clockWise { curX = x + math.Cos(end)*rx curY = y + math.Sin(end)*ry - return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)} + return raster.Point{ + X: raster.Fix32(curX * 256), + Y: raster.Fix32(curY * 256)} } curX = x + math.Cos(angle)*rx curY = y + math.Sin(angle)*ry angle += da - adder.Add1(raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}) + adder.Add1(raster.Point{ + X: raster.Fix32(curX * 256), + Y: raster.Fix32(curY * 256)}) } - return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)} } diff --git a/path_adder.go b/path_adder.go index 5731bb5..526108b 100644 --- a/path_adder.go +++ b/path_adder.go @@ -23,9 +23,13 @@ func (vertexAdder *VertexAdder) NextCommand(cmd VertexCommand) { func (vertexAdder *VertexAdder) Vertex(x, y float64) { switch vertexAdder.command { case VertexStartCommand: - vertexAdder.adder.Start(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)}) + vertexAdder.adder.Start(raster.Point{ + X: raster.Fix32(x * 256), + Y: raster.Fix32(y * 256)}) default: - vertexAdder.adder.Add1(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)}) + vertexAdder.adder.Add1(raster.Point{ + X: raster.Fix32(x * 256), + Y: raster.Fix32(y * 256)}) } vertexAdder.command = VertexNoCommand } @@ -37,7 +41,7 @@ type PathAdder struct { } func NewPathAdder(adder raster.Adder) *PathAdder { - return &PathAdder{adder, raster.Point{0, 0}, 1} + return &PathAdder{adder, raster.Point{X: 0, Y: 0}, 1} } func (pathAdder *PathAdder) Convert(paths ...*PathStorage) { @@ -46,17 +50,36 @@ func (pathAdder *PathAdder) Convert(paths ...*PathStorage) { for _, cmd := range path.Commands { switch cmd { case MoveTo: - pathAdder.firstPoint = raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)} + pathAdder.firstPoint = raster.Point{ + X: raster.Fix32(path.Vertices[j] * 256), + Y: raster.Fix32(path.Vertices[j+1] * 256)} pathAdder.adder.Start(pathAdder.firstPoint) j += 2 case LineTo: - pathAdder.adder.Add1(raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)}) + pathAdder.adder.Add1(raster.Point{ + X: raster.Fix32(path.Vertices[j] * 256), + Y: raster.Fix32(path.Vertices[j+1] * 256)}) j += 2 case QuadCurveTo: - pathAdder.adder.Add2(raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)}, raster.Point{raster.Fix32(path.Vertices[j+2] * 256), raster.Fix32(path.Vertices[j+3] * 256)}) + pathAdder.adder.Add2( + raster.Point{ + X: raster.Fix32(path.Vertices[j] * 256), + Y: raster.Fix32(path.Vertices[j+1] * 256)}, + raster.Point{ + X: raster.Fix32(path.Vertices[j+2] * 256), + Y: raster.Fix32(path.Vertices[j+3] * 256)}) j += 4 case CubicCurveTo: - pathAdder.adder.Add3(raster.Point{raster.Fix32(path.Vertices[j] * 256), raster.Fix32(path.Vertices[j+1] * 256)}, raster.Point{raster.Fix32(path.Vertices[j+2] * 256), raster.Fix32(path.Vertices[j+3] * 256)}, raster.Point{raster.Fix32(path.Vertices[j+4] * 256), raster.Fix32(path.Vertices[j+5] * 256)}) + pathAdder.adder.Add3( + raster.Point{ + X: raster.Fix32(path.Vertices[j] * 256), + Y: raster.Fix32(path.Vertices[j+1] * 256)}, + raster.Point{ + X: raster.Fix32(path.Vertices[j+2] * 256), + Y: raster.Fix32(path.Vertices[j+3] * 256)}, + raster.Point{ + X: raster.Fix32(path.Vertices[j+4] * 256), + Y: raster.Fix32(path.Vertices[j+5] * 256)}) j += 6 case ArcTo: lastPoint := arcAdder(pathAdder.adder, path.Vertices[j], path.Vertices[j+1], path.Vertices[j+2], path.Vertices[j+3], path.Vertices[j+4], path.Vertices[j+5], pathAdder.ApproximationScale) diff --git a/raster/raster_test.go b/raster/raster_test.go index 7d595cc..21840d7 100644 --- a/raster/raster_test.go +++ b/raster/raster_test.go @@ -62,9 +62,13 @@ func TestFreetype(t *testing.T) { img := image.NewRGBA(image.Rect(0, 0, 200, 200)) rasterizer := raster.NewRasterizer(200, 200) rasterizer.UseNonZeroWinding = false - rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)}) + rasterizer.Start(raster.Point{ + X: raster.Fix32(10 * 256), + Y: raster.Fix32(190 * 256)}) for j := 0; j < len(poly); j = j + 2 { - rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)}) + rasterizer.Add1(raster.Point{ + X: raster.Fix32(poly[j] * 256), + Y: raster.Fix32(poly[j+1] * 256)}) } painter := raster.NewRGBAPainter(img) painter.SetColor(color) @@ -84,9 +88,13 @@ func TestFreetypeNonZeroWinding(t *testing.T) { img := image.NewRGBA(image.Rect(0, 0, 200, 200)) rasterizer := raster.NewRasterizer(200, 200) rasterizer.UseNonZeroWinding = true - rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)}) + rasterizer.Start(raster.Point{ + X: raster.Fix32(10 * 256), + Y: raster.Fix32(190 * 256)}) for j := 0; j < len(poly); j = j + 2 { - rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)}) + rasterizer.Add1(raster.Point{ + X: raster.Fix32(poly[j] * 256), + Y: raster.Fix32(poly[j+1] * 256)}) } painter := raster.NewRGBAPainter(img) painter.SetColor(color) @@ -139,15 +147,20 @@ func BenchmarkFreetype(b *testing.B) { img := image.NewRGBA(image.Rect(0, 0, 200, 200)) rasterizer := raster.NewRasterizer(200, 200) rasterizer.UseNonZeroWinding = false - rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)}) + rasterizer.Start(raster.Point{ + X: raster.Fix32(10 * 256), + Y: raster.Fix32(190 * 256)}) for j := 0; j < len(poly); j = j + 2 { - rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)}) + rasterizer.Add1(raster.Point{ + X: raster.Fix32(poly[j] * 256), + Y: raster.Fix32(poly[j+1] * 256)}) } painter := raster.NewRGBAPainter(img) painter.SetColor(color) rasterizer.Rasterize(painter) } } + func BenchmarkFreetypeNonZeroWinding(b *testing.B) { var p Path p.LineTo(10, 190) @@ -160,9 +173,13 @@ func BenchmarkFreetypeNonZeroWinding(b *testing.B) { img := image.NewRGBA(image.Rect(0, 0, 200, 200)) rasterizer := raster.NewRasterizer(200, 200) rasterizer.UseNonZeroWinding = true - rasterizer.Start(raster.Point{raster.Fix32(10 * 256), raster.Fix32(190 * 256)}) + rasterizer.Start(raster.Point{ + X: raster.Fix32(10 * 256), + Y: raster.Fix32(190 * 256)}) for j := 0; j < len(poly); j = j + 2 { - rasterizer.Add1(raster.Point{raster.Fix32(poly[j] * 256), raster.Fix32(poly[j+1] * 256)}) + rasterizer.Add1(raster.Point{ + X: raster.Fix32(poly[j] * 256), + Y: raster.Fix32(poly[j+1] * 256)}) } painter := raster.NewRGBAPainter(img) painter.SetColor(color)