Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/CoreGraphics/CGPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,11 @@ public void Apply (ApplierFunction func)
gch.Free ();
}

static CGPath MakeMutable (IntPtr source)
static CGPath MakeMutable (IntPtr source, bool owns)
{
var mutable = CGPathCreateMutableCopy (source);
if (owns)
CGPathRelease (source);
return new CGPath (mutable, owns: true);
}

Expand All @@ -527,7 +529,7 @@ public CGPath CopyByDashingPath (CGAffineTransform transform, nfloat [] lengths)

public unsafe CGPath CopyByDashingPath (CGAffineTransform transform, nfloat [] lengths, nfloat phase)
{
return MakeMutable (CGPathCreateCopyByDashingPath (Handle, &transform, phase, lengths, lengths is null ? 0 : lengths.Length));
return MakeMutable (CGPathCreateCopyByDashingPath (Handle, &transform, phase, lengths, lengths is null ? 0 : lengths.Length), true);
}

public CGPath CopyByDashingPath (nfloat [] lengths)
Expand All @@ -538,59 +540,59 @@ public CGPath CopyByDashingPath (nfloat [] lengths)
public unsafe CGPath CopyByDashingPath (nfloat [] lengths, nfloat phase)
{
var path = CGPathCreateCopyByDashingPath (Handle, null, phase, lengths, lengths is null ? 0 : lengths.Length);
return MakeMutable (path);
return MakeMutable (path, true);
}

public unsafe CGPath Copy ()
{
return MakeMutable (Handle);
return MakeMutable (Handle, false);
}

[DllImport (Constants.CoreGraphicsLibrary)]
unsafe extern static IntPtr CGPathCreateCopyByStrokingPath (/* CGPathRef */ IntPtr path, CGAffineTransform *transform, nfloat lineWidth, CGLineCap lineCap, CGLineJoin lineJoin, /* CGFloat */ nfloat miterLimit);

public unsafe CGPath CopyByStrokingPath (CGAffineTransform transform, nfloat lineWidth, CGLineCap lineCap, CGLineJoin lineJoin, nfloat miterLimit)
{
return MakeMutable (CGPathCreateCopyByStrokingPath (Handle, &transform, lineWidth, lineCap, lineJoin, miterLimit));
return MakeMutable (CGPathCreateCopyByStrokingPath (Handle, &transform, lineWidth, lineCap, lineJoin, miterLimit), true);
}

public unsafe CGPath CopyByStrokingPath (nfloat lineWidth, CGLineCap lineCap, CGLineJoin lineJoin, nfloat miterLimit)
{
return MakeMutable (CGPathCreateCopyByStrokingPath (Handle, null, lineWidth, lineCap, lineJoin, miterLimit));
return MakeMutable (CGPathCreateCopyByStrokingPath (Handle, null, lineWidth, lineCap, lineJoin, miterLimit), true);
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static IntPtr CGPathCreateCopyByTransformingPath (/* CGPathRef */ IntPtr path, ref CGAffineTransform transform);

public CGPath CopyByTransformingPath (CGAffineTransform transform)
{
return MakeMutable (CGPathCreateCopyByTransformingPath (Handle, ref transform));
return MakeMutable (CGPathCreateCopyByTransformingPath (Handle, ref transform), true);
}

[DllImport (Constants.CoreGraphicsLibrary)]
unsafe extern static IntPtr CGPathCreateWithEllipseInRect (CGRect boundingRect, CGAffineTransform *transform);

static public unsafe CGPath EllipseFromRect (CGRect boundingRect, CGAffineTransform transform)
{
return MakeMutable (CGPathCreateWithEllipseInRect (boundingRect, &transform));
return MakeMutable (CGPathCreateWithEllipseInRect (boundingRect, &transform), true);
}

static public unsafe CGPath EllipseFromRect (CGRect boundingRect)
{
return MakeMutable (CGPathCreateWithEllipseInRect (boundingRect, null));
return MakeMutable (CGPathCreateWithEllipseInRect (boundingRect, null), true);
}

[DllImport (Constants.CoreGraphicsLibrary)]
unsafe extern static IntPtr CGPathCreateWithRect (CGRect boundingRect, CGAffineTransform *transform);

static public unsafe CGPath FromRect (CGRect rectangle, CGAffineTransform transform)
{
return MakeMutable (CGPathCreateWithRect (rectangle, &transform));
return MakeMutable (CGPathCreateWithRect (rectangle, &transform), true);
}

static public unsafe CGPath FromRect (CGRect rectangle)
{
return MakeMutable (CGPathCreateWithRect (rectangle, null));
return MakeMutable (CGPathCreateWithRect (rectangle, null), true);
}

[DllImport (Constants.CoreGraphicsLibrary)]
Expand All @@ -602,7 +604,7 @@ static unsafe CGPath _FromRoundedRect (CGRect rectangle, nfloat cornerWidth, nfl
throw new ArgumentException (nameof (cornerWidth));
if ((cornerHeight < 0) || (2 * cornerHeight > rectangle.Height))
throw new ArgumentException (nameof (cornerHeight));
return MakeMutable (CGPathCreateWithRoundedRect (rectangle, cornerWidth, cornerHeight, transform));
return MakeMutable (CGPathCreateWithRoundedRect (rectangle, cornerWidth, cornerHeight, transform), true);
}

#if !NET
Expand Down