diff --git a/README.md b/README.md index 5d207ab..654163a 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,4 @@ SharpEmf is a cross-platform .NET library for parsing EMF files. It does not dep Documentation for the EMF standard can be found [here](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-emf). **TODO** -- Create a EMF to SVG converter +- Create an EMF to SVG converter diff --git a/SharpEmf.sln.DotSettings b/SharpEmf.sln.DotSettings index dedfda0..85b515d 100644 --- a/SharpEmf.sln.DotSettings +++ b/SharpEmf.sln.DotSettings @@ -83,6 +83,7 @@ True True True + True True True True diff --git a/src/SharpEmf/Enums/EmfRecordType.cs b/src/SharpEmf/Enums/EmfRecordType.cs index 16448b6..21e12e0 100644 --- a/src/SharpEmf/Enums/EmfRecordType.cs +++ b/src/SharpEmf/Enums/EmfRecordType.cs @@ -105,6 +105,11 @@ public enum EmfRecordType : uint /// EMR_INTERSECTCLIPRECT = 0x0000001E, + /// + /// Selects an object in the playback device context, which is identified by its index in the EMF object table + /// + EMR_SELECTOBJECT = 0x00000025, + /// /// Defines a line segment of an arc /// diff --git a/src/SharpEmf/Enums/PolygonFillMode.cs b/src/SharpEmf/Enums/PolygonFillMode.cs index f767520..5a799a2 100644 --- a/src/SharpEmf/Enums/PolygonFillMode.cs +++ b/src/SharpEmf/Enums/PolygonFillMode.cs @@ -6,7 +6,7 @@ namespace SharpEmf.Enums; /// Defines values that specify how to calculate the region of a polygon that is to be filled /// [PublicAPI] -public enum PolygonFillMode +public enum PolygonFillMode : uint { /// /// Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line) diff --git a/src/SharpEmf/Enums/StockObject.cs b/src/SharpEmf/Enums/StockObject.cs new file mode 100644 index 0000000..209cb5e --- /dev/null +++ b/src/SharpEmf/Enums/StockObject.cs @@ -0,0 +1,30 @@ +using JetBrains.Annotations; + +namespace SharpEmf.Enums; + +/// +/// Specifies the indexes of predefined logical graphics objects that can be used in graphics operations +/// +[PublicAPI] +public enum StockObject : uint +{ + WHITE_BRUSH = 0x80000000, + LTGRAY_BRUSH = 0x80000001, + GRAY_BRUSH = 0x80000002, + DKGRAY_BRUSH = 0x80000003, + BLACK_BRUSH = 0x80000004, + NULL_BRUSH = 0x80000005, + WHITE_PEN = 0x80000006, + BLACK_PEN = 0x80000007, + NULL_PEN = 0x80000008, + OEM_FIXED_FONT = 0x8000000A, + ANSI_FIXED_FONT = 0x8000000B, + ANSI_VAR_FONT = 0x8000000C, + SYSTEM_FONT = 0x8000000D, + DEVICE_DEFAULT_FONT = 0x8000000E, + DEFAULT_PALETTE = 0x8000000F, + SYSTEM_FIXED_FONT = 0x80000010, + DEFAULT_GUI_FONT = 0x80000011, + DC_BRUSH = 0x80000012, + DC_PEN = 0x80000013 +} \ No newline at end of file diff --git a/src/SharpEmf/Records/EnhancedMetafileRecord.cs b/src/SharpEmf/Records/EnhancedMetafileRecord.cs index 630465d..3a61af8 100644 --- a/src/SharpEmf/Records/EnhancedMetafileRecord.cs +++ b/src/SharpEmf/Records/EnhancedMetafileRecord.cs @@ -8,6 +8,7 @@ using SharpEmf.Records.Control.Header; using SharpEmf.Records.Drawing; using SharpEmf.Records.Escape; +using SharpEmf.Records.ObjectManipulation; using SharpEmf.Records.PathBracket; using SharpEmf.Records.State; @@ -53,6 +54,7 @@ public static EnhancedMetafileRecord Parse(Stream stream) EmfRecordType.EMR_OFFSETCLIPRGN => EmrOffsetClipRgn.Parse, EmfRecordType.EMR_EXCLUDECLIPRECT => EmrExcludeClipRect.Parse, EmfRecordType.EMR_INTERSECTCLIPRECT => EmrIntersectClipRect.Parse, + EmfRecordType.EMR_SELECTOBJECT => EmrSelectObject.Parse, EmfRecordType.EMR_ANGLEARC => EmrAngleArc.Parse, EmfRecordType.EMR_ELLIPSE => EmrEllipse.Parse, EmfRecordType.EMR_RECTANGLE => EmrRectangle.Parse, diff --git a/src/SharpEmf/Records/ObjectManipulation/EmrSelectObject.cs b/src/SharpEmf/Records/ObjectManipulation/EmrSelectObject.cs new file mode 100644 index 0000000..6ec3a88 --- /dev/null +++ b/src/SharpEmf/Records/ObjectManipulation/EmrSelectObject.cs @@ -0,0 +1,39 @@ +using JetBrains.Annotations; +using SharpEmf.Enums; +using SharpEmf.Exceptions; +using SharpEmf.Extensions; +using SharpEmf.Interfaces; + +namespace SharpEmf.Records.ObjectManipulation; + +/// +[PublicAPI] +public record EmrSelectObject : EnhancedMetafileRecord, IEmfParsable +{ + /// + /// Specifies either the index of a graphics object in the EMF object table or the index of a stock object in the enumeration + /// + /// + /// The object index MUST NOT be zero, which is reserved and refers to the EMF metafile itself. + /// The object specified by this record MUST be used in subsequent EMF drawing operations, until another EMR_SELECTOBJECT record + /// changes the object of that type or the object is deleted + /// + public uint IHObject { get; } + + private EmrSelectObject(EmfRecordType Type, uint Size, uint ihObject) : base(Type, Size) + { + IHObject = ihObject; + } + + public static EmrSelectObject Parse(Stream stream, EmfRecordType recordType, uint size) + { + var ihObject = stream.ReadUInt32(); + + if (ihObject == 0) + { + throw new EmfParseException("Object index MUST NOT be zero"); + } + + return new EmrSelectObject(recordType, size, ihObject); + } +} \ No newline at end of file