Skip to content

Commit

Permalink
Merge pull request #287 from DomCR/Write-TrueColor-dwg-dxf
Browse files Browse the repository at this point in the history
Write true color dwg dxf
  • Loading branch information
DomCR authored Feb 27, 2024
2 parents caad93b + 9e656e0 commit ed9870b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public void DefaultLayer()
this.Document.Layers.Add(new Layer("default_layer"));
}

public void LayerTrueColor()
{
Layer layer = new Layer("Layer_true_color");
layer.Color = Color.FromTrueColor(1151726);

this.Document.Layers.Add(layer);
}

public void EntityColorByLayer()
{
Layer layer = new Layer("Test");
Expand Down Expand Up @@ -171,6 +179,7 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.EntityColorByLayer)));
Data.Add(new(nameof(SingleCaseGenerator.EntityColorTrueColor)));
Data.Add(new(nameof(SingleCaseGenerator.DefaultLayer)));
Data.Add(new(nameof(SingleCaseGenerator.LayerTrueColor)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMText)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMTextSpecialCharacter)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMTextMultiline)));
Expand Down
2 changes: 2 additions & 0 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderAC18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public override Color ReadEnColor(out Transparency transparency, out bool flag)
{
//color flags: first byte of the bitshort.
ushort flags = (ushort)((ushort)size & 0b1111111100000000);

//0x4000: has AcDbColor reference (0x8000 is also set in this case).
if ((flags & 0x4000) > 0)
{
Expand All @@ -83,6 +84,7 @@ public override Color ReadEnColor(out Transparency transparency, out bool flag)
else if ((flags & 0x8000) > 0)
{
//Next value is a BS containing the RGB value(last 24 bits).
//flags: 0b1100_0010_0000_0000_0000_0000_0000_0000
uint rgb = (uint)this.ReadBitLong();
color = Color.FromTrueColor(rgb & 0b00000000111111111111111111111111);
}
Expand Down
11 changes: 6 additions & 5 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgStreamWriterAC18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public override void WriteCmColor(Color value)

if (value.IsTrueColor)
{
arr[0] = (byte)(value.R);
arr[1] = (byte)(value.G);
arr[2] = (byte)(value.B);
arr[0] = (byte)value.R;
arr[1] = (byte)value.G;
arr[2] = (byte)value.B;
arr[3] = 0b1100_0010;
}
else
Expand Down Expand Up @@ -55,7 +55,7 @@ public override void WriteEnColor(Color color, Transparency transparency)
//0x2000: color is followed by a transparency BL
if (!transparency.IsByLayer)
{
size = (ushort)(size | 0x2000);
size = (ushort)(size | 0b10000000000000);
}

//0x8000: complex color (rgb).
Expand All @@ -73,7 +73,8 @@ public override void WriteEnColor(Color color, Transparency transparency)

if (color.IsTrueColor)
{
base.WriteBitLong(color.TrueColor);
uint rgb = (uint)(0b1100_0010_0000_0000_0000_0000_0000_0000 | color.TrueColor);
base.WriteBitLong((int)rgb);
}

if (!transparency.IsByLayer)
Expand Down

0 comments on commit ed9870b

Please sign in to comment.