[dotnet] CoreFont delegates (#17338)
This commit is contained in:
Родитель
608765e2c9
Коммит
ede46ed426
|
@ -196,13 +196,24 @@ namespace CoreText {
|
||||||
return CFArray.ArrayFromHandleFunc (cfArrayRef, fd => new CTFontDescriptor (fd, false), true)!;
|
return CFArray.ArrayFromHandleFunc (cfArrayRef, fd => new CTFontDescriptor (fd, false), true)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[DllImport (Constants.CoreTextLibrary)]
|
||||||
|
static unsafe extern IntPtr CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback (
|
||||||
|
IntPtr collection, delegate* unmanaged<IntPtr, IntPtr, IntPtr, CFIndex> sortCallback,
|
||||||
|
IntPtr refCon);
|
||||||
|
#else
|
||||||
[DllImport (Constants.CoreTextLibrary)]
|
[DllImport (Constants.CoreTextLibrary)]
|
||||||
static extern IntPtr CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback (
|
static extern IntPtr CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback (
|
||||||
IntPtr collection, CTFontCollectionSortDescriptorsCallback sortCallback, IntPtr refCon);
|
IntPtr collection, CTFontCollectionSortDescriptorsCallback sortCallback, IntPtr refCon);
|
||||||
|
|
||||||
delegate CFIndex CTFontCollectionSortDescriptorsCallback (IntPtr first, IntPtr second, IntPtr refCon);
|
delegate CFIndex CTFontCollectionSortDescriptorsCallback (IntPtr first, IntPtr second, IntPtr refCon);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[UnmanagedCallersOnly]
|
||||||
|
#else
|
||||||
[MonoPInvokeCallback (typeof (CTFontCollectionSortDescriptorsCallback))]
|
[MonoPInvokeCallback (typeof (CTFontCollectionSortDescriptorsCallback))]
|
||||||
|
#endif
|
||||||
static CFIndex CompareDescriptors (IntPtr first, IntPtr second, IntPtr context)
|
static CFIndex CompareDescriptors (IntPtr first, IntPtr second, IntPtr context)
|
||||||
{
|
{
|
||||||
GCHandle c = GCHandle.FromIntPtr (context);
|
GCHandle c = GCHandle.FromIntPtr (context);
|
||||||
|
@ -217,10 +228,20 @@ namespace CoreText {
|
||||||
{
|
{
|
||||||
GCHandle comparison = GCHandle.Alloc (comparer);
|
GCHandle comparison = GCHandle.Alloc (comparer);
|
||||||
try {
|
try {
|
||||||
var cfArrayRef = CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback (
|
IntPtr cfArrayRef;
|
||||||
|
#if NET
|
||||||
|
unsafe {
|
||||||
|
cfArrayRef = CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback (
|
||||||
|
Handle,
|
||||||
|
&CompareDescriptors,
|
||||||
|
GCHandle.ToIntPtr (comparison));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
cfArrayRef = CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback (
|
||||||
Handle,
|
Handle,
|
||||||
new CTFontCollectionSortDescriptorsCallback (CompareDescriptors),
|
new CTFontCollectionSortDescriptorsCallback (CompareDescriptors),
|
||||||
GCHandle.ToIntPtr (comparison));
|
GCHandle.ToIntPtr (comparison));
|
||||||
|
#endif
|
||||||
if (cfArrayRef == IntPtr.Zero)
|
if (cfArrayRef == IntPtr.Zero)
|
||||||
return Array.Empty<CTFontDescriptor> ();
|
return Array.Empty<CTFontDescriptor> ();
|
||||||
return CFArray.ArrayFromHandleFunc (cfArrayRef, fd => new CTFontDescriptor (fd, false), true)!;
|
return CFArray.ArrayFromHandleFunc (cfArrayRef, fd => new CTFontDescriptor (fd, false), true)!;
|
||||||
|
|
|
@ -740,10 +740,17 @@ namespace CoreText {
|
||||||
#else
|
#else
|
||||||
[Mac (10, 9)]
|
[Mac (10, 9)]
|
||||||
#endif
|
#endif
|
||||||
|
#if NET
|
||||||
|
[DllImport (Constants.CoreTextLibrary)]
|
||||||
|
[return: MarshalAs (UnmanagedType.I1)]
|
||||||
|
static unsafe extern bool CTFontDescriptorMatchFontDescriptorsWithProgressHandler (IntPtr descriptors, IntPtr mandatoryAttributes,
|
||||||
|
delegate* unmanaged<CTFontDescriptorMatchingState, IntPtr, bool> progressHandler);
|
||||||
|
#else
|
||||||
[DllImport (Constants.CoreTextLibrary)]
|
[DllImport (Constants.CoreTextLibrary)]
|
||||||
[return: MarshalAs (UnmanagedType.I1)]
|
[return: MarshalAs (UnmanagedType.I1)]
|
||||||
static extern bool CTFontDescriptorMatchFontDescriptorsWithProgressHandler (IntPtr descriptors, IntPtr mandatoryAttributes,
|
static extern bool CTFontDescriptorMatchFontDescriptorsWithProgressHandler (IntPtr descriptors, IntPtr mandatoryAttributes,
|
||||||
Func<CTFontDescriptorMatchingState, IntPtr, bool> progressHandler);
|
Func<CTFontDescriptorMatchingState, IntPtr, bool> progressHandler);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if NET
|
#if NET
|
||||||
[SupportedOSPlatform ("macos")]
|
[SupportedOSPlatform ("macos")]
|
||||||
|
|
|
@ -46,6 +46,16 @@ namespace CoreText {
|
||||||
delegate void CTRunDelegateDeallocateCallback (IntPtr refCon);
|
delegate void CTRunDelegateDeallocateCallback (IntPtr refCon);
|
||||||
delegate nfloat CTRunDelegateGetCallback (IntPtr refCon);
|
delegate nfloat CTRunDelegateGetCallback (IntPtr refCon);
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[StructLayout (LayoutKind.Sequential)]
|
||||||
|
struct CTRunDelegateCallbacks {
|
||||||
|
public /* CFIndex */ nint version;
|
||||||
|
public unsafe delegate* unmanaged<IntPtr, void> dealloc;
|
||||||
|
public unsafe delegate* unmanaged<IntPtr, nfloat> getAscent;
|
||||||
|
public unsafe delegate* unmanaged<IntPtr, nfloat> getDescent;
|
||||||
|
public unsafe delegate* unmanaged<IntPtr, nfloat> getWidth;
|
||||||
|
}
|
||||||
|
#else
|
||||||
[StructLayout (LayoutKind.Sequential)]
|
[StructLayout (LayoutKind.Sequential)]
|
||||||
struct CTRunDelegateCallbacks {
|
struct CTRunDelegateCallbacks {
|
||||||
public /* CFIndex */ nint version;
|
public /* CFIndex */ nint version;
|
||||||
|
@ -54,6 +64,7 @@ namespace CoreText {
|
||||||
public CTRunDelegateGetCallback getDescent;
|
public CTRunDelegateGetCallback getDescent;
|
||||||
public CTRunDelegateGetCallback getWidth;
|
public CTRunDelegateGetCallback getWidth;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#if NET
|
#if NET
|
||||||
|
@ -128,6 +139,17 @@ namespace CoreText {
|
||||||
internal CTRunDelegateCallbacks GetCallbacks ()
|
internal CTRunDelegateCallbacks GetCallbacks ()
|
||||||
{
|
{
|
||||||
if (!callbacks.HasValue) {
|
if (!callbacks.HasValue) {
|
||||||
|
#if NET
|
||||||
|
unsafe {
|
||||||
|
callbacks = new CTRunDelegateCallbacks () {
|
||||||
|
version = 1,
|
||||||
|
dealloc = &Deallocate,
|
||||||
|
getAscent = &GetAscent,
|
||||||
|
getDescent = &GetDescent,
|
||||||
|
getWidth = &GetWidth,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#else
|
||||||
callbacks = new CTRunDelegateCallbacks () {
|
callbacks = new CTRunDelegateCallbacks () {
|
||||||
version = 1, // kCTRunDelegateVersion1
|
version = 1, // kCTRunDelegateVersion1
|
||||||
dealloc = Deallocate,
|
dealloc = Deallocate,
|
||||||
|
@ -135,11 +157,16 @@ namespace CoreText {
|
||||||
getDescent = GetDescent,
|
getDescent = GetDescent,
|
||||||
getWidth = GetWidth,
|
getWidth = GetWidth,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return callbacks.Value;
|
return callbacks.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[UnmanagedCallersOnly]
|
||||||
|
#else
|
||||||
[MonoPInvokeCallback (typeof (CTRunDelegateDeallocateCallback))]
|
[MonoPInvokeCallback (typeof (CTRunDelegateDeallocateCallback))]
|
||||||
|
#endif
|
||||||
static void Deallocate (IntPtr refCon)
|
static void Deallocate (IntPtr refCon)
|
||||||
{
|
{
|
||||||
var self = GetOperations (refCon);
|
var self = GetOperations (refCon);
|
||||||
|
@ -160,7 +187,11 @@ namespace CoreText {
|
||||||
return c.Target as CTRunDelegateOperations;
|
return c.Target as CTRunDelegateOperations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[UnmanagedCallersOnly]
|
||||||
|
#else
|
||||||
[MonoPInvokeCallback (typeof (CTRunDelegateGetCallback))]
|
[MonoPInvokeCallback (typeof (CTRunDelegateGetCallback))]
|
||||||
|
#endif
|
||||||
static nfloat GetAscent (IntPtr refCon)
|
static nfloat GetAscent (IntPtr refCon)
|
||||||
{
|
{
|
||||||
var self = GetOperations (refCon);
|
var self = GetOperations (refCon);
|
||||||
|
@ -169,7 +200,11 @@ namespace CoreText {
|
||||||
return (nfloat) self.GetAscent ();
|
return (nfloat) self.GetAscent ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[UnmanagedCallersOnly]
|
||||||
|
#else
|
||||||
[MonoPInvokeCallback (typeof (CTRunDelegateGetCallback))]
|
[MonoPInvokeCallback (typeof (CTRunDelegateGetCallback))]
|
||||||
|
#endif
|
||||||
static nfloat GetDescent (IntPtr refCon)
|
static nfloat GetDescent (IntPtr refCon)
|
||||||
{
|
{
|
||||||
var self = GetOperations (refCon);
|
var self = GetOperations (refCon);
|
||||||
|
@ -178,7 +213,11 @@ namespace CoreText {
|
||||||
return (nfloat) self.GetDescent ();
|
return (nfloat) self.GetDescent ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET
|
||||||
|
[UnmanagedCallersOnly]
|
||||||
|
#else
|
||||||
[MonoPInvokeCallback (typeof (CTRunDelegateGetCallback))]
|
[MonoPInvokeCallback (typeof (CTRunDelegateGetCallback))]
|
||||||
|
#endif
|
||||||
static nfloat GetWidth (IntPtr refCon)
|
static nfloat GetWidth (IntPtr refCon)
|
||||||
{
|
{
|
||||||
var self = GetOperations (refCon);
|
var self = GetOperations (refCon);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче