forked from dotnet/wpf
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate DWrite FontCollectionLoader to managed.
Contributes to dotnet#5305
- Loading branch information
1 parent
57e86a2
commit 7a8760a
Showing
10 changed files
with
126 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.cpp
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.h
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/IFontSourceCollection.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...rosoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteInterfaces.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MS.Internal.Text.TextInterface | ||
{ | ||
/// <summary> | ||
/// The font collection loader interface is used to construct a collection of fonts given a particular type of key. | ||
/// The font collection loader interface is recommended to be implemented by a singleton object. | ||
/// IMPORTANT: font collection loader implementations must not register themselves with DirectWrite factory | ||
/// inside their constructors and must not unregister themselves in their destructors, because | ||
/// registration and unregistraton operations increment and decrement the object reference count respectively. | ||
/// Instead, registration and unregistration of font file loaders with DirectWrite factory should be performed | ||
/// outside of the font file loader implementation as a separate step. | ||
/// </summary> | ||
[ComImport] | ||
[Guid("cca920e4-52f0-492b-bfa8-29c72ee0a468")] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
internal unsafe interface IDWriteFontCollectionLoaderMirror | ||
{ | ||
/// <summary> | ||
/// Creates a font file enumerator object that encapsulates a collection of font files. | ||
/// The font system calls back to this interface to create a font collection. | ||
/// </summary> | ||
/// <param name="collectionKey">Font collection key that uniquely identifies the collection of font files within | ||
/// the scope of the font collection loader being used.</param> | ||
/// <param name="collectionKeySize">Size of the font collection key in bytes.</param> | ||
/// <param name="fontFileEnumerator">Pointer to the newly created font file enumerator.</param> | ||
/// <returns> | ||
/// Standard HRESULT error code. | ||
/// </returns> | ||
[PreserveSig] | ||
int CreateEnumeratorFromKey( | ||
/*[In, MarshalAs(UnmanagedType.Interface)]*/ IntPtr factory, | ||
[In] void* collectionKey, | ||
[In, MarshalAs(UnmanagedType.U4)] uint collectionKeySize, | ||
/*[Out, MarshalAs(UnmanagedType.Interface)]*/ IntPtr* fontFileEnumerator | ||
); | ||
}; | ||
} |
65 changes: 65 additions & 0 deletions
65
...ft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FontCollectionLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using MS.Internal.Text.TextInterface.Interfaces; | ||
|
||
namespace MS.Internal.Text.TextInterface | ||
{ | ||
[ClassInterface(ClassInterfaceType.None)] | ||
[ComVisible(true)] | ||
internal unsafe class FontCollectionLoader : IDWriteFontCollectionLoaderMirror | ||
{ | ||
private const int S_OK = unchecked((int)0L); | ||
private const int E_INVALIDARG = unchecked((int)0x80070057L); | ||
|
||
private readonly IFontSourceCollectionFactory _fontSourceCollectionFactory; | ||
private readonly FontFileLoader _fontFileLoader; | ||
|
||
public FontCollectionLoader(IFontSourceCollectionFactory fontSourceCollectionFactory, FontFileLoader fontFileLoader) | ||
{ | ||
_fontSourceCollectionFactory = fontSourceCollectionFactory; | ||
_fontFileLoader = fontFileLoader; | ||
} | ||
|
||
[ComVisible(true)] | ||
public int CreateEnumeratorFromKey(IntPtr factory, [In] void* collectionKey, [In, MarshalAs(UnmanagedType.U4)] uint collectionKeySize, IntPtr* fontFileEnumerator) | ||
{ | ||
uint numberOfCharacters = collectionKeySize / sizeof(char); | ||
if ((fontFileEnumerator == null) | ||
|| (collectionKeySize % sizeof(char) != 0) // The collectionKeySize must be divisible by sizeof(WCHAR) | ||
|| (numberOfCharacters <= 1) // The collectionKey cannot be less than or equal 1 character as it has to contain the NULL character. | ||
|| (((char*)collectionKey)[numberOfCharacters - 1] != '\0')) // The collectionKey must end with the NULL character | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*fontFileEnumerator = IntPtr.Zero; | ||
|
||
string uriString = new string((char*)collectionKey); | ||
int hr = S_OK; | ||
|
||
try | ||
{ | ||
IFontSourceCollection fontSourceCollection = _fontSourceCollectionFactory.Create(uriString); | ||
FontFileEnumerator fontFileEnum = new FontFileEnumerator( | ||
fontSourceCollection, | ||
_fontFileLoader, | ||
(Native.IDWriteFactory*)factory.ToPointer() | ||
); | ||
IntPtr pIDWriteFontFileEnumeratorMirror = Marshal.GetComInterfaceForObject( | ||
fontFileEnum, | ||
typeof(IDWriteFontFileEnumeratorMirror)); | ||
|
||
*fontFileEnumerator = pIDWriteFontFileEnumeratorMirror; | ||
} | ||
catch (Exception exception) | ||
{ | ||
hr = Marshal.GetHRForException(exception); | ||
} | ||
|
||
return hr; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...t.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/IFontSourceCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace MS.Internal.Text.TextInterface | ||
{ | ||
internal interface IFontSourceCollection : IEnumerable<IFontSource> | ||
{ | ||
} | ||
|
||
internal interface IFontSourceCollectionFactory | ||
{ | ||
IFontSourceCollection Create(string uriString); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters