Skip to content

Commit

Permalink
EMR_SELECTOBJECT
Browse files Browse the repository at this point in the history
  • Loading branch information
KeterSCP committed Nov 9, 2023
1 parent cc1e203 commit 2b3a6a8
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions SharpEmf.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=ROUNDRECT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=RTLREADING/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SELECTCLIPPATH/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SELECTOBJECT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SETABORTPROC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SETCOLORTABLE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SETCOPYCOUNT/@EntryIndexedValue">True</s:Boolean>
Expand Down
5 changes: 5 additions & 0 deletions src/SharpEmf/Enums/EmfRecordType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public enum EmfRecordType : uint
/// </summary>
EMR_INTERSECTCLIPRECT = 0x0000001E,

/// <summary>
/// Selects an object in the playback device context, which is identified by its index in the EMF object table
/// </summary>
EMR_SELECTOBJECT = 0x00000025,

/// <summary>
/// Defines a line segment of an arc
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SharpEmf/Enums/PolygonFillMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SharpEmf.Enums;
/// Defines values that specify how to calculate the region of a polygon that is to be filled
/// </summary>
[PublicAPI]
public enum PolygonFillMode
public enum PolygonFillMode : uint
{
/// <summary>
/// Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line)
Expand Down
30 changes: 30 additions & 0 deletions src/SharpEmf/Enums/StockObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using JetBrains.Annotations;

namespace SharpEmf.Enums;

/// <summary>
/// Specifies the indexes of predefined logical graphics objects that can be used in graphics operations
/// </summary>
[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
}
2 changes: 2 additions & 0 deletions src/SharpEmf/Records/EnhancedMetafileRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
39 changes: 39 additions & 0 deletions src/SharpEmf/Records/ObjectManipulation/EmrSelectObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using JetBrains.Annotations;
using SharpEmf.Enums;
using SharpEmf.Exceptions;
using SharpEmf.Extensions;
using SharpEmf.Interfaces;

namespace SharpEmf.Records.ObjectManipulation;

/// <inheritdoc cref="EmfRecordType.EMR_SELECTOBJECT"/>
[PublicAPI]
public record EmrSelectObject : EnhancedMetafileRecord, IEmfParsable<EmrSelectObject>
{
/// <summary>
/// Specifies either the index of a graphics object in the EMF object table or the index of a stock object in the <see cref="StockObject"/> enumeration
/// </summary>
/// <remarks>
/// The object index MUST NOT be zero, which is reserved and refers to the EMF metafile itself. <para />
/// 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
/// </remarks>
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);
}
}

0 comments on commit 2b3a6a8

Please sign in to comment.