Skip to content

Commit

Permalink
dxf true color fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Nov 25, 2024
1 parent d046dff commit 4fcdd1e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private void writeBookColor(BookColor color)
0b11000010
};

//3269627904
uint rgb = LittleEndianConverter.Instance.ToUInt32(arr);

this._writer.WriteBitLong((int)rgb);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ACadSharp.Entities;
using ACadSharp.Objects;
using CSUtilities.Converters;
using System;
using System.Linq;

Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions src/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using ACadSharp.Entities;
using ACadSharp.Tables;
using CSUtilities.Converters;
using System;
using System.Drawing;

namespace ACadSharp.IO.DXF
{
Expand Down Expand Up @@ -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
{
Expand Down
11 changes: 11 additions & 0 deletions src/ACadSharp/IO/DXF/DxfStreamWriter/DxfStreamWriterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/ACadSharp/IO/DXF/DxfStreamWriter/IDxfStreamWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4fcdd1e

Please sign in to comment.