Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "DWriteWrapper\LocalizedStrings.cpp"
#include "DWriteWrapper\NativePointerWrapper.cpp"

#include "DWriteWrapper\FontFileEnumerator.cpp"
#include "DWriteWrapper\FontFileLoader.cpp"
#include "DWriteWrapper\FontFileStream.cpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Runtime.InteropServices;
using MS.Internal.Interop.DWrite;

namespace MS.Internal.Text.TextInterface
{
Expand Down Expand Up @@ -38,5 +39,37 @@ int CreateEnumeratorFromKey(
[In, MarshalAs(UnmanagedType.U4)] uint collectionKeySize,
/*[Out, MarshalAs(UnmanagedType.Interface)]*/ IntPtr* fontFileEnumerator
);
};
}

/// <summary>
/// The font file enumerator interface encapsulates a collection of font files. The font system uses this interface
/// to enumerate font files when building a font collection.
/// </summary>
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("72755049-5ff7-435d-8348-4be97cfa6c7c")]
internal interface IDWriteFontFileEnumeratorMirror
{
/// <summary>
/// Advances to the next font file in the collection. When it is first created, the enumerator is positioned
/// before the first element of the collection and the first call to MoveNext advances to the first file.
/// </summary>
/// <param name="hasCurrentFile">Receives the value TRUE if the enumerator advances to a file, or FALSE if
/// the enumerator advanced past the last file in the collection.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
[PreserveSig]
int MoveNext([MarshalAs(UnmanagedType.Bool)] out bool hasCurrentFile);

/// <summary>
/// Gets a reference to the current font file.
/// </summary>
/// <param name="fontFile">Pointer to the newly created font file object.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
[PreserveSig]
unsafe int GetCurrentFontFile(/*[Out, MarshalAs(UnmanagedType.Interface)]*/ IDWriteFontFile** fontFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using MS.Internal.Text.TextInterface.Interfaces;
using MS.Internal.Interop.DWrite;

namespace MS.Internal.Text.TextInterface
{
Expand Down Expand Up @@ -63,7 +63,7 @@ public int CreateEnumeratorFromKey(IntPtr factory, [In] void* collectionKey, [In
FontFileEnumerator fontFileEnum = new FontFileEnumerator(
fontSourceCollection,
_fontFileLoader,
(Native.IDWriteFactory*)factory.ToPointer()
(IDWriteFactory*)factory.ToPointer()
);
IntPtr pIDWriteFontFileEnumeratorMirror = Marshal.GetComInterfaceForObject(
fontFileEnum,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using MS.Internal.Interop.DWrite;

namespace MS.Internal.Text.TextInterface
{
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
internal unsafe class FontFileEnumerator : IDWriteFontFileEnumeratorMirror
Comment thread
ThomasGoulet73 marked this conversation as resolved.
Resolved
{
private const int S_OK = unchecked((int)0L);
private const int E_INVALIDARG = unchecked((int)0x80070057L);

private readonly IEnumerator<IFontSource> _fontSourceCollectionEnumerator;
private readonly FontFileLoader _fontFileLoader;
private readonly IDWriteFactory* _factory;

public FontFileEnumerator()
{
Debug.Fail("Assertion failed");
}

public FontFileEnumerator(IEnumerable<IFontSource> fontSourceCollection, FontFileLoader fontFileLoader, IDWriteFactory* factory)
{
_fontSourceCollectionEnumerator = fontSourceCollection.GetEnumerator();
_fontFileLoader = fontFileLoader;
factory->AddRef();
_factory = factory;
}

/// <summary>
/// Advances to the next font file in the collection. When it is first created, the enumerator is positioned
/// before the first element of the collection and the first call to MoveNext advances to the first file.
/// </summary>
/// <param name="hasCurrentFile">Receives the value TRUE if the enumerator advances to a file, or FALSE if
/// the enumerator advanced past the last file in the collection.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
[ComVisible(true)]
public int MoveNext([MarshalAs(UnmanagedType.Bool)] out bool hasCurrentFile)
{
try
{
hasCurrentFile = _fontSourceCollectionEnumerator.MoveNext();
return S_OK;
}
catch (Exception exception)
{
hasCurrentFile = default;
return Marshal.GetHRForException(exception);
}
}

/// <summary>
/// Gets a reference to the current font file.
/// </summary>
/// <param name="fontFile">Pointer to the newly created font file object.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
[ComVisible(true)]
public unsafe int GetCurrentFontFile(IDWriteFontFile** fontFile)
{
if (fontFile is null)
return E_INVALIDARG;

return InternalFactory.CreateFontFile(
(Native.IDWriteFactory*)_factory,
_fontFileLoader,
_fontSourceCollectionEnumerator.Current.Uri,
(Native.IDWriteFontFile**)fontFile
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
<Compile Include="MS\Internal\Text\TextInterface\DWriteUtil.cs" />
<Compile Include="MS\Internal\Text\TextInterface\Factory.cs" />
<Compile Include="MS\Internal\Text\TextInterface\FontCollectionLoader.cs" />
<Compile Include="MS\Internal\Text\TextInterface\FontFileEnumerator.cs" />
<Compile Include="MS\Internal\Text\TextInterface\IFontSourceCollection.cs" />
<Compile Include="MS\Internal\TextFormatting\Bidi.cs" />
<Compile Include="MS\Internal\TextFormatting\CultureMapper.cs" />
Expand Down