Skip to content

Commit

Permalink
EMR_CREATEBRUSHINDIRECT
Browse files Browse the repository at this point in the history
  • Loading branch information
KeterSCP committed Nov 9, 2023
1 parent 754e12d commit 96f773c
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 10 deletions.
12 changes: 12 additions & 0 deletions SharpEmf.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=CHECKPNGFORMAT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CLOSECHANNEL/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CLOSEFIGURE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CREATEBRUSHINDIRECT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DELETEOBJECT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DIBPATTERN/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DIBPATTERNPT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DITHEREDBKCLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DITHEREDCLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DITHEREDTEXTCLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DKGRAY/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DOWNLOADFACE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DOWNLOADHEADER/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DRAFTMODE/@EntryIndexedValue">True</s:Boolean>
Expand Down Expand Up @@ -57,6 +64,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=intercharacter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=INTERSECTCLIPRECT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lineto/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=LTGRAY/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MONOPATTERN/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MOVETOEX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MXDC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NAMEDESCAPE/@EntryIndexedValue">True</s:Boolean>
Expand Down Expand Up @@ -98,6 +107,9 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=SETPIXELV/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SETPOLYFILLMODE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SMALLTEXTOUT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SOLIDBKCLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SOLIDCLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SOLIDTEXTCLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SPCLPASSTHROUGH/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=STARTDOC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=STRETCHBLT/@EntryIndexedValue">True</s:Boolean>
Expand Down
21 changes: 21 additions & 0 deletions src/SharpEmf/Enums/BrushStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using JetBrains.Annotations;

namespace SharpEmf.Enums;

/// <summary>
/// Specifies the different possible brush types that can be used in graphics operations
/// </summary>
[PublicAPI]
public enum BrushStyle : uint
{
BS_SOLID = 0x0000,
BS_NULL = 0x0001,
BS_HATCHED = 0x0002,
BS_PATTERN = 0x0003,
BS_INDEXED = 0x0004,
BS_DIBPATTERN = 0x0005,
BS_DIBPATTERNPT = 0x0006,
BS_PATTERN8X8 = 0x0007,
BS_DIBPATTERN8X8 = 0x0008,
BS_MONOPATTERN = 0x0009
}
5 changes: 5 additions & 0 deletions src/SharpEmf/Enums/EmfRecordType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public enum EmfRecordType : uint
/// </summary>
EMR_SELECTOBJECT = 0x00000025,

/// <summary>
/// Defines a logical brush for filling figures in graphics operations
/// </summary>
EMR_CREATEBRUSHINDIRECT = 0x00000027,

/// <summary>
/// Deletes a graphics object, clearing its index in the EMF object table
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/SharpEmf/Enums/HatchStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JetBrains.Annotations;

namespace SharpEmf.Enums;

/// <summary>
/// Specifies the hatch pattern
/// </summary>
[PublicAPI]
public enum HatchStyle : uint
{
HS_SOLIDCLR = 0x0006,
HS_DITHEREDCLR = 0x0007,
HS_SOLIDTEXTCLR = 0x0008,
HS_DITHEREDTEXTCLR = 0x0009,
HS_SOLIDBKCLR = 0x000A,
HS_DITHEREDBKCLR = 0x000B
}
8 changes: 2 additions & 6 deletions src/SharpEmf/Objects/ColorRef.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Diagnostics;
using JetBrains.Annotations;
using SharpEmf.Exceptions;

namespace SharpEmf.Objects;
Expand Down Expand Up @@ -42,11 +43,6 @@ public static ColorRef Parse(Stream stream)
var blue = stream.ReadByte();
var reserved = stream.ReadByte();

if (reserved != 0x00)
{
throw new EmfParseException($"Reserved byte must be 0x00, but was {reserved}");
}

return new ColorRef((byte)red, (byte)green, (byte)blue, (byte)reserved);
}
}
61 changes: 61 additions & 0 deletions src/SharpEmf/Objects/LogBrushEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using JetBrains.Annotations;
using SharpEmf.Enums;
using SharpEmf.Exceptions;
using SharpEmf.Extensions;

namespace SharpEmf.Objects;

/// <summary>
/// Defines the style, color, and pattern of a device-independent brush
/// </summary>
/// <remarks>
/// The following table shows the relationship between the BrushStyle, Color, and BrushHatch fields:
/// <code>
/// | BrushStyle | Color | BrushHatch
/// |--------------|-----------------------------------------------------|-------------------------------------------------------------|
/// | BS_SOLID | Specifies the color of the brush | Not used and SHOULD be ignored |
/// | BS_NULL | Not used and SHOULD be ignored | Not used and SHOULD be ignored |
/// | BS_HATCHED | Specifies the foreground color of the hatch pattern | Specifies the orientation of lines used to create the hatch |
/// </code>
/// </remarks>
[PublicAPI]
public readonly struct LogBrushEx
{
/// <summary>
/// Specifies the brush style.
/// Values of this field MUST be <see cref="BrushStyle.BS_SOLID"/>, <see cref="BrushStyle.BS_HATCHED"/>, or <see cref="BrushStyle.BS_NULL"/>
/// </summary>
public BrushStyle BrushStyle { get; }

/// <summary>
/// Specifies a color
/// </summary>
public ColorRef Color { get; }

/// <summary>
/// Brush hatch data
/// </summary>
public HatchStyle HatchStyle { get; }

private LogBrushEx(BrushStyle brushStyle, ColorRef color, HatchStyle hatchStyle)
{
BrushStyle = brushStyle;
Color = color;
HatchStyle = hatchStyle;
}

public static LogBrushEx Parse(Stream stream)
{
var brushStyle = stream.ReadEnum<BrushStyle>();

if (brushStyle is not (BrushStyle.BS_SOLID or BrushStyle.BS_HATCHED or BrushStyle.BS_NULL))
{
throw new EmfParseException($"Invalid {nameof(BrushStyle)} value: {brushStyle}");
}

var color = ColorRef.Parse(stream);
var hatchStyle = stream.ReadEnum<HatchStyle>();

return new LogBrushEx(brushStyle, color, hatchStyle);
}
}
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.ObjectCreation;
using SharpEmf.Records.ObjectManipulation;
using SharpEmf.Records.PathBracket;
using SharpEmf.Records.State;
Expand Down Expand Up @@ -56,6 +57,7 @@ public static EnhancedMetafileRecord Parse(Stream stream)
EmfRecordType.EMR_EXCLUDECLIPRECT => EmrExcludeClipRect.Parse,
EmfRecordType.EMR_INTERSECTCLIPRECT => EmrIntersectClipRect.Parse,
EmfRecordType.EMR_SELECTOBJECT => EmrSelectObject.Parse,
EmfRecordType.EMR_CREATEBRUSHINDIRECT => EmrCreateBrushIndirect.Parse,
EmfRecordType.EMR_DELETEOBJECT => EmrDeleteObject.Parse,
EmfRecordType.EMR_ANGLEARC => EmrAngleArc.Parse,
EmfRecordType.EMR_ELLIPSE => EmrEllipse.Parse,
Expand Down
39 changes: 39 additions & 0 deletions src/SharpEmf/Records/ObjectCreation/EmrCreateBrushIndirect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using JetBrains.Annotations;
using SharpEmf.Enums;
using SharpEmf.Extensions;
using SharpEmf.Interfaces;
using SharpEmf.Objects;

namespace SharpEmf.Records.ObjectCreation;

/// <inheritdoc cref="EmfRecordType.EMR_CREATEBRUSHINDIRECT"/>
[PublicAPI]
public record EmrCreateBrushIndirect : EnhancedMetafileRecord, IEmfParsable<EmrCreateBrushIndirect>
{
/// <summary>
/// Specifies the index of the logical brush object in the EMF object table
/// </summary>
/// <remarks>
/// This index is used to refer to the object, so it can be reused or modified
/// </remarks>
public uint IHBrush { get; }

/// <summary>
/// Specifies the style, color, and pattern of the logical brush
/// </summary>
public LogBrushEx LogBrush { get; }

private EmrCreateBrushIndirect(EmfRecordType Type, uint Size, uint ihBrush, LogBrushEx logBrush) : base(Type, Size)
{
IHBrush = ihBrush;
LogBrush = logBrush;
}

public static EmrCreateBrushIndirect Parse(Stream stream, EmfRecordType recordType, uint size)
{
var ihBrush = stream.ReadUInt32();
var logBrush = LogBrushEx.Parse(stream);

return new EmrCreateBrushIndirect(recordType, size, ihBrush, logBrush);
}
}
5 changes: 1 addition & 4 deletions tests/SharpEmf.UnitTests/SharpEmf.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
</ItemGroup>

<ItemGroup>
<None Update="Samples\sample_1.emf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Samples\sample_2.emf">
<None Update="Samples\*.emf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down

0 comments on commit 96f773c

Please sign in to comment.