diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteInterfaces.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteInterfaces.h
index 4c05f4561ec..1c55379f865 100644
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteInterfaces.h
+++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/DWriteInterfaces.h
@@ -150,38 +150,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface { n
/*[Out, MarshalAs(UnmanagedType::Interface)]*/ IDWriteFontFile** fontFile
);
};
-
- ///
- /// 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.
- ///
- [ComImport(), Guid("cca920e4-52f0-492b-bfa8-29c72ee0a468"), InterfaceType(ComInterfaceType::InterfaceIsIUnknown)]
- interface class IDWriteFontCollectionLoaderMirror
- {
- ///
- /// 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.
- ///
- /// Font collection key that uniquely identifies the collection of font files within
- /// the scope of the font collection loader being used.
- /// Size of the font collection key in bytes.
- /// Pointer to the newly created font file enumerator.
- ///
- /// Standard HRESULT error code.
- ///
- [PreserveSig]
- HRESULT CreateEnumeratorFromKey(
- /*[In, MarshalAs(UnmanagedType::Interface)]*/ IntPtr factory,
- [In] void const* collectionKey,
- [In, MarshalAs(UnmanagedType::U4)] UINT32 collectionKeySize,
- /*[Out, MarshalAs(UnmanagedType::Interface)]*/ IntPtr* fontFileEnumerator
- );
- };
}}}}}
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h
index e49f9bb81a8..1b6da612b3f 100644
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h
+++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/Factory.h
@@ -11,8 +11,6 @@
#include "FontFace.h"
#include "FontCollection.h"
#include "DWriteTypeConverter.h"
-#include "IFontSourceCollection.h"
-#include "FontCollectionLoader.h"
#include "FontFileLoader.h"
#include "TextAnalyzer.h"
#include "NativePointerWrapper.h"
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.cpp b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.cpp
deleted file mode 100644
index 6a53d3fc3a8..00000000000
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#include "FontCollectionLoader.h"
-
-namespace MS { namespace Internal { namespace Text { namespace TextInterface
-{
-
- FontCollectionLoader::FontCollectionLoader(
- IFontSourceCollectionFactory^ fontSourceCollectionFactory,
- FontFileLoader^ fontFileLoader
- )
- {
- _fontSourceCollectionFactory = fontSourceCollectionFactory;
- _fontFileLoader = fontFileLoader;
- }
-
- [ComVisible(true)]
- HRESULT FontCollectionLoader::CreateEnumeratorFromKey(
- IntPtr factory,
- __in_bcount(collectionKeySize) void const* collectionKey,
- UINT32 collectionKeySize,
- __out IntPtr* fontFileEnumerator
- )
- {
- UINT32 numberOfCharacters = collectionKeySize / sizeof(WCHAR);
- if ( (fontFileEnumerator == NULL)
- || (collectionKeySize % sizeof(WCHAR) != 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.
- || (((WCHAR*)collectionKey)[numberOfCharacters - 1] != '\0')) // The collectionKey must end with the NULL character
- {
- return E_INVALIDARG;
- }
-
- *fontFileEnumerator = IntPtr::Zero;
-
- String^ uriString = gcnew String((WCHAR*)collectionKey);
- HRESULT hr = S_OK;
-
- try
- {
- IFontSourceCollection^ fontSourceCollection = _fontSourceCollectionFactory->Create(uriString);
- FontFileEnumerator^ fontFileEnum = gcnew FontFileEnumerator(
- fontSourceCollection,
- _fontFileLoader,
- (IDWriteFactory *)factory.ToPointer()
- );
- IntPtr pIDWriteFontFileEnumeratorMirror = Marshal::GetComInterfaceForObject(
- fontFileEnum,
- IDWriteFontFileEnumeratorMirror::typeid);
-
- *fontFileEnumerator = pIDWriteFontFileEnumeratorMirror;
- }
- catch(System::Exception^ exception)
- {
- hr = System::Runtime::InteropServices::Marshal::GetHRForException(exception);
- }
-
- return hr;
- }
-
-}}}}//MS::Internal::Text::TextInterface
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.h
deleted file mode 100644
index a236b1a75de..00000000000
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontCollectionLoader.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#ifndef __FONTCOLLECTIONLOADER_H
-#define __FONTCOLLECTIONLOADER_H
-
-#include "IFontSourceCollection.h"
-#include "FontFileEnumerator.h"
-#include "Common.h"
-#include "DWriteInterfaces.h"
-
-using namespace System;
-using namespace System::Diagnostics;
-
-namespace MS { namespace Internal { namespace Text { namespace TextInterface
-{
- [ClassInterface(ClassInterfaceType::None), ComVisible(true)]
- private ref class FontCollectionLoader : public IDWriteFontCollectionLoaderMirror
- {
- private:
-
- IFontSourceCollectionFactory^ _fontSourceCollectionFactory;
- FontFileLoader^ _fontFileLoader;
-
- public:
-
- FontCollectionLoader() { Debug::Assert(false); }
-
- FontCollectionLoader(
- IFontSourceCollectionFactory^ fontSourceCollectionFactory,
- FontFileLoader^ fontFileLoader
- );
-
- ///
- /// 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.
- ///
- /// Font collection key that uniquely identifies the collection of font files within
- /// the scope of the font collection loader being used.
- /// Size of the font collection key in bytes.
- /// Pointer to the newly created font file enumerator.
- ///
- /// Standard HRESULT error code.
- ///
- [ComVisible(true)]
- virtual HRESULT CreateEnumeratorFromKey(
- IntPtr factory,
- __in_bcount(collectionKeySize) void const* collectionKey,
- UINT32 collectionKeySize,
- __out IntPtr* fontFileEnumerator
- );
- };
-}}}}//MS::Internal::Text::TextInterface
-
-#endif //__FONTCOLLECTIONLOADER_H
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/IFontSourceCollection.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/IFontSourceCollection.h
deleted file mode 100644
index dab5f448fa0..00000000000
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/IFontSourceCollection.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#ifndef __IFONTSOURCECOLLECTION_H
-#define __IFONTSOURCECOLLECTION_H
-
-#include "IFontSource.h"
-
-using namespace System;
-namespace MS { namespace Internal { namespace Text { namespace TextInterface
-{
- private interface class IFontSourceCollection : IEnumerable
- {
- };
-
- private interface class IFontSourceCollectionFactory
- {
- IFontSourceCollection^ Create(String^);
- };
-
-}}}}//MS::Internal::Text::TextInterface
-
-#endif //__IFONTSOURCECOLLECTION_H
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DirectWriteForwarder.cpp b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DirectWriteForwarder.cpp
index b3af9d457b7..254ef87ecf5 100644
--- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DirectWriteForwarder.cpp
+++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DirectWriteForwarder.cpp
@@ -18,7 +18,6 @@
#include "DWriteWrapper\LocalizedStrings.cpp"
#include "DWriteWrapper\NativePointerWrapper.cpp"
-#include "DWriteWrapper\FontCollectionLoader.cpp"
#include "DWriteWrapper\FontFileEnumerator.cpp"
#include "DWriteWrapper\FontFileLoader.cpp"
#include "DWriteWrapper\FontFileStream.cpp"
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteInterfaces.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteInterfaces.cs
new file mode 100644
index 00000000000..8da45bb7c27
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteInterfaces.cs
@@ -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
+{
+ ///
+ /// 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.
+ ///
+ [ComImport]
+ [Guid("cca920e4-52f0-492b-bfa8-29c72ee0a468")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ internal unsafe interface IDWriteFontCollectionLoaderMirror
+ {
+ ///
+ /// 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.
+ ///
+ /// Font collection key that uniquely identifies the collection of font files within
+ /// the scope of the font collection loader being used.
+ /// Size of the font collection key in bytes.
+ /// Pointer to the newly created font file enumerator.
+ ///
+ /// Standard HRESULT error code.
+ ///
+ [PreserveSig]
+ int CreateEnumeratorFromKey(
+ /*[In, MarshalAs(UnmanagedType.Interface)]*/ IntPtr factory,
+ [In] void* collectionKey,
+ [In, MarshalAs(UnmanagedType.U4)] uint collectionKeySize,
+ /*[Out, MarshalAs(UnmanagedType.Interface)]*/ IntPtr* fontFileEnumerator
+ );
+ };
+}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FontCollectionLoader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FontCollectionLoader.cs
new file mode 100644
index 00000000000..a5658b2acd4
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/FontCollectionLoader.cs
@@ -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;
+ }
+ }
+}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/IFontSourceCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/IFontSourceCollection.cs
new file mode 100644
index 00000000000..6295649524e
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/IFontSourceCollection.cs
@@ -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
+ {
+ }
+
+ internal interface IFontSourceCollectionFactory
+ {
+ IFontSourceCollection Create(string uriString);
+ }
+}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
index 41d91b7317a..dfa7af33df2 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj
@@ -273,9 +273,12 @@
+
+
+