From 94d20784db4b8fab6fb4288d9ee94c2eb7825735 Mon Sep 17 00:00:00 2001 From: sunpawlonka Date: Tue, 25 Aug 2026 11:10:33 +0200 Subject: [PATCH 1/2] Add Insert entity support --- ACadSharp.Image/Rendering/EntityRenderDispatcher.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs b/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs index f82b860..5bcd762 100644 --- a/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs +++ b/ACadSharp.Image/Rendering/EntityRenderDispatcher.cs @@ -1,4 +1,4 @@ -using ACadSharp.Entities; +using ACadSharp.Entities; using ACadSharp.Extensions; using ACadSharp.IO; using ACadSharp.Tables; @@ -97,6 +97,9 @@ public void Draw(ImageRenderContext context, Entity entity) case IText text: this._configuration.Notify($"[{entity.SubclassMarker}] Text rendering is not implemented yet.", NotificationType.NotImplemented); break; + case Insert insert: + this.DrawBlockContents(context, insert); + break; default: this._configuration.Notify($"[{entity.SubclassMarker}] Drawing not implemented.", NotificationType.NotImplemented); break; @@ -169,6 +172,14 @@ private void DrawPolyline(ImageRenderContext context, ImageStyle style, IEnumera context.Canvas.Mutate(x => x.DrawLine(style.StrokeColor, style.StrokeWidth, points)); } + private void DrawBlockContents(ImageRenderContext context, Insert insert) + { + foreach (Entity entity in insert.Explode()) + { + Draw(context, entity); + } + } + /// /// Determines whether a polyline should be closed based on a heuristic. /// From c021380ed8e7f2fb20ada0880300da88ae6154df Mon Sep 17 00:00:00 2001 From: sunpawlonka Date: Tue, 25 Aug 2026 11:10:33 +0200 Subject: [PATCH 2/2] Add Insert entity rendering test --- ACadSharp.Image.Tests/ImageExporterTests.cs | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/ACadSharp.Image.Tests/ImageExporterTests.cs b/ACadSharp.Image.Tests/ImageExporterTests.cs index c152959..f522648 100644 --- a/ACadSharp.Image.Tests/ImageExporterTests.cs +++ b/ACadSharp.Image.Tests/ImageExporterTests.cs @@ -1,4 +1,4 @@ -using ACadSharp.Entities; +using ACadSharp.Entities; using ACadSharp.IO; using ACadSharp.Image.Rendering; using ACadSharp.Objects; @@ -165,6 +165,36 @@ public void RenderClosedPeriodicSplineDoesNotDrawSpokeToOrigin() Assert.Equal(SixLabors.ImageSharp.Color.White.ToPixel(), canvas[50, 50]); } + [Fact] + public void RenderInsertDrawsBlockContentsWithoutReportingNotImplemented() + { + BlockRecord insertedBlock = new("inserted-block"); + insertedBlock.Entities.Add(new Line(new XYZ(0, 0, 0), new XYZ(2, 1, 0))); + + BlockRecord pageBlock = new("insert-page"); + pageBlock.Entities.Add(new Insert(insertedBlock) + { + InsertPoint = new XYZ(3, 4, 0), + XScale = 2, + YScale = 3, + }); + + ImageExporter exporter = new(); + exporter.Configuration.Width = 100; + exporter.Configuration.Height = 100; + exporter.Configuration.SetPadding(10); + List notifications = new(); + exporter.Configuration.OnNotification += (_, args) => notifications.Add(args); + exporter.Add(pageBlock); + + using RenderedImagePage page = Assert.Single(exporter.Render()); + + Rgba32 white = SixLabors.ImageSharp.Color.White.ToPixel(); + Assert.DoesNotContain(notifications, n => n.NotificationType == NotificationType.NotImplemented && n.Message.Contains("Insert", StringComparison.OrdinalIgnoreCase)); + Assert.NotEqual(white, page.Canvas[10, 80]); + Assert.NotEqual(white, page.Canvas[90, 20]); + } + [Fact] public void RenderHandlesEntitiesWithNaNBoundingBox() {