Skip to content

Commit

Permalink
More stock objects handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KeterSCP committed Dec 15, 2023
1 parent 2104b29 commit e537104
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,51 @@ public static void HandleSelectObject(EmfState state, EmrSelectObject selectObje
if ((index & 0x80000000) != 0)
{
var stockObject = (StockObject)index;
if (stockObject is StockObject.WHITE_BRUSH)
{
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0xFF, 0xFF, 0xFF));
}
else if (stockObject is StockObject.LTGRAY_BRUSH)
{
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0xC0, 0xC0, 0xC0));
}
else if (stockObject is StockObject.GRAY_BRUSH)
{
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0x80, 0x80, 0x80));
}
else if (stockObject is StockObject.DKGRAY_BRUSH)
{
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0x40, 0x40, 0x40));
}
else if (stockObject is StockObject.NULL_BRUSH)

switch (stockObject)
{
state.CurrentPlaybackDeviceContext.SelectedBrush = LogBrushEx.Null;
case StockObject.WHITE_BRUSH:
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0xFF, 0xFF, 0xFF));
break;
case StockObject.LTGRAY_BRUSH:
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0xC0, 0xC0, 0xC0));
break;
case StockObject.GRAY_BRUSH:
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0x80, 0x80, 0x80));
break;
case StockObject.DKGRAY_BRUSH:
state.CurrentPlaybackDeviceContext.SelectedBrush = new LogBrushEx(
brushStyle: BrushStyle.BS_SOLID,
color: new ColorRef(0x40, 0x40, 0x40));
break;
case StockObject.NULL_BRUSH:
state.CurrentPlaybackDeviceContext.SelectedBrush = LogBrushEx.Null;
break;
case StockObject.WHITE_PEN:
state.CurrentPlaybackDeviceContext.SelectedPen = new LogPenEx(
penStyle: PenStyle.PS_COSMETIC | PenStyle.PS_SOLID,
color: new ColorRef(0xFF, 0xFF, 0xFF));
break;
case StockObject.BLACK_PEN:
state.CurrentPlaybackDeviceContext.SelectedPen = new LogPenEx(
penStyle: PenStyle.PS_COSMETIC | PenStyle.PS_SOLID,
color: new ColorRef(0x00, 0x00, 0x00));
break;
case StockObject.NULL_PEN:
state.CurrentPlaybackDeviceContext.SelectedPen = LogPenEx.Null;
break;
default:
// TODO: handle other stock objects
break;
}

return;
}

var graphicsObject = state.ObjectTable[index];
Expand Down
1 change: 1 addition & 0 deletions src/SharpEmf/Enums/PenStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace SharpEmf.Enums;
/// A pen style is a combination of pen type, line style, line cap, and line join
/// </summary>
[PublicAPI]
[Flags]
public enum PenStyle : uint
{
/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/SharpEmf/Objects/LogPenEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public readonly struct LogPenEx
/// </remarks>
public IReadOnlyList<PenStyle> StyleEntry { get; }

public LogPenEx(PenStyle penStyle, ColorRef color)

Check warning on line 92 in src/SharpEmf/Objects/LogPenEx.cs

View workflow job for this annotation

GitHub Actions / macos

Non-nullable property 'StyleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/SharpEmf/Objects/LogPenEx.cs

View workflow job for this annotation

GitHub Actions / macos

Non-nullable property 'StyleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/SharpEmf/Objects/LogPenEx.cs

View workflow job for this annotation

GitHub Actions / linux

Non-nullable property 'StyleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/SharpEmf/Objects/LogPenEx.cs

View workflow job for this annotation

GitHub Actions / linux

Non-nullable property 'StyleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/SharpEmf/Objects/LogPenEx.cs

View workflow job for this annotation

GitHub Actions / windows

Non-nullable property 'StyleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/SharpEmf/Objects/LogPenEx.cs

View workflow job for this annotation

GitHub Actions / windows

Non-nullable property 'StyleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
PenStyle = penStyle;
ColorRef = color;
Width = 1;
BrushStyle = BrushStyle.BS_SOLID;
}

private LogPenEx(PenStyle penStyle, uint width, BrushStyle brushStyle, ColorRef colorRef, HatchStyle brushHatch, uint numStyleEntries, IReadOnlyList<PenStyle> styleEntry)
{
PenStyle = penStyle;
Expand All @@ -100,6 +108,8 @@ private LogPenEx(PenStyle penStyle, uint width, BrushStyle brushStyle, ColorRef
StyleEntry = styleEntry;
}

public static LogPenEx Null { get; } = new(PenStyle.PS_NULL, color: default);

public static LogPenEx Parse(Stream stream)
{
var penStyle = stream.ReadEnum<PenStyle>();
Expand Down

0 comments on commit e537104

Please sign in to comment.