Skip to content

Commit

Permalink
Move the GraphicsPath type to SafeHandles.
Browse files Browse the repository at this point in the history
And rename some parameter names in the manually marshalled P/Invoke definitions.
  • Loading branch information
teo-tsirpanis committed Dec 24, 2021
1 parent 6d596f7 commit 6b60b9c
Show file tree
Hide file tree
Showing 16 changed files with 465 additions and 408 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Gdip = System.Drawing.SafeNativeMethods.Gdip;

namespace Microsoft.Win32.SafeHandles
{
internal class SafeGraphicsPathHandle : SafeGdiPlusHandle
{
public SafeGraphicsPathHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle)
{
SetHandle(preexistingHandle);
}

public SafeGraphicsPathHandle() : base(true)
{
}

protected override int ReleaseHandleImpl() => Gdip.GdipDeletePath(handle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ Unix support is disabled by default. See https://aka.ms/systemdrawingnonwindows
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
<Compile Include="Microsoft\Win32\SafeHandles\SafeBrushHandle.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafeGdiPlusHandle.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafeGraphicsPathHandle.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafeMatrixHandle.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafePenHandle.cs" />
<Compile Include="Microsoft\Win32\SafeHandles\SafeRegionHandle.cs" />
<Compile Include="System\Drawing\Bitmap.cs" />
<Compile Include="System\Drawing\BitmapSuffixInSameAssemblyAttribute.cs" />
<Compile Include="System\Drawing\BitmapSuffixInSatelliteAssemblyAttribute.cs" />
Expand Down Expand Up @@ -84,6 +86,7 @@ Unix support is disabled by default. See https://aka.ms/systemdrawingnonwindows
<Compile Include="System\Drawing\Drawing2D\FillMode.cs" />
<Compile Include="System\Drawing\Drawing2D\FlushIntention.cs" />
<Compile Include="System\Drawing\Drawing2D\GraphicsContainer.cs" />
<Compile Include="System\Drawing\Drawing2D\GraphicsPath.cs" />
<Compile Include="System\Drawing\Drawing2D\HatchBrush.cs" />
<Compile Include="System\Drawing\Drawing2D\HatchStyle.cs" />
<Compile Include="System\Drawing\Drawing2D\InterpolationMode.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public CustomLineCap(GraphicsPath? fillPath, GraphicsPath? strokePath, LineCap b
{
IntPtr nativeLineCap;
int status = Gdip.GdipCreateCustomLineCap(
new HandleRef(fillPath, (fillPath == null) ? IntPtr.Zero : fillPath._nativePath),
new HandleRef(strokePath, (strokePath == null) ? IntPtr.Zero : strokePath._nativePath),
fillPath?.SafeGraphicsPathHandle,
strokePath?.SafeGraphicsPathHandle,
baseCap, baseInset, out nativeLineCap);

if (status != Gdip.Ok)
Expand Down

0 comments on commit 6b60b9c

Please sign in to comment.