Merge pull request #60 from stanim/coverage

get 100% test coverage for draw2dpdf
This commit is contained in:
Stani 2015-07-10 21:57:42 +02:00
commit bb523db1f4
4 changed files with 22 additions and 10 deletions

View file

@ -105,7 +105,8 @@ func (gc *GraphicContext) Clear() {
clearRect(gc, 0, 0, width, height) 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) { func (gc *GraphicContext) ClearRect(x1, y1, x2, y2 int) {
clearRect(gc, float64(x1), float64(y1), float64(x2), float64(y2)) clearRect(gc, float64(x1), float64(y1), float64(x2), float64(y2))
} }

View file

@ -52,9 +52,8 @@ func (c *PathConverter) ConvertCommand(cmd draw2d.PathCmd, vertices ...float64)
vertices[4]*deg, // degStart = startAngle vertices[4]*deg, // degStart = startAngle
(vertices[4]-vertices[5])*deg) // degEnd = startAngle-angle (vertices[4]-vertices[5])*deg) // degEnd = startAngle-angle
return 6 return 6
case draw2d.Close: default: // case draw2d.Close:
c.pdf.ClosePath() c.pdf.ClosePath()
return 0 return 0
} }
return 0
} }

View file

@ -1,11 +1,12 @@
// Copyright 2010 The draw2d Authors. All rights reserved. // Copyright 2010 The draw2d Authors. All rights reserved.
// created: 21/11/2010 by Laurent Le Goff, Stani Michiels // created: 21/11/2010 by Laurent Le Goff, Stani Michiels
// Package helloworld displays "Hello World" twice (one rotated) in a // Package helloworld displays multiple "Hello World" (one rotated)
// rounded rectangle. // in a rounded rectangle.
package helloworld package helloworld
import ( import (
"fmt"
"image" "image"
"image/color" "image/color"
"math" "math"
@ -18,14 +19,14 @@ import (
// used during testing. // used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) { func Main(gc draw2d.GraphicContext, ext string) (string, error) {
// Draw hello world // Draw hello world
Draw(gc) Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI()))
// Return the output filename // Return the output filename
return samples.Output("helloworld", ext), nil return samples.Output("helloworld", ext), nil
} }
// Draw "Hello World" // Draw "Hello World"
func Draw(gc draw2d.GraphicContext) { func Draw(gc draw2d.GraphicContext, text string) {
// Draw a rounded rectangle using default colors // Draw a rounded rectangle using default colors
draw2d.RoundRect(gc, 5, 5, 292, 205, 10, 10) draw2d.RoundRect(gc, 5, 5, 292, 205, 10, 10)
gc.FillStroke() gc.FillStroke()
@ -40,12 +41,15 @@ func Draw(gc draw2d.GraphicContext) {
gc.SetDPI(72) gc.SetDPI(72)
gc.SetFontSize(14) gc.SetFontSize(14)
// Display Hello World // Display Hello World
gc.FillStringAt("Hello World", 8, 52) gc.FillString(text)
gc.FillStringAt(text, 8, 52)
gc.Save() gc.Save()
gc.SetFillColor(color.NRGBA{0xFF, 0x33, 0x33, 0xFF}) 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.Rotate(math.Pi / 4)
gc.FillStringAt("Hello World", 0, 0) gc.SetFillColor(color.NRGBA{0x33, 0x33, 0xFF, 0xFF})
gc.StrokeString(text)
gc.Restore() gc.Restore()
} }

View file

@ -5,6 +5,8 @@
package line package line
import ( import (
"image/color"
"github.com/llgcode/draw2d" "github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
@ -12,10 +14,16 @@ import (
// Main draws vertically spaced lines and returns the filename. // Main draws vertically spaced lines and returns the filename.
// This should only be used during testing. // This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) { func Main(gc draw2d.GraphicContext, ext string) (string, error) {
gc.SetFillRule(draw2d.FillRuleWinding)
gc.Clear()
// Draw the line // Draw the line
for x := 5.0; x < 297; x += 10 { for x := 5.0; x < 297; x += 10 {
Draw(gc, x, 0, x, 210) 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 the output filename
return samples.Output("line", ext), nil return samples.Output("line", ext), nil