Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue 558 dwg thumbnail support #563

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
hardcoded preview
  • Loading branch information
DomCR committed Feb 18, 2025
commit f58b4302eea45881cfdc08b5e64f207770622064
31 changes: 31 additions & 0 deletions src/ACadSharp/IO/DWG/DwgStreamWriters/DwgPreviewWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,36 @@ public void Write()
this._swriter.WriteByte(0);
this._swriter.WriteBytes(_endSentinel);
}

public void Write(DwgPreview preview, Stream stream)
{
//1745
var a = preview.RawHeader.Length + preview.RawImage.Length + 19;
var c = 1745 - a;

this._swriter.WriteBytes(_startSentinel);

this._swriter.WriteRawLong(a); //4

this._swriter.WriteByte(2); //1

this._swriter.WriteByte(1); //1
var e = stream.Position + this._swriter.Stream.Position + 12 + 5;
this._swriter.WriteRawLong(2727); //4
this._swriter.WriteRawLong(preview.RawHeader.Length); //4

this._swriter.WriteByte(6); //1
var f = stream.Position + this._swriter.Stream.Position + 12 + 6;
this._swriter.WriteRawLong(2807); //4
this._swriter.WriteRawLong(preview.RawImage.Length); //4

var off = stream.Position + this._swriter.Stream.Position; //2695, correct: 2727
this._swriter.WriteBytes(preview.RawHeader);

var off1 = stream.Position + this._swriter.Stream.Position;//2775
this._swriter.WriteBytes(preview.RawImage);

this._swriter.WriteBytes(_endSentinel);
}
}
}
12 changes: 11 additions & 1 deletion src/ACadSharp/IO/DWG/DwgWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace ACadSharp.IO
/// </summary>
public class DwgWriter : CadWriterBase<DwgWriterConfiguration>
{
public DwgPreview Preview { get; set; }

private ACadVersion _version { get { return this._document.Header.Version; } }

private DwgFileHeader _fileHeader;
Expand Down Expand Up @@ -221,7 +223,15 @@ private void writePreview()
{
MemoryStream stream = new MemoryStream();
DwgPreviewWriter writer = new DwgPreviewWriter(this._version, stream);
writer.Write();

if (this.Preview != null)
{
writer.Write(this.Preview, this._stream);
}
else
{
writer.Write();
}

this._fileHeaderWriter.AddSection(DwgSectionDefinition.Preview, stream, false, 0x400);
}
Expand Down