diff --git a/README.md b/README.md index 19f5e49..8a2130c 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ These features *should* work just like their HTML5 counterparts, but there are l - miterLimit - lineDash - getLineDash +- lineDashOffset - global alpha - drawImage - getImageData @@ -123,7 +124,6 @@ These features *should* work just like their HTML5 counterparts, but there are l # Missing features - globalCompositeOperation -- lineDashOffset - textBaseline - isPointInPath - isPointInStroke diff --git a/canvas.go b/canvas.go index fec495a..2338a6e 100644 --- a/canvas.go +++ b/canvas.go @@ -684,6 +684,10 @@ func (cv *Canvas) SetLineDash(dash []float64) { cv.state.lineDashOffset = 0 } +func (cv *Canvas) SetLineDashOffset(offset float64) { + cv.state.lineDashOffset = offset +} + // GetLineDash gets the line dash style func (cv *Canvas) GetLineDash() []float64 { result := make([]float64, len(cv.state.lineDash)) diff --git a/canvas_test.go b/canvas_test.go index 79bcfa4..8bb79c2 100644 --- a/canvas_test.go +++ b/canvas_test.go @@ -239,6 +239,35 @@ func TestLineDash(t *testing.T) { }) } +func TestLineDashOffset(t *testing.T) { + run(t, func(cv *canvas.Canvas) { + cv.SetStrokeStyle("#0F0") + cv.SetLineWidth(2.5) + cv.SetLineDash([]float64{4, 6, 8}) + cv.SetLineDashOffset(5) + cv.BeginPath() + cv.MoveTo(20, 20) + cv.LineTo(80, 20) + cv.LineTo(80, 80) + cv.LineTo(50, 80) + cv.LineTo(50, 50) + cv.LineTo(20, 50) + cv.ClosePath() + cv.MoveTo(30, 30) + cv.LineTo(70, 30) + cv.LineTo(70, 70) + cv.LineTo(60, 70) + cv.LineTo(60, 40) + cv.LineTo(30, 40) + cv.ClosePath() + cv.Stroke() + ld := cv.GetLineDash() + if ld[0] != 4 || ld[1] != 6 || ld[2] != 8 || ld[3] != 4 || ld[4] != 6 || ld[5] != 8 { + t.Fail() + } + }) +} + func TestCurves(t *testing.T) { run(t, func(cv *canvas.Canvas) { cv.SetStrokeStyle("#00F") diff --git a/testdata/LineDashOffset.png b/testdata/LineDashOffset.png new file mode 100755 index 0000000..c1c20ae Binary files /dev/null and b/testdata/LineDashOffset.png differ