gpu,op/clip: implement dashed stroked paths

Signed-off-by: Sebastien Binet <s@sbinet.org>
This commit is contained in:
Sebastien Binet
2020-12-09 09:59:46 +00:00
committed by Elias Naur
parent ac14320bec
commit e71bf13c9a
14 changed files with 745 additions and 7 deletions
+3
View File
@@ -33,6 +33,7 @@ const (
TypeCursor
TypePath
TypeStroke
TypeDash
)
const (
@@ -61,6 +62,7 @@ const (
TypeCursorLen = 1 + 1
TypePathLen = 1 + 4
TypeStrokeLen = 1 + 4 + 4 + 1 + 1
TypeDashLen = 1 + 4 + 1
)
func (t OpType) Size() int {
@@ -90,6 +92,7 @@ func (t OpType) Size() int {
TypeCursorLen,
TypePathLen,
TypeStrokeLen,
TypeDashLen,
}[t-firstOpIndex]
}
+193
View File
@@ -36,6 +36,28 @@ func TestPaintClippedRect(t *testing.T) {
})
}
func TestPaintClippedBorder(t *testing.T) {
run(t, func(o *op.Ops) {
var dashes clip.Dash
dashes.Begin(o)
dashes.Phase(1)
dashes.Dash(2)
dashes.Dash(1)
clip.Border{
Rect: f32.Rect(25, 25, 60, 60),
Width: 4,
Dashes: dashes.End(),
}.Add(o)
paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 50, 50)).Op())
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(25, 25, colornames.Red)
r.expect(50, 0, colornames.White)
r.expect(10, 50, colornames.White)
})
}
func TestPaintClippedCirle(t *testing.T) {
run(t, func(o *op.Ops) {
r := float32(10)
@@ -318,6 +340,177 @@ func TestStrokedPathZeroWidth(t *testing.T) {
})
}
func TestDashedPathFlatCapEllipse(t *testing.T) {
run(t, func(o *op.Ops) {
{
stk := op.Push(o)
p := newEllipsePath(o)
var dash clip.Dash
dash.Begin(o)
dash.Dash(5)
dash.Dash(3)
clip.Stroke{
Path: p,
Style: clip.StrokeStyle{
Width: 10,
Cap: clip.FlatCap,
Join: clip.BevelJoin,
Miter: float32(math.Inf(+1)),
},
Dashes: dash.End(),
}.Op().Add(o)
paint.Fill(
o,
red,
)
stk.Pop()
}
{
stk := op.Push(o)
p := newEllipsePath(o)
clip.Stroke{
Path: p,
Style: clip.StrokeStyle{
Width: 2,
},
}.Op().Add(o)
paint.Fill(
o,
black,
)
stk.Pop()
}
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(0, 62, colornames.Red)
r.expect(0, 65, colornames.Black)
})
}
func TestDashedPathFlatCapZ(t *testing.T) {
run(t, func(o *op.Ops) {
{
stk := op.Push(o)
p := newZigZagPath(o)
var dash clip.Dash
dash.Begin(o)
dash.Dash(5)
dash.Dash(3)
clip.Stroke{
Path: p,
Style: clip.StrokeStyle{
Width: 10,
Cap: clip.FlatCap,
Join: clip.BevelJoin,
Miter: float32(math.Inf(+1)),
},
Dashes: dash.End(),
}.Op().Add(o)
paint.Fill(o, red)
stk.Pop()
}
{
stk := op.Push(o)
p := newZigZagPath(o)
clip.Stroke{
Path: p,
Style: clip.StrokeStyle{Width: 2},
}.Op().Add(o)
paint.Fill(o, black)
stk.Pop()
}
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(40, 10, colornames.Black)
r.expect(40, 12, colornames.Red)
r.expect(46, 12, colornames.White)
})
}
func TestDashedPathFlatCapZNoDash(t *testing.T) {
run(t, func(o *op.Ops) {
{
stk := op.Push(o)
p := newZigZagPath(o)
var dash clip.Dash
dash.Begin(o)
dash.Phase(1)
clip.Stroke{
Path: p,
Style: clip.StrokeStyle{
Width: 10,
Cap: clip.FlatCap,
Join: clip.BevelJoin,
Miter: float32(math.Inf(+1)),
},
Dashes: dash.End(),
}.Op().Add(o)
paint.Fill(o, red)
stk.Pop()
}
{
stk := op.Push(o)
clip.Stroke{
Path: newZigZagPath(o),
Style: clip.StrokeStyle{Width: 2},
}.Op().Add(o)
paint.Fill(o, black)
stk.Pop()
}
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(40, 10, colornames.Black)
r.expect(40, 12, colornames.Red)
r.expect(46, 12, colornames.Red)
})
}
func TestDashedPathFlatCapZNoPath(t *testing.T) {
run(t, func(o *op.Ops) {
{
stk := op.Push(o)
var dash clip.Dash
dash.Begin(o)
dash.Dash(0)
clip.Stroke{
Path: newZigZagPath(o),
Style: clip.StrokeStyle{
Width: 10,
Cap: clip.FlatCap,
Join: clip.BevelJoin,
Miter: float32(math.Inf(+1)),
},
Dashes: dash.End(),
}.Op().Add(o)
paint.Fill(o, red)
stk.Pop()
}
{
stk := op.Push(o)
p := newZigZagPath(o)
clip.Stroke{
Path: p,
Style: clip.StrokeStyle{Width: 2},
}.Op().Add(o)
paint.Fill(o, black)
stk.Pop()
}
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(40, 10, colornames.Black)
r.expect(40, 12, colornames.White)
r.expect(46, 12, colornames.White)
})
}
func newStrokedPath(o *op.Ops) clip.PathSpec {
p := new(clip.Path)
p.Begin(o)
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B