implemented line dash offset

This commit is contained in:
Thomas Friedel 2018-09-18 15:17:04 +02:00
parent e887b6ad3e
commit b73d093683
4 changed files with 34 additions and 1 deletions

View file

@ -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

View file

@ -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))

View file

@ -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")

BIN
testdata/LineDashOffset.png vendored Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B