From b73d093683db611bec8529358ad31d397c032548 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Tue, 18 Sep 2018 15:17:04 +0200 Subject: [PATCH] implemented line dash offset --- README.md | 2 +- canvas.go | 4 ++++ canvas_test.go | 29 +++++++++++++++++++++++++++++ testdata/LineDashOffset.png | Bin 0 -> 445 bytes 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 testdata/LineDashOffset.png 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 0000000000000000000000000000000000000000..c1c20ae0e3ac563377a54e540a876aad35f93dce GIT binary patch literal 445 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-WmfQhQJlS z{_ppR*UlAAHSqJXdj7HN_S7_8g9~-CQfWE|A{sU_Br_gk>S2}OHV{j|CUD^U-~Uyz z$A5m*ueaKLe9qhX_bs2@JTLV)z6OfOl*rb15TP^oKMYDY}>y)0W_b)0-@A=*aHs!-1 zTkS*DhcmtWuI+ul|G)G%|AI|Z4xeQ5I`--9IW|~mEO^3p-)Pg~^nY_#PhKkHhdq2? h-iL0fM literal 0 HcmV?d00001