diff --git a/src/ACadSharp/Entities/ProxyEntity.cs b/src/ACadSharp/Entities/ProxyEntity.cs
index e02b1baf0..b837c48c0 100644
--- a/src/ACadSharp/Entities/ProxyEntity.cs
+++ b/src/ACadSharp/Entities/ProxyEntity.cs
@@ -1,6 +1,7 @@
using ACadSharp.Attributes;
using ACadSharp.Classes;
using CSMath;
+using System.IO;
namespace ACadSharp.Entities
{
@@ -64,6 +65,10 @@ public class ProxyEntity : Entity, IProxy
//An object ID(multiple entries can appear) (optional)
//94 0 (indicates end of object ID section)
+ ///
+ /// No DxfCodeValue: the DXF reader has no handler for code 311 on an entity.
+ public Stream Data { get; set; }
+
///
public ACadVersion Version { get; set; }
diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
index 88239dd14..9430589e3 100644
--- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
+++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
@@ -72,6 +72,8 @@ internal partial class DwgObjectReader : DwgSectionIO
///
private IDwgStreamReader _handlesReader;
+ private long _handleSectionOffset = -1;
+
private IDwgStreamReader _mergedReaders;
private long _objectInitialPos = 0;
@@ -234,7 +236,7 @@ private ObjectType getEntityType(long offset)
ulong handleSize = this._crcReader.ReadModularChar();
//Find the handles offset
- ulong handleSectionOffset = (ulong)this._crcReader.PositionInBits() + sizeInBits - handleSize;
+ this._handleSectionOffset = (long)((ulong)this._crcReader.PositionInBits() + sizeInBits - handleSize);
//Create a handler section reader
this._objectReader = DwgStreamReaderBase.GetStreamHandler(this._version, HugeMemoryStream.Clone(this._memoryStream), this._reader.Encoding);
@@ -246,11 +248,11 @@ private ObjectType getEntityType(long offset)
//Create a handler section reader
this._handlesReader = DwgStreamReaderBase.GetStreamHandler(this._version, HugeMemoryStream.Clone(this._memoryStream), this._reader.Encoding);
- this._handlesReader.SetPositionInBits((long)handleSectionOffset);
+ this._handlesReader.SetPositionInBits(this._handleSectionOffset);
//Create a text section reader
this._textReader = DwgStreamReaderBase.GetStreamHandler(this._version, HugeMemoryStream.Clone(this._memoryStream), this._reader.Encoding);
- this._textReader.SetPositionByFlag((long)handleSectionOffset - 1);
+ this._textReader.SetPositionByFlag(this._handleSectionOffset - 1);
this._mergedReaders = new DwgMergedReader(this._objectReader, this._textReader, this._handlesReader);
}
@@ -1181,8 +1183,18 @@ private void readCommonProxyData(IProxy proxy)
//Common:
//Databits X databits, however many there are to the handles
+ //The retained data has no length of its own, it runs up to the handle section
+ if (this._handleSectionOffset > 0)
+ {
+ long dataBits = this._handleSectionOffset - this._objectReader.PositionInBits();
+ if (dataBits > 0)
+ {
+ int dataBytes = (int)((dataBits + 7L) / 8L);
+ byte[] data = this._objectReader.ReadBytes(dataBytes);
- //TODO: Investigate how to read the data in proxies, it can contain data, strings and handles
+ proxy.Data = new MemoryStream(data, writable: false);
+ }
+ }
}
private CadTemplate readDbColor()
diff --git a/src/ACadSharp/IProxy.cs b/src/ACadSharp/IProxy.cs
index ea6939799..df41357fe 100644
--- a/src/ACadSharp/IProxy.cs
+++ b/src/ACadSharp/IProxy.cs
@@ -1,4 +1,5 @@
using ACadSharp.Classes;
+using System.IO;
namespace ACadSharp;
@@ -29,5 +30,10 @@ public interface IProxy
///
int ProxyClassId { get; }
+ ///
+ /// Gets or sets the retained data of the original object.
+ ///
+ Stream Data { get; set; }
+
ACadVersion Version { get; set; }
}
diff --git a/src/ACadSharp/Objects/ProxyObject.cs b/src/ACadSharp/Objects/ProxyObject.cs
index a0beef042..ce26d8079 100644
--- a/src/ACadSharp/Objects/ProxyObject.cs
+++ b/src/ACadSharp/Objects/ProxyObject.cs
@@ -53,6 +53,7 @@ public class ProxyObject : NonGraphicalObject, IProxy
[DxfCodeValue(310)]
public Stream BinaryData { get; set; }
+ ///
[DxfCodeValue(311)]
public Stream Data { get; set; }