From 4fcdd1e3e346b4fd0a81a372544def9fe1ee6c6b Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 25 Nov 2024 11:35:11 +0100 Subject: [PATCH] dxf true color fix --- .../DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs | 1 - .../IO/DXF/DxfStreamWriter/DxfObjectsSectionWriter.cs | 3 ++- .../IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs | 6 ++++-- .../IO/DXF/DxfStreamWriter/DxfStreamWriterBase.cs | 11 +++++++++++ .../IO/DXF/DxfStreamWriter/IDxfStreamWriter.cs | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs index ced9b81d..8a1e27fa 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs @@ -113,7 +113,6 @@ private void writeBookColor(BookColor color) 0b11000010 }; - //3269627904 uint rgb = LittleEndianConverter.Instance.ToUInt32(arr); this._writer.WriteBitLong((int)rgb); diff --git a/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfObjectsSectionWriter.cs b/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfObjectsSectionWriter.cs index 0d885b46..d51ae536 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfObjectsSectionWriter.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfObjectsSectionWriter.cs @@ -1,5 +1,6 @@ using ACadSharp.Entities; using ACadSharp.Objects; +using CSUtilities.Converters; using System; using System.Linq; @@ -101,7 +102,7 @@ protected void writeBookColor(BookColor color) this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.DbColor); this._writer.Write(62, color.Color.GetApproxIndex()); - this._writer.Write(420, color.Color.TrueColor); + this._writer.WriteTrueColor(420, color.Color); this._writer.Write(430, color.Name); } diff --git a/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs b/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs index bf390f69..30fca5aa 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs @@ -1,6 +1,8 @@ using ACadSharp.Entities; using ACadSharp.Tables; +using CSUtilities.Converters; using System; +using System.Drawing; namespace ACadSharp.IO.DXF { @@ -96,12 +98,12 @@ protected void writeCommonEntityData(Entity entity) if (entity.BookColor != null) { this._writer.Write(62, entity.BookColor.Color.GetApproxIndex()); - this._writer.Write(420, entity.BookColor.Color.TrueColor); + this._writer.WriteTrueColor(420, entity.BookColor.Color); this._writer.Write(430, entity.BookColor.Name); } else if (entity.Color.IsTrueColor) { - this._writer.Write(420, entity.Color.TrueColor); + this._writer.WriteTrueColor(420, entity.Color); } else { diff --git a/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfStreamWriterBase.cs b/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfStreamWriterBase.cs index d996f6d4..f71f5e82 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfStreamWriterBase.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfStreamWriterBase.cs @@ -31,6 +31,17 @@ public void Write(int code, CSMath.IVector value, DxfClassMap map) } } + public void WriteTrueColor(int code, Color color, DxfClassMap map = null) + { + byte[] arr = new byte[4]; + arr[0] = (byte)color.B; + arr[1] = (byte)color.G; + arr[2] = (byte)color.R; + arr[3] = 0; + + this.Write(code, LittleEndianConverter.Instance.ToInt32(arr), map); + } + public void WriteCmColor(int code, Color color, DxfClassMap map = null) { if (GroupCodeValue.TransformValue(code) == GroupCodeValueType.Int16) diff --git a/src/ACadSharp/IO/DXF/DxfStreamWriter/IDxfStreamWriter.cs b/src/ACadSharp/IO/DXF/DxfStreamWriter/IDxfStreamWriter.cs index c0a52b8f..dd9a65c2 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamWriter/IDxfStreamWriter.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamWriter/IDxfStreamWriter.cs @@ -15,6 +15,8 @@ internal interface IDxfStreamWriter : IDisposable void Write(int code, IVector value, DxfClassMap map = null); + void WriteTrueColor(int code, Color color, DxfClassMap map = null); + void WriteCmColor(int code, Color color, DxfClassMap map = null); void WriteHandle(int code, IHandledCadObject value, DxfClassMap map = null);