diff --git a/.gitignore b/.gitignore index 4e61c3c8e..1d55df50f 100644 --- a/.gitignore +++ b/.gitignore @@ -234,3 +234,6 @@ SixLabors.Shapes.Coverage.xml /plans/ samples/Avalonia** + +# Local specifications +specs/ diff --git a/src/ImageSharp.Drawing.WebGPU/WebGPUSceneEncoder.cs b/src/ImageSharp.Drawing.WebGPU/WebGPUSceneEncoder.cs index bb25b67d3..02085d861 100644 --- a/src/ImageSharp.Drawing.WebGPU/WebGPUSceneEncoder.cs +++ b/src/ImageSharp.Drawing.WebGPU/WebGPUSceneEncoder.cs @@ -3429,7 +3429,7 @@ private void AppendPlainStroke( GpuSceneDrawMonoid drawTagMonoid = GpuSceneDrawTag.Map(drawTag); Rectangle interestBounds = ToTargetLocal(command.RasterizerOptions.Interest, this.rootTargetBounds); (uint style0, uint style1, uint style2, uint style3, uint style4, uint style5, uint style6, uint style7, uint style8, uint style9) = - GetStrokeStyle(command.GraphicsOptions, pen, widthScale, interestBounds); + GetStrokeStyle(command.GraphicsOptions, pen, widthScale, interestBounds, command.RasterizerOptions.CoverageBoost); int pathTagCheckpoint = this.PathTags.Count; int styleCheckpoint = this.Styles.Count; bool appendStyle = !this.hasLastStyle || @@ -3572,7 +3572,7 @@ private void AppendExplicitStroke( GpuSceneDrawMonoid drawTagMonoid = GpuSceneDrawTag.Map(drawTag); Rectangle interestBounds = ToTargetLocal(rasterizerOptions.Interest, this.rootTargetBounds); (uint style0, uint style1, uint style2, uint style3, uint style4, uint style5, uint style6, uint style7, uint style8, uint style9) = - GetStrokeStyle(graphicsOptions, pen, widthScale, interestBounds); + GetStrokeStyle(graphicsOptions, pen, widthScale, interestBounds, rasterizerOptions.CoverageBoost); int pathTagCheckpoint = this.PathTags.Count; int styleCheckpoint = this.Styles.Count; bool appendStyle = !this.hasLastStyle || @@ -3711,7 +3711,7 @@ private void AppendExplicitStroke( GpuSceneDrawMonoid drawTagMonoid = GpuSceneDrawTag.Map(drawTag); Rectangle interestBounds = ToTargetLocal(rasterizerOptions.Interest, this.rootTargetBounds); (uint style0, uint style1, uint style2, uint style3, uint style4, uint style5, uint style6, uint style7, uint style8, uint style9) = - GetStrokeStyle(graphicsOptions, pen, widthScale, interestBounds); + GetStrokeStyle(graphicsOptions, pen, widthScale, interestBounds, rasterizerOptions.CoverageBoost); int pathTagCheckpoint = this.PathTags.Count; int styleCheckpoint = this.Styles.Count; bool appendStyle = !this.hasLastStyle || @@ -7561,17 +7561,9 @@ private static int EncodeStrokePath( int segmentCount = keptCount - 1; - // Match the CPU closure rule. A contour with at least three source points is closed - // when it is declared closed or its endpoints are within one scaled stroke width. - bool isClosed = false; - if (contourPoints.Length >= 3) - { - PointF last = contourPoints[^1]; - float closeThreshold = MathF.Max(strokeWidth, 1E-3F); - isClosed = contour.IsClosed || - firstPoint == last || - Vector2.DistanceSquared(firstPoint, last) <= closeThreshold * closeThreshold; - } + // An open path with a gap needs caps, even when the gap is shorter than the stroke width. + bool isClosed = contourPoints.Length >= 3 && + (contour.IsClosed || firstPoint == contourPoints[^1]); bool duplicateClosingPoint = keptCount > 1 && lastKept == firstPoint; int distinctPointCount = keptCount - (isClosed && duplicateClosingPoint ? 1 : 0); @@ -8774,9 +8766,8 @@ private static void AppendIdentityTransform(ref OwnedStream transforms) /// /// /// Word layout consumed by path_lowering.wgsl: 0 = style flags, 1 = device-space stroke width, - /// 2 = packed draw flags, 3 = miter limit, 4 = arc detail scale, 5 = zero, + /// 2 = packed draw flags, 3 = miter limit, 4 = arc detail scale, 5 = coverage boost, /// 6-9 = target-local interest rectangle as left, top, right, bottom. - /// Strokes do not use antialiased text coverage boost data, so word 5 is zero in both modes. /// /// Bits 0-10 of word 0 hold the arc limit: the interior vertex count of a round arc of /// half a turn, from . The shader clamps the vertex count of @@ -8789,6 +8780,7 @@ private static void AppendIdentityTransform(ref OwnedStream transforms) /// The pen that defines stroke width, joins, caps, and miter limit. /// The transform-derived scale applied to the stroke width. /// The target-local raster interest bounds. + /// The coverage boost for antialiased text strokes. /// The ten packed style words. [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ( @@ -8805,7 +8797,8 @@ private static ( GraphicsOptions options, Pen pen, float widthScale, - Rectangle interestBounds) + Rectangle interestBounds, + float coverageBoost) { StyleFlags styleFlags = StyleFlags.Stroke | EncodeStrokeJoinFlags(pen.StrokeOptions.LineJoin) @@ -8825,7 +8818,7 @@ private static ( PackStyleDrawFlags(options), BitcastSingle((float)pen.StrokeOptions.MiterLimit), BitcastSingle((float)pen.StrokeOptions.ArcDetailScale), - 0U, + options.Antialias ? BitcastSingle(coverageBoost) : 0U, BitcastSingle(interestBounds.Left), BitcastSingle(interestBounds.Top), BitcastSingle(interestBounds.Right), diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index 624e49355..84eaeff59 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -46,7 +46,7 @@ - +