Merge remote-tracking branch 'origin/main' into net7.0

This commit is contained in:
Rolf Bjarne Kvinge 2022-06-20 12:13:31 +02:00
Родитель 2b84ce2ccb e3bc284ab1
Коммит 9e6e2449a1
135 изменённых файлов: 2828 добавлений и 991 удалений

Просмотреть файл

@ -213,6 +213,10 @@ XCODE_URL=https://dl.internalx.com/internal-files/xcodes/Xcode_13.3.xip
XCODE_DEVELOPER_ROOT=/Applications/Xcode_13.3.0.app/Contents/Developer
XCODE_PRODUCT_BUILD_VERSION:=$(shell /usr/libexec/PlistBuddy -c 'Print :ProductBuildVersion' $(XCODE_DEVELOPER_ROOT)/../version.plist 2>/dev/null || echo " $(shell tput setaf 1 2>/dev/null)The required Xcode ($(XCODE_VERSION)) is not installed in $(basename $(basename $(XCODE_DEVELOPER_ROOT)))$(shell tput sgr0 2>/dev/null)" >&2)
# Tell both Xcode and our build logic which Xcode we're using.
export DEVELOPER_DIR=$(XCODE_DEVELOPER_ROOT)
export MD_APPLE_SDK_ROOT=$(abspath $(XCODE_DEVELOPER_ROOT)/../..)
# Mono version embedded in XI/XM (NEEDED_MONO_VERSION/BRANCH) are specified in mk/mono.mk
include $(TOP)/mk/mono.mk
MONO_HASH := $(NEEDED_MONO_VERSION)

Просмотреть файл

@ -1,19 +0,0 @@
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
namespace Xamarin.Mac.Tasks
{
public abstract class DetectSdkLocationsTaskBase : DetectSdkLocationsCoreTaskBase
{
protected override IAppleSdkVersion GetDefaultSdkVersion ()
{
var v = CurrentSdk.GetInstalledSdkVersions (false);
return v.Count > 0 ? v [v.Count - 1] : AppleSdkVersion.UseDefault;
}
protected override string GetDefaultXamarinSdkRoot ()
{
return Sdks.XamMac.FrameworkDirectory;
}
}
}

Просмотреть файл

@ -1,7 +0,0 @@
namespace Xamarin.Mac.Tasks
{
public class DetectSdkLocations : DetectSdkLocationsTaskBase
{
}
}

Просмотреть файл

@ -55,7 +55,13 @@ namespace Xamarin.MacDev.Tasks
args.Add ("dsymutil");
args.Add ("-num-threads");
args.Add ("4");
args.Add ("-z");
if (AppleSdkSettings.XcodeVersion < new Version (13, 3)) {
// Apple removed the -z / --minimize option in Xocde 13.3, so now if you use it you get a warning: "ignoring unknown option: -z"
// So just don't pass -z when Xcode >= 13.3
// Ref: https://github.com/llvm/llvm-project/commit/5d07dc897707f877c45cab6c7e4b65dad7d3ff6d
// Ref: https://github.com/dotnet/runtime/issues/66770
args.Add ("-z");
}
args.Add ("-o");
args.Add (dSymDir);

Просмотреть файл

@ -73,8 +73,36 @@ namespace Xamarin.MacDev.Tasks {
}
}
protected abstract string GetDefaultXamarinSdkRoot ();
protected abstract IAppleSdkVersion GetDefaultSdkVersion ();
string GetDefaultXamarinSdkRoot ()
{
switch (Platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
case ApplePlatform.MacCatalyst:
return Sdks.XamIOS.SdkDir;
case ApplePlatform.MacOSX:
return Sdks.XamMac.FrameworkDirectory;
default:
throw new InvalidOperationException (string.Format (MSBStrings.InvalidPlatform, Platform));
}
}
IAppleSdkVersion GetDefaultSdkVersion ()
{
switch (Platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
case ApplePlatform.MacCatalyst:
return AppleSdkVersion.UseDefault;
case ApplePlatform.MacOSX:
var v = CurrentSdk.GetInstalledSdkVersions (false);
return v.Count > 0 ? v [v.Count - 1] : AppleSdkVersion.UseDefault;
default:
throw new InvalidOperationException (string.Format (MSBStrings.InvalidPlatform, Platform));
}
}
protected string GetEnvironmentVariableOverride ()
{
@ -147,6 +175,10 @@ namespace Xamarin.MacDev.Tasks {
public override bool Execute ()
{
AppleSdkSettings.Init ();
SetIsSimulator ();
// If XamarinSdkRoot is set, then make that override any other value, and in order to do so,
// set the corresponding environment variable accordingly.
if (!string.IsNullOrEmpty (XamarinSdkRoot))
@ -159,6 +191,25 @@ namespace Xamarin.MacDev.Tasks {
return !Log.HasLoggedErrors;
}
void SetIsSimulator ()
{
switch (Platform) {
case ApplePlatform.MacCatalyst:
case ApplePlatform.MacOSX:
return;
}
TargetArchitecture architectures;
if (string.IsNullOrEmpty (TargetArchitectures) || !Enum.TryParse (TargetArchitectures, out architectures))
architectures = TargetArchitecture.Default;
if (!string.IsNullOrEmpty (IsDotNetSimulatorBuild)) {
SdkIsSimulator = string.Equals (IsDotNetSimulatorBuild, "true", StringComparison.OrdinalIgnoreCase);
} else {
SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;
}
}
protected bool EnsureAppleSdkRoot ()
{
var currentSdk = CurrentSdk;

Просмотреть файл

@ -1,16 +1,16 @@
using System;
using Microsoft.Build.Framework;
using Xamarin.Messaging.Build.Client;
namespace Xamarin.iOS.Tasks
{
public class DetectSdkLocations : DetectSdkLocationsTaskBase, ICancelableTask
{
namespace Xamarin.MacDev.Tasks {
public class DetectSdkLocations : DetectSdkLocationsCoreTaskBase, ICancelableTask {
const string SdkVersionDefaultValue = "default";
public override bool Execute ()
{
if (!ShouldExecuteRemotely())
if (!ShouldExecuteRemotely ())
return base.Execute ();
// The new targets do not support the "default" value for the MtouchSdkVersion

Просмотреть файл

@ -41,7 +41,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CompileITunesMetadata" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateAssetPack" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.DetectSdkLocations" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.FindWatchOS2AppBundle" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.GetMlaunchArguments" AssemblyFile="$(_TaskAssemblyName)" />
@ -57,7 +56,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<!-- Xamarin.Mac-specific tasks. Some of these are duplicated with the Xamarin.iOS ones above, and should eventually be re-namespaced to be in Xamarin.MacDev -->
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CompileAppManifest" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.DetectSdkLocations" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.Mmp" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" />
@ -88,6 +86,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask TaskName="Xamarin.MacDev.Tasks.CompileProductDefinition" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.ComputeCodesignItems" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.DetectDebugNetworkConfiguration" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.DetectSdkLocations" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.Ditto" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.DSymUtil" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.EmbedProvisionProfile" AssemblyFile="$(_TaskAssemblyName)" />

Просмотреть файл

@ -1,37 +0,0 @@
using System;
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
namespace Xamarin.iOS.Tasks
{
public abstract class DetectSdkLocationsTaskBase : DetectSdkLocationsCoreTaskBase
{
protected override IAppleSdkVersion GetDefaultSdkVersion ()
{
return AppleSdkVersion.UseDefault;
}
public override bool Execute ()
{
AppleSdkSettings.Init ();
TargetArchitecture architectures;
if (string.IsNullOrEmpty (TargetArchitectures) || !Enum.TryParse (TargetArchitectures, out architectures))
architectures = TargetArchitecture.Default;
if (!string.IsNullOrEmpty (IsDotNetSimulatorBuild)) {
SdkIsSimulator = string.Equals (IsDotNetSimulatorBuild, "true", StringComparison.OrdinalIgnoreCase);
} else {
SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;
}
return base.Execute ();
}
protected override string GetDefaultXamarinSdkRoot ()
{
return Sdks.XamIOS.SdkDir;
}
}
}

Просмотреть файл

@ -27,6 +27,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Collections.Generic;
@ -62,58 +64,72 @@ namespace CoreText {
: b;
}
public static int? GetInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static int? GetInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).Int32Value;
}
public static nuint? GetUnsignedIntegerValue (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static nuint? GetUnsignedIntegerValue (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).NUIntValue;
}
public static T[] GetNativeArray<T> (NSDictionary dictionary, NSObject key, Converter<NativeHandle, T> converter)
public static T[]? GetNativeArray<T> (NSDictionary dictionary, NSObject? key, Converter<NativeHandle, T> converter)
{
if (key is null)
return null;
var cfArrayRef = CFDictionary.GetValue (dictionary.Handle, key.Handle);
if (cfArrayRef == NativeHandle.Zero || CFArray.GetCount (cfArrayRef) == 0)
return new T [0];
return NSArray.ArrayFromHandle (cfArrayRef, converter);
}
public static float? GetSingleValue (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static float? GetSingleValue (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).FloatValue;
}
public static string[] GetStringArray (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static string[]? GetStringArray (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return Array.Empty<string> ();
return CFArray.StringArrayFromHandle (value.Handle);
return CFArray.StringArrayFromHandle (value.Handle)!;
}
public static string GetStringValue (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static string? GetStringValue (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSString) value).ToString ();
}
public static uint? GetUInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject key)
public static uint? GetUInt32Value (IDictionary<NSObject, NSObject> dictionary, NSObject? key)
{
if (key is null)
return null;
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).UInt32Value;
}
@ -121,13 +137,15 @@ namespace CoreText {
public static bool? GetBoolValue (NSDictionary dictionary, NSObject key)
{
var value = dictionary [key];
if (value == null)
if (value is null)
return null;
return ((NSNumber) value).BoolValue;
}
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, int? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
@ -136,6 +154,8 @@ namespace CoreText {
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, float? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
@ -144,6 +164,8 @@ namespace CoreText {
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, uint? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
@ -152,6 +174,8 @@ namespace CoreText {
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, bool? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
@ -160,45 +184,55 @@ namespace CoreText {
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, nuint? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value.HasValue)
dictionary [key] = new NSNumber (value.Value);
else
dictionary.Remove (key);
}
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, IEnumerable<string> value)
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, IEnumerable<string>? value)
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
List<string> v;
if (value == null || (v = new List<string>(value)).Count == 0)
SetValue (dictionary, key, (NSObject) null);
if (value is null || (v = new List<string>(value)).Count == 0)
SetValue (dictionary, key, (NSObject?) null);
else
using (var array = NSArray.FromStrings (v.ToArray ()))
SetValue (dictionary, key, array);
}
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, NSObject value)
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, NSObject? value)
{
if (value != null)
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value is not null)
dictionary [key] = value;
else
dictionary.Remove (key);
}
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, string value)
public static void SetValue (IDictionary<NSObject, NSObject> dictionary, NSObject key, string? value)
{
if (value == null)
SetValue (dictionary, key, (NSObject) null);
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value is null)
SetValue (dictionary, key, (NSObject?) null);
else
using (var s = new NSString (value))
SetValue (dictionary, key, (NSObject) s);
}
public static void SetNativeValue<T> (NSDictionary dictionary, NSObject key, IEnumerable<T> value)
public static void SetNativeValue<T> (NSDictionary dictionary, NSObject key, IEnumerable<T>? value)
where T : INativeObject
{
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
List<NativeHandle> v;
if (value == null || (v = GetHandles (value)).Count == 0)
SetNativeValue (dictionary, key, (INativeObject) null);
if (value is null || (v = GetHandles (value)).Count == 0)
SetNativeValue (dictionary, key, (INativeObject?) null);
else
using (var array = CFArray.FromIntPtrs (v.ToArray ()))
SetNativeValue (dictionary, key, array);
@ -213,9 +247,11 @@ namespace CoreText {
return v;
}
public static void SetNativeValue (NSDictionary dictionary, NSObject key, INativeObject value)
public static void SetNativeValue (NSDictionary dictionary, NSObject key, INativeObject? value)
{
if (value != null) {
if (key is null)
throw new ArgumentOutOfRangeException (nameof (key));
if (value is not null) {
AssertWritable (dictionary);
CFMutableDictionary.SetValue (dictionary.Handle, key.Handle, value.Handle);
}

Просмотреть файл

@ -25,6 +25,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using ObjCRuntime;
@ -44,12 +47,12 @@ namespace CoreText {
static partial class CTBaselineClassID {
#if !NET
public static readonly NSString Roman;
public static readonly NSString IdeographicCentered;
public static readonly NSString IdeographicLow;
public static readonly NSString IdeographicHigh;
public static readonly NSString Hanging;
public static readonly NSString Math;
public static readonly NSString? Roman;
public static readonly NSString? IdeographicCentered;
public static readonly NSString? IdeographicLow;
public static readonly NSString? IdeographicHigh;
public static readonly NSString? Hanging;
public static readonly NSString? Math;
static CTBaselineClassID ()
{
@ -63,7 +66,7 @@ namespace CoreText {
}
#endif
public static NSString ToNSString (CTBaselineClass key)
public static NSString? ToNSString (CTBaselineClass key)
{
switch (key) {
case CTBaselineClass.Roman: return Roman;
@ -79,12 +82,12 @@ namespace CoreText {
public static CTBaselineClass FromHandle (IntPtr handle)
{
if (handle == Roman.Handle) return CTBaselineClass.Roman;
if (handle == IdeographicCentered.Handle) return CTBaselineClass.IdeographicCentered;
if (handle == IdeographicLow.Handle) return CTBaselineClass.IdeographicLow;
if (handle == IdeographicHigh.Handle) return CTBaselineClass.IdeographicHigh;
if (handle == Hanging.Handle) return CTBaselineClass.Hanging;
if (handle == Math.Handle) return CTBaselineClass.Math;
if (handle == Roman?.Handle) return CTBaselineClass.Roman;
if (handle == IdeographicCentered?.Handle) return CTBaselineClass.IdeographicCentered;
if (handle == IdeographicLow?.Handle) return CTBaselineClass.IdeographicLow;
if (handle == IdeographicHigh?.Handle) return CTBaselineClass.IdeographicHigh;
if (handle == Hanging?.Handle) return CTBaselineClass.Hanging;
if (handle == Math?.Handle) return CTBaselineClass.Math;
throw new ArgumentOutOfRangeException ("handle");
}
@ -98,8 +101,8 @@ namespace CoreText {
static partial class CTBaselineFontID {
#if !NET
public static readonly NSString Reference;
public static readonly NSString Original;
public static readonly NSString? Reference;
public static readonly NSString? Original;
static CTBaselineFontID ()
{
@ -109,7 +112,7 @@ namespace CoreText {
}
#endif // !NET
public static NSString ToNSString (CTBaselineFont key)
public static NSString? ToNSString (CTBaselineFont key)
{
switch (key) {
case CTBaselineFont.Reference: return Reference;

Просмотреть файл

@ -25,6 +25,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using CoreFoundation;
namespace CoreText {

Просмотреть файл

@ -251,13 +251,13 @@ namespace CoreText {
public CTFontFeatures (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
public NSDictionary Dictionary {get; private set;}
public string Name {
public string? Name {
get {return Adapter.GetStringValue (Dictionary, CTFontFeatureKey.Name);}
set {Adapter.SetValue (Dictionary, CTFontFeatureKey.Name, value);}
}
@ -280,7 +280,7 @@ namespace CoreText {
}
}
public IEnumerable<CTFontFeatureSelectors> Selectors {
public IEnumerable<CTFontFeatureSelectors>? Selectors {
get {
return Adapter.GetNativeArray (Dictionary, CTFontFeatureKey.Selectors,
d => CTFontFeatureSelectors.Create (FeatureGroup, Runtime.GetNSObject<NSDictionary> (d)!));
@ -313,7 +313,7 @@ namespace CoreText {
public CTFontFeatureSelectors (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -411,7 +411,7 @@ namespace CoreText {
}
}
public string Name {
public string? Name {
get {return Adapter.GetStringValue (Dictionary, CTFontFeatureSelectorKey.Name);}
set {Adapter.SetValue (Dictionary, CTFontFeatureSelectorKey.Name, value);}
}
@ -1680,7 +1680,7 @@ namespace CoreText {
internal CTFontFeatureSettings (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -1715,7 +1715,7 @@ namespace CoreText {
public CTFontVariationAxes (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -1741,7 +1741,7 @@ namespace CoreText {
set {Adapter.SetValue (Dictionary, CTFontVariationAxisKey.DefaultValue, value);}
}
public string Name {
public string? Name {
get {return Adapter.GetStringValue (Dictionary, CTFontVariationAxisKey.Name);}
set {Adapter.SetValue (Dictionary, CTFontVariationAxisKey.Name, value);}
}
@ -1779,7 +1779,7 @@ namespace CoreText {
public CTFontVariation (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -1842,7 +1842,7 @@ namespace CoreText {
static IntPtr Create (CTFontDescriptor descriptor, nfloat size)
{
if (descriptor is null)
throw new ArgumentNullException (nameof (descriptor));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptor));
var handle = CTFontCreateWithFontDescriptor (descriptor.Handle, size, IntPtr.Zero);
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -1860,7 +1860,7 @@ namespace CoreText {
static IntPtr Create (CTFontDescriptor descriptor, nfloat size, ref CGAffineTransform matrix)
{
if (descriptor is null)
throw new ArgumentNullException (nameof (descriptor));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptor));
var handle = CTFontCreateWithFontDescriptor (descriptor.Handle, size, ref matrix);
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -1886,7 +1886,7 @@ namespace CoreText {
static IntPtr Create (string name, nfloat size, CTFontOptions options)
{
if (name is null)
throw new ArgumentNullException (nameof (name));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (name));
var n = CFString.CreateNative (name);
try {
var handle = CTFontCreateWithNameAndOptions (n, size, IntPtr.Zero, (nuint) (ulong) options);
@ -1925,7 +1925,7 @@ namespace CoreText {
static IntPtr Create (string name, nfloat size, ref CGAffineTransform matrix, CTFontOptions options)
{
if (name is null)
throw new ArgumentNullException (nameof (name));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (name));
var n = CFString.CreateNative (name);
try {
var handle = CTFontCreateWithNameAndOptions (n, size, ref matrix, (nuint) (ulong) options);
@ -1964,7 +1964,7 @@ namespace CoreText {
static IntPtr Create (CTFontDescriptor descriptor, nfloat size, CTFontOptions options)
{
if (descriptor is null)
throw new ArgumentNullException (nameof (descriptor));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptor));
var handle = CTFontCreateWithFontDescriptorAndOptions (descriptor.Handle, size, IntPtr.Zero, (nuint) (ulong) options);
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -1998,7 +1998,7 @@ namespace CoreText {
static IntPtr Create (CTFontDescriptor descriptor, nfloat size, CTFontOptions options, ref CGAffineTransform matrix)
{
if (descriptor is null)
throw new ArgumentNullException (nameof (descriptor));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (descriptor));
var handle = CTFontCreateWithFontDescriptorAndOptions (descriptor.Handle, size, ref matrix, (nuint) (ulong) options);
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -2027,7 +2027,7 @@ namespace CoreText {
static IntPtr Create (CGFont font, nfloat size, CGAffineTransform transform, CTFontDescriptor descriptor)
{
if (font is null)
throw new ArgumentNullException (nameof (font));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
var handle = CTFontCreateWithGraphicsFont (font.Handle, size, ref transform, descriptor.GetHandle ());
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -2045,7 +2045,7 @@ namespace CoreText {
static IntPtr Create (CGFont font, nfloat size, CTFontDescriptor descriptor)
{
if (font is null)
throw new ArgumentNullException (nameof (font));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
var handle = CTFontCreateWithGraphicsFont2 (font.Handle, size, IntPtr.Zero, descriptor.GetHandle ());
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -2060,7 +2060,7 @@ namespace CoreText {
static IntPtr Create (CGFont font, nfloat size, CGAffineTransform transform)
{
if (font is null)
throw new ArgumentNullException (nameof (font));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
var handle = CTFontCreateWithGraphicsFont (font.Handle, size, ref transform, IntPtr.Zero);
if (handle == IntPtr.Zero)
throw ConstructorError.Unknown (typeof (CTFont));
@ -2098,7 +2098,7 @@ namespace CoreText {
public CTFont? WithAttributes (nfloat size, CTFontDescriptor attributes)
{
if (attributes is null)
throw new ArgumentNullException (nameof (attributes));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (attributes));
return CreateFont (CTFontCreateCopyWithAttributes (Handle, size, IntPtr.Zero, attributes.Handle));
}
@ -2137,7 +2137,7 @@ namespace CoreText {
public CTFont? WithFamily (nfloat size, string family)
{
if (family is null)
throw new ArgumentNullException (nameof (family));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (family));
var n = CFString.CreateNative (family);
try {
return CreateFont (CTFontCreateCopyWithFamily (Handle, size, IntPtr.Zero, n));
@ -2151,7 +2151,7 @@ namespace CoreText {
public CTFont? WithFamily (nfloat size, string family, ref CGAffineTransform matrix)
{
if (family is null)
throw new ArgumentNullException (nameof (family));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (family));
var n = CFString.CreateNative (family);
try {
return CreateFont (CTFontCreateCopyWithFamily (Handle, size, ref matrix, n));
@ -2173,7 +2173,7 @@ namespace CoreText {
public CTFont? ForString (string value, NSRange range)
{
if (value is null)
throw new ArgumentNullException (nameof (value));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
var n = CFString.CreateNative (value);
try {
return CreateFont (CTFontCreateForString (Handle, n, range));
@ -2214,7 +2214,7 @@ namespace CoreText {
public CTFont? ForString (string value, NSRange range, string? language)
{
if (value is null)
throw new ArgumentNullException (nameof (value));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
var v = CFString.CreateNative (value);
var l = CFString.CreateNative (language);
@ -2248,7 +2248,7 @@ namespace CoreText {
public NSObject? GetAttribute (NSString attribute)
{
if (attribute is null)
throw new ArgumentNullException (nameof (attribute));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (attribute));
return Runtime.GetNSObject (CTFontCopyAttribute (Handle, attribute.Handle));
}
@ -2318,7 +2318,7 @@ namespace CoreText {
static extern IntPtr CTFontCopyName (IntPtr font, IntPtr nameKey);
public string? GetName (CTFontNameKey nameKey)
{
return CFString.FromHandle (CTFontCopyName (Handle, CTFontNameKeyId.ToId (nameKey).Handle), releaseHandle: true);
return CFString.FromHandle (CTFontCopyName (Handle, CTFontNameKeyId.ToId (nameKey).GetHandle ()), releaseHandle: true);
}
[DllImport (Constants.CoreTextLibrary)]
@ -2332,7 +2332,7 @@ namespace CoreText {
public string? GetLocalizedName (CTFontNameKey nameKey, out string? actualLanguage)
{
IntPtr actual;
var ret = CFString.FromHandle (CTFontCopyLocalizedName (Handle, CTFontNameKeyId.ToId (nameKey).Handle, out actual), releaseHandle: true);
var ret = CFString.FromHandle (CTFontCopyLocalizedName (Handle, CTFontNameKeyId.ToId (nameKey).GetHandle (), out actual), releaseHandle: true);
actualLanguage = CFString.FromHandle (actual, releaseHandle: true);
return ret;
}
@ -2429,7 +2429,7 @@ namespace CoreText {
if (canBeNull && array is null)
return;
if (array is null)
throw new ArgumentNullException (name);
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (name));
if (array.Length < count)
throw new ArgumentException (string.Format ("{0}.Length cannot be < count", name), name);
}
@ -2517,7 +2517,7 @@ namespace CoreText {
public CGGlyph GetGlyphWithName (string glyphName)
{
if (glyphName is null)
throw new ArgumentNullException (nameof (glyphName));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (glyphName));
var nameHandle = CFString.CreateNative (glyphName);
try {
return CTFontGetGlyphWithName (Handle, nameHandle);
@ -2552,7 +2552,7 @@ namespace CoreText {
public CGRect GetBoundingRects (CTFontOrientation orientation, CGGlyph[] glyphs)
{
if (glyphs is null)
throw new ArgumentNullException (nameof (glyphs));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (glyphs));
return GetBoundingRects (orientation, glyphs, null, glyphs.Length);
}
@ -2570,7 +2570,7 @@ namespace CoreText {
public double GetAdvancesForGlyphs (CTFontOrientation orientation, CGGlyph[] glyphs)
{
if (glyphs is null)
throw new ArgumentNullException (nameof (glyphs));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (glyphs));
return GetAdvancesForGlyphs (orientation, glyphs, null, glyphs.Length);
}
@ -2613,11 +2613,11 @@ namespace CoreText {
public void DrawGlyphs (CGContext context, CGGlyph [] glyphs, CGPoint [] positions)
{
if (context is null)
throw new ArgumentNullException (nameof (context));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (context));
if (glyphs is null)
throw new ArgumentNullException (nameof (glyphs));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (glyphs));
if (positions is null)
throw new ArgumentNullException (nameof (positions));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (positions));
int gl = glyphs.Length;
if (gl != positions.Length)
throw new ArgumentException ("array sizes fo context and glyphs differ");
@ -2630,7 +2630,7 @@ namespace CoreText {
public nint GetLigatureCaretPositions (CGGlyph glyph, nfloat [] positions)
{
if (positions is null)
throw new ArgumentNullException (nameof (positions));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (positions));
return CTFontGetLigatureCaretPositions (Handle, glyph, positions, positions.Length);
}
#endregion

Просмотреть файл

@ -51,11 +51,11 @@ namespace CoreText {
#if !NET
public static class CTFontCollectionOptionKey {
public static readonly NSString RemoveDuplicates;
public static readonly NSString? RemoveDuplicates;
static CTFontCollectionOptionKey ()
{
RemoveDuplicates = Dlfcn.GetStringConstant (Libraries.CoreText.Handle, "kCTFontCollectionRemoveDuplicatesOption")!;
RemoveDuplicates = Dlfcn.GetStringConstant (Libraries.CoreText.Handle, "kCTFontCollectionRemoveDuplicatesOption");
}
}
#endif
@ -76,7 +76,7 @@ namespace CoreText {
public CTFontCollectionOptions (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -86,12 +86,16 @@ namespace CoreText {
// No mention of the expected type (int? NSNumber?)
public bool RemoveDuplicates {
get {
if (CTFontCollectionOptionKey.RemoveDuplicates is null)
return false;
var v = Adapter.GetInt32Value (Dictionary, CTFontCollectionOptionKey.RemoveDuplicates);
return v.HasValue ? v.Value != 0 : false;
}
set {
if (CTFontCollectionOptionKey.RemoveDuplicates is null)
throw new ArgumentOutOfRangeException (nameof (CTFontCollectionOptionKey.RemoveDuplicates));
var v = value ? (int?) 1 : null;
Adapter.SetValue (Dictionary, CTFontCollectionOptionKey.RemoveDuplicates, v);
Adapter.SetValue (Dictionary, CTFontCollectionOptionKey.RemoveDuplicates!, v);
}
}
}

Просмотреть файл

@ -87,54 +87,54 @@ namespace CoreText {
#if !NET
public static class CTFontDescriptorAttributeKey {
public static readonly NSString Url;
public static readonly NSString Name;
public static readonly NSString DisplayName;
public static readonly NSString FamilyName;
public static readonly NSString StyleName;
public static readonly NSString Traits;
public static readonly NSString Variation;
public static readonly NSString Size;
public static readonly NSString Matrix;
public static readonly NSString CascadeList;
public static readonly NSString CharacterSet;
public static readonly NSString Languages;
public static readonly NSString BaselineAdjust;
public static readonly NSString MacintoshEncodings;
public static readonly NSString Features;
public static readonly NSString FeatureSettings;
public static readonly NSString FixedAdvance;
public static readonly NSString FontOrientation;
public static readonly NSString FontFormat;
public static readonly NSString RegistrationScope;
public static readonly NSString Priority;
public static readonly NSString Enabled;
public static readonly NSString? Url;
public static readonly NSString? Name;
public static readonly NSString? DisplayName;
public static readonly NSString? FamilyName;
public static readonly NSString? StyleName;
public static readonly NSString? Traits;
public static readonly NSString? Variation;
public static readonly NSString? Size;
public static readonly NSString? Matrix;
public static readonly NSString? CascadeList;
public static readonly NSString? CharacterSet;
public static readonly NSString? Languages;
public static readonly NSString? BaselineAdjust;
public static readonly NSString? MacintoshEncodings;
public static readonly NSString? Features;
public static readonly NSString? FeatureSettings;
public static readonly NSString? FixedAdvance;
public static readonly NSString? FontOrientation;
public static readonly NSString? FontFormat;
public static readonly NSString? RegistrationScope;
public static readonly NSString? Priority;
public static readonly NSString? Enabled;
static CTFontDescriptorAttributeKey ()
{
var handle = Libraries.CoreText.Handle;
Url = Dlfcn.GetStringConstant (handle, "kCTFontURLAttribute")!;
Name = Dlfcn.GetStringConstant (handle, "kCTFontNameAttribute")!;
DisplayName = Dlfcn.GetStringConstant (handle, "kCTFontDisplayNameAttribute")!;
FamilyName = Dlfcn.GetStringConstant (handle, "kCTFontFamilyNameAttribute")!;
StyleName = Dlfcn.GetStringConstant (handle, "kCTFontStyleNameAttribute")!;
Traits = Dlfcn.GetStringConstant (handle, "kCTFontTraitsAttribute")!;
Variation = Dlfcn.GetStringConstant (handle, "kCTFontVariationAttribute")!;
Size = Dlfcn.GetStringConstant (handle, "kCTFontSizeAttribute")!;
Matrix = Dlfcn.GetStringConstant (handle, "kCTFontMatrixAttribute")!;
CascadeList = Dlfcn.GetStringConstant (handle, "kCTFontCascadeListAttribute")!;
CharacterSet = Dlfcn.GetStringConstant (handle, "kCTFontCharacterSetAttribute")!;
Languages = Dlfcn.GetStringConstant (handle, "kCTFontLanguagesAttribute")!;
BaselineAdjust = Dlfcn.GetStringConstant (handle, "kCTFontBaselineAdjustAttribute")!;
MacintoshEncodings = Dlfcn.GetStringConstant (handle, "kCTFontMacintoshEncodingsAttribute")!;
Features = Dlfcn.GetStringConstant (handle, "kCTFontFeaturesAttribute")!;
FeatureSettings = Dlfcn.GetStringConstant (handle, "kCTFontFeatureSettingsAttribute")!;
FixedAdvance = Dlfcn.GetStringConstant (handle, "kCTFontFixedAdvanceAttribute")!;
FontOrientation = Dlfcn.GetStringConstant (handle, "kCTFontOrientationAttribute")!;
FontFormat = Dlfcn.GetStringConstant (handle, "kCTFontFormatAttribute")!;
RegistrationScope = Dlfcn.GetStringConstant (handle, "kCTFontRegistrationScopeAttribute")!;
Priority = Dlfcn.GetStringConstant (handle, "kCTFontPriorityAttribute")!;
Enabled = Dlfcn.GetStringConstant (handle, "kCTFontEnabledAttribute")!;
Url = Dlfcn.GetStringConstant (handle, "kCTFontURLAttribute");
Name = Dlfcn.GetStringConstant (handle, "kCTFontNameAttribute");
DisplayName = Dlfcn.GetStringConstant (handle, "kCTFontDisplayNameAttribute");
FamilyName = Dlfcn.GetStringConstant (handle, "kCTFontFamilyNameAttribute");
StyleName = Dlfcn.GetStringConstant (handle, "kCTFontStyleNameAttribute");
Traits = Dlfcn.GetStringConstant (handle, "kCTFontTraitsAttribute");
Variation = Dlfcn.GetStringConstant (handle, "kCTFontVariationAttribute");
Size = Dlfcn.GetStringConstant (handle, "kCTFontSizeAttribute");
Matrix = Dlfcn.GetStringConstant (handle, "kCTFontMatrixAttribute");
CascadeList = Dlfcn.GetStringConstant (handle, "kCTFontCascadeListAttribute");
CharacterSet = Dlfcn.GetStringConstant (handle, "kCTFontCharacterSetAttribute");
Languages = Dlfcn.GetStringConstant (handle, "kCTFontLanguagesAttribute");
BaselineAdjust = Dlfcn.GetStringConstant (handle, "kCTFontBaselineAdjustAttribute");
MacintoshEncodings = Dlfcn.GetStringConstant (handle, "kCTFontMacintoshEncodingsAttribute");
Features = Dlfcn.GetStringConstant (handle, "kCTFontFeaturesAttribute");
FeatureSettings = Dlfcn.GetStringConstant (handle, "kCTFontFeatureSettingsAttribute");
FixedAdvance = Dlfcn.GetStringConstant (handle, "kCTFontFixedAdvanceAttribute");
FontOrientation = Dlfcn.GetStringConstant (handle, "kCTFontOrientationAttribute");
FontFormat = Dlfcn.GetStringConstant (handle, "kCTFontFormatAttribute");
RegistrationScope = Dlfcn.GetStringConstant (handle, "kCTFontRegistrationScopeAttribute");
Priority = Dlfcn.GetStringConstant (handle, "kCTFontPriorityAttribute");
Enabled = Dlfcn.GetStringConstant (handle, "kCTFontEnabledAttribute");
}
}
#endif // !NET
@ -155,7 +155,7 @@ namespace CoreText {
public CTFontDescriptorAttributes (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -163,135 +163,148 @@ namespace CoreText {
public NSUrl Url {
get {return (NSUrl) Dictionary [CTFontDescriptorAttributeKey.Url];}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Url, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Url!, value);}
}
public string Name {
public string? Name {
get {return Adapter.GetStringValue (Dictionary, CTFontDescriptorAttributeKey.Name);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Name, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Name!, value);}
}
public string DisplayName {
public string? DisplayName {
get {return Adapter.GetStringValue (Dictionary, CTFontDescriptorAttributeKey.DisplayName);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.DisplayName, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.DisplayName!, value);}
}
public string FamilyName {
public string? FamilyName {
get {return Adapter.GetStringValue (Dictionary, CTFontDescriptorAttributeKey.FamilyName);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FamilyName, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FamilyName!, value);}
}
public string StyleName {
public string? StyleName {
get {return Adapter.GetStringValue (Dictionary, CTFontDescriptorAttributeKey.StyleName);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.StyleName, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.StyleName!, value);}
}
public CTFontTraits? Traits {
get {
var traits = (NSDictionary) Dictionary [CTFontDescriptorAttributeKey.Traits];
if (traits is null)
return null;
return new CTFontTraits (traits);
if (CTFontDescriptorAttributeKey.Traits is NSString traitsKey && Dictionary[traitsKey] is NSDictionary traits)
return new CTFontTraits (traits);
return null;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Traits, value?.Dictionary);
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Traits!, value?.Dictionary);
}
}
public CTFontVariation? Variation {
get {
var variation = (NSDictionary) Dictionary [CTFontDescriptorAttributeKey.Variation];
return variation is null ? null : new CTFontVariation (variation);
if (CTFontDescriptorAttributeKey.Variation is NSString variationKey && Dictionary[variationKey] is NSDictionary variation)
return new CTFontVariation (variation);
return null;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Variation, value?.Dictionary);
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Variation!, value?.Dictionary);
}
}
// CFNumber
public float? Size {
get {return Adapter.GetSingleValue (Dictionary, CTFontDescriptorAttributeKey.Size);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Size, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Size!, value);}
}
public unsafe CGAffineTransform? Matrix {
get {
var d = (NSData) Dictionary [CTFontDescriptorAttributeKey.Matrix];
if (d == null)
return null;
return Marshal.PtrToStructure<CGAffineTransform> (d.Bytes);
if (CTFontDescriptorAttributeKey.Matrix is NSString matrixKey && Dictionary[matrixKey] is NSData d)
return Marshal.PtrToStructure<CGAffineTransform> (d.Bytes);
return null;
}
set {
if (CTFontDescriptorAttributeKey.Matrix is null)
throw new ArgumentOutOfRangeException (nameof (CTFontDescriptorAttributeKey.Matrix));
if (!value.HasValue)
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Matrix, (NSObject?) null);
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Matrix!, (NSObject?) null);
else {
byte[] data = new byte [sizeof (CGAffineTransform)];
fixed (byte* p = data) {
Marshal.StructureToPtr (value.Value, (IntPtr) p, false);
}
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Matrix, NSData.FromArray (data));
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Matrix!, NSData.FromArray (data));
}
}
}
public IEnumerable<CTFontDescriptor> CascadeList {
public IEnumerable<CTFontDescriptor>? CascadeList {
get {
return Adapter.GetNativeArray (Dictionary, CTFontDescriptorAttributeKey.CascadeList,
d => new CTFontDescriptor (d, false));
if (CTFontDescriptorAttributeKey.CascadeList is NSString cascadeList)
return Adapter.GetNativeArray (Dictionary, cascadeList, d => new CTFontDescriptor (d, false));
return null;
}
set {Adapter.SetNativeValue (Dictionary, CTFontDescriptorAttributeKey.CascadeList, value);}
set {Adapter.SetNativeValue (Dictionary, CTFontDescriptorAttributeKey.CascadeList!, value);}
}
public NSCharacterSet CharacterSet {
get {return (NSCharacterSet) Dictionary [CTFontDescriptorAttributeKey.CharacterSet];}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.CharacterSet, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.CharacterSet!, value);}
}
public IEnumerable<string> Languages {
public IEnumerable<string>? Languages {
get {return Adapter.GetStringArray (Dictionary, CTFontDescriptorAttributeKey.Languages);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Languages, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Languages!, value);}
}
// float represented as a CFNumber
public float? BaselineAdjust {
get {return Adapter.GetSingleValue (Dictionary, CTFontDescriptorAttributeKey.BaselineAdjust);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.BaselineAdjust, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.BaselineAdjust!, value);}
}
public float? MacintoshEncodings {
get {return Adapter.GetSingleValue (Dictionary, CTFontDescriptorAttributeKey.MacintoshEncodings);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.MacintoshEncodings, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.MacintoshEncodings!, value);}
}
public IEnumerable<CTFontFeatures> Features {
public IEnumerable<CTFontFeatures>? Features {
get {
return Adapter.GetNativeArray (Dictionary, CTFontDescriptorAttributeKey.Features,
if (CTFontDescriptorAttributeKey.Features is NSString features) {
return Adapter.GetNativeArray (Dictionary, features,
d => new CTFontFeatures ((NSDictionary) Runtime.GetNSObject (d)!));
}
return null;
}
set {
if (CTFontDescriptorAttributeKey.Features is null)
throw new ArgumentOutOfRangeException (nameof (CTFontDescriptorAttributeKey.Features));
List<CTFontFeatures> v;
if (value is null || (v = new List<CTFontFeatures> (value)).Count == 0) {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Features, (NSObject?) null);
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Features!, (NSObject?) null);
return;
}
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Features,
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Features!,
NSArray.FromNSObjects ((IList<NSObject>) v.ConvertAll (e => (NSObject) e.Dictionary)));
}
}
public IEnumerable<CTFontFeatureSettings> FeatureSettings {
public IEnumerable<CTFontFeatureSettings>? FeatureSettings {
get {
return Adapter.GetNativeArray (Dictionary, CTFontDescriptorAttributeKey.Features,
if (CTFontDescriptorAttributeKey.Features is NSString features) {
return Adapter.GetNativeArray (Dictionary, CTFontDescriptorAttributeKey.Features,
d => new CTFontFeatureSettings ((NSDictionary) Runtime.GetNSObject (d)!));
}
return null;
}
set {
if (CTFontDescriptorAttributeKey.Features is null)
throw new ArgumentOutOfRangeException (nameof (CTFontDescriptorAttributeKey.Features));
List<CTFontFeatureSettings> v;
if (value is null || (v = new List<CTFontFeatureSettings> (value)).Count == 0) {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Features, (NSObject?) null);
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Features!, (NSObject?) null);
return;
}
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FeatureSettings,
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FeatureSettings!,
NSArray.FromNSObjects ((IList<NSObject>) v.ConvertAll (e => (NSObject) e.Dictionary)));
}
}
@ -299,49 +312,61 @@ namespace CoreText {
// CFNumber
public float? FixedAdvance {
get {return Adapter.GetSingleValue (Dictionary, CTFontDescriptorAttributeKey.FixedAdvance);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FixedAdvance, value);}
set {Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FixedAdvance!, value);}
}
public CTFontOrientation? FontOrientation {
get {
var value = Adapter.GetUInt32Value (Dictionary, CTFontDescriptorAttributeKey.FontOrientation);
return !value.HasValue ? null : (CTFontOrientation?) value.Value;
if (CTFontDescriptorAttributeKey.FontOrientation is NSString fontOrientation) {
var value = Adapter.GetUInt32Value (Dictionary, fontOrientation);
return !value.HasValue ? null : (CTFontOrientation?) value.Value;
}
return null;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FontOrientation,
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FontOrientation!,
value.HasValue ? (uint?) value.Value : null);
}
}
public CTFontFormat? FontFormat {
get {
var value = Adapter.GetUInt32Value (Dictionary, CTFontDescriptorAttributeKey.FontFormat);
return !value.HasValue ? null : (CTFontFormat?) value.Value;
if (CTFontDescriptorAttributeKey.FontFormat is NSString fontFormat) {
var value = Adapter.GetUInt32Value (Dictionary, fontFormat);
return !value.HasValue ? null : (CTFontFormat?) value.Value;
}
return null;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FontFormat,
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.FontFormat!,
value.HasValue ? (uint?) value.Value : null);
}
}
public CTFontManagerScope? RegistrationScope {
get {
var value = Adapter.GetUnsignedIntegerValue (Dictionary, CTFontDescriptorAttributeKey.RegistrationScope);
return !value.HasValue ? null : (CTFontManagerScope?) (ulong) value.Value;
if (CTFontDescriptorAttributeKey.RegistrationScope is NSString registrationScope) {
var value = Adapter.GetUnsignedIntegerValue (Dictionary, registrationScope);
return !value.HasValue ? null : (CTFontManagerScope?) (ulong) value.Value;
}
return null;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.RegistrationScope,
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.RegistrationScope!,
value.HasValue ? (nuint?) (ulong) value.Value : null);
}
}
public CTFontPriority? Priority {
get {
var value = Adapter.GetUInt32Value (Dictionary, CTFontDescriptorAttributeKey.Priority);
return !value.HasValue ? null : (CTFontPriority?) value.Value;
if (CTFontDescriptorAttributeKey.Priority is NSString priority) {
var value = Adapter.GetUInt32Value (Dictionary, priority);
return !value.HasValue ? null : (CTFontPriority?) value.Value;
}
return null;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Priority,
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Priority!,
value.HasValue ? (uint?) value.Value : null);
}
}
@ -354,8 +379,7 @@ namespace CoreText {
return value.Int32Value != 0;
}
set {
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Enabled,
value ? new NSNumber (1) : null);
Adapter.SetValue (Dictionary, CTFontDescriptorAttributeKey.Enabled!, value ? new NSNumber (1) : null);
}
}
}
@ -379,7 +403,7 @@ namespace CoreText {
static IntPtr Create (string name, nfloat size)
{
if (name is null)
throw new ArgumentNullException (nameof (name));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (name));
var nameHandle = CFString.CreateNative (name);
try {
return CTFontDescriptorCreateWithNameAndSize (nameHandle, size);
@ -405,7 +429,7 @@ namespace CoreText {
public CTFontDescriptor? WithAttributes (NSDictionary attributes)
{
if (attributes is null)
throw new ArgumentNullException (nameof (attributes));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (attributes));
return CreateDescriptor (CTFontDescriptorCreateCopyWithAttributes (Handle, attributes.Handle));
}
@ -418,8 +442,8 @@ namespace CoreText {
public CTFontDescriptor? WithAttributes (CTFontDescriptorAttributes attributes)
{
if (attributes == null)
throw new ArgumentNullException (nameof (attributes));
if (attributes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (attributes));
return CreateDescriptor (CTFontDescriptorCreateCopyWithAttributes (Handle, attributes.Dictionary.Handle));
}
@ -688,7 +712,7 @@ namespace CoreText {
public NSObject? GetAttribute (NSString attribute)
{
if (attribute is null)
throw new ArgumentNullException (nameof (attribute));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (attribute));
return Runtime.GetNSObject<NSObject> (CTFontDescriptorCopyAttribute (Handle, attribute.Handle), true);
}
@ -734,7 +758,7 @@ namespace CoreText {
// FIXME: the P/Invoke used below is wrong, it expects a block, not a function pointer.
// throwing a NIE instead of crashing until this is implemented properly.
throw new NotImplementedException ();
// var ma = mandatoryAttributes == null ? IntPtr.Zero : mandatoryAttributes.Handle;
// var ma = mandatoryAttributes is null ? IntPtr.Zero : mandatoryAttributes.Handle;
// // FIXME: SIGSEGV probably due to mandatoryAttributes mismatch
// using (var ar = CFArray.FromNativeObjects (descriptors)) {
// return CTFontDescriptorMatchFontDescriptorsWithProgressHandler (ar.Handle, ma, progressHandler);

Просмотреть файл

@ -27,6 +27,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
@ -112,8 +115,8 @@ namespace CoreText {
#endif
public static bool IsFontSupported (NSUrl url)
{
if (url == null)
throw new ArgumentNullException ("url");
if (url is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
return CTFontManagerIsSupportedFont (url.Handle);
}
#elif !XAMCORE_3_0
@ -130,8 +133,8 @@ namespace CoreText {
[Obsolete ("API not available on iOS, it will always return false.")]
public static bool IsFontSupported (NSUrl url)
{
if (url == null)
throw new ArgumentNullException ("url");
if (url is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
return false;
}
#endif
@ -139,10 +142,10 @@ namespace CoreText {
[DllImport (Constants.CoreTextLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool CTFontManagerRegisterFontsForURL (IntPtr fontUrl, CTFontManagerScope scope, ref IntPtr error);
public static NSError RegisterFontsForUrl (NSUrl fontUrl, CTFontManagerScope scope)
public static NSError? RegisterFontsForUrl (NSUrl fontUrl, CTFontManagerScope scope)
{
if (fontUrl == null)
throw new ArgumentNullException ("fontUrl");
if (fontUrl is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fontUrl));
IntPtr error = IntPtr.Zero;
@ -159,17 +162,17 @@ namespace CoreText {
static NSArray EnsureNonNullArray (object [] items, string name)
{
if (items == null)
throw new ArgumentNullException (name);
if (items is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (name));
foreach (var i in items)
if (i == null)
if (i is null)
throw new ArgumentException ("Array contains a null entry", name);
return NSArray.FromObjects (items);
}
static T[] ArrayFromHandle<T> (IntPtr handle, bool releaseAfterUse) where T : class, INativeObject
static T[]? ArrayFromHandle<T> (IntPtr handle, bool releaseAfterUse) where T : class, INativeObject
{
if (handle == IntPtr.Zero)
return null;
@ -228,7 +231,7 @@ namespace CoreText {
[Deprecated (PlatformName.WatchOS, 6,0, message: "Use 'RegisterFonts' instead.")]
[Deprecated (PlatformName.TvOS, 13,0, message: "Use 'RegisterFonts' instead.")]
#endif
public static NSError [] RegisterFontsForUrl (NSUrl [] fontUrls, CTFontManagerScope scope)
public static NSError []? RegisterFontsForUrl (NSUrl [] fontUrls, CTFontManagerScope scope)
{
using (var arr = EnsureNonNullArray (fontUrls, nameof (fontUrls))) {
IntPtr error_array = IntPtr.Zero;
@ -258,7 +261,7 @@ namespace CoreText {
static unsafe bool TrampolineRegistrationHandler (IntPtr block, /* NSArray */ IntPtr errors, bool done)
{
var del = BlockLiteral.GetTarget<CTFontRegistrationHandler> (block);
return del != null ? del (NSArray.ArrayFromHandle<NSError> (errors), done) : true;
return del is not null ? del (NSArray.ArrayFromHandle<NSError> (errors), done) : true;
}
#if NET
@ -304,7 +307,7 @@ namespace CoreText {
public static void RegisterFonts (NSUrl [] fontUrls, CTFontManagerScope scope, bool enabled, CTFontRegistrationHandler registrationHandler)
{
using (var arr = EnsureNonNullArray (fontUrls, nameof (fontUrls))) {
if (registrationHandler == null) {
if (registrationHandler is null) {
CTFontManagerRegisterFontURLs (arr.Handle, scope, enabled, IntPtr.Zero);
} else {
BlockLiteral block_handler = new BlockLiteral ();
@ -319,10 +322,10 @@ namespace CoreText {
[return: MarshalAs (UnmanagedType.I1)]
static extern bool CTFontManagerUnregisterFontsForURL(IntPtr fotUrl, CTFontManagerScope scope, ref IntPtr error);
public static NSError UnregisterFontsForUrl (NSUrl fontUrl, CTFontManagerScope scope)
public static NSError? UnregisterFontsForUrl (NSUrl fontUrl, CTFontManagerScope scope)
{
if (fontUrl == null)
throw new ArgumentNullException ("fontUrl");
if (fontUrl is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fontUrl));
IntPtr error = IntPtr.Zero;
@ -383,7 +386,7 @@ namespace CoreText {
[Deprecated (PlatformName.WatchOS, 6,0, message : "Use 'UnregisterFonts' instead.")]
[Deprecated (PlatformName.TvOS, 13,0, message : "Use 'UnregisterFonts' instead.")]
#endif
public static NSError [] UnregisterFontsForUrl (NSUrl [] fontUrls, CTFontManagerScope scope)
public static NSError []? UnregisterFontsForUrl (NSUrl [] fontUrls, CTFontManagerScope scope)
{
IntPtr error_array = IntPtr.Zero;
using (var arr = EnsureNonNullArray (fontUrls, nameof (fontUrls))) {
@ -436,7 +439,7 @@ namespace CoreText {
public static void UnregisterFonts (NSUrl [] fontUrls, CTFontManagerScope scope, CTFontRegistrationHandler registrationHandler)
{
using (var arr = EnsureNonNullArray (fontUrls, nameof (fontUrls))) {
if (registrationHandler == null) {
if (registrationHandler is null) {
CTFontManagerUnregisterFontURLs (arr.Handle, scope, IntPtr.Zero);
} else {
BlockLiteral block_handler = new BlockLiteral ();
@ -468,8 +471,8 @@ namespace CoreText {
#endif
public static CTFontDescriptor[] GetFonts (NSUrl url)
{
if (url == null)
throw new ArgumentNullException ("url");
if (url is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));
var arrayPtr = CTFontManagerCreateFontDescriptorsFromURL (url.Handle);
if (arrayPtr == IntPtr.Zero)
@ -488,10 +491,10 @@ namespace CoreText {
[return: MarshalAs (UnmanagedType.I1)]
static extern bool CTFontManagerRegisterGraphicsFont (IntPtr cgfont, out IntPtr error);
public static bool RegisterGraphicsFont (CGFont font, out NSError error)
public static bool RegisterGraphicsFont (CGFont font, out NSError? error)
{
if (font == null)
throw new ArgumentNullException ("font");
if (font is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
IntPtr h = IntPtr.Zero;
bool ret;
try {
@ -511,10 +514,10 @@ namespace CoreText {
[return: MarshalAs (UnmanagedType.I1)]
static extern bool CTFontManagerUnregisterGraphicsFont (IntPtr cgfont, out IntPtr error);
public static bool UnregisterGraphicsFont (CGFont font, out NSError error)
public static bool UnregisterGraphicsFont (CGFont font, out NSError? error)
{
if (font == null)
throw new ArgumentNullException ("font");
if (font is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
IntPtr h = IntPtr.Zero;
bool ret;
try {
@ -537,11 +540,13 @@ namespace CoreText {
#if !XAMCORE_3_0
ErrorDomain = Dlfcn.GetStringConstant (handle, "kCTFontManagerErrorDomain");
#endif
#pragma warning disable CS0618 // Type or member is obsolete
ErrorFontUrlsKey = Dlfcn.GetStringConstant (handle, "kCTFontManagerErrorFontURLsKey");
#pragma warning restore CS0618 // Type or member is obsolete
}
#endif // !NET
static NSString _RegisteredFontsChangedNotification;
static NSString? _RegisteredFontsChangedNotification;
#if NET
[SupportedOSPlatform ("ios7.0")]
@ -551,20 +556,20 @@ namespace CoreText {
#else
[iOS (7,0)]
#endif
static NSString RegisteredFontsChangedNotification {
static NSString? RegisteredFontsChangedNotification {
get {
if (_RegisteredFontsChangedNotification == null)
if (_RegisteredFontsChangedNotification is null)
_RegisteredFontsChangedNotification = Dlfcn.GetStringConstant (Libraries.CoreText.Handle, "kCTFontManagerRegisteredFontsChangedNotification");
return _RegisteredFontsChangedNotification;
}
}
#if !XAMCORE_3_0
public readonly static NSString ErrorDomain;
public readonly static NSString? ErrorDomain;
#endif
#if !NET
[Obsolete ("Use the 'CTFontManagerErrorKeys.FontUrlsKey' property instead.")]
public readonly static NSString ErrorFontUrlsKey;
public readonly static NSString? ErrorFontUrlsKey;
#endif
public static partial class Notifications {
@ -618,7 +623,7 @@ namespace CoreText {
public static void RegisterFontDescriptors (CTFontDescriptor[] fontDescriptors, CTFontManagerScope scope, bool enabled, CTFontRegistrationHandler registrationHandler)
{
using (var arr = EnsureNonNullArray (fontDescriptors, nameof (fontDescriptors))) {
if (registrationHandler == null) {
if (registrationHandler is null) {
CTFontManagerRegisterFontDescriptors (arr.Handle, scope, enabled, IntPtr.Zero);
} else {
BlockLiteral block_handler = new BlockLiteral ();
@ -672,7 +677,7 @@ namespace CoreText {
public static void UnregisterFontDescriptors (CTFontDescriptor[] fontDescriptors, CTFontManagerScope scope, CTFontRegistrationHandler registrationHandler)
{
using (var arr = EnsureNonNullArray (fontDescriptors, nameof (fontDescriptors))) {
if (registrationHandler == null) {
if (registrationHandler is null) {
CTFontManagerUnregisterFontDescriptors (arr.Handle, scope, IntPtr.Zero);
} else {
BlockLiteral block_handler = new BlockLiteral ();
@ -706,7 +711,7 @@ namespace CoreText {
[NoTV]
[NoMac]
#endif
public static CTFontDescriptor[] GetRegisteredFontDescriptors (CTFontManagerScope scope, bool enabled)
public static CTFontDescriptor[]? GetRegisteredFontDescriptors (CTFontManagerScope scope, bool enabled)
{
var p = CTFontManagerCopyRegisteredFontDescriptors (scope, enabled);
// Copy/Create rule - we must release the CFArrayRef
@ -718,10 +723,10 @@ namespace CoreText {
[DllImport (Constants.CoreTextLibrary)]
static extern unsafe /* CTFontDescriptorRef _Nullable */ IntPtr CTFontManagerCreateFontDescriptorFromData (/* CFDataRef */ IntPtr data);
public static CTFontDescriptor CreateFontDescriptor (NSData data)
public static CTFontDescriptor? CreateFontDescriptor (NSData data)
{
if (data == null)
throw new ArgumentNullException (nameof (data));
if (data is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));
var p = CTFontManagerCreateFontDescriptorFromData (data.Handle);
if (p == IntPtr.Zero)
@ -755,10 +760,10 @@ namespace CoreText {
[Mac (10,15)]
[iOS (13,0)]
#endif
public static CTFontDescriptor[] CreateFontDescriptors (NSData data)
public static CTFontDescriptor[]? CreateFontDescriptors (NSData data)
{
if (data == null)
throw new ArgumentNullException (nameof (data));
if (data is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data));
var p = CTFontManagerCreateFontDescriptorsFromData (data.Handle);
// Copy/Create rule - we must release the CFArrayRef
@ -810,7 +815,7 @@ namespace CoreText {
public static void RegisterFonts (string[] assetNames, CFBundle bundle, CTFontManagerScope scope, bool enabled, CTFontRegistrationHandler registrationHandler)
{
using (var arr = EnsureNonNullArray (assetNames, nameof (assetNames))) {
if (registrationHandler == null) {
if (registrationHandler is null) {
CTFontManagerRegisterFontsWithAssetNames (arr.Handle, bundle.GetHandle (), scope, enabled, IntPtr.Zero);
} else {
BlockLiteral block_handler = new BlockLiteral ();
@ -855,7 +860,7 @@ namespace CoreText {
static unsafe void TrampolineRequestFonts (IntPtr block, /* CFArray */ IntPtr fontDescriptors)
{
var del = BlockLiteral.GetTarget<CTFontManagerRequestFontsHandler> (block);
if (del != null)
if (del is not null)
del (NSArray.ArrayFromHandle<CTFontDescriptor> (fontDescriptors));
}
@ -873,8 +878,8 @@ namespace CoreText {
[BindingImpl (BindingImplOptions.Optimizable)]
public static void RequestFonts (CTFontDescriptor[] fontDescriptors, CTFontManagerRequestFontsHandler completionHandler)
{
if (completionHandler == null)
throw new ArgumentNullException (nameof (completionHandler));
if (completionHandler is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (completionHandler));
using (var arr = EnsureNonNullArray (fontDescriptors, nameof (fontDescriptors))) {
BlockLiteral block_handler = new BlockLiteral ();

Просмотреть файл

@ -26,6 +26,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Runtime.InteropServices;
@ -58,24 +61,24 @@ namespace CoreText {
static partial class CTFontNameKeyId {
#if !NET
public static readonly NSString Copyright;
public static readonly NSString Family;
public static readonly NSString SubFamily;
public static readonly NSString Style;
public static readonly NSString Unique;
public static readonly NSString Full;
public static readonly NSString Version;
public static readonly NSString PostScript;
public static readonly NSString Trademark;
public static readonly NSString Manufacturer;
public static readonly NSString Designer;
public static readonly NSString Description;
public static readonly NSString VendorUrl;
public static readonly NSString DesignerUrl;
public static readonly NSString License;
public static readonly NSString LicenseUrl;
public static readonly NSString SampleText;
public static readonly NSString PostscriptCid;
public static readonly NSString? Copyright;
public static readonly NSString? Family;
public static readonly NSString? SubFamily;
public static readonly NSString? Style;
public static readonly NSString? Unique;
public static readonly NSString? Full;
public static readonly NSString? Version;
public static readonly NSString? PostScript;
public static readonly NSString? Trademark;
public static readonly NSString? Manufacturer;
public static readonly NSString? Designer;
public static readonly NSString? Description;
public static readonly NSString? VendorUrl;
public static readonly NSString? DesignerUrl;
public static readonly NSString? License;
public static readonly NSString? LicenseUrl;
public static readonly NSString? SampleText;
public static readonly NSString? PostscriptCid;
static CTFontNameKeyId ()
{
@ -101,7 +104,7 @@ namespace CoreText {
}
#endif
public static NSString ToId (CTFontNameKey key)
public static NSString? ToId (CTFontNameKey key)
{
switch (key) {
case CTFontNameKey.Copyright: return Copyright;
@ -128,7 +131,10 @@ namespace CoreText {
public static CTFontNameKey ToFontNameKey (NSString key)
{
if (key == Copyright) return CTFontNameKey.Copyright;
if (key is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (key));
if (key == Copyright) return CTFontNameKey.Copyright;
if (key == Family) return CTFontNameKey.Family;
if (key == SubFamily) return CTFontNameKey.SubFamily;
if (key == Style) return CTFontNameKey.Style;

Просмотреть файл

@ -26,6 +26,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Runtime.InteropServices;
@ -38,10 +41,10 @@ namespace CoreText {
#if !NET
public static class CTFontTraitKey {
public static readonly NSString Symbolic;
public static readonly NSString Weight;
public static readonly NSString Width;
public static readonly NSString Slant;
public static readonly NSString? Symbolic;
public static readonly NSString? Weight;
public static readonly NSString? Width;
public static readonly NSString? Slant;
static CTFontTraitKey ()
{
@ -102,8 +105,8 @@ namespace CoreText {
public CTFontTraits (NSDictionary dictionary)
{
if (dictionary == null)
throw new ArgumentNullException ("dictionary");
if (dictionary is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -112,7 +115,7 @@ namespace CoreText {
// CFNumber
public uint? Symbolic {
get {return Adapter.GetUInt32Value (Dictionary, CTFontTraitKey.Symbolic);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Symbolic, value);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Symbolic!, value);}
}
public CTFontSymbolicTraits? SymbolicTraits {
@ -144,19 +147,19 @@ namespace CoreText {
// CFNumber representing a float value
public float? Weight {
get {return Adapter.GetSingleValue (Dictionary, CTFontTraitKey.Weight);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Weight, value);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Weight!, value);}
}
// CFNumber representing a float value
public float? Width {
get {return Adapter.GetSingleValue (Dictionary, CTFontTraitKey.Width);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Width, value);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Width!, value);}
}
// CFNumber representing a float value
public float? Slant {
get {return Adapter.GetSingleValue (Dictionary, CTFontTraitKey.Slant);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Slant, value);}
set {Adapter.SetValue (Dictionary, CTFontTraitKey.Slant!, value);}
}
internal const int ClassMaskShift = 28;

Просмотреть файл

@ -58,21 +58,21 @@ namespace CoreText {
#if !NET
public static class CTFrameAttributeKey {
public static readonly NSString Progression;
public static readonly NSString? Progression;
public static readonly NSString PathFillRule;
public static readonly NSString PathWidth;
public static readonly NSString ClippingPaths;
public static readonly NSString PathClippingPath;
public static readonly NSString? PathFillRule;
public static readonly NSString? PathWidth;
public static readonly NSString? ClippingPaths;
public static readonly NSString? PathClippingPath;
static CTFrameAttributeKey ()
{
var handle = Libraries.CoreText.Handle;
Progression = Dlfcn.GetStringConstant (handle, "kCTFrameProgressionAttributeName")!;
PathFillRule = Dlfcn.GetStringConstant (handle, "kCTFramePathFillRuleAttributeName")!;
PathWidth = Dlfcn.GetStringConstant (handle, "kCTFramePathWidthAttributeName")!;
ClippingPaths = Dlfcn.GetStringConstant (handle, "kCTFrameClippingPathsAttributeName")!;
PathClippingPath = Dlfcn.GetStringConstant (handle, "kCTFramePathClippingPathAttributeName")!;
Progression = Dlfcn.GetStringConstant (handle, "kCTFrameProgressionAttributeName");
PathFillRule = Dlfcn.GetStringConstant (handle, "kCTFramePathFillRuleAttributeName");
PathWidth = Dlfcn.GetStringConstant (handle, "kCTFramePathWidthAttributeName");
ClippingPaths = Dlfcn.GetStringConstant (handle, "kCTFrameClippingPathsAttributeName");
PathClippingPath = Dlfcn.GetStringConstant (handle, "kCTFramePathClippingPathAttributeName");
}
}
#endif
@ -93,7 +93,7 @@ namespace CoreText {
public CTFrameAttributes (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
@ -105,7 +105,7 @@ namespace CoreText {
return !value.HasValue ? null : (CTFrameProgression?) value.Value;
}
set {
Adapter.SetValue (Dictionary, CTFrameAttributeKey.Progression,
Adapter.SetValue (Dictionary, CTFrameAttributeKey.Progression!,
value.HasValue ? (uint?) value.Value : null);
}
}
@ -186,7 +186,7 @@ namespace CoreText {
public void GetLineOrigins (NSRange range, CGPoint[] origins)
{
if (origins is null)
throw new ArgumentNullException (nameof (origins));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (origins));
if (range.Length != 0 && origins.Length < range.Length)
throw new ArgumentException ("origins must contain at least range.Length elements.", nameof (origins));
else if (origins.Length < CFArray.GetCount (CTFrameGetLines (Handle)))
@ -200,7 +200,7 @@ namespace CoreText {
public void Draw (CGContext ctx)
{
if (ctx is null)
throw new ArgumentNullException (nameof (ctx));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (ctx));
CTFrameDraw (Handle, ctx.Handle);
}

Просмотреть файл

@ -69,7 +69,7 @@ namespace CoreText {
public CTFrame? GetFrame (NSRange stringRange, CGPath path, CTFrameAttributes? frameAttributes)
{
if (path is null)
throw new ArgumentNullException (nameof (path));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (path));
var frame = CTFramesetterCreateFrame (Handle, stringRange, path.Handle, frameAttributes.GetHandle ());
if (frame == IntPtr.Zero)
return null;
@ -128,7 +128,7 @@ namespace CoreText {
public static CTFramesetter? Create (CTTypesetter typesetter)
{
if (typesetter is null)
throw new ArgumentNullException (nameof (typesetter));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (typesetter));
var ret = CTFramesetterCreateWithTypesetter (typesetter.Handle);
if (ret == IntPtr.Zero)

Просмотреть файл

@ -74,11 +74,11 @@ namespace CoreText {
static IntPtr Create (string glyphName, CTFont font, string baseString)
{
if (glyphName is null)
throw new ArgumentNullException (nameof (glyphName));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (glyphName));
if (font is null)
throw new ArgumentNullException (nameof (font));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
if (baseString is null)
throw new ArgumentNullException (nameof (baseString));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (baseString));
var gnHandle = CFString.CreateNative (glyphName);
var bsHandle = CFString.CreateNative (baseString);
@ -101,9 +101,9 @@ namespace CoreText {
static IntPtr Create (CGGlyph glyph, CTFont font, string baseString)
{
if (font is null)
throw new ArgumentNullException (nameof (font));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (font));
if (baseString is null)
throw new ArgumentNullException (nameof (baseString));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (baseString));
var bsHandle = CFString.CreateNative (baseString);
try {
@ -124,7 +124,7 @@ namespace CoreText {
static IntPtr Create (CGFontIndex cid, CTCharacterCollection collection, string baseString)
{
if (baseString is null)
throw new ArgumentNullException (nameof (baseString));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (baseString));
var bsHandle = CFString.CreateNative (baseString);
try {

Просмотреть файл

@ -141,7 +141,7 @@ namespace CoreText {
public void Draw (CGContext context)
{
if (context is null)
throw new ArgumentNullException (nameof (context));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (context));
CTLineDraw (Handle, context.Handle);
}
#endregion
@ -245,7 +245,7 @@ namespace CoreText {
public void EnumerateCaretOffsets (CaretEdgeEnumerator enumerator)
{
if (enumerator is null)
throw new ArgumentNullException (nameof (enumerator));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (enumerator));
var block_handler = new BlockLiteral ();
block_handler.SetupBlockUnsafe (static_enumerate, enumerator);

Просмотреть файл

@ -24,6 +24,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
@ -140,7 +143,7 @@ namespace CoreText {
static void Deallocate (IntPtr refCon)
{
var self = GetOperations (refCon);
if (self == null)
if (self is null)
return;
self.Dispose ();
@ -150,7 +153,7 @@ namespace CoreText {
self.handle = new GCHandle ();
}
internal static CTRunDelegateOperations GetOperations (IntPtr refCon)
internal static CTRunDelegateOperations? GetOperations (IntPtr refCon)
{
GCHandle c = GCHandle.FromIntPtr (refCon);
@ -161,7 +164,7 @@ namespace CoreText {
static nfloat GetAscent (IntPtr refCon)
{
var self = GetOperations (refCon);
if (self == null)
if (self is null)
return 0;
return (nfloat) self.GetAscent ();
}
@ -170,7 +173,7 @@ namespace CoreText {
static nfloat GetDescent (IntPtr refCon)
{
var self = GetOperations (refCon);
if (self == null)
if (self is null)
return 0;
return (nfloat) self.GetDescent ();
}
@ -179,7 +182,7 @@ namespace CoreText {
static nfloat GetWidth (IntPtr refCon)
{
var self = GetOperations (refCon);
if (self == null)
if (self is null)
return 0;
return (nfloat) self.GetWidth ();
}
@ -204,8 +207,8 @@ namespace CoreText {
static IntPtr Create (CTRunDelegateOperations operations)
{
if (operations == null)
throw new ArgumentNullException (nameof (operations));
if (operations is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (operations));
CTRunDelegateCallbacks callbacks = operations.GetCallbacks ();
return CTRunDelegateCreate (ref callbacks, operations.Handle);
@ -221,7 +224,7 @@ namespace CoreText {
[DllImport (Constants.CoreTextLibrary)]
static extern IntPtr CTRunDelegateGetRefCon (IntPtr runDelegate);
public CTRunDelegateOperations Operations {
public CTRunDelegateOperations? Operations {
get {
return CTRunDelegateOperations.GetOperations (CTRunDelegateGetRefCon (Handle));
}

Просмотреть файл

@ -28,6 +28,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
@ -79,29 +81,29 @@ namespace CoreText {
#if !NET
public static partial class CTStringAttributeKey {
public static readonly NSString Font;
public static readonly NSString ForegroundColorFromContext;
public static readonly NSString KerningAdjustment;
public static readonly NSString LigatureFormation;
public static readonly NSString ForegroundColor;
public static readonly NSString BackgroundColor;
public static readonly NSString ParagraphStyle;
public static readonly NSString StrokeWidth;
public static readonly NSString StrokeColor;
public static readonly NSString UnderlineStyle;
public static readonly NSString Superscript;
public static readonly NSString UnderlineColor;
public static readonly NSString VerticalForms;
public static readonly NSString HorizontalInVerticalForms;
public static readonly NSString GlyphInfo;
public static readonly NSString CharacterShape;
public static readonly NSString RunDelegate;
public static readonly NSString? Font;
public static readonly NSString? ForegroundColorFromContext;
public static readonly NSString? KerningAdjustment;
public static readonly NSString? LigatureFormation;
public static readonly NSString? ForegroundColor;
public static readonly NSString? BackgroundColor;
public static readonly NSString? ParagraphStyle;
public static readonly NSString? StrokeWidth;
public static readonly NSString? StrokeColor;
public static readonly NSString? UnderlineStyle;
public static readonly NSString? Superscript;
public static readonly NSString? UnderlineColor;
public static readonly NSString? VerticalForms;
public static readonly NSString? HorizontalInVerticalForms;
public static readonly NSString? GlyphInfo;
public static readonly NSString? CharacterShape;
public static readonly NSString? RunDelegate;
// Since 6,0
internal static readonly NSString BaselineClass;
internal static readonly NSString BaselineInfo;
internal static readonly NSString BaselineReferenceInfo;
internal static readonly NSString BaselineOffset;
internal static readonly NSString WritingDirection;
internal static readonly NSString? BaselineClass;
internal static readonly NSString? BaselineInfo;
internal static readonly NSString? BaselineReferenceInfo;
internal static readonly NSString? BaselineOffset;
internal static readonly NSString? WritingDirection;
static CTStringAttributeKey ()
{
@ -148,37 +150,37 @@ namespace CoreText {
public CTStringAttributes (NSDictionary dictionary)
{
if (dictionary == null)
throw new ArgumentNullException ("dictionary");
if (dictionary is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}
public NSDictionary Dictionary {get; private set;}
public CTFont Font {
public CTFont? Font {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.Font.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.Font.GetHandle ());
return h == IntPtr.Zero ? null : new CTFont (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.Font, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.Font!, value);}
}
public bool ForegroundColorFromContext {
get {
return CFDictionary.GetBooleanValue (Dictionary.Handle,
CTStringAttributeKey.ForegroundColorFromContext.Handle);
CTStringAttributeKey.ForegroundColorFromContext.GetHandle ());
}
set {
Adapter.AssertWritable (Dictionary);
CFMutableDictionary.SetValue (Dictionary.Handle,
CTStringAttributeKey.ForegroundColorFromContext.Handle, value);
CTStringAttributeKey.ForegroundColorFromContext.GetHandle (), value);
}
}
// Header says 'Value must be a CFNumberRef float' - System/Library/Frameworks/CoreText.framework/Headers/CTStringAttributes.h
public float? KerningAdjustment {
get {return Adapter.GetSingleValue (Dictionary, CTStringAttributeKey.KerningAdjustment);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.KerningAdjustment, value);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.KerningAdjustment!, value);}
}
// Documentation says this must be 'CFNumber', doesn't specify exact type (but implies it's an integer value)
@ -188,17 +190,17 @@ namespace CoreText {
return !value.HasValue ? null : (CTLigatureFormation?) value.Value;
}
set {
Adapter.SetValue (Dictionary, CTStringAttributeKey.LigatureFormation,
Adapter.SetValue (Dictionary, CTStringAttributeKey.LigatureFormation!,
value.HasValue ? (int?) value.Value : null);
}
}
public CGColor ForegroundColor {
public CGColor? ForegroundColor {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.ForegroundColor.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.ForegroundColor.GetHandle ());
return h == IntPtr.Zero ? null : new CGColor (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.ForegroundColor, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.ForegroundColor!, value);}
}
#if NET
@ -210,41 +212,41 @@ namespace CoreText {
[iOS (10,0)]
[Mac (10,12)]
#endif
public CGColor BackgroundColor {
public CGColor? BackgroundColor {
get {
var h = IntPtr.Zero;
var x = CTStringAttributeKey.BackgroundColor;
if (x != null)
if (x is not null)
h = CFDictionary.GetValue (Dictionary.Handle, x.Handle);
return h == IntPtr.Zero ? null : new CGColor (h, false);
}
set {
var x = CTStringAttributeKey.BackgroundColor;
if (x != null)
if (x is not null)
Adapter.SetNativeValue (Dictionary, x, value);
}
}
public CTParagraphStyle ParagraphStyle {
public CTParagraphStyle? ParagraphStyle {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.ParagraphStyle.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.ParagraphStyle.GetHandle ());
return h == IntPtr.Zero ? null : new CTParagraphStyle (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.ParagraphStyle, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.ParagraphStyle!, value);}
}
// Documentation says this must be 'CFNumber', doesn't specify exact type (but implies it's a floating point value)
public float? StrokeWidth {
get {return Adapter.GetSingleValue (Dictionary, CTStringAttributeKey.StrokeWidth);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.StrokeWidth, value);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.StrokeWidth!, value);}
}
public CGColor StrokeColor {
public CGColor? StrokeColor {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.StrokeColor.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.StrokeColor.GetHandle ());
return h == IntPtr.Zero ? null : new CGColor (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.StrokeColor, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.StrokeColor!, value);}
}
#if NET
@ -266,7 +268,7 @@ namespace CoreText {
// Documentation says this must be 'CFNumber', doesn't specify exact type
public int? UnderlineStyleValue {
get {return Adapter.GetInt32Value (Dictionary, CTStringAttributeKey.UnderlineStyle);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.UnderlineStyle, value);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.UnderlineStyle!, value);}
}
const int UnderlineStyleMask = 0x000F;
@ -304,28 +306,28 @@ namespace CoreText {
return !value.HasValue ? null : (CTSuperscriptStyle?) value.Value;
}
set {
Adapter.SetValue (Dictionary, CTStringAttributeKey.Superscript,
Adapter.SetValue (Dictionary, CTStringAttributeKey.Superscript!,
value.HasValue ? (int?) value.Value : null);
}
}
public CGColor UnderlineColor {
public CGColor? UnderlineColor {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.UnderlineColor.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.UnderlineColor.GetHandle ());
return h == IntPtr.Zero ? null : new CGColor (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.UnderlineColor, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.UnderlineColor!, value);}
}
public bool VerticalForms {
get {
return CFDictionary.GetBooleanValue (Dictionary.Handle,
CTStringAttributeKey.VerticalForms.Handle);
CTStringAttributeKey.VerticalForms.GetHandle ());
}
set {
Adapter.AssertWritable (Dictionary);
CFMutableDictionary.SetValue (Dictionary.Handle,
CTStringAttributeKey.VerticalForms.Handle, value);
CTStringAttributeKey.VerticalForms.GetHandle (), value);
}
}
@ -343,11 +345,11 @@ namespace CoreText {
public int? HorizontalInVerticalForms {
get {
var x = CTStringAttributeKey.HorizontalInVerticalForms;
return x != null ? Adapter.GetInt32Value (Dictionary, x) : null;
return x is not null ? Adapter.GetInt32Value (Dictionary, x) : null;
}
set {
var x = CTStringAttributeKey.HorizontalInVerticalForms;
if (x != null)
if (x is not null)
Adapter.SetValue (Dictionary, x, value);
}
}
@ -365,38 +367,38 @@ namespace CoreText {
#endif
public float? BaselineOffset {
get { return Adapter.GetSingleValue (Dictionary, CTStringAttributeKey.BaselineOffset); }
set { Adapter.SetValue (Dictionary, CTStringAttributeKey.BaselineOffset, value); }
set { Adapter.SetValue (Dictionary, CTStringAttributeKey.BaselineOffset!, value); }
}
public CTGlyphInfo GlyphInfo {
public CTGlyphInfo? GlyphInfo {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.GlyphInfo.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.GlyphInfo.GetHandle ());
return h == IntPtr.Zero ? null : new CTGlyphInfo (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.GlyphInfo, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.GlyphInfo!, value);}
}
public int? CharacterShape {
get {return Adapter.GetInt32Value (Dictionary, CTStringAttributeKey.CharacterShape);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.CharacterShape, value);}
set {Adapter.SetValue (Dictionary, CTStringAttributeKey.CharacterShape!, value);}
}
public CTRunDelegate RunDelegate {
public CTRunDelegate? RunDelegate {
get {
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.RunDelegate.Handle);
var h = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.RunDelegate.GetHandle ());
return h == IntPtr.Zero ? null : new CTRunDelegate (h, false);
}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.RunDelegate, value);}
set {Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.RunDelegate!, value);}
}
public CTBaselineClass? BaselineClass {
get {
var value = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.BaselineClass.Handle);
var value = CFDictionary.GetValue (Dictionary.Handle, CTStringAttributeKey.BaselineClass.GetHandle ());
return value == IntPtr.Zero ? (CTBaselineClass?) null : CTBaselineClassID.FromHandle (value);
}
set {
var ns_value = value == null ? null : CTBaselineClassID.ToNSString (value.Value);
Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.BaselineClass, ns_value);
var ns_value = value is null ? null : CTBaselineClassID.ToNSString (value.Value);
Adapter.SetNativeValue (Dictionary, CTStringAttributeKey.BaselineClass!, ns_value);
}
}
@ -410,16 +412,16 @@ namespace CoreText {
SetBaseline (baselineClass, offset, CTStringAttributeKey.BaselineReferenceInfo);
}
void SetBaseline (CTBaselineClass baselineClass, double offset, NSString infoKey)
void SetBaseline (CTBaselineClass baselineClass, double offset, NSString? infoKey)
{
var ptr = CFDictionary.GetValue (Dictionary.Handle, infoKey.Handle);
var ptr = CFDictionary.GetValue (Dictionary.Handle, infoKey.GetHandle ());
var dict = ptr == IntPtr.Zero ? new NSMutableDictionary () : new NSMutableDictionary (ptr);
var key = CTBaselineClassID.ToNSString (baselineClass);
Adapter.SetValue (dict, key, new NSNumber (offset));
Adapter.SetValue (dict, key!, new NSNumber (offset));
if (ptr == IntPtr.Zero)
Adapter.SetNativeValue (Dictionary, infoKey, (INativeObject)dict);
Adapter.SetNativeValue (Dictionary, infoKey!, (INativeObject)dict);
}
// 'Value must be a CFArray of CFNumberRefs' - System/Library/Frameworks/CoreText.framework/Headers/CTStringAttributes.h
@ -433,7 +435,7 @@ namespace CoreText {
}
var array = CFArray.Create (ptrs);
CFMutableDictionary.SetValue (Dictionary.Handle, CTStringAttributeKey.WritingDirection.Handle, array);
CFMutableDictionary.SetValue (Dictionary.Handle, CTStringAttributeKey.WritingDirection.GetHandle (), array);
GC.KeepAlive (numbers); // make sure the numbers aren't freed until we're done with them
}
}

Просмотреть файл

@ -70,7 +70,7 @@ namespace CoreText {
public CTTextTabOptions (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}

Просмотреть файл

@ -61,7 +61,7 @@ namespace CoreText {
public CTTypesetterOptions (NSDictionary dictionary)
{
if (dictionary is null)
throw new ArgumentNullException (nameof (dictionary));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dictionary));
Dictionary = dictionary;
}

Просмотреть файл

@ -7,6 +7,8 @@
// Copyright 2018 Microsoft Corporation.
//
#nullable enable
#if !NET
using System;
using ObjCRuntime;

Просмотреть файл

@ -24,6 +24,8 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Runtime.InteropServices;
@ -36,12 +38,6 @@ namespace CoreText {
static class ConstructorError {
public static Exception ArgumentNull (object self, string argument)
{
GC.SuppressFinalize (self);
return new ArgumentNullException (argument);
}
public static Exception Unknown (object self)
{
GC.SuppressFinalize (self);

Просмотреть файл

@ -20,6 +20,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using ObjCRuntime;

Просмотреть файл

@ -89,7 +89,7 @@ namespace OpenGL {
static IntPtr Create (CGLPixelFormatAttribute[] attributes, out int npix)
{
if (attributes is null)
throw new ArgumentNullException (nameof (attributes));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (attributes));
IntPtr pixelFormatOut;
var marshalAttribs = new CGLPixelFormatAttribute [attributes.Length + 1];

Просмотреть файл

@ -25,6 +25,8 @@
//
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -25,6 +25,9 @@
//
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
#if OPENTK_DLL
using System;

Просмотреть файл

@ -25,6 +25,8 @@
//
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -22,7 +22,9 @@
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
#nullable enable
#if OPENTK_DLL
@ -41,11 +43,11 @@ namespace OpenTK.Platform.MacOS
public class MonoMacGameView : AppKit.NSView, IGameWindow
{
bool disposed;
NSOpenGLContext openGLContext;
NSOpenGLPixelFormat pixelFormat;
CVDisplayLink displayLink;
NSObject notificationProxy;
NSTimer animationTimer;
NSOpenGLContext? openGLContext;
NSOpenGLPixelFormat? pixelFormat;
CVDisplayLink? displayLink;
NSObject? notificationProxy;
NSTimer? animationTimer;
bool animating;
bool displayLinkSupported = false;
WindowState windowState = WindowState.Normal;
@ -64,7 +66,7 @@ namespace OpenTK.Platform.MacOS
{
}
public MonoMacGameView (CGRect frame, NSOpenGLContext context) : base(frame)
public MonoMacGameView (CGRect frame, NSOpenGLContext? context) : base(frame)
{
var attribs = new object [] {
NSOpenGLPixelFormatAttribute.NoRecovery,
@ -85,11 +87,11 @@ namespace OpenTK.Platform.MacOS
pixelFormat = new NSOpenGLPixelFormat (attribs);
}
if (pixelFormat == null)
if (pixelFormat is null)
Console.WriteLine ("No OpenGL pixel format");
// NSOpenGLView does not handle context sharing, so we draw to a custom NSView instead
openGLContext = new NSOpenGLContext (pixelFormat, context);
openGLContext = new NSOpenGLContext (ActualPixelFormat, context);
openGLContext.MakeCurrentContext ();
@ -108,7 +110,7 @@ namespace OpenTK.Platform.MacOS
if (animating) {
if (displayLinkSupported) {
// Render Scene only if the display link is running
if (displayLink.IsRunning)
if (displayLink?.IsRunning == true)
RenderScene ();
} else {
RenderScene ();
@ -120,24 +122,40 @@ namespace OpenTK.Platform.MacOS
public override void LockFocus ()
{
base.LockFocus ();
if (openGLContext.View != this)
openGLContext.View = this;
if (ActualOpenGLContext.View != this)
ActualOpenGLContext.View = this;
}
public NSOpenGLContext OpenGLContext {
get { return openGLContext; }
public NSOpenGLContext? OpenGLContext {
get => openGLContext;
}
public NSOpenGLPixelFormat PixelFormat {
get { return pixelFormat; }
NSOpenGLContext ActualOpenGLContext {
get {
if (openGLContext is null)
throw new InvalidOperationException ("Operation requires an OpenGLContext, which hasn't been created yet.");
return openGLContext;
}
}
NSViewController GetViewController ()
public NSOpenGLPixelFormat? PixelFormat {
get => pixelFormat;
}
NSOpenGLPixelFormat ActualPixelFormat {
get {
if (pixelFormat is null)
throw new InvalidOperationException ("Operation requires a PixelFormat that cannot be null.");
return pixelFormat;
}
}
NSViewController? GetViewController ()
{
NSResponder r = this;
while (r != null) {
NSResponder? r = this;
while (r is not null) {
var c = r as NSViewController;
if (c != null)
if (c is not null)
return c;
r = r.NextResponder;
}
@ -158,7 +176,7 @@ namespace OpenTK.Platform.MacOS
{
if (!animating) {
if (displayLinkSupported) {
if (displayLink != null && !displayLink.IsRunning)
if (displayLink is not null && !displayLink.IsRunning)
displayLink.Start ();
} else {
// Can't use TimeSpan.FromSeconds() as that only has 1ms
@ -191,10 +209,10 @@ namespace OpenTK.Platform.MacOS
{
if (animating) {
if (displayLinkSupported) {
if (displayLink != null && displayLink.IsRunning)
if (displayLink is not null && displayLink.IsRunning)
displayLink.Stop ();
} else {
} else if (animationTimer is not null) {
animationTimer.Invalidate ();
animationTimer = null;
}
@ -207,7 +225,8 @@ namespace OpenTK.Platform.MacOS
{
Stop ();
displayLink = null;
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationProxy);
if (notificationProxy is not null)
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationProxy);
}
void AssertValid ()
@ -216,23 +235,17 @@ namespace OpenTK.Platform.MacOS
throw new ObjectDisposedException ("");
}
void AssertContext ()
{
if (OpenGLContext == null)
throw new InvalidOperationException ("Operation requires an OpenGLContext, which hasn't been created yet.");
}
public virtual string Title {
get {
AssertValid ();
if (Window != null)
if (Window is not null)
return Window.Title;
else
throw new NotSupportedException();
}
set {
AssertValid ();
if (Window != null)
if (Window is not null)
Window.Title = value;
else
throw new NotSupportedException();
@ -242,7 +255,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnTitleChanged (EventArgs e)
{
var h = TitleChanged;
if (h != null)
if (h is not null)
h (this, EventArgs.Empty);
}
@ -267,7 +280,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnVisibleChanged (EventArgs e)
{
var h = VisibleChanged;
if (h != null)
if (h is not null)
h (this, EventArgs.Empty);
}
@ -292,7 +305,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnWindowStateChanged (EventArgs e)
{
var h = WindowStateChanged;
if (h != null)
if (h is not null)
h (this, EventArgs.Empty);
}
@ -327,13 +340,13 @@ namespace OpenTK.Platform.MacOS
size = value;
// This method will be called on the main thread when resizing, but we may be drawing on a secondary thread through the display link
// Add a mutex around to avoid the threads accessing the context simultaneously
openGLContext.CGLContext.Lock ();
ActualOpenGLContext.CGLContext.Lock ();
// Delegate to the scene object to update for a change in the view size
OnResize (EventArgs.Empty);
openGLContext.Update ();
ActualOpenGLContext.Update ();
openGLContext.CGLContext.Unlock ();
ActualOpenGLContext.CGLContext.Unlock ();
}
}
}
@ -341,7 +354,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnResize (EventArgs e)
{
var h = Resize;
if (h != null)
if (h is not null)
h (this, e);
}
@ -384,7 +397,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnClosed (EventArgs e)
{
var h = Closed;
if (h != null)
if (h is not null)
h (this, e);
}
@ -405,7 +418,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnDisposed (EventArgs e)
{
var h = Disposed;
if (h != null)
if (h is not null)
h (this, e);
}
@ -427,16 +440,14 @@ namespace OpenTK.Platform.MacOS
public virtual void MakeCurrent ()
{
AssertValid ();
AssertContext ();
OpenGLContext.MakeCurrentContext ();
ActualOpenGLContext.MakeCurrentContext ();
}
public virtual void SwapBuffers ()
{
AssertValid ();
AssertContext ();
// basically SwapBuffers is the same as FlushBuffer on OSX
OpenGLContext.FlushBuffer ();
ActualOpenGLContext.FlushBuffer ();
}
private bool SwapInterval { get; set; }
@ -454,7 +465,7 @@ namespace OpenTK.Platform.MacOS
OnLoad (EventArgs.Empty);
// Synchronize buffer swaps with vertical refresh rate
openGLContext.SwapInterval = SwapInterval;
ActualOpenGLContext.SwapInterval = SwapInterval;
if (displayLinkSupported)
SetupDisplayLink ();
@ -478,7 +489,7 @@ namespace OpenTK.Platform.MacOS
DisplaylinkSupported = false;
// Synchronize buffer swaps with vertical refresh rate
openGLContext.SwapInterval = SwapInterval;
ActualOpenGLContext.SwapInterval = SwapInterval;
if (displayLinkSupported)
SetupDisplayLink ();
@ -492,10 +503,10 @@ namespace OpenTK.Platform.MacOS
// This method will be called on both the main thread (through DrawRect:) and a secondary thread (through the display link rendering loop)
// Also, when resizing the view, Reshape is called on the main thread, but we may be drawing on a secondary thread
// Add a mutex around to avoid the threads accessing the context simultaneously
openGLContext.CGLContext.Lock ();
ActualOpenGLContext.CGLContext.Lock ();
// Make sure we draw to the right context
openGLContext.MakeCurrentContext ();
ActualOpenGLContext.MakeCurrentContext ();
var curUpdateTime = DateTime.Now;
if (prevUpdateTime.Ticks == 0) {
@ -523,14 +534,14 @@ namespace OpenTK.Platform.MacOS
OnRenderFrame (renderEventArgs);
prevRenderTime = curRenderTime;
openGLContext.FlushBuffer ();
ActualOpenGLContext.FlushBuffer ();
openGLContext.CGLContext.Unlock ();
ActualOpenGLContext.CGLContext.Unlock ();
}
private void SetupDisplayLink ()
{
if (displayLink != null)
if (displayLink is not null)
return;
// Create a display link capable of being used with all active displays
@ -540,8 +551,8 @@ namespace OpenTK.Platform.MacOS
displayLink.SetOutputCallback (MyDisplayLinkOutputCallback);
// Set the display link for the current renderer
CGLContext cglContext = openGLContext.CGLContext;
CGLPixelFormat cglPixelFormat = PixelFormat.CGLPixelFormat;
CGLContext cglContext = ActualOpenGLContext.CGLContext;
CGLPixelFormat cglPixelFormat = ActualPixelFormat.CGLPixelFormat;
displayLink.SetCurrentDisplay (cglContext, cglPixelFormat);
}
@ -566,7 +577,7 @@ namespace OpenTK.Platform.MacOS
protected virtual void OnLoad (EventArgs e)
{
var h = Load;
if (h != null)
if (h is not null)
h (this, e);
}
@ -574,21 +585,21 @@ namespace OpenTK.Platform.MacOS
{
var h = Unload;
Stop ();
if (h != null)
if (h is not null)
h (this, e);
}
protected virtual void OnUpdateFrame (FrameEventArgs e)
{
var h = UpdateFrame;
if (h != null)
if (h is not null)
h (this, e);
}
protected virtual void OnRenderFrame (FrameEventArgs e)
{
var h = RenderFrame;
if (h != null)
if (h is not null)
h (this, e);
}
@ -597,17 +608,17 @@ namespace OpenTK.Platform.MacOS
remove { throw new NotSupportedException ();}
}
public event EventHandler<EventArgs> Resize;
public event EventHandler<EventArgs>? Resize;
event EventHandler<CancelEventArgs> INativeWindow.Closing {
add { throw new NotSupportedException ();}
remove { throw new NotSupportedException ();}
}
public event EventHandler<EventArgs> Closed;
public event EventHandler<EventArgs> Disposed;
public event EventHandler<EventArgs> TitleChanged;
public event EventHandler<EventArgs> VisibleChanged;
public event EventHandler<EventArgs>? Closed;
public event EventHandler<EventArgs>? Disposed;
public event EventHandler<EventArgs>? TitleChanged;
public event EventHandler<EventArgs>? VisibleChanged;
event EventHandler<EventArgs> INativeWindow.FocusedChanged {
add { throw new NotSupportedException ();}
@ -619,7 +630,7 @@ namespace OpenTK.Platform.MacOS
remove { throw new NotSupportedException ();}
}
public event EventHandler<EventArgs> WindowStateChanged;
public event EventHandler<EventArgs>? WindowStateChanged;
// event EventHandler<KeyPressEventArgs> INativeWindow.KeyPress {
// add { throw new NotSupportedException ();}
@ -630,10 +641,10 @@ namespace OpenTK.Platform.MacOS
remove { throw new NotSupportedException ();}
}
public event EventHandler<EventArgs> Load;
public event EventHandler<EventArgs> Unload;
public event EventHandler<FrameEventArgs> UpdateFrame;
public event EventHandler<FrameEventArgs> RenderFrame;
public event EventHandler<EventArgs>? Load;
public event EventHandler<EventArgs>? Unload;
public event EventHandler<FrameEventArgs>? UpdateFrame;
public event EventHandler<FrameEventArgs>? RenderFrame;
}
}

Просмотреть файл

@ -25,6 +25,8 @@
//
#endregion
#nullable enable
#if OPENTK_DLL
using System;
@ -140,8 +142,8 @@ namespace OpenTK.Audio
StructLayoutAttribute[] attr = (StructLayoutAttribute[])
type.GetCustomAttributes(typeof(StructLayoutAttribute), true);
if ((attr == null) ||
(attr != null && attr.Length > 0 && attr[0].Value != LayoutKind.Explicit && attr[0].Pack != 1))
if ((attr is null) ||
(attr is not null && attr.Length > 0 && attr[0].Value != LayoutKind.Explicit && attr[0].Pack != 1))
return false;
return true;

Просмотреть файл

@ -6,6 +6,8 @@
*/
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -7,6 +7,9 @@
* http://www.OpenTK.net */
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
#if OPENTK_DLL
using System;
@ -499,7 +502,8 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public static void DeleteSources(uint[] sources)
{
if (sources == null) throw new ArgumentNullException();
if (sources is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (sources));
if (sources.Length == 0) throw new ArgumentOutOfRangeException();
DeleteBuffers(sources.Length, ref sources[0]);
}
@ -508,7 +512,8 @@ namespace OpenTK.Audio.OpenAL
/// <param name="sources">An array of source names identifying the sources to be deleted.</param>
public static void DeleteSources(int[] sources)
{
if (sources == null) throw new ArgumentNullException();
if (sources is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (sources));
if (sources.Length == 0) throw new ArgumentOutOfRangeException();
DeleteBuffers(sources.Length, ref sources[0]);
}
@ -1389,7 +1394,8 @@ namespace OpenTK.Audio.OpenAL
[CLSCompliant(false)]
public static void DeleteBuffers(uint[] buffers)
{
if (buffers == null) throw new ArgumentNullException();
if (buffers is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffers));
if (buffers.Length == 0) throw new ArgumentOutOfRangeException();
DeleteBuffers(buffers.Length, ref buffers[0]);
}
@ -1398,7 +1404,8 @@ namespace OpenTK.Audio.OpenAL
/// <param name="buffers">Pointer to an array of buffer names identifying the buffers to be deleted.</param>
public static void DeleteBuffers(int[] buffers)
{
if (buffers == null) throw new ArgumentNullException();
if (buffers is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (buffers));
if (buffers.Length == 0) throw new ArgumentOutOfRangeException();
DeleteBuffers(buffers.Length, ref buffers[0]);
}

Просмотреть файл

@ -7,6 +7,8 @@
* http://www.OpenTK.net */
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -7,6 +7,8 @@
* http://www.OpenTK.net */
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -7,6 +7,8 @@
* http://www.OpenTK.net */
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -25,6 +25,8 @@
//
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -23,6 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
#if OPENTK_DLL
namespace OpenTK.Graphics.OpenGL

Просмотреть файл

@ -23,6 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
#if OPENTK_DLL
namespace OpenTK.Graphics.OpenGL

Просмотреть файл

@ -23,6 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -25,6 +25,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
#if OPENTK_DLL
#region --- Using Directives ---

Просмотреть файл

@ -56,6 +56,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion --- License ---
#nullable enable
using System;
using System.IO;
using System.Runtime.InteropServices;

Просмотреть файл

@ -8,6 +8,8 @@
*/
#endregion
#nullable enable
using System;
using System.Collections.Generic;
using System.Text;

Просмотреть файл

@ -23,6 +23,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
@ -203,7 +206,8 @@ namespace OpenTK
/// <param name="floatArray">The array of floats for the components of the matrix.</param>
public Matrix2(float[] floatArray)
{
if (floatArray == null || floatArray.GetLength(0) < 9) throw new MissingFieldException();
if (floatArray is null || floatArray.GetLength (0) < 9)
throw new MissingFieldException ();
this.R0C0 = floatArray[0];
this.R0C1 = floatArray[1];

Просмотреть файл

@ -22,6 +22,8 @@ SOFTWARE.
*/
#endregion
#nullable enable
using System;
using System.Runtime.InteropServices;
@ -274,7 +276,8 @@ namespace OpenTK
/// <param name="floatArray">The array of floats for the components of the matrix.</param>
public Matrix3(float[] floatArray)
{
if (floatArray == null || floatArray.GetLength(0) < 9) throw new MissingFieldException();
if (floatArray is null || floatArray.GetLength (0) < 9)
throw new MissingFieldException ();
this.R0C0 = floatArray[0];
this.R0C1 = floatArray[1];

Просмотреть файл

@ -22,6 +22,8 @@ SOFTWARE.
*/
#endregion
#nullable enable
using System;
using System.Runtime.InteropServices;
@ -275,7 +277,8 @@ namespace OpenTK
/// <param name="doubleArray">The array of doubles for the components of the matrix.</param>
public Matrix3d(double[] doubleArray)
{
if (doubleArray == null || doubleArray.GetLength(0) < 9) throw new MissingFieldException();
if (doubleArray is null || doubleArray.GetLength (0) < 9)
throw new MissingFieldException ();
this.R0C0 = doubleArray[0];
this.R0C1 = doubleArray[1];

Просмотреть файл

@ -22,6 +22,8 @@ SOFTWARE.
*/
#endregion
#nullable enable
using System;
using System.Runtime.InteropServices;

Просмотреть файл

@ -22,6 +22,8 @@ SOFTWARE.
*/
#endregion
#nullable enable
using System;
using System.Runtime.InteropServices;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
@ -746,7 +749,8 @@ namespace OpenTK
/// <param name="doubleArray">The array of doubles for the components of the Quaterniond.</param>
public Quaterniond(double[] doubleArray)
{
if (doubleArray == null || doubleArray.GetLength(0) < 4) throw new MissingFieldException();
if (doubleArray is null || doubleArray.GetLength (0) < 4)
throw new MissingFieldException ();
this.W = doubleArray[0];
this.X = doubleArray[1];

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
#if !NET

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;

Просмотреть файл

@ -27,6 +27,9 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
#if !NET
namespace OpenTK
{

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.IO;
using System.Runtime.InteropServices;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

Просмотреть файл

@ -22,6 +22,9 @@ SOFTWARE.
*/
#endregion
#nullable enable
#pragma warning disable CS3021 // Type or member does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute
using System;
using System.IO;
using System.Runtime.InteropServices;

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -6,6 +6,8 @@
*/
#endregion
#nullable enable
#if OPENTK_DLL
using System;

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
using System;
using Foundation;
using ObjCRuntime;
@ -9,13 +11,13 @@ namespace PassKit {
static public PKContactFields GetValue (NSSet set)
{
var fields = PKContactFields.None;
if (set == null)
if (set is null)
return fields;
foreach (PKContactFields value in Enum.GetValues (typeof (PKContactFields))) {
var constant = value.GetConstant ();
// None does not have an associated native value and Contains would throw an ANE
if ((constant != null) && set.Contains (constant))
if ((constant is not null) && set.Contains (constant))
fields |= value;
}
return fields;
@ -31,7 +33,7 @@ namespace PassKit {
if (values.HasFlag (value)) {
var constant = value.GetConstant ();
// None does not have an associated native value and Contains would throw an ANE
if (constant != null)
if (constant is not null)
set.Add (constant);
}
}

Просмотреть файл

@ -1,7 +1,4 @@
/*
* This keeps the code of OpenTK's Matrix4 almost intact, except we replace the
* Vector4 with a SCNVector4
Copyright (c) 2006 - 2008 The Open Toolkit library.
Copyright (c) 2014 Xamarin Inc. All rights reserved
@ -52,28 +49,55 @@ using pfloat = System.Runtime.InteropServices.NFloat;
namespace SceneKit {
/// <summary>
/// Represents a 4x4 Matrix
/// Represents a 4x4 matrix using a column-major memory layout.
/// </summary>
[Serializable]
public struct SCNMatrix4 : IEquatable<SCNMatrix4> {
#region Fields
/*
* SCNMatrix4 is defined like this for iOS, tvOS and watchOS:
*
* typedef struct SCNMatrix4 {
* float m11, m12, m13, m14;
* float m21, m22, m23, m24;
* float m31, m32, m33, m34;
* float m41, m42, m43, m44;
* } SCNMatrix4;
*
* and like this for macOS:
*
* struct CATransform3D
* {
* CGFloat m11, m12, m13, m14;
* CGFloat m21, m22, m23, m24;
* CGFloat m31, m32, m33, m34;
* CGFloat m41, m42, m43, m44;
* };
* typedef CATransform3D SCNMatrix4;
*
* It's not obvious from this definitions whether the matrix is row-major or column-major, and neither the documentation
* nor the headers are particularly helpful, but it's possible to do some math to figure it out. See this for more info:
* https://github.com/xamarin/xamarin-macios/issues/15094#issuecomment-1139699662 (result: SCNMatrix4 is using a column-major layout)
*
**/
/// <summary>
/// Left-most column of the matrix
/// </summary>
public SCNVector4 Column0;
public SCNVector4 Column0; // m11, m12, m13, m14
/// <summary>
/// 2nd column of the matrix
/// </summary>
public SCNVector4 Column1;
public SCNVector4 Column1; // m21, m22, m23, m24
/// <summary>
/// 3rd column of the matrix
/// </summary>
public SCNVector4 Column2;
public SCNVector4 Column2; // m31, m32, m33, m34
/// <summary>
/// Right-most column of the matrix
/// </summary>
public SCNVector4 Column3;
public SCNVector4 Column3; // m41, m42, m43, m44
/// <summary>
/// The identity matrix
@ -133,10 +157,10 @@ namespace SceneKit {
#if !WATCH
public SCNMatrix4 (CoreAnimation.CATransform3D transform)
{
Column0 = new SCNVector4 ((pfloat) transform.M11, (pfloat) transform.M21, (pfloat) transform.M31, (pfloat) transform.M41);
Column1 = new SCNVector4 ((pfloat) transform.M12, (pfloat) transform.M22, (pfloat) transform.M32, (pfloat) transform.M42);
Column2 = new SCNVector4 ((pfloat) transform.M13, (pfloat) transform.M23, (pfloat) transform.M33, (pfloat) transform.M43);
Column3 = new SCNVector4 ((pfloat) transform.M14, (pfloat) transform.M24, (pfloat) transform.M34, (pfloat) transform.M44);
Column0 = new SCNVector4 ((pfloat) transform.M11, (pfloat) transform.M12, (pfloat) transform.M13, (pfloat) transform.M14);
Column1 = new SCNVector4 ((pfloat) transform.M21, (pfloat) transform.M22, (pfloat) transform.M23, (pfloat) transform.M24);
Column2 = new SCNVector4 ((pfloat) transform.M31, (pfloat) transform.M32, (pfloat) transform.M33, (pfloat) transform.M34);
Column3 = new SCNVector4 ((pfloat) transform.M41, (pfloat) transform.M42, (pfloat) transform.M43, (pfloat) transform.M44);
}
#endif
@ -167,10 +191,10 @@ namespace SceneKit {
public SCNVector4 Row0 {
get { return new SCNVector4 (Column0.X, Column1.X, Column2.X, Column3.X); }
set {
M11 = value.X;
M12 = value.Y;
M13 = value.Z;
M14 = value.W;
Column0.X = value.X;
Column1.X = value.Y;
Column2.X = value.Z;
Column3.X = value.W;
}
}
@ -180,10 +204,10 @@ namespace SceneKit {
public SCNVector4 Row1 {
get { return new SCNVector4 (Column0.Y, Column1.Y, Column2.Y, Column3.Y); }
set {
M21 = value.X;
M22 = value.Y;
M23 = value.Z;
M24 = value.W;
Column0.Y = value.X;
Column1.Y = value.Y;
Column2.Y = value.Z;
Column3.Y = value.W;
}
}
@ -193,10 +217,10 @@ namespace SceneKit {
public SCNVector4 Row2 {
get { return new SCNVector4 (Column0.Z, Column1.Z, Column2.Z, Column3.Z); }
set {
M31 = value.X;
M32 = value.Y;
M33 = value.Z;
M34 = value.W;
Column0.Z = value.X;
Column1.Z = value.Y;
Column2.Z = value.Z;
Column3.Z = value.W;
}
}
@ -206,90 +230,90 @@ namespace SceneKit {
public SCNVector4 Row3 {
get { return new SCNVector4 (Column0.W, Column1.W, Column2.W, Column3.W); }
set {
M41 = value.X;
M42 = value.Y;
M43 = value.Z;
M44 = value.W;
Column0.W = value.X;
Column1.W = value.Y;
Column2.W = value.Z;
Column3.W = value.W;
}
}
/// <summary>
/// Gets or sets the value at row 1, column 1 of this instance.
/// Gets or sets the value at column 1, row 1 of this instance.
/// </summary>
public pfloat M11 { get { return Column0.X; } set { Column0.X = value; } }
/// <summary>
/// Gets or sets the value at row 1, column 2 of this instance.
/// Gets or sets the value at column 1, row 2 of this instance.
/// </summary>
public pfloat M12 { get { return Column1.X; } set { Column1.X = value; } }
public pfloat M12 { get { return Column0.Y; } set { Column0.Y = value; } }
/// <summary>
/// Gets or sets the value at row 1, column 3 of this instance.
/// Gets or sets the value at column 1, row 3 of this instance.
/// </summary>
public pfloat M13 { get { return Column2.X; } set { Column2.X = value; } }
public pfloat M13 { get { return Column0.Z; } set { Column0.Z = value; } }
/// <summary>
/// Gets or sets the value at row 1, column 4 of this instance.
/// Gets or sets the value at column 1, row 4 of this instance.
/// </summary>
public pfloat M14 { get { return Column3.X; } set { Column3.X = value; } }
public pfloat M14 { get { return Column0.W; } set { Column0.W = value; } }
/// <summary>
/// Gets or sets the value at row 2, column 1 of this instance.
/// Gets or sets the value at column 2, row 1 of this instance.
/// </summary>
public pfloat M21 { get { return Column0.Y; } set { Column0.Y = value; } }
public pfloat M21 { get { return Column1.X; } set { Column1.X = value; } }
/// <summary>
/// Gets or sets the value at row 2, column 2 of this instance.
/// Gets or sets the value at column 2, row 2 of this instance.
/// </summary>
public pfloat M22 { get { return Column1.Y; } set { Column1.Y = value; } }
/// <summary>
/// Gets or sets the value at row 2, column 3 of this instance.
/// Gets or sets the value at column 2, row 3 of this instance.
/// </summary>
public pfloat M23 { get { return Column2.Y; } set { Column2.Y = value; } }
public pfloat M23 { get { return Column1.Z; } set { Column1.Z = value; } }
/// <summary>
/// Gets or sets the value at row 2, column 4 of this instance.
/// Gets or sets the value at column 2, row 4 of this instance.
/// </summary>
public pfloat M24 { get { return Column3.Y; } set { Column3.Y = value; } }
public pfloat M24 { get { return Column1.W; } set { Column1.W = value; } }
/// <summary>
/// Gets or sets the value at row 3, column 1 of this instance.
/// Gets or sets the value at column 3, row 1 of this instance.
/// </summary>
public pfloat M31 { get { return Column0.Z; } set { Column0.Z = value; } }
public pfloat M31 { get { return Column2.X; } set { Column2.X = value; } }
/// <summary>
/// Gets or sets the value at row 3, column 2 of this instance.
/// Gets or sets the value at column 3, row 2 of this instance.
/// </summary>
public pfloat M32 { get { return Column1.Z; } set { Column1.Z = value; } }
public pfloat M32 { get { return Column2.Y; } set { Column2.Y = value; } }
/// <summary>
/// Gets or sets the value at row 3, column 3 of this instance.
/// Gets or sets the value at column 3, row 3 of this instance.
/// </summary>
public pfloat M33 { get { return Column2.Z; } set { Column2.Z = value; } }
/// <summary>
/// Gets or sets the value at row 3, column 4 of this instance.
/// Gets or sets the value at column 3, row 4 of this instance.
/// </summary>
public pfloat M34 { get { return Column3.Z; } set { Column3.Z = value; } }
public pfloat M34 { get { return Column2.W; } set { Column2.W = value; } }
/// <summary>
/// Gets or sets the value at row 4, column 1 of this instance.
/// Gets or sets the value at column 4, row 1 of this instance.
/// </summary>
public pfloat M41 { get { return Column0.W; } set { Column0.W = value; } }
public pfloat M41 { get { return Column3.X; } set { Column3.X = value; } }
/// <summary>
/// Gets or sets the value at row 4, column 2 of this instance.
/// Gets or sets the value at column 4, row 2 of this instance.
/// </summary>
public pfloat M42 { get { return Column1.W; } set { Column1.W = value; } }
public pfloat M42 { get { return Column3.Y; } set { Column3.Y = value; } }
/// <summary>
/// Gets or sets the value at row 4, column 3 of this instance.
/// Gets or sets the value at column 4, row 3 of this instance.
/// </summary>
public pfloat M43 { get { return Column2.W; } set { Column2.W = value; } }
public pfloat M43 { get { return Column3.Z; } set { Column3.Z = value; } }
/// <summary>
/// Gets or sets the value at row 4, column 4 of this instance.
/// Gets or sets the value at column 4, row 4 of this instance.
/// </summary>
public pfloat M44 { get { return Column3.W; } set { Column3.W = value; } }
@ -358,44 +382,85 @@ namespace SceneKit {
/// <param name="result">A matrix instance.</param>
public static void CreateFromAxisAngle (SCNVector3 axis, pfloat angle, out SCNMatrix4 result)
{
pfloat cos = (float) System.Math.Cos (-angle);
pfloat sin = (float) System.Math.Sin (-angle);
pfloat t = 1.0f - cos;
axis.Normalize ();
result = new SCNMatrix4 (t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0.0f,
t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f,
t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f,
0, 0, 0, 1);
CreateFromAxisAngle (axis.X, axis.Y, axis.Z, angle, out result);
}
public static void CreateFromAxisAngle (Vector3 axis, float angle, out SCNMatrix4 result)
{
pfloat cos = (float) System.Math.Cos (-angle);
pfloat sin = (float) System.Math.Sin (-angle);
pfloat t = 1.0f - cos;
axis = Vector3.Normalize (axis);
result = new SCNMatrix4 (t * axis.X * axis.X + cos, t * axis.X * axis.Y - sin * axis.Z, t * axis.X * axis.Z + sin * axis.Y, 0.0f,
t * axis.X * axis.Y + sin * axis.Z, t * axis.Y * axis.Y + cos, t * axis.Y * axis.Z - sin * axis.X, 0.0f,
t * axis.X * axis.Z - sin * axis.Y, t * axis.Y * axis.Z + sin * axis.X, t * axis.Z * axis.Z + cos, 0.0f,
0, 0, 0, 1);
CreateFromAxisAngle (axis.X, axis.Y, axis.Z, angle, out result);
}
public static void CreateFromAxisAngle (Vector3d axis, double angle, out SCNMatrix4 result)
{
double cos = System.Math.Cos (-angle);
double sin = System.Math.Sin (-angle);
double t = 1.0f - cos;
axis.Normalize ();
result = new SCNMatrix4 ((pfloat) (t * axis.X * axis.X + cos), (pfloat) (t * axis.X * axis.Y - sin * axis.Z), (pfloat) (t * axis.X * axis.Z + sin * axis.Y), (pfloat) (0.0f),
(pfloat) ( t * axis.X * axis.Y + sin * axis.Z), (pfloat) (t * axis.Y * axis.Y + cos), (pfloat) (t * axis.Y * axis.Z - sin * axis.X), (pfloat) 0.0f,
(pfloat) (t * axis.X * axis.Z - sin * axis.Y), (pfloat) (t * axis.Y * axis.Z + sin * axis.X), (pfloat) (t * axis.Z * axis.Z + cos), (pfloat) 0.0f,
0, 0, 0, 1);
CreateFromAxisAngle (axis.X, axis.Y, axis.Z, angle, out result);
}
/// <summary>
/// Build a rotation matrix from the specified axis/angle rotation.
/// </summary>
/// <param name="x">The x part of the normalized axis to rotate about.</param>
/// <param name="y">The y part of the normalized axis to rotate about.</param>
/// <param name="z">The z part of the normalized axis to rotate about.</param>
/// <param name="angle">Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).</param>
/// <param name="result">A matrix instance.</param>
static void CreateFromAxisAngle (float x, float y, float z, float angle, out SCNMatrix4 result)
{
var cos = MathF.Cos (-angle);
var sin = MathF.Sin (-angle);
var t = 1.0f - cos;
var m11 = t * x * x + cos;
var m12 = t * x * y - sin * z;
var m13 = t * x * z + sin * y;
var m21 = t * x * y + sin * z;
var m22 = t * y * y + cos;
var m23 = t * y * z - sin * x;
var m31 = t * x * z - sin * y;
var m32 = t * y * z + sin * x;
var m33 = t * z * z + cos;
result = new SCNMatrix4 (
m11, m21, m31, 0.0f,
m12, m22, m32, 0.0f,
m13, m23, m33, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
}
/// <summary>
/// Build a rotation matrix from the specified axis/angle rotation.
/// </summary>
/// <param name="x">The x part of the normalized axis to rotate about.</param>
/// <param name="y">The y part of the normalized axis to rotate about.</param>
/// <param name="z">The z part of the normalized axis to rotate about.</param>
/// <param name="angle">Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).</param>
/// <param name="result">A matrix instance.</param>
static void CreateFromAxisAngle (double x, double y, double z, double angle, out SCNMatrix4 result)
{
var cos = Math.Cos (-angle);
var sin = Math.Sin (-angle);
var t = 1.0f - cos;
var m11 = (pfloat) (t * x * x + cos);
var m12 = (pfloat) (t * x * y - sin * z);
var m13 = (pfloat) (t * x * z + sin * y);
var m21 = (pfloat) (t * x * y + sin * z);
var m22 = (pfloat) (t * y * y + cos);
var m23 = (pfloat) (t * y * z - sin * x);
var m31 = (pfloat) (t * x * z - sin * y);
var m32 = (pfloat) (t * y * z + sin * x);
var m33 = (pfloat) (t * z * z + cos);
result = new SCNMatrix4 (
m11, m21, m31, 0.0f,
m12, m22, m32, 0.0f,
m13, m23, m33, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
}
/// <summary>
@ -425,11 +490,11 @@ namespace SceneKit {
pfloat cos = (pfloat) System.Math.Cos (angle);
pfloat sin = (pfloat) System.Math.Sin (angle);
result = new SCNMatrix4 ();
result.Row0 = SCNVector4.UnitX;
result.Row1 = new SCNVector4 (0.0f, cos, sin, 0.0f);
result.Row2 = new SCNVector4 (0.0f, -sin, cos, 0.0f);
result.Row3 = SCNVector4.UnitW;
result = new SCNMatrix4 (
1, 0, 0, 0,
0, cos, -sin, 0,
0, sin, cos, 0,
0, 0, 0, 1);
}
/// <summary>
@ -454,11 +519,11 @@ namespace SceneKit {
pfloat cos = (pfloat) System.Math.Cos (angle);
pfloat sin = (pfloat) System.Math.Sin (angle);
result = new SCNMatrix4 ();
result.Row0 = new SCNVector4 (cos, 0.0f, -sin, 0.0f);
result.Row1 = SCNVector4.UnitY;
result.Row2 = new SCNVector4 (sin, 0.0f, cos, 0.0f);
result.Row3 = SCNVector4.UnitW;
result = new SCNMatrix4 (
cos, 0, sin, 0,
0, 1, 0, 0,
-sin, 0, cos, 0,
0, 0, 0, 1);
}
/// <summary>
@ -483,11 +548,11 @@ namespace SceneKit {
pfloat cos = (pfloat) System.Math.Cos (angle);
pfloat sin = (pfloat) System.Math.Sin (angle);
result = new SCNMatrix4 ();
result.Row0 = new SCNVector4 (cos, sin, 0.0f, 0.0f);
result.Row1 = new SCNVector4 (-sin, cos, 0.0f, 0.0f);
result.Row2 = SCNVector4.UnitZ;
result.Row3 = SCNVector4.UnitW;
result = new SCNMatrix4 (
cos, -sin, 0, 0,
sin, cos, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}
/// <summary>
@ -515,8 +580,11 @@ namespace SceneKit {
/// <param name="result">The resulting SCNMatrix4 instance.</param>
public static void CreateTranslation (pfloat x, pfloat y, pfloat z, out SCNMatrix4 result)
{
result = Identity;
result.Row3 = new SCNVector4 (x, y, z, 1);
result = new SCNMatrix4 (
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1);
}
/// <summary>
@ -526,8 +594,7 @@ namespace SceneKit {
/// <param name="result">The resulting SCNMatrix4 instance.</param>
public static void CreateTranslation (ref SCNVector3 vector, out SCNMatrix4 result)
{
result = Identity;
result.Row3 = new SCNVector4 (vector.X, vector.Y, vector.Z, 1);
CreateTranslation (vector.X, vector.Y, vector.Z, out result);
}
/// <summary>
@ -743,10 +810,11 @@ namespace SceneKit {
pfloat c = -(zFar + zNear) / (zFar - zNear);
pfloat d = -(2.0f * zFar * zNear) / (zFar - zNear);
result = new SCNMatrix4 (x, 0, 0, 0,
0, y, 0, 0,
a, b, c, -1,
0, 0, d, 0);
result = new SCNMatrix4 (
x, 0, a, 0,
0, y, b, 0,
0, 0, c, d,
0, 0, -1, 0);
}
/// <summary>
@ -807,12 +875,11 @@ namespace SceneKit {
/// <returns>A scaling matrix</returns>
public static SCNMatrix4 Scale (pfloat x, pfloat y, pfloat z)
{
var result = new SCNMatrix4 ();
result.Row0 = SCNVector4.UnitX * x;
result.Row1 = SCNVector4.UnitY * y;
result.Row2 = SCNVector4.UnitZ * z;
result.Row3 = SCNVector4.UnitW;
return result;
return new SCNMatrix4 (
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1);
}
#endregion
@ -865,10 +932,11 @@ namespace SceneKit {
SCNVector3 x = SCNVector3.Normalize (SCNVector3.Cross (up, z));
SCNVector3 y = SCNVector3.Normalize (SCNVector3.Cross (z, x));
SCNMatrix4 rot = new SCNMatrix4 (new SCNVector4 (x.X, y.X, z.X, 0.0f),
new SCNVector4 (x.Y, y.Y, z.Y, 0.0f),
new SCNVector4 (x.Z, y.Z, z.Z, 0.0f),
SCNVector4.UnitW);
SCNMatrix4 rot = new SCNMatrix4 (
x.X, x.Y, x.Z, 0.0f,
y.X, y.Y, y.Z, 0.0f,
z.X, z.Y, z.Z, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
SCNMatrix4 trans = SCNMatrix4.CreateTranslation (-eye);
@ -898,43 +966,92 @@ namespace SceneKit {
#region Multiply Functions
/// <summary>
/// Multiplies two instances.
/// Combines two transformation matrices.
/// </summary>
/// <param name="left">The left operand of the multiplication.</param>
/// <param name="right">The right operand of the multiplication.</param>
/// <returns>A new instance that is the result of the multiplication</returns>
public static SCNMatrix4 Mult (SCNMatrix4 left, SCNMatrix4 right)
#if XAMCORE_5_0
/// <remarks>
/// Combining two transformation matrices means using matrix multiplication to multiply them in the reverse order (secondTransformation * firstTransformation).
/// </remarks>
/// <param name="firstTransformation">The first transformation of the combination.</param>
/// <param name="secondTransformation">The second transformation of the combination.</param>
#else
/// <remarks>
/// Combining two transformation matrices means using matrix multiplication to multiply them in the reverse order (right * left).
/// </remarks>
/// <param name="left">The first transformation of the combination.</param>
/// <param name="right">The second transformation of the combination.</param>
#endif
/// <returns>A new instance that is the result of the combination</returns>
#if XAMCORE_5_0
public static SCNMatrix4 Mult (SCNMatrix4 firstTransformation, SCNMatrix4 secondTransformation)
#else
public static SCNMatrix4 Mult(SCNMatrix4 left, SCNMatrix4 right)
#endif
{
SCNMatrix4 result;
Mult (ref left, ref right, out result);
// the matrices are reversed: https://github.com/xamarin/xamarin-macios/issues/15094#issuecomment-1139699662
#if XAMCORE_5_0
MatrixMultiply (ref secondTransformation, ref firstTransformation, out result);
#else
MatrixMultiply (ref right, ref left, out result);
#endif
return result;
}
/// <summary>
/// Multiplies two instances.
/// Combines two transformation matrices.
/// </summary>
/// <param name="left">The left operand of the multiplication.</param>
/// <param name="right">The right operand of the multiplication.</param>
/// <param name="result">A new instance that is the result of the multiplication</param>
public static void Mult (ref SCNMatrix4 left, ref SCNMatrix4 right, out SCNMatrix4 result)
#if XAMCORE_5_0
/// <remarks>
/// Combining two transformation matrices means using matrix multiplication to multiply them in the reverse order (secondTransformation * firstTransformation).
/// </remarks>
/// <param name="firstTransformation">The first transformation of the combination.</param>
/// <param name="secondTransformation">The second transformation of the combination.</param>
#else
/// <remarks>
/// Combining two transformation matrices means using matrix multiplication to multiply them in the reverse order (right * left).
/// </remarks>
/// <param name="left">The first transformation of the combination.</param>
/// <param name="right">The second transformation of the combination.</param>
#endif
/// <param name="result">A new instance that is the result of the combination</param>
#if XAMCORE_5_0
public static void Mult (ref SCNMatrix4 firstTransformation, ref SCNMatrix4 secondTransformation, out SCNMatrix4 result)
#else
public static void Mult(ref SCNMatrix4 left, ref SCNMatrix4 right, out SCNMatrix4 result)
#endif
{
result = new SCNMatrix4 (
left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41,
left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42,
left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43,
left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44,
left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41,
left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42,
left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43,
left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44,
left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41,
left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42,
left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43,
left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44,
left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41,
left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42,
left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43,
left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44);
// the matrices are reversed: https://github.com/xamarin/xamarin-macios/issues/15094#issuecomment-1139699662
#if XAMCORE_5_0
MatrixMultiply (ref secondTransformation, ref firstTransformation, out result);
#else
MatrixMultiply (ref right, ref left, out result);
#endif
}
// Multiply two matrices in the order you'd expect (left * right).
static void MatrixMultiply (ref SCNMatrix4 left, ref SCNMatrix4 right, out SCNMatrix4 result)
{
result = new SCNMatrix4(
left.Column0.X * right.Column0.X + left.Column1.X * right.Column0.Y + left.Column2.X * right.Column0.Z + left.Column3.X * right.Column0.W,
left.Column0.X * right.Column1.X + left.Column1.X * right.Column1.Y + left.Column2.X * right.Column1.Z + left.Column3.X * right.Column1.W,
left.Column0.X * right.Column2.X + left.Column1.X * right.Column2.Y + left.Column2.X * right.Column2.Z + left.Column3.X * right.Column2.W,
left.Column0.X * right.Column3.X + left.Column1.X * right.Column3.Y + left.Column2.X * right.Column3.Z + left.Column3.X * right.Column3.W,
left.Column0.Y * right.Column0.X + left.Column1.Y * right.Column0.Y + left.Column2.Y * right.Column0.Z + left.Column3.Y * right.Column0.W,
left.Column0.Y * right.Column1.X + left.Column1.Y * right.Column1.Y + left.Column2.Y * right.Column1.Z + left.Column3.Y * right.Column1.W,
left.Column0.Y * right.Column2.X + left.Column1.Y * right.Column2.Y + left.Column2.Y * right.Column2.Z + left.Column3.Y * right.Column2.W,
left.Column0.Y * right.Column3.X + left.Column1.Y * right.Column3.Y + left.Column2.Y * right.Column3.Z + left.Column3.Y * right.Column3.W,
left.Column0.Z * right.Column0.X + left.Column1.Z * right.Column0.Y + left.Column2.Z * right.Column0.Z + left.Column3.Z * right.Column0.W,
left.Column0.Z * right.Column1.X + left.Column1.Z * right.Column1.Y + left.Column2.Z * right.Column1.Z + left.Column3.Z * right.Column1.W,
left.Column0.Z * right.Column2.X + left.Column1.Z * right.Column2.Y + left.Column2.Z * right.Column2.Z + left.Column3.Z * right.Column2.W,
left.Column0.Z * right.Column3.X + left.Column1.Z * right.Column3.Y + left.Column2.Z * right.Column3.Z + left.Column3.Z * right.Column3.W,
left.Column0.W * right.Column0.X + left.Column1.W * right.Column0.Y + left.Column2.W * right.Column0.Z + left.Column3.W * right.Column0.W,
left.Column0.W * right.Column1.X + left.Column1.W * right.Column1.Y + left.Column2.W * right.Column1.Z + left.Column3.W * right.Column1.W,
left.Column0.W * right.Column2.X + left.Column1.W * right.Column2.Y + left.Column2.W * right.Column2.Z + left.Column3.W * right.Column2.W,
left.Column0.W * right.Column3.X + left.Column1.W * right.Column3.Y + left.Column2.W * right.Column3.Z + left.Column3.W * right.Column3.W);
}
#endregion
@ -1102,7 +1219,7 @@ namespace SceneKit {
#region public override string ToString()
/// <summary>
/// Returns a System.String that represents the current SCNMatrix44.
/// Returns a System.String that represents the current SCNMatrix4.
/// </summary>
/// <returns></returns>
public override string ToString ()

Просмотреть файл

@ -740,29 +740,53 @@ namespace SceneKit
#region Transform
#if NET
/// <summary>Transform a direction vector by the given Matrix
/// Assumes the matrix has a right-most column of (0,0,0,1), that is the translation part is ignored.
/// </summary>
/// <param name="vec">The column vector to transform</param>
#else
/// <summary>Transform a direction vector by the given Matrix
/// Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored.
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="vec">The row vector to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static SCNVector3 TransformVector(SCNVector3 vec, SCNMatrix4 mat)
{
SCNVector3 v;
v.X = SCNVector3.Dot(vec, new SCNVector3(mat.Column0));
v.Y = SCNVector3.Dot(vec, new SCNVector3(mat.Column1));
v.Z = SCNVector3.Dot(vec, new SCNVector3(mat.Column2));
TransformVector (ref vec, ref mat, out var v);
return v;
}
#if NET
/// <summary>Transform a direction vector by the given Matrix
/// Assumes the matrix has a right-most column of (0,0,0,1), that is the translation part is ignored.
/// </summary>
/// <param name="vec">The column vector to transform</param>
#else
/// <summary>Transform a direction vector by the given Matrix
/// Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored.
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="vec">The row vector to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void TransformVector(ref SCNVector3 vec, ref SCNMatrix4 mat, out SCNVector3 result)
{
#if NET
result.X = vec.X * mat.Row0.X +
vec.Y * mat.Row0.Y +
vec.Z * mat.Row0.Z;
result.Y = vec.X * mat.Row1.X +
vec.Y * mat.Row1.Y +
vec.Z * mat.Row1.Z;
result.Z = vec.X * mat.Row2.X +
vec.Y * mat.Row2.Y +
vec.Z * mat.Row2.Z;
#else
result.X = vec.X * mat.Row0.X +
vec.Y * mat.Row1.X +
vec.Z * mat.Row2.X;
@ -774,6 +798,7 @@ namespace SceneKit
result.Z = vec.X * mat.Row0.Z +
vec.Y * mat.Row1.Z +
vec.Z * mat.Row2.Z;
#endif
}
/// <summary>Transform a Normal by the given Matrix</summary>
@ -781,7 +806,11 @@ namespace SceneKit
/// This calculates the inverse of the given matrix, use TransformNormalInverse if you
/// already have the inverse to avoid this extra calculation
/// </remarks>
/// <param name="norm">The normal to transform</param>
#if NET
/// <param name="norm">The column-based normal to transform</param>
#else
/// <param name="norm">The row-based normal to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed normal</returns>
public static SCNVector3 TransformNormal(SCNVector3 norm, SCNMatrix4 mat)
@ -795,7 +824,11 @@ namespace SceneKit
/// This calculates the inverse of the given matrix, use TransformNormalInverse if you
/// already have the inverse to avoid this extra calculation
/// </remarks>
/// <param name="norm">The normal to transform</param>
#if NET
/// <param name="norm">The column-based normal to transform</param>
#else
/// <param name="norm">The row-based normal to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed normal</param>
public static void TransformNormal(ref SCNVector3 norm, ref SCNMatrix4 mat, out SCNVector3 result)
@ -809,15 +842,16 @@ namespace SceneKit
/// This version doesn't calculate the inverse matrix.
/// Use this version if you already have the inverse of the desired transform to hand
/// </remarks>
/// <param name="norm">The normal to transform</param>
#if NET
/// <param name="norm">The column-based normal to transform</param>
#else
/// <param name="norm">The row-based normal to transform</param>
#endif
/// <param name="invMat">The inverse of the desired transformation</param>
/// <returns>The transformed normal</returns>
public static SCNVector3 TransformNormalInverse(SCNVector3 norm, SCNMatrix4 invMat)
{
SCNVector3 n;
n.X = SCNVector3.Dot(norm, new SCNVector3(invMat.Row0));
n.Y = SCNVector3.Dot(norm, new SCNVector3(invMat.Row1));
n.Z = SCNVector3.Dot(norm, new SCNVector3(invMat.Row2));
TransformNormalInverse (ref norm, ref invMat, out var n);
return n;
}
@ -826,11 +860,28 @@ namespace SceneKit
/// This version doesn't calculate the inverse matrix.
/// Use this version if you already have the inverse of the desired transform to hand
/// </remarks>
/// <param name="norm">The normal to transform</param>
#if NET
/// <param name="norm">The column-based normal to transform</param>
#else
/// <param name="norm">The row-based normal to transform</param>
#endif
/// <param name="invMat">The inverse of the desired transformation</param>
/// <param name="result">The transformed normal</param>
public static void TransformNormalInverse(ref SCNVector3 norm, ref SCNMatrix4 invMat, out SCNVector3 result)
{
#if NET
result.X = norm.X * invMat.Column0.X +
norm.Y * invMat.Column0.Y +
norm.Z * invMat.Column0.Z;
result.Y = norm.X * invMat.Column1.X +
norm.Y * invMat.Column1.Y +
norm.Z * invMat.Column1.Z;
result.Z = norm.X * invMat.Column2.X +
norm.Y * invMat.Column2.Y +
norm.Z * invMat.Column2.Z;
#else
result.X = norm.X * invMat.Row0.X +
norm.Y * invMat.Row0.Y +
norm.Z * invMat.Row0.Z;
@ -842,27 +893,49 @@ namespace SceneKit
result.Z = norm.X * invMat.Row2.X +
norm.Y * invMat.Row2.Y +
norm.Z * invMat.Row2.Z;
#endif
}
/// <summary>Transform a Position by the given Matrix</summary>
/// <param name="pos">The position to transform</param>
#if NET
/// <param name="pos">The column-based position to transform</param>
#else
/// <param name="pos">The row-based position to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed position</returns>
public static SCNVector3 TransformPosition(SCNVector3 pos, SCNMatrix4 mat)
{
SCNVector3 p;
p.X = SCNVector3.Dot(pos, new SCNVector3(mat.Column0)) + mat.Row3.X;
p.Y = SCNVector3.Dot(pos, new SCNVector3(mat.Column1)) + mat.Row3.Y;
p.Z = SCNVector3.Dot(pos, new SCNVector3(mat.Column2)) + mat.Row3.Z;
TransformPosition (ref pos, ref mat, out var p);
return p;
}
/// <summary>Transform a Position by the given Matrix</summary>
/// <param name="pos">The position to transform</param>
#if NET
/// <param name="pos">The column-based position to transform</param>
#else
/// <param name="pos">The row-based position to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed position</param>
public static void TransformPosition(ref SCNVector3 pos, ref SCNMatrix4 mat, out SCNVector3 result)
{
#if NET
result.X = mat.Row0.X * pos.X +
mat.Row0.Y * pos.Y +
mat.Row0.Z * pos.Z +
mat.Row0.W;
result.Y = mat.Row1.X * pos.X +
mat.Row1.Y * pos.Y +
mat.Row1.Z * pos.Z +
mat.Row1.W;
result.Z = mat.Row2.X * pos.X +
mat.Row2.Y * pos.Y +
mat.Row2.Z * pos.Z +
mat.Row2.W;
#else
result.X = pos.X * mat.Row0.X +
pos.Y * mat.Row1.X +
pos.Z * mat.Row2.X +
@ -877,25 +950,29 @@ namespace SceneKit
pos.Y * mat.Row1.Z +
pos.Z * mat.Row2.Z +
mat.Row3.Z;
#endif
}
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
#if NET
/// <param name="vec">The column vector to transform</param>
#else
/// <param name="vec">The row vector to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static SCNVector4 Transform(SCNVector3 vec, SCNMatrix4 mat)
{
SCNVector4 v4 = new SCNVector4(vec.X, vec.Y, vec.Z, 1.0f);
SCNVector4 result;
result.X = SCNVector4.Dot(v4, mat.Column0);
result.Y = SCNVector4.Dot(v4, mat.Column1);
result.Z = SCNVector4.Dot(v4, mat.Column2);
result.W = SCNVector4.Dot(v4, mat.Column3);
return result;
return SCNVector4.Transform (v4, mat);
}
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
#if NET
/// <param name="vec">The column vector to transform</param>
#else
/// <param name="vec">The row vector to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void Transform(ref SCNVector3 vec, ref SCNMatrix4 mat, out SCNVector4 result)

Просмотреть файл

@ -843,25 +843,50 @@ namespace SceneKit
#region Transform
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
#if NET
/// <param name="vec">The column vector to transform</param>
#else
/// <param name="vec">The row vector to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static SCNVector4 Transform(SCNVector4 vec, SCNMatrix4 mat)
{
SCNVector4 result;
result.X = SCNVector4.Dot(vec, mat.Column0);
result.Y = SCNVector4.Dot(vec, mat.Column1);
result.Z = SCNVector4.Dot(vec, mat.Column2);
result.W = SCNVector4.Dot(vec, mat.Column3);
Transform(ref vec, ref mat, out var result);
return result;
}
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
/// <summary>Transform a Vector by the given Matrix.</summary>
#if NET
/// <param name="vec">The column vector to transform</param>
#else
/// <param name="vec">The row vector to transform</param>
#endif
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void Transform(ref SCNVector4 vec, ref SCNMatrix4 mat, out SCNVector4 result)
{
#if NET
result.X = vec.X * mat.Column0.X +
vec.Y * mat.Column1.X +
vec.Z * mat.Column2.X +
vec.W * mat.Column3.X;
result.Y = vec.X * mat.Column0.Y +
vec.Y * mat.Column1.Y +
vec.Z * mat.Column2.Y +
vec.W * mat.Column3.Y;
result.Z = vec.X * mat.Column0.Z +
vec.Y * mat.Column1.Z +
vec.Z * mat.Column2.Z +
vec.W * mat.Column3.Z;
result.W = vec.X * mat.Column0.W +
vec.Y * mat.Column1.W +
vec.Z * mat.Column2.W +
vec.W * mat.Column3.W;
#else
result.X = vec.X * mat.Row0.X +
vec.Y * mat.Row1.X +
vec.Z * mat.Row2.X +
@ -881,6 +906,7 @@ namespace SceneKit
vec.Y * mat.Row1.W +
vec.Z * mat.Row2.W +
vec.W * mat.Row3.W;
#endif
}
#endregion

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
namespace WebKit {
public partial class DomCssRuleList {

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
using System;
using ObjCRuntime;
using Foundation;

Просмотреть файл

@ -21,6 +21,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using System.Runtime.Versioning;
@ -77,8 +79,8 @@ namespace WebKit {
public DomEventListener AddEventListener (string type, DomEventListenerHandler handler, bool useCapture)
#endif
{
if (handler == null)
throw new ArgumentNullException ("handler");
if (handler is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (handler));
var obj = new DomNodeEventProxy (this, handler);
AddEventListener (type, obj, useCapture);
return obj;
@ -90,8 +92,8 @@ namespace WebKit {
public DomEventListener AddEventListener (string type, Action<DomEvent> callback, bool useCapture)
#endif
{
if (callback == null)
throw new ArgumentNullException ("callback");
if (callback is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));
var obj = new DomNodeEventProxy2 (callback);
AddEventListener (type, obj, useCapture);
return obj;

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
@ -24,15 +26,19 @@ namespace WebKit {
public T Current {
get {
if (_container is null)
throw new ObjectDisposedException (nameof (_container));
return _container [_index];
}
}
object IEnumerator.Current {
object? IEnumerator.Current {
get { return ((IEnumerator<T>) this).Current; }
}
public bool MoveNext () {
if (_container is null)
throw new ObjectDisposedException (nameof (_container));
return ++_index < _container.Count;
}
@ -40,7 +46,7 @@ namespace WebKit {
_index = -1;
}
IIndexedContainer<T> _container;
IIndexedContainer<T>? _container;
int _index;
}

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
namespace WebKit {
public partial class DomCssRuleList {

Просмотреть файл

@ -1,3 +1,5 @@
#nullable enable
using Foundation;
namespace WebKit {

Просмотреть файл

@ -6,6 +6,8 @@
//
// Copyright 2013 Xamarin Inc
#nullable enable
using System;
using Foundation;
@ -27,14 +29,14 @@ namespace WebKit {
get { return (WebNavigationType)((NSNumber)ActionInformation[WebPolicyDelegate.WebActionNavigationTypeKey]).Int32Value; }
}
public NSDictionary ElementInfo {
public NSDictionary? ElementInfo {
get { return ActionInformation[WebPolicyDelegate.WebActionElementKey] as NSDictionary; }
}
public WebActionMouseButton MouseButton {
get {
var number = ActionInformation[WebPolicyDelegate.WebActionButtonKey] as NSNumber;
if (number == null) {
if (number is null) {
return WebActionMouseButton.None;
}
@ -46,7 +48,7 @@ namespace WebKit {
get { return ((NSNumber)ActionInformation[WebPolicyDelegate.WebActionModifierFlagsKey]).UInt32Value; }
}
public NSUrl OriginalUrl {
public NSUrl? OriginalUrl {
get { return ActionInformation[WebPolicyDelegate.WebActionOriginalUrlKey] as NSUrl; }
}
}

Просмотреть файл

@ -20,6 +20,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using Foundation;
using ObjCRuntime;
@ -33,24 +36,24 @@ namespace WebKit {
public static void DecideUse (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("token");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));
ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selUse);
}
public static void DecideDownload (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));
ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selDownload);
}
public static void DecideIgnore (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));
ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selIgnore);
}

Просмотреть файл

@ -20,6 +20,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#nullable enable
using System;
using Foundation;
using ObjCRuntime;
@ -33,24 +36,24 @@ namespace WebKit {
public static void DecideUse (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("token");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));
ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selUse);
}
public static void DecideDownload (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));
ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selDownload);
}
public static void DecideIgnore (NSObject decisionToken)
{
if (decisionToken == null)
throw new ArgumentNullException ("decisionToken");
if (decisionToken is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (decisionToken));
ObjCRuntime.Messaging.void_objc_msgSend (decisionToken.Handle, selIgnore);
}

Просмотреть файл

@ -81,6 +81,7 @@ namespace PassKit {
PKPass[] GetPasses ();
[Export ("passWithPassTypeIdentifier:serialNumber:")]
[return: NullAllowed]
PKPass GetPass (string identifier, string serialNumber);
[iOS (8,0)]
@ -264,7 +265,7 @@ namespace PassKit {
[Deprecated (PlatformName.iOS, 9, 0, message: "Use 'ShippingContact' instead.")]
ABRecord ShippingAddress { get; }
[Export ("shippingMethod", ArgumentSemantic.Strong)]
[NullAllowed, Export ("shippingMethod", ArgumentSemantic.Strong)]
PKShippingMethod ShippingMethod { get; }
@ -813,7 +814,7 @@ namespace PassKit {
[Export ("initWithData:error:")]
NativeHandle Constructor (NSData data, out NSError error);
[Export ("authenticationToken", ArgumentSemantic.Copy)]
[NullAllowed, Export ("authenticationToken", ArgumentSemantic.Copy)]
string AuthenticationToken { get; }
[NoWatch]
@ -838,16 +839,17 @@ namespace PassKit {
[Export ("passURL", ArgumentSemantic.Copy)]
NSUrl PassUrl { get; }
[Export ("relevantDate", ArgumentSemantic.Copy)]
[NullAllowed, Export ("relevantDate", ArgumentSemantic.Copy)]
NSDate RelevantDate { get; }
[Export ("serialNumber", ArgumentSemantic.Copy)]
string SerialNumber { get; }
[Export ("webServiceURL", ArgumentSemantic.Copy)]
[NullAllowed, Export ("webServiceURL", ArgumentSemantic.Copy)]
NSUrl WebServiceUrl { get; }
[Export ("localizedValueForFieldKey:")]
[return: NullAllowed]
NSObject GetLocalizedValue (NSString key); // TODO: Should be enum for PKPassLibraryUserInfoKey
#if !NET
@ -857,7 +859,7 @@ namespace PassKit {
#endif
[iOS (7,0)]
[Export ("userInfo", ArgumentSemantic.Copy)]
[NullAllowed, Export ("userInfo", ArgumentSemantic.Copy)]
NSDictionary UserInfo { get; }
[iOS (8,0)]
@ -1334,7 +1336,7 @@ namespace PassKit {
[Export ("status", ArgumentSemantic.Assign)]
PKPaymentAuthorizationStatus Status { get; set; }
[Export ("errors", ArgumentSemantic.Copy)]
[NullAllowed, Export ("errors", ArgumentSemantic.Copy)]
NSError[] Errors { get; set; }
}
@ -1372,7 +1374,7 @@ namespace PassKit {
[Export ("shippingMethods", ArgumentSemantic.Copy)]
PKShippingMethod[] ShippingMethods { get; set; }
[Export ("errors", ArgumentSemantic.Copy)]
[NullAllowed, Export ("errors", ArgumentSemantic.Copy)]
NSError[] Errors { get; set; }
}
@ -1400,7 +1402,7 @@ namespace PassKit {
NativeHandle Constructor ([NullAllowed] NSError[] errors, PKPaymentSummaryItem [] paymentSummaryItems);
[Watch (6,0), iOS (13,0)]
[Export ("errors", ArgumentSemantic.Copy)]
[NullAllowed, Export ("errors", ArgumentSemantic.Copy)]
NSError [] Errors { get; set; }
// inlined

Просмотреть файл

@ -379,8 +379,6 @@ function install_specific_xcode () {
done
fi
log "Executing '$SUDO xcode-select -s $XCODE_DEVELOPER_ROOT'"
$SUDO xcode-select -s $XCODE_DEVELOPER_ROOT
log "Clearing xcrun cache..."
xcrun -k
@ -494,20 +492,6 @@ function check_specific_xcode () {
return
fi
if test -z "$1"; then
local XCODE_SELECT=$(xcode-select -p)
if [[ "x$XCODE_SELECT" != "x$XCODE_DEVELOPER_ROOT" ]]; then
if ! test -z $PROVISION_XCODE; then
log "Executing '$SUDO xcode-select -s $XCODE_DEVELOPER_ROOT'"
$SUDO xcode-select -s $XCODE_DEVELOPER_ROOT
log "Clearing xcrun cache..."
xcrun -k
else
fail "'xcode-select -p' does not point to $XCODE_DEVELOPER_ROOT, it points to $XCODE_SELECT. Execute 'make fix-xcode-select' to fix."
fi
fi
fi
ok "Found Xcode $XCODE_ACTUAL_VERSION in $XCODE_ROOT"
}

Просмотреть файл

@ -12,7 +12,6 @@ endif
MTOUCH=$(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)/bin/mtouch
export MD_APPLE_SDK_ROOT=$(abspath $(XCODE_DEVELOPER_ROOT)/../..)
export MD_MTOUCH_SDK_ROOT=$(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)
export MSBUILD_EXE_PATH=$(MONO_PREFIX)/lib/mono/msbuild/15.0/bin/MSBuild.dll
export TargetFrameworkFallbackSearchPaths=$(IOS_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild-frameworks

Просмотреть файл

@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
using SceneKit;
#if NET
using MatrixFloat2x2 = global::CoreGraphics.NMatrix2;
@ -16,6 +17,16 @@ using MatrixFloat4x3 = global::OpenTK.NMatrix4x3;
using MatrixFloat4x4 = global::OpenTK.NMatrix4;
#endif
#if __MACOS__
#if NET
using pfloat = System.Runtime.InteropServices.NFloat;
#else
using pfloat = System.nfloat;
#endif
#else
using pfloat = System.Single;
#endif
public static class LibTest {
[DllImport ("__Internal")]
public static extern int theUltimateAnswer ();
@ -126,5 +137,14 @@ namespace Bindings.Test
r3c0, r3c1, r3c2, r3c3);
}
#endif
[DllImport ("__Internal")]
public static extern SCNMatrix4 x_SCNMatrix4MakeTranslation (pfloat tx, pfloat ty, pfloat tz);
[DllImport ("__Internal")]
public static extern SCNMatrix4 x_SCNMatrix4MakeScale (pfloat tx, pfloat ty, pfloat tz);
[DllImport ("__Internal")]
public static extern SCNMatrix4 x_SCNMatrix4Translate (SCNMatrix4 m, pfloat tx, pfloat ty, pfloat tz);
}
}

Просмотреть файл

@ -10,7 +10,6 @@ SOURCES = $(TEST_SRC) \
# Everything that would invalidate a build
ALL_SOURCE_FILES = $(TEST_SRC) $(SOURCES) $(EXTRA_FILES) Makefile
export MD_APPLE_SDK_ROOT=$(shell dirname `dirname $(XCODE_DEVELOPER_ROOT)`)
export TargetFrameworkFallbackSearchPaths=$(MAC_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild-frameworks
export MSBuildExtensionsPathFallbackPathsOverride=$(MAC_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild
export XamarinMacFrameworkRoot=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current

Просмотреть файл

@ -53,6 +53,9 @@
<!-- XAMCORE_3_0 is always defined for .NET -->
<DefineConstants>$(DefineConstants);XAMCORE_3_0</DefineConstants>
<!-- Don't show warnings about platform availability -->
<NoWarn Condition="'$(IncludeCS1416Warnigs)' != 'true'">CA1416;$(NoWarn)</NoWarn>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -33,7 +33,6 @@ report:
COMMON_ARGS=/p:Platform=iPhone /p:Configuration=Release $(MSBUILD_VERBOSITY)
build-oldnet: export MD_APPLE_SDK_ROOT=$(abspath $(XCODE_DEVELOPER_ROOT)/../..)
build-oldnet: export MD_MTOUCH_SDK_ROOT=$(IOS_DESTDIR)/$(MONOTOUCH_PREFIX)
build-oldnet: export MSBUILD_EXE_PATH=$(MONO_PREFIX)/lib/mono/msbuild/15.0/bin/MSBuild.dll
build-oldnet: export TargetFrameworkFallbackSearchPaths=$(IOS_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild-frameworks

Просмотреть файл

@ -1,7 +1,6 @@
TOP=../..
include $(TOP)/Make.config
export MD_APPLE_SDK_ROOT=$(shell dirname `dirname $(XCODE_DEVELOPER_ROOT)`)
export TargetFrameworkFallbackSearchPaths=$(MAC_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild-frameworks
export MSBuildExtensionsPathFallbackPathsOverride=$(MAC_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild
export XamarinMacFrameworkRoot=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current

Просмотреть файл

@ -4,8 +4,6 @@ include $(TOP)/Make.config
MMP=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp
export MD_APPLE_SDK_ROOT:=$(abspath $(XCODE_DEVELOPER_ROOT)/../..)
ifdef TESTS_USE_SYSTEM
export TargetFrameworkFallbackSearchPaths=/Library/Frameworks/Mono.framework/External/xbuild-frameworks
export MSBuildExtensionsPathFallbackPathsOverride=/Library/Frameworks/Mono.framework/External/xbuild

Просмотреть файл

@ -1,8 +1,15 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
#if !__WATCHOS__
using ModelIO;
using MetalPerformanceShaders;
#endif
#if HAS_SCENEKIT
using SceneKit;
#endif
#if NET
using System.Numerics;
@ -31,6 +38,16 @@ using MatrixDouble4x4 = global::OpenTK.NMatrix4d;
using VectorDouble3 = global::OpenTK.NVector3d;
#endif
#if __MACOS__
#if NET
using pfloat = System.Runtime.InteropServices.NFloat;
#else
using pfloat = System.nfloat;
#endif
#else
using pfloat = System.Single;
#endif
using NUnit.Framework;
public static class Asserts
@ -714,4 +731,285 @@ public static class Asserts
AreEqual (expected.M34, actual.M34, $"{message} (M34) expected: {expected} actual: {actual}");
}
#endregion
#if HAS_SCENEKIT
public static void AreEqual (SCNVector3 expected, SCNVector3 actual, string message)
{
if (AreEqual (expected.X, actual.X, out var dX) &
AreEqual (expected.Y, actual.Y, out var dY) &
AreEqual (expected.Z, actual.Z, out var dZ))
return;
var diffString = $"({dX}, {dY}, {dZ})";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNVector3 expected, SCNVector3 actual, pfloat delta, string message)
{
if (AreEqual (expected.X, actual.X, delta, out var dX) &
AreEqual (expected.Y, actual.Y, delta, out var dY) &
AreEqual (expected.Z, actual.Z, delta, out var dZ))
return;
var diffString = $"({dX}, {dY}, {dZ})";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNVector4 expected, SCNVector4 actual, string message)
{
if (AreEqual (expected.X, actual.X, out var dX) &
AreEqual (expected.Y, actual.Y, out var dY) &
AreEqual (expected.Z, actual.Z, out var dZ) &
AreEqual (expected.W, actual.W, out var dW))
return;
var diffString = $"({dX}, {dY}, {dZ}, {dW})";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNVector4 expected, SCNVector4 actual, pfloat delta, string message)
{
if (AreEqual (expected.X, actual.X, delta, out var dX) &
AreEqual (expected.Y, actual.Y, delta, out var dY) &
AreEqual (expected.Z, actual.Z, delta, out var dZ) &
AreEqual (expected.W, actual.W, delta, out var dW))
return;
var diffString = $"({dX}, {dY}, {dZ}, {dW})";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNQuaternion expected, SCNQuaternion actual, string message)
{
if (AreEqual (expected.X, actual.X, out var dX) &
AreEqual (expected.Y, actual.Y, out var dY) &
AreEqual (expected.Z, actual.Z, out var dZ) &
AreEqual (expected.W, actual.W, out var dW))
return;
var diffString = $"[{dX}, {dY}, {dZ}, {dW}]";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNQuaternion expected, SCNQuaternion actual, pfloat delta, string message)
{
if (AreEqual (expected.X, actual.X, delta, out var dX) &
AreEqual (expected.Y, actual.Y, delta, out var dY) &
AreEqual (expected.Z, actual.Z, delta, out var dZ) &
AreEqual (expected.W, actual.W, delta, out var dW))
return;
var diffString = $"[{dX}, {dY}, {dZ}, {dW}]";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNMatrix4 expected, SCNMatrix4 actual, string message)
{
if (AreEqual (expected.M11, actual.M11, out var d11) &
AreEqual (expected.M21, actual.M21, out var d21) &
AreEqual (expected.M31, actual.M31, out var d31) &
AreEqual (expected.M41, actual.M41, out var d41) &
AreEqual (expected.M12, actual.M12, out var d12) &
AreEqual (expected.M22, actual.M22, out var d22) &
AreEqual (expected.M32, actual.M32, out var d32) &
AreEqual (expected.M42, actual.M42, out var d42) &
AreEqual (expected.M13, actual.M13, out var d13) &
AreEqual (expected.M23, actual.M23, out var d23) &
AreEqual (expected.M33, actual.M33, out var d33) &
AreEqual (expected.M43, actual.M43, out var d43) &
AreEqual (expected.M14, actual.M14, out var d14) &
AreEqual (expected.M24, actual.M24, out var d24) &
AreEqual (expected.M34, actual.M34, out var d34) &
AreEqual (expected.M44, actual.M44, out var d44)) {
var size = Marshal.SizeOf (typeof (SCNMatrix4));
unsafe {
byte* e = (byte*) (void*) &expected;
byte* a = (byte*) (void*) &actual;
AreEqual (e, a, size, message);
}
return;
}
var actualString = actual.ToString ();
var expectedString = expected.ToString ();
var diffRow1 = $"({d11}, {d12}, {d13}, {d14})";
var diffRow2 = $"({d21}, {d22}, {d23}, {d24})";
var diffRow3 = $"({d31}, {d32}, {d33}, {d34})";
var diffRow4 = $"({d41}, {d42}, {d43}, {d44})";
var diffString = $"{diffRow1}\n{diffRow2}\n{diffRow3}\n{diffRow4}";
var msg = $"{message}\nExpected:\n{expected}\nActual:\n{actual}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
public static void AreEqual (SCNMatrix4 expected, SCNMatrix4 actual, pfloat delta, string message)
{
if (AreEqual (expected.M11, actual.M11, delta, out var d11) &
AreEqual (expected.M21, actual.M21, delta, out var d21) &
AreEqual (expected.M31, actual.M31, delta, out var d31) &
AreEqual (expected.M41, actual.M41, delta, out var d41) &
AreEqual (expected.M12, actual.M12, delta, out var d12) &
AreEqual (expected.M22, actual.M22, delta, out var d22) &
AreEqual (expected.M32, actual.M32, delta, out var d32) &
AreEqual (expected.M42, actual.M42, delta, out var d42) &
AreEqual (expected.M13, actual.M13, delta, out var d13) &
AreEqual (expected.M23, actual.M23, delta, out var d23) &
AreEqual (expected.M33, actual.M33, delta, out var d33) &
AreEqual (expected.M43, actual.M43, delta, out var d43) &
AreEqual (expected.M14, actual.M14, delta, out var d14) &
AreEqual (expected.M24, actual.M24, delta, out var d24) &
AreEqual (expected.M34, actual.M34, delta, out var d34) &
AreEqual (expected.M44, actual.M44, delta, out var d44))
return;
var actualString = actual.ToString ();
var expectedString = expected.ToString ();
var diffRow1 = $"({d11}, {d12}, {d13}, {d14})";
var diffRow2 = $"({d21}, {d22}, {d23}, {d24})";
var diffRow3 = $"({d31}, {d32}, {d33}, {d34})";
var diffRow4 = $"({d41}, {d42}, {d43}, {d44})";
var diffString = $"{diffRow1}\n{diffRow2}\n{diffRow3}\n{diffRow4}";
var msg = $"{message}\nExpected:\n{expectedString}\nActual:\n{actualString}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
// The m## arguments correspond with the M## fields in SCNMatrix4
// For .NET this means the first four values are the first column (and the first row for legacy Xamarin).
public static void AreEqual (SCNMatrix4 actual, string message,
pfloat m11, pfloat m12, pfloat m13, pfloat m14,
pfloat m21, pfloat m22, pfloat m23, pfloat m24,
pfloat m31, pfloat m32, pfloat m33, pfloat m34,
pfloat m41, pfloat m42, pfloat m43, pfloat m44)
{
AreEqual (actual, message,
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44,
delta: 0);
}
// The m## arguments correspond with the M## fields in SCNMatrix4
// For .NET this means the first four values are the first column (and the first row for legacy Xamarin).
public static void AreEqual (SCNMatrix4 actual, string message,
pfloat m11, pfloat m12, pfloat m13, pfloat m14,
pfloat m21, pfloat m22, pfloat m23, pfloat m24,
pfloat m31, pfloat m32, pfloat m33, pfloat m34,
pfloat m41, pfloat m42, pfloat m43, pfloat m44,
pfloat delta
)
{
if (AreEqual (m11, actual.M11, delta, out var d11) &
AreEqual (m21, actual.M21, delta, out var d21) &
AreEqual (m31, actual.M31, delta, out var d31) &
AreEqual (m41, actual.M41, delta, out var d41) &
AreEqual (m12, actual.M12, delta, out var d12) &
AreEqual (m22, actual.M22, delta, out var d22) &
AreEqual (m32, actual.M32, delta, out var d32) &
AreEqual (m42, actual.M42, delta, out var d42) &
AreEqual (m13, actual.M13, delta, out var d13) &
AreEqual (m23, actual.M23, delta, out var d23) &
AreEqual (m33, actual.M33, delta, out var d33) &
AreEqual (m43, actual.M43, delta, out var d43) &
AreEqual (m14, actual.M14, delta, out var d14) &
AreEqual (m24, actual.M24, delta, out var d24) &
AreEqual (m34, actual.M34, delta, out var d34) &
AreEqual (m44, actual.M44, delta, out var d44))
return;
var actualString = actual.ToString ();
#if NET
var row1 = $"({m11}, {m21}, {m31}, {m41})";
var row2 = $"({m12}, {m22}, {m32}, {m42})";
var row3 = $"({m13}, {m23}, {m33}, {m43})";
var row4 = $"({m14}, {m24}, {m34}, {m44})";
#else
var row1 = $"({m11}, {m12}, {m13}, {m14})";
var row2 = $"({m21}, {m22}, {m23}, {m24})";
var row3 = $"({m31}, {m32}, {m33}, {m34})";
var row4 = $"({m41}, {m42}, {m43}, {m44})";
#endif
var expectedString = $"{row1}\n{row2}\n{row3}\n{row4}";
var diffRow1 = $"({d11}, {d12}, {d13}, {d14})";
var diffRow2 = $"({d21}, {d22}, {d23}, {d24})";
var diffRow3 = $"({d31}, {d32}, {d33}, {d34})";
var diffRow4 = $"({d41}, {d42}, {d43}, {d44})";
var diffString = $"{diffRow1}\n{diffRow2}\n{diffRow3}\n{diffRow4}";
var msg = $"{message}\nExpected:\n{expectedString}\nActual:\n{actualString}\nDiff:\n{diffString}";
Assert.Fail (msg);
}
#endif // HAS_SCENEKIT
static bool AreEqual (pfloat expected, pfloat actual, out string emojii)
{
return AreEqual (expected, actual, 0, out emojii);
}
// Use our own implementation to compare two floating point numbers with a tolerance, because
// the NUnit version doesn't seem to work correctly in legacy Xamarin (older NUnit version?).
static bool AreEqual (pfloat expected, pfloat actual, pfloat tolerance, out string emojii)
{
bool rv;
if (pfloat.IsNaN (expected) && pfloat.IsNaN (actual)) {
rv = true;
} else if (pfloat.IsInfinity (expected) || pfloat.IsNaN (expected) || pfloat.IsNaN (actual)) {
// Handle infinity specially since subtracting two infinite values gives
// NaN and the following test fails. mono also needs NaN to be handled
// specially although ms.net could use either method. Also, handle
// situation where no tolerance is used.
rv = expected.Equals (actual);
} else {
rv = Math.Abs (expected - actual) <= tolerance;
}
emojii = rv ? "✅" : "❌";
return rv;
}
public unsafe static void AreEqual (byte* expected, byte* actual, int length, string message)
{
// Check if the byte arrays are identical
var equal = true;
for (var i = 0; i < length; i++) {
var e = expected [i];
var a = actual [i];
equal &= e == a;
}
if (equal)
return;
// They're not. Create the assertion message and assert.
var e_sb = new StringBuilder ();
var a_sb = new StringBuilder ();
var d_sb = new StringBuilder ();
for (var i = 0; i < length; i++) {
var e = expected [i];
var a = actual [i];
e_sb.Append ($"0x{e:X2} ");
a_sb.Append ($"0x{a:X2} ");
if (e == a) {
d_sb.Append (" ");
} else {
d_sb.Append ("^^^^ ");
}
}
Assert.Fail ($"{message}\nExpected: {e_sb}\nActual: {a_sb}\n {d_sb}");
}
}

Просмотреть файл

@ -0,0 +1,24 @@
#if !__TVOS__ && !MONOMAC
using System;
using Foundation;
using UIKit;
using PassKit;
using NUnit.Framework;
namespace MonoTouchFixtures.PassKit {
[TestFixture]
[Preserve (AllMembers = true)]
public class PKPassTest {
[Test]
public void GetLocalizedValueNull ()
{
using var pass = new PKPass ();
Assert.IsNull (pass.GetLocalizedValue (new NSString ()), "'PKPass.GetLocalizedValue' is not returning a null value");
}
}
}
#endif

Просмотреть файл

@ -64,6 +64,28 @@ namespace MonoTouchFixtures.PassKit {
}
}
}
[Test]
public void CheckDefaultNulls ()
{
using var pr = new PKPaymentRequest ();
Assert.IsNull (pr.CountryCode, "'PKPaymentRequest.CountryCode' is not returning null by default.");
Assert.IsNull (pr.CurrencyCode, "'PKPaymentRequest.CurrencyCode' is not returning null by default.");
Assert.IsNull (pr.MerchantIdentifier, "'PKPaymentRequest.MerchantIdentifier' is not returning null by default.");
Assert.IsNull (pr.PaymentSummaryItems, "'PKPaymentRequest.PaymentSummaryItems' is not returning null by default.");
Assert.IsNull (pr.SupportedNetworks, "'PKPaymentRequest.SupportedNetworks' is not returning null by default.");
Assert.DoesNotThrow (delegate { pr.CountryCode = null; },
"'PKPaymentRequest.CountryCode' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.CurrencyCode = null; },
"'PKPaymentRequest.CurrencyCode' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.MerchantIdentifier = null; },
"'PKPaymentRequest.MerchantIdentifier' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.PaymentSummaryItems = null; },
"'PKPaymentRequest.PaymentSummaryItems' cannot be set to null.");
Assert.DoesNotThrow (delegate { pr.SupportedNetworks = null; },
"'PKPaymentRequest.SupportedNetworks' cannot be set to null.");
}
}
}

Просмотреть файл

@ -0,0 +1,30 @@
#if !__TVOS__ && !MONOMAC
using System;
using Foundation;
using UIKit;
using PassKit;
using NUnit.Framework;
namespace MonoTouchFixtures.PassKit {
[TestFixture]
[Preserve (AllMembers = true)]
public class PKPaymentSummaryItemTest {
[Test]
public void CheckDefaultNulls ()
{
using var ps = new PKPaymentSummaryItem ();
Assert.IsNull (ps.Amount, "'PKPaymentSummaryItem.Amount' is not returning null by default.");
Assert.IsNull (ps.Label, "'PKPaymentSummaryItem.Label' is not returning null by default.");
Assert.DoesNotThrow (delegate { ps.Amount = null; },
"'PKPaymentSummaryItem.Amount' cannot be set to null.");
Assert.DoesNotThrow (delegate { ps.Label = null; },
"'PKPaymentSummaryItem.Label' cannot be set to null.");
}
}
}
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,247 @@
//
// Unit tests for SCNMatrix4
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2014 Xamarin Inc. All rights reserved.
//
#if HAS_SCENEKIT
#nullable enable
using System;
using Foundation;
using SceneKit;
using NUnit.Framework;
#if __MACOS__
#if NET
using pfloat = System.Runtime.InteropServices.NFloat;
#else
using pfloat = System.nfloat;
#endif
#else
using pfloat = System.Single;
#endif
namespace MonoTouchFixtures.SceneKit {
[TestFixture]
[Preserve (AllMembers = true)]
public class SCNVector3Test
{
static pfloat delta = (pfloat) 0.000001;
[Test]
public void TransformVector()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
var transformed = SCNVector3.TransformVector (pos, matrix);
Asserts.AreEqual (new SCNVector3 (740, 1340, 1940), transformed, "Transformed");
}
[Test]
public void TransformVector_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
SCNVector3.TransformVector (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector3 (740, 1340, 1940), transformed, "Transformed");
}
[Test]
public void TransformNormal ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, -22, 23, 24,
31, 32, 33, 34,
41, 42, 43, -44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
pos.Normalize ();
var transformed = SCNVector3.TransformNormal (pos, matrix);
Asserts.AreEqual (new SCNVector3 ((pfloat) 0.406966, 0, (pfloat) (-0.151853)), transformed, delta, "Transformed");
}
[Test]
public void TransformNormal_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, -22, 23, 24,
31, 32, 33, 34,
41, 42, 43, -44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
pos.Normalize ();
SCNVector3.TransformNormal (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector3 ((pfloat) 0.406966, 0, (pfloat) (-0.151853)), transformed, delta, "Transformed");
}
[Test]
public void TransformNormalInverse ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
pos.Normalize ();
var transformed = SCNVector3.TransformNormalInverse (pos, matrix);
Asserts.AreEqual (new SCNVector3 ((pfloat) 39.0201413, (pfloat) 40.62370877, (pfloat) 42.2272762), transformed, delta, "Transformed");
}
[Test]
public void TransformNormalInverse_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
pos.Normalize ();
SCNVector3.TransformNormalInverse (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector3 ((pfloat) 39.0201413, (pfloat) 40.62370877, (pfloat) 42.2272762), transformed, delta, "Transformed");
}
[Test]
public void TransformPosition ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
var transformed = SCNVector3.TransformPosition (pos, matrix);
Asserts.AreEqual (new SCNVector3 (754, 1364, 1974), transformed, "Transformed");
}
[Test]
public void TransformPosition_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
SCNVector3.TransformPosition (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector3 (754, 1364, 1974), transformed, "Transformed");
}
[Test]
public void Transform ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
var transformed = SCNVector3.Transform (pos, matrix);
Asserts.AreEqual (new SCNVector4 (754, 1364, 1974, 2584), transformed, "Transformed");
}
[Test]
public void Transform_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
SCNVector3.Transform (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector4 (754, 1364, 1974, 2584), transformed, "Transformed");
}
[Test]
public void TransformPerspective ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
var transformed = SCNVector3.TransformPerspective (pos, matrix);
Asserts.AreEqual (new SCNVector3 ((pfloat) 0.291795, (pfloat) 0.5278637, (pfloat) 0.76393188), transformed, delta, "Transformed");
}
[Test]
public void TransformPerspective_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector3 (10, 20, 30);
SCNVector3.TransformPerspective (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector3 ((pfloat) 0.291795, (pfloat) 0.5278637, (pfloat) 0.76393188), transformed, delta, "Transformed");
}
}
}
#endif // HAS_SCENEKIT

Просмотреть файл

@ -0,0 +1,73 @@
//
// Unit tests for SCNMatrix4
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2014 Xamarin Inc. All rights reserved.
//
#if HAS_SCENEKIT
#nullable enable
using System;
using Foundation;
using SceneKit;
using NUnit.Framework;
#if __MACOS__
#if NET
using pfloat = System.Runtime.InteropServices.NFloat;
#else
using pfloat = System.nfloat;
#endif
#else
using pfloat = System.Single;
#endif
namespace MonoTouchFixtures.SceneKit {
[TestFixture]
[Preserve (AllMembers = true)]
public class SCNVector4Test
{
[Test]
public void Transform ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector4 (10, 20, 30, 40);
var transformed = SCNVector4.Transform (pos, matrix);
Asserts.AreEqual (new SCNVector4 (1300, 2300, 3300, 4300), transformed, "Transformed");
}
[Test]
public void Transform_out ()
{
var matrix = new SCNMatrix4 (
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44);
#if !NET
matrix.Transpose ();
#endif
var pos = new SCNVector4 (10, 20, 30, 40);
SCNVector4.Transform (ref pos, ref matrix, out var transformed);
Asserts.AreEqual (new SCNVector4 (1300, 2300, 3300, 4300), transformed, "Transformed");
}
}
}
#endif // HAS_SCENEKIT

Просмотреть файл

@ -223,6 +223,8 @@
<Compile Include="..\..\tools\common\ApplePlatform.cs">
<Link>ApplePlatform.cs</Link>
</Compile>
<Compile Include="SceneKit\SCNVector3Test.cs" />
<Compile Include="SceneKit\SCNVector4Test.cs" />
</ItemGroup>
<Import Project="$(RootTestsDirectory)\nunit.framework.targets" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />

Просмотреть файл

@ -3,7 +3,9 @@ using System.IO;
using NUnit.Framework;
namespace Xamarin.iOS.Tasks
using Xamarin.iOS.Tasks;
namespace Xamarin.MacDev.Tasks
{
[TestFixture]
public class DetectSdkLocationsTaskTests : TestBase

Просмотреть файл

@ -55,7 +55,7 @@ namespace Xamarin.MacDev.Tasks {
RedirectStandardOutput = true,
RedirectStandardError = true,
};
psi.EnvironmentVariables.Add ("DEVELOPER_DIR", Configuration.xcode_root);
psi.EnvironmentVariables ["DEVELOPER_DIR"] =Configuration.xcode_root;
psi.EnvironmentVariables.Remove ("XCODE_DEVELOPER_DIR_PATH"); // VSfM sets XCODE_DEVELOPER_DIR_PATH, which confuses the command-line tools if it doesn't match xcode-select, so just unset it.
var proc = Process.Start (psi);

Просмотреть файл

@ -6,7 +6,6 @@ include $(TOP)/Make.config
export TargetFrameworkFallbackSearchPaths:=$(MAC_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild-frameworks
export MSBuildExtensionsPathFallbackPathsOverride:=$(MAC_DESTDIR)/Library/Frameworks/Mono.framework/External/xbuild
export MD_APPLE_SDK_ROOT=$(abspath $(XCODE_DEVELOPER_ROOT)/../..)
ifeq ($(shell uname -a),"arm64")
IS_ARM64=1

Просмотреть файл

@ -8,6 +8,8 @@
#import <ModelIO/ModelIO.h>
#endif
#import <SceneKit/SceneKit.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -29,6 +31,16 @@ void x_mdltransform_create_global_transform (MDLObject *object, NSTimeInterval t
void x_mdltransform_get_rotation_matrix (MDLTransform *self, NSTimeInterval time, float* r0c0, float* r0c1, float* r0c2, float* r0c3, float* r1c0, float* r1c1, float* r1c2, float* r1c3, float* r2c0, float* r2c1, float* r2c2, float* r2c3, float* r3c0, float* r3c1, float* r3c2, float* r3c3);
#endif
#if TARGET_OS_OSX
#define pfloat CGFloat
#else
#define pfloat float
#endif
SCNMatrix4 x_SCNMatrix4MakeTranslation (pfloat tx, pfloat ty, pfloat tz);
SCNMatrix4 x_SCNMatrix4MakeScale (pfloat tx, pfloat ty, pfloat tz);
SCNMatrix4 x_SCNMatrix4Translate (SCNMatrix4 m, pfloat tx, pfloat ty, pfloat tz);
/*
* Various structs used in ObjCRegistrarTest
*/

Просмотреть файл

@ -250,6 +250,24 @@ x_mdltransform_get_rotation_matrix (MDLTransform *self, NSTimeInterval time,
}
#endif // !TARGET_OS_WATCH
SCNMatrix4
x_SCNMatrix4MakeTranslation (pfloat tx, pfloat ty, pfloat tz)
{
return SCNMatrix4MakeTranslation (tx, ty, tz);
}
SCNMatrix4
x_SCNMatrix4MakeScale (pfloat tx, pfloat ty, pfloat tz)
{
return SCNMatrix4MakeScale (tx, ty, tz);
}
SCNMatrix4
x_SCNMatrix4Translate (SCNMatrix4 m, pfloat tx, pfloat ty, pfloat tz)
{
return SCNMatrix4Translate (m, tx, ty, tz);
}
@interface UltimateMachine : NSObject {
}

Просмотреть файл

@ -68,6 +68,9 @@
#define x_get_matrix_float3x3 object_x_get_matrix_float3x3
#define x_get_matrix_float2x2 object_x_get_matrix_float2x2
#define x_call_block object_x_call_block
#define x_SCNMatrix4MakeTranslation object_x_SCNMatrix4MakeTranslation
#define x_SCNMatrix4MakeScale object_x_SCNMatrix4MakeScale
#define x_SCNMatrix4Translate object_x_SCNMatrix4Translate
#elif PREFIX == 2
#define theUltimateAnswer ar_theUltimateAnswer
#define useZLib ar_useZLib
@ -137,6 +140,9 @@
#define x_get_matrix_float3x3 ar_x_get_matrix_float3x3
#define x_get_matrix_float2x2 ar_x_get_matrix_float2x2
#define x_call_block ar_x_call_block
#define x_SCNMatrix4MakeTranslation ar_x_SCNMatrix4MakeTranslation
#define x_SCNMatrix4MakeScale ar_x_SCNMatrix4MakeScale
#define x_SCNMatrix4Translate ar_x_SCNMatrix4Translate
#else
// keep original names
#endif

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше