Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CoreGraphics] Xcode 14 Beta 1-5 #15831

Merged
merged 5 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions src/CoreFoundation/CGAffineTransformComponents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 Microsoft Corporation.

#nullable enable

using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

using CoreGraphics;

namespace CoreFoundation {
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this struct only available in NET?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but we don't add attributes to structs in legacy usually. We have a test that insists we do in NET6.

[StructLayout (LayoutKind.Sequential)]
// The name prefix suggests CoreGraphics and based on CF_DEFINES_CGAFFINETRANSFORMCOMPONENTS
// it could be defined in CoreGraphics but documented as CoreFoundation type
public struct CGAffineTransformComponents
{
public CGSize Scale;

public nfloat HorizontalShear;

public nfloat Rotation;

public CGVector Translation;
}
}
32 changes: 32 additions & 0 deletions src/CoreGraphics/CGAffineTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,38 @@ public CGAffineTransform Invert ()
{
return CGAffineTransformInvert (this);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern CGAffineTransformComponents CGAffineTransformDecompose (CGAffineTransform transform);

public CGAffineTransformComponents Decompose ()
{
return CGAffineTransformDecompose (this);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern CGAffineTransform CGAffineTransformMakeWithComponents (CGAffineTransformComponents components);

public static CGAffineTransform MakeWithComponents (CGAffineTransformComponents components)
{
return CGAffineTransformMakeWithComponents (components);
}
#endif // !COREBUILD
}
}
27 changes: 27 additions & 0 deletions src/CoreGraphics/CGColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,33 @@ public bool UsesExtendedRange {
#endif
public CGColorSpace? CreateExtendedLinearized () => Runtime.GetINativeObject<CGColorSpace> (CGColorSpaceCreateExtendedLinearized (Handle), owns: true);

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[iOS (16,0)]
[TV (16,0)]
[Mac (13,0)]
[MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGColorSpaceCreateCopyWithStandardRange (/* CGColorSpaceRef */ IntPtr s);

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("tvos16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
#else
[iOS (16,0)]
[TV (16,0)]
[Mac (13,0)]
[MacCatalyst (16,0)]
#endif
public CGColorSpace? CreateCopyWithStandardRange () => Runtime.GetINativeObject<CGColorSpace> (CGColorSpaceCreateCopyWithStandardRange (Handle), owns: true);

#if NET
[SupportedOSPlatform ("macos12.0")]
[SupportedOSPlatform ("ios15.0")]
Expand Down
24 changes: 24 additions & 0 deletions src/CoreGraphics/CGPDFScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,29 @@ public bool TryPop (out CGPDFStream? value)
return false;
}
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGPDFScannerStop (/* CGPDFScannerRef */ IntPtr scanner);

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
public void Stop ()
{
CGPDFScannerStop (Handle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, I see in other methods as well that there is a "Handle" var, where is it coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}
167 changes: 167 additions & 0 deletions src/CoreGraphics/CGPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#nullable enable

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

using CoreFoundation;
Expand Down Expand Up @@ -529,6 +532,170 @@ public void Apply (ApplierFunction func)
gch.Free ();
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyByNormalizing (IntPtr path, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateByNormalizing (bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyByNormalizing (Handle, evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyByUnioningPath (IntPtr path, IntPtr maskPath, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateByUnioningPath (CGPath? maskPath, bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyByUnioningPath (Handle, maskPath.GetHandle (), evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyByIntersectingPath (IntPtr path, IntPtr maskPath, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateByIntersectingPath (CGPath? maskPath, bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyByIntersectingPath (Handle, maskPath.GetHandle (), evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyBySubtractingPath (IntPtr path, IntPtr maskPath, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateBySubtractingPath (CGPath? maskPath, bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyBySubtractingPath (Handle, maskPath.GetHandle (), evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyBySymmetricDifferenceOfPath (IntPtr path, IntPtr maskPath, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateBySymmetricDifferenceOfPath (CGPath? maskPath, bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyBySymmetricDifferenceOfPath (Handle, maskPath.GetHandle (), evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyOfLineBySubtractingPath (IntPtr path, IntPtr maskPath, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateLineBySubtractingPath (CGPath? maskPath, bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyOfLineBySubtractingPath (Handle, maskPath.GetHandle (), evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyOfLineByIntersectingPath (IntPtr path, IntPtr maskPath, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath? CreateLineByIntersectingPath (CGPath? maskPath, bool evenOddFillRule)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyOfLineByIntersectingPath (Handle, maskPath.GetHandle (), evenOddFillRule), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern unsafe /* CFArrayRef __nullable */ IntPtr CGPathCreateSeparateComponents (IntPtr path, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public CGPath[] GetSeparateComponents (bool evenOddFillRule)
{
var cfArrayRef = CGPathCreateSeparateComponents (Handle, evenOddFillRule);
if (cfArrayRef == IntPtr.Zero)
return Array.Empty<CGPath> ();
return NSArray.ArrayFromHandle<CGPath> (cfArrayRef);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateCopyByFlattening (IntPtr path, nfloat flatteningThreshold);

public CGPath? CreateByFlattening (nfloat flatteningThreshold)
{
return Runtime.GetINativeObject<CGPath>(CGPathCreateCopyByFlattening (Handle, flatteningThreshold), owns: true);
}

#if NET
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
#endif
[DllImport (Constants.CoreGraphicsLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool CGPathIntersectsPath (IntPtr path1, IntPtr path2, [MarshalAs (UnmanagedType.I1)] bool evenOddFillRule);

public bool DoesIntersect (CGPath? maskPath, bool evenOddFillRule)
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
{
return CGPathIntersectsPath (Handle, maskPath.GetHandle (), evenOddFillRule);
}

static CGPath MakeMutable (IntPtr source, bool owns)
{
var mutable = CGPathCreateMutableCopy (source);
Expand Down
4 changes: 4 additions & 0 deletions src/coregraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ interface CGColorSpaceNames {
[Field ("kCGColorSpaceITUR_709_PQ")]
NSString ItuR_709_PQ { get; }

[Mac (13,0), iOS (16,0), TV (16,0), MacCatalyst (16,0)]
[Field ("kCGColorSpaceITUR_709_HLG")]
NSString ItuR_709_Hlg { get; }

[Mac (10,11)]
[Field ("kCGColorSpaceITUR_2020")]
NSString ItuR_2020 { get; }
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ COREFOUNDATION_CORE_SOURCES = \
CoreFoundation/DispatchData.cs \
CoreFoundation/NativeObject.cs \
CoreFoundation/Architecture.cs \
CoreFoundation/CGAffineTransformComponents.cs \

COREFOUNDATION_SOURCES = \
CoreFoundation/CFAllocator.cs \
Expand Down
33 changes: 33 additions & 0 deletions tests/monotouch-test/CoreGraphics/AffineTransformTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Runtime.InteropServices;
using Foundation;
using CoreGraphics;
using CoreFoundation;
using ObjCRuntime;

using NUnit.Framework;
Expand Down Expand Up @@ -499,6 +500,38 @@ public void Invert ()
#endif
}

[Test]
public void Decompose ()
{
TestRuntime.AssertXcodeVersion (14, 0);

var components = new CGAffineTransform (1, 2, 3, 4, 5, 6).Decompose ();
Assert.AreNotEqual (0.0, components.Scale);
Assert.AreNotEqual (0.0, components.HorizontalShear);
Assert.AreNotEqual (0.0, components.Rotation);
Assert.AreNotEqual (new CGVector ((nfloat)0, (nfloat)0), components.Translation);
}

[Test]
public void MakeWithComponents ()
{
TestRuntime.AssertXcodeVersion (14, 0);

var components = new CGAffineTransformComponents () {
Scale = new CGSize (1.0, 2.0),
HorizontalShear = (nfloat)3.0,
Rotation = (nfloat)4.0,
Translation = new CGVector ((nfloat)5.0, (nfloat)6.0),
};
var transform = CGAffineTransform.MakeWithComponents (components);
Assert.AreNotEqual (0.0, transform.A);
Assert.AreNotEqual (0.0, transform.B);
Assert.AreNotEqual (0.0, transform.C);
Assert.AreNotEqual (0.0, transform.D);
Assert.AreNotEqual (0.0, transform.Tx);
Assert.AreNotEqual (0.0, transform.Ty);
}

[Test]
public void NSValueRoundtrip ()
{
Expand Down
8 changes: 8 additions & 0 deletions tests/monotouch-test/CoreGraphics/ColorSpaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ public void CreateExtendedLinearizedTest ()
Assert.That ((nint) TestRuntime.CFGetRetainCount (csl.Handle), Is.EqualTo ((nint) 1).Or.EqualTo ((nint) 2));
}
}

[Test]
public void CreateCopyWithStandardRange ()
{
TestRuntime.AssertXcodeVersion (14, 0);
using var cs = CGColorSpace.CreateWithName (CGColorSpaceNames.GenericRgb);
Assert.NotNull (cs.CreateCopyWithStandardRange());
}

[Test]
public void IsHlgBasedTest ()
Expand Down
Loading