// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System;
using System.Runtime.InteropServices;
namespace SixLabors.Fonts.Native {
// ReSharper disable InconsistentNaming
internal static class CoreFoundation
{
private const string CoreFoundationFramework = "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation";
///
/// Returns the number of values currently in an array.
///
/// The array to examine.
/// The number of values in .
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern long CFArrayGetCount(IntPtr theArray);
///
/// Returns the type identifier for the CFArray opaque type.
///
/// The type identifier for the CFArray opaque type.
/// CFMutableArray objects have the same type identifier as CFArray objects.
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern ulong CFArrayGetTypeID();
///
/// Retrieves a value at a given index.
///
/// The array to examine.
/// The index of the value to retrieve. If the index is outside the index space of (0 to N-1 inclusive where N is the count of ), the behavior is undefined.
/// The value at the index in . If the return value is a Core Foundation Object, ownership follows The Get Rule.
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern IntPtr CFArrayGetValueAtIndex(IntPtr theArray, long idx);
///
/// Returns the unique identifier of an opaque type to which a Core Foundation object belongs.
///
/// The CFType object to examine.
/// A value of type CFTypeID that identifies the opaque type of .
///
/// This function returns a value that uniquely identifies the opaque type of any Core Foundation object.
/// You can compare this value with the known CFTypeID identifier obtained with a "GetTypeID" function specific to a type, for example CFDateGetTypeID.
/// These values might change from release to release or platform to platform.
///
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern ulong CFGetTypeID(IntPtr cf);
///
/// Returns the number (in terms of UTF-16 code pairs) of Unicode characters in a string.
///
/// The string to examine.
/// The number (in terms of UTF-16 code pairs) of characters stored in .
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern long CFStringGetLength(IntPtr theString);
///
/// Copies the character contents of a string to a local C string buffer after converting the characters to a given encoding.
///
/// The string whose contents you wish to access.
///
/// The C string buffer into which to copy the string. On return, the buffer contains the converted characters. If there is an error in conversion, the buffer contains only partial results.
/// The buffer must be large enough to contain the converted characters and a NUL terminator. For example, if the string is Toby, the buffer must be at least 5 bytes long.
///
/// The length of in bytes.
/// The string encoding to which the character contents of should be converted. The encoding must specify an 8-bit encoding.
/// upon success or if the conversion fails or the provided buffer is too small.
/// This function is useful when you need your own copy of a string’s character data as a C string. You also typically call it as a "backup" when a prior call to the function fails.
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern bool CFStringGetCString(IntPtr theString, byte[] buffer, long bufferSize, CFStringEncoding encoding);
///
/// Quickly obtains a pointer to a C-string buffer containing the characters of a string in a given encoding.
///
/// The string whose contents you wish to access.
/// The string encoding to which the character contents of should be converted. The encoding must specify an 8-bit encoding.
/// A pointer to a C string or NULL if the internal storage of does not allow this to be returned efficiently.
///
///
/// This function either returns the requested pointer immediately, with no memory allocations and no copying, in constant time, or returns NULL. If the latter is the result, call an alternative function such as the function to extract the characters.
///
///
/// Whether or not this function returns a valid pointer or NULL depends on many factors, all of which depend on how the string was created and its properties. In addition, the function result might change between different releases and on different platforms. So do not count on receiving a non-NULL result from this function under any circumstances.
///
///
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern IntPtr CFStringGetCStringPtr(IntPtr theString, CFStringEncoding encoding);
///
/// Releases a Core Foundation object.
///
/// A CFType object to release. This value must not be NULL.
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern void CFRelease(IntPtr cf);
///
/// Returns the path portion of a given URL.
///
/// The CFURL object whose path you want to obtain.
/// The operating system path style to be used to create the path. See for a list of possible values.
/// The URL's path in the format specified by . Ownership follows the create rule. See The Create Rule.
/// This function returns the URL's path as a file system path for a given path style.
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern IntPtr CFURLCopyFileSystemPath(IntPtr anURL, CFURLPathStyle pathStyle);
///
/// Returns the type identifier for the CFURL opaque type.
///
/// The type identifier for the CFURL opaque type.
[DllImport(CoreFoundationFramework, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = ".NET7 Only")]
public static extern ulong CFURLGetTypeID();
}
}