From f879ad32a7d9538777cb59573b335c0043153ba0 Mon Sep 17 00:00:00 2001 From: Stani Date: Fri, 10 Jul 2015 21:50:07 +0200 Subject: [PATCH] get 100% test coverage for draw2dpdf --- draw2dpdf/gc.go | 3 ++- draw2dpdf/path_converter.go | 3 +-- samples/helloworld/helloworld.go | 18 +++++++++++------- samples/line/line.go | 8 ++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/draw2dpdf/gc.go b/draw2dpdf/gc.go index e1844fb..50a7137 100644 --- a/draw2dpdf/gc.go +++ b/draw2dpdf/gc.go @@ -105,7 +105,8 @@ func (gc *GraphicContext) Clear() { clearRect(gc, 0, 0, width, height) } -// ClearRect draws a white rectangle over the specified area +// ClearRect draws a white rectangle over the specified area. +// Samples: line. func (gc *GraphicContext) ClearRect(x1, y1, x2, y2 int) { clearRect(gc, float64(x1), float64(y1), float64(x2), float64(y2)) } diff --git a/draw2dpdf/path_converter.go b/draw2dpdf/path_converter.go index c58d53e..77bbfb6 100644 --- a/draw2dpdf/path_converter.go +++ b/draw2dpdf/path_converter.go @@ -52,9 +52,8 @@ func (c *PathConverter) ConvertCommand(cmd draw2d.PathCmd, vertices ...float64) vertices[4]*deg, // degStart = startAngle (vertices[4]-vertices[5])*deg) // degEnd = startAngle-angle return 6 - case draw2d.Close: + default: // case draw2d.Close: c.pdf.ClosePath() return 0 } - return 0 } diff --git a/samples/helloworld/helloworld.go b/samples/helloworld/helloworld.go index 8d7f330..301edcd 100644 --- a/samples/helloworld/helloworld.go +++ b/samples/helloworld/helloworld.go @@ -1,11 +1,12 @@ // Copyright 2010 The draw2d Authors. All rights reserved. // created: 21/11/2010 by Laurent Le Goff, Stani Michiels -// Package helloworld displays "Hello World" twice (one rotated) in a -// rounded rectangle. +// Package helloworld displays multiple "Hello World" (one rotated) +// in a rounded rectangle. package helloworld import ( + "fmt" "image" "image/color" "math" @@ -18,14 +19,14 @@ import ( // used during testing. func Main(gc draw2d.GraphicContext, ext string) (string, error) { // Draw hello world - Draw(gc) + Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI())) // Return the output filename return samples.Output("helloworld", ext), nil } // Draw "Hello World" -func Draw(gc draw2d.GraphicContext) { +func Draw(gc draw2d.GraphicContext, text string) { // Draw a rounded rectangle using default colors draw2d.RoundRect(gc, 5, 5, 292, 205, 10, 10) gc.FillStroke() @@ -40,12 +41,15 @@ func Draw(gc draw2d.GraphicContext) { gc.SetDPI(72) gc.SetFontSize(14) // Display Hello World - gc.FillStringAt("Hello World", 8, 52) + gc.FillString(text) + gc.FillStringAt(text, 8, 52) gc.Save() gc.SetFillColor(color.NRGBA{0xFF, 0x33, 0x33, 0xFF}) - gc.Translate(145, 105) + gc.Translate(145, 85) + gc.StrokeStringAt(text, -50, 0) gc.Rotate(math.Pi / 4) - gc.FillStringAt("Hello World", 0, 0) + gc.SetFillColor(color.NRGBA{0x33, 0x33, 0xFF, 0xFF}) + gc.StrokeString(text) gc.Restore() } diff --git a/samples/line/line.go b/samples/line/line.go index 7331cd5..2899d94 100644 --- a/samples/line/line.go +++ b/samples/line/line.go @@ -5,6 +5,8 @@ package line import ( + "image/color" + "github.com/llgcode/draw2d" "github.com/llgcode/draw2d/samples" ) @@ -12,10 +14,16 @@ import ( // Main draws vertically spaced lines and returns the filename. // This should only be used during testing. func Main(gc draw2d.GraphicContext, ext string) (string, error) { + gc.SetFillRule(draw2d.FillRuleWinding) + gc.Clear() // Draw the line for x := 5.0; x < 297; x += 10 { Draw(gc, x, 0, x, 210) } + gc.ClearRect(100, 75, 197, 135) + draw2d.Ellipse(gc, 148.5, 105, 35, 25) + gc.SetFillColor(color.RGBA{0xff, 0xff, 0x44, 0xff}) + gc.FillStroke() // Return the output filename return samples.Output("line", ext), nil