Merge pull request #14 from wsw0108/default-fill-stroke-style

default fill/stroke (black on white)
This commit is contained in:
Michael Fogleman 2016-12-08 10:19:18 -05:00 committed by GitHub
commit 19103e0c61

View File

@ -44,6 +44,11 @@ const (
AlignRight AlignRight
) )
var (
defaultFillStyle = NewSolidPattern(color.White)
defaultStrokeStyle = NewSolidPattern(color.Black)
)
type Context struct { type Context struct {
width int width int
height int height int
@ -84,15 +89,17 @@ func NewContextForImage(im image.Image) *Context {
// No copy is made. // No copy is made.
func NewContextForRGBA(im *image.RGBA) *Context { func NewContextForRGBA(im *image.RGBA) *Context {
return &Context{ return &Context{
width: im.Bounds().Size().X, width: im.Bounds().Size().X,
height: im.Bounds().Size().Y, height: im.Bounds().Size().Y,
im: im, im: im,
color: color.Transparent, color: color.Transparent,
lineWidth: 1, fillPattern: defaultFillStyle,
fillRule: FillRuleWinding, strokePattern: defaultStrokeStyle,
fontFace: basicfont.Face7x13, lineWidth: 1,
fontHeight: 13, fillRule: FillRuleWinding,
matrix: Identity(), fontFace: basicfont.Face7x13,
fontHeight: 13,
matrix: Identity(),
} }
} }
@ -182,6 +189,10 @@ func (dc *Context) setFillAndStrokeColor(c color.Color) {
// SetFillStyle sets current fill style // SetFillStyle sets current fill style
func (dc *Context) SetFillStyle(pattern Pattern) { func (dc *Context) SetFillStyle(pattern Pattern) {
// if pattern is SolidPattern, also change dc.color(for dc.Clear, dc.drawString)
if fillStyle, ok := pattern.(*solidPattern); ok {
dc.color = fillStyle.color
}
dc.fillPattern = pattern dc.fillPattern = pattern
} }
@ -190,7 +201,7 @@ func (dc *Context) SetStrokeStyle(pattern Pattern) {
dc.strokePattern = pattern dc.strokePattern = pattern
} }
// SetColor sets the current color. // SetColor sets the current color(for both fill and stroke).
func (dc *Context) SetColor(c color.Color) { func (dc *Context) SetColor(c color.Color) {
dc.setFillAndStrokeColor(c) dc.setFillAndStrokeColor(c)
} }