GraphicsPathIterator
Provides the ability to iterate through subpaths in a GraphicsPath and test the types of shapes contained in each subpath. This class cannot be inherited.
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.GdiPlus;
namespace System.Drawing.Drawing2D
{
[NullableContext(1)]
[Nullable(0)]
public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable
{
[Nullable(0)]
internal unsafe GpPathIterator* _nativeIterator;
public unsafe int Count {
get {
int result = default(int);
PInvoke.GdipPathIterGetCount(_nativeIterator, &result).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
}
public unsafe int SubpathCount {
get {
int result = default(int);
PInvoke.GdipPathIterGetSubpathCount(_nativeIterator, &result).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
}
[NullableContext(2)]
public unsafe GraphicsPathIterator(GraphicsPath path)
{
GpPathIterator* nativeIterator = default(GpPathIterator*);
PInvoke.GdipCreatePathIter(&nativeIterator, path.Pointer()).ThrowIfFailed();
GC.KeepAlive(path);
_nativeIterator = nativeIterator;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private unsafe void Dispose(bool disposing)
{
if (_nativeIterator != null)
try {
PInvoke.GdipDeletePathIter(_nativeIterator);
} catch (Exception ex) {
if (ClientUtils.IsSecurityOrCriticalException(ex))
throw;
} finally {
_nativeIterator = null;
}
}
~GraphicsPathIterator()
{
Dispose(false);
}
public unsafe int NextSubpath(out int startIndex, out int endIndex, out bool isClosed)
{
fixed (int* startIndex2 = &startIndex) {
fixed (int* endIndex2 = &endIndex) {
int result = default(int);
BOOL value = default(BOOL);
PInvoke.GdipPathIterNextSubpath(_nativeIterator, &result, startIndex2, endIndex2, &value).ThrowIfFailed();
isClosed = value;
GC.KeepAlive(this);
return result;
}
}
}
public unsafe int NextSubpath(GraphicsPath path, out bool isClosed)
{
int result = default(int);
BOOL value = default(BOOL);
PInvoke.GdipPathIterNextSubpathPath(_nativeIterator, &result, path.Pointer(), &value).ThrowIfFailed();
isClosed = value;
GC.KeepAlive(this);
return result;
}
public unsafe int NextPathType(out byte pathType, out int startIndex, out int endIndex)
{
fixed (byte* pathType2 = &pathType) {
fixed (int* startIndex2 = &startIndex) {
fixed (int* endIndex2 = &endIndex) {
int result = default(int);
PInvoke.GdipPathIterNextPathType(_nativeIterator, &result, pathType2, startIndex2, endIndex2).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
}
}
}
public unsafe int NextMarker(out int startIndex, out int endIndex)
{
fixed (int* startIndex2 = &startIndex) {
fixed (int* endIndex2 = &endIndex) {
int result = default(int);
PInvoke.GdipPathIterNextMarker(_nativeIterator, &result, startIndex2, endIndex2).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
}
}
public unsafe int NextMarker(GraphicsPath path)
{
int result = default(int);
PInvoke.GdipPathIterNextMarkerPath(_nativeIterator, &result, path.Pointer()).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
public unsafe bool HasCurve()
{
BOOL value = default(BOOL);
PInvoke.GdipPathIterHasCurve(_nativeIterator, &value).ThrowIfFailed();
GC.KeepAlive(this);
return value;
}
public unsafe void Rewind()
{
PInvoke.GdipPathIterRewind(_nativeIterator).ThrowIfFailed();
GC.KeepAlive(this);
}
public unsafe int Enumerate(ref PointF[] points, ref byte[] types)
{
if (points.Length != types.Length)
throw Status.InvalidParameter.GetException();
if (points.Length != 0) {
fixed (PointF* points2 = points) {
fixed (byte* types2 = types) {
int result = default(int);
PInvoke.GdipPathIterEnumerate(_nativeIterator, &result, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, types2, points.Length).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
}
}
return 0;
}
public unsafe int CopyData(ref PointF[] points, ref byte[] types, int startIndex, int endIndex)
{
if (points.Length == types.Length && endIndex - startIndex + 1 <= points.Length) {
fixed (PointF* points2 = points) {
fixed (byte* types2 = types) {
int result = default(int);
PInvoke.GdipPathIterCopyData(_nativeIterator, &result, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, types2, startIndex, endIndex).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
}
}
throw Status.InvalidParameter.GetException();
}
}
}