NewSubPath

This commit is contained in:
Michael Fogleman 2016-02-21 22:22:17 -05:00
parent c8a59bf5b5
commit 68ecba1329
2 changed files with 18 additions and 7 deletions

View File

@ -58,6 +58,7 @@ QuadraticTo(x1, y1, x2, y2 float64)
CubicTo(x1, y1, x2, y2, x3, y3 float64) CubicTo(x1, y1, x2, y2, x3, y3 float64)
ClosePath() ClosePath()
ClearPath() ClearPath()
NewSubPath()
Clear() Clear()
Stroke() Stroke()

View File

@ -42,6 +42,7 @@ type Context struct {
fillPath raster.Path fillPath raster.Path
start Point start Point
current Point current Point
hasCurrent bool
lineWidth float64 lineWidth float64
lineCap LineCap lineCap LineCap
lineJoin LineJoin lineJoin LineJoin
@ -169,7 +170,7 @@ func (dc *Context) SetRGB(r, g, b float64) {
// Path Manipulation // Path Manipulation
func (dc *Context) MoveTo(x, y float64) { func (dc *Context) MoveTo(x, y float64) {
if len(dc.fillPath) > 0 { if dc.hasCurrent {
dc.fillPath.Add1(dc.start.Fixed()) dc.fillPath.Add1(dc.start.Fixed())
} }
x, y = dc.TransformPoint(x, y) x, y = dc.TransformPoint(x, y)
@ -178,10 +179,11 @@ func (dc *Context) MoveTo(x, y float64) {
dc.fillPath.Start(p.Fixed()) dc.fillPath.Start(p.Fixed())
dc.start = p dc.start = p
dc.current = p dc.current = p
dc.hasCurrent = true
} }
func (dc *Context) LineTo(x, y float64) { func (dc *Context) LineTo(x, y float64) {
if len(dc.strokePath) == 0 { if !dc.hasCurrent {
dc.MoveTo(x, y) dc.MoveTo(x, y)
} else { } else {
x, y = dc.TransformPoint(x, y) x, y = dc.TransformPoint(x, y)
@ -193,7 +195,7 @@ func (dc *Context) LineTo(x, y float64) {
} }
func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64) { func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64) {
if len(dc.strokePath) == 0 { if !dc.hasCurrent {
dc.MoveTo(x1, y1) dc.MoveTo(x1, y1)
} }
x1, y1 = dc.TransformPoint(x1, y1) x1, y1 = dc.TransformPoint(x1, y1)
@ -206,7 +208,7 @@ func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64) {
} }
func (dc *Context) CubicTo(x1, y1, x2, y2, x3, y3 float64) { func (dc *Context) CubicTo(x1, y1, x2, y2, x3, y3 float64) {
if len(dc.strokePath) == 0 { if !dc.hasCurrent {
dc.MoveTo(x1, y1) dc.MoveTo(x1, y1)
} }
x0, y0 := dc.current.X, dc.current.Y x0, y0 := dc.current.X, dc.current.Y
@ -229,7 +231,7 @@ func (dc *Context) CubicTo(x1, y1, x2, y2, x3, y3 float64) {
} }
func (dc *Context) ClosePath() { func (dc *Context) ClosePath() {
if len(dc.strokePath) > 0 { if dc.hasCurrent {
dc.strokePath.Add1(dc.start.Fixed()) dc.strokePath.Add1(dc.start.Fixed())
dc.fillPath.Add1(dc.start.Fixed()) dc.fillPath.Add1(dc.start.Fixed())
dc.current = dc.start dc.current = dc.start
@ -239,6 +241,14 @@ func (dc *Context) ClosePath() {
func (dc *Context) ClearPath() { func (dc *Context) ClearPath() {
dc.strokePath.Clear() dc.strokePath.Clear()
dc.fillPath.Clear() dc.fillPath.Clear()
dc.hasCurrent = false
}
func (dc *Context) NewSubPath() {
if dc.hasCurrent {
dc.fillPath.Add1(dc.start.Fixed())
}
dc.hasCurrent = false
} }
// Path Drawing // Path Drawing
@ -280,8 +290,8 @@ func (dc *Context) Stroke() {
} }
func (dc *Context) FillPreserve() { func (dc *Context) FillPreserve() {
var path raster.Path path := dc.fillPath
if len(dc.fillPath) > 0 { if dc.hasCurrent {
path = make(raster.Path, len(dc.fillPath)) path = make(raster.Path, len(dc.fillPath))
copy(path, dc.fillPath) copy(path, dc.fillPath)
path.Add1(dc.start.Fixed()) path.Add1(dc.start.Fixed())