Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Write true color dwg dxf #287

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading