Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Foundation/DictionaryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ protected DictionaryContainer (NSDictionary? dictionary)
return CFBoolean.GetValue (value);
}

/// <summary>Returns the nullable DateTime associated with <paramref name="key" />.</summary>
/// <param name="key">The identifier of the DateTime value.</param>
protected DateTime? GetDateTimeValue (NSString key)
{
if (key is null)
throw new ArgumentNullException (nameof (key));

var value = CFDictionary.GetValue (Dictionary.Handle, key.Handle);
GC.KeepAlive (key);
if (value == IntPtr.Zero)
return null;

return (DateTime) Runtime.GetNSObject<NSDate> (value, false)!;
}

/// <typeparam name="T">The <see cref="ObjCRuntime.INativeObject" /> type associated with <paramref name="key" />.</typeparam>
/// <param name="key">The identifier of the reference.</param>
/// <summary>Returns the native object associated with <paramref name="key" />.</summary>
Expand Down
40 changes: 40 additions & 0 deletions src/ImageIO/CGCopyImageSourceOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#nullable enable

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

using ObjCRuntime;
using Foundation;
using CoreFoundation;
using CoreGraphics;

namespace ImageIO {
#if !XAMCORE_5_0
public partial class CGCopyImageSourceOptions {
[EditorBrowsable (EditorBrowsableState.Never)]
[Obsolete ("Use 'NullableMergeMetadata' instead.")]
public bool MergeMetadata {
get => NullableMergeMetadata.HasValue ? NullableMergeMetadata.Value : false;
set => NullableMergeMetadata = value;
}

[EditorBrowsable (EditorBrowsableState.Never)]
[Obsolete ("Use 'NullableExcludeXmp' instead.")]
public bool ShouldExcludeXMP {
get => NullableShouldExcludeXmp.HasValue ? NullableShouldExcludeXmp.Value : false;
set => NullableShouldExcludeXmp = value;
}

[EditorBrowsable (EditorBrowsableState.Never)]
[Obsolete ("Use 'NullableExcludeGps' instead.")]
public bool ShouldExcludeGPS {
get => NullableShouldExcludeGps.HasValue ? NullableShouldExcludeGps.Value : false;
set => NullableShouldExcludeGps = value;
}
}
#endif // !XAMCORE_5_0
}
88 changes: 1 addition & 87 deletions src/ImageIO/CGImageDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,92 +57,6 @@ internal NSMutableDictionary ToDictionary ()
}
}

public partial class CGCopyImageSourceOptions {
/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
public CGImageMetadata? Metadata { get; set; }

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
public bool MergeMetadata { get; set; }

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
public bool ShouldExcludeXMP { get; set; }

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
public bool ShouldExcludeGPS { get; set; }

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
public DateTime? DateTime { get; set; }

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
public int? Orientation { get; set; }

internal NSMutableDictionary ToDictionary ()
{
var dict = new NSMutableDictionary ();

// new in iOS 7 and 10.8
if (Metadata is not null) {
dict.LowlevelSetObject (Metadata.Handle, kMetadata);
// default are false
if (MergeMetadata)
dict.LowlevelSetObject (CFBoolean.TrueHandle, kMergeMetadata);
if (ShouldExcludeXMP)
dict.LowlevelSetObject (CFBoolean.TrueHandle, kShouldExcludeXMP);
} else {
// DateTime is exclusive of metadata (which includes its own)
if (DateTime.HasValue)
dict.LowlevelSetObject ((NSDate) DateTime, kDateTime);
}

// new in iOS 8 and 10.10 - default is false
if (ShouldExcludeGPS && (kShouldExcludeGPS != IntPtr.Zero))
dict.LowlevelSetObject (CFBoolean.TrueHandle, kShouldExcludeGPS);

if (Orientation.HasValue) {
using (var n = new NSNumber (Orientation.Value))
dict.LowlevelSetObject (n.Handle, kOrientation);
}

return dict;
}
}

/// <summary>To be added.</summary>
/// <remarks>To be added.</remarks>
public partial class CGImageAuxiliaryDataInfo {
Expand Down Expand Up @@ -475,7 +389,7 @@ public bool CopyImageSource (CGImageSource image, NSDictionary? options, out NSE
[SupportedOSPlatform ("tvos")]
public bool CopyImageSource (CGImageSource image, CGCopyImageSourceOptions? options, out NSError? error)
{
using var o = options?.ToDictionary ();
using var o = options?.Dictionary;
return CopyImageSource (image, o, out error);
}

Expand Down
2 changes: 2 additions & 0 deletions src/bgen/Caches/TypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class TypeCache {
public Type System_Boolean { get; }
public Type System_Byte { get; }
public Type System_Char { get; }
public Type System_DateTime { get; }
public Type System_Delegate { get; }
public Type System_Double { get; }
public Type System_Float { get; }
Expand Down Expand Up @@ -168,6 +169,7 @@ public TypeCache (MetadataLoadContext universe, Frameworks frameworks, PlatformN
System_Boolean = Lookup (corlibAssembly, "System", "Boolean");
System_Byte = Lookup (corlibAssembly, "System", "Byte");
System_Char = Lookup (corlibAssembly, "System", "Char");
System_DateTime = Lookup (corlibAssembly, "System", "DateTime");
System_Delegate = Lookup (corlibAssembly, "System", "Delegate");
System_Double = Lookup (corlibAssembly, "System", "Double");
System_Float = Lookup (corlibAssembly, "System", "Single");
Expand Down
15 changes: 6 additions & 9 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,9 @@ void GenerateStrongDictionaryTypes ()
} else if (fetchType == TypeCache.System_nuint) {
getter = "{1} GetNUIntValue ({0})";
setter = "SetNumberValue ({0}, {1}value)";
} else if (fetchType == TypeCache.System_DateTime) {
getter = "GetDateTimeValue ({0})";
setter = "SetNativeValue ({0}, (NSDate?) value)";
} else if (fetchType == TypeCache.CoreGraphics_CGRect) {
getter = "{1} GetCGRectValue ({0})";
setter = "SetCGRectValue ({0}, {1}value)";
Expand Down Expand Up @@ -1951,18 +1954,12 @@ void GenerateStrongDictionaryTypes ()
var strType = pi.PropertyType.Name;
getter = $"GetStrongDictionary<{strType}>({{0}}, (dict) => new {strType} (dict))";
setter = "SetNativeValue ({0}, value.GetDictionary ())";
} else if (TypeCache.INativeObject.IsAssignableFrom (pi.PropertyType)) {
getter = $"GetNativeValue<{pi.PropertyType}> ({{0}})";
setter = "SetNativeValue ({0}, value)";
} else if (TypeManager.IsWrappedType (pi.PropertyType)) {
getter = "Dictionary [{0}] as " + pi.PropertyType;
setter = "SetNativeValue ({0}, value)";
} else if (pi.PropertyType.Name == "CGColorSpace") {
getter = "GetNativeValue<" + pi.PropertyType + "> ({0})";
setter = "SetNativeValue ({0}, value)";
} else if (pi.PropertyType.Name == "CGImageSource") {
getter = "GetNativeValue<" + pi.PropertyType + "> ({0})";
setter = "SetNativeValue ({0}, value)";
} else if (pi.PropertyType.Name == "CTFontDescriptor") {
getter = "GetNativeValue<" + pi.PropertyType + "> ({0})";
setter = "SetNativeValue ({0}, value)";
} else {
exceptions.Add (new BindingException (1033, true, pi.PropertyType, dictType, pi.Name));
continue;
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ IMAGEIO_CORE_SOURCES = \
ImageIO/CGImageSource.cs \

IMAGEIO_SOURCES = \
ImageIO/CGCopyImageSourceOptions.cs \
ImageIO/CGImageAnimation.cs \
ImageIO/CGImageDestination.cs \
ImageIO/CGImageMetadata.cs \
Expand Down
Loading
Loading