private static int CreateEnumeratorFromKeyImpl(IntPtr thisPtr, IntPtr factory, IntPtr collectionKey, int collectionKeySize, out IntPtr fontFileEnumerator) { fontFileEnumerator = IntPtr.Zero; try { IDWriteFontCollectionLoaderShadow shadow = ToShadow <IDWriteFontCollectionLoaderShadow>(thisPtr); IDWriteFontCollectionLoader callback = (IDWriteFontCollectionLoader)shadow.Callback; Debug.Assert(factory == shadow._factory.NativePointer); IDWriteFontFileEnumerator enumerator = callback.CreateEnumeratorFromKey(shadow._factory, collectionKey, collectionKeySize); fontFileEnumerator = IDWriteFontFileEnumeratorShadow.ToIntPtr(enumerator); } catch (Exception exception) { return((int)Result.GetResultFromException(exception)); } return(Result.Ok.Code); }
HRESULT IDWriteFontCollectionLoader.CreateEnumeratorFromKey(IDWriteFactory factory, IntPtr collectionKey, uint collectionKeySize, out IDWriteFontFileEnumerator fontFileEnumerator) { var func = EnumerableFunc; if (func == null) { fontFileEnumerator = null; ComError.SetError(nameof(EnumerableFunc) + " was not set."); return(HRESULTS.DISP_E_EXCEPTION); } byte[] key; if (collectionKey == IntPtr.Zero || collectionKeySize == 0) { key = null; } else { key = new byte[collectionKeySize]; Marshal.Copy(collectionKey, key, 0, (int)collectionKeySize); } var enumerable = func(factory, key); if (enumerable == null) { fontFileEnumerator = null; ComError.SetError(nameof(EnumerableFunc) + " returned nothing."); return(HRESULTS.DISP_E_EXCEPTION); } var enumerator = enumerable.GetEnumerator(); if (enumerator == null) { fontFileEnumerator = null; ComError.SetError(nameof(EnumerableFunc) + " returned a null enumerator."); return(HRESULTS.DISP_E_EXCEPTION); } fontFileEnumerator = new FontFileEnumerator(factory, _loader, enumerator); return(HRESULTS.S_OK); }
/// <summary> /// Return a pointer to the unmanaged version of this callback. /// </summary> /// <param name="callback">The callback.</param> /// <returns>A pointer to a shadow c++ callback</returns> public static IntPtr ToIntPtr(IDWriteFontFileEnumerator callback) => ToCallbackPtr <IDWriteFontFileEnumerator>(callback);