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 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))
}

View file

@ -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
}

View file

@ -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()
}

View file

@ -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