From 6d5de6e912f53c121a5906cfb8a08b34300f36f3 Mon Sep 17 00:00:00 2001 From: Sergiusz Zalewski <38229504+KeterSCP@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:38:46 +0100 Subject: [PATCH] EMR_DELETEOBJECT --- SharpEmf.sln.DotSettings | 1 + src/SharpEmf/Enums/EmfRecordType.cs | 5 +++ .../Records/EnhancedMetafileRecord.cs | 1 + .../ObjectManipulation/EmrDeleteObject.cs | 43 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/SharpEmf/Records/ObjectManipulation/EmrDeleteObject.cs diff --git a/SharpEmf.sln.DotSettings b/SharpEmf.sln.DotSettings index 85b515d..73d801c 100644 --- a/SharpEmf.sln.DotSettings +++ b/SharpEmf.sln.DotSettings @@ -10,6 +10,7 @@ True True True + True True True True diff --git a/src/SharpEmf/Enums/EmfRecordType.cs b/src/SharpEmf/Enums/EmfRecordType.cs index 21e12e0..741a4fa 100644 --- a/src/SharpEmf/Enums/EmfRecordType.cs +++ b/src/SharpEmf/Enums/EmfRecordType.cs @@ -110,6 +110,11 @@ public enum EmfRecordType : uint /// EMR_SELECTOBJECT = 0x00000025, + /// + /// Deletes a graphics object, clearing its index in the EMF object table + /// + EMR_DELETEOBJECT = 0x00000028, + /// /// Defines a line segment of an arc /// diff --git a/src/SharpEmf/Records/EnhancedMetafileRecord.cs b/src/SharpEmf/Records/EnhancedMetafileRecord.cs index 3a61af8..07e0c2b 100644 --- a/src/SharpEmf/Records/EnhancedMetafileRecord.cs +++ b/src/SharpEmf/Records/EnhancedMetafileRecord.cs @@ -55,6 +55,7 @@ public static EnhancedMetafileRecord Parse(Stream stream) EmfRecordType.EMR_EXCLUDECLIPRECT => EmrExcludeClipRect.Parse, EmfRecordType.EMR_INTERSECTCLIPRECT => EmrIntersectClipRect.Parse, EmfRecordType.EMR_SELECTOBJECT => EmrSelectObject.Parse, + EmfRecordType.EMR_DELETEOBJECT => EmrDeleteObject.Parse, EmfRecordType.EMR_ANGLEARC => EmrAngleArc.Parse, EmfRecordType.EMR_ELLIPSE => EmrEllipse.Parse, EmfRecordType.EMR_RECTANGLE => EmrRectangle.Parse, diff --git a/src/SharpEmf/Records/ObjectManipulation/EmrDeleteObject.cs b/src/SharpEmf/Records/ObjectManipulation/EmrDeleteObject.cs new file mode 100644 index 0000000..342edf0 --- /dev/null +++ b/src/SharpEmf/Records/ObjectManipulation/EmrDeleteObject.cs @@ -0,0 +1,43 @@ +using JetBrains.Annotations; +using SharpEmf.Enums; +using SharpEmf.Exceptions; +using SharpEmf.Extensions; +using SharpEmf.Interfaces; + +namespace SharpEmf.Records.ObjectManipulation; + +/// +[PublicAPI] +public record EmrDeleteObject : EnhancedMetafileRecord, IEmfParsable +{ + /// + /// Specifies the index of a graphics object in the EMF object table + /// + /// + /// This value MUST NOT be 0, which is a reserved index that refers to the EMF metafile itself; + /// and it MUST NOT be the index of a , which cannot be deleted + /// + public uint IhObject { get; } + + private EmrDeleteObject(EmfRecordType Type, uint Size, uint ihObject) : base(Type, Size) + { + IhObject = ihObject; + } + + public static EmrDeleteObject Parse(Stream stream, EmfRecordType recordType, uint size) + { + var ihObject = stream.ReadUInt32(); + + if (ihObject == 0) + { + throw new EmfParseException("Object index MUST NOT be zero"); + } + + if (Enum.IsDefined(typeof(StockObject), ihObject)) + { + throw new EmfParseException("Object index MUST NOT be a stock object"); + } + + return new EmrDeleteObject(recordType, size, ihObject); + } +} \ No newline at end of file