diff --git a/ACadSharp.Image.Tests/EntityRenderDispatcherTests.cs b/ACadSharp.Image.Tests/EntityRenderDispatcherTests.cs index 2fe755a..dee31db 100644 --- a/ACadSharp.Image.Tests/EntityRenderDispatcherTests.cs +++ b/ACadSharp.Image.Tests/EntityRenderDispatcherTests.cs @@ -390,6 +390,24 @@ public void PatternHatchDrawsClippedLines() Assert.All(surface.Styles, s => Assert.Null(s.DashPattern)); } + [Fact] + public void PredefinedPatternHatchDrawsItsPatternRatherThanAFill() + { + // DXF group 76 (Hatch.PatternType) is 0 = user-defined, 1 = predefined, 2 = custom. ACadSharp names the value + // 1 "SolidFill", but a hatch read from a file with a predefined pattern such as ANSI31 carries exactly that + // value with IsSolid (group 70) false. Group 70 alone says whether a hatch is a solid fill. + RecordingDrawingSurface surface = new(); + ImageConfiguration configuration = new(); + EntityRenderDispatcher dispatcher = new(configuration); + Hatch hatch = SquareHatch(solid: false); + hatch.PatternType = HatchPatternType.SolidFill; + + dispatcher.Draw(CreateContext(surface, configuration), hatch); + + Assert.DoesNotContain(surface.Calls, c => c.StartsWith("FillPath", StringComparison.Ordinal)); + Assert.InRange(surface.Calls.Count(c => c.StartsWith("DrawLine", StringComparison.Ordinal)), 5, 9); + } + [Fact] public void PatternHatchIsCappedWithWarning() { diff --git a/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs b/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs index f697b1f..4575fa6 100644 --- a/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs +++ b/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs @@ -1689,7 +1689,10 @@ private void DrawHatch(ImageRenderContext context, ImageStyle style, Hatch hatch OcsTransform? toWorld = IsWorldPlane(hatch.Normal) ? null : OcsTransform.For(hatch.Normal); SurfacePoint ToSurface(XYZ point) => context.ToSurfacePoint(InsertPlacement.MapOcsPoint(placement, toWorld, hatch.Elevation, point)); - if (hatch.IsSolid || hatch.PatternType == HatchPatternType.SolidFill) + // Only the solid-fill flag (DXF group 70) says a hatch is a fill. Hatch.PatternType is DXF group 76, whose value + // 1 means "predefined pattern" even though ACadSharp names it SolidFill: every hatch read from a file with a + // stock pattern such as ANSI31 carries it, and testing for it here filled all of those solid. + if (hatch.IsSolid) { List> rings = new(); foreach (Hatch.BoundaryPath path in hatch.Paths)