From f685e7c1635d7f129bbea81ea49dd23f921402b4 Mon Sep 17 00:00:00 2001 From: wsw Date: Thu, 8 Dec 2016 13:11:16 +0800 Subject: [PATCH] default fill/stoke (black on white) --- context.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/context.go b/context.go index d62e2cb..c7b43fa 100644 --- a/context.go +++ b/context.go @@ -44,6 +44,11 @@ const ( AlignRight ) +var ( + defaultFillStyle = NewSolidPattern(color.White) + defaultStrokeStyle = NewSolidPattern(color.Black) +) + type Context struct { width int height int @@ -84,15 +89,17 @@ func NewContextForImage(im image.Image) *Context { // No copy is made. func NewContextForRGBA(im *image.RGBA) *Context { return &Context{ - width: im.Bounds().Size().X, - height: im.Bounds().Size().Y, - im: im, - color: color.Transparent, - lineWidth: 1, - fillRule: FillRuleWinding, - fontFace: basicfont.Face7x13, - fontHeight: 13, - matrix: Identity(), + width: im.Bounds().Size().X, + height: im.Bounds().Size().Y, + im: im, + color: color.Transparent, + fillPattern: defaultFillStyle, + strokePattern: defaultStrokeStyle, + lineWidth: 1, + fillRule: FillRuleWinding, + fontFace: basicfont.Face7x13, + fontHeight: 13, + matrix: Identity(), } } @@ -182,6 +189,10 @@ func (dc *Context) setFillAndStrokeColor(c color.Color) { // SetFillStyle sets current fill style 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 } @@ -190,7 +201,7 @@ func (dc *Context) SetStrokeStyle(pattern 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) { dc.setFillAndStrokeColor(c) }