From 11bb86166a5b29eb95f1180d3add751fae4e7edc Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Sun, 19 Dec 2021 17:09:54 +0100 Subject: [PATCH] op/clip: automatically close Path in Outlines Unclosed path segments in Path will be automatically closed by a line. Fixes: https://todo.sr.ht/~eliasnaur/gio/320 Signed-off-by: Pierre Curto --- gpu/compute.go | 15 +++-- gpu/gpu.go | 6 ++ .../refs/TestGapsInPath/Outline.png | Bin 0 -> 408 bytes .../rendertest/refs/TestGapsInPath/Stroke.png | Bin 0 -> 488 bytes gpu/internal/rendertest/render_test.go | 54 ++++++++++++++++++ gpu/internal/rendertest/util_test.go | 16 +++++- internal/scene/scene.go | 25 +++++++- internal/stroke/stroke.go | 2 + op/clip/clip.go | 22 ++++--- op/clip/clip_test.go | 11 ---- 10 files changed, 123 insertions(+), 28 deletions(-) create mode 100644 gpu/internal/rendertest/refs/TestGapsInPath/Outline.png create mode 100644 gpu/internal/rendertest/refs/TestGapsInPath/Stroke.png diff --git a/gpu/compute.go b/gpu/compute.go index ee6e127c..625658c7 100644 --- a/gpu/compute.go +++ b/gpu/compute.go @@ -1186,12 +1186,19 @@ func min(p1, p2 f32.Point) f32.Point { return p } -func (enc *encoder) encodePath(verts []byte) { - for len(verts) >= scene.CommandSize+4 { +func (enc *encoder) encodePath(verts []byte, fillMode int) { + for ; len(verts) >= scene.CommandSize+4; verts = verts[scene.CommandSize+4:] { cmd := ops.DecodeCommand(verts[4:]) + if cmd.Op() == scene.OpGap { + if fillMode != scene.FillModeNonzero { + // Skip gaps in strokes. + continue + } + // Replace them by a straight line in outlines. + cmd = scene.Line(scene.DecodeGap(cmd)) + } enc.scene = append(enc.scene, cmd) enc.npathseg++ - verts = verts[scene.CommandSize+4:] } } @@ -2109,7 +2116,7 @@ func encodeOp(viewport image.Point, absOff image.Point, enc *encoder, texOps []t if len(cl.path) == 0 { enc.rect(cl.state.bounds) } else { - enc.encodePath(cl.path) + enc.encodePath(cl.path, fillMode) } if i != 0 { enc.beginClip(cl.union.Add(absOfff)) diff --git a/gpu/gpu.go b/gpu/gpu.go index dd2161d2..0bd15c69 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -1344,6 +1344,12 @@ func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) { q.Ctrl = q.From.Add(q.To).Mul(.5) q = q.Transform(tr) qs.splitAndEncode(q) + case scene.OpGap: + var q stroke.QuadSegment + q.From, q.To = scene.DecodeGap(cmd) + q.Ctrl = q.From.Add(q.To).Mul(.5) + q = q.Transform(tr) + qs.splitAndEncode(q) case scene.OpQuad: var q stroke.QuadSegment q.From, q.Ctrl, q.To = scene.DecodeQuad(cmd) diff --git a/gpu/internal/rendertest/refs/TestGapsInPath/Outline.png b/gpu/internal/rendertest/refs/TestGapsInPath/Outline.png new file mode 100644 index 0000000000000000000000000000000000000000..aa0a7749307cffe20070cb4ef5d1e2a78fe15571 GIT binary patch literal 408 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrV2t;4aSW-L^XAGy&ISVk)>S%XoxS!H=PksYBRd4#OiB0rdt8 r(u5j}|5NGgo^>bP0l+XkKfva(K literal 0 HcmV?d00001 diff --git a/gpu/internal/rendertest/refs/TestGapsInPath/Stroke.png b/gpu/internal/rendertest/refs/TestGapsInPath/Stroke.png new file mode 100644 index 0000000000000000000000000000000000000000..1420f6b7ae73562e325f458e595e1a3501ab1c3b GIT binary patch literal 488 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrU|jF%;uumf=gn